Parcourir la source

Gestion partielle du mode de vente (poids ou unité)

Le but de l'opération est d'éliminer le bug du calcul des montants des commandes qui fait exploser les stats dans le cas d'une vente au poids considéré comme une vente à l'unité.
prodstable
keun il y a 7 ans
Parent
révision
d717cdcf57
3 fichiers modifiés avec 30 ajouts et 11 suppressions
  1. +3
    -0
      backend/controllers/StatsController.php
  2. +8
    -11
      common/models/Commande.php
  3. +19
    -0
      console/migrations/m170426_143226_add_champs_mode_vente_commandeProduit.php

+ 3
- 0
backend/controllers/StatsController.php Voir le fichier

@@ -70,6 +70,9 @@ class StatsController extends BackendController {
$mois = date('m/Y',strtotime($c->production->date)) ;
if(isset($data_pain[$mois]))
{
if($mois == '06/2016') {
//print_r($c) ;
}
$data_pain[$mois] += $c->montant_pain ;
}
}

+ 8
- 11
common/models/Commande.php Voir le fichier

@@ -50,17 +50,14 @@ class Commande extends \yii\db\ActiveRecord
{
foreach($this->commandeProduits as $p)
{
if(isset($p->produit) && $p->produit->vrac)
{
$this->montant_vrac += $p->prix * $p->quantite/1000 ;
$this->poids_vrac += $p->quantite/1000 ;
}
else {
$this->montant_pain += $p->prix * $p->quantite ;
if(isset($p->produit))
$this->poids_pain += $p->quantite * $p->produit->poids/1000 ;
}
if($p->mode_vente == 'unite')
{
$this->montant_pain += $p->prix * $p->quantite ;
}
elseif($p->mode_vente == 'poids')
{
$this->montant_pain += $p->prix * $p->quantite/1000 ;
}
}
$this->montant = $this->montant_vrac + $this->montant_pain ;

+ 19
- 0
console/migrations/m170426_143226_add_champs_mode_vente_commandeProduit.php Voir le fichier

@@ -0,0 +1,19 @@
<?php

use yii\db\Migration;
use yii\db\Schema ;

class m170426_143226_add_champs_mode_vente_commandeProduit extends Migration
{
public function up()
{
$this->addColumn('produit', 'mode_vente', Schema::TYPE_STRING.' DEFAULT \'unite\'') ;
$this->addColumn('commande_produit', 'mode_vente', Schema::TYPE_STRING.' DEFAULT \'unite\'') ;
}

public function down()
{
$this->dropColumn('produit', 'mode_vente') ;
$this->dropColumn('commande_produit', 'mode_vente') ;
}
}

Chargement…
Annuler
Enregistrer