Pārlūkot izejas kodu

[backend] Distributions : amélioration report CSV (unités)

Affichage des unités au niveau des produit en haut des colonnes.
Affichage des unités au niveau de chaque commande uniquement si l'unité est différente de l'unité définie au niveau du produit.
dev
Guillaume Bourgeois pirms 5 gadiem
vecāks
revīzija
8a3af6162e
1 mainītis faili ar 61 papildinājumiem un 33 dzēšanām
  1. +61
    -33
      backend/controllers/DistributionController.php

+ 61
- 33
backend/controllers/DistributionController.php Parādīt failu

@@ -458,11 +458,18 @@ class DistributionController extends BackendController
// produits en colonne
$productsNameArray = [''] ;
$productsIndexArray = [] ;
$productsHasQuantity = [] ;
$cpt = 1 ;
foreach ($productsArray as $product) {
$quantity = Order::getProductQuantity($product->id, $ordersArray);
if($quantity) {
$productsNameArray[] = $product->name ;
$productsHasQuantity[$product->id] = 0 ;
foreach(Product::$unitsArray as $unit => $dataUnit) {
$quantity = Order::getProductQuantity($product->id, $ordersArray, true, $unit);
if($quantity) {
$productsHasQuantity[$product->id] += $quantity ;
}
}
if($productsHasQuantity[$product->id] > 0) {
$productsNameArray[] = $product->name .' ('.Product::strUnit($product->unit, 'wording_short', true).')' ;
$productsIndexArray[$product->id] = $cpt ++ ;
}
}
@@ -475,47 +482,42 @@ class DistributionController extends BackendController
$datas[] = ['> '.$pointSale->name] ;
foreach($pointSale->orders as $order) {
$orderLine = [$order->getStrUser()] ;
foreach($productsIndexArray as $idProduct => $indexProduct) {
$orderLine[$indexProduct] = '' ;
}
foreach($order->productOrder as $productOrder) {
$orderLine[$productsIndexArray[$productOrder->id_product]] = $productOrder->quantity . ' '.Product::strUnit($productOrder->unit, 'wording_short', true);
if(strlen($orderLine[$productsIndexArray[$productOrder->id_product]])) {
$orderLine[$productsIndexArray[$productOrder->id_product]] .= ' + ' ;
}
$orderLine[$productsIndexArray[$productOrder->id_product]] .= $productOrder->quantity;
if($productOrder->product->unit != $productOrder->unit) {
$orderLine[$productsIndexArray[$productOrder->id_product]] .= Product::strUnit($productOrder->unit, 'wording_short', true) ;
}
}
$datas[] = $this->_lineOrderReportCSV($orderLine, $cpt) ;
}
// total point de vente
$totalsPointSaleArray = ['Total'] ;
foreach ($productsArray as $product) {
foreach(Product::$unitsArray as $unit => $dataUnit) {
$quantity = Order::getProductQuantity($product->id, $pointSale->orders, false, $unit);
if ($quantity) {
$index = $productsIndexArray[$product->id] ;
if(!isset($totalsPointSaleArray[$index])) {
$totalsPointSaleArray[$index] = '' ;
}
$totalsPointSaleArray[$index] .= $quantity . ' '.Product::strUnit($unit, 'wording_short', true).' ';
}
}
}
$totalsPointSaleArray = $this->_totalReportCSV(
'Total',
$pointSale->orders,
$productsArray,
$productsIndexArray
) ;
$datas[] = $this->_lineOrderReportCSV($totalsPointSaleArray, $cpt) ;
$datas[] = [] ;
}
}
// global
$totalsGlobalArray = ['> Totaux'] ;
foreach ($productsArray as $product) {
foreach(Product::$unitsArray as $unit => $dataUnit) {
$quantity = Order::getProductQuantity($product->id, $ordersArray, false, $unit);
if ($quantity) {
$index = $productsIndexArray[$product->id] ;
if(!isset($totalsGlobalArray[$index])) {
$totalsGlobalArray[$index] = '' ;
}
$totalsGlobalArray[$index] .= $quantity . ' '.Product::strUnit($unit, 'wording_short', true).' ';
}
}
}

// global
$totalsGlobalArray = $this->_totalReportCSV(
'> Totaux',
$ordersArray,
$productsArray,
$productsIndexArray
) ;
$datas[] = $this->_lineOrderReportCSV($totalsGlobalArray, $cpt) ;
CSV::downloadSendHeaders('Commandes_'.$date.'.csv');
@@ -527,6 +529,32 @@ class DistributionController extends BackendController
return null ;
}
public function _totalReportCSV($label, $ordersArray, $productsArray, $productsIndexArray) {
$totalsPointSaleArray = [$label] ;
foreach ($productsArray as $product) {
foreach(Product::$unitsArray as $unit => $dataUnit) {
$quantity = Order::getProductQuantity($product->id, $ordersArray, false, $unit);
if ($quantity) {
$index = $productsIndexArray[$product->id] ;
if(!isset($totalsPointSaleArray[$index])) {
$totalsPointSaleArray[$index] = '' ;
}

if(strlen($totalsPointSaleArray[$index])) {
$totalsPointSaleArray[$index] .= ' + ' ;
}

$totalsPointSaleArray[$index] .= $quantity ;

if($product->unit != $unit) {
$totalsPointSaleArray[$index] .= ''.Product::strUnit($unit, 'wording_short', true) ;
}
}
}
}
return $totalsPointSaleArray ;
}
public function _lineOrderReportCSV($orderLine, $cptMax)
{
$line = [] ;

Notiek ielāde…
Atcelt
Saglabāt