From 9fdcf7dbbe0bbdb7fab349678b2c76624397e622 Mon Sep 17 00:00:00 2001 From: cuneytsenturk Date: Wed, 7 Nov 2018 11:45:29 +0300 Subject: [PATCH] refs #602 change calculate to included --- app/Http/Controllers/Common/Items.php | 16 +++++----- app/Http/Controllers/Settings/Taxes.php | 4 +-- app/Jobs/Expense/CreateBillItem.php | 42 +++++++++++++++---------- app/Jobs/Income/CreateInvoiceItem.php | 42 +++++++++++++++---------- resources/lang/en-GB/taxes.php | 2 +- 5 files changed, 61 insertions(+), 45 deletions(-) diff --git a/app/Http/Controllers/Common/Items.php b/app/Http/Controllers/Common/Items.php index 04bb2ebfe..beaa3c34c 100644 --- a/app/Http/Controllers/Common/Items.php +++ b/app/Http/Controllers/Common/Items.php @@ -334,14 +334,14 @@ class Items extends Controller } if (!empty($item['tax_id'])) { - $calculates = $compounds = $taxes = []; + $includes = $compounds = $taxes = []; foreach ($item['tax_id'] as $tax_id) { $tax = Tax::find($tax_id); switch ($tax->type) { - case 'calculate': - $calculates[] = $tax; + case 'included': + $includes[] = $tax; break; case 'compound': $compounds[] = $tax; @@ -357,7 +357,7 @@ class Items extends Controller } } - if ($calculates) { + if ($includes) { if ($discount) { $item_tax_total = 0; @@ -369,20 +369,20 @@ class Items extends Controller } } - foreach ($calculates as $calculate) { + foreach ($includes as $include) { $item_sub_and_tax_total = $item_sub_total + $item_tax_total; - $item_tax_total = $item_sub_and_tax_total - (($item_sub_and_tax_total * (100 - $calculate->rate)) / 100); + $item_tax_total = $item_sub_and_tax_total - (($item_sub_and_tax_total * (100 - $include->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 ($calculates as $calculate) { + foreach ($includes as $include) { $item_sub_and_tax_total = $item_discount_total + $item_tax_total; - $item_tax_total = $item_sub_and_tax_total - (($item_sub_and_tax_total * (100 - $calculate->rate)) / 100); + $item_tax_total = $item_sub_and_tax_total - (($item_sub_and_tax_total * (100 - $include->rate)) / 100); $item_sub_total = $item_sub_and_tax_total - $item_tax_total; diff --git a/app/Http/Controllers/Settings/Taxes.php b/app/Http/Controllers/Settings/Taxes.php index 688dd99ef..9998ecd2f 100644 --- a/app/Http/Controllers/Settings/Taxes.php +++ b/app/Http/Controllers/Settings/Taxes.php @@ -40,7 +40,7 @@ class Taxes extends Controller { $types = [ 'normal' => trans('taxes.normal'), - 'calculate' => trans('taxes.calculate'), + 'included' => trans('taxes.included'), 'compound' => trans('taxes.compound'), ]; @@ -76,7 +76,7 @@ class Taxes extends Controller { $types = [ 'normal' => trans('taxes.normal'), - 'calculate' => trans('taxes.calculate'), + 'included' => trans('taxes.included'), 'compound' => trans('taxes.compound'), ]; diff --git a/app/Jobs/Expense/CreateBillItem.php b/app/Jobs/Expense/CreateBillItem.php index 093f167d9..662d87d03 100644 --- a/app/Jobs/Expense/CreateBillItem.php +++ b/app/Jobs/Expense/CreateBillItem.php @@ -71,14 +71,14 @@ class CreateBillItem $item_tax_total = 0; if (!empty($this->data['tax_id'])) { - $calculates = $compounds = $taxes = []; + $includes = $compounds = $taxes = []; foreach ((array) $this->data['tax_id'] as $tax_id) { $tax = Tax::find($tax_id); switch ($tax->type) { - case 'calculate': - $calculates[] = $tax; + case 'included': + $includes[] = $tax; break; case 'compound': $compounds[] = $tax; @@ -102,7 +102,7 @@ class CreateBillItem } } - if ($calculates) { + if ($includes) { if ($this->discount) { $item_tax_total = 0; @@ -114,26 +114,34 @@ class CreateBillItem } } - foreach ($calculates as $calculate) { + foreach ($includes as $include) { $item_sub_and_tax_total = $item_amount + $item_tax_total; - $item_tax_total = $item_sub_and_tax_total - (($item_sub_and_tax_total * (100 - $calculate->rate)) / 100); + $item_tax_total = $item_sub_and_tax_total - (($item_sub_and_tax_total * (100 - $include->rate)) / 100); $item_sub_total = $item_sub_and_tax_total - $item_tax_total; - $item_discount_amount = $item_sub_total - ($item_sub_total * ($this->discount / 100)); - } - } else { - foreach ($calculates as $calculate) { - $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 + ($calculate->rate / 100))); - $item_taxes[] = [ 'company_id' => $this->bill->company_id, 'bill_id' => $this->bill->id, - 'tax_id' => $calculate->id, - 'name' => $calculate->name, + 'tax_id' => $include->id, + 'name' => $include->name, + 'amount' => $tax_amount, + ]; + + $item_discount_amount = $item_sub_total - ($item_sub_total * ($this->discount / 100)); + } + } else { + foreach ($includes as $include) { + $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 + ($include->rate / 100))); + + $item_taxes[] = [ + 'company_id' => $this->bill->company_id, + 'bill_id' => $this->bill->id, + 'tax_id' => $include->id, + 'name' => $include->name, 'amount' => $tax_amount, ]; @@ -175,7 +183,7 @@ class CreateBillItem if (!empty($this->data['tax_id'])) { // set item_taxes for $bill_item->item_taxes = $item_taxes; - $bill_item->calculates = $calculates; + $bill_item->includes = $includes; $bill_item->compounds = $compounds; } diff --git a/app/Jobs/Income/CreateInvoiceItem.php b/app/Jobs/Income/CreateInvoiceItem.php index c2cfc1a68..03f99f513 100644 --- a/app/Jobs/Income/CreateInvoiceItem.php +++ b/app/Jobs/Income/CreateInvoiceItem.php @@ -98,14 +98,14 @@ class CreateInvoiceItem $item_tax_total = 0; if (!empty($this->data['tax_id'])) { - $calculates = $compounds = $taxes = []; + $includes = $compounds = $taxes = []; foreach ((array) $this->data['tax_id'] as $tax_id) { $tax = Tax::find($tax_id); switch ($tax->type) { - case 'calculate': - $calculates[] = $tax; + case 'included': + $includes[] = $tax; break; case 'compound': $compounds[] = $tax; @@ -129,7 +129,7 @@ class CreateInvoiceItem } } - if ($calculates) { + if ($includes) { if ($this->discount) { $item_tax_total = 0; @@ -141,26 +141,34 @@ class CreateInvoiceItem } } - foreach ($calculates as $calculate) { + foreach ($includes as $include) { $item_sub_and_tax_total = $item_amount + $item_tax_total; - $item_tax_total = $item_sub_and_tax_total - (($item_sub_and_tax_total * (100 - $calculate->rate)) / 100); + $item_tax_total = $item_sub_and_tax_total - (($item_sub_and_tax_total * (100 - $include->rate)) / 100); $item_sub_total = $item_sub_and_tax_total - $item_tax_total; - $item_discount_amount = $item_sub_total - ($item_sub_total * ($this->discount / 100)); - } - } else { - foreach ($calculates as $calculate) { - $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 + ($calculate->rate / 100))); - $item_taxes[] = [ 'company_id' => $this->invoice->company_id, 'invoice_id' => $this->invoice->id, - 'tax_id' => $calculate->id, - 'name' => $calculate->name, + 'tax_id' => $include->id, + 'name' => $include->name, + 'amount' => $tax_amount, + ]; + + $item_discount_amount = $item_sub_total - ($item_sub_total * ($this->discount / 100)); + } + } else { + foreach ($includes as $include) { + $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 + ($include->rate / 100))); + + $item_taxes[] = [ + 'company_id' => $this->invoice->company_id, + 'invoice_id' => $this->invoice->id, + 'tax_id' => $include->id, + 'name' => $include->name, 'amount' => $tax_amount, ]; @@ -202,7 +210,7 @@ class CreateInvoiceItem if (!empty($this->data['tax_id'])) { // set item_taxes for $invoice_item->item_taxes = $item_taxes; - $invoice_item->calculates = $calculates; + $invoice_item->includes = $includes; $invoice_item->compounds = $compounds; } diff --git a/resources/lang/en-GB/taxes.php b/resources/lang/en-GB/taxes.php index 180c8b0e1..d5aea8a56 100644 --- a/resources/lang/en-GB/taxes.php +++ b/resources/lang/en-GB/taxes.php @@ -5,7 +5,7 @@ return [ 'rate' => 'Rate', 'rate_percent' => 'Rate (%)', 'normal' => 'Normal', - 'calculate' => 'Calculate as VAT/GST', + 'included' => 'Included in Price', 'compound' => 'Compound', ];