mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -04:00
Fixes for tests. Fixes for invoice calculations
This commit is contained in:
parent
2008b38473
commit
5e86fa33c1
@ -61,6 +61,7 @@ class InvoiceCalc
|
||||
$this->calcLineItems()
|
||||
->calcDiscount()
|
||||
->calcCustomValues()
|
||||
//->calcTaxes()
|
||||
->calcBalance()
|
||||
->calcPartial();
|
||||
|
||||
@ -72,6 +73,8 @@ class InvoiceCalc
|
||||
if ( !isset($this->invoice->id) && isset($this->invoice->partial) ) {
|
||||
$this->invoice->partial = max(0, min($this->formatValue($this->invoice->partial, 2), $this->invoice->balance));
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
private function calcDiscount()
|
||||
@ -117,7 +120,6 @@ class InvoiceCalc
|
||||
|
||||
private function calcCustomValues()
|
||||
{
|
||||
$this->total += $this->getSubTotal();
|
||||
|
||||
// custom fields charged taxes
|
||||
if ($this->invoice->custom_value1 && $this->settings->custom_taxes1) {
|
||||
@ -149,9 +151,8 @@ 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_taxes = round($taxAmount1 + $taxAmount2, 2);
|
||||
$this->total_taxes = round($taxAmount1 + $taxAmount2, 2) + $this->total_item_taxes;
|
||||
$this->total += $this->total_taxes;
|
||||
$this->total += $this->total_item_taxes;
|
||||
}
|
||||
|
||||
return $this;
|
||||
@ -176,7 +177,7 @@ class InvoiceCalc
|
||||
$new_line_items[] = $item_calc->getLineItem();
|
||||
|
||||
//set collection of itemised taxes
|
||||
$this->tax_map->merge($item_calc->getGroupedTaxes());
|
||||
$this->tax_map->push($item_calc->getGroupedTaxes());
|
||||
|
||||
//set running total of taxes
|
||||
$this->total_item_taxes += $item_calc->getTotalTaxes();
|
||||
@ -186,7 +187,9 @@ class InvoiceCalc
|
||||
|
||||
//set running subtotal
|
||||
$this->sub_total += $item_calc->getLineTotal();
|
||||
|
||||
|
||||
$this->total += $item_calc->getLineTotal();
|
||||
|
||||
}
|
||||
|
||||
$this->invoice->line_items = $new_line_items;
|
||||
|
@ -30,7 +30,7 @@ class InvoiceItemCalc
|
||||
|
||||
$this->settings = $settings;
|
||||
|
||||
$this->tax_collection = new Collection;
|
||||
$this->tax_collection = collect([]);
|
||||
|
||||
}
|
||||
|
||||
@ -76,7 +76,7 @@ class InvoiceItemCalc
|
||||
|
||||
if($tax_rate1 != 0)
|
||||
{
|
||||
if($this->settings->inclusive_tax)
|
||||
if($this->settings->inclusive_taxes)
|
||||
$item_tax_rate1_total = $this->formatValue(($this->line_total - ($this->line_total / (1+$tax_rate1/100))) , $this->settings->precision);
|
||||
else
|
||||
$item_tax_rate1_total = $this->formatValue(($this->line_total * $tax_rate1/100), $this->settings->precision);
|
||||
@ -90,7 +90,7 @@ class InvoiceItemCalc
|
||||
|
||||
if($tax_rate2 != 0)
|
||||
{
|
||||
if($this->settings->inclusive_tax)
|
||||
if($this->settings->inclusive_taxes)
|
||||
$item_tax_rate2_total = $this->formatValue(($this->line_total - ($this->line_total / (1+$tax_rate2/100))) , $this->settings->precision);
|
||||
else
|
||||
$item_tax_rate2_total = $this->formatValue(($this->line_total * $tax_rate2/100), $this->settings->precision);
|
||||
@ -113,7 +113,7 @@ class InvoiceItemCalc
|
||||
|
||||
$group_tax[$key] = ['total' => $tax_total, 'tax_name' => $tax_name . ' ' . $tax_rate];
|
||||
|
||||
$this->tax_collection->merge(collect($group_tax));
|
||||
$this->tax_collection->push(collect($group_tax));
|
||||
|
||||
}
|
||||
|
||||
|
@ -27,7 +27,7 @@ class InvoiceItemTest extends TestCase
|
||||
$item->is_amount_discount = true;
|
||||
|
||||
$settings = new \stdClass;
|
||||
$settings->inclusive_tax = true;
|
||||
$settings->inclusive_taxes = true;
|
||||
$settings->precision = 2;
|
||||
|
||||
$item_calc = new InvoiceItemCalc($item, $settings);
|
||||
@ -45,7 +45,7 @@ class InvoiceItemTest extends TestCase
|
||||
$item->discount = 2;
|
||||
|
||||
$settings = new \stdClass;
|
||||
$settings->inclusive_tax = true;
|
||||
$settings->inclusive_taxes = true;
|
||||
$settings->precision = 2;
|
||||
$item_calc = new InvoiceItemCalc($item, $settings);
|
||||
$item_calc->process();
|
||||
@ -62,7 +62,7 @@ class InvoiceItemTest extends TestCase
|
||||
$item->discount = 2.521254522145214511;
|
||||
|
||||
$settings = new \stdClass;
|
||||
$settings->inclusive_tax = true;
|
||||
$settings->inclusive_taxes = true;
|
||||
$settings->precision = 2;
|
||||
|
||||
$item_calc = new InvoiceItemCalc($item, $settings);
|
||||
@ -81,7 +81,7 @@ class InvoiceItemTest extends TestCase
|
||||
$item->tax_rate1 = 10;
|
||||
|
||||
$settings = new \stdClass;
|
||||
$settings->inclusive_tax = true;
|
||||
$settings->inclusive_taxes = true;
|
||||
$settings->precision = 2;
|
||||
|
||||
$item_calc = new InvoiceItemCalc($item, $settings);
|
||||
@ -100,7 +100,7 @@ class InvoiceItemTest extends TestCase
|
||||
$item->tax_rate1 = 10;
|
||||
|
||||
$settings = new \stdClass;
|
||||
$settings->inclusive_tax = false;
|
||||
$settings->inclusive_taxes = false;
|
||||
$settings->precision = 2;
|
||||
|
||||
$item_calc = new InvoiceItemCalc($item, $settings);
|
||||
@ -120,7 +120,7 @@ class InvoiceItemTest extends TestCase
|
||||
$item->tax_rate2 = 17.5;
|
||||
|
||||
$settings = new \stdClass;
|
||||
$settings->inclusive_tax = true;
|
||||
$settings->inclusive_taxes = true;
|
||||
$settings->precision = 2;
|
||||
|
||||
$item_calc = new InvoiceItemCalc($item, $settings);
|
||||
@ -140,13 +140,14 @@ class InvoiceItemTest extends TestCase
|
||||
$item->tax_rate2 = 17.5;
|
||||
|
||||
$settings = new \stdClass;
|
||||
$settings->inclusive_tax = false;
|
||||
$settings->inclusive_taxes = false;
|
||||
$settings->precision = 2;
|
||||
|
||||
$item_calc = new InvoiceItemCalc($item, $settings);
|
||||
$item_calc->process();
|
||||
|
||||
$this->assertEquals($item_calc->getTotalTaxes(), 2.06);
|
||||
$this->assertEquals($item_calc->getGroupedTaxes()->count(), 2);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -114,7 +114,6 @@ class InvoiceTest extends TestCase
|
||||
public function testInvoiceTotalsWithDiscountWithSurchargeWithExclusiveTax()
|
||||
{
|
||||
|
||||
$this->invoice_calc = new InvoiceCalc($this->invoice, $this->settings);
|
||||
|
||||
$this->invoice->discount = 5;
|
||||
$this->invoice->custom_value1 = 5;
|
||||
@ -122,6 +121,8 @@ class InvoiceTest extends TestCase
|
||||
$this->invoice->tax_rate1 = 10;
|
||||
$this->settings->inclusive_taxes = false;
|
||||
|
||||
$this->invoice_calc = new InvoiceCalc($this->invoice, $this->settings);
|
||||
|
||||
$this->invoice_calc->build();
|
||||
|
||||
$this->assertEquals($this->invoice_calc->getSubTotal(), 20);
|
||||
@ -130,7 +131,7 @@ class InvoiceTest extends TestCase
|
||||
$this->assertEquals($this->invoice_calc->getTotalTaxes(), 2);
|
||||
}
|
||||
|
||||
public function testInvoiceTotalsWithDiscountWithSurchargeWithDoubleExclusiveTax()
|
||||
public function testInvoiceTotalsWithDiscountWithSurchargeWithDoubleExclusiveTax()
|
||||
{
|
||||
|
||||
$this->invoice_calc = new InvoiceCalc($this->invoice, $this->settings);
|
||||
@ -152,6 +153,78 @@ class InvoiceTest extends TestCase
|
||||
}
|
||||
|
||||
|
||||
public function testLineItemTaxRatesInclusiveTaxes()
|
||||
{
|
||||
$line_items = [];
|
||||
|
||||
$item = InvoiceItemFactory::create();
|
||||
$item->qty = 1;
|
||||
$item->cost =10;
|
||||
$item->tax_rate1 = 10;
|
||||
$item->tax_name1 = 10;
|
||||
|
||||
$line_items[] = $item;
|
||||
|
||||
$item = InvoiceItemFactory::create();
|
||||
$item->qty = 1;
|
||||
$item->cost =10;
|
||||
$item->tax_rate1 = 10;
|
||||
$item->tax_name1 = 10;
|
||||
|
||||
$line_items[] = $item;
|
||||
|
||||
$this->invoice->line_items = $line_items;
|
||||
$this->settings->inclusive_taxes = true;
|
||||
$this->invoice->discount = 0;
|
||||
$this->invoice->custom_value1 = 0;
|
||||
|
||||
$this->invoice_calc = new InvoiceCalc($this->invoice, $this->settings);
|
||||
$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);
|
||||
$this->assertEquals($this->invoice_calc->getTotalTaxes(), 0);
|
||||
$this->assertEquals($this->invoice_calc->getTaxMap()->count(), 2);
|
||||
}
|
||||
|
||||
public function testLineItemTaxRatesExclusiveTaxes()
|
||||
{
|
||||
|
||||
$line_items = [];
|
||||
|
||||
$item = InvoiceItemFactory::create();
|
||||
$item->qty = 1;
|
||||
$item->cost =10;
|
||||
$item->tax_rate1 = 10;
|
||||
$item->tax_name1 = 10;
|
||||
|
||||
$line_items[] = $item;
|
||||
|
||||
$item = InvoiceItemFactory::create();
|
||||
$item->qty = 1;
|
||||
$item->cost =10;
|
||||
$item->tax_rate1 = 10;
|
||||
$item->tax_name1 = 10;
|
||||
|
||||
$line_items[] = $item;
|
||||
|
||||
$this->invoice->line_items = $line_items;
|
||||
$this->invoice->discount = 0;
|
||||
$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 = new InvoiceCalc($this->invoice, $this->settings);
|
||||
$this->invoice_calc->build();
|
||||
|
||||
$this->assertEquals($this->invoice_calc->getSubTotal(), 20);
|
||||
$this->assertEquals($this->invoice_calc->getTotal(), 26);
|
||||
$this->assertEquals($this->invoice_calc->getBalance(), 26);
|
||||
$this->assertEquals($this->invoice_calc->getTotalTaxes(), 6);
|
||||
$this->assertEquals($this->invoice_calc->getTaxMap()->count(), 2);
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user