Explorar el Código

Merge branch 'dev'

master
Guillaume Bourgeois hace 5 años
padre
commit
30cf2de717
Se han modificado 1 ficheros con 19 adiciones y 14 borrados
  1. +19
    -14
      backend/controllers/StatsController.php

+ 19
- 14
backend/controllers/StatsController.php Ver fichero

@@ -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

Cargando…
Cancelar
Guardar