diff --git a/app/Classes/Modules/Segments/ControllersLogic/UpdateSegmentLogic.php b/app/Classes/Modules/Segments/ControllersLogic/UpdateSegmentLogic.php index 43eaa54e..f0378691 100644 --- a/app/Classes/Modules/Segments/ControllersLogic/UpdateSegmentLogic.php +++ b/app/Classes/Modules/Segments/ControllersLogic/UpdateSegmentLogic.php @@ -70,7 +70,8 @@ class UpdateSegmentLogic extends AbstractControllerLogic $segment_query = $this->fetchesSegment->execute(['id' => $request->route('id')]); $segment_object = new SegmentObject( - $request->input('name', $segment_query->name) + $request->input('name'), + $segment_query->company_module_id ); $this->canUpdateSegment->passes($segment_object); $segment_query = $this->updatesSegment->execute($segment_query, $segment_object); diff --git a/app/Classes/Modules/Segments/ControllersLogic/UpdateSegmentPriceLogic.php b/app/Classes/Modules/Segments/ControllersLogic/UpdateSegmentPriceLogic.php new file mode 100644 index 00000000..6f1567a8 --- /dev/null +++ b/app/Classes/Modules/Segments/ControllersLogic/UpdateSegmentPriceLogic.php @@ -0,0 +1,124 @@ + 'Updated Segment Price', + 'message' => 'You have successfully updated the Segment 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 CreatesSegment */ + private $createsSegment; + + /** @var UpdatesConstantValue */ + private $updatesConstantValue; + + /** + * UpdateConstantLogic constructor. + * @param CanUpdateConstant $canUpdateConstant + * @param UpdatesConstant $updatesConstant + * @param FetchesSegment $fetchesSegment + * @param FetchesConstant $fetchesConstant + * @param CanCreateConstant $canCreateConstant + * @param CreatesConstant $createsConstant + * @param UpdatesConstantValueByState $updatesConstantValueByState + * @param CreatesSegment $createsSegment + */ + public function __construct( + CanUpdateConstant $canUpdateConstant, + UpdatesConstant $updatesConstant, + FetchesSegment $fetchesSegment, + FetchesConstant $fetchesConstant, + CanCreateConstant $canCreateConstant, + CreatesConstant $createsConstant, + UpdatesConstantValue $updatesConstantValue, + CreatesSegment $createsSegment + ) + { + $this->canUpdateConstant = $canUpdateConstant; + $this->updatesConstant = $updatesConstant; + $this->fetchesSegment = $fetchesSegment; + $this->fetchesConstant = $fetchesConstant; + $this->canCreateConstant = $canCreateConstant; + $this->createsConstant = $createsConstant; + $this->updatesConstantValue = $updatesConstantValue; + $this->createsSegment = $createsSegment; + } + /** + * @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' => $request->input('reference')]); + + $object = new ConstantObject($request->input('reference'), [$request->input('value')]); + + $this->canUpdateConstant->passes($object); + + } catch (ResourceNotFoundException $exception){ + + $object = new ConstantObject( + $request->input('reference'), + [$request->input('value')] + ); + + $constant = $this->createsConstant->execute($segment, $object); + } + + $constant = $this->updatesConstant->execute($constant, $object); + + return $this->resourceResponse(new ConstantResource($constant)); + } + +} \ No newline at end of file diff --git a/app/Http/Controllers/Segments/UpdateSegmentPriceController.php b/app/Http/Controllers/Segments/UpdateSegmentPriceController.php new file mode 100644 index 00000000..4e403348 --- /dev/null +++ b/app/Http/Controllers/Segments/UpdateSegmentPriceController.php @@ -0,0 +1,20 @@ +execute($request); + } + +} \ No newline at end of file diff --git a/app/Http/Resources/SegmentResource.php b/app/Http/Resources/SegmentResource.php index a587a7ff..2ec22145 100644 --- a/app/Http/Resources/SegmentResource.php +++ b/app/Http/Resources/SegmentResource.php @@ -19,7 +19,7 @@ class SegmentResource extends JsonResource return [ 'id' => $this->id, 'name' => $this->name, - 'price' => $constant ? $constant->value : 0 + 'price' => $constant ? $constant->value[0] : 0 ]; } } diff --git a/resources/assets/vue/components/paymentsBilling/elements/CustomerPaymentsBillingComponent.vue b/resources/assets/vue/components/paymentsBilling/elements/CustomerPaymentsBillingComponent.vue index 6573fdca..b2c22979 100644 --- a/resources/assets/vue/components/paymentsBilling/elements/CustomerPaymentsBillingComponent.vue +++ b/resources/assets/vue/components/paymentsBilling/elements/CustomerPaymentsBillingComponent.vue @@ -17,7 +17,10 @@
Amount