From cd59debee4a929db4ff8d1524688a2598596f02e Mon Sep 17 00:00:00 2001 From: edmondlang Date: Sat, 6 Aug 2022 01:46:06 +0800 Subject: [PATCH] update CUSTOM SEGMENTS price api --- .../ControllersLogic/UpdateSegmentLogic.php | 3 +- .../UpdateSegmentPriceLogic.php | 124 ++++++++++++++++++ .../Segments/UpdateSegmentPriceController.php | 20 +++ app/Http/Resources/SegmentResource.php | 2 +- .../CustomerPaymentsBillingComponent.vue | 5 +- .../settings/elements/SegmentComponent.vue | 2 +- .../forms/EditSegmentPriceFormComponent.vue | 12 +- routes/segment.php | 1 + 8 files changed, 158 insertions(+), 11 deletions(-) create mode 100644 app/Classes/Modules/Segments/ControllersLogic/UpdateSegmentPriceLogic.php create mode 100644 app/Http/Controllers/Segments/UpdateSegmentPriceController.php 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

MYR {{ item.amount.toFixed(2) }}
-
+
+
+ Billing Question? +
diff --git a/resources/assets/vue/components/settings/elements/SegmentComponent.vue b/resources/assets/vue/components/settings/elements/SegmentComponent.vue index 0c0e8866..bc698ea5 100644 --- a/resources/assets/vue/components/settings/elements/SegmentComponent.vue +++ b/resources/assets/vue/components/settings/elements/SegmentComponent.vue @@ -27,7 +27,7 @@
-
MYR {{item.price[data.id].amount}}
+
MYR {{item.price}}
diff --git a/resources/assets/vue/components/settings/forms/EditSegmentPriceFormComponent.vue b/resources/assets/vue/components/settings/forms/EditSegmentPriceFormComponent.vue index 73ab5c61..a6f613e3 100644 --- a/resources/assets/vue/components/settings/forms/EditSegmentPriceFormComponent.vue +++ b/resources/assets/vue/components/settings/forms/EditSegmentPriceFormComponent.vue @@ -6,10 +6,10 @@

Edit {{data.name}} Price

- +
- +
@@ -17,7 +17,7 @@
Cancel
-
Confirm
+
Confirm
@@ -34,16 +34,14 @@ reference: 'CUSTOM_PRICE', id: this.data.id, value : { - amount: this.data.price[this.data.id].amount + amount: this.data.price } } }; }, validations: { parameters: { - rate: { - amount: { required } - } + value: { required } } }, mixins: [modalFormHandler] diff --git a/routes/segment.php b/routes/segment.php index caf8ff82..c59f4ca9 100644 --- a/routes/segment.php +++ b/routes/segment.php @@ -7,6 +7,7 @@ Route::group(['prefix' => 'segment', 'as' => 'segment.', 'namespace' => 'Segment Route::delete('/delete/{id}', 'DeleteSegmentController@destroy')->name('delete'); Route::get('/{id}/show', 'FetchSegmentController@fetch')->name('show'); Route::put('/update/{id}', 'UpdateSegmentController@update')->name('update'); + Route::put('price/update/{id}', 'UpdateSegmentPriceController@update')->name('price.update'); Route::get('/list', 'ListSegmentsController@list')->name('list'); Route::get('/air-shipment/item-price/list', 'ListAirShipmentPriceController@list')->name('air_shipment.price.list');