|
|
@@ -529,10 +529,12 @@ class DistributionController extends BackendController |
|
|
|
|
|
|
|
// return the pdf output as per the destination setting |
|
|
|
return $pdf->render(); |
|
|
|
} elseif ($type == 'csv') { |
|
|
|
} |
|
|
|
elseif ($type == 'csv') { |
|
|
|
$datas = []; |
|
|
|
|
|
|
|
$optionCsvExportAllProducts = Producer::getConfig('option_csv_export_all_products') ; |
|
|
|
$optionCsvExportByPiece = Producer::getConfig('option_csv_export_by_piece') ; |
|
|
|
|
|
|
|
// produits en colonne |
|
|
|
$productsNameArray = ['']; |
|
|
@@ -548,7 +550,18 @@ class DistributionController extends BackendController |
|
|
|
} |
|
|
|
} |
|
|
|
if ($productsHasQuantity[$product->id] > 0 || $optionCsvExportAllProducts) { |
|
|
|
$productsNameArray[] = $product->name . ' (' . Product::strUnit($product->unit, 'wording_short', true) . ')'; |
|
|
|
$productName = $product->name ; |
|
|
|
|
|
|
|
if($optionCsvExportByPiece) { |
|
|
|
$productUnit = 'piece' ; |
|
|
|
} |
|
|
|
else { |
|
|
|
$productUnit .= $product->unit ; |
|
|
|
} |
|
|
|
|
|
|
|
$productName .= ' (' . Product::strUnit($productUnit, 'wording_short', true) . ')'; |
|
|
|
|
|
|
|
$productsNameArray[] = $productName ; |
|
|
|
$productsIndexArray[$product->id] = $cpt++; |
|
|
|
} |
|
|
|
} |
|
|
@@ -562,60 +575,73 @@ class DistributionController extends BackendController |
|
|
|
foreach ($pointSale->orders as $order) { |
|
|
|
$orderLine = [$order->getStrUser()]; |
|
|
|
|
|
|
|
foreach ($productsIndexArray as $idProduct => $indexProduct) { |
|
|
|
$orderLine[$indexProduct] = ''; |
|
|
|
if($optionCsvExportByPiece) { |
|
|
|
foreach ($order->productOrder as $productOrder) { |
|
|
|
$orderLine[$productsIndexArray[$productOrder->id_product]] = Order::getProductQuantityPieces($productOrder->id_product, [$order]) ; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
foreach ($order->productOrder as $productOrder) { |
|
|
|
if (strlen($orderLine[$productsIndexArray[$productOrder->id_product]])) { |
|
|
|
$orderLine[$productsIndexArray[$productOrder->id_product]] .= ' + '; |
|
|
|
else { |
|
|
|
foreach ($productsIndexArray as $idProduct => $indexProduct) { |
|
|
|
$orderLine[$indexProduct] = ''; |
|
|
|
} |
|
|
|
$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); |
|
|
|
|
|
|
|
foreach ($order->productOrder as $productOrder) { |
|
|
|
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 = $this->_totalReportCSV( |
|
|
|
' Total (unité)', |
|
|
|
$pointSale->orders, |
|
|
|
$productsArray, |
|
|
|
$productsIndexArray |
|
|
|
); |
|
|
|
$datas[] = $this->_lineOrderReportCSV($totalsPointSaleArray, $cpt); |
|
|
|
if($optionCsvExportByPiece) { |
|
|
|
$totalsPointSaleArray = $this->_totalReportPiecesCSV( |
|
|
|
'Total', |
|
|
|
$pointSale->orders, |
|
|
|
$productsArray, |
|
|
|
$productsIndexArray |
|
|
|
); |
|
|
|
} |
|
|
|
else { |
|
|
|
$totalsPointSaleArray = $this->_totalReportCSV( |
|
|
|
'Total', |
|
|
|
$pointSale->orders, |
|
|
|
$productsArray, |
|
|
|
$productsIndexArray |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
$totalsGlobalPiecesArray = $this->_totalReportPiecesCSV( |
|
|
|
' Total (pièces)', |
|
|
|
$pointSale->orders, |
|
|
|
$productsArray, |
|
|
|
$productsIndexArray |
|
|
|
); |
|
|
|
$datas[] = $this->_lineOrderReportCSV($totalsGlobalPiecesArray, $cpt); |
|
|
|
$datas[] = $this->_lineOrderReportCSV($totalsPointSaleArray, $cpt); |
|
|
|
|
|
|
|
$datas[] = []; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// global |
|
|
|
$totalsGlobalArray = $this->_totalReportCSV( |
|
|
|
'> Totaux (unité)', |
|
|
|
$ordersArray, |
|
|
|
$productsArray, |
|
|
|
$productsIndexArray |
|
|
|
); |
|
|
|
$datas[] = $this->_lineOrderReportCSV($totalsGlobalArray, $cpt); |
|
|
|
if($optionCsvExportByPiece) { |
|
|
|
$totalsGlobalArray = $this->_totalReportPiecesCSV( |
|
|
|
'> Totaux', |
|
|
|
$ordersArray, |
|
|
|
$productsArray, |
|
|
|
$productsIndexArray |
|
|
|
); |
|
|
|
} |
|
|
|
else { |
|
|
|
$totalsGlobalArray = $this->_totalReportCSV( |
|
|
|
'> Totaux', |
|
|
|
$ordersArray, |
|
|
|
$productsArray, |
|
|
|
$productsIndexArray |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
// global (pièces) |
|
|
|
$totalsGlobalPiecesArray = $this->_totalReportPiecesCSV( |
|
|
|
'> Totaux (pièces)', |
|
|
|
$ordersArray, |
|
|
|
$productsArray, |
|
|
|
$productsIndexArray |
|
|
|
); |
|
|
|
$datas[] = $this->_lineOrderReportCSV($totalsGlobalPiecesArray, $cpt); |
|
|
|
$datas[] = $this->_lineOrderReportCSV($totalsGlobalArray, $cpt); |
|
|
|
|
|
|
|
CSV::downloadSendHeaders('Commandes_' . $date . '.csv'); |
|
|
|
echo CSV::array2csv($datas); |