浏览代码

Merge branch 'dev'

prodstable
父节点
当前提交
30cf2de717
共有 1 个文件被更改,包括 19 次插入14 次删除
  1. +19
    -14
      backend/controllers/StatsController.php

+ 19
- 14
backend/controllers/StatsController.php 查看文件

@@ -96,22 +96,27 @@ class StatsController extends BackendController
foreach ($period as $date) {
$month = date('m/Y', $date->getTimestamp());
$dataLabels[] = $month;
$data[$month] = 0;
}

// commandes
$ordersArray = Order::searchAll([],[
'conditions' => 'distribution.date > :date',
'params' => [':date' => $dateStart]
]) ;

if($ordersArray) {
foreach ($ordersArray as $order) {
$month = date('m/Y', strtotime($order->distribution->date));
if (isset($data[$month])) {
$data[$month] += $order->amount;
}
$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
")
->bindValue(':id_producer', Producer::getId())
->bindValue(':date_start', date('Y-m-', $date->getTimestamp()).'01')
->bindValue(':date_end', date('Y-m-', $date->getTimestamp()).'31' )
->queryOne();

if($res['total']) {
$data[$month] = $res['total'];
}
else {
$data[$month] = 0;
}

}

// création d'un tableau sans index car chart.js n'accepte pas les index

正在加载...
取消
保存