diff --git a/app/Http/Controllers/Api/CompaniesController.php b/app/Http/Controllers/Api/CompaniesController.php index 72297440dd..42b5302448 100644 --- a/app/Http/Controllers/Api/CompaniesController.php +++ b/app/Http/Controllers/Api/CompaniesController.php @@ -29,6 +29,7 @@ class CompaniesController extends Controller 'name', 'phone', 'fax', + 'email', 'created_at', 'updated_at', 'users_count', @@ -49,6 +50,10 @@ class CompaniesController extends Controller $companies->where('name', '=', $request->input('name')); } + if ($request->filled('email')) { + $companies->where('email', '=', $request->input('email')); + } + // Make sure the offset and limit are actually integers and do not exceed system limits $offset = ($request->input('offset') > $companies->count()) ? $companies->count() : abs($request->input('offset')); @@ -168,6 +173,7 @@ class CompaniesController extends Controller $companies = Company::select([ 'companies.id', 'companies.name', + 'companies.email', 'companies.image', ]); diff --git a/app/Http/Controllers/CompaniesController.php b/app/Http/Controllers/CompaniesController.php index b02e3194f9..6c4072362f 100644 --- a/app/Http/Controllers/CompaniesController.php +++ b/app/Http/Controllers/CompaniesController.php @@ -62,6 +62,7 @@ final class CompaniesController extends Controller $company->name = $request->input('name'); $company->phone = $request->input('phone'); $company->fax = $request->input('fax'); + $company->email = $request->input('email'); $company = $request->handleImages($company); @@ -115,6 +116,7 @@ final class CompaniesController extends Controller $company->name = $request->input('name'); $company->phone = $request->input('phone'); $company->fax = $request->input('fax'); + $company->email = $request->input('email'); $company = $request->handleImages($company); @@ -123,8 +125,7 @@ final class CompaniesController extends Controller ->with('success', trans('admin/companies/message.update.success')); } - return redirect()->route('companies.edit', ['company' => $companyId]) - ->with('error', trans('admin/companies/message.update.error')); + return redirect()->back()->withInput()->withErrors($company->getErrors()); } /** diff --git a/app/Http/Transformers/CompaniesTransformer.php b/app/Http/Transformers/CompaniesTransformer.php index 4726630c4e..fe8befc27a 100644 --- a/app/Http/Transformers/CompaniesTransformer.php +++ b/app/Http/Transformers/CompaniesTransformer.php @@ -28,6 +28,7 @@ class CompaniesTransformer 'name' => e($company->name), 'phone' => ($company->phone!='') ? e($company->phone): null, 'fax' => ($company->fax!='') ? e($company->fax): null, + 'email' => ($company->email!='') ? e($company->email): null, 'image' => ($company->image) ? Storage::disk('public')->url('companies/'.e($company->image)) : null, 'created_at' => Helper::getFormattedDateObject($company->created_at, 'datetime'), 'updated_at' => Helper::getFormattedDateObject($company->updated_at, 'datetime'), diff --git a/app/Models/Company.php b/app/Models/Company.php index 10b44077ae..c3a2fdae7f 100644 --- a/app/Models/Company.php +++ b/app/Models/Company.php @@ -24,6 +24,9 @@ final class Company extends SnipeModel // Declare the rules for the model validation protected $rules = [ 'name' => 'required|min:1|max:255|unique:companies,name', + 'fax' => 'min:7|max:35|nullable', + 'phone' => 'min:7|max:35|nullable', + 'email' => 'email|max:150|nullable', ]; protected $presenter = \App\Presenters\CompanyPresenter::class; @@ -45,7 +48,7 @@ final class Company extends SnipeModel * * @var array */ - protected $searchableAttributes = ['name', 'phone', 'fax', 'created_at', 'updated_at']; + protected $searchableAttributes = ['name', 'phone', 'fax', 'email', 'created_at', 'updated_at']; /** * The relations and their attributes that should be included when searching the model. @@ -63,6 +66,7 @@ final class Company extends SnipeModel 'name', 'phone', 'fax', + 'email', ]; private static function isFullMultipleCompanySupportEnabled() diff --git a/app/Presenters/CompanyPresenter.php b/app/Presenters/CompanyPresenter.php index 767def2e36..ec2e7cfc5a 100644 --- a/app/Presenters/CompanyPresenter.php +++ b/app/Presenters/CompanyPresenter.php @@ -45,6 +45,14 @@ class CompanyPresenter extends Presenter 'title' => trans('admin/suppliers/table.fax'), 'visible' => false, 'formatter' => 'phoneFormatter', + ], [ + 'field' => 'email', + 'searchable' => true, + 'sortable' => true, + 'switchable' => true, + 'title' => trans('admin/suppliers/table.email'), + 'visible' => true, + 'formatter' => 'emailFormatter', ], [ 'field' => 'image', 'searchable' => false, diff --git a/database/migrations/2023_08_13_172600_add_email_to_companies.php b/database/migrations/2023_08_13_172600_add_email_to_companies.php new file mode 100644 index 0000000000..a1369d9ade --- /dev/null +++ b/database/migrations/2023_08_13_172600_add_email_to_companies.php @@ -0,0 +1,32 @@ +string('email', 150)->after('fax')->nullable()->default(null); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('companies', function (Blueprint $table) { + $table->dropColumn('email'); + }); + } +} diff --git a/resources/views/companies/edit.blade.php b/resources/views/companies/edit.blade.php index d05a53709b..60d5f74ccb 100644 --- a/resources/views/companies/edit.blade.php +++ b/resources/views/companies/edit.blade.php @@ -11,6 +11,7 @@ @include ('partials.forms.edit.name', ['translated_name' => trans('admin/companies/table.name')]) @include ('partials.forms.edit.phone') @include ('partials.forms.edit.fax') +@include ('partials.forms.edit.email') @include ('partials.forms.edit.image-upload', ['image_path' => app('companies_upload_path')]) @stop