Browse Source

[Administration] Distribution > exports : création ExportManager #1352

feature/souke
Guillaume Bourgeois 1 year ago
parent
commit
888b84b5e8
21 changed files with 520 additions and 436 deletions
  1. +7
    -38
      backend/controllers/CronController.php
  2. +12
    -97
      backend/controllers/DistributionController.php
  3. +7
    -6
      backend/views/distribution/index.php
  4. +36
    -34
      backend/views/producer/update.php
  5. +1
    -1
      backend/views/product/_form.php
  6. +191
    -190
      backend/web/css/screen.css
  7. +2
    -2
      backend/web/js/backend.js
  8. +5
    -0
      backend/web/js/vuejs/producer-update.js
  9. +1
    -0
      backend/web/sass/screen.scss
  10. +10
    -0
      common/logic/Distribution/Distribution/Export/DistributionExportGeneratorInterface.php
  11. +3
    -3
      common/logic/Distribution/Distribution/Export/DistributionReport2CsvGenerator.php
  12. +7
    -4
      common/logic/Distribution/Distribution/Export/DistributionReportCsvGenerator.php
  13. +3
    -3
      common/logic/Distribution/Distribution/Export/DistributionReportGridPdfGenerator.php
  14. +3
    -3
      common/logic/Distribution/Distribution/Export/DistributionReportPdfGenerator.php
  15. +3
    -3
      common/logic/Distribution/Distribution/Export/DistributionReportTotalProductCsvGenerator.php
  16. +3
    -3
      common/logic/Distribution/Distribution/Export/DistributionShoppingCartLabelsPdfGenerator.php
  17. +14
    -42
      common/logic/Distribution/Distribution/Module/DistributionModule.php
  18. +151
    -0
      common/logic/Distribution/Distribution/Service/ExportManager.php
  19. +7
    -2
      common/logic/Order/ProductOrder/Service/ProductOrderSolver.php
  20. +15
    -5
      common/logic/Producer/Producer/Model/Producer.php
  21. +39
    -0
      console/migrations/m231024_062121_add_column_producer_options_exports.php

+ 7
- 38
backend/controllers/CronController.php View File



use common\helpers\GlobalParam; use common\helpers\GlobalParam;
use common\helpers\MeanPayment; use common\helpers\MeanPayment;
use common\logic\Distribution\Distribution\Service\ExportManager;
use common\logic\Order\Order\Model\Order; use common\logic\Order\Order\Model\Order;
use common\logic\User\User\Model\User; use common\logic\User\User\Model\User;
use Yii; use Yii;
* @param string $key * @param string $key
* @param string $forceDate * @param string $forceDate
*/ */
public function actionProcessOrders($key = '', $forceDate = '')
public function actionProcessOrders(string $key = '', string $forceDate = '')
{ {
$producerModule = $this->getProducerModule(); $producerModule = $this->getProducerModule();
$distributionModule = $this-> getDistributionModule(); $distributionModule = $this-> getDistributionModule();
$arrayProducers = $producerModule->findProducers(); $arrayProducers = $producerModule->findProducers();


foreach ($arrayProducers as $producer) { foreach ($arrayProducers as $producer) {

$this->getLogic()->setProducerContext($producer); $this->getLogic()->setProducerContext($producer);

$countOrders = 0;
$mailOrdersSend = false;
$distribution = $distributionModule $distribution = $distributionModule
->findOneDistribution($date, true); ->findOneDistribution($date, true);


if ($order->auto_payment && $configCredit) { if ($order->auto_payment && $configCredit) {
if ($orderModule->isCreditAutoPayment($order) && $orderModule->getOrderAmount($order, Order::AMOUNT_REMAINING) > 0) { if ($orderModule->isCreditAutoPayment($order) && $orderModule->getOrderAmount($order, Order::AMOUNT_REMAINING) > 0) {
$paymentManager->payOrder($order, MeanPayment::CREDIT, $userModule->findOneUserById(User::ID_USER_SYSTEM), false); $paymentManager->payOrder($order, MeanPayment::CREDIT, $userModule->findOneUserById(User::ID_USER_SYSTEM), false);
$countOrders++;
} }
} }
} }


$mail = Yii::$app->mailer->compose( $mail = Yii::$app->mailer->compose(
[ [
'html' => 'cronOrdersSummary-html',
'text' => 'cronOrdersSummary-text',
'html' => '@common/mail/cronOrdersSummary-html',
'text' => '@common/mail/cronOrdersSummary-text',
], [ ], [
'date' => $date, 'date' => $date,
'orders' => $arrayOrders 'orders' => $arrayOrders
if (is_array($arrayOrders) && count($arrayOrders)) { if (is_array($arrayOrders) && count($arrayOrders)) {
$subject = '[Opendistrib] Commandes du ' . date('d/m', strtotime($date)); $subject = '[Opendistrib] Commandes du ' . date('d/m', strtotime($date));


// génération du pdf de commande
Yii::$app->runAction('distribution/report-cron', [
'date' => $date,
'save' => true,
'idProducer' => $producer->id,
'key' => '64ac0bdab7e9f5e48c4d991ec5201d57'
]);
// @TODO : envoyer uniquement les exports qui sont activés dans les paramètres du producteur
$distributionModule->getExportManager()->generate(ExportManager::ORDERS_PDF, $distribution, true);

$mail->attach( $mail->attach(
Yii::getAlias('@app/web/pdf/Commandes-' . $date . '-' . $producer->id . '.pdf') Yii::getAlias('@app/web/pdf/Commandes-' . $date . '-' . $producer->id . '.pdf')
); );
foreach ($userArray as $user) { foreach ($userArray as $user) {
if($user->email && strlen($user->email) > 0) { if($user->email && strlen($user->email) > 0) {
$mail->setTo($user->email)->send(); $mail->setTo($user->email)->send();
$mailOrdersSend = true;
} }
} }
} }

if ($producer->active) {

$strCountOrders = 0;
if ($arrayOrders && is_array($arrayOrders)) {
$strCountOrders = count($arrayOrders);
}

$messageLog =
$producer->name . '<br />' .
'Distribution du ' . $date . '<br />' .
$strCountOrders . ' commande(s) enregistrée(s)<br />' .
$countOrders . ' commande(s) payée(s)<br .>' .
($mailOrdersSend ? 'Récapitulatif de commandes envoyé' : 'Aucun récapitulatif envoyé');

/*Yii::$app->mailer->compose()
->setFrom('contact@opendistrib.net')
->setTo('contact@opendistrib.net')
->setSubject('[Opendistrib] Log '.$producer->name)
->setTextBody($messageLog)
->send();*/
}
} }
} }
} }

