Browse Source

Merge branch 'dev'

prodstable
Guillaume Bourgeois 2 years ago
parent
commit
33a801c13e
3 changed files with 35 additions and 8 deletions
  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 View File

return $priceWithoutTax + $vat; 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) { if($taxCalculationMethod == Document::TAX_CALCULATION_METHOD_SUM_OF_ROUNDINGS) {
$vat = self::round($vat); $vat = self::round($vat);

+ 30
- 3
common/models/Document.php View File

$totalVat = 0; $totalVat = 0;
$ordersArray = $this->orders; $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); $order->init($this->tax_calculation_method);
$amount += $order->getAmount($type); $amount += $order->getAmount($type);
$totalVat += $order->getTotalVat($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()) { if ($this->isTaxCalculationMethodRoundingOfTheSum()) {
{ {
$totalVatArray = []; $totalVatArray = [];


$ordersArray = $this->orders;
// Méthode de calcul via les commandes liées
/*$ordersArray = $this->orders;
foreach ($ordersArray as $order) { foreach ($ordersArray as $order) {
$order->init($this->tax_calculation_method); $order->init($this->tax_calculation_method);
$fieldNameVat = $order->getFieldNameAmount($typeTotal, 'vat'); $fieldNameVat = $order->getFieldNameAmount($typeTotal, 'vat');
} }
$totalVatArray[$idTaxRate] += $vat; $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; return $totalVatArray;

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

$productOrder->taxRate->value, $productOrder->taxRate->value,
$taxCalculationMethod $taxCalculationMethod
) * $productOrder->quantity; ) * $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'); $fieldName = $this->getFieldNameAmount($typeTotal, 'vat');


$this->$fieldName[$taxRate->id] = 0; $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) public function getTotalVat($typeTotal = self::AMOUNT_TOTAL)

Loading…
Cancel
Save