Bladeren bron

Améliorations / adaptations subscription

dev
Guillaume Bourgeois 5 jaren geleden
bovenliggende
commit
62a31f5c63
11 gewijzigde bestanden met toevoegingen van 265 en 54 verwijderingen
  1. +13
    -5
      backend/controllers/SubscriptionController.php
  2. +65
    -33
      backend/views/subscription/index.php
  3. BIN
      backend/web/.sass-cache/2a0ffb00578c9d5a537db16d14c734a22b18f35c/screen.scssc
  4. +21
    -8
      backend/web/css/screen.css
  5. +9
    -0
      backend/web/sass/_adminlte.scss
  6. +2
    -1
      backend/web/sass/screen.scss
  7. +8
    -0
      backend/web/sass/subscription/_index.scss
  8. +2
    -2
      common/components/ActiveRecordCommon.php
  9. +2
    -2
      common/models/Order.php
  10. +4
    -3
      common/models/Subscription.php
  11. +139
    -0
      common/models/SubscriptionSearch.php

+ 13
- 5
backend/controllers/SubscriptionController.php Bestand weergeven

@@ -106,7 +106,7 @@ class SubscriptionController extends BackendController
$this->redirect(['site/index', 'error_products_points_sale' => 1]);
}
$dataProvider = new ActiveDataProvider([
/*$dataProvider = new ActiveDataProvider([
'query' => Subscription::find()
->with(['user', 'producer', 'pointSale', 'productSubscription', 'productSubscription.product'])
->joinWith(['user'])
@@ -115,9 +115,14 @@ class SubscriptionController extends BackendController
'pagination' => [
'pageSize' => 1000,
],
]);
]);*/

$searchModel = new SubscriptionSearch ;
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider
]);
}
@@ -139,7 +144,8 @@ class SubscriptionController extends BackendController
if ($model->load(Yii::$app->request->post()) && $model->validate()
&& $model->save())
{
$this->redirect(['subscription/index']);
Yii::$app->getSession()->setFlash('success', 'Abonnement ajouté');
return $this->redirect(['subscription/index']);
}

return $this->render('create', [
@@ -202,7 +208,8 @@ class SubscriptionController extends BackendController
$model->date_end = null;
}
if ($model->save()) {
$this->redirect(['subscription/index']);
Yii::$app->getSession()->setFlash('success', 'Abonnement modifié');
return $this->redirect(['subscription/index']);
}
}

@@ -221,7 +228,8 @@ class SubscriptionController extends BackendController
{
ProductSubscription::deleteAll(['id_subscription' => $id]);
Subscription::findOne($id)->delete();
$this->redirect(['subscription/index']);
Yii::$app->getSession()->setFlash('success', 'Abonnement supprimé');
return $this->redirect(['subscription/index']);
}

}

+ 65
- 33
backend/views/subscription/index.php Bestand weergeven

