mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/exchange-2.0.git
synced 2026-08-19 04:23:55 +00:00
106 lines
3.2 KiB
PHP
106 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\ValueObjects\Constants\ApprovalStatus;
|
|
use App\Http\Resources\BookingBaseResource;
|
|
use App\Models\Booking;
|
|
use App\Models\KeyValuePair;
|
|
use Carbon\Carbon;
|
|
use ErrorException;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Request;
|
|
|
|
class FetchAdminWFBookingLogic extends AbstractControllerLogic
|
|
{
|
|
|
|
/**
|
|
* @return array
|
|
*/
|
|
protected function notification():array {
|
|
return [
|
|
'title' => 'Retrieved Booking for Admin Workflow ',
|
|
'message' => 'You have successfully retrieved a Booking for Admin Workflow'
|
|
];
|
|
}
|
|
|
|
/** @var CanFetchQuestion */
|
|
private $canFetchQuestion;
|
|
|
|
/**
|
|
* FetchAdminWFBookingLogic 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', '1688_admin_workflow_processed')
|
|
->orWhere(function ($query) {
|
|
$query->where('key', '1688_admin_workflow_processing')
|
|
->where('updated_at', '>', Carbon::now()->subHour());
|
|
});
|
|
})
|
|
->pluck('owner_id')
|
|
->filter(function ($value) {
|
|
return is_numeric($value);
|
|
})
|
|
->toArray();
|
|
|
|
|
|
$timeAgo = Carbon::now()->subMonths(6);
|
|
$serviceId = 4;
|
|
$booking = Booking::where('service_id', $serviceId)
|
|
->where('status', ApprovalStatus::APPROVED)
|
|
->whereNotIn('id', $excludedBookingIds)
|
|
->whereHas('bills', function ($query) {
|
|
$query->whereHas('groupTransaction', function ($query) {
|
|
$query->whereHas('group', function ($query) {
|
|
$query->whereDoesntHave('billGroup')->whereIn('issuer', [2]);
|
|
});
|
|
});
|
|
})
|
|
->where('created_at', '>=', $timeAgo)
|
|
->latest()
|
|
->first();
|
|
|
|
if(!$booking){
|
|
return responseJson(null, 'No booking found', 404);
|
|
}
|
|
|
|
markedProcessing($booking, '1688_admin_workflow_processing');
|
|
|
|
// return responseJson([
|
|
// 'passwords' => $booking->bank->holder_name ?? null,
|
|
// 'account_no' => $booking->bank->account_no ?? null,
|
|
// 'pin' => $booking->bank->bank_branch ?? null,
|
|
// 'holder_name' => $booking->bank->holder_name ?? null,
|
|
// 'booking' => $booking
|
|
// ]);
|
|
|
|
// return responseJson([
|
|
// 'booking' => new BookingBaseResource($booking)
|
|
// ]);
|
|
|
|
|
|
return $this->resourceResponse(new BookingBaseResource($booking));
|
|
}
|
|
|
|
}
|