Parcourir la source

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

feature/souke
Guillaume Bourgeois il y a 1 an
Parent
révision
852da18c91
6 fichiers modifiés avec 115 ajouts et 80 suppressions
  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 Voir le fichier

@@ -1,35 +1,18 @@
<?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;

?>
<?php
$i = 0;
foreach($ordersArray as $key => $order):
foreach($ordersArray as $key => $order) {
$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;
} ?>
<?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 Voir le fichier

@@ -6,32 +6,76 @@ 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\OrderSolver;
use common\logic\Producer\Producer\Service\ProducerSolver;
use kartik\mpdf\Pdf;
use yii\helpers\BaseStringHelper;
use yii\helpers\Html;

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

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

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->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,
'format' => Pdf::FORMAT_A4,
'orientation' => Pdf::ORIENT_PORTRAIT,
@@ -40,17 +84,8 @@ class DistributionShoppingCartLabelsPdfGenerator extends AbstractGenerator imple
'@app/web/pdf/Etiquettes-' . $distribution->date . '-' . $this->getProducerContextId() . '.pdf'
),
'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)
@@ -77,9 +112,9 @@ class DistributionShoppingCartLabelsPdfGenerator extends AbstractGenerator imple
return $order->pointSale && $order->pointSale->exclude_export_shopping_cart_labels;
}

public function getCss(): string
public function getCss(bool $isSpecificFormat = false): string
{
return '
$css = '
@page {
margin: 0px 0px 0px 0px !important;
padding: 0px 0px 0px 0px !important;
@@ -90,21 +125,6 @@ class DistributionShoppingCartLabelsPdfGenerator extends AbstractGenerator imple
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 {
font-weight: bold;
font-size: 13px;
@@ -119,7 +139,49 @@ class DistributionShoppingCartLabelsPdfGenerator extends AbstractGenerator imple
.shopping-cart-label .products {
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 Voir le fichier

@@ -48,6 +48,7 @@ class Feature extends ActiveRecordCommon
const ALIAS_CONTACT = 'contact';
const ALIAS_PRODUCT_PRICE_IMPORT = 'product_price_import';
const ALIAS_ONLINE_PAYMENT = 'online_payment';
const ALIAS_EXPORT_SHOPPING_CART_LABELS_ADVANCED = 'export_shopping_cart_labels_advanced';

/**
* @inheritdoc

+ 1
- 1
common/logic/Feature/Feature/Service/FeatureBuilder.php Voir le fichier

@@ -38,7 +38,7 @@ class FeatureBuilder extends AbstractBuilder
public function createFeature(
string $alias,
string $name,
string $description,
string $description = '',
bool $status = true,
bool $isPaidFeature = false,
float $price = null

+ 4
- 12
common/logic/Feature/Feature/Service/FeatureDefinition.php Voir le fichier

@@ -15,18 +15,10 @@ class FeatureDefinition extends AbstractDefinition
public function getFeaturesBase(): array
{
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 Voir le fichier

@@ -19,13 +19,10 @@ class FeatureImporter extends AbstractManager
{
$featuresBaseArray = $this->featureDefinition->getFeaturesBase();

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

Chargement…
Annuler
Enregistrer