'Retrieved Pending Approval PO for Admin Workflow ', 'message' => 'You have successfully retrieved Pending Approval PO for Admin Workflow' ]; } /** @var CanFetchQuestion */ 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()->subMinutes(30)); }); }) ->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 BookingBaseResource($booking)); } }