mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/exchange-2.0.git
synced 2026-08-22 14:04:01 +00:00
97 lines
3.2 KiB
PHP
97 lines
3.2 KiB
PHP
<?php
|
|
|
|
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\BookingResource;
|
|
use App\Models\KeyValuePair;
|
|
use Carbon\Carbon;
|
|
use App\Models\Booking;
|
|
use ErrorException;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Request;
|
|
|
|
class FetchAdminWFPendingFillPOLogic extends AbstractControllerLogic
|
|
{
|
|
|
|
/**
|
|
* @return array
|
|
*/
|
|
protected function notification():array {
|
|
return [
|
|
'title' => 'Retrieved Pending Fill PO for Admin Workflow ',
|
|
'message' => 'You have successfully retrieved Pending Fill PO for Admin Workflow'
|
|
];
|
|
}
|
|
|
|
/** @var CanFetchQuestion */
|
|
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));
|
|
}
|
|
|
|
}
|