Selaa lähdekoodia

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

feature/souke
Guillaume Bourgeois 1 vuosi sitten
vanhempi
commit
2475c6227c
8 muutettua tiedostoa jossa 109 lisäystä ja 44 poistoa
  1. +2
    -1
      backend/controllers/DistributionController.php
  2. +1
    -1
      backend/controllers/FeatureAdminController.php
  3. +3
    -1
      backend/views/distribution/shopping-cart-labels.php
  4. +8
    -2
      backend/views/producer/update.php
  5. +66
    -38
      common/logic/Distribution/Distribution/Export/DistributionShoppingCartLabelsPdfGenerator.php
  6. +1
    -1
      common/logic/Feature/FeatureProducer/Repository/FeatureProducerRepositoryQuery.php
  7. +2
    -0
      common/logic/Producer/Producer/Model/Producer.php
  8. +26
    -0
      console/migrations/m231113_131131_add_column_producer_export_shopping_cart_labels_format.php

+ 2
- 1
backend/controllers/DistributionController.php Näytä tiedosto

@@ -577,7 +577,8 @@ class DistributionController extends BackendController
return $distributionModule->getExportManager()->getGenerator($name)->generate($distribution);
}
catch(ErrorException $exception) {
$this->setFlash('error', "Une erreur est survenue lors de la génération de l'export.");
//$this->setFlash('error', "Une erreur est survenue lors de la génération de l'export.");
$this->setFlash('error', $exception->getMessage());
return $this->redirectReferer();
}
}

+ 1
- 1
backend/controllers/FeatureAdminController.php Näytä tiedosto

@@ -96,7 +96,7 @@ class FeatureAdminController extends BackendController
return Ajax::responseSuccess($messageResponse);
}

