|
|
@@ -106,9 +106,9 @@ class StatsController extends BackendController |
|
|
|
]) ; |
|
|
|
|
|
|
|
foreach ($ordersArray as $order) { |
|
|
|
$month = date('m/Y', strtotime($c->distribution->date)); |
|
|
|
$month = date('m/Y', strtotime($order->distribution->date)); |
|
|
|
if (isset($data[$month])) { |
|
|
|
$data[$month] += $c->amount; |
|
|
|
$data[$month] += $order->amount; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@@ -141,10 +141,10 @@ class StatsController extends BackendController |
|
|
|
|
|
|
|
$dataProducts = [] ; |
|
|
|
|
|
|
|
$dataProducts[self::TOTAUX] = ['max' => [], 'orders' => []] ; |
|
|
|
$dataProducts[self::TOTALS] = ['max' => [], 'orders' => []] ; |
|
|
|
foreach($productsArray as $product) { |
|
|
|
$dataProducts[self::TOTALS]['max'][$p['name']] = 0 ; |
|
|
|
$dataProducts[self::TOTALS]['orders'][$p['name']] = 0 ; |
|
|
|
$dataProducts[self::TOTALS]['max'][$product['name']] = 0 ; |
|
|
|
$dataProducts[self::TOTALS]['orders'][$product['name']] = 0 ; |
|
|
|
} |
|
|
|
|
|
|
|
$empty = true ; |
|
|
@@ -152,7 +152,7 @@ class StatsController extends BackendController |
|
|
|
// Maximums |
|
|
|
$resMaximums = Yii::$app->db->createCommand("SELECT product.name, SUM(IF(product_distribution.active, product_distribution.quantity_max,0)) AS total |
|
|
|
FROM distribution, product_distribution, product |
|
|
|
WHERE distribution.id_producer = ".Yii::$app->user->identity->id_etablissement." |
|
|
|
WHERE distribution.id_producer = ".Producer::getId()." |
|
|
|
AND distribution.date >= :date_begin |
|
|
|
AND distribution.date <= :date_end |
|
|
|
AND distribution.id = product_distribution.id_distribution |
|
|
@@ -167,21 +167,24 @@ class StatsController extends BackendController |
|
|
|
if(count($resMaximums)) $empty = false ; |
|
|
|
|
|
|
|
foreach($resMaximums as $productMax) { |
|
|
|
if(!isset($dataProducts[self::TOTALS]['max'][$productMax['name']])) $dataProducts[self::TOTALS]['max'][$productMax['name']] = 0 ; |
|
|
|
if(!isset($dataProducts[self::TOTALS]['max'][$productMax['name']])) { |
|
|
|
$dataProducts[self::TOTALS]['max'][$productMax['name']] = 0 ; |
|
|
|
} |
|
|
|
$dataProducts[self::TOTALS]['max'][$productMax['name']] += $productMax['total'] ; |
|
|
|
} |
|
|
|
|
|
|
|
// Commandés |
|
|
|
$resOrders = Yii::$app->db->createCommand("SELECT product.name, SUM(product_order.quantity) AS total |
|
|
|
FROM distribution, order, product_order, product |
|
|
|
WHERE distribution.id_producer = ".Producer::getId()." |
|
|
|
$resOrders = Yii::$app->db->createCommand(' |
|
|
|
SELECT product.name, SUM(product_order.quantity) AS total |
|
|
|
FROM `distribution`, `order`, `product_order`, `product` |
|
|
|
WHERE distribution.id_producer = '.Producer::getId().' |
|
|
|
AND distribution.date >= :date_begin |
|
|
|
AND distribution.date <= :date_end |
|
|
|
AND distribution.id = order.id_distribution |
|
|
|
AND order.id = product_order.id_order |
|
|
|
AND distribution.id = `order`.id_distribution |
|
|
|
AND `order`.id = product_order.id_order |
|
|
|
AND product_order.id_product = product.id |
|
|
|
GROUP BY product.id |
|
|
|
ORDER BY product.name") |
|
|
|
ORDER BY product.name') |
|
|
|
->bindValue(':date_begin', date($year.'-'.str_pad($i, 2, 0, STR_PAD_LEFT).'-01')) |
|
|
|
->bindValue(':date_end', date($year.'-'.str_pad($i, 2, 0, STR_PAD_LEFT).'-31')) |
|
|
|
->queryAll(); |
|
|
@@ -190,8 +193,10 @@ class StatsController extends BackendController |
|
|
|
if(count($resOrders)) $empty = false ; |
|
|
|
|
|
|
|
foreach($resOrders as $productOrder) { |
|
|
|
if(!isset($dataProducts[self::TOTAUX]['orders'][$productOrder['name']])) $dataProducts[self::TOTAUX]['order'][$productOrder['name']] = 0 ; |
|
|
|
$dataProducts[self::TOTAUX]['orders'][$productOrder['name']] += $productOrder['total'] ; |
|
|
|
if(!isset($dataProducts[self::TOTALS]['orders'][$productOrder['name']])) { |
|
|
|
$dataProducts[self::TOTALS]['orders'][$productOrder['name']] = 0 ; |
|
|
|
} |
|
|
|
$dataProducts[self::TOTALS]['orders'][$productOrder['name']] += $productOrder['total'] ; |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
@@ -200,7 +205,7 @@ class StatsController extends BackendController |
|
|
|
|
|
|
|
$monthArray = ['Janvier','Février','Mars','Avril','Mai','Juin','Juillet','Août','Septembre','Octobre','Novembre','Décembre','Totaux'] ; |
|
|
|
|
|
|
|
return $this->render('produits', [ |
|
|
|
return $this->render('products', [ |
|
|
|
'year' => $year, |
|
|
|
'monthArray' => $monthArray, |
|
|
|
'productsArray' => $productsArray, |