Browse Source

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

refactoring
Guillaume 3 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



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

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

$datas[] = []; $datas[] = [];
} }
} }


// global // global
$totalsGlobalArray = $this->_totalReportCSV( $totalsGlobalArray = $this->_totalReportCSV(
'> Totaux',
'> Totaux (unité)',
$ordersArray, $ordersArray,
$productsArray, $productsArray,
$productsIndexArray $productsIndexArray
); );
$datas[] = $this->_lineOrderReportCSV($totalsGlobalArray, $cpt); $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'); CSV::downloadSendHeaders('Commandes_' . $date . '.csv');
echo CSV::array2csv($datas); echo CSV::array2csv($datas);
die(); die();
return $totalsPointSaleArray; 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) public function _lineOrderReportCSV($orderLine, $cptMax, $showTotal = false)
{ {
$line = []; $line = [];

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

$order->processCredit(); $order->processCredit();
} }


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


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

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

if(typeof taxRateSelected == 'undefined') { if(typeof taxRateSelected == 'undefined') {
taxRateSelected = 0 ; 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(){ function opendistrib_products_event_price(){
taxRateSelected = $('#product-id_tax_rate').find('option:selected').data('tax-rate-value'); taxRateSelected = $('#product-id_tax_rate').find('option:selected').data('tax-rate-value');
var unit = $('#product-unit').val() ; var unit = $('#product-unit').val() ;
if(unit == 'piece') { if(unit == 'piece') {
$('.field-product-step').hide() ; $('.field-product-step').hide() ;
$('.field-product-weight').show() ;
$('.field-product-weight label').html('Poids (g)') ;
} }
else { else {
$('.field-product-step').show() ; $('.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') ; var label_price_ttc = $('.field-product-price .control-label.with-tax') ;

Loading…
Cancel
Save