$productOrderArray[$product['id']] = [ | $productOrderArray[$product['id']] = [ | ||||
'quantity' => 0, | 'quantity' => 0, | ||||
'unit' => $product['unit'], | 'unit' => $product['unit'], | ||||
'price' => number_format($product['price'], 3), | |||||
'price' => number_format($product['price'], 5), | |||||
'price_with_tax' => Price::getPriceWithTax($product['price'], $product['taxRate']['value']), | 'price_with_tax' => Price::getPriceWithTax($product['price'], $product['taxRate']['value']), | ||||
]; | ]; | ||||
} | } | ||||
$productOrderArray[$product['id']] = [ | $productOrderArray[$product['id']] = [ | ||||
'quantity' => 0, | 'quantity' => 0, | ||||
'unit' => $product['unit'], | 'unit' => $product['unit'], | ||||
//'price' => Price::getPriceWithTax($product['price'], $product['taxRate']['value']), | |||||
'price' => number_format($product['price'], 5), | |||||
'price_with_tax' => Price::getPriceWithTax($product['price'], $product['taxRate']['value']), | |||||
]; | ]; | ||||
} | } | ||||
return [ | return [ | ||||
'id_point_sale' => $pointSaleDefault ? $pointSaleDefault->id : false, | |||||
'id_point_sale' => $pointSaleDefault ? $pointSaleDefault->id : 0, | |||||
'id_user' => 0, | 'id_user' => 0, | ||||
'username' => '', | 'username' => '', | ||||
'comment' => '', | 'comment' => '', | ||||
foreach ($order->productOrder as $productOrder) { | foreach ($order->productOrder as $productOrder) { | ||||
if ($productOrder->id_product == $product['id']) { | if ($productOrder->id_product == $product['id']) { | ||||
if ($productOrder->invoice_price) { | if ($productOrder->invoice_price) { | ||||
$invoicePrice = number_format($productOrder->invoice_price, 3); | |||||
$invoicePrice = number_format($productOrder->invoice_price, 5); | |||||
} else { | } else { | ||||
$invoicePrice = number_format($productOrder->price, 3); | |||||
$invoicePrice = number_format($productOrder->price, 5); | |||||
} | } | ||||
$quantity = $productOrder->quantity; | $quantity = $productOrder->quantity; | ||||
} | } | ||||
$distributionManager->generateDistributionReportCsv($distribution); | $distributionManager->generateDistributionReportCsv($distribution); | ||||
} | } | ||||
} | } | ||||
return null; | |||||
} | } | ||||
public function actionReportGrid($date = '', $save = false, $idProducer = 0, $type = "pdf") | |||||
public function actionReportGrid(string $date = '', bool $save = false, int $idProducer = 0) | |||||
{ | { | ||||
$producerManager = $this->getProducerManager(); | |||||
$productDistribution = $this->getProductDistributionManager(); | |||||
$orderManager = $this->getOrderManager(); | |||||
$productCategoryManager = $this->getProductCategoryManager(); | |||||
if (!\Yii::$app->user->isGuest) { | |||||
$idProducer = GlobalParam::getCurrentProducerId(); | |||||
if (!$idProducer) { | |||||
$idProducer = $this->getProducerCurrent()->id; | |||||
} | } | ||||
$distribution = Distribution::searchOne([ | |||||
'id_producer' => $idProducer | |||||
], [ | |||||
'conditions' => 'date LIKE :date', | |||||
'params' => [':date' => $date] | |||||
]); | |||||
$distributionManager = $this->getDistributionManager(); | |||||
$producerManager = $this->getProducerManager(); | |||||
$producerCurrent = $producerManager->findOneProducerById($idProducer); | |||||
$this->getLogic()->setProducerContext($producerCurrent); | |||||
$distribution = $distributionManager->findOneDistribution($date); | |||||
if ($distribution) { | if ($distribution) { | ||||
$ordersArray = Order::searchAll( | |||||
[ | |||||
'distribution.date' => $date, | |||||
'distribution.id_producer' => $idProducer | |||||
], | |||||
[ | |||||
'orderby' => 'user.lastname ASC, user.name ASC, comment_point_sale ASC', | |||||
'conditions' => 'date_delete IS NULL' | |||||
] | |||||
); | |||||
$selectedProductsArray = $productDistribution->findProductDistributionsByDistribution($distribution); | |||||
$pointsSaleArray = PointSale::searchAll([ | |||||
'point_sale.id_producer' => $idProducer | |||||
]); | |||||
foreach ($pointsSaleArray as $pointSale) { | |||||
$orderManager->initPointSaleOrders($pointSale, $ordersArray); | |||||
} | |||||
$ordersByPage = 22; | |||||
$nbPages = ceil(count($ordersArray) / $ordersByPage); | |||||
$ordersArrayPaged = []; | |||||
foreach ($pointsSaleArray as $pointSale) { | |||||
$index = 0; | |||||
$indexPage = 0; | |||||
foreach ($pointSale->orders as $order) { | |||||
if (!isset($ordersArrayPaged[$pointSale->id])) { | |||||
$ordersArrayPaged[$pointSale->id] = []; | |||||
} | |||||
if (!isset($ordersArrayPaged[$pointSale->id][$indexPage])) { | |||||
$ordersArrayPaged[$pointSale->id][$indexPage] = []; | |||||
} | |||||
$ordersArrayPaged[$pointSale->id][$indexPage][] = $order; | |||||
$index++; | |||||
if ($index == $ordersByPage) { | |||||
$index = 0; | |||||
$indexPage++; | |||||
} | |||||
} | |||||
} | |||||
// catégories | |||||
$categoriesArray = $productCategoryManager->findProductCategories(); | |||||
array_unshift($categoriesArray, null); | |||||
// produits | |||||
$productsArray = Product::find() | |||||
->joinWith([ | |||||
'productDistribution' => function ($q) use ($distribution) { | |||||
$q->where(['id_distribution' => $distribution->id]); | |||||
} | |||||
]) | |||||
->where([ | |||||
'id_producer' => $idProducer, | |||||
]) | |||||
->orderBy('order ASC') | |||||
->all(); | |||||
$viewPdf = 'report-grid'; | |||||
$orientationPdf = Pdf::ORIENT_PORTRAIT; | |||||
$producer = GlobalParam::getCurrentProducer(); | |||||
if ($producer->slug == 'bourlinguepacotille') { | |||||
$viewPdf = 'report-bourlingue'; | |||||
$orientationPdf = Pdf::ORIENT_LANDSCAPE; | |||||
} | |||||
// get your HTML raw content without any layouts or scripts | |||||
$content = $this->renderPartial($viewPdf, [ | |||||
'date' => $date, | |||||
'distribution' => $distribution, | |||||
'selectedProductsArray' => $selectedProductsArray, | |||||
'pointsSaleArray' => $pointsSaleArray, | |||||
'categoriesArray' => $categoriesArray, | |||||
'productsArray' => $productsArray, | |||||
'ordersArray' => $ordersArrayPaged, | |||||
'producer' => $producerManager->findOneProducerById($idProducer) | |||||
]); | |||||
$dateStr = date('d/m/Y', strtotime($date)); | |||||
if ($save) { | |||||
$destination = Pdf::DEST_FILE; | |||||
} else { | |||||
$destination = Pdf::DEST_BROWSER; | |||||
} | |||||
$pdf = new Pdf([ | |||||
// set to use core fonts only | |||||
'mode' => Pdf::MODE_UTF8, | |||||
// A4 paper format | |||||
'format' => Pdf::FORMAT_A4, | |||||
// portrait orientation | |||||
'orientation' => $orientationPdf, | |||||
// stream to browser inline | |||||
'destination' => $destination, | |||||
'filename' => \Yii::getAlias( | |||||
'@app/web/pdf/Commandes-' . $date . '-' . $idProducer . '.pdf' | |||||
), | |||||
// your html content input | |||||
'content' => $content, | |||||
// format content from your own css file if needed or use the | |||||
// enhanced bootstrap css built by Krajee for mPDF formatting | |||||
//'cssFile' => Yii::getAlias('@web/css/distribution/report.css'), | |||||
// any css to be embedded if required | |||||
'cssInline' => ' | |||||
table { | |||||
border-spacing : 0px ; | |||||
border-collapse : collapse ; | |||||
width: 100% ; | |||||
} | |||||
table tr th, | |||||
table tr td { | |||||
padding: 0px ; | |||||
margin: 0px ; | |||||
border: solid 1px #e0e0e0 ; | |||||
padding: 3px ; | |||||
vertical-align : top; | |||||
page-break-inside: avoid !important; | |||||
} | |||||
table tr th { | |||||
font-size: 10px ; | |||||
} | |||||
table tr td { | |||||
font-size: 10px ; | |||||
} | |||||
table thead tr { | |||||
line-height: 220px; | |||||
text-align:left; | |||||
} | |||||
.th-user, | |||||
.td-nb-products { | |||||
/* width: 35px ; */ | |||||
text-align: center ; | |||||
} | |||||
.th-user { | |||||
padding: 10px ; | |||||
} | |||||
.category-name { | |||||
font-weight: bold ; | |||||
} | |||||
', | |||||
// set mPDF properties on the fly | |||||
//'options' => ['title' => 'Krajee Report Title'], | |||||
// call mPDF methods on the fly | |||||
'methods' => [ | |||||
'SetHeader' => ['Commandes du ' . $dateStr], | |||||
'SetFooter' => ['{PAGENO}'], | |||||
] | |||||
]); | |||||
// return the pdf output as per the destination setting | |||||
return $pdf->render(); | |||||
return $distributionManager->generateDistributionReportGridPdf($distribution, $save); | |||||
} | } | ||||
} | } | ||||
public function actionAjaxProcessProductQuantityMax($idDistribution, $idProduct, $quantityMax) | public function actionAjaxProcessProductQuantityMax($idDistribution, $idProduct, $quantityMax) | ||||
{ | { | ||||
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; | \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; | ||||
$productDistributionManager = $this->getProductDistributionManager(); | $productDistributionManager = $this->getProductDistributionManager(); | ||||
$productDistribution = $this->getProductDistribution($idProduct, $idDistribution); | $productDistribution = $this->getProductDistribution($idProduct, $idDistribution); | ||||
$productDistribution->quantity_max = ($quantityMax == -1) ? null : (float) abs($quantityMax); | |||||
$productDistributionManager->update($productDistribution); | |||||
$productDistributionManager->updateProductDistributionQuantityMax($productDistribution, $quantityMax); | |||||
return ['success']; | return ['success']; | ||||
} | } | ||||
public function actionAjaxProcessActiveProduct($idDistribution, $idProduct, $active) | |||||
public function actionAjaxProcessActiveProduct(int $idDistribution, int $idProduct, int $active) | |||||
{ | { | ||||
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; | \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; | ||||
$productDistributionManager = $this->getProductDistributionManager(); | $productDistributionManager = $this->getProductDistributionManager(); | ||||
$productDistribution = $this->getProductDistribution($idProduct, $idDistribution); | $productDistribution = $this->getProductDistribution($idProduct, $idDistribution); | ||||
$productDistribution->active = $active; | |||||
$productDistributionManager->update($productDistribution); | |||||
$productDistributionManager->updateProductDistributionActive($productDistribution, $active); | |||||
return ['success']; | return ['success']; | ||||
} | } | ||||
public function actionAjaxProcessActivePointSale($idDistribution, $idPointSale, $delivery) | |||||
public function actionAjaxProcessActivePointSale(int $idDistribution, int $idPointSale, int $delivery) | |||||
{ | { | ||||
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; | \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; | ||||
* @param boolean $active | * @param boolean $active | ||||
* @return array | * @return array | ||||
*/ | */ | ||||
public function actionAjaxProcessActiveDistribution($idDistribution = 0, $date = '', $active) | |||||
public function actionAjaxProcessActiveDistribution(int $idDistribution = 0, string $date = '', bool $active = false) | |||||
{ | { | ||||
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; | \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; | ||||
$distributionManager = $this->getDistributionManager(); | $distributionManager = $this->getDistributionManager(); | ||||
$producerCurrent = $this->getProducerCurrent(); | |||||
if ($idDistribution) { | if ($idDistribution) { | ||||
$distribution = $distributionManager->findOneDistributionById($idDistribution); | $distribution = $distributionManager->findOneDistributionById($idDistribution); | ||||
$distribution = $distributionManager->createDistributionIfNotExist($date); | $distribution = $distributionManager->createDistributionIfNotExist($date); | ||||
} | } | ||||
if ($distribution) { | |||||
if (isset($distribution) && $distribution) { | |||||
$distributionManager->activeDistribution($distribution, $active); | $distributionManager->activeDistribution($distribution, $active); | ||||
return ['success']; | return ['success']; | ||||
} | } |
price = getPrice(priceWithTax, taxRateValue); | price = getPrice(priceWithTax, taxRateValue); | ||||
} | } | ||||
else { | else { | ||||
price = priceValue.toFixed(3); | |||||
price = priceValue.toFixed(5); | |||||
priceWithTax = getPriceWithTax(price, taxRateValue); | priceWithTax = getPriceWithTax(price, taxRateValue); | ||||
} | } | ||||
<?php | |||||
namespace common\logic\Distribution\Distribution\Service; | |||||
use common\logic\AbstractGenerator; | |||||
class DistributionReportGridCsvGenerator extends AbstractGenerator | |||||
{ | |||||
} |
<?php | |||||
namespace common\logic\Distribution\Distribution\Service; | |||||
use common\logic\AbstractGenerator; | |||||
use common\logic\Distribution\Distribution\Model\Distribution; | |||||
use common\logic\Distribution\ProductDistribution\Repository\ProductDistributionRepository; | |||||
use common\logic\Order\Order\Repository\OrderRepository; | |||||
use common\logic\Order\Order\Service\OrderBuilder; | |||||
use common\logic\PointSale\PointSale\Repository\PointSaleRepository; | |||||
use common\logic\Product\Product\Repository\ProductRepository; | |||||
use common\logic\Product\ProductCategory\Repository\ProductCategoryRepository; | |||||
use kartik\mpdf\Pdf; | |||||
class DistributionReportGridPdfGenerator extends AbstractGenerator | |||||
{ | |||||
protected OrderRepository $orderRepository; | |||||
protected OrderBuilder $orderBuilder; | |||||
protected ProductDistributionRepository $productDistributionRepository; | |||||
protected PointSaleRepository $pointSaleRepository; | |||||
protected ProductCategoryRepository $productCategoryRepository; | |||||
protected ProductRepository $productRepository; | |||||
public function loadDependencies(): void | |||||
{ | |||||
$this->orderRepository = $this->loadService(OrderRepository::class); | |||||
$this->orderBuilder = $this->loadService(OrderBuilder::class); | |||||
$this->productDistributionRepository = $this->loadService(ProductDistributionRepository::class); | |||||
$this->pointSaleRepository = $this->loadService(PointSaleRepository::class); | |||||
$this->productCategoryRepository = $this->loadService(ProductCategoryRepository::class); | |||||
$this->productRepository = $this->loadService(ProductRepository::class); | |||||
} | |||||
public function generateDistributionReportGridPdf(Distribution $distribution, bool $save = false) | |||||
{ | |||||
$producer = $this->getProducerContext(); | |||||
$ordersArray = $this->orderRepository->findOrdersByDistribution($distribution); | |||||
$selectedProductsArray = $this->productDistributionRepository->findProductDistributionsByDistribution($distribution); | |||||
$pointsSaleArray = $this->pointSaleRepository->findPointSales(); | |||||
foreach ($pointsSaleArray as $pointSale) { | |||||
$this->orderBuilder->initPointSaleOrders($pointSale, $ordersArray); | |||||
} | |||||
$ordersByPage = 22; | |||||
$ordersArrayPaged = []; | |||||
foreach ($pointsSaleArray as $pointSale) { | |||||
$index = 0; | |||||
$indexPage = 0; | |||||
foreach ($pointSale->orders as $order) { | |||||
if (!isset($ordersArrayPaged[$pointSale->id])) { | |||||
$ordersArrayPaged[$pointSale->id] = []; | |||||
} | |||||
if (!isset($ordersArrayPaged[$pointSale->id][$indexPage])) { | |||||
$ordersArrayPaged[$pointSale->id][$indexPage] = []; | |||||
} | |||||
$ordersArrayPaged[$pointSale->id][$indexPage][] = $order; | |||||
$index++; | |||||
if ($index == $ordersByPage) { | |||||
$index = 0; | |||||
$indexPage++; | |||||
} | |||||
} | |||||
} | |||||
$categoriesArray = $this->productCategoryRepository->findProductCategories(); | |||||
array_unshift($categoriesArray, null); | |||||
$productsArray = $this->productRepository->findProductsByDistribution($distribution); | |||||
$viewPdf = '@backend/views/distribution/report-grid'; | |||||
$orientationPdf = Pdf::ORIENT_PORTRAIT; | |||||
if ($producer->slug == 'bourlinguepacotille') { | |||||
$viewPdf = '@backend/views/distribution/report-bourlingue'; | |||||
$orientationPdf = Pdf::ORIENT_LANDSCAPE; | |||||
} | |||||
// get your HTML raw content without any layouts or scripts | |||||
$content = \Yii::$app->getView()->render($viewPdf, [ | |||||
'date' => $distribution->date, | |||||
'distribution' => $distribution, | |||||
'selectedProductsArray' => $selectedProductsArray, | |||||
'pointsSaleArray' => $pointsSaleArray, | |||||
'categoriesArray' => $categoriesArray, | |||||
'productsArray' => $productsArray, | |||||
'ordersArray' => $ordersArrayPaged, | |||||
'producer' => $producer | |||||
]); | |||||
$dateStr = date('d/m/Y', strtotime($distribution->date)); | |||||
if ($save) { | |||||
$destination = Pdf::DEST_FILE; | |||||
} else { | |||||
$destination = Pdf::DEST_BROWSER; | |||||
} | |||||
$pdf = new Pdf([ | |||||
'mode' => Pdf::MODE_UTF8, | |||||
'format' => Pdf::FORMAT_A4, | |||||
'orientation' => $orientationPdf, | |||||
'destination' => $destination, | |||||
'filename' => \Yii::getAlias( | |||||
'@app/web/pdf/Commandes-' . $distribution->date . '-' . $producer->id . '.pdf' | |||||
), | |||||
'content' => $content, | |||||
//'cssFile' => Yii::getAlias('@web/css/distribution/report.css'), | |||||
'cssInline' => ' | |||||
table { | |||||
border-spacing : 0px ; | |||||
border-collapse : collapse ; | |||||
width: 100% ; | |||||
} | |||||
table tr th, | |||||
table tr td { | |||||
padding: 0px ; | |||||
margin: 0px ; | |||||
border: solid 1px #e0e0e0 ; | |||||
padding: 3px ; | |||||
vertical-align : top; | |||||
page-break-inside: avoid !important; | |||||
} | |||||
table tr th { | |||||
font-size: 10px ; | |||||
} | |||||
table tr td { | |||||
font-size: 10px ; | |||||
} | |||||
table thead tr { | |||||
line-height: 220px; | |||||
text-align:left; | |||||
} | |||||
.th-user, | |||||
.td-nb-products { | |||||
/* width: 35px ; */ | |||||
text-align: center ; | |||||
} | |||||
.th-user { | |||||
padding: 10px ; | |||||
} | |||||
.category-name { | |||||
font-weight: bold ; | |||||
} | |||||
', | |||||
'methods' => [ | |||||
'SetHeader' => ['Commandes du ' . $dateStr], | |||||
'SetFooter' => ['{PAGENO}'], | |||||
] | |||||
]); | |||||
return $pdf->render(); | |||||
} | |||||
} |
} | } | ||||
$pdf = new Pdf([ | $pdf = new Pdf([ | ||||
// set to use core fonts only | |||||
'mode' => Pdf::MODE_UTF8, | 'mode' => Pdf::MODE_UTF8, | ||||
// A4 paper format | |||||
'format' => Pdf::FORMAT_A4, | 'format' => Pdf::FORMAT_A4, | ||||
// portrait orientation | |||||
'orientation' => $orientationPdf, | 'orientation' => $orientationPdf, | ||||
// stream to browser inline | |||||
'destination' => $destination, | 'destination' => $destination, | ||||
'filename' => \Yii::getAlias( | 'filename' => \Yii::getAlias( | ||||
'@app/web/pdf/Commandes-' . $distribution->date . '-' . $this->getProducerContextId() . '.pdf' | '@app/web/pdf/Commandes-' . $distribution->date . '-' . $this->getProducerContextId() . '.pdf' | ||||
), | ), | ||||
// your html content input | |||||
'content' => $content, | 'content' => $content, | ||||
// format content from your own css file if needed or use the | |||||
// enhanced bootstrap css built by Krajee for mPDF formatting | |||||
//'cssFile' => Yii::getAlias('@web/css/distribution/report.css'), | //'cssFile' => Yii::getAlias('@web/css/distribution/report.css'), | ||||
// any css to be embedded if required | |||||
'cssInline' => ' | 'cssInline' => ' | ||||
table { | table { | ||||
border-spacing : 0px ; | border-spacing : 0px ; | ||||
font-size: 13px ; | font-size: 13px ; | ||||
} | } | ||||
', | ', | ||||
// set mPDF properties on the fly | |||||
//'options' => ['title' => 'Krajee Report Title'], | |||||
// call mPDF methods on the fly | |||||
'methods' => [ | 'methods' => [ | ||||
'SetHeader' => ['Commandes du ' . $dateStr], | 'SetHeader' => ['Commandes du ' . $dateStr], | ||||
'SetFooter' => ['{PAGENO}'], | 'SetFooter' => ['{PAGENO}'], | ||||
] | ] | ||||
]); | ]); | ||||
// return the pdf output as per the destination setting | |||||
return $pdf->render(); | return $pdf->render(); | ||||
} | } | ||||
} | } |
use common\logic\Distribution\Distribution\Service\DistributionBuilder; | use common\logic\Distribution\Distribution\Service\DistributionBuilder; | ||||
use common\logic\Distribution\Distribution\Service\DistributionDefinition; | use common\logic\Distribution\Distribution\Service\DistributionDefinition; | ||||
use common\logic\Distribution\Distribution\Service\DistributionReportCsvGenerator; | use common\logic\Distribution\Distribution\Service\DistributionReportCsvGenerator; | ||||
use common\logic\Distribution\Distribution\Service\DistributionReportGridCsvGenerator; | |||||
use common\logic\Distribution\Distribution\Service\DistributionReportGridPdfGenerator; | |||||
use common\logic\Distribution\Distribution\Service\DistributionReportPdfGenerator; | use common\logic\Distribution\Distribution\Service\DistributionReportPdfGenerator; | ||||
use common\logic\Distribution\Distribution\Service\DistributionSolver; | use common\logic\Distribution\Distribution\Service\DistributionSolver; | ||||
DistributionRepository::class, | DistributionRepository::class, | ||||
DistributionBuilder::class, | DistributionBuilder::class, | ||||
DistributionReportCsvGenerator::class, | DistributionReportCsvGenerator::class, | ||||
DistributionReportGridCsvGenerator::class, | |||||
DistributionReportGridPdfGenerator::class, | |||||
DistributionReportPdfGenerator::class, | DistributionReportPdfGenerator::class, | ||||
]; | ]; | ||||
} | } |
use common\logic\Distribution\Distribution\Service\DistributionBuilder; | use common\logic\Distribution\Distribution\Service\DistributionBuilder; | ||||
use common\logic\Distribution\Distribution\Service\DistributionDefinition; | use common\logic\Distribution\Distribution\Service\DistributionDefinition; | ||||
use common\logic\Distribution\Distribution\Service\DistributionReportCsvGenerator; | use common\logic\Distribution\Distribution\Service\DistributionReportCsvGenerator; | ||||
use common\logic\Distribution\Distribution\Service\DistributionReportGridCsvGenerator; | |||||
use common\logic\Distribution\Distribution\Service\DistributionReportGridPdfGenerator; | |||||
use common\logic\Distribution\Distribution\Service\DistributionReportPdfGenerator; | use common\logic\Distribution\Distribution\Service\DistributionReportPdfGenerator; | ||||
use common\logic\Distribution\Distribution\Service\DistributionSolver; | use common\logic\Distribution\Distribution\Service\DistributionSolver; | ||||
* @mixin DistributionRepository | * @mixin DistributionRepository | ||||
* @mixin DistributionBuilder | * @mixin DistributionBuilder | ||||
* @mixin DistributionReportCsvGenerator | * @mixin DistributionReportCsvGenerator | ||||
* @mixin DistributionReportGridCsvGenerator | |||||
* @mixin DistributionReportGridPdfGenerator | |||||
* @mixin DistributionReportPdfGenerator | * @mixin DistributionReportPdfGenerator | ||||
*/ | */ | ||||
class DistributionManager extends AbstractManager | class DistributionManager extends AbstractManager |
return $this->productDistributionRepository->findOneProductDistribution($distribution, $product) | return $this->productDistributionRepository->findOneProductDistribution($distribution, $product) | ||||
?? $this->createProductDistribution($distribution, $product); | ?? $this->createProductDistribution($distribution, $product); | ||||
} | } | ||||
public function updateProductDistribution(ProductDistribution $productDistribution): ProductDistribution | public function updateProductDistribution(ProductDistribution $productDistribution): ProductDistribution | ||||
{ | { | ||||
$this->initProductDistribution($productDistribution); | $this->initProductDistribution($productDistribution); | ||||
$this->saveUpdate($productDistribution); | |||||
$this->update($productDistribution); | |||||
return $productDistribution; | return $productDistribution; | ||||
} | } | ||||
return $productDistribution; | return $productDistribution; | ||||
} | } | ||||
public function updateProductDistributionQuantityMax(ProductDistribution $productDistribution, float $quantityMax) | |||||
{ | |||||
$productDistribution->quantity_max = ($quantityMax == -1) ? null : (float) abs($quantityMax); | |||||
$this->update($productDistribution); | |||||
return $productDistribution; | |||||
} | |||||
public function updateProductDistributionActive(ProductDistribution $productDistribution, int $active) | |||||
{ | |||||
$productDistribution->active = $active; | |||||
$this->update($productDistribution); | |||||
} | |||||
} | } |
'user_producer' => $userProducer, | 'user_producer' => $userProducer, | ||||
'point_sale' => $pointSale, | 'point_sale' => $pointSale, | ||||
'quantity' => $specificPrice->from_quantity | 'quantity' => $specificPrice->from_quantity | ||||
]), 3), | |||||
]), 5), | |||||
'price_with_tax' => number_format($this->productSolver->getPriceWithTax($product, [ | 'price_with_tax' => number_format($this->productSolver->getPriceWithTax($product, [ | ||||
'user' => $user, | 'user' => $user, | ||||
'user_producer' => $userProducer, | 'user_producer' => $userProducer, | ||||
// base price | // base price | ||||
$priceArray[] = [ | $priceArray[] = [ | ||||
'from_quantity' => 0, | 'from_quantity' => 0, | ||||
'price' => $this->productSolver->getPrice($product), | |||||
'price_with_tax' => $this->productSolver->getPriceWithTax($product), | |||||
'price' => number_format($this->productSolver->getPrice($product), 5), | |||||
'price_with_tax' => number_format($this->productSolver->getPriceWithTax($product), 2), | |||||
]; | ]; | ||||
} | } | ||||