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).' '; | |||||
} | } | ||||
} | } | ||||
} | } |
$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).'), '; | |||||
} | } | ||||
} | } | ||||
} | } |
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 ; |
$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 />'; | ||||
} | } |
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 ; |
'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 '' ; | ||||
} | } |