Files
exchange-2.0/app/Classes/Modules/Questionnaires/ControllersLogic/FetchAdminWFModelAttributesLogic.php
T

76 lines
2.3 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\Http\Resources\BookingBaseResource;
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;
/**
* FetchAdminWFModelAttributesLogic 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();
$booking = Booking::find($request->route('booking_id'));
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 BookingBaseResource($booking));
}
}