|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233 |
- <?php
-
-
-
- use yii\helpers\Html;
- use yii\grid\GridView;
- use common\models\Product ;
- use common\helpers\GlobalParam ;
-
-
- $this->setTitle('Abonnements') ;
- $this->addBreadcrumb($this->getTitle()) ;
- $this->addButton(['label' => 'Nouvel abonnement <span class="glyphicon glyphicon-plus"></span>', 'url' => 'subscription/create', 'class' => 'btn btn-primary']) ;
-
- $subscriptionsArray = Subscription::searchAll() ;
-
-
-
- ?>
- <div class="subscription-index">
-
- <?= GridView::widget([
- 'filterModel' => $searchModel,
- 'dataProvider' => $dataProvider,
- 'columns' => [
- [
- 'attribute' => 'username',
- 'label' => 'Utilisateur',
- 'format' => 'raw',
- 'value' => function($model) {
- if(strlen($model->username))
- {
- return Html::encode($model->username) ;
- }
- else {
- if(isset($model->user)) {
- return Html::encode($model->user->lastname.' '.$model->user->name) ;
- }
- }
- }
- ],
- [
- 'attribute' => 'product_name',
- 'label' => 'Produits',
- 'format' => 'raw',
- 'value' => function($model) {
- $html = '' ;
- foreach($model->productSubscription as $productSubscription)
- {
- if(isset($productSubscription->product)) {
- $html .= Html::encode($productSubscription->product->name).' ('.($productSubscription->quantity * Product::$unitsArray[$productSubscription->product->unit]['coefficient']).' '.Product::strUnit($productSubscription->product->unit, 'wording_short').')<br />' ;
- }
- else {
- $html .= 'Produit non défini<br />' ;
- }
- }
-
-
- if(!count($model->productSubscription))
- {
- $html .= '<span class="glyphicon glyphicon-warning-sign"></span> Aucun produit<br />' ;
- }
-
- return $html ;
- }
- ],
- [
- 'attribute' => 'id_point_sale',
- 'label' => 'Point de vente',
- 'format' => 'raw',
- 'filter' => ArrayHelper::map(PointSale::find()->where(['id_producer' => GlobalParam::getCurrentProducerId()])->asArray()->all(), 'id', 'name'),
- 'value' => function($model) {
- return Html::encode($model->pointSale->name) ;
- }
- ],
- [
- 'attribute' => 'date_begin',
- 'label' => 'Période',
- 'format' => 'raw',
- 'value' => function($model) {
- $html = '<small>' ;
- if($model->date_end) {
- $html .= 'Du ' ;
- }
- else {
- $html .= 'À partir du ' ;
- }
- $html .= '</small>' ;
- $html .= date('d/m/Y',strtotime($model->date_begin)) ;
- if($model->date_end) {
- $html .= '<br />au '.date('d/m/Y',strtotime($model->date_end)) ;
- if(date('Y-m-d') > $model->date_end) {
- $html .= ' <span class="label label-danger">Terminé</span>' ;
- }
- }
-
- return $html ;
- }
- ],
- [
- '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) {
- $html .= 'lundi, ' ;
- }
- if($model->tuesday) {
- $html .= 'mardi, ' ;
- }
- if($model->wednesday) {
- $html .= 'mercredi, ' ;
- }
- if($model->thursday) {
- $html .= 'jeudi, ' ;
- }
- if($model->friday) {
- $html .= 'vendredi, ' ;
- }
- if($model->saturday) {
- $html .= 'samedi, ' ;
- }
- if($model->sunday) {
- $html .= 'dimanche, ' ;
- }
-
- if(strlen($html)) {
- return substr ($html, 0, strlen($html) - 2) ;
- }
- 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) {
- return 'Toutes les semaines' ;
- }
- 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) {
- return '<span class="label label-success">Oui</span>' ;
- }
- else {
- return '<span class="label label-danger">Non</span>' ;
- }
- }
- ],
- [
- 'class' => 'yii\grid\ActionColumn',
- 'template' => '{update} {delete}',
- 'headerOptions' => ['class' => 'column-actions'],
- 'contentOptions' => ['class' => 'column-actions'],
- 'buttons' => [
- 'update' => function ($url, $model) {
- 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>', $url, [
- 'title' => Yii::t('app', 'Supprimer'), 'class' => 'btn btn-default'
- ]);
- }
- ],
- ],
- ],
- ]); ?>
- </div>
|