@@ -40,6 +40,7 @@ namespace backend\controllers; | |||
use common\helpers\GlobalParam; | |||
use common\helpers\MeanPayment; | |||
use common\logic\Distribution\Distribution\Service\ExportManager; | |||
use common\logic\Order\Order\Model\Order; | |||
use common\logic\User\User\Model\User; | |||
use Yii; | |||
@@ -106,7 +107,7 @@ class CronController extends BackendController | |||
* @param string $key | |||
* @param string $forceDate | |||
*/ | |||
public function actionProcessOrders($key = '', $forceDate = '') | |||
public function actionProcessOrders(string $key = '', string $forceDate = '') | |||
{ | |||
$producerModule = $this->getProducerModule(); | |||
$distributionModule = $this-> getDistributionModule(); | |||
@@ -137,11 +138,7 @@ class CronController extends BackendController | |||
$arrayProducers = $producerModule->findProducers(); | |||
foreach ($arrayProducers as $producer) { | |||
$this->getLogic()->setProducerContext($producer); | |||
$countOrders = 0; | |||
$mailOrdersSend = false; | |||
$distribution = $distributionModule | |||
->findOneDistribution($date, true); | |||
@@ -165,7 +162,6 @@ class CronController extends BackendController | |||
if ($order->auto_payment && $configCredit) { | |||
if ($orderModule->isCreditAutoPayment($order) && $orderModule->getOrderAmount($order, Order::AMOUNT_REMAINING) > 0) { | |||
$paymentManager->payOrder($order, MeanPayment::CREDIT, $userModule->findOneUserById(User::ID_USER_SYSTEM), false); | |||
$countOrders++; | |||
} | |||
} | |||
} | |||
@@ -185,8 +181,8 @@ class CronController extends BackendController | |||
$mail = Yii::$app->mailer->compose( | |||
[ | |||
'html' => 'cronOrdersSummary-html', | |||
'text' => 'cronOrdersSummary-text', | |||
'html' => '@common/mail/cronOrdersSummary-html', | |||
'text' => '@common/mail/cronOrdersSummary-text', | |||
], [ | |||
'date' => $date, | |||
'orders' => $arrayOrders | |||
@@ -197,13 +193,9 @@ class CronController extends BackendController | |||
if (is_array($arrayOrders) && count($arrayOrders)) { | |||
$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( | |||
Yii::getAlias('@app/web/pdf/Commandes-' . $date . '-' . $producer->id . '.pdf') | |||
); | |||
@@ -222,32 +214,9 @@ class CronController extends BackendController | |||
foreach ($userArray as $user) { | |||
if($user->email && strlen($user->email) > 0) { | |||
$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();*/ | |||
} | |||
} | |||
} | |||
} |
@@ -43,12 +43,13 @@ use common\helpers\GlobalParam; | |||
use common\helpers\MeanPayment; | |||
use common\helpers\Price; | |||
use common\logic\Distribution\Distribution\Model\Distribution; | |||
use common\logic\Distribution\Distribution\Service\ExportManager; | |||
use common\logic\Document\DeliveryNote\Model\DeliveryNote; | |||
use common\logic\Order\Order\Model\Order; | |||
use common\logic\Producer\Producer\Model\Producer; | |||
use common\logic\Product\Product\Model\Product; | |||
use DateTime; | |||
use kartik\mpdf\Pdf; | |||
use yii\base\ErrorException; | |||
use yii\base\Exception; | |||
use yii\filters\AccessControl; | |||
@@ -216,7 +217,7 @@ class DistributionController extends BackendController | |||
return [ | |||
'credit' => $producer->credit, | |||
'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 | |||
]; | |||
} | |||
@@ -261,21 +262,7 @@ class DistributionController extends BackendController | |||
$distributionJsonData = [ | |||
'id' => $distribution->id, | |||
'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), | |||
]; | |||
@@ -301,7 +288,6 @@ class DistributionController extends BackendController | |||
public function buildAjaxInfosResponseOrders(array $ordersArray, array $productsArray) | |||
{ | |||
$productModule = $this->getProductModule(); | |||
$userModule = $this->getUserModule(); | |||
$orderModule = $this->getOrderModule(); | |||
$paymentManager = $this->getPaymentModule(); | |||
@@ -579,95 +565,24 @@ class DistributionController extends BackendController | |||
} | |||
/** | |||
* 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(); | |||
$producerModule = $this->getProducerModule(); | |||
$producerCurrent = $producerModule->findOneProducerById($idProducer); | |||
$this->getLogic()->setProducerContext($producerCurrent); | |||
$distribution = $distributionModule->findOneDistribution($date); | |||
$distribution = $distributionModule->getRepository()->findOneDistribution($date); | |||
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) | |||
{ | |||
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; |
@@ -213,13 +213,16 @@ $this->setPageTitle('Distributions') ; | |||
<div class="info-box-content"> | |||
<span class="info-box-text"> | |||
{{ 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> | |||
<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_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> | |||
</div> | |||
</div> | |||
@@ -403,8 +406,6 @@ $this->setPageTitle('Distributions') ; | |||
</div> | |||
<div v-if="order.amount_paid > order.amount"> | |||
<span class="glyphicon glyphicon-alert"></span> Surplus à rembourser | |||
{{ order.amount_paid }} / | |||
{{ order.amount }} | |||
</div> | |||
</td> | |||
<td class="column-credit" v-if="!idActivePointSale || (pointSaleActive && pointSaleActive.credit == 1)"> |
@@ -37,6 +37,8 @@ | |||
*/ | |||
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 yii\helpers\Html; | |||
use yii\widgets\ActiveForm; | |||
@@ -48,6 +50,7 @@ use yii\helpers\ArrayHelper; | |||
\backend\assets\VuejsProducerUpdateAsset::register($this); | |||
$userModule = UserModule::getInstance(); | |||
$userCurrent = GlobalParam::getCurrentUser(); | |||
$distributionExportManager = DistributionModule::getInstance()->getExportManager(); | |||
$this->setTitle('Paramètres'); | |||
$this->addBreadcrumb($this->getTitle()); | |||
@@ -66,7 +69,6 @@ $this->addBreadcrumb($this->getTitle()); | |||
:class="'btn '+((currentSection == section.name) ? 'btn-primary' : 'btn-default')" | |||
@click="changeSection(section)" :href="'#'+section.name"> | |||
{{ section.nameDisplay }} | |||
<span class="glyphicon glyphicon-triangle-bottom"></span> | |||
</a> | |||
</div> | |||
@@ -281,39 +283,6 @@ $this->addBreadcrumb($this->getTitle()); | |||
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> | |||
<?php | |||
$choicesWeeksDistributionsActivatedInAdvanceArray = [null => '--']; | |||
@@ -337,6 +306,39 @@ $this->addBreadcrumb($this->getTitle()); | |||
</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 class="panel-body"> |
@@ -78,7 +78,7 @@ $taxRateModule = $this-> getTaxRateModule(); | |||
]) ?> | |||
<?= $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"> | |||
<?= $form->field($model, 'quantity_max')->textInput() ?> |
@@ -233,11 +233,11 @@ function opendistrib_products_event_unit(change) { | |||
if (unit == 'piece') { | |||
$('.field-product-step').hide(); | |||
$('.field-product-weight label').html('Poids (g)'); | |||
$('.field-product-weight').show(); | |||
//$('.field-product-weight').show(); | |||
} else { | |||
$('.field-product-step').show(); | |||
$('.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'); |
@@ -51,6 +51,11 @@ var app = new Vue({ | |||
nameDisplay: 'Commandes', | |||
isAdminSection: 0 | |||
}, | |||
{ | |||
name: 'exports', | |||
nameDisplay: 'Exports', | |||
isAdminSection: 0 | |||
}, | |||
{ | |||
name: 'credit-payment', | |||
nameDisplay: 'Crédit', |
@@ -346,6 +346,7 @@ a.btn, button.btn { | |||
a { | |||
margin-right: 10px ; | |||
margin-bottom: 10px; | |||
} | |||
} | |||
@@ -0,0 +1,10 @@ | |||
<?php | |||
namespace common\logic\Distribution\Distribution\Export; | |||
use common\logic\Distribution\Distribution\Model\Distribution; | |||
interface DistributionExportGeneratorInterface | |||
{ | |||
public function generate(Distribution $distribution, bool $save = false); | |||
} |
@@ -1,6 +1,6 @@ | |||
<?php | |||
namespace common\logic\Distribution\Distribution\Service; | |||
namespace common\logic\Distribution\Distribution\Export; | |||
use common\helpers\CSV; | |||
use common\logic\AbstractGenerator; | |||
@@ -15,7 +15,7 @@ use common\logic\PointSale\PointSale\Repository\PointSaleRepository; | |||
use common\logic\Producer\Producer\Service\ProducerSolver; | |||
use common\logic\Product\Product\Service\ProductSolver; | |||
class DistributionReport2CsvGenerator extends AbstractGenerator | |||
class DistributionReport2CsvGenerator extends AbstractGenerator implements DistributionExportGeneratorInterface | |||
{ | |||
protected ProductSolver $productSolver; | |||
protected OrderRepository $orderRepository; | |||
@@ -36,7 +36,7 @@ class DistributionReport2CsvGenerator extends AbstractGenerator | |||
$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))]]; | |||
$ordersArray = $this->orderRepository->findOrdersByDistribution($distribution); |
@@ -1,9 +1,10 @@ | |||
<?php | |||
namespace common\logic\Distribution\Distribution\Service; | |||
namespace common\logic\Distribution\Distribution\Export; | |||
use common\helpers\CSV; | |||
use common\logic\AbstractGenerator; | |||
use common\logic\Config\Unit\Service\UnitSolver; | |||
use common\logic\Distribution\Distribution\Model\Distribution; | |||
use common\logic\Order\Order\Repository\OrderRepository; | |||
use common\logic\Order\Order\Service\OrderBuilder; | |||
@@ -15,8 +16,9 @@ use common\logic\Product\Product\Model\Product; | |||
use common\logic\Product\Product\Repository\ProductRepository; | |||
use common\logic\Product\Product\Service\ProductSolver; | |||
class DistributionReportCsvGenerator extends AbstractGenerator | |||
class DistributionReportCsvGenerator extends AbstractGenerator implements DistributionExportGeneratorInterface | |||
{ | |||
protected UnitSolver $unitSolver; | |||
protected ProducerRepository $producerRepository; | |||
protected ProductRepository $productRepository; | |||
protected ProductSolver $productSolver; | |||
@@ -28,6 +30,7 @@ class DistributionReportCsvGenerator extends AbstractGenerator | |||
public function loadDependencies(): void | |||
{ | |||
$this->unitSolver = $this->loadService(UnitSolver::class); | |||
$this->producerRepository = $this->loadService(ProducerRepository::class); | |||
$this->productRepository = $this->loadService(ProductRepository::class); | |||
$this->productSolver = $this->loadService(ProductSolver::class); | |||
@@ -38,7 +41,7 @@ class DistributionReportCsvGenerator extends AbstractGenerator | |||
$this->producerSolver = $this->loadService(ProducerSolver::class); | |||
} | |||
public function generateDistributionReportCsv(Distribution $distribution) | |||
public function generate(Distribution $distribution, bool $save = false) | |||
{ | |||
$datas = []; | |||
$ordersArray = $this->orderRepository->findOrdersByDistribution($distribution); | |||
@@ -72,7 +75,7 @@ class DistributionReportCsvGenerator extends AbstractGenerator | |||
$productUnit = $product->unit; | |||
} | |||
$productName .= ' (' . $this->productSolver->strUnit($productUnit, 'wording_short', true) . ')'; | |||
$productName .= ' (' . $this->unitSolver->strUnit($productUnit, 'wording_short', true) . ')'; | |||
$productsNameArray[] = $productName; | |||
$productsIndexArray[$product->id] = $cpt++; |
@@ -1,6 +1,6 @@ | |||
<?php | |||
namespace common\logic\Distribution\Distribution\Service; | |||
namespace common\logic\Distribution\Distribution\Export; | |||
use common\logic\AbstractGenerator; | |||
use common\logic\Distribution\Distribution\Model\Distribution; | |||
@@ -12,7 +12,7 @@ use common\logic\Product\Product\Repository\ProductRepository; | |||
use common\logic\Product\ProductCategory\Repository\ProductCategoryRepository; | |||
use kartik\mpdf\Pdf; | |||
class DistributionReportGridPdfGenerator extends AbstractGenerator | |||
class DistributionReportGridPdfGenerator extends AbstractGenerator implements DistributionExportGeneratorInterface | |||
{ | |||
protected OrderRepository $orderRepository; | |||
protected OrderBuilder $orderBuilder; | |||
@@ -31,7 +31,7 @@ class DistributionReportGridPdfGenerator extends AbstractGenerator | |||
$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(); | |||
$ordersArray = $this->orderRepository->findOrdersByDistribution($distribution); |
@@ -1,6 +1,6 @@ | |||
<?php | |||
namespace common\logic\Distribution\Distribution\Service; | |||
namespace common\logic\Distribution\Distribution\Export; | |||
use common\helpers\Price; | |||
use common\logic\AbstractGenerator; | |||
@@ -21,7 +21,7 @@ use common\logic\Product\Product\Service\ProductSolver; | |||
use common\logic\User\User\Repository\UserRepository; | |||
use kartik\mpdf\Pdf; | |||
class DistributionReportPdfGenerator extends AbstractGenerator | |||
class DistributionReportPdfGenerator extends AbstractGenerator implements DistributionExportGeneratorInterface | |||
{ | |||
const LIMIT_PRODUCTS = 120; | |||
@@ -50,7 +50,7 @@ class DistributionReportPdfGenerator extends AbstractGenerator | |||
$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(); | |||
$ordersArray = $this->orderRepository->findOrdersByDistribution($distribution); |
@@ -1,6 +1,6 @@ | |||
<?php | |||
namespace common\logic\Distribution\Distribution\Service; | |||
namespace common\logic\Distribution\Distribution\Export; | |||
use common\helpers\CSV; | |||
use common\logic\AbstractGenerator; | |||
@@ -10,7 +10,7 @@ use common\logic\Order\Order\Service\OrderSolver; | |||
use common\logic\Product\Product\Repository\ProductRepository; | |||
use common\logic\Product\Product\Service\ProductSolver; | |||
class DistributionReportTotalProductCsvGenerator extends AbstractGenerator | |||
class DistributionReportTotalProductCsvGenerator extends AbstractGenerator implements DistributionExportGeneratorInterface | |||
{ | |||
protected ProductRepository $productRepository; | |||
protected ProductSolver $productSolver; | |||
@@ -25,7 +25,7 @@ class DistributionReportTotalProductCsvGenerator extends AbstractGenerator | |||
$this->orderSolver = $this->loadService(OrderSolver::class); | |||
} | |||
public function generateCsv(Distribution $distribution) | |||
public function generate(Distribution $distribution, bool $save = false) | |||
{ | |||
$datas = []; | |||
$productsArray = $this->productRepository->findProductsByDistribution($distribution); |
@@ -1,13 +1,13 @@ | |||
<?php | |||
namespace common\logic\Distribution\Distribution\Service; | |||
namespace common\logic\Distribution\Distribution\Export; | |||
use common\logic\AbstractGenerator; | |||
use common\logic\Distribution\Distribution\Model\Distribution; | |||
use common\logic\Order\Order\Repository\OrderRepository; | |||
use kartik\mpdf\Pdf; | |||
class DistributionShoppingCartLabelsPdfGenerator extends AbstractGenerator | |||
class DistributionShoppingCartLabelsPdfGenerator extends AbstractGenerator implements DistributionExportGeneratorInterface | |||
{ | |||
protected OrderRepository $orderRepository; | |||
@@ -16,7 +16,7 @@ class DistributionShoppingCartLabelsPdfGenerator extends AbstractGenerator | |||
$this->orderRepository = $this->loadService(OrderRepository::class); | |||
} | |||
public function generateDistributionShoppingCartLabelsPdf(Distribution $distribution) | |||
public function generate(Distribution $distribution, bool $save = false) | |||
{ | |||
$ordersArray = $this->orderRepository->findOrdersByDistribution($distribution); | |||
@@ -2,30 +2,25 @@ | |||
namespace common\logic\Distribution\Distribution\Module; | |||
use common\logic\AbstractManager; | |||
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\Service\DistributionBuilder; | |||
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\ExportManager; | |||
/** | |||
* @mixin DistributionDefinition | |||
* @mixin DistributionSolver | |||
* @mixin DistributionRepository | |||
* @mixin DistributionBuilder | |||
* @mixin DistributionReportCsvGenerator | |||
* @mixin DistributionReportGridPdfGenerator | |||
* @mixin DistributionReportPdfGenerator | |||
* @mixin DistributionShoppingCartLabelsPdfGenerator | |||
* @mixin DistributionReportTotalProductCsvGenerator | |||
* @mixin DistributionReport2CsvGenerator | |||
* @mixin ExportManager | |||
*/ | |||
class DistributionModule extends AbstractModule | |||
{ | |||
@@ -36,12 +31,14 @@ class DistributionModule extends AbstractModule | |||
DistributionSolver::class, | |||
DistributionRepository::class, | |||
DistributionBuilder::class, | |||
ExportManager::class, | |||
DistributionReport2CsvGenerator::class, | |||
DistributionReportCsvGenerator::class, | |||
DistributionReportGridPdfGenerator::class, | |||
DistributionReportPdfGenerator::class, | |||
DistributionShoppingCartLabelsPdfGenerator::class, | |||
DistributionReportTotalProductCsvGenerator::class, | |||
DistributionReport2CsvGenerator::class, | |||
DistributionShoppingCartLabelsPdfGenerator::class | |||
]; | |||
} | |||
@@ -65,33 +62,8 @@ class DistributionModule extends AbstractModule | |||
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(); | |||
} | |||
} |
@@ -0,0 +1,151 @@ | |||
<?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)]); | |||
} | |||
} |
@@ -23,7 +23,7 @@ class ProductOrderSolver extends AbstractService implements SolverInterface | |||
public function getQuantityPriorityPieces(ProductOrder $productOrder): string | |||
{ | |||
$quantityPieces = $this->getQuantityPiecesStrict($productOrder); | |||
$quantityPieces = $this->getQuantityPieces($productOrder); | |||
if($quantityPieces) { | |||
return $quantityPieces; | |||
} | |||
@@ -37,7 +37,7 @@ class ProductOrderSolver extends AbstractService implements SolverInterface | |||
return $productOrder->quantity.' '.$this->productSolver->strUnit($productOrder->product); | |||
} | |||
public function getQuantityPiecesStrict(ProductOrder $productOrder): float | |||
public function getQuantityPieces(ProductOrder $productOrder): float | |||
{ | |||
if ($productOrder->unit == 'piece') { | |||
return $productOrder->quantity; | |||
@@ -51,6 +51,11 @@ class ProductOrderSolver extends AbstractService implements SolverInterface | |||
return 0; | |||
} | |||
public function getQuantityToCoefficientOfUnit(ProductOrder $productOrder): float | |||
{ | |||
return $productOrder->quantity * $this->unitSolver->getUnitCoefficient($productOrder->unit); | |||
} | |||
public function getPriceWithTax(ProductOrder $productOrder) | |||
{ | |||
return Price::getPriceWithTax($productOrder->price, $productOrder->taxRate->value); |
@@ -261,7 +261,12 @@ class Producer extends ActiveRecordCommon | |||
'option_export_display_product_reference', | |||
'option_allow_order_guest', | |||
'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_notify_producer_order_summary', | |||
'option_billing_reduction', | |||
@@ -402,14 +407,20 @@ class Producer extends ActiveRecordCommon | |||
'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_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_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_order_entry_point' => 'Point d\'entrée par point de vente ou par date', | |||
'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', | |||
'option_notify_producer_order_summary' => 'Recevoir les récapitulatifs de commande par email', | |||
'option_billing_type' => 'Type de facturation', | |||
@@ -434,7 +445,6 @@ class Producer extends ActiveRecordCommon | |||
'admin_comment' => 'Commentaire', | |||
'dolibarr_socid' => 'Dolibarr : id user', | |||
'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_invoice_only_based_on_delivery_notes' => 'Facturer uniquement sur la base des bons de livraison' | |||
]; |
@@ -0,0 +1,39 @@ | |||
<?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'); | |||
} | |||
} |