mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/exchange-2.0.git
synced 2026-08-19 12:33:56 +00:00
8b01421be7
-Update Non Segment Constant Service Class -Create Non Standard Segment Constant Logic Class -Update Non Standard Segment Constant Logic Class -Delete Non Standard Segment Logic Class
187 lines
8.5 KiB
PHP
187 lines
8.5 KiB
PHP
<?php
|
|
|
|
namespace App\Classes\Modules\SegmentConstants\ControllersLogic;
|
|
|
|
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
|
|
|
use App\Classes\Modules\SegmentConstants\Services\FetchesSegmentConstant;
|
|
use App\Classes\Modules\Segments\Services\FetchesSegment;
|
|
|
|
use App\Classes\Modules\SegmentConstants\Standards\Rules\CanCreateSegmentConstant;
|
|
|
|
use App\Classes\Modules\SegmentConstants\Services\CreatesSegmentConstantTax;
|
|
use App\Classes\Modules\SegmentConstants\DataTransferObjects\SegmentConstantTaxObject;
|
|
|
|
use App\Classes\Modules\SegmentConstants\Services\CreatesSegmentConstantBillingFee;
|
|
use App\Classes\Modules\SegmentConstants\DataTransferObjects\SegmentConstantBillingFeeObject;
|
|
|
|
use App\Classes\Modules\SegmentConstants\Services\CreatesSegmentConstantServiceCharge;
|
|
use App\Classes\Modules\SegmentConstants\DataTransferObjects\SegmentConstantServiceChargeObject;
|
|
|
|
use App\Classes\Modules\SegmentConstants\Services\CreatesSegmentConstantBookingAmountMax;
|
|
use App\Classes\Modules\SegmentConstants\DataTransferObjects\SegmentConstantBookingAmountMaxObject;
|
|
|
|
use App\Classes\Modules\SegmentConstants\Services\CreatesSegmentConstantPaymentAttemptExpiryTime;
|
|
use App\Classes\Modules\SegmentConstants\DataTransferObjects\SegmentConstantPaymentAttemptExpiryTimeObject;
|
|
|
|
use App\Http\Resources\SegmentConstantResource;
|
|
|
|
use ErrorException;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
class CreateSegmentConstantLogic extends AbstractControllerLogic
|
|
{
|
|
/**
|
|
* @return array
|
|
*/
|
|
protected function notification():array {
|
|
return [
|
|
'title' => 'Created Segment Constant',
|
|
'message' => 'You have successfully created a new Segment Constant'
|
|
];
|
|
}
|
|
|
|
/** @var CanCreateSegmentConstant */
|
|
private $canCreateSegmentConstant;
|
|
|
|
/** @var CreatesSegmentConstantTax */
|
|
private $createsSegmentConstantTax;
|
|
|
|
/** @var CreatesSegmentConstantBillingFee */
|
|
private $createsSegmentConstantBillingFee;
|
|
|
|
/** @var CreatesSegmentConstantServiceCharge */
|
|
private $createsSegmentConstantServiceCharge;
|
|
|
|
/** @var CreatesSegmentConstantBookingAmountMax */
|
|
private $createsSegmentConstantBookingAmountMax;
|
|
|
|
/** @var CreatesSegmentConstantPaymentAttemptExpiryTime */
|
|
private $createsSegmentConstantPaymentAttemptExpiryTime;
|
|
|
|
/** @var FetchesSegmentConstant */
|
|
private $fetchesSegmentConstant;
|
|
|
|
/** @var FetchesSegment */
|
|
private $fetchesSegment;
|
|
|
|
/**
|
|
* CreateSegmentConstantLogic constructor.
|
|
* @param CanCreateSegmentConstant $canCreateSegmentConstant
|
|
* @param CreatesSegmentConstantTax $createsSegmentConstantTax
|
|
* @param CreatesSegmentConstantBillingFee $createsSegmentConstantBillingFee
|
|
* @param CreatesSegmentConstantServiceCharge $createsSegmentConstantServiceCharge
|
|
* @param CreatesSegmentConstantBookingAmountMax $createsSegmentConstantBookingAmountMax
|
|
* @param CreatesSegmentConstantPaymentAttemptExpiryTime $createsSegmentConstantPaymentAttemptExpiryTime
|
|
* @param FetchesSegmentConstant $fetchesSegmentConstant
|
|
* @param FetchesSegment $fetchesSegment
|
|
*/
|
|
public function __construct(
|
|
CanCreateSegmentConstant $canCreateSegmentConstant,
|
|
CreatesSegmentConstantTax $createsSegmentConstantTax,
|
|
CreatesSegmentConstantBillingFee $createsSegmentConstantBillingFee,
|
|
CreatesSegmentConstantServiceCharge $createsSegmentConstantServiceCharge,
|
|
CreatesSegmentConstantBookingAmountMax $createsSegmentConstantBookingAmountMax,
|
|
CreatesSegmentConstantPaymentAttemptExpiryTime $createsSegmentConstantPaymentAttemptExpiryTime,
|
|
FetchesSegmentConstant $fetchesSegmentConstant,
|
|
FetchesSegment $fetchesSegment
|
|
)
|
|
{
|
|
$this->canCreateSegmentConstant = $canCreateSegmentConstant;
|
|
$this->createsSegmentConstantTax = $createsSegmentConstantTax;
|
|
$this->createsSegmentConstantBillingFee = $createsSegmentConstantBillingFee;
|
|
$this->createsSegmentConstantServiceCharge = $createsSegmentConstantServiceCharge;
|
|
$this->createsSegmentConstantBookingAmountMax = $createsSegmentConstantBookingAmountMax;
|
|
$this->createsSegmentConstantPaymentAttemptExpiryTime = $createsSegmentConstantPaymentAttemptExpiryTime;
|
|
$this->fetchesSegmentConstant = $fetchesSegmentConstant;
|
|
$this->fetchesSegment = $fetchesSegment;
|
|
}
|
|
|
|
/**
|
|
* @param Request $request
|
|
* @return JsonResponse
|
|
* @throws ErrorException
|
|
*/
|
|
public function logic(Request $request) : JsonResponse
|
|
{
|
|
try {
|
|
DB::beginTransaction();
|
|
|
|
$segment_query = $this->fetchesSegment->execute([
|
|
'id' => $request->input('segment_id'),
|
|
]);
|
|
|
|
$segment_constant_query = $this->fetchesSegmentConstant->execute([
|
|
'id' => $request->input('standard_segment_constant_id'),
|
|
]);
|
|
|
|
if ($segment_constant_query->reference == 'TAX') {
|
|
$segment_constant_object = new SegmentConstantTaxObject(
|
|
$request->input('segment_id'),
|
|
$segment_constant_query->name,
|
|
$segment_constant_query->reference,
|
|
$segment_constant_query->detail->type,
|
|
$request->input('value')
|
|
);
|
|
|
|
$this->canCreateSegmentConstant->passes($segment_constant_object);
|
|
$segment_constant_query = $this->createsSegmentConstantTax->execute($segment_query, $segment_constant_object);
|
|
}
|
|
elseif ($segment_constant_query->reference == 'BILLING_FEE') {
|
|
$segment_constant_object = new SegmentConstantBillingFeeObject(
|
|
$request->input('segment_id'),
|
|
$segment_constant_query->name,
|
|
$segment_constant_query->reference,
|
|
$segment_constant_query->detail->type,
|
|
$request->input('value')
|
|
);
|
|
$this->canCreateSegmentConstant->passes($segment_constant_object);
|
|
$segment_constant_query = $this->createsSegmentConstantBillingFee->execute($segment_query, $segment_constant_object);
|
|
}
|
|
elseif ($segment_constant_query->reference == 'SERVICE_CHARGE') {
|
|
$segment_constant_object = new SegmentConstantServiceChargeObject(
|
|
$request->input('segment_id'),
|
|
$segment_constant_query->name,
|
|
$segment_constant_query->reference,
|
|
$segment_constant_query->detail->type,
|
|
$request->input('value')
|
|
);
|
|
$this->canCreateSegmentConstant->passes($segment_constant_object);
|
|
$segment_constant_query = $this->createsSegmentConstantServiceCharge->execute($segment_query, $segment_constant_object);
|
|
}
|
|
elseif ($segment_constant_query->reference == 'BOOKING_AMOUNT_MAX') {
|
|
$segment_constant_object = new SegmentConstantBookingAmountMaxObject(
|
|
$request->input('segment_id'),
|
|
$segment_constant_query->name,
|
|
$segment_constant_query->reference,
|
|
$segment_constant_query->detail->type,
|
|
$request->input('value'),
|
|
$segment_constant_query->detail->currency_id
|
|
);
|
|
$this->canCreateSegmentConstant->passes($segment_constant_object);
|
|
$segment_constant_query = $this->createsSegmentConstantBookingAmountMax->execute($segment_query, $segment_constant_object);
|
|
}
|
|
elseif ($segment_constant_query->reference == 'PAYMENT_ATTEMP_EXPIRY_TIME') {
|
|
$segment_constant_object = new SegmentConstantPaymentAttemptExpiryTimeObject(
|
|
$request->input('segment_id'),
|
|
$segment_constant_query->name,
|
|
$segment_constant_query->reference,
|
|
$segment_constant_query->detail->type,
|
|
$request->input('value')
|
|
);
|
|
$this->canCreateSegmentConstant->passes($segment_constant_object);
|
|
$segment_constant_query = $this->createsSegmentConstantPaymentAttemptExpiryTime->execute($segment_query, $segment_constant_object);
|
|
}
|
|
|
|
DB::commit();
|
|
|
|
return $this->resourceResponse(new SegmentConstantResource($segment_constant_query));
|
|
|
|
} catch (\Exception $exception) {
|
|
throw new ErrorException($exception->getMessage(), $exception->getCode());
|
|
}
|
|
|
|
}
|
|
} |