mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/exchange-2.0.git
synced 2026-08-22 05:53:58 +00:00
83 lines
2.7 KiB
PHP
83 lines
2.7 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\BookingAttributeNames;
|
|
use App\Classes\Modules\Bookings\Services\FetchesBooking;
|
|
use App\Http\Resources\BookingBaseResource;
|
|
use App\Http\Resources\BookingResource;
|
|
use App\Models\Booking;
|
|
use ErrorException;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Request;
|
|
|
|
class FetchAdminWFModelAttributesLogic extends AbstractControllerLogic
|
|
{
|
|
|
|
/**
|
|
* @return array
|
|
*/
|
|
protected function notification():array {
|
|
return [
|
|
'title' => 'Retrieved Model Attributes for Admin Workflow ',
|
|
'message' => 'You have successfully retrieved Model Attributes for Admin Workflow'
|
|
];
|
|
}
|
|
|
|
/** @var CanFetchQuestion */
|
|
private $canFetchQuestion;
|
|
|
|
/** @var FetchesBooking */
|
|
private $fetchesBooking;
|
|
|
|
/**
|
|
* FetchAdminWFModelAttributesLogic 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();
|
|
|
|
// $booking = Booking::find($request->route('booking_id'));
|
|
$booking = $this->fetchesBooking->execute(['id' => $request->route('booking_id'), 'with_transactions' => true, 'order_by_id_desc' => true]);
|
|
|
|
if (!$booking) {
|
|
return responseJson(null, 'No booking found', 404);
|
|
}
|
|
|
|
$attributes = $booking->modelAttributes()
|
|
->where('name', BookingAttributeNames::ORDER_REFERENCE_NO)
|
|
->get(['id', 'value'])
|
|
->map(fn ($attr) => $attr->only(['id', 'value']));
|
|
|
|
$transaction = $booking->bills()->first(); //cief todo: 74 - more than 1 record?
|
|
// return responseJson([
|
|
// 'booking' => $booking,
|
|
// 'booking_attributes' => $attributes,
|
|
// 'reference' =>$transaction->owner->owner->marking,
|
|
// 'marking' => $transaction->owner->owner->company->reference,
|
|
// 'currency_rate' => $transaction->currency_rate,
|
|
// 'total_amount' =>$transaction->currency->short_code . ' ' . number_format((float)$transaction->amount, 2, '.', '')
|
|
// ]);
|
|
|
|
return $this->resourceResponse(new BookingResource($booking));
|
|
}
|
|
|
|
}
|