瀏覽代碼

Documents : ajustement calcul TVA

refactoring
Guillaume Bourgeois 2 年之前
父節點
當前提交
aca86741b6
共有 3 個文件被更改,包括 35 次插入8 次删除
  1. +2
    -2
      common/helpers/Price.php
  2. +30
    -3
      common/models/Document.php
  3. +3
    -3
      common/models/Order.php

+ 2
- 2
common/helpers/Price.php 查看文件

@@ -64,9 +64,9 @@ class Price
return $priceWithoutTax + $vat;
}

public static function getVat($priceWithoutTax, $taxRate, $taxCalculationMethod = Document::TAX_CALCULATION_METHOD_DEFAULT)
public static function getVat($priceTotalWithoutTax, $taxRate, $taxCalculationMethod = Document::TAX_CALCULATION_METHOD_DEFAULT)
{
$vat = $priceWithoutTax * $taxRate;
$vat = $priceTotalWithoutTax * $taxRate;

if($taxCalculationMethod == Document::TAX_CALCULATION_METHOD_SUM_OF_ROUNDINGS) {
$vat = self::round($vat);

+ 30
- 3
common/models/Document.php 查看文件

@@ -135,10 +135,20 @@ class Document extends ActiveRecordCommon
$totalVat = 0;
$ordersArray = $this->orders;

foreach ($ordersArray as $order) {
// Méthode de calcul via les commandes liées
/*foreach ($ordersArray as $order) {
$order->init($this->tax_calculation_method);
$amount += $order->getAmount($type);
$totalVat += $order->getTotalVat($type);
}*/

// Méthode de calcul via getProductOrders()
foreach($this->getProductsOrders() as $productOrderArray) {
foreach($productOrderArray as $productOrder) {
$priceLine = $productOrder->getPriceByTypeTotal($type) * $productOrder->quantity;
$amount += $priceLine;
$totalVat += Price::getVat($priceLine, $productOrder->taxRate->value, $this->tax_calculation_method);
}
}

if ($this->isTaxCalculationMethodRoundingOfTheSum()) {
@@ -160,8 +170,8 @@ class Document extends ActiveRecordCommon
{
$totalVatArray = [];

$ordersArray = $this->orders;
// Méthode de calcul via les commandes liées
/*$ordersArray = $this->orders;
foreach ($ordersArray as $order) {
$order->init($this->tax_calculation_method);
$fieldNameVat = $order->getFieldNameAmount($typeTotal, 'vat');
@@ -171,6 +181,23 @@ class Document extends ActiveRecordCommon
}
$totalVatArray[$idTaxRate] += $vat;
}
}*/

// Méthode de calcul via getProductOrders()
foreach($this->getProductsOrders() as $productOrderArray) {
foreach ($productOrderArray as $productOrder) {

$idTaxRate = $productOrder->taxRate->id;
if (!isset($totalVatArray[$idTaxRate])) {
$totalVatArray[$idTaxRate] = 0;
}

$totalVatArray[$idTaxRate] += Price::getVat(
$productOrder->getPriceByTypeTotal($typeTotal) * $productOrder->quantity,
$productOrder->taxRate->value,
$this->tax_calculation_method
);
}
}

return $totalVatArray;

+ 3
- 3
common/models/Order.php 查看文件

@@ -278,10 +278,10 @@ class Order extends ActiveRecordCommon
$productOrder->taxRate->value,
$taxCalculationMethod
) * $productOrder->quantity;
$this->addVat($typeTotal, $price, $productOrder->quantity, $productOrder->taxRate, $taxCalculationMethod);
$this->addVat($typeTotal, $price * $productOrder->quantity, $productOrder->taxRate, $taxCalculationMethod);
}

public function addVat($typeTotal, $priceWithoutTax, $quantity, $taxRate, $taxCalculationMethod)
public function addVat($typeTotal, $priceTotalWithoutTax, $taxRate, $taxCalculationMethod)
{
$fieldName = $this->getFieldNameAmount($typeTotal, 'vat');

@@ -289,7 +289,7 @@ class Order extends ActiveRecordCommon
$this->$fieldName[$taxRate->id] = 0;
}

$this->$fieldName[$taxRate->id] += Price::getVat($priceWithoutTax, $taxRate->value, $taxCalculationMethod) * $quantity;
$this->$fieldName[$taxRate->id] += Price::getVat($priceTotalWithoutTax, $taxRate->value, $taxCalculationMethod);
}

public function getTotalVat($typeTotal = self::AMOUNT_TOTAL)

Loading…
取消
儲存