@@ -48,10 +48,12 @@ $this->addButton(['label' => '+', 'url' => 'subscription/create', 'class' => 'bt
<div class="subscription-index">
<?= GridView::widget([
'filterModel' => $searchModel,
'dataProvider' => $dataProvider,
'columns' => [
[
'attribute' => 'id_user',
'attribute' => 'username',
'label' => 'Utilisateur',
'format' => 'raw',
'value' => function($model) {
if(strlen($model->username))
@@ -66,21 +68,15 @@ $this->addButton(['label' => '+', 'url' => 'subscription/create', 'class' => 'bt
}
],
[
'attribute' => 'id_point_sale',
'format' => 'raw',
'value' => function($model) {
return Html::encode($model->pointSale->name) ;
}
],
[
'attribute' => 'products',
'attribute' => 'product_name',
'label' => 'Produits',
'format' => 'raw',
'value' => function($model) {
$html = '' ;
foreach($model->productSubscription as $productSubscription)
{
if(isset($productSubscription->product)) {
$html .= $productSubscription->quantity . ' x '.Html::encode($productSubscription->product->name).'<br />' ;
$html .= $productSubscription->quantity . '&nbsp;x&nbsp;'.Html::encode($productSubscription->product->name).'<br />' ;
}
else {
$html .= 'Produit non défini<br />' ;
@@ -97,64 +93,100 @@ $this->addButton(['label' => '+', 'url' => 'subscription/create', 'class' => 'bt
}
],
[
'attribute' => 'date_begin',
'attribute' => 'id_point_sale',
'label' => 'Point de vente',
'format' => 'raw',
'filter' => ArrayHelper::map(PointSale::find()->where(['id_producer' => Producer::getId()])->asArray()->all(), 'id', 'name'),
'value' => function($model) {
return date('d/m/Y',strtotime($model->date_begin)) ;
return Html::encode($model->pointSale->name) ;
}
],
[
'attribute' => 'date_end',
'attribute' => 'date_begin',
'label' => 'Date de début',
'format' => 'raw',
'value' => function($model) {
if($model->date_end)
return date('d/m/Y',strtotime($model->date_end)) ;
else
return 'indéterminée' ;
$html = date('d/m/Y',strtotime($model->date_begin)) ;
return $html ;
}
],
[
'attribute' => 'monday',
'attribute' => 'day',
'label' => 'Jours',
'format' => 'raw',
'filter' => [
'monday' => 'Lundi',
'tuesday' => 'Mardi',
'wednesday' => 'Mercredi',
'thursday' => 'Jeudi',
'friday' => 'Vendredi',
'saterday' => 'Samedi',
'sunday' => 'Dimanche',
],
'contentOptions' => ['class' => 'text-small'],
'value' => function($model) {
$html = '' ;
if($model->monday)
if($model->monday) {
$html .= 'lundi, ' ;
if($model->tuesday)
}
if($model->tuesday) {
$html .= 'mardi, ' ;
if($model->wednesday)
}
if($model->wednesday) {
$html .= 'mercredi, ' ;
if($model->thursday)
}
if($model->thursday) {
$html .= 'jeudi, ' ;
if($model->friday)
}
if($model->friday) {
$html .= 'vendredi, ' ;
if($model->saturday)
}
if($model->saturday) {
$html .= 'samedi, ' ;
if($model->sunday)
}
if($model->sunday) {
$html .= 'dimanche, ' ;
}
if(strlen($html))
if(strlen($html)) {
return substr ($html, 0, strlen($html) - 2) ;
else
}
else {
return '<span class="glyphicon glyphicon-warning-sign"></span> Aucun jour' ;
}
}
],
[
'attribute' => 'week_frequency',
'filter' => [
1 => 'Toutes les semaines',
2 => 'Toutes les 2 semaines',
3 => 'Toutes les 3 semaines',
4 => 'Tous les mois'],
'value' => function($model) {
if($model->week_frequency == 1)
if($model->week_frequency == 1) {
return 'Toutes les semaines' ;
else
}
else {
return 'Toutes les '.$model->week_frequency.' semaines' ;
}
}
],
[
'attribute' => 'auto_payment',
'format' => 'raw',
'label' => 'Paiement automatique',
'headerOptions' => ['class' => 'column-auto-payment'],
'contentOptions' => ['class' => 'column-auto-payment'],
'filter' => [0 => 'Non', 1 => 'Oui'],
'value' => function($model) {
if($model->auto_payment)
if($model->auto_payment) {
return '<span class="label label-success">Oui</span>' ;
else
}
else {
return '<span class="label label-danger">Non</span>' ;
}
}
],
[
@@ -163,12 +195,12 @@ $this->addButton(['label' => '+', 'url' => 'subscription/create', 'class' => 'bt
'headerOptions' => ['class' => 'actions'],
'buttons' => [
'update' => function ($url, $model) {
return Html::a('<span class="glyphicon glyphicon-pencil"></span> Modifier', $url, [
return Html::a('<span class="glyphicon glyphicon-pencil"></span>', $url, [
'title' => Yii::t('app', 'Modifier'), 'class' => 'btn btn-default'
]);
},
'delete' => function ($url, $model) {
return Html::a('<span class="glyphicon glyphicon-trash"></span> Suprimer', $url, [
return Html::a('<span class="glyphicon glyphicon-trash"></span>', $url, [
'title' => Yii::t('app', 'Supprimer'), 'class' => 'btn btn-default'
]);
}

BIN
backend/web/.sass-cache/2a0ffb00578c9d5a537db16d14c734a22b18f35c/screen.scssc Bestand weergeven


+ 21
- 8
backend/web/css/screen.css Bestand weergeven

@@ -1503,41 +1503,49 @@ body.skin-black .content-wrapper .btn-primary, body.skin-black .content-wrapper
body.skin-black .content-wrapper .alert a {
color: white;
}
/* line 125, ../sass/_adminlte.scss */
/* line 124, ../sass/_adminlte.scss */
body.skin-black .content-wrapper .table th {
font-size: 13px;
}
/* line 127, ../sass/_adminlte.scss */
body.skin-black .content-wrapper .table td.text-small, body.skin-black .content-wrapper .table th.text-small {
font-size: 12px;
}
/* line 134, ../sass/_adminlte.scss */
body.skin-black .main-footer a {
color: #BB8757;
}

/* line 131, ../sass/_adminlte.scss */
/* line 140, ../sass/_adminlte.scss */
body.login-page {
background: none;
background-color: #F8F1DD;
}
/* line 135, ../sass/_adminlte.scss */
/* line 144, ../sass/_adminlte.scss */
body.login-page .login-box .login-logo {
text-align: center;
font-family: "comfortaalight";
}
/* line 138, ../sass/_adminlte.scss */
/* line 147, ../sass/_adminlte.scss */
body.login-page .login-box .login-logo img {
width: 50px;
}
/* line 143, ../sass/_adminlte.scss */
/* line 152, ../sass/_adminlte.scss */
body.login-page .login-box .login-box-body .btn-primary {
background-color: #BB8757;
border-color: #BB8757;
padding: 5px 10px;
}
/* line 148, ../sass/_adminlte.scss */
/* line 157, ../sass/_adminlte.scss */
body.login-page .login-box .login-box-body .btn-primary:active {
background-color: #c29469;
border-color: #BB8757;
}
/* line 154, ../sass/_adminlte.scss */
/* line 163, ../sass/_adminlte.scss */
body.login-page .login-box .login-box-body a {
color: #BB8757;
}
/* line 156, ../sass/_adminlte.scss */
/* line 165, ../sass/_adminlte.scss */
body.login-page .login-box .login-box-body a:hover {
color: #c29469;
}
@@ -1563,3 +1571,8 @@ body.login-page .login-box .login-box-body a:hover {
.site-index #distributions .info-box-content .buttons {
margin-top: 10px;
}

/* line 4, ../sass/subscription/_index.scss */
.subscription-index .table .column-auto-payment {
width: 50px;
}

+ 9
- 0
backend/web/sass/_adminlte.scss Bestand weergeven

@@ -119,6 +119,15 @@ body.skin-black {
color: white ;
}
}
.table {
th {
font-size: 13px ;
}
td.text-small, th.text-small {
font-size: 12px ;
}
}
}
.main-footer {

+ 2
- 1
backend/web/sass/screen.scss Bestand weergeven

@@ -1369,4 +1369,5 @@ a {
}

@import "_adminlte.scss" ;
@import "site/_index.scss" ;
@import "site/_index.scss" ;
@import "subscription/_index.scss" ;

+ 8
- 0
backend/web/sass/subscription/_index.scss Bestand weergeven

@@ -0,0 +1,8 @@

.subscription-index {
.table {
.column-auto-payment {
width: 50px ;
}
}
}

+ 2
- 2
common/components/ActiveRecordCommon.php Bestand weergeven

@@ -53,7 +53,7 @@ class ActiveRecordCommon extends \yii\db\ActiveRecord
* @return mixed
* @throws NotFoundHttpException
*/
public static function search($params = [], $options = [])
public static function searchBy($params = [], $options = [])
{
$class = get_called_class() ;
@@ -208,7 +208,7 @@ class ActiveRecordCommon extends \yii\db\ActiveRecord
public static function searchDispatch($params = [], $options = [])
{
$class = get_called_class() ;
return $class::search($params, $options) ;
return $class::searchBy($params, $options) ;
}
}

+ 2
- 2
common/models/Order.php Bestand weergeven

@@ -585,9 +585,9 @@ class Order extends ActiveRecordCommon
* @param integer $limit
* @return array
*/
public static function search($params = [], $options = [])
public static function searchBy($params = [], $options = [])
{
$orders = parent::search($params, $options) ;
$orders = parent::searchBy($params, $options) ;
/*
* Initialisation des commandes

+ 4
- 3
common/models/Subscription.php Bestand weergeven

@@ -152,10 +152,11 @@ class Subscription extends ActiveRecordCommon
*
* @return array
*/
public static function defaultOptionsSearch() {
public static function defaultOptionsSearch()
{
return [
'with' => ['producer', 'pointSale', 'productSubscription'],
'join_with' => ['user'],
'with' => ['producer'],
'join_with' => ['user', 'productSubscription', 'productSubscription.product', 'pointSale'],
'orderby' => 'user.name ASC',
'attribute_id_producer' => 'subscription.id_producer'
] ;

+ 139
- 0
common/models/SubscriptionSearch.php Bestand weergeven

@@ -0,0 +1,139 @@
<?php

/**
Copyright La boîte à pain (2018)

contact@laboiteapain.net

Ce logiciel est un programme informatique servant à aider les producteurs
à distribuer leur production en circuits courts.

Ce logiciel est régi par la licence CeCILL soumise au droit français et
respectant les principes de diffusion des logiciels libres. Vous pouvez
utiliser, modifier et/ou redistribuer ce programme sous les conditions
de la licence CeCILL telle que diffusée par le CEA, le CNRS et l'INRIA
sur le site "http://www.cecill.info".

En contrepartie de l'accessibilité au code source et des droits de copie,
de modification et de redistribution accordés par cette licence, il n'est
offert aux utilisateurs qu'une garantie limitée. Pour les mêmes raisons,
seule une responsabilité restreinte pèse sur l'auteur du programme, le
titulaire des droits patrimoniaux et les concédants successifs.

A cet égard l'attention de l'utilisateur est attirée sur les risques
associés au chargement, à l'utilisation, à la modification et/ou au
développement et à la reproduction du logiciel par l'utilisateur étant
donné sa spécificité de logiciel libre, qui peut le rendre complexe à
manipuler et qui le réserve donc à des développeurs et des professionnels
avertis possédant des connaissances informatiques approfondies. Les
utilisateurs sont donc invités à charger et tester l'adéquation du
logiciel à leurs besoins dans des conditions permettant d'assurer la
sécurité de leurs systèmes et ou de leurs données et, plus généralement,
à l'utiliser et l'exploiter dans les mêmes conditions de sécurité.

Le fait que vous puissiez accéder à cet en-tête signifie que vous avez
pris connaissance de la licence CeCILL, et que vous en avez accepté les
termes.
*/

namespace common\models;

use common\models\Subscription ;

class SubscriptionSearch extends Subscription
{
var $username;
var $product_name;
var $day ;
public function rules()
{
return [
[['id_point_sale', 'week_frequency'], 'integer'],
[['auto_payment'], 'boolean'],
[['date_begin', 'username','product_name', 'day'], 'safe'],
];
}
public function search($params) {
$optionsSearch = self::defaultOptionsSearch() ;
$query = Subscription::find()
->with($optionsSearch['with'])
->innerJoinWith($optionsSearch['join_with'], true)
->where(['subscription.id_producer' => Producer::getId()])
;
$dataProvider = new ActiveDataProvider([
'query' => $query,
'sort' => ['attributes' => ['username']],
'pagination' => [
'pageSize' => 20,
],
]);

$dataProvider->sort->attributes['username'] = [
'asc' => ['user.lastname' => SORT_ASC, 'user.name' => SORT_ASC],
'desc' => ['user.lastname' => SORT_DESC, 'user.name' => SORT_DESC],
];
$dataProvider->sort->attributes['id_point_sale'] = [
'asc' => ['point_sale.name' => SORT_ASC],
'desc' => ['point_sale.name' => SORT_DESC],
];

$dataProvider->sort->attributes['auto_payment'] = [
'asc' => ['subscription.auto_payment' => SORT_ASC],
'desc' => ['subscription.auto_payment' => SORT_DESC],
];
$this->load($params);
if (!$this->validate()) {
return $dataProvider;
}

if(isset($this->id_point_sale) && is_numeric($this->id_point_sale)) {
$query->andWhere([
'subscription.id_point_sale' => $this->id_point_sale
]) ;
}
if(isset($this->auto_payment) && is_numeric($this->auto_payment)) {
$query->andWhere([
'subscription.auto_payment' => $this->auto_payment
]) ;
}
if(isset($this->week_frequency) && is_numeric($this->week_frequency)) {
$query->andWhere([
'subscription.week_frequency' => $this->week_frequency
]) ;
}
if(isset($this->day) && strlen($this->day)) {
$query->andWhere([
'subscription.'.$this->day => 1
]) ;
}
if(strlen($this->date_begin)) {
$date = \DateTime::createFromFormat('d/m/Y', $this->date_begin);
$query->andWhere([
'subscription.date_begin' => date('Y-m-d',$date->format('U'))
]) ;
}
$query->andFilterWhere([
'or',
['like', 'user.lastname', $this->username],
['like', 'user.name', $this->username]
]);
$query->andFilterWhere(['like', 'product.name', $this->product_name]) ;
return $dataProvider;
}
}

Laden…
Annuleren
Opslaan