Merge branch 'address-extra-fields' of https://gitlab.com/CIEFWorldwideSdnBhd/shipping-portal into development

# Conflicts:
#	app/Classes/Modules/Addresses/ControllersLogic/CreateAddressLogic.php
#	app/Classes/Modules/Addresses/ControllersLogic/UpdateAddressLogic.php
#	app/Models/Address.php
This commit is contained in:
edmondlang
2024-06-12 12:06:00 +08:00
10 changed files with 148 additions and 27 deletions
@@ -18,6 +18,7 @@ use App\Classes\Modules\Contacts\Processors\CreateContactProcessor;
use App\Classes\Modules\Remarks\DataTransferObjects\RemarkObject;
use App\Classes\Modules\Remarks\Processors\CreateRemarkProcessor;
use App\Classes\ValueObjects\Constants\ApprovalStatus;
use App\Classes\ValueObjects\Constants\RemarkTypes;
use App\Http\Resources\AddressResource;
use App\Models\Address;
use App\Transformers\AddressTransformer;
@@ -110,6 +111,15 @@ class CreateAddressLogic extends AbstractControllerLogic
->parseIncludes('remark')
->respond(200, [], JSON_PRETTY_PRINT);*/
$addressExtraFields = [
'property_type' => $request->input('property_type'),
'tools_required_unload' => $request->input('tools_required_unload'),
'pickup_time_from' => $request->input('pickup_time_from'),
'pickup_time_to' => $request->input('pickup_time_to'),
];
$addressExtraFieldsObject = new RemarkObject(json_encode($addressExtraFields), Auth()->user()->id, RemarkTypes::ADDRESS_EXTRA_COLUMNS);
$this->createRemarkProcessor->execute($address, $addressExtraFieldsObject);
return $this->resourceResponse(new AddressResource($address));
@@ -15,6 +15,7 @@ use App\Classes\Modules\Remarks\DataTransferObjects\RemarkObject;
use App\Classes\Modules\Remarks\Processors\CreateRemarkProcessor;
use App\Classes\ValueObjects\Constants\AddressType;
use App\Classes\ValueObjects\Constants\ApprovalStatus;
use App\Classes\ValueObjects\Constants\RemarkTypes;
use App\Http\Resources\AddressResource;
use App\Models\Address;
use App\Transformers\AddressTransformer;
@@ -110,6 +111,15 @@ class UpdateAddressLogic extends AbstractControllerLogic
->item($address, new AddressTransformer())
->parseIncludes('remark')
->respond(200, [], JSON_PRETTY_PRINT);*/
$addressExtraFields = [
'property_type' => $request->input('property_type'),
'tools_required_unload' => $request->input('tools_required_unload'),
'pickup_time_from' => $request->input('pickup_time_from'),
'pickup_time_to' => $request->input('pickup_time_to'),
];
$addressExtraFieldsObject = new RemarkObject(json_encode($addressExtraFields), Auth()->user()->id, RemarkTypes::ADDRESS_EXTRA_COLUMNS);
$this->createRemarkProcessor->execute($address, $addressExtraFieldsObject);
return $this->resourceResponse(new AddressResource($address));
@@ -13,10 +13,14 @@ class RemarkObject implements DataTransferObject
/** @var string*/
private $content;
public function __construct(string $content, int $commenterID)
/** @var int|null */
private $type;
public function __construct(string $content, int $commenterID, int $type = null)
{
$this->commenterID = $commenterID;
$this->content = $content;
$this->type = $type;
}
/**
@@ -35,4 +39,12 @@ class RemarkObject implements DataTransferObject
return $this->content;
}
/**
* @return int|null
*/
public function getType(): ?int
{
return $this->type;
}
}
@@ -24,6 +24,7 @@ class CreatesRemark extends AbstractUpdateRelationshipRecord
$model->commenter_id = $object->getCommenterId();
$model->content = $object->getContent();
$model->type = $object->getType();
return $this->handler($remarkable->remarks(), $model);
@@ -10,4 +10,6 @@ final class RemarkTypes
public const EXTERNAL = 1;
}
public const ADDRESS_EXTRA_COLUMNS = 2;
}
+8
View File
@@ -27,6 +27,9 @@ class AddressResource extends JsonResource
$outstationPostcodeConstant = $outstationPostcodeConstantObject->isEmpty() ? [] : (array)$outstationPostcodeConstantObject->first()->value;
in_array((String)$this->postcode, $outstationPostcodeConstant) ? $postcodeArea = 'OUTSTATION_POSTCODE' : null;
$extrafields = json_decode($this->addressExtraFields->first());
$extrafields = $extrafields ? (isset($extrafields->content) ? json_decode($extrafields->content) : null) : null;
return [
'id' => $this->id,
'reference' => $this->reference,
@@ -43,6 +46,11 @@ class AddressResource extends JsonResource
'contact' => new ContactResource($this->contacts->first()),
'remark' => new RemarkResource($this->remarks->first()),
'type' => $this->type,
'extrafields' => $extrafields,
'property_type' => $extrafields ? $extrafields->property_type : null,
'tools_required_unload' => $extrafields ? $extrafields->tools_required_unload : null,
'pickup_time_from' => $extrafields ? $extrafields->pickup_time_from : null,
'pickup_time_to' => $extrafields ? $extrafields->pickup_time_to : null,
$this->mergeWhen($this->relationLoaded('owner'), [
'owner' => $this->when($this->owner instanceof Order, [
'reference' => $this->owner->reference,
+9
View File
@@ -5,6 +5,7 @@ namespace App\Models;
use App\Classes\General\Interfaces\Contactable;
use App\Classes\General\Interfaces\Remarkable;
use Barryvdh\LaravelIdeHelper\Eloquent;
use App\Classes\ValueObjects\Constants\RemarkTypes;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Model;
@@ -142,4 +143,12 @@ class Address extends AbstractModel implements Contactable, Remarkable
{
return $this->morphMany(Remark::class, 'owner');
}
/**
* @return MorphMany
*/
public function addressExtraFields(): MorphMany
{
return $this->morphMany(Remark::class, 'owner')->where('type', RemarkTypes::ADDRESS_EXTRA_COLUMNS);
}
}
@@ -0,0 +1,32 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class AddTypeToRemarksTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('remarks', function (Blueprint $table) {
$table->string('type')->nullable();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('remarks', function (Blueprint $table) {
$table->dropColumn('type');
});
}
}
@@ -3,14 +3,6 @@
<div class="col">
<div class="row" v-if="![7,8].includes($store.getters.getCompanyModuleType)">
<div class="col">
<div class="row m-b-15">
<div class="col">
<validation-wrapper-component :validator="$v.parameters.reference">
<label>Address Reference/Label</label>
<input class="form-control" name="reference" v-model="parameters.reference">
</validation-wrapper-component>
</div>
</div>
<div class="row m-b-15">
<div class="col">
<validation-wrapper-component :validator="$v.parameters.street_one">
@@ -41,6 +33,14 @@
</validation-wrapper-component>
</div>
</div>
<div class="row m-b-15">
<div class="col">
<validation-wrapper-component :validator="$v.parameters.reference">
<label>Address Name / Label</label>
<input class="form-control" name="reference" v-model="parameters.reference" placeholder="E.g. Home Address">
</validation-wrapper-component>
</div>
</div>
<div class="row">
<div class="col">
<div class="row">
@@ -59,14 +59,6 @@
</validation-wrapper-component>
</div>
</div>
<div class="row m-b-15">
<div class="col">
<validation-wrapper-component :validator="$v.parameters.remark">
<label>Delivery Remark</label>
<input class="form-control" name="remark" v-model="parameters.remark">
</validation-wrapper-component>
</div>
</div>
</div>
</div>
</div>
@@ -125,14 +117,47 @@
</validation-wrapper-component>
</div>
</div>
<div class="row m-b-15">
<div class="col">
<validation-wrapper-component :validator="$v.parameters.remark">
<label>Remark</label>
<input class="form-control" name="remark" v-model="parameters.remark">
</validation-wrapper-component>
</div>
</div>
</div>
</div>
<div class="row m-b-15">
<div class="col">
<validation-wrapper-component :validator="$v.parameters.remark">
<label>Delivery Remark</label>
<input class="form-control" name="remark" v-model="parameters.remark">
</validation-wrapper-component>
</div>
</div>
<div class="row m-b-15">
<div class="col-12 col-md pr-md-1 pb-3 pb-md-0">
<validation-wrapper-component :validator="$v.parameters.pickup_time_from">
<label>收货时间从 Available Hours From</label>
<input type="time" class="form-control" name="pickup_time" v-model="parameters.pickup_time_from">
</validation-wrapper-component>
</div>
<div class="col-12 col-md pl-md-1">
<validation-wrapper-component :validator="$v.parameters.pickup_time_to">
<label>最晚收货时间 Available Hours To</label>
<input type="time" class="form-control" name="latest_pickup_time" v-model="parameters.pickup_time_to">
</validation-wrapper-component>
</div>
</div>
<div class="row m-b-15">
<div class="col-12 col-md pr-md-1 pb-3 pb-md-0">
<validation-wrapper-component selectable :validator="$v.parameters.property_type">
<label>房型 Receiver's property type</label>
<select-component :options="['住家Landed house', '公寓Condominium (Drop on lobby only)', '工厂Factory', '店面Shop', '商场Shopping Mall (Drop on loading bay only)', 'Others']" v-model="parameters.property_type"></select-component>
</validation-wrapper-component>
</div>
<div class="col-12 col-md pl-md-1 pb-3 pb-md-0">
<validation-wrapper-component selectable :validator="$v.parameters.tools_required_unload">
<label>卸货工具 Tools require to unload goods</label>
<select-component :options="['Manpower', 'Forklift', 'None of above']" v-model="parameters.tools_required_unload"></select-component>
</validation-wrapper-component>
</div>
</div>
<div class="row justify-content-center allign-items-center">
<div class="col-12 col-sm-7">
<h6 class="text-center fs-12 text-danger">**kindly reply within 2 hours while warehouse contact to arrange for delivery, otherwise, reschedule of delivery date will apply</h6>
</div>
</div>
<div class="row">
@@ -154,7 +179,7 @@
props: {
id: {
type: Number,
required: true
// required: true
},
type: {
type: Number,
@@ -174,6 +199,10 @@
remark: '',
phone: '',
person_in_charge: '',
property_type: '',
tools_required_unload: '',
pickup_time_from: '',
pickup_time_to: '',
}
}
@@ -189,6 +218,10 @@
this.parameters.phone = this.data.contact ? this.data.contact.phone : '';
this.parameters.person_in_charge = this.data.contact ? this.data.contact.reference : '';
this.parameters.remark = this.data.remark ? this.data.remark.content : '';
this.parameters.property_type = this.data.property_type ? this.data.property_type : '';
this.parameters.tools_required_unload = this.data.tools_required_unload ? this.data.tools_required_unload : '';
this.parameters.pickup_time_from = this.data.pickup_time_from ? this.data.pickup_time_from : '';
this.parameters.pickup_time_to = this.data.pickup_time_to ? this.data.pickup_time_to : '';
}
},
watch: {
@@ -19,6 +19,10 @@ export default {
remark: {},
phone: {required, numeric},
person_in_charge: { required },
property_type: { required },
tools_required_unload: { required },
pickup_time_from: { required },
pickup_time_to: { required },
}
},
mixins: [addressFormHandler]