setTitle('Producteurs') ;
$this->addBreadcrumb($this->getTitle()) ;
$this->addButton(['label' => 'Nouveau producteur ', 'url' => 'producer-admin/create', 'class' => 'btn btn-primary']) ;
?>
Abonnements mensuels : = $sumFreePrice ?> € HT
= GridView::widget([
'dataProvider' => $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() ;
$res = Yii::$app->db->createCommand("SELECT SUM(product_order.price * product_order.quantity) AS total
FROM `order`, product_order, distribution
WHERE distribution.id_producer = :id_producer
AND `order`.id_distribution = distribution.id
AND `order`.id = product_order.id_order
AND distribution.date >= :date_start
AND distribution.date <= :date_end
AND product_order.id_product = :id_product_gift
")
->bindValue(':id_producer', $model->id)
->bindValue(':date_start', date('Y-m-01', strtotime("-1 month")))
->bindValue(':date_end', date('Y-m-31', strtotime("-1 month")))
->bindValue(':id_product_gift', $productGift->id)
->queryOne();
return Price::format($res['total']) ;
}
],
],
]); ?>