From 3317483e39d2e731f37ffcd83336c75d0fd7d848 Mon Sep 17 00:00:00 2001 From: denisdulici Date: Fri, 16 Nov 2018 11:55:04 +0300 Subject: [PATCH] check if totals are in request --- app/Jobs/Expense/CreateBill.php | 19 +++++++++++++++++++ app/Jobs/Expense/UpdateBill.php | 19 +++++++++++++++++++ app/Jobs/Income/CreateInvoice.php | 19 +++++++++++++++++++ app/Jobs/Income/UpdateInvoice.php | 19 +++++++++++++++++++ 4 files changed, 76 insertions(+) diff --git a/app/Jobs/Expense/CreateBill.php b/app/Jobs/Expense/CreateBill.php index a4463fa82..9c67ee186 100644 --- a/app/Jobs/Expense/CreateBill.php +++ b/app/Jobs/Expense/CreateBill.php @@ -112,6 +112,25 @@ class CreateBill protected function addTotals($bill, $request, $taxes, $sub_total, $discount_total, $tax_total) { + // Check if totals are in request, i.e. api + if (!empty($request['totals'])) { + $sort_order = 1; + + foreach ($request['totals'] as $total) { + $total['bill_id'] = $bill->id; + + if (empty($total['sort_order'])) { + $total['sort_order'] = $sort_order; + } + + BillTotal::create($total); + + $sort_order++; + } + + return; + } + $sort_order = 1; // Added bill sub total diff --git a/app/Jobs/Expense/UpdateBill.php b/app/Jobs/Expense/UpdateBill.php index 759aa2a2b..c1fa62a40 100644 --- a/app/Jobs/Expense/UpdateBill.php +++ b/app/Jobs/Expense/UpdateBill.php @@ -109,6 +109,25 @@ class UpdateBill protected function addTotals($bill, $request, $taxes, $sub_total, $discount_total, $tax_total) { + // Check if totals are in request, i.e. api + if (!empty($request['totals'])) { + $sort_order = 1; + + foreach ($request['totals'] as $total) { + $total['bill_id'] = $bill->id; + + if (empty($total['sort_order'])) { + $total['sort_order'] = $sort_order; + } + + BillTotal::create($total); + + $sort_order++; + } + + return; + } + $sort_order = 1; // Added bill sub total diff --git a/app/Jobs/Income/CreateInvoice.php b/app/Jobs/Income/CreateInvoice.php index 3139b1471..e739a25ac 100644 --- a/app/Jobs/Income/CreateInvoice.php +++ b/app/Jobs/Income/CreateInvoice.php @@ -116,6 +116,25 @@ class CreateInvoice protected function addTotals($invoice, $request, $taxes, $sub_total, $discount_total, $tax_total) { + // Check if totals are in request, i.e. api + if (!empty($request['totals'])) { + $sort_order = 1; + + foreach ($request['totals'] as $total) { + $total['invoice_id'] = $invoice->id; + + if (empty($total['sort_order'])) { + $total['sort_order'] = $sort_order; + } + + InvoiceTotal::create($total); + + $sort_order++; + } + + return; + } + $sort_order = 1; // Added invoice sub total diff --git a/app/Jobs/Income/UpdateInvoice.php b/app/Jobs/Income/UpdateInvoice.php index 075550cff..4afd144c4 100644 --- a/app/Jobs/Income/UpdateInvoice.php +++ b/app/Jobs/Income/UpdateInvoice.php @@ -110,6 +110,25 @@ class UpdateInvoice protected function addTotals($invoice, $request, $taxes, $sub_total, $discount_total, $tax_total) { + // Check if totals are in request, i.e. api + if (!empty($request['totals'])) { + $sort_order = 1; + + foreach ($request['totals'] as $total) { + $total['invoice_id'] = $invoice->id; + + if (empty($total['sort_order'])) { + $total['sort_order'] = $sort_order; + } + + InvoiceTotal::create($total); + + $sort_order++; + } + + return; + } + $sort_order = 1; // Added invoice sub total