setTitle('Producteurs') ; $this->addBreadcrumb($this->getTitle()) ; $this->addButton(['label' => '+', 'url' => 'producer-admin/create', 'class' => 'btn btn-primary']) ; ?> $dataProviderProducer, 'columns' => [ 'name', [ 'attribute' => 'date_creation', 'format' => 'raw', 'value' => function($model) { return date('d/m/Y', strtotime($model->date_creation)) ; } ], [ 'attribute' => 'Lieu', 'format' => 'raw', 'value' => function($model) { return Html::encode($model->city.' ('.$model->postcode.')') ; } ], [ 'attribute' => 'Utilisateurs', 'format' => 'raw', 'value' => function($model) { if(!$model->userProducer || !count($model->userProducer)) { return 'Aucun utilisateur' ; } else { $users = count($model->userProducer).' client' ; if(count($model->userProducer) > 1) { $users .= 's' ; } return $users ; } } ], [ 'attribute' => 'Contact', 'format' => 'raw', 'value' => function($model) { if(!isset($model->user) || (isset($model->user) && count($model->user) == 0)) { return 'Aucun contact' ; } else { foreach($model->user as $u) { if($u->status == User::STATUS_PRODUCER) { return Html::encode($u->lastname.' '.$u->name) .'
'.Html::encode($u->email) .'
'.Html::encode($u->phone) ; } } } } ], [ 'attribute' => 'active', 'format' => 'raw', 'value' => function($model) { $html = '' ; if($model->active) { $html .= 'En ligne' ; } else { $html .= 'Hors-ligne' ; } if(strlen($model->code)) { $html .= ' ' ; } return $html ; } ], [ 'attribute' => 'Prix libre', 'label' => 'Prix libre', 'format' => 'raw', 'value' => function($model) { if(is_null($model->free_price)) { return '' ; } else { return $model->getFreePrice() ; } } ], [ 'label' => 'Dons (mois précédent)', 'format' => 'raw', 'value' => function($model) { $productGift = Product::getProductGift() ; $distributionsArray = Distribution::find() ->where(['>=', 'distribution.date', date('Y-m-01', strtotime("-1 month"))]) ->andWhere(['<=', 'distribution.date', date('Y-m-31', strtotime("-1 month"))]) ->andWhere(['distribution.id_producer' => $model->id]) ->with(['order','order.productOrder']) ->all() ; $gifts = 0 ; foreach($distributionsArray as $distribution) { foreach($distribution->order as $order) { foreach($order->productOrder as $productOrder) { if($productOrder->id_product == $productGift->id) { $gifts += $productOrder->quantity * $productGift->price ; } } } } return Price::format($gifts) ; } ], ], ]); ?>