浏览代码

[backend] Vente au kilo : adaptation export PDF

refactoring
父节点
当前提交
a3e20e3687
共有 3 个文件被更改,包括 60 次插入24 次删除
  1. +19
    -15
      backend/views/distribution/report.php
  2. +4
    -3
      common/models/Order.php
  3. +37
    -6
      common/models/Product.php

+ 19
- 15
backend/views/distribution/report.php 查看文件

@@ -37,6 +37,7 @@ termes.
*/

use common\models\Order ;
use common\models\Product ;

$dayWeek = date('w', strtotime($date));
$dayWeekArray = [0 => 'sunday', 1 => 'monday', 2 => 'tuesday', 3 => 'wednesday', 4 => 'thursday', 5 => 'friday', 6 => 'saturday'];
@@ -91,7 +92,7 @@ foreach ($pointsSaleArray as $pointSale) {
$add = false;
foreach ($order->productOrder as $productOrder) {
if ($product->id == $productOrder->id_product) {
$strProducts .= $productOrder->quantity . ' ' . $product->name . ', ';
$strProducts .= $product->name . ' (' .$productOrder->quantity . ' '.Product::strUnit($productOrder->unit, true, true).'), ';
$add = true;
}
}
@@ -133,11 +134,11 @@ foreach ($pointsSaleArray as $pointSale) {
$strProducts = '';
foreach ($productsArray as $product) {
$quantity = Order::getProductQuantity($product->id, $pointSale->orders);
$strQuantity = '';
if ($quantity) {
$strQuantity = $quantity;
$strProducts .= $strQuantity .' '. $product->name . ', ';
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).'), ';
}
}
}
@@ -170,14 +171,14 @@ foreach ($pointsSaleArray as $pointSale)
if (count($pointSale->orders))
{
$html .= '<tr><td>'.$pointSale->name.'</td><td>' ;
foreach ($productsArray as $product) {
$quantity = Order::getProductQuantity($product->id, $pointSale->orders);
$strQuantity = ($quantity) ? $quantity : '' ;
if(strlen($strQuantity)) {
$html .= $strQuantity . '&nbsp;'.$product->name.', ' ;
foreach(Product::$unitsArray as $unit => $dataUnit) {
$quantity = Order::getProductQuantity($product->id, $pointSale->orders, false, $unit);
if ($quantity) {
$html .= $product->name . ' (' .$quantity . '&nbsp;'.Product::strUnit($unit, true, true).'), ';
}
}
}
$html = substr($html, 0, strlen($html) - 2) ;
@@ -189,10 +190,13 @@ foreach ($pointsSaleArray as $pointSale)

// total
$html .= '<tr><td><strong>Total</strong></td><td>' ;

foreach ($productsArray as $product) {
$quantity = Order::getProductQuantity($product->id, $ordersArray);
if($quantity) {
$html .= $quantity . '&nbsp;'.$product->name.', ' ;
foreach(Product::$unitsArray as $unit => $dataUnit) {
$quantity = Order::getProductQuantity($product->id, $ordersArray, false, $unit);
if ($quantity) {
$html .= $product->name . ' (' .$quantity . '&nbsp;'.Product::strUnit($unit, true, true).'), ';
}
}
}


+ 4
- 3
common/models/Order.php 查看文件

@@ -598,15 +598,16 @@ class Order extends ActiveRecordCommon
*
* @return integer
*/
public static function getProductQuantity($idProduct, $orders, $ignoreCancel = false)
{
public static function getProductQuantity($idProduct, $orders, $ignoreCancel = false, $unit = null)
{
$quantity = 0;
if (isset($orders) && is_array($orders) && count($orders)) {
foreach ($orders as $c) {
if(is_null($c->date_delete) || $ignoreCancel) {
foreach ($c->productOrder as $po) {
if ($po->id_product == $idProduct && $po->product->unit == $po->unit) {
if ($po->id_product == $idProduct &&
((is_null($unit) && $po->product->unit == $po->unit) || (!is_null($unit) && strlen($unit) && $po->unit == $unit))) {
$quantity += $po->quantity ;
}
}

+ 37
- 6
common/models/Product.php 查看文件

@@ -61,11 +61,11 @@ class Product extends ActiveRecordCommon
var $apply_distributions = false ;
public static $unitsArray = [
'piece' => ['unit' => 'piece', 'wording' => 'pièce', 'coefficient' => 1],
'g' => ['unit' => 'g', 'wording' => 'g', 'coefficient' => 1000],
'kg' => ['unit' => 'kg', 'wording' => 'kg', 'coefficient' => 1],
'mL' => ['unit' => 'mL', 'wording' => 'mL', 'coefficient' => 1000],
'L' => ['unit' => 'L', 'wording' => 'L', 'coefficient' => 1],
'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],
];
/**
@@ -231,5 +231,36 @@ class Product extends ActiveRecordCommon
return $productGift ;
}

/**
* Retourne le libellé d'une unité.
*
* @param $short Unité raccourcie
* @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)
{
$strUnit = '' ;
if($unitInDb) {
if($unit == 'g') {
$unit = 'kg' ;
}
if($unit == 'mL') {
$unit = 'L' ;
}
}
if(isset(self::$unitsArray[$unit])) {
if($short) {
$strUnit = self::$unitsArray[$unit]['short'] ;
}
else {
$strUnit = self::$unitsArray[$unit]['wording'] ;
}
}
return $strUnit ;
}
}

正在加载...
取消
保存