|
|
|
|
|
|
|
|
]) ; |
|
|
]) ; |
|
|
|
|
|
|
|
|
foreach ($ordersArray as $order) { |
|
|
foreach ($ordersArray as $order) { |
|
|
$month = date('m/Y', strtotime($c->distribution->date)); |
|
|
|
|
|
|
|
|
$month = date('m/Y', strtotime($order->distribution->date)); |
|
|
if (isset($data[$month])) { |
|
|
if (isset($data[$month])) { |
|
|
$data[$month] += $c->amount; |
|
|
|
|
|
|
|
|
$data[$month] += $order->amount; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$dataProducts = [] ; |
|
|
$dataProducts = [] ; |
|
|
|
|
|
|
|
|
$dataProducts[self::TOTAUX] = ['max' => [], 'orders' => []] ; |
|
|
|
|
|
|
|
|
$dataProducts[self::TOTALS] = ['max' => [], 'orders' => []] ; |
|
|
foreach($productsArray as $product) { |
|
|
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 ; |
|
|
$empty = true ; |
|
|
|
|
|
|
|
|
// Maximums |
|
|
// Maximums |
|
|
$resMaximums = Yii::$app->db->createCommand("SELECT product.name, SUM(IF(product_distribution.active, product_distribution.quantity_max,0)) AS total |
|
|
$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 |
|
|
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_begin |
|
|
AND distribution.date <= :date_end |
|
|
AND distribution.date <= :date_end |
|
|
AND distribution.id = product_distribution.id_distribution |
|
|
AND distribution.id = product_distribution.id_distribution |
|
|
|
|
|
|
|
|
if(count($resMaximums)) $empty = false ; |
|
|
if(count($resMaximums)) $empty = false ; |
|
|
|
|
|
|
|
|
foreach($resMaximums as $productMax) { |
|
|
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'] ; |
|
|
$dataProducts[self::TOTALS]['max'][$productMax['name']] += $productMax['total'] ; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// Commandés |
|
|
// 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_begin |
|
|
AND distribution.date <= :date_end |
|
|
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 |
|
|
AND product_order.id_product = product.id |
|
|
GROUP BY 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_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')) |
|
|
->bindValue(':date_end', date($year.'-'.str_pad($i, 2, 0, STR_PAD_LEFT).'-31')) |
|
|
->queryAll(); |
|
|
->queryAll(); |
|
|
|
|
|
|
|
|
if(count($resOrders)) $empty = false ; |
|
|
if(count($resOrders)) $empty = false ; |
|
|
|
|
|
|
|
|
foreach($resOrders as $productOrder) { |
|
|
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'] ; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$monthArray = ['Janvier','Février','Mars','Avril','Mai','Juin','Juillet','Août','Septembre','Octobre','Novembre','Décembre','Totaux'] ; |
|
|
$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, |
|
|
'year' => $year, |
|
|
'monthArray' => $monthArray, |
|
|
'monthArray' => $monthArray, |
|
|
'productsArray' => $productsArray, |
|
|
'productsArray' => $productsArray, |