validate total and save

This commit is contained in:
Edmond Teh
2020-09-25 18:54:45 +08:00
parent 3bb6587399
commit 56f288e05c
+13 -3
View File
@@ -93,9 +93,13 @@ class InvoiceController extends Controller
function ($line) { return $line['total']; },
$validatedData['lines']
);
$total = array_reduce($subtotalArray, function ($v1, $v2) {
$subtotal = array_reduce($subtotalArray, function ($v1, $v2) {
return $v1 + $v2;
});
$adjustment = $request->adjustment;
$billing_charges = $booking->billing_charge;
$total = $subtotal + $adjustment + $billing_charges;
if ($total !== $booking->bia) {
return response()->json([
'message' => 'Booking amount expected is '.$booking->bia.'. Your Invoice amount is '.$total
@@ -121,6 +125,7 @@ class InvoiceController extends Controller
$invoice->address = $validatedData['address'];
$invoice->contact_no = $validatedData['contact_no'];
$invoice->po_number = $po_number;
$invoice->adjustment = $adjustment;
$invoice->save();
if (!$invoice) {
@@ -215,10 +220,14 @@ class InvoiceController extends Controller
function ($line) { return $line['total']; },
$validatedData['lines']
);
$total = array_reduce($subtotalArray, function ($v1, $v2) {
$subtotal = array_reduce($subtotalArray, function ($v1, $v2) {
return $v1 + $v2;
});
if ($total != $booking->bia) {
$adjustment = $request->adjustment;
$billing_charges = $booking->billing_charge;
$total = $subtotal + $adjustment + $billing_charges;
if ($total !== $booking->bia) {
return response()->json([
'message' => 'Booking amount expected is '.$booking->bia.'. Your Invoice amount is '.$total
], 400);
@@ -235,6 +244,7 @@ class InvoiceController extends Controller
$invoice->address = $validatedData['address'];
$invoice->contact_no = $validatedData['contact_no'];
$invoice->po_number = $po_number;
$invoice->adjustment = $adjustment;
$invoice->save();
if (!$invoice) {