Browse Source

[producer] Vente au kilo : adaptation liste produits

dev
Guillaume Bourgeois 5 years ago
parent
commit
0efb98661b
6 changed files with 20 additions and 36 deletions
  1. +3
    -3
      backend/controllers/DistributionController.php
  2. +4
    -4
      backend/views/distribution/report.php
  3. +2
    -13
      backend/views/product/index.php
  4. +1
    -1
      common/models/Order.php
  5. +9
    -14
      common/models/Product.php
  6. +1
    -1
      producer/views/site/index.php

+ 3
- 3
backend/controllers/DistributionController.php View File

foreach($pointSale->orders as $order) { foreach($pointSale->orders as $order) {
$orderLine = [$order->getStrUser()] ; $orderLine = [$order->getStrUser()] ;
foreach($order->productOrder as $productOrder) { foreach($order->productOrder as $productOrder) {
$orderLine[$productsIndexArray[$productOrder->id_product]] = $productOrder->quantity . ' '.Product::strUnit($productOrder->unit, true, true);
$orderLine[$productsIndexArray[$productOrder->id_product]] = $productOrder->quantity . ' '.Product::strUnit($productOrder->unit, 'short', true);
} }
$datas[] = $this->_lineOrderReportCSV($orderLine, $cpt) ; $datas[] = $this->_lineOrderReportCSV($orderLine, $cpt) ;
} }
if(!isset($totalsPointSaleArray[$index])) { if(!isset($totalsPointSaleArray[$index])) {
$totalsPointSaleArray[$index] = '' ; $totalsPointSaleArray[$index] = '' ;
} }
$totalsPointSaleArray[$index] .= $quantity . ' '.Product::strUnit($unit, true, true).' ';
$totalsPointSaleArray[$index] .= $quantity . ' '.Product::strUnit($unit, 'short', true).' ';
} }
} }
} }
if(!isset($totalsGlobalArray[$index])) { if(!isset($totalsGlobalArray[$index])) {
$totalsGlobalArray[$index] = '' ; $totalsGlobalArray[$index] = '' ;
} }
$totalsGlobalArray[$index] .= $quantity . ' '.Product::strUnit($unit, true, true).' ';
$totalsGlobalArray[$index] .= $quantity . ' '.Product::strUnit($unit, 'short', true).' ';
} }
} }
} }

+ 4
- 4
backend/views/distribution/report.php View File

$add = false; $add = false;
foreach ($order->productOrder as $productOrder) { foreach ($order->productOrder as $productOrder) {
if ($product->id == $productOrder->id_product) { if ($product->id == $productOrder->id_product) {
$strProducts .= $product->name . ' (' .$productOrder->quantity . ' '.Product::strUnit($productOrder->unit, true, true).'), ';
$strProducts .= $product->name . ' (' .$productOrder->quantity . ' '.Product::strUnit($productOrder->unit, 'short', true).'), ';
$add = true; $add = true;
} }
} }
foreach(Product::$unitsArray as $unit => $dataUnit) { foreach(Product::$unitsArray as $unit => $dataUnit) {
$quantity = Order::getProductQuantity($product->id, $pointSale->orders, false, $unit); $quantity = Order::getProductQuantity($product->id, $pointSale->orders, false, $unit);
if ($quantity) { if ($quantity) {
$strProducts .= $product->name . ' (' .$quantity . ' '.Product::strUnit($unit, true, true).'), ';
$strProducts .= $product->name . ' (' .$quantity . ' '.Product::strUnit($unit, 'short', true).'), ';
} }
} }
} }
foreach(Product::$unitsArray as $unit => $dataUnit) { foreach(Product::$unitsArray as $unit => $dataUnit) {
$quantity = Order::getProductQuantity($product->id, $pointSale->orders, false, $unit); $quantity = Order::getProductQuantity($product->id, $pointSale->orders, false, $unit);
if ($quantity) { if ($quantity) {
$html .= $product->name . ' (' .$quantity . ' '.Product::strUnit($unit, true, true).'), ';
$html .= $product->name . ' (' .$quantity . ' '.Product::strUnit($unit, 'short', true).'), ';
} }
} }
} }
foreach(Product::$unitsArray as $unit => $dataUnit) { foreach(Product::$unitsArray as $unit => $dataUnit) {
$quantity = Order::getProductQuantity($product->id, $ordersArray, false, $unit); $quantity = Order::getProductQuantity($product->id, $ordersArray, false, $unit);
if ($quantity) { if ($quantity) {
$html .= $product->name . ' (' .$quantity . ' '.Product::strUnit($unit, true, true).'), ';
$html .= $product->name . ' (' .$quantity . ' '.Product::strUnit($unit, 'short', true).'), ';
} }
} }
} }

