diff --git a/app/Http/Controllers/Common/Items.php b/app/Http/Controllers/Common/Items.php index 6cfc73ebd..4b29ebac3 100644 --- a/app/Http/Controllers/Common/Items.php +++ b/app/Http/Controllers/Common/Items.php @@ -345,6 +345,22 @@ class Items extends Controller } } + if ($request['multiple_tax']) { + foreach ($request['multiple_tax'] as $tax_row => $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; + + $sub_total += $multiple_tax_amount; + + $taxes['multiple-tax-' . $tax_row . '-total'] = money($multiple_tax_amount, $currency_code, true)->format(); + } + } + $json->items = $items; $json->sub_total = money($sub_total, $currency_code, true)->format(); @@ -362,10 +378,32 @@ class Items extends Controller $sub_total = $sub_total - ($sub_total * ($discount / 100)); } + if ($request['multiple_tax']) { + foreach ($request['multiple_tax'] as $tax_row => $multiple_tax) { + if ($multiple_tax['position'] != 'PST') { + continue; + } + + $multible_tax_object = Tax::find($multiple_tax['tax_id']); + + $multiple_tax_amount = ($sub_total / 100) * $multible_tax_object->rate; + + $tax_total += $multiple_tax_amount; + + $taxes['multiple-tax-' . $tax_row . '-total'] = money($multiple_tax_amount, $currency_code, true)->format(); + } + } + $grand_total = $sub_total + $tax_total; $json->grand_total = money($grand_total, $currency_code, true)->format(); + $json->multible_taxes = false; + + if (!empty($taxes)) { + $json->multible_taxes = $taxes; + } + // Get currency object $currency = Currency::where('code', $currency_code)->first(); diff --git a/app/Http/Controllers/Expenses/Bills.php b/app/Http/Controllers/Expenses/Bills.php index 9beb38e8a..7cdfcf4d5 100644 --- a/app/Http/Controllers/Expenses/Bills.php +++ b/app/Http/Controllers/Expenses/Bills.php @@ -211,10 +211,10 @@ class Bills extends Controller // Set taxes if (isset($tax_object)) { - if (array_key_exists($tax_object->id, $taxes)) { - $taxes[$tax_object->id]['amount'] += $tax; + if (isset($taxes['VAT']) && array_key_exists($tax_object->id, $taxes['VAT'])) { + $taxes['VAT'][$tax_object->id]['amount'] += $tax; } else { - $taxes[$tax_object->id] = [ + $taxes['VAT'][$tax_object->id] = [ 'name' => $tax_object->name, 'amount' => $tax ]; @@ -229,6 +229,30 @@ 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 @@ -238,6 +262,30 @@ 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,10 +470,10 @@ class Bills extends Controller $bill_item['total'] = (double) $item['price'] * (double) $item['quantity']; if (isset($tax_object)) { - if (array_key_exists($tax_object->id, $taxes)) { - $taxes[$tax_object->id]['amount'] += $tax; + if (isset($taxes['VAT']) && array_key_exists($tax_object->id, $taxes['VAT'])) { + $taxes['VAT'][$tax_object->id]['amount'] += $tax; } else { - $taxes[$tax_object->id] = [ + $taxes['VAT'][$tax_object->id] = [ 'name' => $tax_object->name, 'amount' => $tax ]; @@ -439,6 +487,30 @@ 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 @@ -448,6 +520,30 @@ 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(); @@ -796,6 +892,21 @@ 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'], @@ -821,13 +932,28 @@ class Bills extends Controller // This is for total $sub_total = $sub_total - $discount_total; + + $sort_order++; } - $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 ($taxes) { - foreach ($taxes as $tax) { + if (isset($taxes['VAT'])) { + foreach ($taxes['VAT'] as $tax) { BillTotal::create([ 'company_id' => $request['company_id'], 'bill_id' => $bill->id, diff --git a/app/Http/Controllers/Incomes/Invoices.php b/app/Http/Controllers/Incomes/Invoices.php index 75bad69d0..dd97566a2 100644 --- a/app/Http/Controllers/Incomes/Invoices.php +++ b/app/Http/Controllers/Incomes/Invoices.php @@ -243,10 +243,10 @@ class Invoices extends Controller // Set taxes if (isset($tax_object)) { - if (array_key_exists($tax_object->id, $taxes)) { - $taxes[$tax_object->id]['amount'] += $tax; + if (isset($taxes['VAT']) && array_key_exists($tax_object->id, $taxes['VAT'])) { + $taxes['VAT'][$tax_object->id]['amount'] += $tax; } else { - $taxes[$tax_object->id] = [ + $taxes['VAT'][$tax_object->id] = [ 'name' => $tax_object->name, 'amount' => $tax ]; @@ -261,6 +261,30 @@ class Invoices 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 @@ -270,6 +294,30 @@ class Invoices 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(); @@ -460,10 +508,10 @@ class Invoices extends Controller $invoice_item['total'] = (double) $item['price'] * (double) $item['quantity']; if (isset($tax_object)) { - if (array_key_exists($tax_object->id, $taxes)) { - $taxes[$tax_object->id]['amount'] += $tax; + if (isset($taxes['VAT']) && array_key_exists($tax_object->id, $taxes['VAT'])) { + $taxes['VAT'][$tax_object->id]['amount'] += $tax; } else { - $taxes[$tax_object->id] = [ + $taxes['VAT'][$tax_object->id] = [ 'name' => $tax_object->name, 'amount' => $tax ]; @@ -477,6 +525,30 @@ class Invoices 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 @@ -486,6 +558,30 @@ class Invoices 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(); @@ -950,6 +1046,21 @@ class Invoices 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 invoice sub total InvoiceTotal::create([ 'company_id' => $request['company_id'], @@ -975,13 +1086,28 @@ class Invoices extends Controller // This is for total $sub_total = $sub_total - $discount_total; + + $sort_order++; } - $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 invoice taxes - if ($taxes) { - foreach ($taxes as $tax) { + if (isset($taxes['VAT'])) { + foreach ($taxes['VAT'] as $tax) { InvoiceTotal::create([ 'company_id' => $request['company_id'], 'invoice_id' => $invoice->id, diff --git a/resources/lang/en-GB/bills.php b/resources/lang/en-GB/bills.php index b8832c93d..2f8effef0 100644 --- a/resources/lang/en-GB/bills.php +++ b/resources/lang/en-GB/bills.php @@ -39,6 +39,14 @@ return [ 'paid' => 'Paid', ], + 'taxes' => [ + 'position' => 'Position', + 'positions' => [ + 'before' => 'Before Subtotal (GST)', + 'after' => 'After Subtotal (PST)', + ], + ], + 'messages' => [ 'received' => 'Bill marked as received successfully!', ], diff --git a/resources/lang/en-GB/invoices.php b/resources/lang/en-GB/invoices.php index 66e75187d..776cb09b6 100644 --- a/resources/lang/en-GB/invoices.php +++ b/resources/lang/en-GB/invoices.php @@ -41,6 +41,14 @@ return [ 'paid' => 'Paid', ], + 'taxes' => [ + 'position' => 'Position', + 'positions' => [ + 'before' => 'Before Subtotal (GST)', + 'after' => 'After Subtotal (PST)', + ], + ], + 'messages' => [ 'email_sent' => 'Invoice email has been sent successfully!', 'marked_sent' => 'Invoice marked as sent successfully!', diff --git a/resources/views/expenses/bills/create.blade.php b/resources/views/expenses/bills/create.blade.php index 593358906..7d1c7dc59 100644 --- a/resources/views/expenses/bills/create.blade.php +++ b/resources/views/expenses/bills/create.blade.php @@ -77,13 +77,13 @@ @stack('add_item_td_end') @stack('sub_total_td_start') - + {{ trans('bills.sub_total') }} 0 @stack('sub_total_td_end') @stack('add_discount_td_start') - + {{ trans('bills.add_discount') }} @@ -94,13 +94,16 @@ @stack('add_discount_td_end') @stack('tax_total_td_start') - - {{ trans_choice('general.taxes', 1) }} + + + + {{ trans_choice('general.taxes', 1) }} + 0 @stack('tax_total_td_end') @stack('grand_total_td_start') - + {{ trans('bills.total') }} 0 @@ -167,6 +170,7 @@ @push('scripts')