Browse Source

[backend] Export CSV : option nombre de pièces

dev
Guillaume 4 years ago
parent
commit
d4879c401c
5 changed files with 117 additions and 41 deletions
  1. +66
    -40
      backend/controllers/DistributionController.php
  2. +5
    -0
      backend/views/producer/update.php
  3. +26
    -0
      common/models/Order.php
  4. +2
    -1
      common/models/Producer.php
  5. +18
    -0
      console/migrations/m201230_102708_add_option_export_csv.php

+ 66
- 40
backend/controllers/DistributionController.php View File



// return the pdf output as per the destination setting // return the pdf output as per the destination setting
return $pdf->render(); return $pdf->render();
} elseif ($type == 'csv') {
}
elseif ($type == 'csv') {
$datas = []; $datas = [];


$optionCsvExportAllProducts = Producer::getConfig('option_csv_export_all_products') ; $optionCsvExportAllProducts = Producer::getConfig('option_csv_export_all_products') ;
$optionCsvExportByPiece = Producer::getConfig('option_csv_export_by_piece') ;


// produits en colonne // produits en colonne
$productsNameArray = ['']; $productsNameArray = [''];
} }
} }
if ($productsHasQuantity[$product->id] > 0 || $optionCsvExportAllProducts) { 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++; $productsIndexArray[$product->id] = $cpt++;
} }
} }
foreach ($pointSale->orders as $order) { foreach ($pointSale->orders as $order) {
$orderLine = [$order->getStrUser()]; $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); $datas[] = $this->_lineOrderReportCSV($orderLine, $cpt);
} }


// total point de vente // 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[] = []; $datas[] = [];
} }
} }


// global // 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'); CSV::downloadSendHeaders('Commandes_' . $date . '.csv');
echo CSV::array2csv($datas); echo CSV::array2csv($datas);

+ 5
- 0
backend/views/producer/update.php View File

0 => 'Non', 0 => 'Non',
1 => 'Oui' 1 => 'Oui'
], []); ?> ], []); ?>
<?= $form->field($model, 'option_csv_export_by_piece')
->dropDownList([
0 => 'Non',
1 => 'Oui'
], []); ?>
</div> </div>
</div> </div>



+ 26
- 0
common/models/Order.php View File

return $quantity; return $quantity;
} }


public static function getProductQuantityPieces($idProduct, $orders)
{
$quantity = 0;

if (isset($orders) && is_array($orders) && count($orders)) {
foreach ($orders as $c) {
if (is_null($c->date_delete)) {
foreach ($c->productOrder as $po) {
if ($po->id_product == $idProduct) {
if($po->unit == 'piece') {
$quantity += $po->quantity ;
}
else {
if(isset($po->product) && $po->product->weight > 0) {
$quantity += ($po->quantity * Product::$unitsArray[$po->unit]['coefficient']) / $po->product->weight ;
}
}
}
}
}
}
}

return $quantity;
}

/** /**
* Recherche et initialise des commandes. * Recherche et initialise des commandes.
* *

+ 2
- 1
common/models/Producer.php View File

}], }],
[['description', 'mentions', 'gcs', 'order_infos', 'slug', 'secret_key_payplug', 'background_color_logo', 'option_behavior_cancel_order', 'tiller_provider_token', 'tiller_restaurant_token', 'status', [['description', 'mentions', 'gcs', 'order_infos', 'slug', 'secret_key_payplug', 'background_color_logo', 'option_behavior_cancel_order', 'tiller_provider_token', 'tiller_restaurant_token', 'status',
'document_infos_bottom', 'document_infos_quotation', 'document_infos_invoice', 'document_infos_delivery_note', 'address', 'behavior_home_point_sale_day_list', 'behavior_order_select_distribution', 'option_payment_info'], 'string'], 'document_infos_bottom', 'document_infos_quotation', 'document_infos_invoice', 'document_infos_delivery_note', 'address', 'behavior_home_point_sale_day_list', 'behavior_order_select_distribution', 'option_payment_info'], 'string'],
[['negative_balance', 'credit', 'active', 'online_payment', 'user_manage_subscription', 'option_allow_user_gift', 'use_credit_checked_default', 'tiller', 'document_display_orders_invoice', 'document_display_orders_delivery_note', 'document_display_prices_delivery_note', 'option_email_confirm', 'option_email_confirm_producer', 'option_csv_export_all_products'], 'boolean'],
[['negative_balance', 'credit', 'active', 'online_payment', 'user_manage_subscription', 'option_allow_user_gift', 'use_credit_checked_default', 'tiller', 'document_display_orders_invoice', 'document_display_orders_delivery_note', 'document_display_prices_delivery_note', 'option_email_confirm', 'option_email_confirm_producer', 'option_csv_export_all_products', 'option_csv_export_by_piece'], 'boolean'],
[['name', 'siret', 'logo', 'photo', 'postcode', 'city', 'code', 'type', 'credit_functioning', 'option_behavior_cancel_order', 'document_quotation_prefix', 'document_quotation_first_reference', 'document_invoice_prefix', 'document_invoice_first_reference', 'document_delivery_note_prefix', 'document_delivery_note_first_reference'], 'string', 'max' => 255], [['name', 'siret', 'logo', 'photo', 'postcode', 'city', 'code', 'type', 'credit_functioning', 'option_behavior_cancel_order', 'document_quotation_prefix', 'document_quotation_first_reference', 'document_invoice_prefix', 'document_invoice_first_reference', 'document_delivery_note_prefix', 'document_delivery_note_first_reference'], 'string', 'max' => 255],
[['free_price', 'credit_limit_reminder', 'credit_limit'], 'double'], [['free_price', 'credit_limit_reminder', 'credit_limit'], 'double'],
['free_price', 'compare', 'compareValue' => 0, 'operator' => '>=', 'type' => 'number', 'message' => 'Prix libre doit être supérieur ou égal à 0'], ['free_price', 'compare', 'compareValue' => 0, 'operator' => '>=', 'type' => 'number', 'message' => 'Prix libre doit être supérieur ou égal à 0'],
'option_dashboard_date_start' => 'Date de début', 'option_dashboard_date_start' => 'Date de début',
'option_dashboard_date_end' => 'Date de fin', 'option_dashboard_date_end' => 'Date de fin',
'option_csv_export_all_products' => 'Exporter tous les produits dans le fichier récapitulatif (CSV)', 'option_csv_export_all_products' => 'Exporter tous les produits dans le fichier récapitulatif (CSV)',
'option_csv_export_by_piece' => 'Exporter les produits par pièce dans le fichier récapitulatif (CSV)',
]; ];
} }



+ 18
- 0
console/migrations/m201230_102708_add_option_export_csv.php View File

<?php

use yii\db\Migration;

class m201230_102708_add_option_export_csv extends Migration
{
public function safeUp()
{
$this->addColumn('producer', 'option_csv_export_by_piece', Schema::TYPE_BOOLEAN.' DEFAULT 0');
}

public function safeDown()
{
$this->dropColumn('producer', 'option_csv_export_by_piece');

return false;
}
}

Loading…
Cancel
Save