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