Multible Tax files for Items
This commit is contained in:
@ -211,10 +211,10 @@ class Bills extends Controller
|
||||
|
||||
// Set taxes
|
||||
if (isset($tax_object)) {
|
||||
if (isset($taxes['VAT']) && array_key_exists($tax_object->id, $taxes['VAT'])) {
|
||||
$taxes['VAT'][$tax_object->id]['amount'] += $tax;
|
||||
if (isset($taxes) && array_key_exists($tax_object->id, $taxes)) {
|
||||
$taxes[$tax_object->id]['amount'] += $tax;
|
||||
} else {
|
||||
$taxes['VAT'][$tax_object->id] = [
|
||||
$taxes[$tax_object->id] = [
|
||||
'name' => $tax_object->name,
|
||||
'amount' => $tax
|
||||
];
|
||||
@ -229,30 +229,6 @@ class Bills extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
if ($request['multiple_tax']) {
|
||||
foreach ($request['multiple_tax'] as $multiple_tax) {
|
||||
if ($multiple_tax['position'] != 'GST') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$multible_tax_object = Tax::find($multiple_tax['tax_id']);
|
||||
|
||||
$multiple_tax_amount = ($sub_total / 100) * $multible_tax_object->rate;
|
||||
|
||||
if (isset($taxes['GST']) && array_key_exists($multible_tax_object->id, $taxes['GST'])) {
|
||||
$taxes['GST'][$multible_tax_object->id]['amount'] += $multiple_tax_amount;
|
||||
} else {
|
||||
$taxes['GST'][$multible_tax_object->id] = [
|
||||
'id' => $multible_tax_object->id,
|
||||
'name' => $multible_tax_object->name,
|
||||
'amount' => $multiple_tax_amount
|
||||
];
|
||||
}
|
||||
|
||||
$sub_total += $multiple_tax_amount;
|
||||
}
|
||||
}
|
||||
|
||||
$s_total = $sub_total;
|
||||
|
||||
// Apply discount to total
|
||||
@ -262,30 +238,6 @@ class Bills extends Controller
|
||||
$s_total = $s_total - $s_discount;
|
||||
}
|
||||
|
||||
if ($request['multiple_tax']) {
|
||||
foreach ($request['multiple_tax'] as $multiple_tax) {
|
||||
if ($multiple_tax['position'] != 'PST') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$multible_tax_object = Tax::find($multiple_tax['tax_id']);
|
||||
|
||||
$multiple_tax_amount = ($s_total / 100) * $multible_tax_object->rate;
|
||||
|
||||
if (isset($taxes['PST']) && array_key_exists($multible_tax_object->id, $taxes['PST'])) {
|
||||
$taxes['PST'][$multible_tax_object->id]['amount'] += $multiple_tax_amount;
|
||||
} else {
|
||||
$taxes['PST'][$multible_tax_object->id] = [
|
||||
'id' => $multible_tax_object->id,
|
||||
'name' => $multible_tax_object->name,
|
||||
'amount' => $multiple_tax_amount
|
||||
];
|
||||
}
|
||||
|
||||
$tax_total += $multiple_tax_amount;
|
||||
}
|
||||
}
|
||||
|
||||
$amount = $s_total + $tax_total;
|
||||
|
||||
$request['amount'] = money($amount, $request['currency_code'])->getAmount();
|
||||
@ -422,6 +374,7 @@ class Bills extends Controller
|
||||
public function update(Bill $bill, Request $request)
|
||||
{
|
||||
$taxes = [];
|
||||
|
||||
$tax_total = 0;
|
||||
$sub_total = 0;
|
||||
$discount_total = 0;
|
||||
@ -470,10 +423,10 @@ class Bills extends Controller
|
||||
$bill_item['total'] = (double) $item['price'] * (double) $item['quantity'];
|
||||
|
||||
if (isset($tax_object)) {
|
||||
if (isset($taxes['VAT']) && array_key_exists($tax_object->id, $taxes['VAT'])) {
|
||||
$taxes['VAT'][$tax_object->id]['amount'] += $tax;
|
||||
if (isset($taxes) && array_key_exists($tax_object->id, $taxes)) {
|
||||
$taxes[$tax_object->id]['amount'] += $tax;
|
||||
} else {
|
||||
$taxes['VAT'][$tax_object->id] = [
|
||||
$taxes[$tax_object->id] = [
|
||||
'name' => $tax_object->name,
|
||||
'amount' => $tax
|
||||
];
|
||||
@ -487,30 +440,6 @@ class Bills extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
if ($request['multiple_tax']) {
|
||||
foreach ($request['multiple_tax'] as $multiple_tax) {
|
||||
if ($multiple_tax['position'] != 'GST') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$multible_tax_object = Tax::find($multiple_tax['tax_id']);
|
||||
|
||||
$multiple_tax_amount = ($sub_total / 100) * $multible_tax_object->rate;
|
||||
|
||||
if (isset($taxes['GST']) && array_key_exists($multible_tax_object->id, $taxes['GST'])) {
|
||||
$taxes['GST'][$multible_tax_object->id]['amount'] += $multiple_tax_amount;
|
||||
} else {
|
||||
$taxes['GST'][$multible_tax_object->id] = [
|
||||
'id' => $multible_tax_object->id,
|
||||
'name' => $multible_tax_object->name,
|
||||
'amount' => $multiple_tax_amount
|
||||
];
|
||||
}
|
||||
|
||||
$sub_total += $multiple_tax_amount;
|
||||
}
|
||||
}
|
||||
|
||||
$s_total = $sub_total;
|
||||
|
||||
// Apply discount to total
|
||||
@ -520,30 +449,6 @@ class Bills extends Controller
|
||||
$s_total = $s_total - $s_discount;
|
||||
}
|
||||
|
||||
if ($request['multiple_tax']) {
|
||||
foreach ($request['multiple_tax'] as $multiple_tax) {
|
||||
if ($multiple_tax['position'] != 'PST') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$multible_tax_object = Tax::find($multiple_tax['tax_id']);
|
||||
|
||||
$multiple_tax_amount = ($s_total / 100) * $multible_tax_object->rate;
|
||||
|
||||
if (isset($taxes['PST']) && array_key_exists($multible_tax_object->id, $taxes['PST'])) {
|
||||
$taxes['PST'][$multible_tax_object->id]['amount'] += $multiple_tax_amount;
|
||||
} else {
|
||||
$taxes['PST'][$multible_tax_object->id] = [
|
||||
'id' => $multible_tax_object->id,
|
||||
'name' => $multible_tax_object->name,
|
||||
'amount' => $multiple_tax_amount
|
||||
];
|
||||
}
|
||||
|
||||
$tax_total += $multiple_tax_amount;
|
||||
}
|
||||
}
|
||||
|
||||
$amount = $s_total + $tax_total;
|
||||
|
||||
$request['amount'] = money($amount, $request['currency_code'])->getAmount();
|
||||
@ -892,21 +797,6 @@ class Bills extends Controller
|
||||
{
|
||||
$sort_order = 1;
|
||||
|
||||
if (isset($taxes['GST'])) {
|
||||
foreach ($taxes['GST'] as $tax) {
|
||||
InvoiceTotal::create([
|
||||
'company_id' => $request['company_id'],
|
||||
'invoice_id' => $invoice->id,
|
||||
'code' => 'gst-' . $tax['id'],
|
||||
'name' => $tax['name'],
|
||||
'amount' => $tax['amount'],
|
||||
'sort_order' => $sort_order,
|
||||
]);
|
||||
|
||||
$sort_order++;
|
||||
}
|
||||
}
|
||||
|
||||
// Added bill sub total
|
||||
BillTotal::create([
|
||||
'company_id' => $request['company_id'],
|
||||
@ -936,24 +826,9 @@ class Bills extends Controller
|
||||
$sort_order++;
|
||||
}
|
||||
|
||||
if (isset($taxes['PST'])) {
|
||||
foreach ($taxes['PST'] as $tax) {
|
||||
InvoiceTotal::create([
|
||||
'company_id' => $request['company_id'],
|
||||
'invoice_id' => $invoice->id,
|
||||
'code' => 'pst-' . $tax['id'],
|
||||
'name' => $tax['name'],
|
||||
'amount' => $tax['amount'],
|
||||
'sort_order' => $sort_order,
|
||||
]);
|
||||
|
||||
$sort_order++;
|
||||
}
|
||||
}
|
||||
|
||||
// Added bill taxes
|
||||
if (isset($taxes['VAT'])) {
|
||||
foreach ($taxes['VAT'] as $tax) {
|
||||
if (isset($taxes)) {
|
||||
foreach ($taxes as $tax) {
|
||||
BillTotal::create([
|
||||
'company_id' => $request['company_id'],
|
||||
'bill_id' => $bill->id,
|
||||
|
Reference in New Issue
Block a user