refs #602 change calculate to included

This commit is contained in:
cuneytsenturk 2018-11-07 11:45:29 +03:00
parent 4131237c47
commit 9fdcf7dbbe
5 changed files with 61 additions and 45 deletions

View File

@ -334,14 +334,14 @@ class Items extends Controller
} }
if (!empty($item['tax_id'])) { if (!empty($item['tax_id'])) {
$calculates = $compounds = $taxes = []; $includes = $compounds = $taxes = [];
foreach ($item['tax_id'] as $tax_id) { foreach ($item['tax_id'] as $tax_id) {
$tax = Tax::find($tax_id); $tax = Tax::find($tax_id);
switch ($tax->type) { switch ($tax->type) {
case 'calculate': case 'included':
$calculates[] = $tax; $includes[] = $tax;
break; break;
case 'compound': case 'compound':
$compounds[] = $tax; $compounds[] = $tax;
@ -357,7 +357,7 @@ class Items extends Controller
} }
} }
if ($calculates) { if ($includes) {
if ($discount) { if ($discount) {
$item_tax_total = 0; $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_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_sub_total = $item_sub_and_tax_total - $item_tax_total;
$item_discount_total = $item_sub_total - ($item_sub_total * ($discount / 100)); $item_discount_total = $item_sub_total - ($item_sub_total * ($discount / 100));
} }
} else { } else {
foreach ($calculates as $calculate) { foreach ($includes as $include) {
$item_sub_and_tax_total = $item_discount_total + $item_tax_total; $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; $item_sub_total = $item_sub_and_tax_total - $item_tax_total;

View File

@ -40,7 +40,7 @@ class Taxes extends Controller
{ {
$types = [ $types = [
'normal' => trans('taxes.normal'), 'normal' => trans('taxes.normal'),
'calculate' => trans('taxes.calculate'), 'included' => trans('taxes.included'),
'compound' => trans('taxes.compound'), 'compound' => trans('taxes.compound'),
]; ];
@ -76,7 +76,7 @@ class Taxes extends Controller
{ {
$types = [ $types = [
'normal' => trans('taxes.normal'), 'normal' => trans('taxes.normal'),
'calculate' => trans('taxes.calculate'), 'included' => trans('taxes.included'),
'compound' => trans('taxes.compound'), 'compound' => trans('taxes.compound'),
]; ];

View File

@ -71,14 +71,14 @@ class CreateBillItem
$item_tax_total = 0; $item_tax_total = 0;
if (!empty($this->data['tax_id'])) { if (!empty($this->data['tax_id'])) {
$calculates = $compounds = $taxes = []; $includes = $compounds = $taxes = [];
foreach ((array) $this->data['tax_id'] as $tax_id) { foreach ((array) $this->data['tax_id'] as $tax_id) {
$tax = Tax::find($tax_id); $tax = Tax::find($tax_id);
switch ($tax->type) { switch ($tax->type) {
case 'calculate': case 'included':
$calculates[] = $tax; $includes[] = $tax;
break; break;
case 'compound': case 'compound':
$compounds[] = $tax; $compounds[] = $tax;
@ -102,7 +102,7 @@ class CreateBillItem
} }
} }
if ($calculates) { if ($includes) {
if ($this->discount) { if ($this->discount) {
$item_tax_total = 0; $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_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_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[] = [ $item_taxes[] = [
'company_id' => $this->bill->company_id, 'company_id' => $this->bill->company_id,
'bill_id' => $this->bill->id, 'bill_id' => $this->bill->id,
'tax_id' => $calculate->id, 'tax_id' => $include->id,
'name' => $calculate->name, '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, 'amount' => $tax_amount,
]; ];
@ -175,7 +183,7 @@ class CreateBillItem
if (!empty($this->data['tax_id'])) { if (!empty($this->data['tax_id'])) {
// set item_taxes for // set item_taxes for
$bill_item->item_taxes = $item_taxes; $bill_item->item_taxes = $item_taxes;
$bill_item->calculates = $calculates; $bill_item->includes = $includes;
$bill_item->compounds = $compounds; $bill_item->compounds = $compounds;
} }

View File

@ -98,14 +98,14 @@ class CreateInvoiceItem
$item_tax_total = 0; $item_tax_total = 0;
if (!empty($this->data['tax_id'])) { if (!empty($this->data['tax_id'])) {
$calculates = $compounds = $taxes = []; $includes = $compounds = $taxes = [];
foreach ((array) $this->data['tax_id'] as $tax_id) { foreach ((array) $this->data['tax_id'] as $tax_id) {
$tax = Tax::find($tax_id); $tax = Tax::find($tax_id);
switch ($tax->type) { switch ($tax->type) {
case 'calculate': case 'included':
$calculates[] = $tax; $includes[] = $tax;
break; break;
case 'compound': case 'compound':
$compounds[] = $tax; $compounds[] = $tax;
@ -129,7 +129,7 @@ class CreateInvoiceItem
} }
} }
if ($calculates) { if ($includes) {
if ($this->discount) { if ($this->discount) {
$item_tax_total = 0; $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_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_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[] = [ $item_taxes[] = [
'company_id' => $this->invoice->company_id, 'company_id' => $this->invoice->company_id,
'invoice_id' => $this->invoice->id, 'invoice_id' => $this->invoice->id,
'tax_id' => $calculate->id, 'tax_id' => $include->id,
'name' => $calculate->name, '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, 'amount' => $tax_amount,
]; ];
@ -202,7 +210,7 @@ class CreateInvoiceItem
if (!empty($this->data['tax_id'])) { if (!empty($this->data['tax_id'])) {
// set item_taxes for // set item_taxes for
$invoice_item->item_taxes = $item_taxes; $invoice_item->item_taxes = $item_taxes;
$invoice_item->calculates = $calculates; $invoice_item->includes = $includes;
$invoice_item->compounds = $compounds; $invoice_item->compounds = $compounds;
} }

View File

@ -5,7 +5,7 @@ return [
'rate' => 'Rate', 'rate' => 'Rate',
'rate_percent' => 'Rate (%)', 'rate_percent' => 'Rate (%)',
'normal' => 'Normal', 'normal' => 'Normal',
'calculate' => 'Calculate as VAT/GST', 'included' => 'Included in Price',
'compound' => 'Compound', 'compound' => 'Compound',
]; ];