public function actionToggleStatusFeatureProducer(int $id, bool $status = null)
public function actionToggleStatusFeatureProducer(int $id, int $status = null)
{
$featureManager = $this->getFeatureModule()->getManager();
$feature = $this->findModel($id);

+ 3
- 1
backend/views/distribution/shopping-cart-labels.php Näytä tiedosto

@@ -7,11 +7,13 @@ $index = 0;
$i = 0;
foreach($ordersArray as $key => $order) {
$index ++;

echo $distributionShoppingCartLabelsPdfGenerator->getShoppingCartLabelAsHtml($order);

if($index == $shoppingCartLabelsPerColumn) {
$index = 0;
}
if($index == 0 && $key !== array_key_last($ordersArray)) {
if(!$isSpecificFormat && $index == 0 && $key !== array_key_last($ordersArray)) {
echo '<columnbreak />';
}
}

+ 8
- 2
backend/views/producer/update.php Näytä tiedosto

@@ -39,6 +39,7 @@
use common\helpers\Dropdown;
use common\helpers\GlobalParam;
use common\logic\Distribution\Distribution\Module\DistributionModule;
use common\logic\Distribution\Distribution\Service\ExportManager;
use common\logic\Feature\Feature\Model\Feature;
use common\logic\Feature\Feature\Module\FeatureModule;
use common\logic\User\User\Module\UserModule;
@@ -307,8 +308,13 @@ $this->addBreadcrumb($this->getTitle());
->dropDownList(Dropdown::noYesChoices()); ?>
<?= $form->field($model, 'option_csv_export_by_piece')
->dropDownList(Dropdown::noYesChoices()); ?>
<?= $form->field($model, 'export_shopping_cart_labels_number_per_column')
->dropDownList(Dropdown::numberChoices(1, 20)); ?>
<?php if($featureManager->isEnabled(Feature::ALIAS_EXPORT_SHOPPING_CART_LABELS_ADVANCED)): ?>
<?= $form->field($model, 'export_shopping_cart_labels_format')
->dropDownList($distributionExportManager->getGenerator(ExportManager::SHOPPING_CART_LABELS_PDF)->populateDropdownSpecificFormats()); ?>
<?php else: ?>
<?= $form->field($model, 'export_shopping_cart_labels_number_per_column')
->dropDownList(Dropdown::numberChoices(1, 20)); ?>
<?php endif; ?>
</div>
</div>


+ 66
- 38
common/logic/Distribution/Distribution/Export/DistributionShoppingCartLabelsPdfGenerator.php Näytä tiedosto

@@ -4,16 +4,21 @@ namespace common\logic\Distribution\Distribution\Export;

use common\logic\AbstractGenerator;
use common\logic\Distribution\Distribution\Model\Distribution;
use common\logic\Feature\Feature\Model\Feature;
use common\logic\Feature\Feature\Service\FeatureManager;
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\base\ErrorException;
use yii\helpers\BaseStringHelper;
use yii\helpers\Html;

class DistributionShoppingCartLabelsPdfGenerator extends AbstractGenerator implements DistributionExportGeneratorInterface
{
const FORMAT_70_42 = '70x42';

protected ProducerSolver $producerSolver;
protected OrderRepository $orderRepository;
protected OrderSolver $orderSolver;
@@ -25,47 +30,44 @@ class DistributionShoppingCartLabelsPdfGenerator extends AbstractGenerator imple
$this->orderSolver = $this->loadService(OrderSolver::class);
}

public function getSpecificFormatDetailsArray(): array
{
return [
self::FORMAT_70_42 => [70, 42]
];
}

public function generate(Distribution $distribution, bool $save = false)
{
$isSpecificFormat = true;
$specificFormatWidth = 42;
$specificFormatHeight = 70;
$specificFormatNumberColumns = 4;
$specificFormatNumberLines = 7;
// @TODO : obligé de charger FeatureManager comme ça car on est dans un service Generator (problème de hiérarchie de services)
$featureManager = FeatureManager::getInstance();
$isSpecificFormat = false;
$exportShoppingCartLabelsFormat = $this->producerSolver->getConfig('export_shopping_cart_labels_format');
if($featureManager->isEnabled(Feature::ALIAS_EXPORT_SHOPPING_CART_LABELS_ADVANCED)) {
if($exportShoppingCartLabelsFormat) {
$isSpecificFormat = true;
[$specificFormatWidth, $specificFormatHeight] = $this->getSpecificFormatDetails($exportShoppingCartLabelsFormat);
}
else {
throw new ErrorException("Aucun format d'étiquette n'est défini dans les paramètres.");
}
}

$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,
'isSpecificFormat' => $isSpecificFormat,
'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();
}
}
}
$pdf = $this->getPdf($distribution, $content, true, $specificFormatWidth, $specificFormatHeight);
}
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 = $this->getPdf($distribution, $content, false);
$pdf->getApi()->SetColumns(4);
$pdf->getApi()->keepColumns = true;
}
@@ -73,7 +75,7 @@ class DistributionShoppingCartLabelsPdfGenerator extends AbstractGenerator imple
return $pdf->render();
}

public function getPdf(Distribution $distribution, bool $isSpecificFormat, string $content = '')
public function getPdf(Distribution $distribution, string $content, bool $isSpecificFormat, float $specificFormatWidth = 0, float $specificFormatHeight = 0)
{
return new Pdf([
'mode' => Pdf::MODE_UTF8,
@@ -84,7 +86,7 @@ class DistributionShoppingCartLabelsPdfGenerator extends AbstractGenerator imple
'@app/web/pdf/Etiquettes-' . $distribution->date . '-' . $this->getProducerContextId() . '.pdf'
),
'content' => $content,
'cssInline' => !$isSpecificFormat ? $this->getCss() : '',
'cssInline' => $this->getCss($isSpecificFormat, $specificFormatWidth, $specificFormatHeight),
]);
}

@@ -112,7 +114,7 @@ class DistributionShoppingCartLabelsPdfGenerator extends AbstractGenerator imple
return $order->pointSale && $order->pointSale->exclude_export_shopping_cart_labels;
}

