diff --git a/VERSION.txt b/VERSION.txt index 40fdb9da290f..1dcfa2b73936 100644 --- a/VERSION.txt +++ b/VERSION.txt @@ -1 +1 @@ -5.8.30 \ No newline at end of file +5.8.31 \ No newline at end of file diff --git a/app/Helpers/Invoice/InvoiceItemSum.php b/app/Helpers/Invoice/InvoiceItemSum.php index f9dc63c972b7..b4b8bd5980d1 100644 --- a/app/Helpers/Invoice/InvoiceItemSum.php +++ b/app/Helpers/Invoice/InvoiceItemSum.php @@ -277,7 +277,7 @@ class InvoiceItemSum $item_tax += $item_tax_rate1_total; - if (strlen($this->item->tax_name1) > 2) { + if (strlen($this->item->tax_name1) > 1) { $this->groupTax($this->item->tax_name1, $this->item->tax_rate1, $item_tax_rate1_total); } @@ -285,7 +285,7 @@ class InvoiceItemSum $item_tax += $item_tax_rate2_total; - if (strlen($this->item->tax_name2) > 2) { + if (strlen($this->item->tax_name2) > 1) { $this->groupTax($this->item->tax_name2, $this->item->tax_rate2, $item_tax_rate2_total); } @@ -293,7 +293,7 @@ class InvoiceItemSum $item_tax += $item_tax_rate3_total; - if (strlen($this->item->tax_name3) > 2) { + if (strlen($this->item->tax_name3) > 1) { $this->groupTax($this->item->tax_name3, $this->item->tax_rate3, $item_tax_rate3_total); } diff --git a/app/Helpers/Invoice/InvoiceItemSumInclusive.php b/app/Helpers/Invoice/InvoiceItemSumInclusive.php index 299de3153076..a09bc9314a64 100644 --- a/app/Helpers/Invoice/InvoiceItemSumInclusive.php +++ b/app/Helpers/Invoice/InvoiceItemSumInclusive.php @@ -231,7 +231,7 @@ class InvoiceItemSumInclusive /** @var float $item_tax */ $item_tax += $this->formatValue($item_tax_rate1_total, $this->currency->precision); - if (strlen($this->item->tax_name1) > 2) { + if (strlen($this->item->tax_name1) > 1) { $this->groupTax($this->item->tax_name1, $this->item->tax_rate1, $item_tax_rate1_total); } @@ -239,7 +239,7 @@ class InvoiceItemSumInclusive $item_tax += $this->formatValue($item_tax_rate2_total, $this->currency->precision); - if (strlen($this->item->tax_name2) > 2) { + if (strlen($this->item->tax_name2) > 1) { $this->groupTax($this->item->tax_name2, $this->item->tax_rate2, $item_tax_rate2_total); } @@ -247,7 +247,7 @@ class InvoiceItemSumInclusive $item_tax += $this->formatValue($item_tax_rate3_total, $this->currency->precision); - if (strlen($this->item->tax_name3) > 2) { + if (strlen($this->item->tax_name3) > 1) { $this->groupTax($this->item->tax_name3, $this->item->tax_rate3, $item_tax_rate3_total); } diff --git a/app/Helpers/Invoice/InvoiceSum.php b/app/Helpers/Invoice/InvoiceSum.php index fd1472c18e7f..de498a2dfa91 100644 --- a/app/Helpers/Invoice/InvoiceSum.php +++ b/app/Helpers/Invoice/InvoiceSum.php @@ -316,8 +316,10 @@ class InvoiceSum $this->tax_map = collect(); $keys = $this->invoice_items->getGroupedTaxes()->pluck('key')->unique(); +nlog($keys); $values = $this->invoice_items->getGroupedTaxes(); +nlog($values); foreach ($keys as $key) { $tax_name = $values->filter(function ($value, $k) use ($key) { diff --git a/app/Helpers/Invoice/InvoiceSumInclusive.php b/app/Helpers/Invoice/InvoiceSumInclusive.php index d213874e68b2..3786b55f99e6 100644 --- a/app/Helpers/Invoice/InvoiceSumInclusive.php +++ b/app/Helpers/Invoice/InvoiceSumInclusive.php @@ -340,8 +340,7 @@ class InvoiceSumInclusive $this->total_taxes += $total_line_tax; } -nlog($this->tax_map); -nlog($this->total_taxes); + return $this; } diff --git a/config/ninja.php b/config/ninja.php index 3f9061733a16..d9174d53721e 100644 --- a/config/ninja.php +++ b/config/ninja.php @@ -17,8 +17,8 @@ return [ 'require_https' => env('REQUIRE_HTTPS', true), 'app_url' => rtrim(env('APP_URL', ''), '/'), 'app_domain' => env('APP_DOMAIN', 'invoicing.co'), - 'app_version' => env('APP_VERSION', '5.8.30'), - 'app_tag' => env('APP_TAG', '5.8.30'), + 'app_version' => env('APP_VERSION', '5.8.31'), + 'app_tag' => env('APP_TAG', '5.8.31'), 'minimum_client_version' => '5.0.16', 'terms_version' => '1.0.1', 'api_secret' => env('API_SECRET', false), diff --git a/tests/Unit/InvoiceItemTest.php b/tests/Unit/InvoiceItemTest.php index 6b736f4005e5..d3aeb1a72999 100644 --- a/tests/Unit/InvoiceItemTest.php +++ b/tests/Unit/InvoiceItemTest.php @@ -36,6 +36,42 @@ class InvoiceItemTest extends TestCase } + public function testEdgeCasewithDiscountsPercentageAndTaxCalculations() + { + $invoice = InvoiceFactory::create($this->company->id, $this->user->id); + $invoice->client_id = $this->client->id; + $invoice->uses_inclusive_taxes = false; + $invoice->is_amount_discount =false; + $invoice->discount = 0; + $invoice->tax_rate1 = 0; + $invoice->tax_rate2 = 0; + $invoice->tax_rate3 = 0; + $invoice->tax_name1 = ''; + $invoice->tax_name2 = ''; + $invoice->tax_name3 = ''; + + $line_items = []; + + $line_item = new InvoiceItem; + $line_item->quantity = 1; + $line_item->cost = 100; + $line_item->tax_rate1 = 22; + $line_item->tax_name1 = 'Km'; + $line_item->product_key = 'Test'; + $line_item->notes = 'Test'; + $line_item->is_amount_discount = false; + $line_items[] = $line_item; + + $invoice->line_items = $line_items; + $invoice->save(); + + $invoice = $invoice->calc()->getInvoice(); + + $this->assertEquals(122, $invoice->amount); + $this->assertEquals(22, $invoice->total_taxes); + } + + public function testDiscountsWithInclusiveTaxes() { $invoice = InvoiceFactory::create($this->company->id, $this->user->id);