Browse Source

[Administration] Export : étiquettes avancées #1416

feature/souke
Guillaume Bourgeois 1 year ago
parent
commit
852da18c91
6 changed files with 115 additions and 80 deletions
  1. +11
    -28
      backend/views/distribution/shopping-cart-labels.php
  2. +96
    -34
      common/logic/Distribution/Distribution/Export/DistributionShoppingCartLabelsPdfGenerator.php
  3. +1
    -0
      common/logic/Feature/Feature/Model/Feature.php
  4. +1
    -1
      common/logic/Feature/Feature/Service/FeatureBuilder.php
  5. +4
    -12
      common/logic/Feature/Feature/Service/FeatureDefinition.php
  6. +2
    -5
      common/logic/Feature/Feature/Service/FeatureImporter.php

+ 11
- 28
backend/views/distribution/shopping-cart-labels.php View File

<?php <?php


use common\logic\Order\Order\Module\OrderModule;
use yii\helpers\Html;
use common\logic\Distribution\Distribution\Export\DistributionShoppingCartLabelsPdfGenerator;


$orderModule = OrderModule::getInstance();
$distributionShoppingCartLabelsPdfGenerator = DistributionShoppingCartLabelsPdfGenerator::getInstance();
$index = 0; $index = 0;

?>
<?php
$i = 0; $i = 0;
foreach($ordersArray as $key => $order):
foreach($ordersArray as $key => $order) {
$index ++; $index ++;
?>
<div class="shopping-cart-label">
<div class="inner">
<div class="username">
<?= $orderModule->getOrderUsername($order); ?>
</div>
<div class="point-sale">
<?= date('d/m', strtotime($distribution->date)); ?> &bull;
<?= Html::encode($order->pointSale->name); ?>
</div>
<div class="products">
<?= $orderModule->getCartSummary($order); ?>
</div>
</div>
</div>
<?php if($index == $shoppingCartLabelsPerColumn) {
echo $distributionShoppingCartLabelsPdfGenerator->getShoppingCartLabelAsHtml($order);
if($index == $shoppingCartLabelsPerColumn) {
$index = 0; $index = 0;
} ?>
<?php if($index == 0 && $key !== array_key_last($ordersArray)): ?>
<columnbreak />
<?php endif; ?>
<?php endforeach; ?>
}
if($index == 0 && $key !== array_key_last($ordersArray)) {
echo '<columnbreak />';
}
}
?>

+ 96
- 34
common/logic/Distribution/Distribution/Export/DistributionShoppingCartLabelsPdfGenerator.php View File

use common\logic\Distribution\Distribution\Model\Distribution; use common\logic\Distribution\Distribution\Model\Distribution;
use common\logic\Order\Order\Model\Order; use common\logic\Order\Order\Model\Order;
use common\logic\Order\Order\Repository\OrderRepository; use common\logic\Order\Order\Repository\OrderRepository;
use common\logic\Order\Order\Service\OrderSolver;
use common\logic\Producer\Producer\Service\ProducerSolver; use common\logic\Producer\Producer\Service\ProducerSolver;
use kartik\mpdf\Pdf; use kartik\mpdf\Pdf;
use yii\helpers\BaseStringHelper;
use yii\helpers\Html;


