|
|
@@ -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; |
|
|
|
} |
|
|
|
} |