From 38d4da72f7fca2afa5549325c81ced7245542db0 Mon Sep 17 00:00:00 2001 From: Dillon Ngo Date: Sat, 4 Jan 2025 23:32:11 +0800 Subject: [PATCH] Admin Workflow - API code refactor to fetch information to display on workflow --- .../FetchAdminWFPendingApprovalPOLogic.php | 25 +++++++++++++------ .../FetchAdminWFPendingFillPOLogic.php | 22 ++++++++++------ 2 files changed, 32 insertions(+), 15 deletions(-) diff --git a/app/Classes/Modules/Questionnaires/ControllersLogic/FetchAdminWFPendingApprovalPOLogic.php b/app/Classes/Modules/Questionnaires/ControllersLogic/FetchAdminWFPendingApprovalPOLogic.php index 878cde78..64ecac70 100644 --- a/app/Classes/Modules/Questionnaires/ControllersLogic/FetchAdminWFPendingApprovalPOLogic.php +++ b/app/Classes/Modules/Questionnaires/ControllersLogic/FetchAdminWFPendingApprovalPOLogic.php @@ -5,6 +5,7 @@ namespace App\Classes\Modules\Questionnaires\ControllersLogic; use App\Classes\General\Abstracts\AbstractControllerLogic; use App\Classes\Modules\Questionnaires\Standards\Rules\CanFetchQuestion; +use App\Classes\Modules\Bookings\Services\FetchesBooking; use App\Classes\ValueObjects\Constants\ApprovalStatus; use App\Classes\ValueObjects\Constants\TransactionType; use App\Http\Resources\BookingBaseResource; @@ -15,6 +16,7 @@ use App\Models\Booking; use ErrorException; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; +use Illuminate\Support\Facades\Log; class FetchAdminWFPendingApprovalPOLogic extends AbstractControllerLogic { @@ -32,14 +34,18 @@ class FetchAdminWFPendingApprovalPOLogic extends AbstractControllerLogic /** @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) + public function __construct(CanFetchQuestion $canFetchQuestion, FetchesBooking $fetchesBooking) { $this->canFetchQuestion = $canFetchQuestion; + $this->fetchesBooking = $fetchesBooking; } @@ -66,12 +72,17 @@ class FetchAdminWFPendingApprovalPOLogic extends AbstractControllerLogic }) ->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 = 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(); + + // $booking1 = $this->fetchesBooking->execute(['purchase_order_approval' => true, 'status_in' => [2], 'order_by_id_desc' => true, 'with_transactions' => true]); + // Log::info('booking1 '.json_encode($booking1)); + + $booking = $this->fetchesBooking->execute(['purchase_order_approval' => true, 'status_in' => [2], 'id_not_in' => $excludedBookingIds, 'order_by_id_desc' => true]); if(!$booking){ return responseJson(null, 'No booking found', 404); diff --git a/app/Classes/Modules/Questionnaires/ControllersLogic/FetchAdminWFPendingFillPOLogic.php b/app/Classes/Modules/Questionnaires/ControllersLogic/FetchAdminWFPendingFillPOLogic.php index 91e1b54a..00e5b1f6 100644 --- a/app/Classes/Modules/Questionnaires/ControllersLogic/FetchAdminWFPendingFillPOLogic.php +++ b/app/Classes/Modules/Questionnaires/ControllersLogic/FetchAdminWFPendingFillPOLogic.php @@ -5,6 +5,7 @@ namespace App\Classes\Modules\Questionnaires\ControllersLogic; use App\Classes\General\Abstracts\AbstractControllerLogic; use App\Classes\Modules\Questionnaires\Standards\Rules\CanFetchQuestion; +use App\Classes\Modules\Bookings\Services\FetchesBooking; use App\Classes\ValueObjects\Constants\ApprovalStatus; use App\Classes\ValueObjects\Constants\TransactionType; use App\Http\Resources\BookingBaseResource; @@ -31,17 +32,20 @@ class FetchAdminWFPendingFillPOLogic extends AbstractControllerLogic /** @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) + public function __construct(CanFetchQuestion $canFetchQuestion, FetchesBooking $fetchesBooking) { $this->canFetchQuestion = $canFetchQuestion; + $this->fetchesBooking = $fetchesBooking; } - /** * @param Request $request * @return JsonResponse @@ -65,12 +69,14 @@ class FetchAdminWFPendingFillPOLogic extends AbstractControllerLogic }) ->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 = 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, 'order_by_id_desc' => true]); if(!$booking){ return responseJson(null, 'No booking found', 404);