+ 12
- 97
backend/controllers/DistributionController.php View File

use common\helpers\MeanPayment; use common\helpers\MeanPayment;
use common\helpers\Price; use common\helpers\Price;
use common\logic\Distribution\Distribution\Model\Distribution; use common\logic\Distribution\Distribution\Model\Distribution;
use common\logic\Distribution\Distribution\Service\ExportManager;
use common\logic\Document\DeliveryNote\Model\DeliveryNote; use common\logic\Document\DeliveryNote\Model\DeliveryNote;
use common\logic\Order\Order\Model\Order; use common\logic\Order\Order\Model\Order;
use common\logic\Producer\Producer\Model\Producer; use common\logic\Producer\Producer\Model\Producer;
use common\logic\Product\Product\Model\Product; use common\logic\Product\Product\Model\Product;
use DateTime; use DateTime;
use kartik\mpdf\Pdf;
use yii\base\ErrorException;
use yii\base\Exception; use yii\base\Exception;
use yii\filters\AccessControl; use yii\filters\AccessControl;


return [ return [
'credit' => $producer->credit, 'credit' => $producer->credit,
'tiller' => $producer->tiller, 'tiller' => $producer->tiller,
'option_display_export_grid' => $producer->option_display_export_grid
'option_distribution_export_orders_grid_pdf' => $producer->option_distribution_export_orders_grid_pdf
]; ];
} }


$distributionJsonData = [ $distributionJsonData = [
'id' => $distribution->id, 'id' => $distribution->id,
'active' => $distribution->active, 'active' => $distribution->active,
'url_report' => $this->getUrlManagerBackend()->createUrl(
['distribution/report', 'date' => $distribution->date]
),
'url_report_csv2' => $this->getUrlManagerBackend()->createUrl(
['distribution/report-csv2', 'date' => $distribution->date]
),
'url_report_grid' => $this->getUrlManagerBackend()->createUrl(
['distribution/report-grid', 'date' => $distribution->date]
),
'url_export_shopping_cart_labels' => $this->getUrlManagerBackend()->createUrl(
['distribution/export-shopping-cart-labels', 'date' => $distribution->date]
),
'url_report_total_products' => $this->getUrlManagerBackend()->createUrl(
['distribution/report-total-products', 'date' => $distribution->date]
),
'exports' => $distributionModule->getExportManager()->getAjaxArray($distribution),
'url_order' => $distributionModule->getLinkOrder($distribution), 'url_order' => $distributionModule->getLinkOrder($distribution),
]; ];




public function buildAjaxInfosResponseOrders(array $ordersArray, array $productsArray) public function buildAjaxInfosResponseOrders(array $ordersArray, array $productsArray)
{ {
$productModule = $this->getProductModule();
$userModule = $this->getUserModule(); $userModule = $this->getUserModule();
$orderModule = $this->getOrderModule(); $orderModule = $this->getOrderModule();
$paymentManager = $this->getPaymentModule(); $paymentManager = $this->getPaymentModule();
} }


/** /**
* Génére un PDF récapitulatif des des commandes d'un producteur pour une
* date donnée (Méthode appelable via CRON)
*
* @param string $date
* @param boolean $save
* @param integer $idProducer
* @param string $key
* @return Pdf|null
*/
public function actionReportCron($date = '', $save = false, $idProducer = 0, $key = '')
{
if ($key == '64ac0bdab7e9f5e48c4d991ec5201d57') {
$this->actionReport($date, $save, $idProducer);
}
}

/**
* Génére un PDF récapitulatif des commandes d'un producteur pour une
* date donnée.
* Génére un export pour une distribution.
*/ */
public function actionReport(string $date = '', bool $save = false, int $idProducer = 0, string $type = "pdf")
public function actionExport(string $name, string $date = '')
{ {
if (!$idProducer) {
$idProducer = $this->getProducerCurrent()->id;
}

$distributionModule = $this-> getDistributionModule(); $distributionModule = $this-> getDistributionModule();
$producerModule = $this->getProducerModule();
$producerCurrent = $producerModule->findOneProducerById($idProducer);
$this->getLogic()->setProducerContext($producerCurrent);
$distribution = $distributionModule->findOneDistribution($date);
$distribution = $distributionModule->getRepository()->findOneDistribution($date);


if ($distribution) { if ($distribution) {
if ($type == 'pdf') {
return $distributionModule->getReportPdfGenerator()
->generateDistributionReportPdf($distribution, $save);
try {
return $distributionModule->getExportManager()->getGenerator($name)->generate($distribution);
} }
elseif ($type == 'csv') {
$distributionModule->getReportCsvGenerator()
->generateDistributionReportCsv($distribution);
catch(ErrorException $exception) {
$this->setFlash('error', "Une erreur est survenue lors de la génération de l'export.");
return $this->redirectReferer();
} }
} }
} }


public function actionReportCsv2(string $date = '')
{
$distributionModule = $this->getDistributionModule();
$distribution = $distributionModule->getRepository()->findOneDistribution($date);
if ($distribution) {
$distributionModule->getReport2CsvGenerator()->generateCsv($distribution);
}
}

public function actionReportGrid(string $date = '', bool $save = false, int $idProducer = 0)
{
if (!$idProducer) {
$idProducer = $this->getProducerCurrent()->id;
}

$distributionModule = $this-> getDistributionModule();
$producerModule = $this->getProducerModule();
$producerCurrent = $producerModule->findOneProducerById($idProducer);
$this->getLogic()->setProducerContext($producerCurrent);
$distribution = $distributionModule->findOneDistribution($date);

if ($distribution) {
return $distributionModule->generateDistributionReportGridPdf($distribution, $save);
}
}

