Browse Source

Merge branch 'dev'

master
Guillaume Bourgeois 5 years ago
parent
commit
30cf2de717
1 changed files with 19 additions and 14 deletions
  1. +19
    -14
      backend/controllers/StatsController.php

+ 19
- 14
backend/controllers/StatsController.php View File

foreach ($period as $date) { foreach ($period as $date) {
$month = date('m/Y', $date->getTimestamp()); $month = date('m/Y', $date->getTimestamp());
$dataLabels[] = $month; $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 // création d'un tableau sans index car chart.js n'accepte pas les index

Loading…
Cancel
Save