From a8125eaab4f50646f7531d8830cc1cab37034e17 Mon Sep 17 00:00:00 2001 From: Edmond Teh Date: Sun, 6 Sep 2020 21:29:13 +0800 Subject: [PATCH] validate getPO --- app/Http/Controllers/InvoiceController.php | 60 +++++++++++++++++++++- 1 file changed, 59 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/InvoiceController.php b/app/Http/Controllers/InvoiceController.php index 0490cd73..30155f41 100644 --- a/app/Http/Controllers/InvoiceController.php +++ b/app/Http/Controllers/InvoiceController.php @@ -293,18 +293,76 @@ class InvoiceController extends Controller } - public function getPO($id) + public function getPO(Request $request, $id) { + // Booking Exist and Belongs to User or is Admin + if ($request->user()->role === 'member') { + if (!$this->isUser($id, $request->user()->id)) { + return response()->json(['message' => 'The PO Does not belongs to you.'], 403); + } + } + // Ensure Invoice Status is Approve + if ($this->invoiceStatus($id) !== 'approve') { + return response()->json(['message' => 'Invoice must and exist and approve status.'], 403); + } + + // Generate PO + + // Send + return response()->json(['message' => 'successful'], 200); } public function getDO($id) { + // Ensure Invoice Exist and Completed + + // Generate PO + + // Send } public function getSupplierDO($id) { + // Only Admin Can get Supplier DO + // Ensure Invoice Exist and Completed + + // Generate PO + + // Send + } + + // private invoiceExist($id) + // { + + // } + + // private invoiceStatus($id) { + + // } + + private function isUser($booking_id, $user_id) { + + $booking = Booking::where([ + ['id', '=', $booking_id], + ['user_id', '=', $user_id] + ])->first(); + + if ($booking) { + return true; + } else { + return false; + } + } + + private function invoiceStatus($booking_id) { + $invoice = Invoice::where('booking_id', $booking_id).first(); + if (!$invoice) { + return + } + $currentstatus = InvoiceStatuses::where('invoice_id', $invoice['id'])->latest('created_at')->first()->status; + return $currentstatus; } }