check if totals are in request

This commit is contained in:
denisdulici 2018-11-16 11:55:04 +03:00
parent 1a8224c0c7
commit 3317483e39
4 changed files with 76 additions and 0 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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