Browse Source

[backend] Export CSV : ajout d'une ligne total en nombre de pièces

refactoring
Guillaume 4 years ago
parent
commit
a58155b097
3 changed files with 58 additions and 8 deletions
  1. +48
    -2
      backend/controllers/DistributionController.php
  2. +3
    -1
      backend/controllers/OrderController.php
  3. +7
    -5
      backend/web/js/backend.js

+ 48
- 2
backend/controllers/DistributionController.php View File

@@ -580,25 +580,43 @@ class DistributionController extends BackendController

// total point de vente
$totalsPointSaleArray = $this->_totalReportCSV(
'Total',
' Total (unité)',
$pointSale->orders,
$productsArray,
$productsIndexArray
);
$datas[] = $this->_lineOrderReportCSV($totalsPointSaleArray, $cpt);

$totalsGlobalPiecesArray = $this->_totalReportPiecesCSV(
' Total (pièces)',
$ordersArray,
$productsArray,
$productsIndexArray
);
$datas[] = $this->_lineOrderReportCSV($totalsGlobalPiecesArray, $cpt);

$datas[] = [];
}
}

// global
$totalsGlobalArray = $this->_totalReportCSV(
'> Totaux',
'> Totaux (unité)',
$ordersArray,
$productsArray,
$productsIndexArray
);
$datas[] = $this->_lineOrderReportCSV($totalsGlobalArray, $cpt);

// global (pièces)
$totalsGlobalPiecesArray = $this->_totalReportPiecesCSV(
'> Totaux (pièces)',
$ordersArray,
$productsArray,
$productsIndexArray
);
$datas[] = $this->_lineOrderReportCSV($totalsGlobalPiecesArray, $cpt);

CSV::downloadSendHeaders('Commandes_' . $date . '.csv');
echo CSV::array2csv($datas);
die();
@@ -765,6 +783,34 @@ class DistributionController extends BackendController
return $totalsPointSaleArray;
}

public function _totalReportPiecesCSV($label, $ordersArray, $productsArray, $productsIndexArray)
{
$totalsPointSaleArray = [$label];

foreach ($productsArray as $product) {
$quantity = 0 ;
foreach (Product::$unitsArray as $unit => $dataUnit) {
$quantityProduct = Order::getProductQuantity($product->id, $ordersArray, false, $unit);

if($unit == 'piece') {
$quantity += $quantityProduct ;
}
else {
if($product->weight > 0) {
$quantity += ($quantityProduct * $dataUnit['coefficient']) / $product->weight ;
}
}
}

if($quantity) {
$index = $productsIndexArray[$product->id];
$totalsPointSaleArray[$index] = $quantity;
}
}

return $totalsPointSaleArray;
}

public function _lineOrderReportCSV($orderLine, $cptMax, $showTotal = false)
{
$line = [];

+ 3
- 1
backend/controllers/OrderController.php View File

@@ -880,7 +880,9 @@ class OrderController extends BackendController
$order->processCredit();
}

$order->setTillerSynchronization() ;
if($order) {
$order->setTillerSynchronization() ;
}

// lien utilisateur / point de vente
if ($idUser && $pointSale) {

+ 7
- 5
backend/web/js/backend.js View File

@@ -87,9 +87,11 @@ function opendistrib_products_event_price_with_tax() {
if(typeof taxRateSelected == 'undefined') {
taxRateSelected = 0 ;
}
$('#product-price-with-tax').val(getPriceWithTax($('#product-price').val(), taxRateSelected));
//formattage des prix
$('#product-price').val(parseFloat($('#product-price').val()).toFixed(3));
if($('#product-price').val()) {
$('#product-price-with-tax').val(getPriceWithTax($('#product-price').val(), taxRateSelected));
//formattage des prix
$('#product-price').val(parseFloat($('#product-price').val()).toFixed(3));
}
}
function opendistrib_products_event_price(){
taxRateSelected = $('#product-id_tax_rate').find('option:selected').data('tax-rate-value');
@@ -104,11 +106,11 @@ function opendistrib_products_event_unit(change) {
var unit = $('#product-unit').val() ;
if(unit == 'piece') {
$('.field-product-step').hide() ;
$('.field-product-weight').show() ;
$('.field-product-weight label').html('Poids (g)') ;
}
else {
$('.field-product-step').show() ;
$('.field-product-weight').hide() ;
$('.field-product-weight label').html('Poids ('+$('#product-unit').val()+')') ;
}
var label_price_ttc = $('.field-product-price .control-label.with-tax') ;

Loading…
Cancel
Save