+ 2
- 13
backend/views/product/index.php View File

use yii\helpers\Html; use yii\helpers\Html;
use yii\grid\GridView; use yii\grid\GridView;
use common\helpers\Url ; use common\helpers\Url ;
use common\models\Product ;


$this->setTitle('Produits') ; $this->setTitle('Produits') ;
$this->addBreadcrumb($this->getTitle()) ; $this->addBreadcrumb($this->getTitle()) ;
'value' => function($model) { 'value' => function($model) {
$return = '' ; $return = '' ;
if($model->price) { if($model->price) {
$return = Price::format($model->price).' (' ;
if($model->unit == 'piece') {
$return .= 'la pièce' ;
}
elseif(in_array($model->unit, ['g','kg'])) {
$return .= 'le kg' ;
}
elseif(in_array($model->unit, ['mL','L'])) {
$return .= 'le litre' ;
}
$return .= ')' ;
$return = Price::format($model->price).' ('.Product::strUnit($model->unit, 'wording_unit', true).')' ;
} }
return $return ; return $return ;

+ 1
- 1
common/models/Order.php View File

$i = 0; $i = 0;
foreach ($this->productOrder as $p) { foreach ($this->productOrder as $p) {
if (isset($p->product)) { if (isset($p->product)) {
$html .= Html::encode($p->product->name) .' ('. $p->quantity .' '.Product::strUnit($p->unit, true, true).')';
$html .= Html::encode($p->product->name) .' ('. $p->quantity .' '.Product::strUnit($p->unit, 'short', true).')';
if (++$i != $count) { if (++$i != $count) {
$html .= '<br />'; $html .= '<br />';
} }

+ 9
- 14
common/models/Product.php View File

var $apply_distributions = false ; var $apply_distributions = false ;
public static $unitsArray = [ public static $unitsArray = [
'piece' => ['unit' => 'piece', 'wording' => 'pièce(s)', 'short' => 'p.', 'coefficient' => 1],
'g' => ['unit' => 'g', 'wording' => 'g', 'short' => 'g','coefficient' => 1000],
'kg' => ['unit' => 'kg', 'wording' => 'kg', 'short' => 'kg', 'coefficient' => 1],
'mL' => ['unit' => 'mL', 'wording' => 'mL', 'short' => 'mL', 'coefficient' => 1000],
'L' => ['unit' => 'L', 'wording' => 'L', 'short' => 'L', 'coefficient' => 1],
'piece' => ['wording_unit' => 'la pièce', 'wording' => 'pièce(s)', 'short' => 'p.', 'coefficient' => 1],
'g' => ['wording_unit' => 'le g', 'wording' => 'g', 'short' => 'g','coefficient' => 1000],
'kg' => ['wording_unit' => 'le kg', 'wording' => 'kg', 'short' => 'kg', 'coefficient' => 1],
'mL' => ['wording_unit' => 'le mL', 'wording' => 'mL', 'short' => 'mL', 'coefficient' => 1000],
'L' => ['wording_unit' => 'le litre', 'wording' => 'L', 'short' => 'L', 'coefficient' => 1],
]; ];
/** /**
/** /**
* Retourne le libellé d'une unité. * Retourne le libellé d'une unité.
* *
* @param $short Unité raccourcie
* @param $format wording_unit, wording, short
* @param $unitInDb Unité stockée en base de données (ex: si g > kg, si mL > L) * @param $unitInDb Unité stockée en base de données (ex: si g > kg, si mL > L)
* @return $string Libellé de l'unité * @return $string Libellé de l'unité
*/ */
public static function strUnit($unit, $short = true, $unitInDb = false)
public static function strUnit($unit, $format = 'short', $unitInDb = false)
{ {
$strUnit = '' ; $strUnit = '' ;
} }
} }
if(isset(self::$unitsArray[$unit])) {
if($short) {
$strUnit = self::$unitsArray[$unit]['short'] ;
}
else {
$strUnit = self::$unitsArray[$unit]['wording'] ;
}
if(isset(self::$unitsArray[$unit]) && isset(self::$unitsArray[$unit][$format])) {
$strUnit = self::$unitsArray[$unit][$format] ;
} }
return $strUnit ; return $strUnit ;

+ 1
- 1
producer/views/site/index.php View File

'attribute' => 'price', 'attribute' => 'price',
'value' => function($model) { 'value' => function($model) {
if($model->price) { if($model->price) {
return Price::format($model->price) ;
return Price::format($model->price).' ('.Product::strUnit($model->unit, 'wording_unit', true).')' ;
} }
return '' ; return '' ;
} }

Loading…
Cancel
Save