mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-05 18:52:44 +01:00
Invoice Test Assertions
This commit is contained in:
parent
3813d31994
commit
2008b38473
@ -33,6 +33,8 @@ class InvoiceCalc
|
||||
|
||||
private $tax_map;
|
||||
|
||||
private $total_item_taxes;
|
||||
|
||||
private $total_taxes;
|
||||
|
||||
private $total_discount;
|
||||
@ -147,8 +149,9 @@ class InvoiceCalc
|
||||
if (! $this->settings->inclusive_taxes) {
|
||||
$taxAmount1 = round($this->total * ($this->invoice->tax_rate1 ? $this->invoice->tax_rate1 : 0) / 100, 2);
|
||||
$taxAmount2 = round($this->total * ($this->invoice->tax_rate2 ? $this->invoice->tax_rate2 : 0) / 100, 2);
|
||||
$this->total = round($this->total + $taxAmount1 + $taxAmount2, 2);
|
||||
$this->total_taxes = round($taxAmount1 + $taxAmount2, 2);
|
||||
$this->total += $this->total_taxes;
|
||||
$this->total += $this->total_item_taxes;
|
||||
}
|
||||
|
||||
return $this;
|
||||
@ -176,7 +179,7 @@ class InvoiceCalc
|
||||
$this->tax_map->merge($item_calc->getGroupedTaxes());
|
||||
|
||||
//set running total of taxes
|
||||
$this->total_taxes += $item_calc->getTotalTaxes();
|
||||
$this->total_item_taxes += $item_calc->getTotalTaxes();
|
||||
|
||||
//set running total of discounts
|
||||
$this->total_discount += $item_calc->getTotalDiscounts();
|
||||
|
@ -83,4 +83,75 @@ class InvoiceTest extends TestCase
|
||||
$this->assertEquals($this->invoice_calc->getTotal(), 15);
|
||||
$this->assertEquals($this->invoice_calc->getBalance(), 15);
|
||||
}
|
||||
|
||||
public function testInvoiceTotalsWithDiscountWithSurcharge()
|
||||
{
|
||||
$this->invoice->discount = 5;
|
||||
$this->invoice->custom_value1 = 5;
|
||||
|
||||
$this->invoice_calc->build();
|
||||
|
||||
$this->assertEquals($this->invoice_calc->getSubTotal(), 20);
|
||||
$this->assertEquals($this->invoice_calc->getTotal(), 20);
|
||||
$this->assertEquals($this->invoice_calc->getBalance(), 20);
|
||||
}
|
||||
|
||||
public function testInvoiceTotalsWithDiscountWithSurchargeWithInclusiveTax()
|
||||
{
|
||||
$this->invoice->discount = 5;
|
||||
$this->invoice->custom_value1 = 5;
|
||||
$this->invoice->tax_name1 = 'GST';
|
||||
$this->invoice->tax_rate1 = 10;
|
||||
|
||||
|
||||
$this->invoice_calc->build();
|
||||
|
||||
$this->assertEquals($this->invoice_calc->getSubTotal(), 20);
|
||||
$this->assertEquals($this->invoice_calc->getTotal(), 20);
|
||||
$this->assertEquals($this->invoice_calc->getBalance(), 20);
|
||||
}
|
||||
|
||||
public function testInvoiceTotalsWithDiscountWithSurchargeWithExclusiveTax()
|
||||
{
|
||||
|
||||
$this->invoice_calc = new InvoiceCalc($this->invoice, $this->settings);
|
||||
|
||||
$this->invoice->discount = 5;
|
||||
$this->invoice->custom_value1 = 5;
|
||||
$this->invoice->tax_name1 = 'GST';
|
||||
$this->invoice->tax_rate1 = 10;
|
||||
$this->settings->inclusive_taxes = false;
|
||||
|
||||
$this->invoice_calc->build();
|
||||
|
||||
$this->assertEquals($this->invoice_calc->getSubTotal(), 20);
|
||||
$this->assertEquals($this->invoice_calc->getTotal(), 22);
|
||||
$this->assertEquals($this->invoice_calc->getBalance(), 22);
|
||||
$this->assertEquals($this->invoice_calc->getTotalTaxes(), 2);
|
||||
}
|
||||
|
||||
public function testInvoiceTotalsWithDiscountWithSurchargeWithDoubleExclusiveTax()
|
||||
{
|
||||
|
||||
$this->invoice_calc = new InvoiceCalc($this->invoice, $this->settings);
|
||||
|
||||
$this->invoice->discount = 5;
|
||||
$this->invoice->custom_value1 = 5;
|
||||
$this->invoice->tax_name1 = 'GST';
|
||||
$this->invoice->tax_rate1 = 10;
|
||||
$this->invoice->tax_name2 = 'GST';
|
||||
$this->invoice->tax_rate2 = 10;
|
||||
$this->settings->inclusive_taxes = false;
|
||||
|
||||
$this->invoice_calc->build();
|
||||
|
||||
$this->assertEquals($this->invoice_calc->getSubTotal(), 20);
|
||||
$this->assertEquals($this->invoice_calc->getTotal(), 24);
|
||||
$this->assertEquals($this->invoice_calc->getBalance(), 24);
|
||||
$this->assertEquals($this->invoice_calc->getTotalTaxes(), 4);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user