mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/exchange-2.0.git
synced 2026-08-20 21:13:59 +00:00
91 lines
2.8 KiB
PHP
91 lines
2.8 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\ValueObjects\Constants\ApprovalStatus;
|
|
use App\Classes\ValueObjects\Constants\TransactionType;
|
|
use App\Http\Resources\BookingBaseResource;
|
|
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 */ //cief todo: 74 - permission update
|
|
private $canFetchQuestion;
|
|
|
|
|
|
/**
|
|
* FetchAdminWFPendingFillPOLogic constructor.
|
|
* @param CanFetchQuestion $canFetchQuestion
|
|
*/
|
|
public function __construct(CanFetchQuestion $canFetchQuestion)
|
|
{
|
|
$this->canFetchQuestion = $canFetchQuestion;
|
|
}
|
|
|
|
|
|
/**
|
|
* @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();
|
|
|
|
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 BookingBaseResource($booking));
|
|
}
|
|
|
|
}
|