Browse Source

[Administration] Distribution > export commandes CSV total produits

feature/souke
Guillaume Bourgeois 1 year ago
parent
commit
6022c0196b
4 changed files with 70 additions and 3 deletions
  1. +17
    -2
      backend/controllers/DistributionController.php
  2. +1
    -0
      backend/views/distribution/index.php
  3. +9
    -1
      common/logic/Distribution/Distribution/Module/DistributionModule.php
  4. +43
    -0
      common/logic/Distribution/Distribution/Service/DistributionReportTotalProductCsvGenerator.php

+ 17
- 2
backend/controllers/DistributionController.php View File

'url_export_shopping_cart_labels' => $this->getUrlManagerBackend()->createUrl( 'url_export_shopping_cart_labels' => $this->getUrlManagerBackend()->createUrl(
['distribution/export-shopping-cart-labels', 'date' => $distribution->date] ['distribution/export-shopping-cart-labels', 'date' => $distribution->date]
), ),
'url_report_total_products' => $this->getUrlManagerBackend()->createUrl(
['distribution/report-total-products', 'date' => $distribution->date]
),
'url_order' => $distributionModule->getLinkOrder($distribution), 'url_order' => $distributionModule->getLinkOrder($distribution),
]; ];




if ($distribution) { if ($distribution) {
if ($type == 'pdf') { if ($type == 'pdf') {
return $distributionModule->generateDistributionReportPdf($distribution, $save);
return $distributionModule->getReportPdfGenerator()
->generateDistributionReportPdf($distribution, $save);
} }
elseif ($type == 'csv') { elseif ($type == 'csv') {
$distributionModule->generateDistributionReportCsv($distribution);
$distributionModule->getReportCsvGenerator()
->generateDistributionReportCsv($distribution);
} }
} }
} }
} }
} }


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

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

public function actionExportShoppingCartLabels(string $date) public function actionExportShoppingCartLabels(string $date)
{ {
$distributionModule = $this-> getDistributionModule(); $distributionModule = $this-> getDistributionModule();

+ 1
- 0
backend/views/distribution/index.php View File

<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_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> <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>
</span> </span>
</div> </div>
</div> </div>

+ 9
- 1
common/logic/Distribution/Distribution/Module/DistributionModule.php View File

use common\logic\Distribution\Distribution\Service\DistributionReportCsvGenerator; use common\logic\Distribution\Distribution\Service\DistributionReportCsvGenerator;
use common\logic\Distribution\Distribution\Service\DistributionReportGridPdfGenerator; use common\logic\Distribution\Distribution\Service\DistributionReportGridPdfGenerator;
use common\logic\Distribution\Distribution\Service\DistributionReportPdfGenerator; 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\DistributionShoppingCartLabelsPdfGenerator;
use common\logic\Distribution\Distribution\Service\DistributionSolver; use common\logic\Distribution\Distribution\Service\DistributionSolver;


* @mixin DistributionReportGridPdfGenerator * @mixin DistributionReportGridPdfGenerator
* @mixin DistributionReportPdfGenerator * @mixin DistributionReportPdfGenerator
* @mixin DistributionShoppingCartLabelsPdfGenerator * @mixin DistributionShoppingCartLabelsPdfGenerator
* @mixin DistributionReportTotalProductCsvGenerator
*/ */
class DistributionModule extends AbstractModule class DistributionModule extends AbstractModule
{ {
DistributionReportCsvGenerator::class, DistributionReportCsvGenerator::class,
DistributionReportGridPdfGenerator::class, DistributionReportGridPdfGenerator::class,
DistributionReportPdfGenerator::class, DistributionReportPdfGenerator::class,
DistributionShoppingCartLabelsPdfGenerator::class
DistributionShoppingCartLabelsPdfGenerator::class,
DistributionReportTotalProductCsvGenerator::class
]; ];
} }


{ {
return DistributionShoppingCartLabelsPdfGenerator::getInstance(); return DistributionShoppingCartLabelsPdfGenerator::getInstance();
} }

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

+ 43
- 0
common/logic/Distribution/Distribution/Service/DistributionReportTotalProductCsvGenerator.php View File

<?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\Repository\OrderRepository;
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
{
protected ProductRepository $productRepository;
protected ProductSolver $productSolver;
protected OrderRepository $orderRepository;
protected OrderSolver $orderSolver;

public function loadDependencies(): void
{
$this->productRepository = $this->loadService(ProductRepository::class);
$this->orderRepository = $this->loadService(OrderRepository::class);
$this->productSolver = $this->loadService(ProductSolver::class);
$this->orderSolver = $this->loadService(OrderSolver::class);
}

public function generateCsv(Distribution $distribution)
{
$datas = [];
$productsArray = $this->productRepository->findProductsByDistribution($distribution);
$ordersArray = $this->orderRepository->findOrdersByDistribution($distribution);

foreach($productsArray as $product) {
$datas[] = [
$this->productSolver->getNameExport($product),
$this->orderSolver->getProductQuantityPieces($product, $ordersArray)
];
}

CSV::send('Total_produits_' . $distribution->date . '.csv', $datas);
}
}

Loading…
Cancel
Save