|
|
|
|
|
|
|
|
'format' => 'raw', |
|
|
'format' => 'raw', |
|
|
'value' => function($model) { |
|
|
'value' => function($model) { |
|
|
$productGift = Product::getProductGift() ; |
|
|
$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) ; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$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']) ; |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
], |
|
|
], |
|
|
], |
|
|
], |