Tax rate change workflow.
This commit is contained in:
@ -323,20 +323,78 @@ class Items extends Controller
|
||||
$quantity = (double) $item['quantity'];
|
||||
|
||||
$item_tax_total = 0;
|
||||
$item_tax_amount = 0;
|
||||
|
||||
$item_sub_total = ($price * $quantity);
|
||||
$item_discount_total = $item_sub_total;
|
||||
|
||||
// Apply discount to item
|
||||
if ($discount) {
|
||||
$item_discount_total = $item_sub_total - ($item_sub_total * ($discount / 100));
|
||||
}
|
||||
|
||||
if (!empty($item['tax_id'])) {
|
||||
$calculates = $compounds = $taxes = [];
|
||||
|
||||
foreach ($item['tax_id'] as $tax_id) {
|
||||
$tax = Tax::find($tax_id);
|
||||
|
||||
$item_tax = (($price * $quantity) / 100) * $tax->rate;
|
||||
switch ($tax->type) {
|
||||
case 'calculate':
|
||||
$calculates[] = $tax;
|
||||
break;
|
||||
case 'compound':
|
||||
$compounds[] = $tax;
|
||||
break;
|
||||
case 'normal':
|
||||
default:
|
||||
$taxes[] = $tax;
|
||||
|
||||
// Apply discount to tax
|
||||
if ($discount) {
|
||||
$item_tax = $item_tax - ($item_tax * ($discount / 100));
|
||||
$item_tax_amount = ($item_discount_total / 100) * $tax->rate;
|
||||
|
||||
$item_tax_total += $item_tax_amount;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$item_tax_total += $item_tax;
|
||||
if ($calculates) {
|
||||
if ($discount) {
|
||||
$item_tax_total = 0;
|
||||
|
||||
if ($taxes) {
|
||||
foreach ($taxes as $tax) {
|
||||
$item_tax_amount = ($item_sub_total / 100) * $tax->rate;
|
||||
|
||||
$item_tax_total += $item_tax_amount;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($calculates as $calculate) {
|
||||
$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_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) {
|
||||
$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_sub_total = $item_sub_and_tax_total - $item_tax_total;
|
||||
|
||||
$item_discount_total = $item_sub_total - ($item_sub_total * ($discount / 100));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($compounds) {
|
||||
foreach ($compounds as $compound) {
|
||||
$item_tax_total += (($item_discount_total + $item_tax_total) / 100) * $compound->rate;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -38,7 +38,13 @@ class Taxes extends Controller
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
return view('settings.taxes.create');
|
||||
$types = [
|
||||
'normal' => trans('taxes.normal'),
|
||||
'calculate' => trans('taxes.calculate'),
|
||||
'compound' => trans('taxes.compound'),
|
||||
];
|
||||
|
||||
return view('settings.taxes.create', compact('types'));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -68,7 +74,13 @@ class Taxes extends Controller
|
||||
*/
|
||||
public function edit(Tax $tax)
|
||||
{
|
||||
return view('settings.taxes.edit', compact('tax'));
|
||||
$types = [
|
||||
'normal' => trans('taxes.normal'),
|
||||
'calculate' => trans('taxes.calculate'),
|
||||
'compound' => trans('taxes.compound'),
|
||||
];
|
||||
|
||||
return view('settings.taxes.edit', compact('tax', 'types'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user