From b135f0a57b87a6ff1b4bf07cf2d2b01dfa37be04 Mon Sep 17 00:00:00 2001 From: sausin Date: Sun, 3 Feb 2019 21:01:08 +0530 Subject: [PATCH 1/3] Closes #688 The additional point about restricting the types of taxes is not covered here. --- app/Jobs/Expense/CreateBillItem.php | 56 ++++++++--------------------- 1 file changed, 14 insertions(+), 42 deletions(-) diff --git a/app/Jobs/Expense/CreateBillItem.php b/app/Jobs/Expense/CreateBillItem.php index b1d7af6d3..d66446384 100644 --- a/app/Jobs/Expense/CreateBillItem.php +++ b/app/Jobs/Expense/CreateBillItem.php @@ -103,51 +103,23 @@ class CreateBillItem } if ($inclusives) { - if ($this->discount) { - $item_tax_total = 0; + $item_amount = $item_discount_amount + $item_tax_total; - if ($taxes) { - foreach ($taxes as $tax) { - $item_tax_amount = ($item_amount / 100) * $tax->rate; + $item_base_rate = $item_amount / (1 + collect($inclusives)->sum('rate')/100); + + foreach ($inclusives as $inclusive) { + $item_tax_total += $tax_amount = $item_base_rate * ($inclusive->rate / 100); - $item_tax_total += $item_tax_amount; - } - } - - foreach ($inclusives as $inclusive) { - $item_sub_and_tax_total = $item_amount + $item_tax_total; - - $item_tax_total = $item_sub_and_tax_total - ($item_sub_and_tax_total / (1 + ($inclusive->rate / 100))); - - $item_sub_total = $item_sub_and_tax_total - $item_tax_total; - - $item_taxes[] = [ - 'company_id' => $this->bill->company_id, - 'bill_id' => $this->bill->id, - 'tax_id' => $inclusive->id, - 'name' => $inclusive->name, - 'amount' => $tax_amount, - ]; - - $item_discount_amount = $item_sub_total - ($item_sub_total * ($this->discount / 100)); - } - } else { - foreach ($inclusives as $inclusive) { - $item_sub_and_tax_total = $item_discount_amount + $item_tax_total; - - $item_tax_total = $tax_amount = $item_sub_and_tax_total - ($item_sub_and_tax_total / (1 + ($inclusive->rate / 100))); - - $item_taxes[] = [ - 'company_id' => $this->bill->company_id, - 'bill_id' => $this->bill->id, - 'tax_id' => $inclusive->id, - 'name' => $inclusive->name, - 'amount' => $tax_amount, - ]; - - $item_amount = $item_sub_and_tax_total - $item_tax_total; - } + $item_taxes[] = [ + 'company_id' => $this->bill->company_id, + 'bill_id' => $this->bill->id, + 'tax_id' => $inclusive->id, + 'name' => $inclusive->name, + 'amount' => $tax_amount, + ]; } + + $item_amount = ($item_amount - $item_tax_total) / (1 - $this->discount / 100); } if ($compounds) { From 1bef5738f44ba2ee5a28a2d906046cafefba9cf0 Mon Sep 17 00:00:00 2001 From: sausin Date: Sun, 3 Feb 2019 21:23:50 +0530 Subject: [PATCH 2/3] Update Items.php --- app/Http/Controllers/Common/Items.php | 33 ++++----------------------- 1 file changed, 4 insertions(+), 29 deletions(-) diff --git a/app/Http/Controllers/Common/Items.php b/app/Http/Controllers/Common/Items.php index 6e7f8a4e3..076f22aeb 100644 --- a/app/Http/Controllers/Common/Items.php +++ b/app/Http/Controllers/Common/Items.php @@ -358,37 +358,12 @@ class Items extends Controller } if ($inclusives) { - if ($discount) { - $item_tax_total = 0; + $item_sub_and_tax_total = $item_discount_total + $item_tax_total; - if ($taxes) { - foreach ($taxes as $tax) { - $item_tax_amount = ($item_sub_total / 100) * $tax->rate; + $item_base_rate = $item_sub_and_tax_total / (1 + collect($inclusives)->sum('rate')/100); + $item_tax_total = $item_sub_and_tax_total - $item_base_rate; - $item_tax_total += $item_tax_amount; - } - } - - foreach ($inclusives as $inclusive) { - $item_sub_and_tax_total = $item_sub_total + $item_tax_total; - - $item_tax_total = $item_sub_and_tax_total - ($item_sub_and_tax_total / (1 + ($inclusive->rate / 100))); - - $item_sub_total = $item_sub_and_tax_total - $item_tax_total; - - $item_discount_total = $item_sub_total - ($item_sub_total * ($discount / 100)); - } - } else { - foreach ($inclusives as $inclusive) { - $item_sub_and_tax_total = $item_discount_total + $item_tax_total; - - $item_tax_total = $item_sub_and_tax_total - ($item_sub_and_tax_total / (1 + ($inclusive->rate / 100))); - - $item_sub_total = $item_sub_and_tax_total - $item_tax_total; - - $item_discount_total = $item_sub_total - ($item_sub_total * ($discount / 100)); - } - } + $item_sub_total = $item_base_rate + $discount; } if ($compounds) { From 31e076b59d00de11b6acbf1d17896e0c4bf709d6 Mon Sep 17 00:00:00 2001 From: cuneytsenturk Date: Thu, 7 Mar 2019 12:01:32 +0300 Subject: [PATCH 3/3] refs #688 add this changes InvoiceItem Tax --- app/Jobs/Expense/CreateBillItem.php | 12 +++--- app/Jobs/Income/CreateInvoiceItem.php | 54 +++++++-------------------- 2 files changed, 19 insertions(+), 47 deletions(-) diff --git a/app/Jobs/Expense/CreateBillItem.php b/app/Jobs/Expense/CreateBillItem.php index d66446384..f61d70ecb 100644 --- a/app/Jobs/Expense/CreateBillItem.php +++ b/app/Jobs/Expense/CreateBillItem.php @@ -106,16 +106,16 @@ class CreateBillItem $item_amount = $item_discount_amount + $item_tax_total; $item_base_rate = $item_amount / (1 + collect($inclusives)->sum('rate')/100); - + foreach ($inclusives as $inclusive) { $item_tax_total += $tax_amount = $item_base_rate * ($inclusive->rate / 100); $item_taxes[] = [ - 'company_id' => $this->bill->company_id, - 'bill_id' => $this->bill->id, - 'tax_id' => $inclusive->id, - 'name' => $inclusive->name, - 'amount' => $tax_amount, + 'company_id' => $this->bill->company_id, + 'bill_id' => $this->bill->id, + 'tax_id' => $inclusive->id, + 'name' => $inclusive->name, + 'amount' => $tax_amount, ]; } diff --git a/app/Jobs/Income/CreateInvoiceItem.php b/app/Jobs/Income/CreateInvoiceItem.php index 83ec50bfd..4b9454d35 100644 --- a/app/Jobs/Income/CreateInvoiceItem.php +++ b/app/Jobs/Income/CreateInvoiceItem.php @@ -130,51 +130,23 @@ class CreateInvoiceItem } if ($inclusives) { - if ($this->discount) { - $item_tax_total = 0; + $item_amount = $item_discount_amount + $item_tax_total; - if ($taxes) { - foreach ($taxes as $tax) { - $item_tax_amount = ($item_amount / 100) * $tax->rate; + $item_base_rate = $item_amount / (1 + collect($inclusives)->sum('rate')/100); - $item_tax_total += $item_tax_amount; - } - } + foreach ($inclusives as $inclusive) { + $item_tax_total += $tax_amount = $item_base_rate * ($inclusive->rate / 100); - foreach ($inclusives as $inclusive) { - $item_sub_and_tax_total = $item_amount + $item_tax_total; - - $item_tax_total = $item_sub_and_tax_total - ($item_sub_and_tax_total / (1 + ($inclusive->rate / 100))); - - $item_sub_total = $item_sub_and_tax_total - $item_tax_total; - - $item_taxes[] = [ - 'company_id' => $this->invoice->company_id, - 'invoice_id' => $this->invoice->id, - 'tax_id' => $inclusive->id, - 'name' => $inclusive->name, - 'amount' => $tax_amount, - ]; - - $item_discount_amount = $item_sub_total - ($item_sub_total * ($this->discount / 100)); - } - } else { - foreach ($inclusives as $inclusive) { - $item_sub_and_tax_total = $item_discount_amount + $item_tax_total; - - $item_tax_total = $tax_amount = $item_sub_and_tax_total - ($item_sub_and_tax_total / (1 + ($inclusive->rate / 100))); - - $item_taxes[] = [ - 'company_id' => $this->invoice->company_id, - 'invoice_id' => $this->invoice->id, - 'tax_id' => $inclusive->id, - 'name' => $inclusive->name, - 'amount' => $tax_amount, - ]; - - $item_amount = $item_sub_and_tax_total - $item_tax_total; - } + $item_taxes[] = [ + 'company_id' => $this->invoice->company_id, + 'invoice_id' => $this->invoice->id, + 'tax_id' => $inclusive->id, + 'name' => $inclusive->name, + 'amount' => $tax_amount, + ]; } + + $item_amount = ($item_amount - $item_tax_total) / (1 - $this->discount / 100); } if ($compounds) {