setTitle('Abonnements') ;
$this->addBreadcrumb($this->getTitle()) ;
$this->addButton(['label' => 'Nouvel abonnement ', 'url' => 'subscription/create', 'class' => 'btn btn-primary']) ;
$subscriptionsArray = Subscription::searchAll() ;
?>
= 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',
'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').')
' ;
}
else {
$html .= 'Produit non défini
' ;
}
}
// aucun produit
if(!count($model->productSubscription))
{
$html .= ' Aucun produit
' ;
}
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) {
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',
'saterday' => '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) {
if($model->week_frequency == 1) {
return 'Toutes les semaines' ;
}
else {
return 'Toutes les '.$model->week_frequency.' semaines' ;
}
}
],
[
'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 'Déduit' ;
}
elseif($model->auto_payment == Subscription::AUTO_PAYMENT_YES) {
return 'Oui' ;
}
else {
return 'Non' ;
}
}
],
[
'class' => 'yii\grid\ActionColumn',
'template' => '{update} {delete}',
'headerOptions' => ['class' => 'column-actions'],
'contentOptions' => ['class' => 'column-actions'],
'buttons' => [
'update' => function ($url, $model) {
return Html::a('', $url, [
'title' => 'Modifier', 'class' => 'btn btn-default'
]);
},
'delete' => function ($url, $model) {
return Html::a('', $url, [
'title' => 'Supprimer', 'class' => 'btn btn-default'
]);
}
],
],
],
]); ?>