1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 13:12:50 +01:00

Tests for Invoice Item

This commit is contained in:
David Bomba 2019-04-04 20:53:40 +11:00
parent ae57c05659
commit 336bd26bb9
2 changed files with 58 additions and 11 deletions

View File

@ -52,14 +52,21 @@ class InvoiceItemCalc
if($tax_rate1 != 0) if($tax_rate1 != 0)
{ {
$item_tax += $this->formatValue(($this->getLineTotal() * $tax_rate1/100) , $this->precision); if($this->inclusive_tax)
$item_tax += $this->formatValue(($this->getLineTotal() - ($this->getLineTotal() / (1+$tax_rate1/100))) , $this->precision);
else
$item_tax += $this->formatValue(($this->getLineTotal() * $tax_rate1/100), $this->precision);
} }
$tax_rate2 = $this->formatValue($this->item->tax_rate2, $this->precision); $tax_rate2 = $this->formatValue($this->item->tax_rate2, $this->precision);
if($tax_rate2 != 0) if($tax_rate2 != 0)
{ {
$item_tax += $this->formatValue(($this->getLineTotal() * $tax_rate2/100) , $this->precision); if($this->inclusive_tax)
$item_tax += $this->formatValue(($this->getLineTotal() - ($this->getLineTotal() / (1+$tax_rate2/100))) , $this->precision);
else
$item_tax += $this->formatValue(($this->getLineTotal() * $tax_rate2/100), $this->precision);
} }
$this->setTotalTaxes($item_tax); $this->setTotalTaxes($item_tax);

View File

@ -26,7 +26,7 @@ class InvoiceItemTest extends TestCase
$item->cost =10; $item->cost =10;
$item->is_amount_discount = true; $item->is_amount_discount = true;
$inclusive_tax = true $inclusive_tax = true;
$item_calc = new InvoiceItemCalc($item, 2, $inclusive_tax); $item_calc = new InvoiceItemCalc($item, 2, $inclusive_tax);
$item_calc->process(); $item_calc->process();
@ -42,7 +42,7 @@ class InvoiceItemTest extends TestCase
$item->is_amount_discount = true; $item->is_amount_discount = true;
$item->discount = 2; $item->discount = 2;
$inclusive_tax = true $inclusive_tax = true;
$item_calc = new InvoiceItemCalc($item, 2, $inclusive_tax); $item_calc = new InvoiceItemCalc($item, 2, $inclusive_tax);
$item_calc->process(); $item_calc->process();
@ -58,7 +58,7 @@ class InvoiceItemTest extends TestCase
$item->is_amount_discount = true; $item->is_amount_discount = true;
$item->discount = 2.521254522145214511; $item->discount = 2.521254522145214511;
$inclusive_tax = true $inclusive_tax = true;
$item_calc = new InvoiceItemCalc($item, 2, $inclusive_tax); $item_calc = new InvoiceItemCalc($item, 2, $inclusive_tax);
$item_calc->process(); $item_calc->process();
@ -66,36 +66,76 @@ class InvoiceItemTest extends TestCase
$this->assertEquals($item_calc->getLineTotal(), 7.48); $this->assertEquals($item_calc->getLineTotal(), 7.48);
} }
public function testInvoiceItemTotalSimpleWithDiscountWithPrecision() public function testInvoiceItemTotalSimpleWithDiscountWithPrecisionWithSingleInclusiveTax()
{ {
$item = InvoiceItemFactory::create(); $item = InvoiceItemFactory::create();
$item->qty = 1; $item->qty = 1;
$item->cost =10; $item->cost =10;
$item->is_amount_discount = true; $item->is_amount_discount = true;
$item->discount = 2.521254522145214511; $item->discount = 2.521254522145214511;
$item->tax_rate1 = 10;
$inclusive_tax = true $inclusive_tax = true;
$item_calc = new InvoiceItemCalc($item, 2, $inclusive_tax); $item_calc = new InvoiceItemCalc($item, 2, $inclusive_tax);
$item_calc->process(); $item_calc->process();
$this->assertEquals($item_calc->getLineTotal(), 7.48); $this->assertEquals($item_calc->getTotalTaxes(), 0.68);
} }
public function testInvoiceItemTotalSimpleWithDiscountWithPrecisionWithSingleTax() public function testInvoiceItemTotalSimpleWithDiscountWithPrecisionWithSingleExclusiveTax()
{ {
$item = InvoiceItemFactory::create(); $item = InvoiceItemFactory::create();
$item->qty = 1; $item->qty = 1;
$item->cost =10; $item->cost =10;
$item->is_amount_discount = true; $item->is_amount_discount = true;
$item->discount = 2.521254522145214511; $item->discount = 2.521254522145214511;
$item->tax_rate1 = 10;
$inclusive_tax = true $inclusive_tax = false;
$item_calc = new InvoiceItemCalc($item, 2, $inclusive_tax); $item_calc = new InvoiceItemCalc($item, 2, $inclusive_tax);
$item_calc->process(); $item_calc->process();
$this->assertEquals($item_calc->getLineTotal(), 7.48); $this->assertEquals($item_calc->getTotalTaxes(), 0.75);
}
public function testInvoiceItemTotalSimpleWithDiscountWithPrecisionWithDoubleInclusiveTax()
{
$item = InvoiceItemFactory::create();
$item->qty = 1;
$item->cost =10;
$item->is_amount_discount = true;
$item->discount = 2.521254522145214511;
$item->tax_rate1 = 10;
$item->tax_rate2 = 17.5;
$inclusive_tax = true;
$item_calc = new InvoiceItemCalc($item, 2, $inclusive_tax);
$item_calc->process();
$this->assertEquals($item_calc->getTotalTaxes(), 1.79);
}
public function testInvoiceItemTotalSimpleWithDiscountWithPrecisionWithDoubleExclusiveTax()
{
$item = InvoiceItemFactory::create();
$item->qty = 1;
$item->cost =10;
$item->is_amount_discount = true;
$item->discount = 2.521254522145214511;
$item->tax_rate1 = 10;
$item->tax_rate2 = 17.5;
$inclusive_tax = false;
$item_calc = new InvoiceItemCalc($item, 2, $inclusive_tax);
$item_calc->process();
$this->assertEquals($item_calc->getTotalTaxes(), 2.06);
} }
} }