mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/portal.git
synced 2026-08-19 04:23:59 +00:00
update CUSTOM SEGMENTS price api
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -0,0 +1,124 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Segments\ControllersLogic;
|
||||
|
||||
use App\Classes\Exceptions\ResourceNotFoundException;
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\Segments\DataTransferObjects\ConstantObject;
|
||||
use App\Classes\Modules\Segments\DataTransferObjects\SegmentObject;
|
||||
use App\Classes\Modules\Segments\Services\CreatesConstant;
|
||||
use App\Classes\Modules\Segments\Services\CreatesSegment;
|
||||
use App\Classes\Modules\Segments\Services\FetchesConstant;
|
||||
use App\Classes\Modules\Segments\Services\FetchesSegment;
|
||||
use App\Classes\Modules\Segments\Standards\Rules\CanCreateConstant;
|
||||
use App\Classes\Modules\Segments\Standards\Rules\CanUpdateConstant;
|
||||
use App\Classes\Modules\Segments\Services\UpdatesConstant;
|
||||
use App\Http\Resources\ConstantResource;
|
||||
use App\Models\SegmentConstant;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Classes\Modules\Segments\Services\UpdatesConstantValue;
|
||||
|
||||
class UpdateSegmentPriceLogic extends AbstractControllerLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => '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));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Segments;
|
||||
|
||||
use App\Classes\Modules\Segments\ControllersLogic\UpdateSegmentPriceLogic;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class UpdateSegmentPriceController
|
||||
{
|
||||
/**
|
||||
* @param Request $request
|
||||
* @param UpdateSegmentLogic $logic
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function update(Request $request, UpdateSegmentPriceLogic $logic): JsonResponse {
|
||||
return $logic->execute($request);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
+4
-1
@@ -17,7 +17,10 @@
|
||||
<p class="no-margin fs-10 all-caps">Amount</p>
|
||||
<div>MYR {{ item.amount.toFixed(2) }}</div>
|
||||
</div>
|
||||
<div class="col-auto p-l-0 p-r-0">
|
||||
<div class="col-auto p-l-0 p-r-0 d-flex justify-content-center align-items-center">
|
||||
<div>
|
||||
<span class="d-inline-block m-r-15 text-primary bold text-underline pointer">Billing Question?</span>
|
||||
</div>
|
||||
<div v-if="item.documents.length">
|
||||
<div v-for="file in item.documents[0].files" v-bind:key="file.id" class="col-auto no-padding">
|
||||
<document-file-viewer-component :file="file">
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<div class="font-heading all-caps">MYR {{item.price[data.id].amount}} <i class="fa fa-edit pointer fa-fw m-l-5 requestModal text-primary" data-type="editSegmentPrice"></i></div>
|
||||
<div class="font-heading all-caps">MYR {{item.price}} <i class="fa fa-edit pointer fa-fw m-l-5 requestModal text-primary" data-type="editSegmentPrice"></i></div>
|
||||
<modal-component class="animate__animated animate__fast animate__fadeIn" type="editSegmentPrice">
|
||||
<edit-segment-price-form-component :data="item" :section="section"></edit-segment-price-form-component>
|
||||
</modal-component>
|
||||
|
||||
@@ -6,10 +6,10 @@
|
||||
<h3 class="text-center">Edit {{data.name}} Price</h3>
|
||||
</div>
|
||||
</div>
|
||||
<validation-wrapper-component class="m-b-15" :validator="$v.parameters.rate.amount">
|
||||
<validation-wrapper-component class="m-b-15" :validator="$v.parameters.value">
|
||||
<label class="text-primary">Segment Price (MYR)</label>
|
||||
<div class="controls">
|
||||
<input type="text" class="form-control fs-12" v-model.trim="parameters.price[data.id].amount" v-money="money">
|
||||
<input type="text" class="form-control fs-12" v-model.trim="parameters.value" v-money="money">
|
||||
</div>
|
||||
</validation-wrapper-component>
|
||||
<div class="row m-t-15">
|
||||
@@ -17,7 +17,7 @@
|
||||
<div class="btn btn-lg btn-default b-rad-none" data-dismiss="modal">Cancel</div>
|
||||
</div>
|
||||
<div class="col p-l-5">
|
||||
<div class="btn btn-primary w-100 btn-lg" @click="submit(route('api.segment.constant.update', data.id), 'put', section, true, true)">Confirm</div>
|
||||
<div class="btn btn-primary w-100 btn-lg" @click="submit(route('api.segment.price.update', data.id), 'put', section, true, true)">Confirm</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -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]
|
||||
|
||||
@@ -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');
|
||||
|
||||
Reference in New Issue
Block a user