diff --git a/app/Classes/Modules/Companies/ControllersLogic/ListBusinessTypesLogic.php b/app/Classes/Modules/Companies/ControllersLogic/ListBusinessTypesLogic.php new file mode 100644 index 00000000..fc39d1ec --- /dev/null +++ b/app/Classes/Modules/Companies/ControllersLogic/ListBusinessTypesLogic.php @@ -0,0 +1,44 @@ + 'Retrieved Business Types', + 'message' => 'You have successfully retrieved a list of Business Types' + ]; + } + + + /** + * @param Request $request + * @return JsonResponse + * @throws \App\Classes\Exceptions\AccessForbiddenException + * @throws \App\Classes\Exceptions\MalformedRequestException + * @throws \App\Classes\Exceptions\RequestValidationException + */ + public function logic(Request $request) : JsonResponse + { + $businessTypes = []; + + foreach(BusinessType::BUSINESS_TYPE_LIST as $key => $val) { + $type = (object)["id" => $key, "type" => $val]; + array_push($businessTypes, $type); + } + + return $this->collectionResponse(BusinessTypeResource::collection($businessTypes)); + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Companies/ControllersLogic/UpdateCompanyProfileLogic.php b/app/Classes/Modules/Companies/ControllersLogic/UpdateCompanyProfileLogic.php new file mode 100644 index 00000000..ddc4fd08 --- /dev/null +++ b/app/Classes/Modules/Companies/ControllersLogic/UpdateCompanyProfileLogic.php @@ -0,0 +1,65 @@ + 'Update Company Account Profile', + 'message' => 'You have successfully updated the Company Account Profile' + ]; + } + + /** @var FetchesCompany */ + private $fetchesCompany; + + /** @var UpdatesCompanyProfile */ + private $updatesCompanyProfile; + + /** + * UpdateCompanyProfileLogic constructor. + * @param FetchesCompany $fetchesCompany + * @param UpdatesCompanyProfile $updatesCompanyProfile + */ + public function __construct( + FetchesCompany $fetchesCompany, + UpdatesCompanyProfile $updatesCompanyProfile + ) + { + $this->fetchesCompany = $fetchesCompany; + $this->updatesCompanyProfile = $updatesCompanyProfile; + } + + /** + * @param Request $request + * @return JsonResponse + * @throws \App\Classes\Exceptions\AccessForbiddenException + * @throws \App\Classes\Exceptions\MalformedRequestException + * @throws \App\Classes\Exceptions\RequestValidationException + */ + public function logic(Request $request) : JsonResponse + { + $object = new CompanyProfileObject($request->input('email'), $request->input('phone'), $request->input('business_type')); + + $company = $this->fetchesCompany->execute(['id' => $request->route('id')]); + + $company_query = $this->updatesCompanyProfile->execute($company, $object); + + return $this->resourceResponse(new CompanyResource($company_query)); + + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Companies/DataTransferObjects/CompanyProfileObject.php b/app/Classes/Modules/Companies/DataTransferObjects/CompanyProfileObject.php new file mode 100644 index 00000000..99c57f93 --- /dev/null +++ b/app/Classes/Modules/Companies/DataTransferObjects/CompanyProfileObject.php @@ -0,0 +1,55 @@ +email = $email; + $this->phone = $phone; + $this->businessType = $businessType; + } + + /** + * @return string + */ + public function getEmail(): string + { + return $this->email; + } + + /** + * @return string + */ + public function getPhone(): string + { + return $this->phone; + } + + /** + * @return int + */ + public function getBusinessType(): int + { + return $this->businessType; + } +} diff --git a/app/Classes/Modules/Companies/Services/UpdatesCompanyProfile.php b/app/Classes/Modules/Companies/Services/UpdatesCompanyProfile.php new file mode 100644 index 00000000..498f859d --- /dev/null +++ b/app/Classes/Modules/Companies/Services/UpdatesCompanyProfile.php @@ -0,0 +1,32 @@ +business_type = $object->getBusinessType(); + + if ($model->contacts) { + $contact = $model->contacts()->first(); + $contact->email = $object->getEmail(); + $contact->phone = $object->getPhone(); + $contact->save(); + } + + return $this->handler($model); + + } +} \ No newline at end of file diff --git a/app/Classes/ValueObjects/Constants/BusinessType.php b/app/Classes/ValueObjects/Constants/BusinessType.php index 8cd4aa7c..69ea3202 100644 --- a/app/Classes/ValueObjects/Constants/BusinessType.php +++ b/app/Classes/ValueObjects/Constants/BusinessType.php @@ -13,10 +13,10 @@ final class BusinessType { public const TRANSFER_AGENT = 4; public const BUSINESS_TYPE_LIST = [ - self::FREIGHT_FORWARDER => 'FREIGHT_FORWARDER', - self::IMPORTER => 'IMPORTER', - self::CURRENCY_VENDOR => 'CURRENCY_VENDOR', - self::TRANSFER_AGENT => 'TRANSFER_AGENT', + self::FREIGHT_FORWARDER => 'Freight Forwarder', + self::IMPORTER => 'Importer', + self::CURRENCY_VENDOR => 'Currency Vendor', + self::TRANSFER_AGENT => 'Transfer Agent', ]; } diff --git a/app/Http/Controllers/Companies/ListBusinessTypesController.php b/app/Http/Controllers/Companies/ListBusinessTypesController.php new file mode 100644 index 00000000..ecf1f0c9 --- /dev/null +++ b/app/Http/Controllers/Companies/ListBusinessTypesController.php @@ -0,0 +1,20 @@ +execute($request); + } + +} \ No newline at end of file diff --git a/app/Http/Controllers/Companies/UpdateCompanyProfileController.php b/app/Http/Controllers/Companies/UpdateCompanyProfileController.php new file mode 100644 index 00000000..0ec9a688 --- /dev/null +++ b/app/Http/Controllers/Companies/UpdateCompanyProfileController.php @@ -0,0 +1,21 @@ +execute($request); + } + +} \ No newline at end of file diff --git a/app/Http/Resources/BusinessTypeResource.php b/app/Http/Resources/BusinessTypeResource.php new file mode 100644 index 00000000..18e73753 --- /dev/null +++ b/app/Http/Resources/BusinessTypeResource.php @@ -0,0 +1,22 @@ + $this->id, + 'type' => $this->type, + ]; + } +} diff --git a/resources/assets/vue/components/companies/forms/EditCustomerProfileInfoFormComponent.vue b/resources/assets/vue/components/companies/forms/EditCustomerProfileInfoFormComponent.vue index 21eb294a..11447285 100644 --- a/resources/assets/vue/components/companies/forms/EditCustomerProfileInfoFormComponent.vue +++ b/resources/assets/vue/components/companies/forms/EditCustomerProfileInfoFormComponent.vue @@ -10,9 +10,9 @@
- + - +
@@ -24,14 +24,6 @@ -
-
- - - - -
-
@@ -66,8 +58,7 @@ created() { if(this.data){ this.parameters.business_type = this.data.business_type; - this.parameters.email = this.data.employee ? this.data.employee.email : ""; - this.parameters.contact_email = this.data.contact ? this.data.contact.email : ""; + this.parameters.email = this.data.contact ? this.data.contact.email : ""; this.parameters.phone = this.data.contact ? this.data.contact.phone : ""; } }, @@ -76,7 +67,6 @@ parameters: { business_type: "", email: "", - contact_email: "", phone: "", } } @@ -89,9 +79,6 @@ email: { required, }, - contact_email: { - required, - }, phone: { required, }, @@ -99,7 +86,7 @@ }, methods: { submitForm(){ - this.submit(route('api.company.update', this.data.id), 'put', '', false, false); + this.submit(route('api.company.profile.update', this.data.id), 'put', '', false, false); }, }, } diff --git a/routes/company.php b/routes/company.php index 6571daa4..1be568e8 100644 --- a/routes/company.php +++ b/routes/company.php @@ -7,10 +7,13 @@ Route::group(['prefix' => 'company', 'as' => 'company.', 'namespace' => 'Compani Route::get('/list', 'ListCompaniesController@list')->name('list'); Route::post('/create', 'CreateCompanyController@create')->name('create'); Route::put('/update/{id}', 'UpdateCompanyController@update')->name('update'); + Route::put('/update/{id}/profile', 'UpdateCompanyProfileController@update')->name('profile.update'); Route::put('update/{id}/status', 'UpdateCompanyStatusController@update')->name('status.update'); Route::delete('/delete/{id}', 'DeleteCompanyController@destroy')->name('delete'); Route::put('/name-and-debtor/update/{id}', 'UpdateCompanyNameAndDebtorController@update')->name('update.nameAndDebtor'); + Route::get('/business_type/list', 'ListBusinessTypesController@list')->name('business_type.list'); + Route::put('/update/debtor/{id}', 'UpdateCompanyDebtorController@update')->name('delete'); Route::post('/team/create', 'AddNewMemberController@create')->name('team.create');