diff --git a/app/Helpers/Invoice/InvoiceSumInclusive.php b/app/Helpers/Invoice/InvoiceSumInclusive.php index f4a57f27de..3786b55f99 100644 --- a/app/Helpers/Invoice/InvoiceSumInclusive.php +++ b/app/Helpers/Invoice/InvoiceSumInclusive.php @@ -122,7 +122,7 @@ class InvoiceSumInclusive private function calculateInvoiceTaxes() { $amount = $this->total; - + if ($this->invoice->discount > 0 && $this->invoice->is_amount_discount) { $amount = $this->formatValue(($this->sub_total - $this->invoice->discount), 2); } @@ -131,20 +131,20 @@ class InvoiceSumInclusive $amount = $this->formatValue(($this->sub_total - ($this->sub_total * ($this->invoice->discount / 100))), 2); } - if (is_string($this->invoice->tax_name1) && strlen($this->invoice->tax_name1) > 2) { + if (is_string($this->invoice->tax_name1) && strlen($this->invoice->tax_name1) > 1) { $tax = $this->calcInclusiveLineTax($this->invoice->tax_rate1, $amount); $this->total_taxes += $tax; $this->total_tax_map[] = ['name' => $this->invoice->tax_name1.' '.floatval($this->invoice->tax_rate1).'%', 'total' => $tax]; } - if (is_string($this->invoice->tax_name2) && strlen($this->invoice->tax_name2) > 2) { + if (is_string($this->invoice->tax_name2) && strlen($this->invoice->tax_name2) > 1) { $tax = $this->calcInclusiveLineTax($this->invoice->tax_rate2, $amount); $this->total_taxes += $tax; $this->total_tax_map[] = ['name' => $this->invoice->tax_name2.' '.floatval($this->invoice->tax_rate2).'%', 'total' => $tax]; } - if (is_string($this->invoice->tax_name3) && strlen($this->invoice->tax_name3) > 2) { + if (is_string($this->invoice->tax_name3) && strlen($this->invoice->tax_name3) > 1) { $tax = $this->calcInclusiveLineTax($this->invoice->tax_rate3, $amount); $this->total_taxes += $tax; $this->total_tax_map[] = ['name' => $this->invoice->tax_name3.' '.floatval($this->invoice->tax_rate3).'%', 'total' => $tax]; diff --git a/tests/Unit/InvoiceInclusiveTest.php b/tests/Unit/InvoiceInclusiveTest.php index e4b6b5d870..c5e8eba22a 100644 --- a/tests/Unit/InvoiceInclusiveTest.php +++ b/tests/Unit/InvoiceInclusiveTest.php @@ -66,6 +66,8 @@ class InvoiceInclusiveTest extends TestCase public function testInvoiceTotals() { + + $this->invoice_calc = new InvoiceSumInclusive($this->invoice); $this->invoice_calc->build(); $this->assertEquals($this->invoice_calc->getSubTotal(), 20); @@ -76,6 +78,8 @@ class InvoiceInclusiveTest extends TestCase { $this->invoice->discount = 5; + + $this->invoice_calc = new InvoiceSumInclusive($this->invoice); $this->invoice_calc->build(); $this->assertEquals($this->invoice_calc->getSubTotal(), 20); @@ -88,6 +92,8 @@ class InvoiceInclusiveTest extends TestCase $this->invoice->discount = 5; $this->invoice->custom_surcharge1 = 5; + + $this->invoice_calc = new InvoiceSumInclusive($this->invoice); $this->invoice_calc->build(); $this->assertEquals($this->invoice_calc->getSubTotal(), 20); @@ -103,6 +109,8 @@ class InvoiceInclusiveTest extends TestCase $this->invoice->tax_rate1 = 10; $this->invoice->is_amount_discount = true; + + $this->invoice_calc = new InvoiceSumInclusive($this->invoice); $this->invoice_calc->build(); $this->assertEquals($this->invoice_calc->getSubTotal(), 20); @@ -119,6 +127,7 @@ class InvoiceInclusiveTest extends TestCase $this->invoice->tax_rate1 = 10; $this->invoice->is_amount_discount = false; + $this->invoice_calc = new InvoiceSumInclusive($this->invoice); $this->invoice_calc->build(); $this->assertEquals($this->invoice_calc->getSubTotal(), 20); @@ -135,6 +144,7 @@ class InvoiceInclusiveTest extends TestCase $this->invoice->uses_inclusive_taxes = true; $this->invoice->is_amount_discount = true; + $this->invoice_calc = new InvoiceSumInclusive($this->invoice); $this->invoice_calc->build(); $this->assertEquals($this->invoice_calc->getSubTotal(), 20); @@ -154,6 +164,8 @@ class InvoiceInclusiveTest extends TestCase $this->invoice->uses_inclusive_taxes = true; $this->invoice->is_amount_discount = true; + + $this->invoice_calc = new InvoiceSumInclusive($this->invoice); $this->invoice_calc->build(); $this->assertEquals($this->invoice_calc->getSubTotal(), 20); @@ -170,7 +182,10 @@ class InvoiceInclusiveTest extends TestCase $item->cost = 10; $item->tax_rate1 = 10; $item->tax_name1 = 10; - + $item->tax_rate2 = 0; + $item->tax_name2 = ''; + $item->tax_rate3 = 0; + $item->tax_name3 = ''; $line_items[] = $item; $item = InvoiceItemFactory::create(); @@ -178,6 +193,10 @@ class InvoiceInclusiveTest extends TestCase $item->cost = 10; $item->tax_rate1 = 10; $item->tax_name1 = 10; + $item->tax_rate2 = 0; + $item->tax_name2 = ''; + $item->tax_rate3 = 0; + $item->tax_name3 = ''; $line_items[] = $item; @@ -223,14 +242,17 @@ class InvoiceInclusiveTest extends TestCase $this->invoice->discount = 0; $this->invoice->custom_surcharge1 = 0; + $this->invoice->tax_name1 = 'dog'; + $this->invoice->tax_name2 = 'cat'; $this->invoice->tax_rate1 = 10; $this->invoice->tax_rate2 = 10; + $this->invoice_calc = null; $this->invoice_calc = new InvoiceSumInclusive($this->invoice, $this->settings); $this->invoice_calc->build(); - $this->assertEquals($this->invoice_calc->getSubTotal(), 20); - $this->assertEquals($this->invoice_calc->getTotalTaxes(), 5.46); + $this->assertEquals(20, $this->invoice_calc->getSubTotal()); + $this->assertEquals(5.46, $this->invoice_calc->getTotalTaxes()); $this->assertEquals(count($this->invoice_calc->getTaxMap()), 1); $this->assertEquals($this->invoice_calc->getTotal(), 20); $this->assertEquals($this->invoice_calc->getBalance(), 20); @@ -268,6 +290,10 @@ class InvoiceInclusiveTest extends TestCase $this->invoice->tax_rate1 = 10; $this->invoice->tax_rate2 = 10; +$this->invoice->tax_name1 = 'dog'; +$this->invoice->tax_name2 = 'cat'; + + $this->invoice_calc = null; $this->invoice_calc = new InvoiceSumInclusive($this->invoice, $this->settings); $this->invoice_calc->build(); @@ -316,6 +342,9 @@ class InvoiceInclusiveTest extends TestCase $this->invoice->tax_rate1 = 10; $this->invoice->tax_rate2 = 10; +$this->invoice->tax_name1 = 'dog'; +$this->invoice->tax_name2 = 'cat'; + $this->invoice_calc = new InvoiceSumInclusive($this->invoice, $this->settings); $this->invoice_calc->build(); @@ -361,6 +390,9 @@ class InvoiceInclusiveTest extends TestCase $this->invoice->tax_rate1 = 10; $this->invoice->tax_rate2 = 10; + $this->invoice->tax_name1 = 'dog'; + $this->invoice->tax_name2 = 'cat'; + $this->invoice_calc = new InvoiceSumInclusive($this->invoice, $this->settings); $this->invoice_calc->build();