Browse Source

Adaptations backend/stats

dev
Guillaume Bourgeois 6 years ago
parent
commit
85e2bc3706
2 changed files with 33 additions and 24 deletions
  1. +21
    -16
      backend/controllers/StatsController.php
  2. +12
    -8
      backend/views/stats/products.php

+ 21
- 16
backend/controllers/StatsController.php View File

]) ; ]) ;


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,

+ 12
- 8
backend/views/stats/products.php View File

<?php if($month != StatsController::TOTALS): ?> <?php if($month != StatsController::TOTALS): ?>
<!-- max --> <!-- max -->
<?php foreach($productsMonthArray['max'] as $product):
$tooltip = 'data-toggle="tooltip" data-placement="top" data-original-title="'.Html::encode($currentProduct['name']).' / '.$monthArray[$month - 1] .' '. $year.' / Maximum"' ;
<?php
$tooltip = 'data-toggle="tooltip" data-placement="top" data-original-title="'.Html::encode($currentProduct['name']).' / '.$monthArray[$month - 1] .' '. $year.' / Maximum"' ;
foreach($productsMonthArray['max'] as $product):
?> ?>
<?php if($product['name'] == $currentProduct['name']): <?php if($product['name'] == $currentProduct['name']):
$findMax = true ; $findMax = true ;
<?php if(!$findMax): ?><td class="align-center"><div <?= $tooltip; ?>>0</div></td><?php endif; ?> <?php if(!$findMax): ?><td class="align-center"><div <?= $tooltip; ?>>0</div></td><?php endif; ?>


<!-- commandes --> <!-- commandes -->
<?php foreach($productsMonthArray['orders'] as $product):
$tooltip = 'data-toggle="tooltip" data-placement="top" data-original-title="'.Html::encode($currentProduct['name']).' / '. $monthArray[$month - 1] . ' '. $year .' / Commandés"' ;
<?php
$tooltip = 'data-toggle="tooltip" data-placement="top" data-original-title="'.Html::encode($currentProduct['name']).' / '. $monthArray[$month - 1] . ' '. $year .' / Commandés"' ;
foreach($productsMonthArray['orders'] as $product):
?> ?>
<?php if($product['name'] == $currentProduct['name']): <?php if($product['name'] == $currentProduct['name']):
$findOrders = true ; $findOrders = true ;
<?php else: ?> <?php else: ?>
<!-- totaux max --> <!-- totaux max -->
<?php foreach($productsArray[StatsController::TOTALS]['max'] as $productName => $totalMax):
$tooltip = 'data-toggle="tooltip" data-placement="top" data-original-title="'.Html::encode($currentProduct['name']).' / Total '. $year .' / Maximums"' ;
<?php
$tooltip = 'data-toggle="tooltip" data-placement="top" data-original-title="'.Html::encode($currentProduct['name']).' / Total '. $year .' / Maximums"' ;
foreach($dataProducts[StatsController::TOTALS]['max'] as $productName => $totalMax):
?> ?>
<?php if($productName == $currentProduct['name']): ?> <?php if($productName == $currentProduct['name']): ?>
<td class="align-center"> <td class="align-center">
<?php endforeach; ?> <?php endforeach; ?>


<!-- totaux commandés --> <!-- totaux commandés -->
<?php foreach($productsArray[StatsController::TOTALS]['orders'] as $productName => $totalOrders):
$tooltip = 'data-toggle="tooltip" data-placement="top" data-original-title="'.Html::encode($currentProduct['name']).' / Total '. $year .' / Commandés"' ;
<?php
$tooltip = 'data-toggle="tooltip" data-placement="top" data-original-title="'.Html::encode($currentProduct['name']).' / Total '. $year .' / Commandés"' ;
foreach($dataProducts[StatsController::TOTALS]['orders'] as $productName => $totalOrders):
?> ?>
<?php if($productName == $currentProduct['name']): ?> <?php if($productName == $currentProduct['name']): ?>
<td class="align-center"> <td class="align-center">

Loading…
Cancel
Save