class DistributionShoppingCartLabelsPdfGenerator extends AbstractGenerator implements DistributionExportGeneratorInterface class DistributionShoppingCartLabelsPdfGenerator extends AbstractGenerator implements DistributionExportGeneratorInterface
{ {
protected ProducerSolver $producerSolver; protected ProducerSolver $producerSolver;
protected OrderRepository $orderRepository; protected OrderRepository $orderRepository;
protected OrderSolver $orderSolver;


public function loadDependencies(): void public function loadDependencies(): void
{ {
$this->producerSolver = $this->loadService(ProducerSolver::class); $this->producerSolver = $this->loadService(ProducerSolver::class);
$this->orderRepository = $this->loadService(OrderRepository::class); $this->orderRepository = $this->loadService(OrderRepository::class);
$this->orderSolver = $this->loadService(OrderSolver::class);
} }


public function generate(Distribution $distribution, bool $save = false) public function generate(Distribution $distribution, bool $save = false)
{ {
$isSpecificFormat = true;
$specificFormatWidth = 42;
$specificFormatHeight = 70;
$specificFormatNumberColumns = 4;
$specificFormatNumberLines = 7;

$ordersArray = $this->orderRepository->findOrdersByDistribution($distribution); $ordersArray = $this->orderRepository->findOrdersByDistribution($distribution);
$ordersArray = $this->filterOrdersExcludedUsersAndPointSales($ordersArray); $ordersArray = $this->filterOrdersExcludedUsersAndPointSales($ordersArray);


$content = \Yii::$app->getView()->render('@backend/views/distribution/shopping-cart-labels.php', [
'distribution' => $distribution,
'ordersArray' => $ordersArray,
'shoppingCartLabelsPerColumn' => $this->producerSolver->getConfig('export_shopping_cart_labels_number_per_column') ?: 8
]);
if($isSpecificFormat) {
$pdf = $this->getPdf($distribution, true);
$pdf->getApi()->WriteHTML($this->getCss(true), 1);

$x = 0;
$y = 0;
$pdf->getApi()->AddPage();

foreach($ordersArray as $order) {
$pdf->getApi()->SetXY($x * $specificFormatWidth, $y * $specificFormatHeight);
$pdf->getApi()->WriteHTML($this->getShoppingCartLabelAsHtml($order));

$y ++;
if($y == $specificFormatNumberLines) {
$y = 0;
$x ++;
if($x == $specificFormatNumberColumns) {
$x = 0;
$pdf->getApi()->AddPage();
}
}
}
}
else {
$content = \Yii::$app->getView()->render('@backend/views/distribution/shopping-cart-labels.php', [
'distribution' => $distribution,
'ordersArray' => $ordersArray,
'shoppingCartLabelsPerColumn' => $this->producerSolver->getConfig('export_shopping_cart_labels_number_per_column') ?: 8
]);
$pdf = $this->getPdf($distribution, false, $content);
$pdf->getApi()->SetColumns(4);
$pdf->getApi()->keepColumns = true;
}

return $pdf->render();
}


$pdf = new Pdf([
public function getPdf(Distribution $distribution, bool $isSpecificFormat, string $content = '')
{
return new Pdf([
'mode' => Pdf::MODE_UTF8, 'mode' => Pdf::MODE_UTF8,
'format' => Pdf::FORMAT_A4, 'format' => Pdf::FORMAT_A4,
'orientation' => Pdf::ORIENT_PORTRAIT, 'orientation' => Pdf::ORIENT_PORTRAIT,
'@app/web/pdf/Etiquettes-' . $distribution->date . '-' . $this->getProducerContextId() . '.pdf' '@app/web/pdf/Etiquettes-' . $distribution->date . '-' . $this->getProducerContextId() . '.pdf'
), ),
'content' => $content, 'content' => $content,
'cssInline' => $this->getCss(),
'methods' => [
'SetHeader' => ['Étiquettes du ' . date('d/m/Y', strtotime($distribution->date))],
'SetFooter' => ['{PAGENO}'],
],
'cssInline' => !$isSpecificFormat ? $this->getCss() : '',
]); ]);

$pdf->getApi()->SetColumns(4);
$pdf->getApi()->keepColumns = true;

return $pdf->render();
} }


public function filterOrdersExcludedUsersAndPointSales(array $ordersArray) public function filterOrdersExcludedUsersAndPointSales(array $ordersArray)
return $order->pointSale && $order->pointSale->exclude_export_shopping_cart_labels; return $order->pointSale && $order->pointSale->exclude_export_shopping_cart_labels;
} }


