Browse Source

Merge branch 'dev'

master
Guillaume Bourgeois 5 years ago
parent
commit
92103cee9b
1 changed files with 61 additions and 33 deletions
  1. +61
    -33
      backend/controllers/DistributionController.php

+ 61
- 33
backend/controllers/DistributionController.php View File

// produits en colonne // produits en colonne
$productsNameArray = [''] ; $productsNameArray = [''] ;
$productsIndexArray = [] ; $productsIndexArray = [] ;
$productsHasQuantity = [] ;
$cpt = 1 ; $cpt = 1 ;
foreach ($productsArray as $product) { 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 ++ ; $productsIndexArray[$product->id] = $cpt ++ ;
} }
} }
$datas[] = ['> '.$pointSale->name] ; $datas[] = ['> '.$pointSale->name] ;
foreach($pointSale->orders as $order) { foreach($pointSale->orders as $order) {
$orderLine = [$order->getStrUser()] ; $orderLine = [$order->getStrUser()] ;
foreach($productsIndexArray as $idProduct => $indexProduct) {
$orderLine[$indexProduct] = '' ;
}
foreach($order->productOrder as $productOrder) { 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) ; $datas[] = $this->_lineOrderReportCSV($orderLine, $cpt) ;
} }
// total point de vente // 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[] = $this->_lineOrderReportCSV($totalsPointSaleArray, $cpt) ;
$datas[] = [] ; $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) ; $datas[] = $this->_lineOrderReportCSV($totalsGlobalArray, $cpt) ;
CSV::downloadSendHeaders('Commandes_'.$date.'.csv'); CSV::downloadSendHeaders('Commandes_'.$date.'.csv');
return null ; 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) public function _lineOrderReportCSV($orderLine, $cptMax)
{ {
$line = [] ; $line = [] ;

Loading…
Cancel
Save