'admin-work-flow', 'as' => 'admin_work_flow.', 'namespace' => 'AdminWorkFlow'], function () { // Generalized JSON response function function jsonResponse($data = null, $message = null, $status = 200) { $response = ['message' => $message]; if ($data !== null) { $response['data'] = $data; } return response()->json($response, $status); } Route::get('/fetch-oldest-order', function () { $booking = Booking::where('service_id', 4) ->where('status', ApprovalStatus::APPROVED) ->first(); return $booking ? jsonResponse([ 'passwords' => $booking->bank->holder_name ?? null, 'account_no' => $booking->bank->account_no ?? null, 'pin' => $booking->bank->bank_branch ?? null, 'holder_name' => $booking->bank->holder_name ?? null, 'booking_marking' => $booking->marking ?? null, 'booking_id' => $booking->id ?? null, ]) : jsonResponse(null, 'No booking found', 404); })->name('fetch_oldest_order'); Route::post('/add-workflow-timestamp', function (Request $request) { $validator = Validator::make($request->all(), [ 'current_node' => 'required|string', 'next_node' => 'required|string', 'seconds' => 'required|integer', 'user_id' => 'required|integer|exists:users,id', 'session_id' => 'required|string', ]); if ($validator->fails()) { throw new RequestValidationException($validator->messages()->first()); } $workflowTimestamp = WorkflowTimestamp::create($validator->validated()); return jsonResponse($workflowTimestamp, 'Workflow timestamp created successfully', 201); })->name('add_workflow_timestamp'); Route::get('/fetch-pending-approved-po', function () { $booking = Booking::with('transactions') ->where('service_id', 4) ->where('status', ApprovalStatus::APPROVED) ->whereHas('transactions', fn ($query) => $query->where('type', TransactionType::PURCHASE_ORDER)->where('status', '<', ApprovalStatus::APPROVED)) ->first(); return $booking ? jsonResponse(new BookingResource($booking)) : jsonResponse(null, 'No booking found', 404); })->name('fetch_pending_approve_po'); Route::get('/fetch-pending-fill-po', function () { $booking = Booking::with('transactions') ->where('service_id', 4) ->where('status', ApprovalStatus::APPROVED) ->whereDoesntHave('transactions', fn ($query) => $query->where('type', TransactionType::PURCHASE_ORDER)) ->first(); return $booking ? jsonResponse(new BookingResource($booking)) : jsonResponse(null, 'No booking found', 404); })->name('fetch_pending_fill_po'); Route::get('{booking_id}/fetch-model-attributes', function ($bookingId) { $booking = Booking::find($bookingId); if (!$booking) { return jsonResponse(null, 'No approved booking found', 404); } $attributes = $booking->modelAttributes() ->where('name', BookingAttributeNames::ORDER_REFERENCE_NO) ->get(['id', 'value']) ->map(fn ($attr) => $attr->only(['id', 'value'])); return jsonResponse([ 'booking' => $booking, 'booking_attributes' => $attributes, ]); })->name('fetch_model_attributes'); // Route::post('/create-1688-login-issue-remark', function (Request $request) { // $validator = Validator::make($request->all(), [ // 'booking_id' => 'required', // 'remark' => 'required', // 'user_id' => 'required', // ]); // if ($validator->fails()) { // throw new RequestValidationException($validator->messages()->first()); // } // $booking = Booking::find($request->booking_id); // if (!$booking) { // return jsonResponse(null, 'Booking not found', 404); // } // $remark = new Remark([ // 'commenter_id' => $request->user_id, // 'content' => $request->remark, // 'owner_type' => get_class($booking), // 'owner_id' => $booking->id, // ]); // $remark->save(); // return jsonResponse($remark, 'Remark created successfully', 201); // })->name('create_1688_login_issue_remark'); Route::post('/create_issue_remark', function (Request $request) { $validator = Validator::make($request->all(), [ 'booking_id' => 'required', 'remark' => 'required', 'user_id' => 'required', ]); if ($validator->fails()) { throw new RequestValidationException($validator->messages()->first()); } $booking = Booking::find($request->booking_id); if (!$booking) { return jsonResponse(null, 'Booking not found', 404); } $remark = new Remark([ 'commenter_id' => $request->user_id, 'content' => $request->remark, 'owner_type' => get_class($booking), 'owner_id' => $booking->id, ]); $remark->save(); return jsonResponse($remark, 'Remark created successfully', 201); })->name('create_issue_remark'); Route::post('/create_po_issue_remark', function (Request $request) { $validator = Validator::make($request->all(), [ 'booking_id' => 'required', 'remark' => 'required', 'user_id' => 'required', ]); if ($validator->fails()) { return response()->json(['message' => $validator->messages()->first()], 400); // Return validation error } $booking = Booking::find($request->booking_id); if (!$booking) { return response()->json(['message' => 'Booking not found'], 404); } $remark = new Remark([ 'commenter_id' => $request->user_id, 'content' => $request->remark, 'owner_type' => get_class($booking), 'owner_id' => $booking->id, ]); $remark->save(); return response()->json(['data' => $remark, 'message' => 'Remark created successfully'], 201); })->name('create_po_issue_remark'); });