public function actionReportTotalProductsCsv(string $date = '')
{
$distributionModule = $this-> getDistributionModule();
$distribution = $distributionModule->getRepository()->findOneDistribution($date);

if ($distribution) {
$distributionModule->getReportTotalProductCsvGenerator()->generateCsv($distribution);
}
}

public function actionExportShoppingCartLabels(string $date)
{
$distributionModule = $this-> getDistributionModule();
$distribution = $distributionModule->findOneDistribution($date);
if($distribution) {
return $distributionModule->generateDistributionShoppingCartLabelsPdf($distribution);
}
}

public function actionAjaxProcessProductQuantityMax($idDistribution, $idProduct, $quantityMax) public function actionAjaxProcessProductQuantityMax($idDistribution, $idProduct, $quantityMax)
{ {
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;

+ 7
- 6
backend/views/distribution/index.php View File

<div class="info-box-content"> <div class="info-box-content">
<span class="info-box-text"> <span class="info-box-text">
{{ countOrders }} Commande<span v-if="countOrders > 1">s</span><br /> {{ countOrders }} Commande<span v-if="countOrders > 1">s</span><br />
<a :href="distribution.url_report" class="btn btn-xs btn-default" v-if="countOrders > 0">Liste (PDF)</a>
<a :href="distribution.url_report+'&type=csv'" class="btn btn-xs btn-default" v-if="countOrders > 0">Tableau (CSV)</a>

<template v-for="distributionExport in distribution.exports">
<a v-if="countOrders > 0" :href="distributionExport.url" class="btn btn-xs btn-default">{{ distributionExport.label }}</a><br />
</template>
<!--<a :href="distribution.url_report+'&type=csv'" class="btn btn-xs btn-default" v-if="countOrders > 0">Tableau (CSV)</a>
<a :href="distribution.url_report_csv2" class="btn btn-xs btn-default" v-if="countOrders > 0">Tableau 2 (CSV)</a> <a :href="distribution.url_report_csv2" class="btn btn-xs btn-default" v-if="countOrders > 0">Tableau 2 (CSV)</a>
<br /> <br />
<a :href="distribution.url_report_grid" class="btn btn-xs btn-default" v-if="producer && producer.option_display_export_grid && countOrders > 0">Grille (PDF)</a>
<a :href="distribution.url_report_grid" class="btn btn-xs btn-default" v-if="producer && producer.option_distribution_export_orders_grid_pdf && countOrders > 0">Grille (PDF)</a>
<a :href="distribution.url_export_shopping_cart_labels" class="btn btn-xs btn-default" v-if="countOrders > 0">Étiquettes (PDF)</a> <a :href="distribution.url_export_shopping_cart_labels" class="btn btn-xs btn-default" v-if="countOrders > 0">Étiquettes (PDF)</a>
<a :href="distribution.url_report_total_products" class="btn btn-xs btn-default" v-if="countOrders > 0">Total produits (CSV)</a>
<a :href="distribution.url_report_total_products" class="btn btn-xs btn-default" v-if="countOrders > 0">Total produits (CSV)</a>-->
</span> </span>
</div> </div>
</div> </div>
</div> </div>
<div v-if="order.amount_paid > order.amount"> <div v-if="order.amount_paid > order.amount">
<span class="glyphicon glyphicon-alert"></span> Surplus à rembourser <span class="glyphicon glyphicon-alert"></span> Surplus à rembourser
{{ order.amount_paid }} /
{{ order.amount }}
</div> </div>
</td> </td>
<td class="column-credit" v-if="!idActivePointSale || (pointSaleActive && pointSaleActive.credit == 1)"> <td class="column-credit" v-if="!idActivePointSale || (pointSaleActive && pointSaleActive.credit == 1)">

+ 36
- 34
backend/views/producer/update.php View File

*/ */


use common\helpers\GlobalParam; use common\helpers\GlobalParam;
use common\logic\Distribution\Distribution\Module\DistributionModule;
use common\logic\Distribution\Distribution\Service\ExportManager;
use common\logic\User\User\Module\UserModule; use common\logic\User\User\Module\UserModule;
use yii\helpers\Html; use yii\helpers\Html;
use yii\widgets\ActiveForm; use yii\widgets\ActiveForm;
\backend\assets\VuejsProducerUpdateAsset::register($this); \backend\assets\VuejsProducerUpdateAsset::register($this);
$userModule = UserModule::getInstance(); $userModule = UserModule::getInstance();
$userCurrent = GlobalParam::getCurrentUser(); $userCurrent = GlobalParam::getCurrentUser();
$distributionExportManager = DistributionModule::getInstance()->getExportManager();
$this->setTitle('Paramètres'); $this->setTitle('Paramètres');
$this->addBreadcrumb($this->getTitle()); $this->addBreadcrumb($this->getTitle());


:class="'btn '+((currentSection == section.name) ? 'btn-primary' : 'btn-default')" :class="'btn '+((currentSection == section.name) ? 'btn-primary' : 'btn-default')"
@click="changeSection(section)" :href="'#'+section.name"> @click="changeSection(section)" :href="'#'+section.name">
{{ section.nameDisplay }} {{ section.nameDisplay }}
<span class="glyphicon glyphicon-triangle-bottom"></span>
</a> </a>
</div> </div>


1 => 'Oui' 1 => 'Oui'
], []); ?> ], []); ?>



<h4>Exports</h4>
<?= $form->field($model, 'option_csv_separator')
->dropDownList([
';' => 'Point-virgule (;)',
',' => 'Virgule (,)'
], []); ?>
<?= $form->field($model, 'option_csv_export_all_products')
->dropDownList([
0 => 'Non',
1 => 'Oui'
], []); ?>
<?= $form->field($model, 'option_csv_export_by_piece')
->dropDownList([
0 => 'Non',
1 => 'Oui'
], []); ?>
<?= $form->field($model, 'option_display_export_grid')
->dropDownList([
0 => 'Non',
1 => 'Oui'
], []); ?>
<?= $form->field($model, 'option_export_display_product_reference')
->dropDownList([
0 => 'Non',
1 => 'Oui'
], []); ?>
<?= $form->field($model, 'option_export_display_column_delivery_note')
->dropDownList([
0 => 'Non',
1 => 'Oui'
], []); ?>

