Admin Workflow - API code refactor to fetch information to display on workflow

This commit is contained in:
Dillon Ngo
2025-01-04 23:32:11 +08:00
parent db36336484
commit 38d4da72f7
2 changed files with 32 additions and 15 deletions
@@ -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);
@@ -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);