diff --git a/app/Http/Controllers/InvoiceController.php b/app/Http/Controllers/InvoiceController.php index e3b94c3c..a78b6800 100644 --- a/app/Http/Controllers/InvoiceController.php +++ b/app/Http/Controllers/InvoiceController.php @@ -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) {