<h4>Divers</h4> <h4>Divers</h4>
<?php <?php
$choicesWeeksDistributionsActivatedInAdvanceArray = [null => '--']; $choicesWeeksDistributionsActivatedInAdvanceArray = [null => '--'];
</div> </div>
</div> </div>


<div v-show="currentSection == 'exports'" class="panel panel-default">
<div class="panel-body">
<h4>Exports affichés dans les distributions</h4>
<?= $distributionExportManager->getProducerFormCheckboxes($form, $model) ?>

<h4>Options exports</h4>
<?= $form->field($model, 'option_csv_separator')
->dropDownList([
';' => 'Point-virgule (;)',
',' => 'Virgule (,)'
], []); ?>
<?= $form->field($model, 'option_export_display_product_reference')
->dropDownList([
0 => 'Non',
1 => 'Oui'
], []); ?>
<?= $form->field($model, 'option_export_display_column_delivery_note')
->dropDownList([
0 => 'Non',
1 => 'Oui'
], []); ?>
<?= $form->field($model, 'option_csv_export_all_products')
->dropDownList([
0 => 'Non',
1 => 'Oui'
], []); ?>
<?= $form->field($model, 'option_csv_export_by_piece')
->dropDownList([
0 => 'Non',
1 => 'Oui'
], []); ?>
</div>
</div>


<div v-show="currentSection == 'abonnements'" class="panel panel-default"> <div v-show="currentSection == 'abonnements'" class="panel panel-default">
<div class="panel-body"> <div class="panel-body">

+ 1
- 1
backend/views/product/_form.php View File

]) ?> ]) ?>
<?= $form->field($model, 'step')->textInput()->hint('Définit ce qui est ajouté ou enlevé lors des changements de quantité.') ?> <?= $form->field($model, 'step')->textInput()->hint('Définit ce qui est ajouté ou enlevé lors des changements de quantité.') ?>


<?= $form->field($model, 'weight')->textInput()->label('Poids (g)') ?>
<?= $form->field($model, 'weight')->textInput()->label('Poids (g)')->hint("Si unité au poids ou volume, utilisé pour déterminer le nombre de pièces dans les exports.") ?>


<div class="col-md-3"> <div class="col-md-3">
<?= $form->field($model, 'quantity_max')->textInput() ?> <?= $form->field($model, 'quantity_max')->textInput() ?>

+ 191
- 190
backend/web/css/screen.css
File diff suppressed because it is too large
View File


+ 2
- 2
backend/web/js/backend.js View File

if (unit == 'piece') { if (unit == 'piece') {
$('.field-product-step').hide(); $('.field-product-step').hide();
$('.field-product-weight label').html('Poids (g)'); $('.field-product-weight label').html('Poids (g)');
$('.field-product-weight').show();
//$('.field-product-weight').show();
} else { } else {
$('.field-product-step').show(); $('.field-product-step').show();
$('.field-product-weight label').html('Poids (' + $('#product-unit').val() + ')'); $('.field-product-weight label').html('Poids (' + $('#product-unit').val() + ')');
$('.field-product-weight').hide();
//$('.field-product-weight').hide();
} }


var label_price_ttc = $('.field-product-price .control-label.with-tax'); var label_price_ttc = $('.field-product-price .control-label.with-tax');

+ 5
- 0
backend/web/js/vuejs/producer-update.js View File

nameDisplay: 'Commandes', nameDisplay: 'Commandes',
isAdminSection: 0 isAdminSection: 0
}, },
{
name: 'exports',
nameDisplay: 'Exports',
isAdminSection: 0
},
{ {
name: 'credit-payment', name: 'credit-payment',
nameDisplay: 'Crédit', nameDisplay: 'Crédit',

+ 1
- 0
backend/web/sass/screen.scss View File



a { a {
margin-right: 10px ; margin-right: 10px ;
margin-bottom: 10px;
} }
} }



+ 10
- 0
common/logic/Distribution/Distribution/Export/DistributionExportGeneratorInterface.php View File

<?php

namespace common\logic\Distribution\Distribution\Export;

use common\logic\Distribution\Distribution\Model\Distribution;

interface DistributionExportGeneratorInterface
{
public function generate(Distribution $distribution, bool $save = false);
}

common/logic/Distribution/Distribution/Service/DistributionReport2CsvGenerator.php → common/logic/Distribution/Distribution/Export/DistributionReport2CsvGenerator.php View File

<?php <?php


namespace common\logic\Distribution\Distribution\Service;
namespace common\logic\Distribution\Distribution\Export;


use common\helpers\CSV; use common\helpers\CSV;
use common\logic\AbstractGenerator; use common\logic\AbstractGenerator;
use common\logic\Producer\Producer\Service\ProducerSolver; use common\logic\Producer\Producer\Service\ProducerSolver;
use common\logic\Product\Product\Service\ProductSolver; use common\logic\Product\Product\Service\ProductSolver;


class DistributionReport2CsvGenerator extends AbstractGenerator
class DistributionReport2CsvGenerator extends AbstractGenerator implements DistributionExportGeneratorInterface
{ {
protected ProductSolver $productSolver; protected ProductSolver $productSolver;
protected OrderRepository $orderRepository; protected OrderRepository $orderRepository;
$this->productOrderSolver = $this->loadService(ProductOrderSolver::class); $this->productOrderSolver = $this->loadService(ProductOrderSolver::class);
} }


