mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/shipping-portal.git
synced 2026-08-19 04:24:12 +00:00
update warehouse api
This commit is contained in:
@@ -15,6 +15,7 @@ use App\Http\Resources\ConstantResource;
|
||||
use App\Models\SegmentConstant;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Classes\Modules\Segments\Services\UpdatesConstantValueByState;
|
||||
|
||||
class UpdateConstantLogic extends AbstractControllerLogic
|
||||
{
|
||||
@@ -47,6 +48,8 @@ class UpdateConstantLogic extends AbstractControllerLogic
|
||||
/** @var CreatesConstant */
|
||||
private $createsConstant;
|
||||
|
||||
/** @var UpdatesConstantValueByState */
|
||||
private $updatesConstantValueByState;
|
||||
|
||||
/**
|
||||
* UpdateConstantLogic constructor.
|
||||
@@ -56,8 +59,17 @@ class UpdateConstantLogic extends AbstractControllerLogic
|
||||
* @param FetchesConstant $fetchesConstant
|
||||
* @param CanCreateConstant $canCreateConstant
|
||||
* @param CreatesConstant $createsConstant
|
||||
* @param UpdatesConstantValueByState $updatesConstantValueByState
|
||||
*/
|
||||
public function __construct(CanUpdateConstant $canUpdateConstant, UpdatesConstant $updatesConstant, FetchesSegment $fetchesSegment, FetchesConstant $fetchesConstant, CanCreateConstant $canCreateConstant, CreatesConstant $createsConstant)
|
||||
public function __construct(
|
||||
CanUpdateConstant $canUpdateConstant,
|
||||
UpdatesConstant $updatesConstant,
|
||||
FetchesSegment $fetchesSegment,
|
||||
FetchesConstant $fetchesConstant,
|
||||
CanCreateConstant $canCreateConstant,
|
||||
CreatesConstant $createsConstant,
|
||||
UpdatesConstantValueByState $updatesConstantValueByState
|
||||
)
|
||||
{
|
||||
$this->canUpdateConstant = $canUpdateConstant;
|
||||
$this->updatesConstant = $updatesConstant;
|
||||
@@ -65,6 +77,7 @@ class UpdateConstantLogic extends AbstractControllerLogic
|
||||
$this->fetchesConstant = $fetchesConstant;
|
||||
$this->canCreateConstant = $canCreateConstant;
|
||||
$this->createsConstant = $createsConstant;
|
||||
$this->updatesConstantValueByState = $updatesConstantValueByState;
|
||||
}
|
||||
/**
|
||||
* @param Request $request
|
||||
@@ -76,27 +89,33 @@ class UpdateConstantLogic extends AbstractControllerLogic
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
|
||||
$object = new ConstantObject($request->input('reference'), $request->input('value'));
|
||||
|
||||
$segment = $this->fetchesSegment->execute(['id' => $request->route('id')]);
|
||||
|
||||
try {
|
||||
|
||||
$constant = $this->fetchesConstant->execute(['segment_id' => $segment->id, 'reference' => $object->getReference()]);
|
||||
$this->canUpdateConstant->passes($object);
|
||||
$constant = $this->fetchesConstant->execute(['segment_id' => $segment->id, 'reference' => $request->input('reference')]);
|
||||
|
||||
/** @var SegmentConstant $constant */
|
||||
$constant = $this->updatesConstant->execute($constant, $object);
|
||||
$constantValue = $this->updatesConstantValueByState->execute($constant->value, $request->input('id'), $request->input('rate'));
|
||||
|
||||
$object = new ConstantObject($request->input('reference'), $constantValue);
|
||||
|
||||
$this->canUpdateConstant->passes($object);
|
||||
|
||||
} catch (ResourceNotFoundException $exception){
|
||||
|
||||
$this->canCreateConstant->passes($object);
|
||||
$constantObject = [];
|
||||
|
||||
$constantObject[$request->input('id')] = $request->input('rate');
|
||||
|
||||
$object = new ConstantObject(
|
||||
$request->input('reference'),
|
||||
$constantObject
|
||||
);
|
||||
|
||||
/** @var SegmentConstant $constant */
|
||||
$constant = $this->createsConstant->execute($segment, $object);
|
||||
|
||||
}
|
||||
|
||||
|
||||
$constant = $this->updatesConstant->execute($constant, $object);
|
||||
|
||||
return $this->resourceResponse(new ConstantResource($constant));
|
||||
}
|
||||
|
||||
@@ -32,6 +32,9 @@ class CompanyModuleResource extends JsonResource
|
||||
$connection = $this->inviters()->withPivot('invitee_reference')->first();
|
||||
$marking = $connection ? $connection->pivot->invitee_reference:'';
|
||||
|
||||
$segmentConstantObject = SegmentConstant::where('reference', SegmentConstants::WAREHOUSE_RATE)->get();
|
||||
$segmentConstant = $segmentConstantObject->isEmpty() ? [] : (array)$segmentConstantObject->first()->value;
|
||||
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'type' => $this->type,
|
||||
@@ -40,7 +43,8 @@ class CompanyModuleResource extends JsonResource
|
||||
'address' => new AddressResource($defaultAddress),
|
||||
'company' => new CompanyResource($this->whenLoaded('company')),
|
||||
'remarks' => RemarkResource::collection($this->remarks),
|
||||
'marking' => $marking
|
||||
'marking' => $marking,
|
||||
'warehouseCharges' => array_key_exists($this->id, $segmentConstant) ? $segmentConstant[$this->id] : null,
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
@@ -16,7 +16,8 @@ class StateResource extends JsonResource
|
||||
public function toArray($request)
|
||||
{
|
||||
|
||||
$segmentConstant = (array) SegmentConstant::where('reference', SegmentConstants::STATE_RATE)->get()->first()->value;
|
||||
$segmentConstantObject = SegmentConstant::where('reference', SegmentConstants::STATE_RATE)->get();
|
||||
$segmentConstant = $segmentConstantObject->isEmpty() ? [] : (array)$segmentConstantObject->first()->value;
|
||||
|
||||
return [
|
||||
'id' => $this->id,
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<div class="font-heading all-caps">MYR {{ data.stateCharges === null ? 0.00 : data.stateCharges.center }}</div>
|
||||
<div class="font-heading all-caps">MYR {{ data.stateCharges === null ? '0.00' : data.stateCharges.center }}</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -39,7 +39,7 @@
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<div class="font-heading all-caps">MYR {{ data.stateCharges === null ? 0.00 : data.stateCharges.outstation }}</div>
|
||||
<div class="font-heading all-caps">MYR {{ data.stateCharges === null ? '0.00' : data.stateCharges.outstation }}</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<div class="font-heading all-caps">MYR 0.00 <i class="fa fa-edit pointer fa-fw m-l-5 requestModal text-primary" data-type="editWarehouseCharges"></i></div>
|
||||
<div class="font-heading all-caps">MYR {{ data.warehouseCharges === null ? '0.00' : data.warehouseCharges.amount }} <i class="fa fa-edit pointer fa-fw m-l-5 requestModal text-primary" data-type="editWarehouseCharges"></i></div>
|
||||
<modal-component class="animate__animated animate__fast animate__fadeIn" styleType="fill-in" type="editWarehouseCharges">
|
||||
<edit-warehouse-charges-form-component :data="data" section="warhouseListSection"></edit-warehouse-charges-form-component>
|
||||
</modal-component>
|
||||
@@ -54,7 +54,7 @@
|
||||
<modal-component class="animate__animated animate__fast animate__fadeIn" type="warehouseRemark">
|
||||
<remark-form-component module_type="CompanyModule" :data="data" section="warhouseListSection"></remark-form-component>
|
||||
</modal-component>
|
||||
<modal-component class="animate__animated animate__fast animate__fadeIn" type="deleteWarehouseRemark">
|
||||
<modal-component class="animate__animated animate__fast animate__fadeIn" type="deleteWarehouseRemark">
|
||||
<delete-remark-form-component :section="section" :data="data.remarks[0]"></delete-remark-form-component>
|
||||
</modal-component>
|
||||
</div>
|
||||
|
||||
+7
-7
@@ -6,10 +6,10 @@
|
||||
<h2 class="text-center">{{data.name}}</h2>
|
||||
</div>
|
||||
</div>
|
||||
<validation-wrapper-component class="m-b-15" :validator="$v.parameters.value.amount">
|
||||
<validation-wrapper-component class="m-b-15" :validator="$v.parameters.rate.amount">
|
||||
<label class="text-primary">Extra Charges (MYR)</label>
|
||||
<div class="controls">
|
||||
<input type="text" class="form-control fs-12" v-model.trim="parameters.value.amount" v-money="money">
|
||||
<input type="text" class="form-control fs-12" v-model.trim="parameters.rate.amount" v-money="money">
|
||||
</div>
|
||||
</validation-wrapper-component>
|
||||
<div class="row m-t-15">
|
||||
@@ -40,17 +40,17 @@
|
||||
data() {
|
||||
return {
|
||||
parameters: {
|
||||
reference: 'WAREHOUSE_CHARGE',
|
||||
value : {
|
||||
id: this.data.id,
|
||||
amount: 0
|
||||
reference: 'WAREHOUSE_RATE',
|
||||
id: this.data.id,
|
||||
rate : {
|
||||
amount: this.data.warehouseCharges == null ? 0 : this.data.warehouseCharges.amount,
|
||||
}
|
||||
}
|
||||
};
|
||||
},
|
||||
validations: {
|
||||
parameters: {
|
||||
value: {
|
||||
rate: {
|
||||
amount: { required }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user