diff --git a/app/Classes/Modules/Segments/ControllersLogic/CreateBasePriceLogic.php b/app/Classes/Modules/Segments/ControllersLogic/CreateBasePriceLogic.php new file mode 100644 index 00000000..a589995c --- /dev/null +++ b/app/Classes/Modules/Segments/ControllersLogic/CreateBasePriceLogic.php @@ -0,0 +1,121 @@ + 'Create Base Price', + 'message' => 'You have successfully created a Base Price' + ]; + } + + /** @var CanUpdateConstant */ + private $canUpdateConstant; + + /** @var UpdatesConstant */ + private $updatesConstant; + + /** @var FetchesSegment */ + private $fetchesSegment; + + /** @var FetchesConstant */ + private $fetchesConstant; + + /** @var CanCreateConstant */ + private $canCreateConstant; + + /** @var CreatesConstant */ + private $createsConstant; + + + /** @var UpdatesBasePriceConstantByDates */ + private $updatesBasePriceConstantByDates; + + /** + * UpdateConstantLogic constructor. + * @param CanUpdateConstant $canUpdateConstant + * @param UpdatesConstant $updatesConstant + * @param FetchesSegment $fetchesSegment + * @param FetchesConstant $fetchesConstant + * @param CanCreateConstant $canCreateConstant + * @param CreatesConstant $createsConstant + * @param UpdatesBasePriceConstantByDates $updatesBasePriceConstantByDates + */ + public function __construct( + CanUpdateConstant $canUpdateConstant, + UpdatesConstant $updatesConstant, + FetchesSegment $fetchesSegment, + FetchesConstant $fetchesConstant, + CanCreateConstant $canCreateConstant, + CreatesConstant $createsConstant, + UpdatesBasePriceConstantByDates $updatesBasePriceConstantByDates + ) + { + $this->canUpdateConstant = $canUpdateConstant; + $this->updatesConstant = $updatesConstant; + $this->fetchesSegment = $fetchesSegment; + $this->fetchesConstant = $fetchesConstant; + $this->canCreateConstant = $canCreateConstant; + $this->createsConstant = $createsConstant; + $this->updatesBasePriceConstantByDates = $updatesBasePriceConstantByDates; + } + /** + * @param Request $request + * @return JsonResponse + * @throws \App\Classes\Exceptions\AccessForbiddenException + * @throws \App\Classes\Exceptions\MalformedRequestException + * @throws \App\Classes\Exceptions\RequestValidationException + */ + public function logic(Request $request) : JsonResponse + { + $segment = $this->fetchesSegment->execute(['id' => $request->route('id')]); + + try { + + $constant = $this->fetchesConstant->execute(['segment_id' => $segment->id, 'reference' => SegmentConstants::BASE_PRICE]); + + } catch (ResourceNotFoundException $exception){ + + $constantObject = []; + + $object = new ConstantObject( + SegmentConstants::BASE_PRICE, + $constantObject + ); + + $constant = $this->createsConstant->execute($segment, $object); + } + + $constantValue = $this->updatesBasePriceConstantByDates->execute($constant->value, $request->input('dateFrom'), $request->input('dateTo'), $request->input('rate')); + + $object = new ConstantObject(SegmentConstants::BASE_PRICE, $constantValue); + + $this->canUpdateConstant->passes($object); + + $constant = $this->updatesConstant->execute($constant, $object); + + return $this->resourceResponse(new ConstantResource($constant)); + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Segments/ControllersLogic/FetchBasePriceLogic.php b/app/Classes/Modules/Segments/ControllersLogic/FetchBasePriceLogic.php new file mode 100644 index 00000000..49d24bd3 --- /dev/null +++ b/app/Classes/Modules/Segments/ControllersLogic/FetchBasePriceLogic.php @@ -0,0 +1,68 @@ + 'Retrieved Base Price', + 'message' => 'You have successfully retrieved the Base Price' + ]; + } + + + /** @var FetchesConstant */ + private $fetchesConstant; + + /** + * FetchConstantLogic constructor. + * @param FetchesConstant $fetchesConstant + */ + public function __construct(FetchesConstant $fetchesConstant) + { + $this->fetchesConstant = $fetchesConstant; + } + + + /** + * @param Request $request + * @return JsonResponse + */ + public function logic(Request $request) : JsonResponse + { + + $constant = $this->fetchesConstant->execute(['segment_id' => $request->route('id'), 'reference' => SegmentConstants::BASE_PRICE]); + + $constantObject = (array) $constant->value; + + if ($request->input('dateFrom') !== null && $request->input('dateTo') !== null) { + + $period = CarbonPeriod::create($request->input('dateFrom'), $request->input('dateTo')); + + $returnObject = []; + + foreach ($period as $date) { + array_key_exists($date->format('Y-m-d'), $constantObject) === true ? $returnObject[$date->format('Y-m-d')] = $constantObject[$date->format('Y-m-d')] : ''; + } + + $constant->value = json_encode($returnObject); + + } + + return $this->resourceResponse(new ConstantResource($constant)); + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Segments/Services/UpdatesBasePriceConstantByDates.php b/app/Classes/Modules/Segments/Services/UpdatesBasePriceConstantByDates.php new file mode 100644 index 00000000..db49d2c8 --- /dev/null +++ b/app/Classes/Modules/Segments/Services/UpdatesBasePriceConstantByDates.php @@ -0,0 +1,29 @@ +format('Y-m-d')] = $rate; + } + + return $objectArray; + } + +} \ No newline at end of file diff --git a/app/Http/Controllers/Segments/CreateBasePriceController.php b/app/Http/Controllers/Segments/CreateBasePriceController.php new file mode 100644 index 00000000..b8f63eeb --- /dev/null +++ b/app/Http/Controllers/Segments/CreateBasePriceController.php @@ -0,0 +1,20 @@ +execute($request); + } + +} \ No newline at end of file diff --git a/app/Http/Controllers/Segments/FetchBasePriceController.php b/app/Http/Controllers/Segments/FetchBasePriceController.php new file mode 100644 index 00000000..9ef0b225 --- /dev/null +++ b/app/Http/Controllers/Segments/FetchBasePriceController.php @@ -0,0 +1,20 @@ +execute($request); + } + +} \ No newline at end of file diff --git a/resources/assets/vue/components/settings/elements/ListBasePriceSectionComponent.vue b/resources/assets/vue/components/settings/elements/ListBasePriceSectionComponent.vue new file mode 100644 index 00000000..cb31b4de --- /dev/null +++ b/resources/assets/vue/components/settings/elements/ListBasePriceSectionComponent.vue @@ -0,0 +1,195 @@ + + diff --git a/resources/assets/vue/components/settings/forms/BasePriceFormComponent.vue b/resources/assets/vue/components/settings/forms/BasePriceFormComponent.vue new file mode 100644 index 00000000..62d8deda --- /dev/null +++ b/resources/assets/vue/components/settings/forms/BasePriceFormComponent.vue @@ -0,0 +1,80 @@ + + \ No newline at end of file diff --git a/resources/assets/vue/components/settings/forms/EditBasePriceFormComponent.vue b/resources/assets/vue/components/settings/forms/EditBasePriceFormComponent.vue index 3fa9e870..742e95dc 100644 --- a/resources/assets/vue/components/settings/forms/EditBasePriceFormComponent.vue +++ b/resources/assets/vue/components/settings/forms/EditBasePriceFormComponent.vue @@ -1,15 +1,16 @@