|
- <?php
-
-
-
- use common\helpers\GlobalParam;
- use domain\_\StatusInterface;
- use domain\PointSale\PointSale\PointSale;
- use domain\Product\Product\Product;
- use domain\Product\Product\ProductModule;
- use domain\Subscription\Subscription\Subscription;
- use domain\Subscription\Subscription\SubscriptionModule;
- use domain\User\User\UserModule;
- use yii\grid\GridView;
- use yii\helpers\ArrayHelper;
- use yii\helpers\Html;
-
- $subscriptionModule = SubscriptionModule::getInstance();
- $userModule = UserModule::getInstance();
-
- $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) use ($userModule) {
- if(strlen($model->username))
- {
- return Html::encode($model->username) ;
- }
- else {
- if(isset($model->user)) {
- return Html::encode($userModule->getSolver()->getUsername($model->user)) ;
- }
- }
- }
- ],
- [
- 'attribute' => 'product_name',
- 'label' => 'Produits',
- 'format' => 'raw',
- 'headerOptions' => ['class' => 'column-hide-on-mobile'],
- 'filterOptions' => ['class' => 'column-hide-on-mobile'],
- 'contentOptions' => ['class' => 'column-hide-on-mobile'],
- 'value' => function($model) {
- $productModule = ProductModule::getInstance();
- $html = '' ;
- foreach($model->productSubscription as $productSubscription)
- {
- if(isset($productSubscription->product)) {
- $html .= Html::encode($productSubscription->product->name).' ('.($productSubscription->quantity * Product::$unitsArray[$productSubscription->product->unit]['coefficient']).' '. $productModule->getSolver()->strUnit($productSubscription->product, '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(), 'status' => StatusInterface::STATUS_ONLINE])->orderBy('is_bread_box ASC, name ASC')->asArray()->all(), 'id', 'name'),
- 'value' => function($model) {
- if($model->pointSale) {
- return Html::encode($model->pointSale->name) ;
- }
- return '';
- }
- ],
- [
- 'attribute' => 'date_begin',
- 'label' => 'Période',
- 'format' => 'raw',
- 'headerOptions' => ['class' => 'column-hide-on-mobile'],
- 'filterOptions' => ['class' => 'column-hide-on-mobile'],
- 'contentOptions' => ['class' => 'column-hide-on-mobile'],
- 'value' => function($model) use ($subscriptionModule) {
- return $subscriptionModule->getPeriodAsHtml($model);
- }
- ],
- [
- 'attribute' => 'day',
- 'label' => 'Jours',
- 'format' => 'raw',
- 'filter' => [
- 'monday' => 'Lundi',
- 'tuesday' => 'Mardi',
- 'wednesday' => 'Mercredi',
- 'thursday' => 'Jeudi',
- 'friday' => 'Vendredi',
- 'saturday' => 'Samedi',
- 'sunday' => 'Dimanche',
- ],
- 'headerOptions' => ['class' => 'column-hide-on-mobile'],
- 'filterOptions' => ['class' => 'column-hide-on-mobile'],
- 'contentOptions' => ['class' => 'text-small column-hide-on-mobile'],
- 'value' => function($model) use ($subscriptionModule) {
- return $subscriptionModule->getDaysAsHtml($model);
- }
- ],
- [
- 'attribute' => 'week_frequency',
- 'filter' => [
- 1 => 'Toutes les semaines',
- 2 => 'Toutes les 2 semaines',
- 3 => 'Toutes les 3 semaines',
- 4 => 'Tous les mois'
- ],
- 'headerOptions' => ['class' => 'column-hide-on-mobile'],
- 'filterOptions' => ['class' => 'column-hide-on-mobile'],
- 'contentOptions' => ['class' => 'column-hide-on-mobile'],
- 'value' => function($model) use ($subscriptionModule) {
- return $subscriptionModule->getSolver()->getWeekFrequencyAsString($model);
- }
- ],
- [
- 'attribute' => 'auto_payment',
- 'format' => 'raw',
- 'label' => 'Débit automatique',
- 'headerOptions' => ['class' => 'column-auto-payment column-hide-on-mobile'],
- 'filterOptions' => ['class' => 'column-hide-on-mobile'],
- 'contentOptions' => ['class' => 'column-auto-payment column-hide-on-mobile'],
- 'filter' => [0 => 'Non', 1 => 'Oui'],
- 'value' => function($model) {
- if($model->auto_payment == Subscription::AUTO_PAYMENT_DEDUCTED) {
- return '<span class="label label-success">Déduit</span>' ;
- }
- elseif($model->auto_payment == Subscription::AUTO_PAYMENT_YES) {
- 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' => 'Modifier', 'class' => 'btn btn-default'
- ]);
- },
- 'delete' => function ($url, $model) {
- return Html::a('<span class="glyphicon glyphicon-trash"></span>', $url, [
- 'title' => 'Supprimer', 'class' => 'btn btn-default'
- ]);
- }
- ],
- ],
- ],
- ]); ?>
- </div>
|