public function getCss(bool $isSpecificFormat = false): string
public function getCss(bool $isSpecificFormat = false, float $specificFormatWith = 0, float $specificFormatHeight = 0): string
{
$css = '
@page {
@@ -142,11 +144,19 @@ class DistributionShoppingCartLabelsPdfGenerator extends AbstractGenerator imple
}';

if($isSpecificFormat) {

$paddingShoppingCartLabel = 3;
$specificFormatWith = $specificFormatWith - 2 * $paddingShoppingCartLabel;
$specificFormatHeight = $specificFormatHeight - 2 * $paddingShoppingCartLabel;

$css .= '
.shopping-cart-label {
width: 42mm;
height: 70mm;
overflow: hidden;
box-sizing: border-box;
padding: '.$paddingShoppingCartLabel.'mm;
width: '.$specificFormatWith.'mm;
height: '.$specificFormatHeight.'mm;
display: block;
float: left;
}';
}
else {
@@ -184,4 +194,22 @@ class DistributionShoppingCartLabelsPdfGenerator extends AbstractGenerator imple
</div>
</div>';
}

public function getSpecificFormatDetails(string $name): array
{
$specificFormatDetailsArray = $this->getSpecificFormatDetailsArray();
if(!isset($specificFormatDetailsArray[$name])) {
throw new ErrorException("Format d'étiquette inconnu");
}
return $specificFormatDetailsArray[$name];
}

public function populateDropdownSpecificFormats(): array
{
$specificFormatsArray = [null => '--'];
foreach($this->getSpecificFormatDetailsArray() as $key => $specificFormat) {
$specificFormatsArray[$key] = $specificFormat[0].'x'.$specificFormat[1].' mm';
}
return $specificFormatsArray;
}
}

+ 1
- 1
common/logic/Feature/FeatureProducer/Repository/FeatureProducerRepositoryQuery.php Näytä tiedosto

@@ -17,7 +17,7 @@ class FeatureProducerRepositoryQuery extends AbstractRepositoryQuery

public function filterByFeature(Feature $feature): self
{
$this->andWhere(['id_feature' => $feature]);
$this->andWhere(['id_feature' => $feature->id]);
return $this;
}
}

+ 2
- 0
common/logic/Producer/Producer/Model/Producer.php Näytä tiedosto

@@ -241,6 +241,7 @@ class Producer extends ActiveRecordCommon
'option_testimony',
'contact_email',
'admin_comment',
'export_shopping_cart_labels_format',
],
'string'
],
@@ -455,6 +456,7 @@ class Producer extends ActiveRecordCommon
'option_invoice_only_based_on_delivery_notes' => 'Facturer uniquement sur la base des bons de livraison',
'option_document_width_logo' => 'Largeur du logo dans les documents',
'export_shopping_cart_labels_number_per_column' => "Étiquettes (PDF) : nombre d'étiquettes par colonne",
'export_shopping_cart_labels_format' => 'Étiquettes (PDF) : format',
'option_document_display_price_unit_reference' => "Afficher les prix au kilogramme",
'id_user_group_default' => "Groupe utilisateur par défaut attribué à l'inscription",
'option_check_by_default_prevent_user_credit' => "Par défaut, prévenir l'utilisateur quand on crédite son compte"

+ 26
- 0
console/migrations/m231113_131131_add_column_producer_export_shopping_cart_labels_format.php Näytä tiedosto

@@ -0,0 +1,26 @@
<?php

use yii\db\Migration;
use yii\db\Schema;

/**
* Class m231113_131131_add_column_producer_export_shopping_cart_labels_format
*/
class m231113_131131_add_column_producer_export_shopping_cart_labels_format extends Migration
{
/**
* {@inheritdoc}
*/
public function safeUp()
{
$this->addColumn('producer', 'export_shopping_cart_labels_format', Schema::TYPE_STRING);
}

/**
* {@inheritdoc}
*/
public function safeDown()
{
$this->dropColumn('producer', 'export_shopping_cart_labels_format');
}
}

Loading…
Peruuta
Tallenna