Bladeren bron

Adaptations backend/stats

dev
Guillaume Bourgeois 6 jaren geleden
bovenliggende
commit
85e2bc3706
2 gewijzigde bestanden met toevoegingen van 33 en 24 verwijderingen
  1. +21
    -16
      backend/controllers/StatsController.php
  2. +12
    -8
      backend/views/stats/products.php

+ 21
- 16
backend/controllers/StatsController.php Bestand weergeven

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

+ 12
- 8
backend/views/stats/products.php Bestand weergeven

@@ -82,8 +82,9 @@ $this->params['breadcrumbs'][] = 'Statistiques produits';
<?php if($month != StatsController::TOTALS): ?>
<!-- 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']):
$findMax = true ;
@@ -96,8 +97,9 @@ $this->params['breadcrumbs'][] = 'Statistiques produits';
<?php if(!$findMax): ?><td class="align-center"><div <?= $tooltip; ?>>0</div></td><?php endif; ?>

<!-- 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']):
$findOrders = true ;
@@ -112,8 +114,9 @@ $this->params['breadcrumbs'][] = 'Statistiques produits';
<?php else: ?>
<!-- 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']): ?>
<td class="align-center">
@@ -123,8 +126,9 @@ $this->params['breadcrumbs'][] = 'Statistiques produits';
<?php endforeach; ?>

<!-- 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']): ?>
<td class="align-center">

Laden…
Annuleren
Opslaan