|
|
@@ -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)).' • |
|
|
|
'.$order->pointSale->name.' |
|
|
|
</div> |
|
|
|
<div class="products"> |
|
|
|
'.$this->orderRepository->getCartSummary($order).' |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
</div>'; |
|
|
|
} |
|
|
|
} |