Parcourir la source

Intégration des totaux

refactoring
keun il y a 6 ans
Parent
révision
18b06c22ae
2 fichiers modifiés avec 85 ajouts et 32 suppressions
  1. +28
    -6
      backend/controllers/StatsController.php
  2. +57
    -26
      backend/views/stats/produits.php

+ 28
- 6
backend/controllers/StatsController.php Voir le fichier

@@ -85,11 +85,26 @@ class StatsController extends BackendController {
]);
}
const TOTAUX = 13 ;
public function actionProduits($year = 0) {
if(!$year) $year = date('Y') ;
$produits = Produit::find()
->where('(vrac IS NULL OR vrac = 0)')
->andWhere(['id_etablissement' => Yii::$app->user->identity->id_etablissement])
->orderBy('order ASC')
->all() ;
$arr_produits = [] ;
$arr_produits[self::TOTAUX] = ['max' => [], 'commandes' => []] ;
foreach($produits as $p) {
$arr_produits[self::TOTAUX]['max'][$p['nom']] = 0 ;
$arr_produits[self::TOTAUX]['commandes'][$p['nom']] = 0 ;
}
$empty = true ;
for($i = 1; $i <= 12; $i++) {
@@ -110,6 +125,11 @@ class StatsController extends BackendController {
$arr_produits[$i]['max'] = $res_maximums ;
if(count($res_maximums)) $empty = false ;
foreach($res_maximums as $produit_max) {
if(!isset($arr_produits[self::TOTAUX]['max'][$produit_max['nom']])) $arr_produits[self::TOTAUX]['max'][$produit_max['nom']] = 0 ;
$arr_produits[self::TOTAUX]['max'][$produit_max['nom']] += $produit_max['total'] ;
}

// Commandés
$res_commandes = Yii::$app->db->createCommand("SELECT produit.nom, SUM(commande_produit.quantite) AS total
FROM production, commande, commande_produit, produit
@@ -127,15 +147,17 @@ class StatsController extends BackendController {
$arr_produits[$i]['commandes'] = $res_commandes ;
if(count($res_commandes)) $empty = false ;
foreach($res_commandes as $produit_commandes) {
if(!isset($arr_produits[self::TOTAUX]['commandes'][$produit_commandes['nom']])) $arr_produits[self::TOTAUX]['commandes'][$produit_commandes['nom']] = 0 ;
$arr_produits[self::TOTAUX]['commandes'][$produit_commandes['nom']] += $produit_commandes['total'] ;
}
}
$produits = Produit::find()
->where('(vrac IS NULL OR vrac = 0)')
->andWhere(['id_etablissement' => Yii::$app->user->identity->id_etablissement])
->orderBy('order ASC')
->all() ;
ksort($arr_produits) ;
$arr_mois = ['Janvier','Février','Mars','Avril','Mai','Juin','Juillet','Août','Septembre','Octobre','Novembre','Décembre'] ;
$arr_mois = ['Janvier','Février','Mars','Avril','Mai','Juin','Juillet','Août','Septembre','Octobre','Novembre','Décembre','Totaux'] ;
return $this->render('produits', [
'year' => $year,

+ 57
- 26
backend/views/stats/produits.php Voir le fichier

@@ -1,5 +1,7 @@
<?php

use \backend\controllers\StatsController ;

$this->title = 'Statistiques produits' ;
$this->params['breadcrumbs'][] = 'Statistiques produits';

@@ -27,7 +29,7 @@ $this->params['breadcrumbs'][] = 'Statistiques produits';
</tr>
<tr class="sub-head">
<th></th>
<?php for($i=1; $i<=12; $i++): ?>
<?php for($i=1; $i<=13; $i++): ?>
<th>Maximum</th>
<th>Commandés</th>
<?php endfor; ?>
@@ -41,36 +43,65 @@ $this->params['breadcrumbs'][] = 'Statistiques produits';
$find_max = false ;
$find_commandes = false ;
?>
<!-- max -->
<?php foreach($arr_produit_mois['max'] as $produit):
$tooltip = 'data-toggle="tooltip" data-placement="top" data-original-title="'.Html::encode($produit_current['nom']).' / '.$arr_mois[$mois - 1] .' '. $year.' / Maximum"' ;
?>
<?php if($produit['nom'] == $produit_current['nom']):
$find_max = true ;
<?php if($mois != StatsController::TOTAUX): ?>
<!-- max -->
<?php foreach($arr_produit_mois['max'] as $produit):
$tooltip = 'data-toggle="tooltip" data-placement="top" data-original-title="'.Html::encode($produit_current['nom']).' / '.$arr_mois[$mois - 1] .' '. $year.' / Maximum"' ;
?>
<?php if($produit['nom'] == $produit_current['nom']):
$find_max = true ;
?>
<td class="align-center">
<div <?= $tooltip; ?>><?= $produit['total'] ?></div>
</td>
<?php endif; ?>
<?php endforeach; ?>
<?php if(!$find_max): ?><td class="align-center"><div <?= $tooltip; ?>>0</div></td><?php endif; ?>

<!-- commandes -->
<?php foreach($arr_produit_mois['commandes'] as $produit):
$tooltip = 'data-toggle="tooltip" data-placement="top" data-original-title="'.Html::encode($produit_current['nom']).' / '. $arr_mois[$mois - 1] . ' '. $year .' / Commandés"' ;
?>
<td class="align-center">
<div <?= $tooltip; ?>><?= $produit['total'] ?></div>
</td>
<?php endif; ?>
<?php endforeach; ?>
<?php if(!$find_max): ?><td class="align-center"><div <?= $tooltip; ?>>0</div></td><?php endif; ?>
<!-- commandes -->
<?php foreach($arr_produit_mois['commandes'] as $produit):
$tooltip = 'data-toggle="tooltip" data-placement="top" data-original-title="'.Html::encode($produit_current['nom']).' / '. $arr_mois[$mois - 1] . ' '. $year .' / Commandés"' ;
?>
<?php if($produit['nom'] == $produit_current['nom']):
$find_commandes = true ;
<?php if($produit['nom'] == $produit_current['nom']):
$find_commandes = true ;
?>
<td class="align-center">
<div <?= $tooltip ?> ><?= $produit['total'] ?></div>
</td>
<?php endif; ?>
<?php endforeach; ?>
<?php if(!$find_commandes): ?><td class="align-center"><div <?= $tooltip ?> >0</div></td><?php endif; ?>

<?php else: ?>
<!-- totaux max -->
<?php foreach($arr_produits[StatsController::TOTAUX]['max'] as $nom_produit => $total_max):
$tooltip = 'data-toggle="tooltip" data-placement="top" data-original-title="'.Html::encode($produit_current['nom']).' / Total '. $year .' / Maximums"' ;
?>
<?php if($nom_produit == $produit_current['nom']): ?>
<td class="align-center">
<div <?= $tooltip ?> ><?= $total_max ?></div>
</td>
<?php endif; ?>
<?php endforeach; ?>

<!-- totaux commandés -->
<?php foreach($arr_produits[StatsController::TOTAUX]['commandes'] as $nom_produit => $total_commandes):
$tooltip = 'data-toggle="tooltip" data-placement="top" data-original-title="'.Html::encode($produit_current['nom']).' / Total '. $year .' / Commandés"' ;
?>
<td class="align-center">
<div <?= $tooltip ?> ><?= $produit['total'] ?></div>
</td>
<?php endif; ?>
<?php endforeach; ?>
<?php if(!$find_commandes): ?><td class="align-center"><div <?= $tooltip ?> >0</div></td><?php endif; ?>
<?php if($nom_produit == $produit_current['nom']): ?>
<td class="align-center">
<div <?= $tooltip ?> ><?= $total_commandes ?></div>
</td>
<?php endif; ?>
<?php endforeach; ?>
<?php endif; ?>
<?php endforeach; ?>
</tr>
<?php endforeach; ?>
</tbody>
</table>

Chargement…
Annuler
Enregistrer