diff --git a/app/Http/Controllers/Api/UsersController.php b/app/Http/Controllers/Api/UsersController.php index 92d763dd23..eded29f82f 100644 --- a/app/Http/Controllers/Api/UsersController.php +++ b/app/Http/Controllers/Api/UsersController.php @@ -66,6 +66,8 @@ class UsersController extends Controller 'users.zip', 'users.remote', 'users.ldap_import', + 'users.start_date', + 'users.end_date', ])->with('manager', 'groups', 'userloc', 'company', 'department', 'assets', 'licenses', 'accessories', 'consumables', 'createdBy',) ->withCount('assets as assets_count', 'licenses as licenses_count', 'accessories as accessories_count', 'consumables as consumables_count'); @@ -146,6 +148,15 @@ class UsersController extends Controller $users = $users->where('remote', '=', $request->input('remote')); } + if ($request->filled('start_date')) { + $users = $users->where('users.start_date', '=', $request->input('start_date')); + } + + if ($request->filled('end_date')) { + $users = $users->where('users.end_date', '=', $request->input('end_date')); + } + + if ($request->filled('assets_count')) { $users->has('assets', '=', $request->input('assets_count')); } @@ -200,7 +211,7 @@ class UsersController extends Controller 'assets', 'accessories', 'consumables', 'licenses', 'groups', 'activated', 'created_at', 'two_factor_enrolled', 'two_factor_optin', 'last_login', 'assets_count', 'licenses_count', 'consumables_count', 'accessories_count', 'phone', 'address', 'city', 'state', - 'country', 'zip', 'id', 'ldap_import', 'remote', + 'country', 'zip', 'id', 'ldap_import', 'remote', 'start_date', 'end_date', ]; $sort = in_array($request->get('sort'), $allowed_columns) ? $request->get('sort') : 'first_name'; diff --git a/app/Http/Controllers/Users/UsersController.php b/app/Http/Controllers/Users/UsersController.php index 8582ace158..52d423036f 100755 --- a/app/Http/Controllers/Users/UsersController.php +++ b/app/Http/Controllers/Users/UsersController.php @@ -119,6 +119,8 @@ class UsersController extends Controller $user->remote = $request->input('remote', 0); $user->website = $request->input('website', null); $user->created_by = Auth::user()->id; + $user->start_date = $request->input('start_date', null); + $user->end_date = $request->input('end_date', null); // Strip out the superuser permission if the user isn't a superadmin $permissions_array = $request->input('permission'); @@ -270,6 +272,8 @@ class UsersController extends Controller $user->zip = $request->input('zip', null); $user->remote = $request->input('remote', 0); $user->website = $request->input('website', null); + $user->start_date = $request->input('start_date', null); + $user->end_date = $request->input('end_date', null); // Update the location of any assets checked out to this user Asset::where('assigned_type', User::class) diff --git a/app/Http/Transformers/UsersTransformer.php b/app/Http/Transformers/UsersTransformer.php index 4cd0159a07..4d291d22d4 100644 --- a/app/Http/Transformers/UsersTransformer.php +++ b/app/Http/Transformers/UsersTransformer.php @@ -30,7 +30,7 @@ class UsersTransformer 'username' => e($user->username), 'remote' => ($user->remote == '1') ? true : false, 'locale' => ($user->locale) ? e($user->locale) : null, - 'employee_num' => e($user->employee_num), + 'employee_num' => ($user->employee_num) ? e($user->employee_num) : null, 'manager' => ($user->manager) ? [ 'id' => (int) $user->manager->id, 'name'=> e($user->manager->first_name).' '.e($user->manager->last_name), @@ -43,7 +43,7 @@ class UsersTransformer 'state' => ($user->state) ? e($user->state) : null, 'country' => ($user->country) ? e($user->country) : null, 'zip' => ($user->zip) ? e($user->zip) : null, - 'email' => e($user->email), + 'email' => ($user->email) ? e($user->email) : null, 'department' => ($user->department) ? [ 'id' => (int) $user->department->id, 'name'=> e($user->department->name), @@ -69,6 +69,8 @@ class UsersTransformer ] : null, 'created_at' => Helper::getFormattedDateObject($user->created_at, 'datetime'), 'updated_at' => Helper::getFormattedDateObject($user->updated_at, 'datetime'), + 'start_date' => Helper::getFormattedDateObject($user->start_date, 'date'), + 'end_date' => Helper::getFormattedDateObject($user->end_date, 'date'), 'last_login' => Helper::getFormattedDateObject($user->last_login, 'datetime'), 'deleted_at' => ($user->deleted_at) ? Helper::getFormattedDateObject($user->deleted_at, 'datetime') : null, ]; diff --git a/app/Models/User.php b/app/Models/User.php index b33997e860..09e3509124 100755 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -59,6 +59,8 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo 'username', 'zip', 'remote', + 'start_date', + 'end_date', ]; protected $casts = [ @@ -68,6 +70,16 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo 'company_id' => 'integer', ]; + + protected $dates = [ + 'created_at', + 'updated_at', + 'deleted_at', + 'start_date', + 'end_date', + ]; + + /** * Model validation rules * @@ -83,6 +95,8 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo 'website' => 'url|nullable|max:191', 'manager_id' => 'nullable|exists:users,id|cant_manage_self', 'location_id' => 'exists:locations,id|nullable', + 'start_date' => 'nullable|date', + 'end_date' => 'nullable|date|after_or_equal:start_date', ]; /** diff --git a/app/Presenters/UserPresenter.php b/app/Presenters/UserPresenter.php index 598f8f677e..c2a003bdc1 100644 --- a/app/Presenters/UserPresenter.php +++ b/app/Presenters/UserPresenter.php @@ -302,6 +302,24 @@ class UserPresenter extends Presenter 'visible' => false, 'formatter' => 'dateDisplayFormatter', ], + [ + 'field' => 'start_date', + 'searchable' => true, + 'sortable' => true, + 'switchable' => true, + 'title' => trans('general.start_date'), + 'visible' => false, + 'formatter' => 'dateDisplayFormatter', + ], + [ + 'field' => 'end_date', + 'searchable' => true, + 'sortable' => true, + 'switchable' => true, + 'title' => trans('general.end_date'), + 'visible' => false, + 'formatter' => 'dateDisplayFormatter', + ], [ 'field' => 'last_login', 'searchable' => false, diff --git a/database/migrations/2022_10_05_163044_add_start_termination_date_to_users.php b/database/migrations/2022_10_05_163044_add_start_termination_date_to_users.php new file mode 100644 index 0000000000..23074b6eaf --- /dev/null +++ b/database/migrations/2022_10_05_163044_add_start_termination_date_to_users.php @@ -0,0 +1,34 @@ +date('start_date')->nullable()->default(null); + $table->date('end_date')->nullable()->default(null); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('users', function (Blueprint $table) { + $table->dropColumn('start_date'); + $table->dropColumn('end_date'); + }); + } +} diff --git a/resources/lang/en/general.php b/resources/lang/en/general.php index 0f82492428..e4b2af1e45 100644 --- a/resources/lang/en/general.php +++ b/resources/lang/en/general.php @@ -378,6 +378,8 @@ return [ 'pie_chart_type' => 'Dashboard Pie Chart Type', 'hello_name' => 'Hello, :name!', 'unaccepted_profile_warning' => 'You have :count items requiring acceptance. Click here to accept or decline them', + 'start_date' => 'Start Date', + 'end_date' => 'End Date', ]; \ No newline at end of file diff --git a/resources/views/partials/forms/edit/datepicker.blade.php b/resources/views/partials/forms/edit/datepicker.blade.php index 74bc96d8db..eab990877d 100644 --- a/resources/views/partials/forms/edit/datepicker.blade.php +++ b/resources/views/partials/forms/edit/datepicker.blade.php @@ -1,9 +1,9 @@