From 51d9a785d764a05d975ef5047e076325ff0de37a Mon Sep 17 00:00:00 2001 From: Dillon Ngo Date: Fri, 20 Jun 2025 14:31:31 +0800 Subject: [PATCH] E-Invoice - Fix minor problems discovered from Shipping Portal --- .../Resources/AddressEInvoiceResource.php | 28 +++++ app/Http/Resources/CompanyResource.php | 2 +- app/Http/Resources/EInvoiceInfoResource.php | 2 +- ...ngeCustomerCompanyDetailsFormComponent.vue | 103 +++++++----------- 4 files changed, 71 insertions(+), 64 deletions(-) create mode 100644 app/Http/Resources/AddressEInvoiceResource.php diff --git a/app/Http/Resources/AddressEInvoiceResource.php b/app/Http/Resources/AddressEInvoiceResource.php new file mode 100644 index 00000000..cbdabe17 --- /dev/null +++ b/app/Http/Resources/AddressEInvoiceResource.php @@ -0,0 +1,28 @@ + $this->id, + 'street_one' => $this->street_one, + 'street_two' => $this->street_two, + 'district' => $this->district, + 'state' => $this->state, + 'post_code' => (int) $this->postcode, + 'country' => $this->country, + 'billing' => (int) $this->billing + ]; + } +} diff --git a/app/Http/Resources/CompanyResource.php b/app/Http/Resources/CompanyResource.php index 4e3ac2f0..741bd604 100644 --- a/app/Http/Resources/CompanyResource.php +++ b/app/Http/Resources/CompanyResource.php @@ -45,7 +45,7 @@ class CompanyResource extends JsonResource 'status' => (int) $this->status, 'contact' => new ContactResource ($this->when($this->has('contacts'), $this->contacts->first())), 'address' => new AddressResource($this->when($this->has('addresses'), $this->addresses->where('billing', true)->first())), - 'address_einvoice' => $this->e_invoice ? new AddressResource($this->when($this->has('addresses'), $this->addresses->where('billing', false)->where('e_invoice', true)->sortByDesc('created_at')->first())) : null, + 'address_einvoice' => $this->e_invoice ? new AddressEInvoiceResource($this->when($this->has('addresses'), $this->addresses->where('billing', false)->where('e_invoice', true)->sortByDesc('created_at')->first())) : null, 'employee' => new UserResource(Auth::user()->type === RoleTypes::USER ? $this->employees()->where('email', '=', Auth::user()->email)->first() : $this->employees()->orderBy('id', 'DESC')->first()), 'identification' => new DocumentResource($this->documents->whereIn('document_type', DocumentType::IDENTIFICATION_DOCUMENTS)->first()), 'bookings' => $this->whenLoaded('bookings', $this->bookings()->orderBy('id', 'DESC')->get(), []), diff --git a/app/Http/Resources/EInvoiceInfoResource.php b/app/Http/Resources/EInvoiceInfoResource.php index 565e86a7..0037edff 100644 --- a/app/Http/Resources/EInvoiceInfoResource.php +++ b/app/Http/Resources/EInvoiceInfoResource.php @@ -20,7 +20,7 @@ class EInvoiceInfoResource extends JsonResource 'street_two' => $this->street_two, 'district' => $this->district, 'state' => $this->state, - 'post_code' => $this->postcode, + 'post_code' => (int) $this->postcode, 'country' => $this->country, 'billing' => (int) $this->billing, 'msic_code' => (int) $this->msic_code, diff --git a/resources/assets/vue/components/companies/forms/ChangeCustomerCompanyDetailsFormComponent.vue b/resources/assets/vue/components/companies/forms/ChangeCustomerCompanyDetailsFormComponent.vue index b27083e8..3f432f7a 100644 --- a/resources/assets/vue/components/companies/forms/ChangeCustomerCompanyDetailsFormComponent.vue +++ b/resources/assets/vue/components/companies/forms/ChangeCustomerCompanyDetailsFormComponent.vue @@ -8,17 +8,17 @@
- + - +
- + - +
@@ -27,58 +27,58 @@ E-Invoice Info
- + - +
- + - +
- + - +
- + - +
- + - +
- + - +
- + - +
@@ -116,28 +116,32 @@ } export default { - // validations: { - // parameters: { - // name: { - // required, - // }, - // debtor: {}, - // tin: {}, - // msic_code: {}, + data() { + return { + params: { + id: this.data.id, + reference: this.data.reference, + type: this.data.type, - // address_id: {}, - // street_one: {}, - // street_two: {}, - // district_id: {}, - // state_id: {}, - // post_code: {}, - // } - // }, + name: this.data.name, + debtor: this.data.debtor, + tin: this.data.tin, + msic_code: this.data.msic_code, + + address_id: this.data.address_einvoice ? this.data.address_einvoice.id : null, + street_one: this.data.address_einvoice ? this.data.address_einvoice.street_one : null, + street_two: this.data.address_einvoice ? this.data.address_einvoice.street_two : null, + district_id: this.data.address_einvoice ? this.data.address_einvoice.district.id : null, + state_id: this.data.address_einvoice ? this.data.address_einvoice.state.id : null, + post_code: this.data.address_einvoice ? this.data.address_einvoice.post_code : null, + } + } + }, validations() { const companyType = this.data.type const isEInvoiceEnabled = this.data.e_invoice !== 0 && this.data.e_invoice !== null; return { - parameters: { + params: { name: { required, }, @@ -171,41 +175,16 @@ street_two: {}, district_id: isEInvoiceEnabled ? { required } : {}, state_id: isEInvoiceEnabled ? { required } : {}, - post_code: isEInvoiceEnabled ? { required, notZero } : {}, - + post_code: isEInvoiceEnabled ? { notZero, fiveDigits } : {}, } } }, - created() { - if (this.data) { - if (this.data.address_einvoice) { - this.parameters.address_id = this.data.address_einvoice.id; - this.parameters.street_one = this.data.address_einvoice.street_one; - this.parameters.street_two = this.data.address_einvoice.street_two; - this.parameters.district_id = this.data.address_einvoice.district.id; - this.parameters.state_id = this.data.address_einvoice.state.id; - this.parameters.post_code = this.data.address_einvoice.post_code; - } - } - }, - // watch: { - // 'data': function(newData) { //cief todo: 90 - // if (newData && newData.address_einvoice) { - // this.parameters.address_id = newData.address_einvoice.id; - // this.parameters.street_one = newData.address_einvoice.street_one; - // this.parameters.street_two = newData.address_einvoice.street_two; - // this.parameters.district_id = newData.address_einvoice.district.id; - // this.parameters.state_id = newData.address_einvoice.state.id; - // this.parameters.post_code = newData.address_einvoice.post_code; - // } - // } - // }, methods: { successHandler(response) { - // window.location.replace(this.route('customers', response.payload.data.reference)); this.closeModal(); }, submitForm() { + this.parameters = this.params; this.submit(this.route('api.company.update.details', this.data.id), 'put', this.section, true, true) } },