'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)); } }