|
|
|
|
|
|
|
|
use yii\grid\GridView; |
|
|
use yii\grid\GridView; |
|
|
use common\models\User ; |
|
|
use common\models\User ; |
|
|
use common\models\Producer ; |
|
|
use common\models\Producer ; |
|
|
|
|
|
use common\models\Distribution ; |
|
|
|
|
|
|
|
|
$this->setTitle('Producteurs') ; |
|
|
$this->setTitle('Producteurs') ; |
|
|
$this->addBreadcrumb($this->getTitle()) ; |
|
|
$this->addBreadcrumb($this->getTitle()) ; |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
], |
|
|
], |
|
|
[ |
|
|
[ |
|
|
'attribute' => 'Cours', |
|
|
|
|
|
'label' => 'CA mois en cours', |
|
|
|
|
|
|
|
|
'label' => 'Dons (mois précédent)', |
|
|
'format' => 'raw', |
|
|
'format' => 'raw', |
|
|
'value' => function($model) { |
|
|
'value' => function($model) { |
|
|
$turnover = $model->getTurnover(date('Y-m')) ; |
|
|
|
|
|
return 'CA : '.number_format($turnover,2).' €<br />' ; |
|
|
|
|
|
|
|
|
$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) ; |
|
|
} |
|
|
} |
|
|
], |
|
|
], |
|
|
], |
|
|
], |