Explorar el Código

[producer] Vente au kilo : adaptation liste produits

refactoring
Guillaume Bourgeois hace 5 años
padre
commit
0efb98661b
Se han modificado 6 ficheros con 20 adiciones y 36 borrados
  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 Ver fichero

@@ -464,7 +464,7 @@ class DistributionController extends BackendController
foreach($pointSale->orders as $order) {
$orderLine = [$order->getStrUser()] ;
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) ;
}
@@ -479,7 +479,7 @@ class DistributionController extends BackendController
if(!isset($totalsPointSaleArray[$index])) {
$totalsPointSaleArray[$index] = '' ;
}
$totalsPointSaleArray[$index] .= $quantity . ' '.Product::strUnit($unit, true, true).' ';
$totalsPointSaleArray[$index] .= $quantity . ' '.Product::strUnit($unit, 'short', true).' ';
}
}
}
@@ -499,7 +499,7 @@ class DistributionController extends BackendController
if(!isset($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 Ver fichero

@@ -92,7 +92,7 @@ foreach ($pointsSaleArray as $pointSale) {
$add = false;
foreach ($order->productOrder as $productOrder) {
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;
}
}
@@ -137,7 +137,7 @@ foreach ($pointsSaleArray as $pointSale) {
foreach(Product::$unitsArray as $unit => $dataUnit) {
$quantity = Order::getProductQuantity($product->id, $pointSale->orders, false, $unit);
if ($quantity) {
$strProducts .= $product->name . ' (' .$quantity . ' '.Product::strUnit($unit, true, true).'), ';
$strProducts .= $product->name . ' (' .$quantity . ' '.Product::strUnit($unit, 'short', true).'), ';
}
}
}
@@ -176,7 +176,7 @@ foreach ($pointsSaleArray as $pointSale)
foreach(Product::$unitsArray as $unit => $dataUnit) {
$quantity = Order::getProductQuantity($product->id, $pointSale->orders, false, $unit);
if ($quantity) {
$html .= $product->name . ' (' .$quantity . ' '.Product::strUnit($unit, true, true).'), ';
$html .= $product->name . ' (' .$quantity . ' '.Product::strUnit($unit, 'short', true).'), ';
}
}
}
@@ -195,7 +195,7 @@ foreach ($productsArray as $product) {
foreach(Product::$unitsArray as $unit => $dataUnit) {
$quantity = Order::getProductQuantity($product->id, $ordersArray, false, $unit);
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 Ver fichero

@@ -39,6 +39,7 @@ termes.
use yii\helpers\Html;
use yii\grid\GridView;
use common\helpers\Url ;
use common\models\Product ;

$this->setTitle('Produits') ;
$this->addBreadcrumb($this->getTitle()) ;
@@ -81,19 +82,7 @@ $this->addButton(['label' => 'Nouveau produit <span class="glyphicon glyphicon-p
'value' => function($model) {
$return = '' ;
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 ;

+ 1
- 1
common/models/Order.php Ver fichero

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

+ 9
- 14
common/models/Product.php Ver fichero

@@ -61,11 +61,11 @@ class Product extends ActiveRecordCommon
var $apply_distributions = false ;
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],
];
/**
@@ -235,11 +235,11 @@ class Product extends ActiveRecordCommon
/**
* 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)
* @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 = '' ;
@@ -252,13 +252,8 @@ class Product extends ActiveRecordCommon
}
}
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 ;

+ 1
- 1
producer/views/site/index.php Ver fichero

@@ -125,7 +125,7 @@ $this->setPageTitle(Html::encode($producer->type.' à '.$producer->city)) ;
'attribute' => 'price',
'value' => function($model) {
if($model->price) {
return Price::format($model->price) ;
return Price::format($model->price).' ('.Product::strUnit($model->unit, 'wording_unit', true).')' ;
}
return '' ;
}

Cargando…
Cancelar
Guardar