Admin Workflow - API code refactor to fetch booking information

This commit is contained in:
Dillon Ngo
2025-01-03 19:40:00 +08:00
parent 44b7c7294b
commit abe1f3df2b
7 changed files with 228 additions and 79 deletions
+2 -23
View File
@@ -46,7 +46,8 @@ if (!function_exists('markedProcessing')) {
Route::group(['prefix' => 'admin-work-flow', 'as' => 'admin_work_flow.', 'namespace' => 'Questionnaires'], function () {
Route::get('/fetch-oldest-order', [AdminWorkflowBaseController::class, 'fetchOldestOrder'])->name('fetch_oldest_order');
Route::get('/fetch-booking', [AdminWorkflowBaseController::class, 'fetchBooking'])->name('fetch_oldest_order');
Route::get('{booking_id}/fetch-model-attributes', [AdminWorkflowBaseController::class, 'fetchModelAttributes'])->name('fetch_model_attributes');
Route::get('/fetch-pending-approved-po', function () {
$excludedBookingIds = KeyValuePair::where('owner_type', 'App\Models\Booking')
@@ -122,28 +123,6 @@ Route::group(['prefix' => 'admin-work-flow', 'as' => 'admin_work_flow.', 'namesp
})->name('fetch_pending_fill_po');
Route::get('{booking_id}/fetch-model-attributes', function ($bookingId) {
$booking = Booking::find($bookingId);
if (!$booking) {
return responseJson(null, 'No booking found', 404);
}
$attributes = $booking->modelAttributes()
->where('name', BookingAttributeNames::ORDER_REFERENCE_NO)
->get(['id', 'value'])
->map(fn ($attr) => $attr->only(['id', 'value']));
$transaction = $booking->bills()->first(); //cief todo: 74 - more than 1 record?
return responseJson([
'booking' => $booking,
'booking_attributes' => $attributes,
'reference' =>$transaction->owner->owner->marking,
'marking' => $transaction->owner->owner->company->reference,
'currency_rate' => $transaction->currency_rate,
'total_amount' =>$transaction->currency->short_code . ' ' . number_format((float)$transaction->amount, 2, '.', '')
]);
})->name('fetch_model_attributes');
// Route::post('/add-workflow-timestamp', function (Request $request) {