Browse Source

Backend : Montant des dons du mois précédent pour chaque producteur

refactoring
Guillaume Bourgeois 5 years ago
parent
commit
952ab8c26f
1 changed files with 22 additions and 4 deletions
  1. +22
    -4
      backend/views/producer-admin/index.php

+ 22
- 4
backend/views/producer-admin/index.php View File

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) ;
} }
], ],
], ],

Loading…
Cancel
Save