mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/exchange-2.0.git
synced 2026-08-19 04:23:55 +00:00
92 lines
2.9 KiB
PHP
92 lines
2.9 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\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 FetchAdminWFPendingApprovalPOLogic extends AbstractControllerLogic
|
|
{
|
|
|
|
/**
|
|
* @return array
|
|
*/
|
|
protected function notification():array {
|
|
return [
|
|
'title' => 'Retrieved Pending Approval PO for Admin Workflow ',
|
|
'message' => 'You have successfully retrieved Pending Approval PO for Admin Workflow'
|
|
];
|
|
}
|
|
|
|
/** @var CanFetchQuestion */ //cief todo: permission update
|
|
private $canFetchQuestion;
|
|
|
|
|
|
/**
|
|
* FetchAdminWFPendingApprovalPOLogic 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', 'approve_po_admin_workflow_processed')
|
|
->orWhere(function ($query) {
|
|
$query->where('key', 'approve_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)
|
|
->whereHas('transactions', fn ($query) => $query->where('type', TransactionType::PURCHASE_ORDER)->where('status', '<', ApprovalStatus::APPROVED))
|
|
->first();
|
|
|
|
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 BookingResource($booking));
|
|
}
|
|
|
|
}
|