public function getCss(): string
public function getCss(bool $isSpecificFormat = false): string
{ {
return '
$css = '
@page { @page {
margin: 0px 0px 0px 0px !important; margin: 0px 0px 0px 0px !important;
padding: 0px 0px 0px 0px !important; padding: 0px 0px 0px 0px !important;
font-size: 13px; font-size: 13px;
} }
.clr {
clear: both;
}
.shopping-cart-label {
-webkit-column-break-inside:avoid;
column-break-inside: avoid;
-webkit-page-break-inside:avoid;
page-break-inside: avoid;
}
.shopping-cart-label .inner {
padding: 8px;
}
.shopping-cart-label .username { .shopping-cart-label .username {
font-weight: bold; font-weight: bold;
font-size: 13px; font-size: 13px;
.shopping-cart-label .products { .shopping-cart-label .products {
font-size: 10px; font-size: 10px;
}';

if($isSpecificFormat) {
$css .= '
.shopping-cart-label {
width: 42mm;
height: 70mm;
overflow: hidden;
}';
}
else {
$css .= '
.shopping-cart-label {
-webkit-column-break-inside:avoid;
column-break-inside: avoid;
-webkit-page-break-inside:avoid;
page-break-inside: avoid;
}
.shopping-cart-label .inner {
padding: 8px;
} }
';
';
}

return $css;
}

public function getShoppingCartLabelAsHtml(Order $order): string
{
return '<div class="shopping-cart-label">
<div class="inner">
<div class="username">
'.$this->orderSolver->getOrderUsername($order).'
</div>
<div class="point-sale">
'.date('d/m', strtotime($order->distribution->date)).' &bull;
'.$order->pointSale->name.'
</div>
<div class="products">
'.$this->orderRepository->getCartSummary($order).'
</div>
</div>
</div>';
} }
} }

+ 1
- 0
common/logic/Feature/Feature/Model/Feature.php View File

const ALIAS_CONTACT = 'contact'; const ALIAS_CONTACT = 'contact';
const ALIAS_PRODUCT_PRICE_IMPORT = 'product_price_import'; const ALIAS_PRODUCT_PRICE_IMPORT = 'product_price_import';
const ALIAS_ONLINE_PAYMENT = 'online_payment'; const ALIAS_ONLINE_PAYMENT = 'online_payment';
const ALIAS_EXPORT_SHOPPING_CART_LABELS_ADVANCED = 'export_shopping_cart_labels_advanced';


/** /**
* @inheritdoc * @inheritdoc

+ 1
- 1
common/logic/Feature/Feature/Service/FeatureBuilder.php View File

public function createFeature( public function createFeature(
string $alias, string $alias,
string $name, string $name,
string $description,
string $description = '',
bool $status = true, bool $status = true,
bool $isPaidFeature = false, bool $isPaidFeature = false,
float $price = null float $price = null

+ 4
- 12
common/logic/Feature/Feature/Service/FeatureDefinition.php View File

public function getFeaturesBase(): array public function getFeaturesBase(): array
{ {
return [ return [
Feature::ALIAS_CONTACT => $this->buildFeatureArray('Formulaire de contact', true, false),
Feature::ALIAS_PRODUCT_PRICE_IMPORT => $this->buildFeatureArray('Produits : import prix', true, false),
Feature::ALIAS_ONLINE_PAYMENT => $this->buildFeatureArray('Paiement en ligne', true, false),
];
}

public function buildFeatureArray(string $name, bool $status, bool $isPaidFeature): array
{
return [
'name' => $name,
'status' => $status,
'is_paid_feature' => $isPaidFeature
Feature::ALIAS_CONTACT => 'Formulaire de contact',
Feature::ALIAS_PRODUCT_PRICE_IMPORT => 'Produits : import prix',
Feature::ALIAS_ONLINE_PAYMENT => 'Paiement en ligne',
Feature::ALIAS_EXPORT_SHOPPING_CART_LABELS_ADVANCED => "Génération d'étiquettes avec un format spécifique",
]; ];
} }
} }

+ 2
- 5
common/logic/Feature/Feature/Service/FeatureImporter.php View File

{ {
$featuresBaseArray = $this->featureDefinition->getFeaturesBase(); $featuresBaseArray = $this->featureDefinition->getFeaturesBase();


foreach($featuresBaseArray as $alias => $featureBase) {
foreach($featuresBaseArray as $alias => $featureBaseName) {
$this->featureBuilder->createFeature( $this->featureBuilder->createFeature(
$alias, $alias,
$featureBase['name'],
'',
$featureBase['status'],
$featureBase['is_paid_feature']
$featureBaseName
); );
} }
} }

Loading…
Cancel
Save