<?= Price::format($price) ?> | <?= Price::format($price) ?> | ||||
</td> | </td> | ||||
<?php endif; ?> | <?php endif; ?> | ||||
<td class="align-center"><?= $productOrder->quantity * Product::$unitsArray[$productOrder->unit]['coefficient'] ?></td> | |||||
<td class="align-center"> | |||||
<?= $productOrder->quantity * Product::$unitsArray[$productOrder->unit]['coefficient'] ?> | |||||
</td> | |||||
<td class="align-center"><?= Product::strUnit($productOrder->unit, 'wording') ?></td> | <td class="align-center"><?= Product::strUnit($productOrder->unit, 'wording') ?></td> | ||||
<?php if($displayPrices): ?> | <?php if($displayPrices): ?> | ||||
<?php if(GlobalParam::getCurrentProducer()->taxRate->value != 0): ?> | <?php if(GlobalParam::getCurrentProducer()->taxRate->value != 0): ?> |
<?php endforeach; ?> | <?php endforeach; ?> | ||||
<?php endforeach; ?> | <?php endforeach; ?> | ||||
<?php else: ?> | <?php else: ?> | ||||
<?php foreach($document->getProductsOrders() as $product): ?> | |||||
<?php foreach($product as $productOrder): ?> | |||||
<?= $this->render('_download_product_line', [ | |||||
'document' => $document, | |||||
'productOrder' => $productOrder, | |||||
'displayPrices' => $displayPrices, | |||||
'displayProductDescription' => $displayProductDescription | |||||
]) ?> | |||||
<?php endforeach; ?> | |||||
<?php foreach($document->getProductsOrders() as $product): ?> | |||||
<?php foreach($product as $productOrder): ?> | |||||
<?= $this->render('_download_product_line', [ | |||||
'document' => $document, | |||||
'productOrder' => $productOrder, | |||||
'displayPrices' => $displayPrices, | |||||
'displayProductDescription' => $displayProductDescription | |||||
]) ?> | |||||
<?php endforeach; ?> | <?php endforeach; ?> | ||||
<?php endforeach; ?> | |||||
<?php endif; ?> | <?php endif; ?> | ||||
<?php if($displayPrices): ?> | <?php if($displayPrices): ?> | ||||
<?php $typeAmount = $document->isInvoicePrice() ? Order::INVOICE_AMOUNT_TOTAL : Order::AMOUNT_TOTAL ; ?> | <?php $typeAmount = $document->isInvoicePrice() ? Order::INVOICE_AMOUNT_TOTAL : Order::AMOUNT_TOTAL ; ?> |
'attribute' => 'amount', | 'attribute' => 'amount', | ||||
'header' => 'Montant', | 'header' => 'Montant', | ||||
'value' => function($invoice) { | 'value' => function($invoice) { | ||||
return $invoice->getAmountWithTax(Order::INVOICE_AMOUNT_TOTAL, true) ; | |||||
return $invoice->getAmountWithTax(Order::INVOICE_AMOUNT_TOTAL, true) ; | |||||
} | } | ||||
], | ], | ||||
[ | [ |
if ($ordersArray && count($ordersArray)) { | if ($ordersArray && count($ordersArray)) { | ||||
foreach ($ordersArray as $order) { | foreach ($ordersArray as $order) { | ||||
foreach ($order->productOrder as $productOrder) { | foreach ($order->productOrder as $productOrder) { | ||||
//$indexProductOrder = $productOrder->id_product ; | |||||
$indexProductOrder = $productOrder->product->order ; | $indexProductOrder = $productOrder->product->order ; | ||||
$newProductOrder = clone $productOrder ; | |||||
if (!isset($productsOrdersArray[$indexProductOrder])) { | if (!isset($productsOrdersArray[$indexProductOrder])) { | ||||
$newProductOrder = clone $productOrder ; | |||||
$productsOrdersArray[$indexProductOrder] = [$newProductOrder]; | $productsOrdersArray[$indexProductOrder] = [$newProductOrder]; | ||||
} else { | } else { | ||||
$productOrderMatch = false; | $productOrderMatch = false; | ||||
foreach ($productsOrdersArray[$indexProductOrder] as &$theProductOrder) { | foreach ($productsOrdersArray[$indexProductOrder] as &$theProductOrder) { | ||||
if ($theProductOrder->unit == $productOrder->unit | if ($theProductOrder->unit == $productOrder->unit | ||||
&& ($theProductOrder->price == $productOrder->price | |||||
|| ($this->isInvoicePrice() | |||||
&& $theProductOrder->invoice_price == $productOrder->invoice_price))) { | |||||
&& ( (!$this->isInvoicePrice() && $theProductOrder->price == $productOrder->price) | |||||
|| ($this->isInvoicePrice() && $theProductOrder->invoice_price == $productOrder->invoice_price) | |||||
)) { | |||||
$theProductOrder->quantity += $productOrder->quantity; | $theProductOrder->quantity += $productOrder->quantity; | ||||
$productOrderMatch = true; | $productOrderMatch = true; | ||||
} | } | ||||
} | } | ||||
if (!$productOrderMatch) { | if (!$productOrderMatch) { | ||||
$productsOrdersArray[$indexProductOrder][] = $productOrder; | |||||
$productsOrdersArray[$indexProductOrder][] = $newProductOrder; | |||||
} | } | ||||
} | } | ||||
} | } |
$productOrder->taxRate->value | $productOrder->taxRate->value | ||||
) * $productOrder->quantity; | ) * $productOrder->quantity; | ||||
$invoicePrice = $productOrder->invoice_price ? $productOrder->invoice_price : $productOrder->price; | |||||
if($productOrder->invoice_price) { | |||||
$invoicePrice = $productOrder->invoice_price; | |||||
} | |||||
else { | |||||
$invoicePrice = $productOrder->price; | |||||
} | |||||
$this->invoice_amount += $invoicePrice * $productOrder->quantity; | $this->invoice_amount += $invoicePrice * $productOrder->quantity; | ||||
$this->invoice_amount_with_tax += Price::getPriceWithTax( | $this->invoice_amount_with_tax += Price::getPriceWithTax( | ||||
$invoicePrice, | $invoicePrice, | ||||
public function getAmount($type = self::AMOUNT_TOTAL, $format = false) | public function getAmount($type = self::AMOUNT_TOTAL, $format = false) | ||||
{ | { | ||||
$amount = $this->amount; | $amount = $this->amount; | ||||
if ($type == self::INVOICE_AMOUNT_TOTAL) { | |||||
if ($type == self::INVOICE_AMOUNT_TOTAL && $this->invoice_amount) { | |||||
$amount = $this->invoice_amount; | $amount = $this->invoice_amount; | ||||
} | } | ||||
public function getAmountWithTax($type = self::AMOUNT_TOTAL, $format = false) | public function getAmountWithTax($type = self::AMOUNT_TOTAL, $format = false) | ||||
{ | { | ||||
$amount = $this->amount_with_tax; | $amount = $this->amount_with_tax; | ||||
if ($type == self::INVOICE_AMOUNT_TOTAL) { | |||||
if ($type == self::INVOICE_AMOUNT_TOTAL && $this->invoice_amount) { | |||||
$amount = $this->invoice_amount_with_tax; | $amount = $this->invoice_amount_with_tax; | ||||
} | } | ||||