diff --git a/app/Classes/Modules/Bookings/ControllersLogic/ApprovePurchaseOrderLogic.php b/app/Classes/Modules/Bookings/ControllersLogic/ApprovePurchaseOrderLogic.php index f7d1d775..f790feca 100644 --- a/app/Classes/Modules/Bookings/ControllersLogic/ApprovePurchaseOrderLogic.php +++ b/app/Classes/Modules/Bookings/ControllersLogic/ApprovePurchaseOrderLogic.php @@ -4,15 +4,7 @@ namespace App\Classes\Modules\Bookings\ControllersLogic; use App\Classes\General\Abstracts\AbstractControllerLogic; -use App\Classes\Modules\Bookings\Services\FetchesBooking; -use App\Classes\Modules\Documents\Services\ApprovesDocument; -use App\Classes\Modules\Documents\Services\FetchesDocument; -use App\Classes\Modules\Documents\Services\RejectsDocument; -use App\Classes\Modules\Transactions\Processors\CreateInvoiceTransactionProcessor; -use App\Classes\Modules\Transactions\Services\FetchesTransaction; -use App\Classes\Modules\Transactions\Services\UpdatesTransactionStatus; -use App\Classes\ValueObjects\Constants\ApprovalStatus; -use App\Classes\ValueObjects\Constants\TransactionType; +use App\Classes\Modules\Bookings\Processors\ApprovePurchaseOrderProcessor; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; @@ -29,26 +21,16 @@ class ApprovePurchaseOrderLogic extends AbstractControllerLogic ]; } - /** @var FetchesBooking */ - private $fetchesBooking; - - /** @var UpdatesTransactionStatus */ - private $updatesTransactionStatus; - - /** @var CreateInvoiceTransactionProcessor */ - private $createInvoiceTransactionProcessor; + /** @var ApprovePurchaseOrderProcessor */ + private $approvePurchaseOrderProcessor; /** * ApprovePurchaseOrderLogic constructor. - * @param FetchesBooking $fetchesBooking - * @param UpdatesTransactionStatus $updatesTransactionStatus - * @param CreateInvoiceTransactionProcessor $createInvoiceTransactionProcessor + * @param ApprovePurchaseOrderProcessor $approvePurchaseOrderProcessor */ - public function __construct(FetchesBooking $fetchesBooking, UpdatesTransactionStatus $updatesTransactionStatus, CreateInvoiceTransactionProcessor $createInvoiceTransactionProcessor) + public function __construct(ApprovePurchaseOrderProcessor $approvePurchaseOrderProcessor) { - $this->fetchesBooking = $fetchesBooking; - $this->updatesTransactionStatus = $updatesTransactionStatus; - $this->createInvoiceTransactionProcessor = $createInvoiceTransactionProcessor; + $this->approvePurchaseOrderProcessor = $approvePurchaseOrderProcessor; } /** @@ -58,18 +40,7 @@ class ApprovePurchaseOrderLogic extends AbstractControllerLogic */ public function logic(Request $request) : JsonResponse { - - $booking = $this->fetchesBooking->execute(['id' => $request->route('id')]); - - $purchaseOrder = $booking->transactions()->where('type', TransactionType::PURCHASE_ORDER)->first(); - - $booking->transactions()->where('type', TransactionType::PURCHASE_ORDER)->where('id', '!=', $purchaseOrder->id)->delete(); - - $this->updatesTransactionStatus->execute($purchaseOrder, ApprovalStatus::APPROVED); - - $this->createInvoiceTransactionProcessor->execute($booking); - + $this->approvePurchaseOrderProcessor->execute($request->route('id')); return $this->response([]); } - -} \ No newline at end of file +} 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/Bookings/Processors/ApprovePurchaseOrderProcessor.php b/app/Classes/Modules/Bookings/Processors/ApprovePurchaseOrderProcessor.php new file mode 100644 index 00000000..1a1a0341 --- /dev/null +++ b/app/Classes/Modules/Bookings/Processors/ApprovePurchaseOrderProcessor.php @@ -0,0 +1,55 @@ +fetchesBooking = $fetchesBooking; + $this->updatesTransactionStatus = $updatesTransactionStatus; + $this->createInvoiceTransactionProcessor = $createInvoiceTransactionProcessor; + } + + /** + * @param int $bookingId + * @return void + * @throws \App\Classes\Exceptions\MalformedRequestException + * @throws \App\Classes\Exceptions\JobResourceNotFoundException + */ + public function execute(int $bookingId) { + + $booking = $this->fetchesBooking->execute(['id' => $bookingId]); + + $purchaseOrder = $booking->transactions()->where('type', TransactionType::PURCHASE_ORDER)->first(); + + $booking->transactions()->where('type', TransactionType::PURCHASE_ORDER)->where('id', '!=', $purchaseOrder->id)->delete(); + + $this->updatesTransactionStatus->execute($purchaseOrder, ApprovalStatus::APPROVED); + + $this->createInvoiceTransactionProcessor->execute($booking); + } +} diff --git a/app/Classes/Modules/Questionnaires/ControllersLogic/FetchAdminWFBookingLogic.php b/app/Classes/Modules/Questionnaires/ControllersLogic/FetchAdminWFBookingLogic.php new file mode 100644 index 00000000..3d3b75a4 --- /dev/null +++ b/app/Classes/Modules/Questionnaires/ControllersLogic/FetchAdminWFBookingLogic.php @@ -0,0 +1,105 @@ + '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 responseJson([ + // 'booking' => new BookingBaseResource($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/Classes/Modules/Questionnaires/ControllersLogic/FetchAdminWFPendingApprovalPOLogic.php b/app/Classes/Modules/Questionnaires/ControllersLogic/FetchAdminWFPendingApprovalPOLogic.php new file mode 100644 index 00000000..94d4f07a --- /dev/null +++ b/app/Classes/Modules/Questionnaires/ControllersLogic/FetchAdminWFPendingApprovalPOLogic.php @@ -0,0 +1,99 @@ + '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; + + /** @var FetchesBooking */ + private $fetchesBooking; + + /** + * FetchAdminWFPendingApprovalPOLogic constructor. + * @param CanFetchQuestion $canFetchQuestion + * @param FetchesBooking $fetchesBooking + */ + public function __construct(CanFetchQuestion $canFetchQuestion, FetchesBooking $fetchesBooking) + { + $this->canFetchQuestion = $canFetchQuestion; + $this->fetchesBooking = $fetchesBooking; + } + + + /** + * @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(); + + $booking = $this->fetchesBooking->execute(['purchase_order_approval' => true, 'status_in' => [2], 'id_not_in' => $excludedBookingIds, 'with_transactions' => true, 'order_by_id_desc' => true]); + + 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..7687a2ff --- /dev/null +++ b/app/Classes/Modules/Questionnaires/ControllersLogic/FetchAdminWFPendingFillPOLogic.php @@ -0,0 +1,96 @@ + '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; + + /** @var FetchesBooking */ + private $fetchesBooking; + + /** + * FetchAdminWFPendingFillPOLogic constructor. + * @param CanFetchQuestion $canFetchQuestion + * @param FetchesBooking $fetchesBooking + */ + public function __construct(CanFetchQuestion $canFetchQuestion, FetchesBooking $fetchesBooking) + { + $this->canFetchQuestion = $canFetchQuestion; + $this->fetchesBooking = $fetchesBooking; + } + + /** + * @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(); + + $booking = $this->fetchesBooking->execute(['pending_purchase_order' => true, 'has_payment_status_in' => [2, 3], 'id_not_in' => $excludedBookingIds, 'with_transactions' => true, 'order_by_id_desc' => true]); + + 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 BookingResource($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/Classes/Modules/Questionnaires/Processors/SaveAnswerActionV1AdminWFProcessor.php b/app/Classes/Modules/Questionnaires/Processors/SaveAnswerActionV1AdminWFProcessor.php new file mode 100644 index 00000000..0e1ead49 --- /dev/null +++ b/app/Classes/Modules/Questionnaires/Processors/SaveAnswerActionV1AdminWFProcessor.php @@ -0,0 +1,31 @@ +approvePurchaseOrderProcessor = $approvePurchaseOrderProcessor; + } + + /** + * @return + */ + public function execute($questionMetadata, $answerInText){ + if($answerInText === "approve_po_approved"){ + $this->approvePurchaseOrderProcessor->execute($questionMetadata['id']); + } + } +} diff --git a/app/Classes/Modules/Questionnaires/Processors/SaveAnswerV1AdminWFProcessor.php b/app/Classes/Modules/Questionnaires/Processors/SaveAnswerV1AdminWFProcessor.php index 2b91e60c..1a92a56c 100644 --- a/app/Classes/Modules/Questionnaires/Processors/SaveAnswerV1AdminWFProcessor.php +++ b/app/Classes/Modules/Questionnaires/Processors/SaveAnswerV1AdminWFProcessor.php @@ -4,28 +4,27 @@ namespace App\Classes\Modules\Questionnaires\Processors; use App\Models\QAUserAnswerSelected; -use App\Classes\Modules\Questionnaires\Services\FetchesUserAnswerSelected; +use App\Classes\Modules\Questionnaires\Processors\SaveAnswerActionV1AdminWFProcessor; use App\Classes\Modules\Documents\Processors\UploadDocumentProcessor; use App\Classes\ValueObjects\Constants\QAType; - class SaveAnswerV1AdminWFProcessor { - /** @var FetchesUserAnswerSelected */ - private $fetchesUserAnswerSelected; - /** @var UploadDocumentProcessor */ private $uploadDocumentForProcessor; + /** @var SaveAnswerActionV1AdminWFProcessor */ + private $saveAnswerActionProcessor; + /** * SaveAnswerV1AdminWFProcessor constructor. - * @param FetchesUserAnswerSelected $fetchesUserAnswerSelected * @param UploadDocumentProcessor $uploadDocumentForProcessor + * @param SaveAnswerActionV1AdminWFProcessor $saveAnswerActionProcessor */ - public function __construct(FetchesUserAnswerSelected $fetchesUserAnswerSelected, UploadDocumentProcessor $uploadDocumentForProcessor) + public function __construct(UploadDocumentProcessor $uploadDocumentForProcessor, SaveAnswerActionV1AdminWFProcessor $saveAnswerActionProcessor) { - $this->fetchesUserAnswerSelected = $fetchesUserAnswerSelected; $this->uploadDocumentForProcessor = $uploadDocumentForProcessor; + $this->saveAnswerActionProcessor = $saveAnswerActionProcessor; } /** @@ -80,6 +79,8 @@ class SaveAnswerV1AdminWFProcessor } $answer->save(); + $this->saveAnswerActionProcessor->execute($questionMetadata, $answerInText); + return $answer; } } diff --git a/app/Http/Controllers/Questionnaires/AdminWorkflowBaseController.php b/app/Http/Controllers/Questionnaires/AdminWorkflowBaseController.php index 068728a7..a3c95140 100644 --- a/app/Http/Controllers/Questionnaires/AdminWorkflowBaseController.php +++ b/app/Http/Controllers/Questionnaires/AdminWorkflowBaseController.php @@ -1,61 +1,50 @@ 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 FetchAdminWFBookingLogic $logic + * @return JsonResponse + */ + public function fetchBooking(Request $request, FetchAdminWFBookingLogic $logic): JsonResponse { + return $logic->execute($request); + } + /** + * @param Request $request + * @param FetchAdminWFModelAttributesLogic $logic + * @return JsonResponse + */ + public function fetchModelAttributes(Request $request, FetchAdminWFModelAttributesLogic $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(); + /** + * @param Request $request + * @param FetchAdminWFPendingApprovalPOLogic $logic + * @return JsonResponse + */ + public function fetchPendingApprovalPO(Request $request, FetchAdminWFPendingApprovalPOLogic $logic): JsonResponse { + return $logic->execute($request); + } - 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 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 new file mode 100644 index 00000000..1490bf24 --- /dev/null +++ b/app/Http/Resources/BookingBaseResource.php @@ -0,0 +1,27 @@ + $this->id, + '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 @@
- {{ externalApiResponse.data.booking.marking
+ |
@@ -39,7 +39,7 @@
- {{ externalApiResponse.data.account_no }}+{{ externalApiResponse.data.bank.account_no }} |
- {{ externalApiResponse.data.holder_name }}+{{ externalApiResponse.data.bank.holder_name }} |
- {{ externalApiResponse.data.pin }}+{{ externalApiResponse.data.bank.bank_branch }} |