Browse Source

[Backend] Documents : problème calcul total #456

refactoring
Guillaume Bourgeois 2 years ago
parent
commit
4045428c30
5 changed files with 28 additions and 21 deletions
  1. +3
    -1
      backend/views/document/_download_product_line.php
  2. +9
    -9
      backend/views/document/download.php
  3. +1
    -1
      backend/views/invoice/index.php
  4. +6
    -7
      common/models/Document.php
  5. +9
    -3
      common/models/Order.php

+ 3
- 1
backend/views/document/_download_product_line.php View File

<?= 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): ?>

+ 9
- 9
backend/views/document/download.php View File

<?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 ; ?>

+ 1
- 1
backend/views/invoice/index.php View File

'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) ;
} }
], ],
[ [

+ 6
- 7
common/models/Document.php View File

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

+ 9
- 3
common/models/Order.php View File

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



Loading…
Cancel
Save