@@ -264,6 +264,9 @@ class DistributionController extends BackendController | |||
'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] | |||
), | |||
@@ -618,6 +621,15 @@ class DistributionController extends BackendController | |||
} | |||
} | |||
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) { |
@@ -215,6 +215,7 @@ $this->setPageTitle('Distributions') ; | |||
{{ 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> | |||
<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_export_shopping_cart_labels" class="btn btn-xs btn-default" v-if="countOrders > 0">Étiquettes (PDF)</a> |
@@ -44,8 +44,8 @@ class CSV | |||
{ | |||
public static function send(string $filename, array $data) | |||
{ | |||
CSV::downloadSendHeaders($filename); | |||
echo CSV::array2csv($data); | |||
self::downloadSendHeaders($filename); | |||
echo self::array2csv($data); | |||
die(); | |||
} | |||
@@ -7,6 +7,7 @@ use common\logic\AbstractModule; | |||
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; | |||
@@ -24,6 +25,7 @@ use common\logic\Distribution\Distribution\Service\DistributionSolver; | |||
* @mixin DistributionReportPdfGenerator | |||
* @mixin DistributionShoppingCartLabelsPdfGenerator | |||
* @mixin DistributionReportTotalProductCsvGenerator | |||
* @mixin DistributionReport2CsvGenerator | |||
*/ | |||
class DistributionModule extends AbstractModule | |||
{ | |||
@@ -38,7 +40,8 @@ class DistributionModule extends AbstractModule | |||
DistributionReportGridPdfGenerator::class, | |||
DistributionReportPdfGenerator::class, | |||
DistributionShoppingCartLabelsPdfGenerator::class, | |||
DistributionReportTotalProductCsvGenerator::class | |||
DistributionReportTotalProductCsvGenerator::class, | |||
DistributionReport2CsvGenerator::class, | |||
]; | |||
} | |||
@@ -67,6 +70,11 @@ class DistributionModule extends AbstractModule | |||
return DistributionReportCsvGenerator::getInstance(); | |||
} | |||
public function getReport2CsvGenerator(): DistributionReport2CsvGenerator | |||
{ | |||
return DistributionReport2CsvGenerator::getInstance(); | |||
} | |||
public function getReportGridPdfGenerator(): DistributionReportGridPdfGenerator | |||
{ | |||
return DistributionReportGridPdfGenerator::getInstance(); |
@@ -0,0 +1,96 @@ | |||
<?php | |||
namespace common\logic\Distribution\Distribution\Service; | |||
use common\helpers\CSV; | |||
use common\logic\AbstractGenerator; | |||
use common\logic\Distribution\Distribution\Model\Distribution; | |||
use common\logic\Order\Order\Model\Order; | |||
use common\logic\Order\Order\Repository\OrderRepository; | |||
use common\logic\Order\Order\Service\OrderBuilder; | |||
use common\logic\Order\Order\Service\OrderSolver; | |||
use common\logic\PointSale\PointSale\Model\PointSale; | |||
use common\logic\PointSale\PointSale\Repository\PointSaleRepository; | |||
use common\logic\Producer\Producer\Repository\ProducerRepository; | |||
use common\logic\Producer\Producer\Service\ProducerSolver; | |||
use common\logic\Product\Product\Model\Product; | |||
use common\logic\Product\Product\Repository\ProductRepository; | |||
use common\logic\Product\Product\Service\ProductSolver; | |||
class DistributionReport2CsvGenerator extends AbstractGenerator | |||
{ | |||
protected ProducerRepository $producerRepository; | |||
protected ProductRepository $productRepository; | |||
protected ProductSolver $productSolver; | |||
protected OrderRepository $orderRepository; | |||
protected OrderSolver $orderSolver; | |||
protected PointSaleRepository $pointSaleRepository; | |||
protected OrderBuilder $orderBuilder; | |||
protected ProducerSolver $producerSolver; | |||
public function loadDependencies(): void | |||
{ | |||
$this->producerRepository = $this->loadService(ProducerRepository::class); | |||
$this->productRepository = $this->loadService(ProductRepository::class); | |||
$this->productSolver = $this->loadService(ProductSolver::class); | |||
$this->orderRepository = $this->loadService(OrderRepository::class); | |||
$this->orderSolver = $this->loadService(OrderSolver::class); | |||
$this->pointSaleRepository = $this->loadService(PointSaleRepository::class); | |||
$this->orderBuilder = $this->loadService(OrderBuilder::class); | |||
$this->producerSolver = $this->loadService(ProducerSolver::class); | |||
} | |||
public function generateCsv(Distribution $distribution) | |||
{ | |||
$datas = [['Distribution du '.date('d/m/Y', strtotime($distribution->date))]]; | |||
$ordersArray = $this->orderRepository->findOrdersByDistribution($distribution); | |||
$pointsSaleArray = $this->pointSaleRepository->findPointSales(); | |||
foreach ($pointsSaleArray as $pointSale) { | |||
$this->orderBuilder->initPointSaleOrders($pointSale, $ordersArray); | |||
} | |||
foreach($pointsSaleArray as $pointSale) { | |||
if(count($pointSale->orders)) { | |||
foreach($this->addOrder($pointSale->orders[0], $pointSale) as $line) { | |||
$datas[] = $line; | |||
} | |||
foreach($pointSale->orders as $key => $order) { | |||
if ($key !== array_key_first($pointSale->orders)) { | |||
foreach($this->addOrder($order) as $line) { | |||
$datas[] = $line; | |||
} | |||
} | |||
} | |||
} | |||
} | |||
CSV::send('Commandes.csv', $datas); | |||
} | |||
public function addOrder(Order $order, PointSale $pointSale = null) | |||
{ | |||
$datas = []; | |||
$datas[] = [ | |||
$pointSale ? $pointSale->name : '', | |||
$this->orderSolver->getOrderUsername($order), | |||
1, | |||
$this->productSolver->getNameExport($order->productOrder[0]->product), | |||
$order->user ? "'".$order->user->phone : '', | |||
$this->orderRepository->getPaymentLabelPaid($order), | |||
str_replace('.',',',$this->orderSolver->getOrderAmountWithTax($order)) | |||
]; | |||
foreach($order->productOrder as $key => $productOrder) { | |||
if ($key !== array_key_first($order->productOrder)) { | |||
$datas[] = [ | |||
'', | |||
'', | |||
1, | |||
$this->productSolver->getNameExport($productOrder->product), | |||
]; | |||
} | |||
} | |||
return $datas; | |||
} | |||
} |