Browse Source

Merge branch 'dev'

prodstable
Guillaume 4 years ago
parent
commit
8bdc55bfb8
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

@@ -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);

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

@@ -266,6 +266,11 @@ $this->addBreadcrumb($this->getTitle()) ;
0 => 'Non',
1 => 'Oui'
], []); ?>
<?= $form->field($model, 'option_csv_export_by_piece')
->dropDownList([
0 => 'Non',
1 => 'Oui'
], []); ?>
</div>
</div>


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

@@ -818,6 +818,32 @@ class Order extends ActiveRecordCommon
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.
*

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

@@ -134,7 +134,7 @@ class Producer extends ActiveRecordCommon
}],
[['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'],
[['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],
[['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'],
@@ -222,6 +222,7 @@ class Producer extends ActiveRecordCommon
'option_dashboard_date_start' => 'Date de début',
'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_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

@@ -0,0 +1,18 @@
<?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