From 9d0924c674cc556ac53d2e9b4b5855f372d3cdcb Mon Sep 17 00:00:00 2001 From: edmondlang Date: Wed, 12 Jun 2024 12:02:31 +0800 Subject: [PATCH] address extra fields --- .../ControllersLogic/CreateAddressLogic.php | 11 +++ .../ControllersLogic/UpdateAddressLogic.php | 11 +++ .../DataTransferObjects/RemarkObject.php | 14 +++- .../Remarks/Services/CreatesRemark.php | 1 + .../ValueObjects/Constants/RemarkTypes.php | 4 +- app/Http/Resources/AddressResource.php | 8 ++ app/Models/Address.php | 9 ++ ...06_12_110706_add_type_to_remarks_table.php | 32 +++++++ .../addresses/forms/AddressFormComponent.vue | 83 +++++++++++++------ .../validation/addressFormValidation.js | 4 + 10 files changed, 150 insertions(+), 27 deletions(-) create mode 100644 database/migrations/2024_06_12_110706_add_type_to_remarks_table.php diff --git a/app/Classes/Modules/Addresses/ControllersLogic/CreateAddressLogic.php b/app/Classes/Modules/Addresses/ControllersLogic/CreateAddressLogic.php index f019bab3..dfa00975 100644 --- a/app/Classes/Modules/Addresses/ControllersLogic/CreateAddressLogic.php +++ b/app/Classes/Modules/Addresses/ControllersLogic/CreateAddressLogic.php @@ -15,6 +15,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 ErrorException; @@ -100,6 +101,16 @@ class CreateAddressLogic extends AbstractControllerLogic $this->createRemarkProcessor->execute($address, $remarkObject); } + $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)); } diff --git a/app/Classes/Modules/Addresses/ControllersLogic/UpdateAddressLogic.php b/app/Classes/Modules/Addresses/ControllersLogic/UpdateAddressLogic.php index 94d960f6..8c577a57 100644 --- a/app/Classes/Modules/Addresses/ControllersLogic/UpdateAddressLogic.php +++ b/app/Classes/Modules/Addresses/ControllersLogic/UpdateAddressLogic.php @@ -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 Illuminate\Http\JsonResponse; @@ -102,6 +103,16 @@ class UpdateAddressLogic extends AbstractControllerLogic $this->createRemarkProcessor->execute($address, $remarkObject); } + $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)); } diff --git a/app/Classes/Modules/Remarks/DataTransferObjects/RemarkObject.php b/app/Classes/Modules/Remarks/DataTransferObjects/RemarkObject.php index 44a9507f..5a07c508 100644 --- a/app/Classes/Modules/Remarks/DataTransferObjects/RemarkObject.php +++ b/app/Classes/Modules/Remarks/DataTransferObjects/RemarkObject.php @@ -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; + } + } diff --git a/app/Classes/Modules/Remarks/Services/CreatesRemark.php b/app/Classes/Modules/Remarks/Services/CreatesRemark.php index ac0d57a3..b7bcf388 100644 --- a/app/Classes/Modules/Remarks/Services/CreatesRemark.php +++ b/app/Classes/Modules/Remarks/Services/CreatesRemark.php @@ -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); diff --git a/app/Classes/ValueObjects/Constants/RemarkTypes.php b/app/Classes/ValueObjects/Constants/RemarkTypes.php index 9629e89a..7c233594 100644 --- a/app/Classes/ValueObjects/Constants/RemarkTypes.php +++ b/app/Classes/ValueObjects/Constants/RemarkTypes.php @@ -10,4 +10,6 @@ final class RemarkTypes public const EXTERNAL = 1; -} \ No newline at end of file + public const ADDRESS_EXTRA_COLUMNS = 2; + +} diff --git a/app/Http/Resources/AddressResource.php b/app/Http/Resources/AddressResource.php index 70461cd6..5d2d8b5b 100644 --- a/app/Http/Resources/AddressResource.php +++ b/app/Http/Resources/AddressResource.php @@ -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, diff --git a/app/Models/Address.php b/app/Models/Address.php index 8357940f..9585a134 100644 --- a/app/Models/Address.php +++ b/app/Models/Address.php @@ -4,6 +4,7 @@ namespace App\Models; use App\Classes\General\Interfaces\Contactable; use App\Classes\General\Interfaces\Remarkable; +use App\Classes\ValueObjects\Constants\RemarkTypes; use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\HasOne; @@ -89,4 +90,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); + } } diff --git a/database/migrations/2024_06_12_110706_add_type_to_remarks_table.php b/database/migrations/2024_06_12_110706_add_type_to_remarks_table.php new file mode 100644 index 00000000..76ed8bac --- /dev/null +++ b/database/migrations/2024_06_12_110706_add_type_to_remarks_table.php @@ -0,0 +1,32 @@ +string('type')->nullable(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('remarks', function (Blueprint $table) { + $table->dropColumn('type'); + }); + } +} diff --git a/resources/assets/vue/components/addresses/forms/AddressFormComponent.vue b/resources/assets/vue/components/addresses/forms/AddressFormComponent.vue index 3dc9325c..fff12540 100644 --- a/resources/assets/vue/components/addresses/forms/AddressFormComponent.vue +++ b/resources/assets/vue/components/addresses/forms/AddressFormComponent.vue @@ -3,14 +3,6 @@
-
-
- - - - -
-
@@ -41,6 +33,14 @@
+
+
+ + + + +
+
@@ -59,14 +59,6 @@
-
-
- - - - -
-
@@ -125,14 +117,47 @@
-
-
- - - - -
-
+ + +
+
+ + + + +
+
+
+
+ + + + +
+
+ + + + +
+
+
+
+ + + + +
+
+ + + + +
+
+
+
+
**kindly reply within 2 hours while warehouse contact to arrange for delivery, otherwise, reschedule of delivery date will apply
@@ -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: { diff --git a/resources/assets/vue/general/mixins/addresses/validation/addressFormValidation.js b/resources/assets/vue/general/mixins/addresses/validation/addressFormValidation.js index 4552a9d5..ea98bf75 100644 --- a/resources/assets/vue/general/mixins/addresses/validation/addressFormValidation.js +++ b/resources/assets/vue/general/mixins/addresses/validation/addressFormValidation.js @@ -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]