Browse Source

Améliorations / adaptations subscription

dev
Guillaume Bourgeois 5 years ago
parent
commit
62a31f5c63
11 changed files with 265 additions and 54 deletions
  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 View File

$this->redirect(['site/index', 'error_products_points_sale' => 1]); $this->redirect(['site/index', 'error_products_points_sale' => 1]);
} }
$dataProvider = new ActiveDataProvider([
/*$dataProvider = new ActiveDataProvider([
'query' => Subscription::find() 'query' => Subscription::find()
->with(['user', 'producer', 'pointSale', 'productSubscription', 'productSubscription.product']) ->with(['user', 'producer', 'pointSale', 'productSubscription', 'productSubscription.product'])
->joinWith(['user']) ->joinWith(['user'])
'pagination' => [ 'pagination' => [
'pageSize' => 1000, 'pageSize' => 1000,
], ],
]);
]);*/


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


return $this->render('create', [ return $this->render('create', [
$model->date_end = null; $model->date_end = null;
} }
if ($model->save()) { if ($model->save()) {
$this->redirect(['subscription/index']);
Yii::$app->getSession()->setFlash('success', 'Abonnement modifié');
return $this->redirect(['subscription/index']);
} }
} }


{ {
ProductSubscription::deleteAll(['id_subscription' => $id]); ProductSubscription::deleteAll(['id_subscription' => $id]);
Subscription::findOne($id)->delete(); 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 View File

<div class="subscription-index"> <div class="subscription-index">
<?= GridView::widget([ <?= GridView::widget([
'filterModel' => $searchModel,
'dataProvider' => $dataProvider, 'dataProvider' => $dataProvider,
'columns' => [ 'columns' => [
[ [
'attribute' => 'id_user',
'attribute' => 'username',
'label' => 'Utilisateur',
'format' => 'raw', 'format' => 'raw',
'value' => function($model) { 'value' => function($model) {
if(strlen($model->username)) if(strlen($model->username))
} }
], ],
[ [
'attribute' => 'id_point_sale',
'format' => 'raw',
'value' => function($model) {
return Html::encode($model->pointSale->name) ;
}
],
[
'attribute' => 'products',
'attribute' => 'product_name',
'label' => 'Produits',
'format' => 'raw', 'format' => 'raw',
'value' => function($model) { 'value' => function($model) {
$html = '' ; $html = '' ;
foreach($model->productSubscription as $productSubscription) foreach($model->productSubscription as $productSubscription)
{ {
if(isset($productSubscription->product)) { 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 { else {
$html .= 'Produit non défini<br />' ; $html .= 'Produit non défini<br />' ;
} }
], ],
[ [
'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) { '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) { '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', 'label' => 'Jours',
'format' => 'raw', 'format' => 'raw',
'filter' => [
'monday' => 'Lundi',
'tuesday' => 'Mardi',
'wednesday' => 'Mercredi',
'thursday' => 'Jeudi',
'friday' => 'Vendredi',
'saterday' => 'Samedi',
'sunday' => 'Dimanche',
],
'contentOptions' => ['class' => 'text-small'],
'value' => function($model) { 'value' => function($model) {
$html = '' ; $html = '' ;
if($model->monday)
if($model->monday) {
$html .= 'lundi, ' ; $html .= 'lundi, ' ;
if($model->tuesday)
}
if($model->tuesday) {
$html .= 'mardi, ' ; $html .= 'mardi, ' ;
if($model->wednesday)
}
if($model->wednesday) {
$html .= 'mercredi, ' ; $html .= 'mercredi, ' ;
if($model->thursday)
}
if($model->thursday) {
$html .= 'jeudi, ' ; $html .= 'jeudi, ' ;
if($model->friday)
}
if($model->friday) {
$html .= 'vendredi, ' ; $html .= 'vendredi, ' ;
if($model->saturday)
}
if($model->saturday) {
$html .= 'samedi, ' ; $html .= 'samedi, ' ;
if($model->sunday)
}
if($model->sunday) {
$html .= 'dimanche, ' ; $html .= 'dimanche, ' ;
}
if(strlen($html))
if(strlen($html)) {
return substr ($html, 0, strlen($html) - 2) ; return substr ($html, 0, strlen($html) - 2) ;
else
}
else {
return '<span class="glyphicon glyphicon-warning-sign"></span> Aucun jour' ; return '<span class="glyphicon glyphicon-warning-sign"></span> Aucun jour' ;
}
} }
], ],
[ [
'attribute' => 'week_frequency', '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) { 'value' => function($model) {
if($model->week_frequency == 1)
if($model->week_frequency == 1) {
return 'Toutes les semaines' ; return 'Toutes les semaines' ;
else
}
else {
return 'Toutes les '.$model->week_frequency.' semaines' ; return 'Toutes les '.$model->week_frequency.' semaines' ;
}
} }
], ],
[ [
'attribute' => 'auto_payment', 'attribute' => 'auto_payment',
'format' => 'raw', 'format' => 'raw',
'label' => 'Paiement automatique',
'headerOptions' => ['class' => 'column-auto-payment'],
'contentOptions' => ['class' => 'column-auto-payment'],
'filter' => [0 => 'Non', 1 => 'Oui'],
'value' => function($model) { 'value' => function($model) {
if($model->auto_payment)
if($model->auto_payment) {
return '<span class="label label-success">Oui</span>' ; return '<span class="label label-success">Oui</span>' ;
else
}
else {
return '<span class="label label-danger">Non</span>' ; return '<span class="label label-danger">Non</span>' ;
}
} }
], ],
[ [
'headerOptions' => ['class' => 'actions'], 'headerOptions' => ['class' => 'actions'],
'buttons' => [ 'buttons' => [
'update' => function ($url, $model) { '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' 'title' => Yii::t('app', 'Modifier'), 'class' => 'btn btn-default'
]); ]);
}, },
'delete' => function ($url, $model) { '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' 'title' => Yii::t('app', 'Supprimer'), 'class' => 'btn btn-default'
]); ]);
} }

BIN
backend/web/.sass-cache/2a0ffb00578c9d5a537db16d14c734a22b18f35c/screen.scssc View File


+ 21
- 8
backend/web/css/screen.css View File

body.skin-black .content-wrapper .alert a { body.skin-black .content-wrapper .alert a {
color: white; 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 { body.skin-black .main-footer a {
color: #BB8757; color: #BB8757;
} }


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

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

+ 9
- 0
backend/web/sass/_adminlte.scss View File

color: white ; color: white ;
} }
} }
.table {
th {
font-size: 13px ;
}
td.text-small, th.text-small {
font-size: 12px ;
}
}
} }
.main-footer { .main-footer {

+ 2
- 1
backend/web/sass/screen.scss View File

} }


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

+ 8
- 0
backend/web/sass/subscription/_index.scss View File


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

+ 2
- 2
common/components/ActiveRecordCommon.php View File

* @return mixed * @return mixed
* @throws NotFoundHttpException * @throws NotFoundHttpException
*/ */
public static function search($params = [], $options = [])
public static function searchBy($params = [], $options = [])
{ {
$class = get_called_class() ; $class = get_called_class() ;
public static function searchDispatch($params = [], $options = []) public static function searchDispatch($params = [], $options = [])
{ {
$class = get_called_class() ; $class = get_called_class() ;
return $class::search($params, $options) ;
return $class::searchBy($params, $options) ;
} }
} }

+ 2
- 2
common/models/Order.php View File

* @param integer $limit * @param integer $limit
* @return array * @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 * Initialisation des commandes

+ 4
- 3
common/models/Subscription.php View File

* *
* @return array * @return array
*/ */
public static function defaultOptionsSearch() {
public static function defaultOptionsSearch()
{
return [ return [
'with' => ['producer', 'pointSale', 'productSubscription'],
'join_with' => ['user'],
'with' => ['producer'],
'join_with' => ['user', 'productSubscription', 'productSubscription.product', 'pointSale'],
'orderby' => 'user.name ASC', 'orderby' => 'user.name ASC',
'attribute_id_producer' => 'subscription.id_producer' 'attribute_id_producer' => 'subscription.id_producer'
] ; ] ;

+ 139
- 0
common/models/SubscriptionSearch.php View File

<?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;
}
}

Loading…
Cancel
Save