public function generateCsv(Distribution $distribution)
public function generate(Distribution $distribution, bool $save = false)
{ {
$datas = [['Distribution du '.date('d/m/Y', strtotime($distribution->date))]]; $datas = [['Distribution du '.date('d/m/Y', strtotime($distribution->date))]];
$ordersArray = $this->orderRepository->findOrdersByDistribution($distribution); $ordersArray = $this->orderRepository->findOrdersByDistribution($distribution);

common/logic/Distribution/Distribution/Service/DistributionReportCsvGenerator.php → common/logic/Distribution/Distribution/Export/DistributionReportCsvGenerator.php View File

<?php <?php


namespace common\logic\Distribution\Distribution\Service;
namespace common\logic\Distribution\Distribution\Export;


use common\helpers\CSV; use common\helpers\CSV;
use common\logic\AbstractGenerator; use common\logic\AbstractGenerator;
use common\logic\Config\Unit\Service\UnitSolver;
use common\logic\Distribution\Distribution\Model\Distribution; use common\logic\Distribution\Distribution\Model\Distribution;
use common\logic\Order\Order\Repository\OrderRepository; use common\logic\Order\Order\Repository\OrderRepository;
use common\logic\Order\Order\Service\OrderBuilder; use common\logic\Order\Order\Service\OrderBuilder;
use common\logic\Product\Product\Repository\ProductRepository; use common\logic\Product\Product\Repository\ProductRepository;
use common\logic\Product\Product\Service\ProductSolver; use common\logic\Product\Product\Service\ProductSolver;


class DistributionReportCsvGenerator extends AbstractGenerator
class DistributionReportCsvGenerator extends AbstractGenerator implements DistributionExportGeneratorInterface
{ {
protected UnitSolver $unitSolver;
protected ProducerRepository $producerRepository; protected ProducerRepository $producerRepository;
protected ProductRepository $productRepository; protected ProductRepository $productRepository;
protected ProductSolver $productSolver; protected ProductSolver $productSolver;


public function loadDependencies(): void public function loadDependencies(): void
{ {
$this->unitSolver = $this->loadService(UnitSolver::class);
$this->producerRepository = $this->loadService(ProducerRepository::class); $this->producerRepository = $this->loadService(ProducerRepository::class);
$this->productRepository = $this->loadService(ProductRepository::class); $this->productRepository = $this->loadService(ProductRepository::class);
$this->productSolver = $this->loadService(ProductSolver::class); $this->productSolver = $this->loadService(ProductSolver::class);
$this->producerSolver = $this->loadService(ProducerSolver::class); $this->producerSolver = $this->loadService(ProducerSolver::class);
} }


public function generateDistributionReportCsv(Distribution $distribution)
public function generate(Distribution $distribution, bool $save = false)
{ {
$datas = []; $datas = [];
$ordersArray = $this->orderRepository->findOrdersByDistribution($distribution); $ordersArray = $this->orderRepository->findOrdersByDistribution($distribution);
$productUnit = $product->unit; $productUnit = $product->unit;
} }


$productName .= ' (' . $this->productSolver->strUnit($productUnit, 'wording_short', true) . ')';
$productName .= ' (' . $this->unitSolver->strUnit($productUnit, 'wording_short', true) . ')';


$productsNameArray[] = $productName; $productsNameArray[] = $productName;
$productsIndexArray[$product->id] = $cpt++; $productsIndexArray[$product->id] = $cpt++;

common/logic/Distribution/Distribution/Service/DistributionReportGridPdfGenerator.php → common/logic/Distribution/Distribution/Export/DistributionReportGridPdfGenerator.php View File

<?php <?php


namespace common\logic\Distribution\Distribution\Service;
namespace common\logic\Distribution\Distribution\Export;


use common\logic\AbstractGenerator; use common\logic\AbstractGenerator;
use common\logic\Distribution\Distribution\Model\Distribution; use common\logic\Distribution\Distribution\Model\Distribution;
use common\logic\Product\ProductCategory\Repository\ProductCategoryRepository; use common\logic\Product\ProductCategory\Repository\ProductCategoryRepository;
use kartik\mpdf\Pdf; use kartik\mpdf\Pdf;


class DistributionReportGridPdfGenerator extends AbstractGenerator
class DistributionReportGridPdfGenerator extends AbstractGenerator implements DistributionExportGeneratorInterface
{ {
protected OrderRepository $orderRepository; protected OrderRepository $orderRepository;
protected OrderBuilder $orderBuilder; protected OrderBuilder $orderBuilder;
$this->productRepository = $this->loadService(ProductRepository::class); $this->productRepository = $this->loadService(ProductRepository::class);
} }


public function generateDistributionReportGridPdf(Distribution $distribution, bool $save = false)
public function generate(Distribution $distribution, bool $save = false)
{ {
$producer = $this->getProducerContext(); $producer = $this->getProducerContext();
$ordersArray = $this->orderRepository->findOrdersByDistribution($distribution); $ordersArray = $this->orderRepository->findOrdersByDistribution($distribution);

common/logic/Distribution/Distribution/Service/DistributionReportPdfGenerator.php → common/logic/Distribution/Distribution/Export/DistributionReportPdfGenerator.php View File

<?php <?php


namespace common\logic\Distribution\Distribution\Service;
namespace common\logic\Distribution\Distribution\Export;


use common\helpers\Price; use common\helpers\Price;
use common\logic\AbstractGenerator; use common\logic\AbstractGenerator;
use common\logic\User\User\Repository\UserRepository; use common\logic\User\User\Repository\UserRepository;
use kartik\mpdf\Pdf; use kartik\mpdf\Pdf;


class DistributionReportPdfGenerator extends AbstractGenerator
class DistributionReportPdfGenerator extends AbstractGenerator implements DistributionExportGeneratorInterface
{ {
const LIMIT_PRODUCTS = 120; const LIMIT_PRODUCTS = 120;


$this->userRepository = $this->loadService(UserRepository::class); $this->userRepository = $this->loadService(UserRepository::class);
} }


public function generateDistributionReportPdf(Distribution $distribution, bool $save = false)
public function generate(Distribution $distribution, bool $save = false)
{ {
$producer = $this->getProducerContext(); $producer = $this->getProducerContext();
$ordersArray = $this->orderRepository->findOrdersByDistribution($distribution); $ordersArray = $this->orderRepository->findOrdersByDistribution($distribution);

common/logic/Distribution/Distribution/Service/DistributionReportTotalProductCsvGenerator.php → common/logic/Distribution/Distribution/Export/DistributionReportTotalProductCsvGenerator.php View File

<?php <?php


namespace common\logic\Distribution\Distribution\Service;
namespace common\logic\Distribution\Distribution\Export;


use common\helpers\CSV; use common\helpers\CSV;
use common\logic\AbstractGenerator; use common\logic\AbstractGenerator;
use common\logic\Product\Product\Repository\ProductRepository; use common\logic\Product\Product\Repository\ProductRepository;
use common\logic\Product\Product\Service\ProductSolver; use common\logic\Product\Product\Service\ProductSolver;


class DistributionReportTotalProductCsvGenerator extends AbstractGenerator
class DistributionReportTotalProductCsvGenerator extends AbstractGenerator implements DistributionExportGeneratorInterface
{ {
protected ProductRepository $productRepository; protected ProductRepository $productRepository;
protected ProductSolver $productSolver; protected ProductSolver $productSolver;
$this->orderSolver = $this->loadService(OrderSolver::class); $this->orderSolver = $this->loadService(OrderSolver::class);
} }


public function generateCsv(Distribution $distribution)
public function generate(Distribution $distribution, bool $save = false)
{ {
$datas = []; $datas = [];
$productsArray = $this->productRepository->findProductsByDistribution($distribution); $productsArray = $this->productRepository->findProductsByDistribution($distribution);

common/logic/Distribution/Distribution/Service/DistributionShoppingCartLabelsPdfGenerator.php → common/logic/Distribution/Distribution/Export/DistributionShoppingCartLabelsPdfGenerator.php View File

<?php <?php


namespace common\logic\Distribution\Distribution\Service;
namespace common\logic\Distribution\Distribution\Export;


use common\logic\AbstractGenerator; use common\logic\AbstractGenerator;
use common\logic\Distribution\Distribution\Model\Distribution; use common\logic\Distribution\Distribution\Model\Distribution;
use common\logic\Order\Order\Repository\OrderRepository; use common\logic\Order\Order\Repository\OrderRepository;
use kartik\mpdf\Pdf; use kartik\mpdf\Pdf;


class DistributionShoppingCartLabelsPdfGenerator extends AbstractGenerator
class DistributionShoppingCartLabelsPdfGenerator extends AbstractGenerator implements DistributionExportGeneratorInterface
{ {
protected OrderRepository $orderRepository; protected OrderRepository $orderRepository;


$this->orderRepository = $this->loadService(OrderRepository::class); $this->orderRepository = $this->loadService(OrderRepository::class);
} }


public function generateDistributionShoppingCartLabelsPdf(Distribution $distribution)
public function generate(Distribution $distribution, bool $save = false)
{ {
$ordersArray = $this->orderRepository->findOrdersByDistribution($distribution); $ordersArray = $this->orderRepository->findOrdersByDistribution($distribution);



+ 14
- 42
common/logic/Distribution/Distribution/Module/DistributionModule.php View File



namespace common\logic\Distribution\Distribution\Module; namespace common\logic\Distribution\Distribution\Module;


use common\logic\AbstractManager;
use common\logic\AbstractModule; use common\logic\AbstractModule;
use common\logic\Distribution\Distribution\Export\DistributionReport2CsvGenerator;
use common\logic\Distribution\Distribution\Export\DistributionReportCsvGenerator;
use common\logic\Distribution\Distribution\Export\DistributionReportGridPdfGenerator;
use common\logic\Distribution\Distribution\Export\DistributionReportPdfGenerator;
use common\logic\Distribution\Distribution\Export\DistributionReportTotalProductCsvGenerator;
use common\logic\Distribution\Distribution\Export\DistributionShoppingCartLabelsPdfGenerator;
use common\logic\Distribution\Distribution\Repository\DistributionRepository; use common\logic\Distribution\Distribution\Repository\DistributionRepository;
use common\logic\Distribution\Distribution\Service\DistributionBuilder; use common\logic\Distribution\Distribution\Service\DistributionBuilder;
use common\logic\Distribution\Distribution\Service\DistributionDefinition; use common\logic\Distribution\Distribution\Service\DistributionDefinition;
use common\logic\Distribution\Distribution\Service\DistributionReport2CsvGenerator;
use common\logic\Distribution\Distribution\Service\DistributionReportCsvGenerator;
use common\logic\Distribution\Distribution\Service\DistributionReportGridPdfGenerator;
use common\logic\Distribution\Distribution\Service\DistributionReportPdfGenerator;
use common\logic\Distribution\Distribution\Service\DistributionReportTotalProductCsvGenerator;
use common\logic\Distribution\Distribution\Service\DistributionShoppingCartLabelsPdfGenerator;
use common\logic\Distribution\Distribution\Service\DistributionSolver; use common\logic\Distribution\Distribution\Service\DistributionSolver;
use common\logic\Distribution\Distribution\Service\ExportManager;


/** /**
* @mixin DistributionDefinition * @mixin DistributionDefinition
* @mixin DistributionSolver * @mixin DistributionSolver
* @mixin DistributionRepository * @mixin DistributionRepository
* @mixin DistributionBuilder * @mixin DistributionBuilder
* @mixin DistributionReportCsvGenerator
* @mixin DistributionReportGridPdfGenerator
* @mixin DistributionReportPdfGenerator
* @mixin DistributionShoppingCartLabelsPdfGenerator
* @mixin DistributionReportTotalProductCsvGenerator
* @mixin DistributionReport2CsvGenerator
* @mixin ExportManager
*/ */
class DistributionModule extends AbstractModule class DistributionModule extends AbstractModule
{ {
DistributionSolver::class, DistributionSolver::class,
DistributionRepository::class, DistributionRepository::class,
DistributionBuilder::class, DistributionBuilder::class,

ExportManager::class,
DistributionReport2CsvGenerator::class,
DistributionReportCsvGenerator::class, DistributionReportCsvGenerator::class,
DistributionReportGridPdfGenerator::class, DistributionReportGridPdfGenerator::class,
DistributionReportPdfGenerator::class, DistributionReportPdfGenerator::class,
DistributionShoppingCartLabelsPdfGenerator::class,
DistributionReportTotalProductCsvGenerator::class, DistributionReportTotalProductCsvGenerator::class,
DistributionReport2CsvGenerator::class,
DistributionShoppingCartLabelsPdfGenerator::class
]; ];
} }


return DistributionBuilder::getInstance(); return DistributionBuilder::getInstance();
} }


public function getReportCsvGenerator(): DistributionReportCsvGenerator
{
return DistributionReportCsvGenerator::getInstance();
}

public function getReport2CsvGenerator(): DistributionReport2CsvGenerator
{
return DistributionReport2CsvGenerator::getInstance();
}

public function getReportGridPdfGenerator(): DistributionReportGridPdfGenerator
{
return DistributionReportGridPdfGenerator::getInstance();
}

public function getReportPdfGenerator(): DistributionReportPdfGenerator
{
return DistributionReportPdfGenerator::getInstance();
}

public function getShoppingCartLabelsPdfGenerator(): DistributionShoppingCartLabelsPdfGenerator
{
return DistributionShoppingCartLabelsPdfGenerator::getInstance();
}

public function getReportTotalProductCsvGenerator(): DistributionReportTotalProductCsvGenerator
public function getExportManager(): ExportManager
{ {
return DistributionReportTotalProductCsvGenerator::getInstance();
return ExportManager::getInstance();
} }
} }

+ 151
- 0
common/logic/Distribution/Distribution/Service/ExportManager.php View File

<?php

namespace common\logic\Distribution\Distribution\Service;

use common\logic\AbstractManager;
use common\logic\Distribution\Distribution\Export\DistributionReport2CsvGenerator;
use common\logic\Distribution\Distribution\Export\DistributionReportCsvGenerator;
use common\logic\Distribution\Distribution\Export\DistributionReportGridPdfGenerator;
use common\logic\Distribution\Distribution\Export\DistributionReportPdfGenerator;
use common\logic\Distribution\Distribution\Export\DistributionReportTotalProductCsvGenerator;
use common\logic\Distribution\Distribution\Export\DistributionShoppingCartLabelsPdfGenerator;
use common\logic\Distribution\Distribution\Model\Distribution;
use common\logic\Producer\Producer\Model\Producer;
use yii\base\ErrorException;
use yii\widgets\ActiveForm;

class ExportManager extends AbstractManager
{
const ORDERS_PDF = 'orders_pdf';
const ORDERS_GRID_PDF = 'orders_grid_pdf';
const ORDERS1_CSV = 'orders1_csv';
const ORDERS2_CSV = 'orders2_csv';
const TOTAL_PRODUCTS_CSV = 'total_products_csv';
const SHOPPING_CART_LABELS_PDF = 'shopping_cart_labels_pdf';

public function getAll(): array
{
return [
self::ORDERS_PDF => [
'Commandes (PDF)',
DistributionReportPdfGenerator::class,
],
self::ORDERS_GRID_PDF => [
'Commandes grille (PDF)',
DistributionReportGridPdfGenerator::class,
],
self::ORDERS1_CSV => [
'Commandes #1 (CSV)',
DistributionReportCsvGenerator::class,
],
self::ORDERS2_CSV => [
'Commandes #2 (CSV)',
DistributionReport2CsvGenerator::class,
],
self::TOTAL_PRODUCTS_CSV => [
'Totaux produits (CSV)',
DistributionReportTotalProductCsvGenerator::class,
],
self::SHOPPING_CART_LABELS_PDF => [
'Étiquettes (PDF)',
DistributionShoppingCartLabelsPdfGenerator::class,
]
];
}

public function getExport(string $exportName): array
{
$exportsArray = $this->getAll();
return $exportsArray[$exportName];
}

public function getExportLabel(string $exportName): string
{
$export = $this->getExport($exportName);
return $export[0];
}

public function generate(string $exportName, Distribution $distribution, bool $save = false)
{
return $this->getGenerator($exportName)->generate($distribution, $save);
}

public function getGenerator(string $exportName)
{
if($this->exist($exportName)) {
$export = $this->getExport($exportName);
$classGenerator = $export[1];
return $classGenerator::getInstance();
}
else {
throw new ErrorException("Cet export n'existe pas.");
}
}

public function exist(string $exportName): bool
{
return array_key_exists($exportName, $this->getAll());
}

public function isEnabled(string $exportName): bool
{
return $this->exist($exportName) && $this->producerHasOptionExportEnabled($exportName);
}

public function getAjaxArray(Distribution $distribution): array
{
$datas = [];
$exportsArray = $this->getAll();

foreach($exportsArray as $exportName => $export) {
if($this->isEnabled($exportName)) {
$datas[] = $this->buildAjaxArray($distribution, $exportName, $export);
}
}

return $datas;
}

public function buildAjaxArray(Distribution $distribution, string $exportName, array $export): array
{
return [
'name' => $exportName,
'label' => $export[0],
'url' => \Yii::$app->urlManagerBackend->createUrl([
'distribution/export',
'date' => $distribution->date,
'name' => $exportName
])
];
}

private function producerHasOptionExportEnabled(string $exportName): bool
{
$producer = $this->getProducerContext();
$fieldOptionExport = $this->getProducerFieldOptionExport($exportName);
return $producer->$fieldOptionExport;
}

private function getProducerFieldOptionExport(string $exportName): string
{
return 'option_distribution_export_'.$exportName;
}

public function getProducerFormCheckboxes(ActiveForm $form, Producer $producer): string
{
$html = '';
$exportsArray = $this->getAll();

foreach($exportsArray as $exportName => $export) {
$html .= $this->getProducerFormCheckbox($form, $producer, $exportName);
}

return $html;
}

public function getProducerFormCheckbox(ActiveForm $form, Producer $producer, string $exportName): string
{
return $form->field($producer, $this->getProducerFieldOptionExport($exportName))
->checkbox(['label' => $this->getExportLabel($exportName)]);
}
}

+ 7
- 2
common/logic/Order/ProductOrder/Service/ProductOrderSolver.php View File



public function getQuantityPriorityPieces(ProductOrder $productOrder): string public function getQuantityPriorityPieces(ProductOrder $productOrder): string
{ {
$quantityPieces = $this->getQuantityPiecesStrict($productOrder);
$quantityPieces = $this->getQuantityPieces($productOrder);
if($quantityPieces) { if($quantityPieces) {
return $quantityPieces; return $quantityPieces;
} }
return $productOrder->quantity.' '.$this->productSolver->strUnit($productOrder->product); return $productOrder->quantity.' '.$this->productSolver->strUnit($productOrder->product);
} }


public function getQuantityPiecesStrict(ProductOrder $productOrder): float
public function getQuantityPieces(ProductOrder $productOrder): float
{ {
if ($productOrder->unit == 'piece') { if ($productOrder->unit == 'piece') {
return $productOrder->quantity; return $productOrder->quantity;
return 0; return 0;
} }


public function getQuantityToCoefficientOfUnit(ProductOrder $productOrder): float
{
return $productOrder->quantity * $this->unitSolver->getUnitCoefficient($productOrder->unit);
}

public function getPriceWithTax(ProductOrder $productOrder) public function getPriceWithTax(ProductOrder $productOrder)
{ {
return Price::getPriceWithTax($productOrder->price, $productOrder->taxRate->value); return Price::getPriceWithTax($productOrder->price, $productOrder->taxRate->value);

+ 15
- 5
common/logic/Producer/Producer/Model/Producer.php View File

'option_export_display_product_reference', 'option_export_display_product_reference',
'option_allow_order_guest', 'option_allow_order_guest',
'option_delivery', 'option_delivery',
'option_display_export_grid',
'option_distribution_export_shopping_cart_labels_pdf',
'option_distribution_export_total_products_csv',
'option_distribution_export_orders1_csv',
'option_distribution_export_orders2_csv',
'option_distribution_export_orders_pdf',
'option_distribution_export_orders_grid_pdf',
'option_stripe_mode_test', 'option_stripe_mode_test',
'option_notify_producer_order_summary', 'option_notify_producer_order_summary',
'option_billing_reduction', 'option_billing_reduction',
'option_dashboard_number_distributions' => 'Nombre de distributions affichées sur le tableau de board', 'option_dashboard_number_distributions' => 'Nombre de distributions affichées sur le tableau de board',
'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_by_piece' => 'Exporter les produits par pièce dans le fichier récapitulatif (CSV)',
'option_export_display_column_delivery_note' => "Commandes (PDF) : afficher une colonne bon de livraison",
'option_csv_export_all_products' => "Commandes #1 (CSV) : exporter tous les produits",
'option_csv_export_by_piece' => 'Commandes #1 (CSV) : exporter les produits par pièce',
'option_order_reference_type' => 'Type de référence', 'option_order_reference_type' => 'Type de référence',
'option_export_display_product_reference' => 'Afficher la référence des produits au moment de l\'export', 'option_export_display_product_reference' => 'Afficher la référence des produits au moment de l\'export',
'option_allow_order_guest' => 'Autoriser les visiteurs à passer commande (création de compte à la fin du tunnel)', 'option_allow_order_guest' => 'Autoriser les visiteurs à passer commande (création de compte à la fin du tunnel)',
'option_order_entry_point' => 'Point d\'entrée par point de vente ou par date', 'option_order_entry_point' => 'Point d\'entrée par point de vente ou par date',
'option_delivery' => 'Proposer la livraison à domicile', 'option_delivery' => 'Proposer la livraison à domicile',
'option_display_export_grid' => 'Afficher l\'export grille dans les distributions',
'option_distribution_export_shopping_cart_labels_pdf' => 'Étiquettes (PDF)',
'option_distribution_export_total_products_csv' => 'Totaux produits (CSV)',
'option_distribution_export_orders1_csv' => 'Commandes 1 (CSV)',
'option_distribution_export_orders2_csv' => 'Commandes 2 (CSV)',
'option_distribution_export_orders_pdf' => 'Commandes (PDF)',
'option_distribution_export_orders_grid_pdf' => 'Commandes grille (PDF)',
'document_display_product_description' => 'Documents : afficher la description des produits', 'document_display_product_description' => 'Documents : afficher la description des produits',
'option_notify_producer_order_summary' => 'Recevoir les récapitulatifs de commande par email', 'option_notify_producer_order_summary' => 'Recevoir les récapitulatifs de commande par email',
'option_billing_type' => 'Type de facturation', 'option_billing_type' => 'Type de facturation',
'admin_comment' => 'Commentaire', 'admin_comment' => 'Commentaire',
'dolibarr_socid' => 'Dolibarr : id user', 'dolibarr_socid' => 'Dolibarr : id user',
'dolibarr_product_id' => 'Dolibarr : id produit', 'dolibarr_product_id' => 'Dolibarr : id produit',
'option_export_display_column_delivery_note' => "Récapitulatif PDF : afficher une colonne bon de livraison",
'option_weeks_distributions_activated_in_advance' => "Semaines de distributions à activer à l'avance", 'option_weeks_distributions_activated_in_advance' => "Semaines de distributions à activer à l'avance",
'option_invoice_only_based_on_delivery_notes' => 'Facturer uniquement sur la base des bons de livraison' 'option_invoice_only_based_on_delivery_notes' => 'Facturer uniquement sur la base des bons de livraison'
]; ];

+ 39
- 0
console/migrations/m231024_062121_add_column_producer_options_exports.php View File

<?php

use yii\db\Migration;
use yii\db\Schema;

/**
* Class m231024_062121_add_column_producer_options_exports
*/
class m231024_062121_add_column_producer_options_exports extends Migration
{
/**
* {@inheritdoc}
*/
public function safeUp()
{
$this->addColumn('producer', 'option_distribution_export_orders_pdf', Schema::TYPE_BOOLEAN.' DEFAULT 1');
$this->addColumn('producer', 'option_distribution_export_orders_grid_pdf', Schema::TYPE_BOOLEAN);
$this->addColumn('producer', 'option_distribution_export_orders1_csv', Schema::TYPE_BOOLEAN.' DEFAULT 1');
$this->addColumn('producer', 'option_distribution_export_orders2_csv', Schema::TYPE_BOOLEAN);
$this->addColumn('producer', 'option_distribution_export_total_products_csv', Schema::TYPE_BOOLEAN);
$this->addColumn('producer', 'option_distribution_export_shopping_cart_labels_pdf', Schema::TYPE_BOOLEAN);

$this->execute("UPDATE producer SET option_distribution_export_orders_grid_pdf = 1 WHERE option_display_export_grid = 1");
$this->dropColumn('producer', 'option_display_export_grid');
}

/**
* {@inheritdoc}
*/
public function safeDown()
{
$this->dropColumn('producer', 'option_distribution_export_shopping_cart_labels_pdf');
$this->dropColumn('producer', 'option_distribution_export_total_products_csv');
$this->dropColumn('producer', 'option_distribution_export_orders1_csv');
$this->dropColumn('producer', 'option_distribution_export_orders2_csv');
$this->dropColumn('producer', 'option_distribution_export_orders_pdf');
$this->dropColumn('producer', 'option_distribution_export_orders_grid_pdf');
}
}

Loading…
Cancel
Save