Browse Source

[backend] Vente au kilo : adaptation export PDF

dev
Guillaume Bourgeois 5 years ago
parent
commit
a3e20e3687
3 changed files with 60 additions and 24 deletions
  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 View File

*/ */


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


$dayWeek = date('w', strtotime($date)); $dayWeek = date('w', strtotime($date));
$dayWeekArray = [0 => 'sunday', 1 => 'monday', 2 => 'tuesday', 3 => 'wednesday', 4 => 'thursday', 5 => 'friday', 6 => 'saturday']; $dayWeekArray = [0 => 'sunday', 1 => 'monday', 2 => 'tuesday', 3 => 'wednesday', 4 => 'thursday', 5 => 'friday', 6 => 'saturday'];
$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 .= $productOrder->quantity . ' ' . $product->name . ', ';
$strProducts .= $product->name . ' (' .$productOrder->quantity . ' '.Product::strUnit($productOrder->unit, true, true).'), ';
$add = true; $add = true;
} }
} }
$strProducts = ''; $strProducts = '';
foreach ($productsArray as $product) { 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).'), ';
}
} }
} }
if (count($pointSale->orders)) if (count($pointSale->orders))
{ {
$html .= '<tr><td>'.$pointSale->name.'</td><td>' ; $html .= '<tr><td>'.$pointSale->name.'</td><td>' ;
foreach ($productsArray as $product) { 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) ; $html = substr($html, 0, strlen($html) - 2) ;


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

foreach ($productsArray as $product) { 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 View File

* *
* @return integer * @return integer
*/ */
public static function getProductQuantity($idProduct, $orders, $ignoreCancel = false)
{
public static function getProductQuantity($idProduct, $orders, $ignoreCancel = false, $unit = null)
{
$quantity = 0; $quantity = 0;
if (isset($orders) && is_array($orders) && count($orders)) { if (isset($orders) && is_array($orders) && count($orders)) {
foreach ($orders as $c) { foreach ($orders as $c) {
if(is_null($c->date_delete) || $ignoreCancel) { if(is_null($c->date_delete) || $ignoreCancel) {
foreach ($c->productOrder as $po) { 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 ; $quantity += $po->quantity ;
} }
} }

+ 37
- 6
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', '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],
]; ];
/** /**
return $productGift ; 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 ;
}
} }

Loading…
Cancel
Save