Skip to content

Commit

Permalink
refs #602 change calculate to included
Browse files Browse the repository at this point in the history
  • Loading branch information
cuneytsenturk committed Nov 7, 2018
1 parent 4131237 commit 9fdcf7d
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 33 deletions.
16 changes: 8 additions & 8 deletions app/Http/Controllers/Common/Items.php
Original file line number Diff line number Diff line change
Expand Up @@ -334,14 +334,14 @@ public function totalItem(TRequest $request)
}

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;
Expand All @@ -357,7 +357,7 @@ public function totalItem(TRequest $request)
}
}

if ($calculates) {
if ($includes) {
if ($discount) {
$item_tax_total = 0;

Expand All @@ -369,20 +369,20 @@ public function totalItem(TRequest $request)
}
}

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;

Expand Down
4 changes: 2 additions & 2 deletions app/Http/Controllers/Settings/Taxes.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function create()
{
$types = [
'normal' => trans('taxes.normal'),
'calculate' => trans('taxes.calculate'),
'included' => trans('taxes.included'),
'compound' => trans('taxes.compound'),
];

Expand Down Expand Up @@ -76,7 +76,7 @@ public function edit(Tax $tax)
{
$types = [
'normal' => trans('taxes.normal'),
'calculate' => trans('taxes.calculate'),
'included' => trans('taxes.included'),
'compound' => trans('taxes.compound'),
];

Expand Down
30 changes: 19 additions & 11 deletions app/Jobs/Expense/CreateBillItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,14 @@ public function handle()
$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;
Expand All @@ -102,7 +102,7 @@ public function handle()
}
}

if ($calculates) {
if ($includes) {
if ($this->discount) {
$item_tax_total = 0;

Expand All @@ -114,26 +114,34 @@ public function handle()
}
}

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_taxes[] = [
'company_id' => $this->bill->company_id,
'bill_id' => $this->bill->id,
'tax_id' => $include->id,
'name' => $include->name,
'amount' => $tax_amount,
];

$item_discount_amount = $item_sub_total - ($item_sub_total * ($this->discount / 100));
}
} else {
foreach ($calculates as $calculate) {
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 + ($calculate->rate / 100)));
$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' => $calculate->id,
'name' => $calculate->name,
'tax_id' => $include->id,
'name' => $include->name,
'amount' => $tax_amount,
];

Expand Down Expand Up @@ -175,7 +183,7 @@ public function handle()
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;
}

Expand Down
30 changes: 19 additions & 11 deletions app/Jobs/Income/CreateInvoiceItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,14 @@ public function handle()
$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;
Expand All @@ -129,7 +129,7 @@ public function handle()
}
}

if ($calculates) {
if ($includes) {
if ($this->discount) {
$item_tax_total = 0;

Expand All @@ -141,26 +141,34 @@ public function handle()
}
}

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_taxes[] = [
'company_id' => $this->invoice->company_id,
'invoice_id' => $this->invoice->id,
'tax_id' => $include->id,
'name' => $include->name,
'amount' => $tax_amount,
];

$item_discount_amount = $item_sub_total - ($item_sub_total * ($this->discount / 100));
}
} else {
foreach ($calculates as $calculate) {
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 + ($calculate->rate / 100)));
$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' => $calculate->id,
'name' => $calculate->name,
'tax_id' => $include->id,
'name' => $include->name,
'amount' => $tax_amount,
];

Expand Down Expand Up @@ -202,7 +210,7 @@ public function handle()
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;
}

Expand Down
2 changes: 1 addition & 1 deletion resources/lang/en-GB/taxes.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
'rate' => 'Rate',
'rate_percent' => 'Rate (%)',
'normal' => 'Normal',
'calculate' => 'Calculate as VAT/GST',
'included' => 'Included in Price',
'compound' => 'Compound',

];

0 comments on commit 9fdcf7d

Please sign in to comment.