diff --git a/app/Classes/Modules/Companies/ControllersLogic/CreateCompanyContactNumberLogic.php b/app/Classes/Modules/Companies/ControllersLogic/CreateCompanyContactNumberLogic.php new file mode 100644 index 00000000..34d8d235 --- /dev/null +++ b/app/Classes/Modules/Companies/ControllersLogic/CreateCompanyContactNumberLogic.php @@ -0,0 +1,74 @@ + 'Created Company Contact Number', + 'message' => 'You have successfully created the Company Contact Number' + ]; + } + + /** @var FetchesCompany */ + private $fetchesCompany; + + /** @var CreatesContact */ + private $createsContact; + + /** @var CreateContactProcessor */ + private $createContactProcessor; + + /** + * UpdateCompanyControllersLogic constructor. + * @param FetchesCompany $fetchesCompany + * @param CreatesContact $createsContact + * @param CreateContactProcessor $createContactProcessor + */ + public function __construct(FetchesCompany $fetchesCompany, CreatesContact $createsContact, CreateContactProcessor $createContactProcessor) + { + $this->fetchesCompany = $fetchesCompany; + $this->createsContact = $createsContact; + $this->createContactProcessor = $createContactProcessor; + } + + /** + * @param Request $request + * @return JsonResponse + * @throws ErrorException + */ + public function logic(Request $request) : JsonResponse + { + $company = $this->fetchesCompany->execute(['id' => $request->input('companyId')]); + + $contact = new ContactObject( + $company->reference, + $request->input('contactNumber'), + $company->email, + $company->wechat_id + ); + + $this->createContactProcessor->execute($contact, $company); + + return $this->resourceResponse(new CompanyResource($company)); + + } + +} diff --git a/app/Http/Controllers/Companies/CreateCompanyContactNumberController.php b/app/Http/Controllers/Companies/CreateCompanyContactNumberController.php new file mode 100644 index 00000000..a912964f --- /dev/null +++ b/app/Http/Controllers/Companies/CreateCompanyContactNumberController.php @@ -0,0 +1,21 @@ +execute($request); + } +} diff --git a/resources/assets/vue/components/companies/elements/CustomerProfileComponent.vue b/resources/assets/vue/components/companies/elements/CustomerProfileComponent.vue index f99262b9..c93a5e3f 100644 --- a/resources/assets/vue/components/companies/elements/CustomerProfileComponent.vue +++ b/resources/assets/vue/components/companies/elements/CustomerProfileComponent.vue @@ -114,7 +114,8 @@ -
+ +
Contact Number
@@ -122,7 +123,7 @@
- {{item.contact.phone}} + {{item?.contact?.phone || 'N/A'}}
diff --git a/resources/assets/vue/components/orders/forms/ChangeCustomerContactNumberFormComponent.vue b/resources/assets/vue/components/orders/forms/ChangeCustomerContactNumberFormComponent.vue index 842f52dc..04a99884 100644 --- a/resources/assets/vue/components/orders/forms/ChangeCustomerContactNumberFormComponent.vue +++ b/resources/assets/vue/components/orders/forms/ChangeCustomerContactNumberFormComponent.vue @@ -3,7 +3,7 @@
-

Edit Contact Number

+

{{ isEdit ? 'Edit Contact Number' : 'Add Contact Number' }}

@@ -32,12 +32,20 @@ export default { data() { return { - parameters: { + parameters: this.data.contact ? { id: this.data.contact.id, contactNumber: this.data.contact.phone, + } : { + contactNumber: '', + companyId: this.data.id, } }; }, + computed: { + isEdit() { + return !!this.data.contact; + } + }, validations: { parameters: { contactNumber: { @@ -47,10 +55,14 @@ }, methods: { submitForm() { - this.submit(this.route('api.company.update.contactNumber', this.data.id), 'put', this.section, true, true) + const route = this.isEdit + ? this.route('api.company.update.contactNumber', this.data.id) + : this.route('api.company.create.contactNumber'); + + this.submit(route, this.isEdit ? 'put' : 'post', this.section, true, true); } }, mixins: [modalFormHandler] } - \ No newline at end of file + diff --git a/routes/company.php b/routes/company.php index d95a0511..ad0ca9ee 100644 --- a/routes/company.php +++ b/routes/company.php @@ -11,6 +11,7 @@ Route::group(['prefix' => 'company', 'as' => 'company.', 'namespace' => 'Compani Route::put('/name-and-debtor/update/{id}', 'UpdateCompanyNameAndDebtorController@update')->name('update.nameAndDebtor'); Route::post('/update-credit-term/{id}', 'UpdateCompanyCreditTermStatusController@update')->name('update.creditterm.status'); Route::put('/contact-number/update/{id}', 'UpdateCompanyContactNumberController@update')->name('update.contactNumber'); + Route::post('/contact-number/create', 'CreateCompanyContactNumberController@create')->name('create.contactNumber'); Route::put('/type/update/{id}', 'UpdateCompanyTypeController@create')->name('update.type'); Route::post('/team/create', 'AddNewMemberController@create')->name('team.create');