Pārlūkot izejas kodu

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

refactoring
Guillaume Bourgeois pirms 2 gadiem
vecāks
revīzija
4045428c30
5 mainītis faili ar 28 papildinājumiem un 21 dzēšanām
  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 Parādīt failu

@@ -21,7 +21,9 @@
<?= Price::format($price) ?>
</td>
<?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>
<?php if($displayPrices): ?>
<?php if(GlobalParam::getCurrentProducer()->taxRate->value != 0): ?>

+ 9
- 9
backend/views/document/download.php Parādīt failu

@@ -106,16 +106,16 @@ $displayProductDescription = Producer::getConfig('document_display_product_descr
<?php endforeach; ?>
<?php endforeach; ?>
<?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 endif; ?>
<?php if($displayPrices): ?>
<?php $typeAmount = $document->isInvoicePrice() ? Order::INVOICE_AMOUNT_TOTAL : Order::AMOUNT_TOTAL ; ?>

+ 1
- 1
backend/views/invoice/index.php Parādīt failu

@@ -96,7 +96,7 @@ $this->addButton(['label' => 'Nouvelle facture <span class="glyphicon glyphicon-
'attribute' => 'amount',
'header' => 'Montant',
'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 Parādīt failu

@@ -342,26 +342,25 @@ class Document extends ActiveRecordCommon
if ($ordersArray && count($ordersArray)) {
foreach ($ordersArray as $order) {
foreach ($order->productOrder as $productOrder) {

//$indexProductOrder = $productOrder->id_product ;
$indexProductOrder = $productOrder->product->order ;
$newProductOrder = clone $productOrder ;

if (!isset($productsOrdersArray[$indexProductOrder])) {
$newProductOrder = clone $productOrder ;
$productsOrdersArray[$indexProductOrder] = [$newProductOrder];
} else {
$productOrderMatch = false;
foreach ($productsOrdersArray[$indexProductOrder] as &$theProductOrder) {
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;
$productOrderMatch = true;
}
}
if (!$productOrderMatch) {
$productsOrdersArray[$indexProductOrder][] = $productOrder;
$productsOrdersArray[$indexProductOrder][] = $newProductOrder;
}
}
}

+ 9
- 3
common/models/Order.php Parādīt failu

@@ -251,7 +251,13 @@ class Order extends ActiveRecordCommon
$productOrder->taxRate->value
) * $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_with_tax += Price::getPriceWithTax(
$invoicePrice,
@@ -416,7 +422,7 @@ class Order extends ActiveRecordCommon
public function getAmount($type = self::AMOUNT_TOTAL, $format = false)
{
$amount = $this->amount;
if ($type == self::INVOICE_AMOUNT_TOTAL) {
if ($type == self::INVOICE_AMOUNT_TOTAL && $this->invoice_amount) {
$amount = $this->invoice_amount;
}

@@ -426,7 +432,7 @@ class Order extends ActiveRecordCommon
public function getAmountWithTax($type = self::AMOUNT_TOTAL, $format = false)
{
$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;
}


Notiek ielāde…
Atcelt
Saglabāt