From abe1f3df2b5983ca1cc49af016b299ffadf7d2d8 Mon Sep 17 00:00:00 2001 From: Dillon Ngo Date: Fri, 3 Jan 2025 19:40:00 +0800 Subject: [PATCH 1/4] Admin Workflow - API code refactor to fetch booking information --- .../ControllersLogic/FetchBookingLogic.php | 4 +- .../FetchAdminWFBookingLogic.php | 100 ++++++++++++++++++ .../FetchAdminWFModelAttributesLogic.php | 75 +++++++++++++ .../AdminWorkflowBaseController.php | 71 ++++--------- app/Http/Resources/BookingBaseResource.php | 26 +++++ .../forms/AdminWorkFlowFormComponent.vue | 6 +- routes/admin_workflow.php | 25 +---- 7 files changed, 228 insertions(+), 79 deletions(-) create mode 100644 app/Classes/Modules/Questionnaires/ControllersLogic/FetchAdminWFBookingLogic.php create mode 100644 app/Classes/Modules/Questionnaires/ControllersLogic/FetchAdminWFModelAttributesLogic.php create mode 100644 app/Http/Resources/BookingBaseResource.php diff --git a/app/Classes/Modules/Bookings/ControllersLogic/FetchBookingLogic.php b/app/Classes/Modules/Bookings/ControllersLogic/FetchBookingLogic.php index d1f2286e..711ae1cb 100644 --- a/app/Classes/Modules/Bookings/ControllersLogic/FetchBookingLogic.php +++ b/app/Classes/Modules/Bookings/ControllersLogic/FetchBookingLogic.php @@ -19,7 +19,7 @@ class FetchBookingLogic extends AbstractControllerLogic protected function notification():array { return [ 'title' => 'Retrieved Booking', - 'message' => 'You have successfully retrieved a Address' + 'message' => 'You have successfully retrieved a Booking' ]; } @@ -58,4 +58,4 @@ class FetchBookingLogic extends AbstractControllerLogic } -} \ No newline at end of file +} diff --git a/app/Classes/Modules/Questionnaires/ControllersLogic/FetchAdminWFBookingLogic.php b/app/Classes/Modules/Questionnaires/ControllersLogic/FetchAdminWFBookingLogic.php new file mode 100644 index 00000000..77dc0372 --- /dev/null +++ b/app/Classes/Modules/Questionnaires/ControllersLogic/FetchAdminWFBookingLogic.php @@ -0,0 +1,100 @@ + 'Retrieved Booking for Admin Workflow ', + 'message' => 'You have successfully retrieved a Booking for Admin Workflow' + ]; + } + + /** @var CanFetchQuestion */ + private $canFetchQuestion; + + /** + * FetchAdminWFBookingLogic constructor. + * @param CanFetchQuestion $canFetchQuestion + */ + public function __construct(CanFetchQuestion $canFetchQuestion) + { + $this->canFetchQuestion = $canFetchQuestion; + } + + + /** + * @param Request $request + * @return JsonResponse + * @throws ErrorException + */ + public function logic(Request $request) : JsonResponse + { + $this->canFetchQuestion->passes(); + + $excludedBookingIds = KeyValuePair::where('owner_type', 'App\Models\Booking') + ->where(function ($query) { + $query->where('key', '1688_admin_workflow_processed') + ->orWhere(function ($query) { + $query->where('key', '1688_admin_workflow_processing') + ->where('updated_at', '>', Carbon::now()->subHour()); + }); + }) + ->pluck('owner_id') + ->filter(function ($value) { + return is_numeric($value); + }) + ->toArray(); + + + $timeAgo = Carbon::now()->subMonths(6); + $serviceId = 4; + $booking = Booking::where('service_id', $serviceId) + ->where('status', ApprovalStatus::APPROVED) + ->whereNotIn('id', $excludedBookingIds) + ->whereHas('bills', function ($query) { + $query->whereHas('groupTransaction', function ($query) { + $query->whereHas('group', function ($query) { + $query->whereDoesntHave('billGroup')->whereIn('issuer', [2]); + }); + }); + }) + ->where('created_at', '>=', $timeAgo) + ->latest() + ->first(); + + if(!$booking){ + return responseJson(null, 'No booking found', 404); + } + + markedProcessing($booking, '1688_admin_workflow_processing'); + + // return responseJson([ + // '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' => $booking + // ]); + + return $this->resourceResponse(new BookingBaseResource($booking)); + } + +} diff --git a/app/Classes/Modules/Questionnaires/ControllersLogic/FetchAdminWFModelAttributesLogic.php b/app/Classes/Modules/Questionnaires/ControllersLogic/FetchAdminWFModelAttributesLogic.php new file mode 100644 index 00000000..456f51cf --- /dev/null +++ b/app/Classes/Modules/Questionnaires/ControllersLogic/FetchAdminWFModelAttributesLogic.php @@ -0,0 +1,75 @@ + 'Retrieved Model Attributes for Admin Workflow ', + 'message' => 'You have successfully retrieved Model Attributes for Admin Workflow' + ]; + } + + /** @var CanFetchQuestion */ + private $canFetchQuestion; + + + /** + * FetchAdminWFModelAttributesLogic constructor. + * @param CanFetchQuestion $canFetchQuestion + */ + public function __construct(CanFetchQuestion $canFetchQuestion) + { + $this->canFetchQuestion = $canFetchQuestion; + } + + + /** + * @param Request $request + * @return JsonResponse + * @throws ErrorException + */ + public function logic(Request $request) : JsonResponse + { + $this->canFetchQuestion->passes(); + + $booking = Booking::find($request->route('booking_id')); + + 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, '.', '') + ]); + + return $this->resourceResponse(new BookingBaseResource($booking)); + } + +} diff --git a/app/Http/Controllers/Questionnaires/AdminWorkflowBaseController.php b/app/Http/Controllers/Questionnaires/AdminWorkflowBaseController.php index 068728a7..4214984c 100644 --- a/app/Http/Controllers/Questionnaires/AdminWorkflowBaseController.php +++ b/app/Http/Controllers/Questionnaires/AdminWorkflowBaseController.php @@ -1,61 +1,30 @@ where(function ($query) { - $query->where('key', '1688_admin_workflow_processed') - ->orWhere(function ($query) { - $query->where('key', '1688_admin_workflow_processing') - ->where('updated_at', '>', Carbon::now()->subHour()); - }); - }) - ->pluck('owner_id') - ->filter(function ($value) { - return is_numeric($value); - }) - ->toArray(); + /** + * @param Request $request + * @param FetchQuestionV1AdminWFLogic $logic + * @return JsonResponse + */ + public function fetchBooking(Request $request, FetchAdminWFBookingLogic $logic): JsonResponse { + return $logic->execute($request); + } - - $timeAgo = Carbon::now()->subMonths(6); - $serviceId = 4; - $booking = Booking::where('service_id', $serviceId) - ->where('status', ApprovalStatus::APPROVED) - ->whereNotIn('id', $excludedBookingIds) - ->whereHas('bills', function ($query) { - $query->whereHas('groupTransaction', function ($query) { - $query->whereHas('group', function ($query) { - $query->whereDoesntHave('billGroup')->whereIn('issuer', [2]); - }); - }); - }) - ->where('created_at', '>=', $timeAgo) - ->latest() - ->first(); - - if(!$booking){ - return responseJson(null, 'No booking found', 404); - } - - markedProcessing($booking, '1688_admin_workflow_processing'); - - return responseJson([ - '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' => $booking - ]); + /** + * @param Request $request + * @param FetchAdminWFModelAttributesLogic $logic + * @return JsonResponse + */ + public function fetchModelAttributes(Request $request, FetchAdminWFModelAttributesLogic $logic): JsonResponse { + return $logic->execute($request); } } diff --git a/app/Http/Resources/BookingBaseResource.php b/app/Http/Resources/BookingBaseResource.php new file mode 100644 index 00000000..945812f8 --- /dev/null +++ b/app/Http/Resources/BookingBaseResource.php @@ -0,0 +1,26 @@ + $this->id, + 'company' => new CompanyResource($this->company), + 'bank' => new BankResource($this->bank), + 'marking' => $this->marking, + ]; + } +} diff --git a/resources/assets/vue/components/general/forms/AdminWorkFlowFormComponent.vue b/resources/assets/vue/components/general/forms/AdminWorkFlowFormComponent.vue index 96fc0717..4e0db9e5 100644 --- a/resources/assets/vue/components/general/forms/AdminWorkFlowFormComponent.vue +++ b/resources/assets/vue/components/general/forms/AdminWorkFlowFormComponent.vue @@ -39,7 +39,7 @@ -

{{ externalApiResponse.data.account_no }}

+

{{ externalApiResponse.data.booking.bank.account_no }}

@@ -48,7 +48,7 @@ -

{{ externalApiResponse.data.holder_name }}

+

{{ externalApiResponse.data.booking.bank.holder_name }}

@@ -57,7 +57,7 @@ -

{{ externalApiResponse.data.pin }}

+

{{ externalApiResponse.data.booking.bank.bank_branch }}

diff --git a/routes/admin_workflow.php b/routes/admin_workflow.php index 13a1f5d7..b5ff7d03 100644 --- a/routes/admin_workflow.php +++ b/routes/admin_workflow.php @@ -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) { From db36336484c0bcae70dd2c81f20111ad95c97bd4 Mon Sep 17 00:00:00 2001 From: Dillon Ngo Date: Sat, 4 Jan 2025 22:38:42 +0800 Subject: [PATCH 2/4] Admin Workflow - API code refactor to fetch information to display on workflow --- .../FetchAdminWFBookingLogic.php | 5 + .../FetchAdminWFPendingApprovalPOLogic.php | 91 +++++++++++++++++++ .../FetchAdminWFPendingFillPOLogic.php | 90 ++++++++++++++++++ .../UpdateNextQuestionV1AdminWFLogic.php | 2 +- .../AdminWorkflowBaseController.php | 22 ++++- app/Http/Resources/BookingBaseResource.php | 1 + .../elements/QuestionAnswerInnerComponent.vue | 4 +- .../forms/AdminWorkFlowFormComponent.vue | 72 +++++++-------- routes/admin_workflow.php | 77 +--------------- 9 files changed, 249 insertions(+), 115 deletions(-) create mode 100644 app/Classes/Modules/Questionnaires/ControllersLogic/FetchAdminWFPendingApprovalPOLogic.php create mode 100644 app/Classes/Modules/Questionnaires/ControllersLogic/FetchAdminWFPendingFillPOLogic.php diff --git a/app/Classes/Modules/Questionnaires/ControllersLogic/FetchAdminWFBookingLogic.php b/app/Classes/Modules/Questionnaires/ControllersLogic/FetchAdminWFBookingLogic.php index 77dc0372..3d3b75a4 100644 --- a/app/Classes/Modules/Questionnaires/ControllersLogic/FetchAdminWFBookingLogic.php +++ b/app/Classes/Modules/Questionnaires/ControllersLogic/FetchAdminWFBookingLogic.php @@ -94,6 +94,11 @@ class FetchAdminWFBookingLogic extends AbstractControllerLogic // 'booking' => $booking // ]); + // return responseJson([ + // 'booking' => new BookingBaseResource($booking) + // ]); + + return $this->resourceResponse(new BookingBaseResource($booking)); } diff --git a/app/Classes/Modules/Questionnaires/ControllersLogic/FetchAdminWFPendingApprovalPOLogic.php b/app/Classes/Modules/Questionnaires/ControllersLogic/FetchAdminWFPendingApprovalPOLogic.php new file mode 100644 index 00000000..878cde78 --- /dev/null +++ b/app/Classes/Modules/Questionnaires/ControllersLogic/FetchAdminWFPendingApprovalPOLogic.php @@ -0,0 +1,91 @@ + 'Retrieved Pending Approval PO for Admin Workflow ', + 'message' => 'You have successfully retrieved Pending Approval PO for Admin Workflow' + ]; + } + + /** @var CanFetchQuestion */ //cief todo: permission update + private $canFetchQuestion; + + + /** + * FetchAdminWFPendingApprovalPOLogic constructor. + * @param CanFetchQuestion $canFetchQuestion + */ + public function __construct(CanFetchQuestion $canFetchQuestion) + { + $this->canFetchQuestion = $canFetchQuestion; + } + + + /** + * @param Request $request + * @return JsonResponse + * @throws ErrorException + */ + public function logic(Request $request) : JsonResponse + { + $this->canFetchQuestion->passes(); + + $excludedBookingIds = KeyValuePair::where('owner_type', 'App\Models\Booking') + ->where(function ($query) { + $query->where('key', 'approve_po_admin_workflow_processed') + ->orWhere(function ($query) { + $query->where('key', 'approve_po_admin_workflow_processing') + ->where('updated_at', '>', Carbon::now()->subHour()); + }); + }) + ->pluck('owner_id') + ->filter(function ($value) { + return is_numeric($value); + }) + ->toArray(); + + $booking = Booking::with('transactions') + ->where('service_id', 4) + ->where('status', ApprovalStatus::APPROVED) + ->whereNotIn('id', $excludedBookingIds) + ->whereHas('transactions', fn ($query) => $query->where('type', TransactionType::PURCHASE_ORDER)->where('status', '<', ApprovalStatus::APPROVED)) + ->first(); + + if(!$booking){ + return responseJson(null, 'No booking found', 404); + } + + markedProcessing($booking, 'approve_po_admin_workflow_processing'); + + // $result = new BookingBaseResource($booking); + // return responseJson([ + // 'booking' => $result, + // ]); + // return $booking ? responseJson(new BookingBaseResource($booking)) : responseJson(null, 'No booking found', 404); + + return $this->resourceResponse(new BookingResource($booking)); + } + +} diff --git a/app/Classes/Modules/Questionnaires/ControllersLogic/FetchAdminWFPendingFillPOLogic.php b/app/Classes/Modules/Questionnaires/ControllersLogic/FetchAdminWFPendingFillPOLogic.php new file mode 100644 index 00000000..91e1b54a --- /dev/null +++ b/app/Classes/Modules/Questionnaires/ControllersLogic/FetchAdminWFPendingFillPOLogic.php @@ -0,0 +1,90 @@ + 'Retrieved Pending Fill PO for Admin Workflow ', + 'message' => 'You have successfully retrieved Pending Fill PO for Admin Workflow' + ]; + } + + /** @var CanFetchQuestion */ //cief todo: 74 - permission update + private $canFetchQuestion; + + + /** + * FetchAdminWFPendingFillPOLogic constructor. + * @param CanFetchQuestion $canFetchQuestion + */ + public function __construct(CanFetchQuestion $canFetchQuestion) + { + $this->canFetchQuestion = $canFetchQuestion; + } + + + /** + * @param Request $request + * @return JsonResponse + * @throws ErrorException + */ + public function logic(Request $request) : JsonResponse + { + $this->canFetchQuestion->passes(); + + $excludedBookingIds = KeyValuePair::where('owner_type', 'App\Models\Booking') + ->where(function ($query) { + $query->where('key', 'fill_po_admin_workflow_processed') + ->orWhere(function ($query) { + $query->where('key', 'fill_po_admin_workflow_processing') + ->where('updated_at', '>', Carbon::now()->subHour()); + }); + }) + ->pluck('owner_id') + ->filter(function ($value) { + return is_numeric($value); + }) + ->toArray(); + + $booking = Booking::with('transactions') + ->where('service_id', 4) + ->where('status', ApprovalStatus::APPROVED) + ->whereNotIn('id', $excludedBookingIds) + ->whereDoesntHave('transactions', fn ($query) => $query->where('type', TransactionType::PURCHASE_ORDER)) + ->first(); + + if(!$booking){ + return responseJson(null, 'No booking found', 404); + } + + markedProcessing($booking, 'fill_po_admin_workflow_processing'); + + // $result = new BookingBaseResource($booking); + // return responseJson([ + // 'booking' => $result, + // ]); + // return $booking ? responseJson(new BookingResource($booking)) : responseJson(null, 'No booking found', 404); + + return $this->resourceResponse(new BookingBaseResource($booking)); + } + +} diff --git a/app/Classes/Modules/Questionnaires/ControllersLogic/UpdateNextQuestionV1AdminWFLogic.php b/app/Classes/Modules/Questionnaires/ControllersLogic/UpdateNextQuestionV1AdminWFLogic.php index 53b36cce..8731c659 100644 --- a/app/Classes/Modules/Questionnaires/ControllersLogic/UpdateNextQuestionV1AdminWFLogic.php +++ b/app/Classes/Modules/Questionnaires/ControllersLogic/UpdateNextQuestionV1AdminWFLogic.php @@ -121,7 +121,7 @@ class UpdateNextQuestionV1AdminWFLogic extends AbstractControllerLogic //Marked data that has already been processed so that it does not appear again $isNoGoingBack = null; if($currentQuestion && $currentQuestion['is_end'] === 1){ - $booking = Booking::where('id', $questionMetadata['booking']['id'])->first(); + $booking = Booking::where('id', $questionMetadata['id'])->first(); $key1 = "admin_workflow_processed"; $key2 = "admin_workflow_processing"; diff --git a/app/Http/Controllers/Questionnaires/AdminWorkflowBaseController.php b/app/Http/Controllers/Questionnaires/AdminWorkflowBaseController.php index 4214984c..a3c95140 100644 --- a/app/Http/Controllers/Questionnaires/AdminWorkflowBaseController.php +++ b/app/Http/Controllers/Questionnaires/AdminWorkflowBaseController.php @@ -4,6 +4,8 @@ namespace App\Http\Controllers\Questionnaires; use App\Classes\Modules\Questionnaires\ControllersLogic\FetchAdminWFBookingLogic; use App\Classes\Modules\Questionnaires\ControllersLogic\FetchAdminWFModelAttributesLogic; +use App\Classes\Modules\Questionnaires\ControllersLogic\FetchAdminWFPendingApprovalPOLogic; +use App\Classes\Modules\Questionnaires\ControllersLogic\FetchAdminWFPendingFillPOLogic; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; @@ -12,7 +14,7 @@ class AdminWorkflowBaseController { /** * @param Request $request - * @param FetchQuestionV1AdminWFLogic $logic + * @param FetchAdminWFBookingLogic $logic * @return JsonResponse */ public function fetchBooking(Request $request, FetchAdminWFBookingLogic $logic): JsonResponse { @@ -27,4 +29,22 @@ class AdminWorkflowBaseController public function fetchModelAttributes(Request $request, FetchAdminWFModelAttributesLogic $logic): JsonResponse { return $logic->execute($request); } + + /** + * @param Request $request + * @param FetchAdminWFPendingApprovalPOLogic $logic + * @return JsonResponse + */ + public function fetchPendingApprovalPO(Request $request, FetchAdminWFPendingApprovalPOLogic $logic): JsonResponse { + return $logic->execute($request); + } + + /** + * @param Request $request + * @param FetchAdminWFPendingFillPOLogic $logic + * @return JsonResponse + */ + public function fetchPendingFillPO(Request $request, FetchAdminWFPendingFillPOLogic $logic): JsonResponse { + return $logic->execute($request); + } } diff --git a/app/Http/Resources/BookingBaseResource.php b/app/Http/Resources/BookingBaseResource.php index 945812f8..1490bf24 100644 --- a/app/Http/Resources/BookingBaseResource.php +++ b/app/Http/Resources/BookingBaseResource.php @@ -21,6 +21,7 @@ class BookingBaseResource extends JsonResource 'company' => new CompanyResource($this->company), 'bank' => new BankResource($this->bank), 'marking' => $this->marking, + 'fixed_currency' => new CurrencyResource($this->fixedCurrency), ]; } } diff --git a/resources/assets/vue/components/admin-workflow/elements/QuestionAnswerInnerComponent.vue b/resources/assets/vue/components/admin-workflow/elements/QuestionAnswerInnerComponent.vue index 155ca243..4627dfcf 100644 --- a/resources/assets/vue/components/admin-workflow/elements/QuestionAnswerInnerComponent.vue +++ b/resources/assets/vue/components/admin-workflow/elements/QuestionAnswerInnerComponent.vue @@ -3,8 +3,8 @@
{{ item.id }}
{{ item.question_title }}
{{ parsedAnswer === 'go_back' ? '' : item.answer }}
diff --git a/resources/assets/vue/components/general/forms/AdminWorkFlowFormComponent.vue b/resources/assets/vue/components/general/forms/AdminWorkFlowFormComponent.vue index 4e0db9e5..dcebee9e 100644 --- a/resources/assets/vue/components/general/forms/AdminWorkFlowFormComponent.vue +++ b/resources/assets/vue/components/general/forms/AdminWorkFlowFormComponent.vue @@ -19,7 +19,7 @@

{{question.question_description}}

Login Information

-
@@ -28,8 +28,8 @@

ORDER Marking:

@@ -39,7 +39,7 @@ @@ -48,7 +48,7 @@ @@ -57,7 +57,7 @@
-

{{ externalApiResponse.data.booking.marking +

{{ externalApiResponse.data.marking }}

-

{{ externalApiResponse.data.booking.bank.account_no }}

+

{{ externalApiResponse.data.bank.account_no }}

-

{{ externalApiResponse.data.booking.bank.holder_name }}

+

{{ externalApiResponse.data.bank.holder_name }}

-

{{ externalApiResponse.data.booking.bank.bank_branch }}

+

{{ externalApiResponse.data.bank.bank_branch }}

@@ -68,9 +68,9 @@