From 57c2df1c8718855e11bf4f158a3ec4931224cb80 Mon Sep 17 00:00:00 2001 From: jacobsen9026 Date: Tue, 5 Nov 2019 17:19:07 -0500 Subject: [PATCH 01/25] Update AssetsController.php Only update location if asset is not checked out already. --- app/Http/Controllers/Assets/AssetsController.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/Assets/AssetsController.php b/app/Http/Controllers/Assets/AssetsController.php index 6025167a1547..857b42cde732 100755 --- a/app/Http/Controllers/Assets/AssetsController.php +++ b/app/Http/Controllers/Assets/AssetsController.php @@ -759,7 +759,9 @@ public function auditStore(Request $request, $id) // Check to see if they checked the box to update the physical location, // not just note it in the audit notes - if ($request->input('update_location')=='1') { + if ($request->input('update_location')=='1' && is_null($target = $asset->assignedTo)) { + $asset->location_id = $request->input('location_id'); + } \Log::debug('update location in audit'); $asset->location_id = $request->input('location_id'); } From 030ae4eef6002ae5a183af156abf257557632396 Mon Sep 17 00:00:00 2001 From: jacobsen9026 Date: Tue, 5 Nov 2019 17:19:55 -0500 Subject: [PATCH 02/25] Update AssetsController.php Only update location on audit if asset is not already checked out. --- app/Http/Controllers/Api/AssetsController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Controllers/Api/AssetsController.php b/app/Http/Controllers/Api/AssetsController.php index a07f18662013..ecf59dc16a8a 100644 --- a/app/Http/Controllers/Api/AssetsController.php +++ b/app/Http/Controllers/Api/AssetsController.php @@ -782,7 +782,7 @@ public function audit(Request $request) { // Check to see if they checked the box to update the physical location, // not just note it in the audit notes - if ($request->input('update_location')=='1') { + if ($request->input('update_location')=='1' && is_null($target = $asset->assignedTo)) { $asset->location_id = $request->input('location_id'); } From 478628100e8bbdbffad9c5a2b6d8e7410aabfc0b Mon Sep 17 00:00:00 2001 From: jacobsen9026 Date: Fri, 8 Nov 2019 08:38:04 -0500 Subject: [PATCH 03/25] Add Checkout on Audit Setting Save checkout on audit setting when saving. Default value 0. The database needs the checkout_on_audit column added to the Settings table during install. I am unsure how. --- app/Http/Controllers/SettingsController.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/Http/Controllers/SettingsController.php b/app/Http/Controllers/SettingsController.php index 0af5eb7425cb..4479ddfaf5e2 100755 --- a/app/Http/Controllers/SettingsController.php +++ b/app/Http/Controllers/SettingsController.php @@ -327,6 +327,7 @@ public function postSettings(Request $request) $setting->full_multiple_companies_support = $request->input('full_multiple_companies_support', '0'); $setting->unique_serial = $request->input('unique_serial', '0'); + $setting->checkout_on_audit = $request->input('checkout_on_audit','0'); $setting->show_images_in_email = $request->input('show_images_in_email', '0'); $setting->show_archived_in_list = $request->input('show_archived_in_list', '0'); $setting->dashboard_message = $request->input('dashboard_message'); From 2b8dce3e4930395745a22c43a002d17e9d80ebf7 Mon Sep 17 00:00:00 2001 From: jacobsen9026 Date: Fri, 8 Nov 2019 08:39:40 -0500 Subject: [PATCH 04/25] Add Checkout on Audit Add Checkout on Audit option to general settings page --- resources/views/settings/general.blade.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/resources/views/settings/general.blade.php b/resources/views/settings/general.blade.php index 7fb6a59767d3..5a825910c736 100644 --- a/resources/views/settings/general.blade.php +++ b/resources/views/settings/general.blade.php @@ -256,6 +256,20 @@ + + + +
+
+ {{ Form::label('checkout_on_audit', trans('admin/settings/general.checkout_on_audit')) }} +
+
+ {{ Form::checkbox('checkout_on_audit', '1', Input::old('checkout_on_audit', $setting->checkout_on_audit),array('class' => 'minimal')) }} + {{ trans('general.yes') }} + {!! $errors->first('checkout_on_audit', ':message') !!} +
+
+
From f7101ee9133d9b3a27c824b967724ab3c27b7518 Mon Sep 17 00:00:00 2001 From: jacobsen9026 Date: Fri, 8 Nov 2019 08:41:23 -0500 Subject: [PATCH 05/25] Add checkout_on_audit lang English lang reference, other languages would need translation. --- resources/lang/en/general.php | 1 + 1 file changed, 1 insertion(+) diff --git a/resources/lang/en/general.php b/resources/lang/en/general.php index 0399a53dab08..9b8bfbfaad0d 100644 --- a/resources/lang/en/general.php +++ b/resources/lang/en/general.php @@ -41,6 +41,7 @@ 'checkin_from' => 'Checkin from', 'checkout' => 'Checkout', 'checkouts_count' => 'Checkouts', + 'checkout_on_audit' => 'Checkout on Audit', 'checkins_count' => 'Checkins', 'user_requests_count' => 'Requests', 'city' => 'City', From 778a317e0e6553333e0f59ab76cb4c2e946fae19 Mon Sep 17 00:00:00 2001 From: jacobsen9026 Date: Fri, 8 Nov 2019 09:41:59 -0500 Subject: [PATCH 06/25] Add Checkout On Audit setting functionality Added check to checkout if asset is unassigned --- app/Http/Controllers/Api/AssetsController.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/Api/AssetsController.php b/app/Http/Controllers/Api/AssetsController.php index ecf59dc16a8a..0fed8813c3b6 100644 --- a/app/Http/Controllers/Api/AssetsController.php +++ b/app/Http/Controllers/Api/AssetsController.php @@ -782,7 +782,12 @@ public function audit(Request $request) { // Check to see if they checked the box to update the physical location, // not just note it in the audit notes - if ($request->input('update_location')=='1' && is_null($target = $asset->assignedTo)) { + $target = Location::find($request->input('location_id')); + if ($settings->checkout_on_audit) { + if ((Location::find($asset->assignedTo['id']) != $target && $asset->assignedType() == Asset::LOCATION) || $asset->assignedType() == Asset::LOCATION || is_null($asset->assignedTo)) { + $asset->checkOut($target, Auth::user(), date('Y-m-d H:i:s'), '', 'Checked out on asset audit'); + } + }else if ($request->input('update_location')=='1' && is_null($asset->assignedTo)) { $asset->location_id = $request->input('location_id'); } From 38d2fa27dc8874182f522a69b0fffbb6168ee6a8 Mon Sep 17 00:00:00 2001 From: jacobsen9026 Date: Fri, 8 Nov 2019 09:43:53 -0500 Subject: [PATCH 07/25] Add checkout on audit setting functionality Add check from settings to checkout on audit if item is checked out to location or is not checked out at all. --- app/Http/Controllers/Assets/AssetsController.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/Assets/AssetsController.php b/app/Http/Controllers/Assets/AssetsController.php index 857b42cde732..ef0fbe75cb43 100755 --- a/app/Http/Controllers/Assets/AssetsController.php +++ b/app/Http/Controllers/Assets/AssetsController.php @@ -759,10 +759,14 @@ public function auditStore(Request $request, $id) // Check to see if they checked the box to update the physical location, // not just note it in the audit notes - if ($request->input('update_location')=='1' && is_null($target = $asset->assignedTo)) { - $asset->location_id = $request->input('location_id'); + $target = Location::find($request->input('location_id')); + if ($settings->checkout_on_audit) { + if ((Location::find($asset->assignedTo['id']) != $target && $asset->assignedType() == Asset::LOCATION) || $asset->assignedType() == Asset::LOCATION || is_null($asset->assignedTo)) { + $asset->checkOut($target, Auth::user(), date('Y-m-d H:i:s'), '', 'Checked out on asset audit'); } - \Log::debug('update location in audit'); + }else if ($request->input('update_location')=='1' && is_null($asset->assignedTo)) { + $asset->location_id = $request->input('location_id'); + \Log::debug('update location in audit'); $asset->location_id = $request->input('location_id'); } From 35524e8c587eb28bee0a0196268586695acdcdda Mon Sep 17 00:00:00 2001 From: jacobsen9026 Date: Fri, 8 Nov 2019 09:59:06 -0500 Subject: [PATCH 08/25] Forgot to provide settings object Added call to load settings --- app/Http/Controllers/Assets/AssetsController.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/Http/Controllers/Assets/AssetsController.php b/app/Http/Controllers/Assets/AssetsController.php index ef0fbe75cb43..a24a18182638 100755 --- a/app/Http/Controllers/Assets/AssetsController.php +++ b/app/Http/Controllers/Assets/AssetsController.php @@ -736,6 +736,7 @@ public function overdueForAudit() public function auditStore(Request $request, $id) { + $settings = Setting::getSettings(); $this->authorize('audit', Asset::class); $rules = array( From f2a7215bf49d0a3ab52fe81a58ebf7ac400b24df Mon Sep 17 00:00:00 2001 From: jacobsen9026 Date: Fri, 8 Nov 2019 09:59:51 -0500 Subject: [PATCH 09/25] Provide settings object for bulk audit --- app/Http/Controllers/Api/AssetsController.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/Http/Controllers/Api/AssetsController.php b/app/Http/Controllers/Api/AssetsController.php index 0fed8813c3b6..958d0d9db11c 100644 --- a/app/Http/Controllers/Api/AssetsController.php +++ b/app/Http/Controllers/Api/AssetsController.php @@ -753,6 +753,7 @@ public function checkin(Request $request, $asset_id) public function audit(Request $request) { + $settings = Setting::getSettings(); $this->authorize('audit', Asset::class); $rules = array( 'asset_tag' => 'required', From e5dfe8efa53acf192ffb70829481b3b036a38a7e Mon Sep 17 00:00:00 2001 From: jacobsen9026 Date: Fri, 8 Nov 2019 11:07:33 -0500 Subject: [PATCH 10/25] Fixed checkout on audit logic Fix for checking out of assets that are already checked out to audited location --- app/Http/Controllers/Assets/AssetsController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Controllers/Assets/AssetsController.php b/app/Http/Controllers/Assets/AssetsController.php index a24a18182638..de8c831f4845 100755 --- a/app/Http/Controllers/Assets/AssetsController.php +++ b/app/Http/Controllers/Assets/AssetsController.php @@ -762,7 +762,7 @@ public function auditStore(Request $request, $id) // not just note it in the audit notes $target = Location::find($request->input('location_id')); if ($settings->checkout_on_audit) { - if ((Location::find($asset->assignedTo['id']) != $target && $asset->assignedType() == Asset::LOCATION) || $asset->assignedType() == Asset::LOCATION || is_null($asset->assignedTo)) { + if ((Location::find($asset->assignedTo['id']) != $target && $asset->assignedType() == Asset::LOCATION) || is_null($asset->assignedTo)) { $asset->checkOut($target, Auth::user(), date('Y-m-d H:i:s'), '', 'Checked out on asset audit'); } }else if ($request->input('update_location')=='1' && is_null($asset->assignedTo)) { From 7536ea487336a946a296fba5fa97d1acda239ef3 Mon Sep 17 00:00:00 2001 From: jacobsen9026 Date: Fri, 8 Nov 2019 11:08:29 -0500 Subject: [PATCH 11/25] Fix checkout on audit logic Fix for checking out of assets that are already checked out to audited location --- app/Http/Controllers/Api/AssetsController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Controllers/Api/AssetsController.php b/app/Http/Controllers/Api/AssetsController.php index 958d0d9db11c..f75adcb454be 100644 --- a/app/Http/Controllers/Api/AssetsController.php +++ b/app/Http/Controllers/Api/AssetsController.php @@ -785,7 +785,7 @@ public function audit(Request $request) { // not just note it in the audit notes $target = Location::find($request->input('location_id')); if ($settings->checkout_on_audit) { - if ((Location::find($asset->assignedTo['id']) != $target && $asset->assignedType() == Asset::LOCATION) || $asset->assignedType() == Asset::LOCATION || is_null($asset->assignedTo)) { + if ((Location::find($asset->assignedTo['id']) != $target && $asset->assignedType() == Asset::LOCATION) || is_null($asset->assignedTo)) { $asset->checkOut($target, Auth::user(), date('Y-m-d H:i:s'), '', 'Checked out on asset audit'); } }else if ($request->input('update_location')=='1' && is_null($asset->assignedTo)) { From 1cc9108285d969698a8e64b8c8928e37778ccb2a Mon Sep 17 00:00:00 2001 From: jacobsen9026 Date: Sat, 9 Nov 2019 11:31:51 -0500 Subject: [PATCH 12/25] Fix for Issue 7437 Fix for can't save when require accept signature not checked. https://github.com/snipe/snipe-it/issues/7437 --- app/Http/Controllers/SettingsController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Controllers/SettingsController.php b/app/Http/Controllers/SettingsController.php index 4479ddfaf5e2..6ff6d4c26e04 100755 --- a/app/Http/Controllers/SettingsController.php +++ b/app/Http/Controllers/SettingsController.php @@ -334,7 +334,7 @@ public function postSettings(Request $request) $setting->email_domain = $request->input('email_domain'); $setting->email_format = $request->input('email_format'); $setting->username_format = $request->input('username_format'); - $setting->require_accept_signature = $request->input('require_accept_signature'); + $setting->require_accept_signature = $request->input('require_accept_signature', '0'); if (! config('app.lock_passwords')) { $setting->login_note = $request->input('login_note'); } From f87641e795ca492eb41d4b0f97fce475119e7de8 Mon Sep 17 00:00:00 2001 From: jacobsen9026 Date: Sat, 9 Nov 2019 14:57:29 -0500 Subject: [PATCH 13/25] Bulk Checkin Routes Add routes for bulk checkin page --- routes/web/hardware.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/routes/web/hardware.php b/routes/web/hardware.php index 1f34a661e8bb..7ecbd6054f11 100644 --- a/routes/web/hardware.php +++ b/routes/web/hardware.php @@ -161,6 +161,16 @@ function () { 'as' => 'hardware/bulkcheckout', 'uses' => 'Assets\BulkAssetsController@storeCheckout' ]); + + Route::get( 'bulkcheckin', [ + 'as' => 'hardware/bulkcheckin', + 'uses' => 'BulkAssetsController@showCheckin' + ]); + Route::post( 'bulkcheckin', [ + 'as' => 'hardware/bulkcheckin', + 'uses' => 'BulkAssetsController@storeCheckin' + ]); + From f71511fd29f89ac5b19e66178ce9b59cb97d1a82 Mon Sep 17 00:00:00 2001 From: jacobsen9026 Date: Sat, 9 Nov 2019 15:02:54 -0500 Subject: [PATCH 14/25] Bulk Checkin Menu Item Issue #6057 --- resources/views/layouts/default.blade.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/resources/views/layouts/default.blade.php b/resources/views/layouts/default.blade.php index eabddf976c5e..11e427742884 100644 --- a/resources/views/layouts/default.blade.php +++ b/resources/views/layouts/default.blade.php @@ -439,6 +439,14 @@ @endcan
  •  
  • + @can('checkin', \App\Models\Asset::class) + + + {{ trans('general.bulk_checkin') }} + + + @endcan + @can('checkout', \App\Models\Asset::class) From bb1310932d631128f7cb2e1b39e31441e0a6c0bc Mon Sep 17 00:00:00 2001 From: jacobsen9026 Date: Sat, 9 Nov 2019 15:04:50 -0500 Subject: [PATCH 15/25] Bulk Checkin Functions For issue #6057 --- .../Controllers/BulkAssetModelsController.php | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/app/Http/Controllers/BulkAssetModelsController.php b/app/Http/Controllers/BulkAssetModelsController.php index f8c15d1ebdd7..c5b9d3ee1c9a 100644 --- a/app/Http/Controllers/BulkAssetModelsController.php +++ b/app/Http/Controllers/BulkAssetModelsController.php @@ -134,5 +134,77 @@ public function destroy() ->with('error', trans('admin/models/message.bulkdelete.error')); } + + + /** + * Show Bulk Checkin Page + * @return View View to checkout multiple assets + */ + public function showCheckin() + { + $this->authorize('checkin', Asset::class); + // Filter out assets that are not checked out. + + return view('hardware/bulk-checkin'); + } + + + + + + /** + * Process Multiple Checkin Request + * @return View + */ + public function storeCheckin(Request $request) + { + try { + $admin = Auth::user(); + + $target = $this->determineCheckinTarget(); + + if (!is_array($request->get('selected_assets'))) { + return redirect()->route('hardware/bulkcheckin')->withInput()->with('error', trans('admin/hardware/message.checkout.no_assets_selected')); + } + + $asset_ids = array_filter($request->get('selected_assets')); + + $checkin_at = date("Y-m-d H:i:s"); + if (($request->filled('checkin_at')) && ($request->get('checkin_at')!= date("Y-m-d"))) { + $checkin_at = e($request->get('checkin_at')); + } + + + $errors = []; + DB::transaction(function () use ($target, $admin, $checkin_at, $errors, $asset_ids, $request) { + + foreach ($asset_ids as $asset_id) { + $asset = Asset::findOrFail($asset_id); + $this->authorize('checkin', $asset); + $error = $asset->checkIn($target, $admin, $checkin_at, e($request->get('note')), null); + + + //$asset->location_id = $target->location_id; + //$asset->unsetEventDispatcher(); + $asset->save(); + + + if ($error) { + array_merge_recursive($errors, $asset->getErrors()->toArray()); + } + } + }); + + if (!$errors) { + // Redirect to the new asset page + return redirect()->to("hardware")->with('success', trans('admin/hardware/message.checkin.success')); + } + // Redirect to the asset management page with error + return redirect()->to("hardware/bulk-checkin")->with('error', trans('admin/hardware/message.checkin.error'))->withErrors($errors); + } catch (ModelNotFoundException $e) { + return redirect()->to("hardware/bulk-checkin")->with('error', $e->getErrors()); + } + } + } From c372d813e62a4ed70797000ce7d7643865987e3c Mon Sep 17 00:00:00 2001 From: jacobsen9026 Date: Sat, 9 Nov 2019 15:06:10 -0500 Subject: [PATCH 16/25] Bulk Checkin Layout For issue #6057 --- .../views/hardware/bulk-checkin.blade.php | 93 +++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 resources/views/hardware/bulk-checkin.blade.php diff --git a/resources/views/hardware/bulk-checkin.blade.php b/resources/views/hardware/bulk-checkin.blade.php new file mode 100644 index 000000000000..60dd9d82ce1c --- /dev/null +++ b/resources/views/hardware/bulk-checkin.blade.php @@ -0,0 +1,93 @@ +@extends('layouts/default') + +{{-- Page title --}} +@section('title') + {{ trans('admin/hardware/general.bulk_checkin') }} +@parent +@stop + +{{-- Page content --}} +@section('content') + + + + + +@stop + +@section('moar_scripts') +@include('partials/assets-assigned') + +@stop From ce1787af21a386fd3f19b515f92407ed752e100c Mon Sep 17 00:00:00 2001 From: jacobsen9026 Date: Sat, 9 Nov 2019 15:11:21 -0500 Subject: [PATCH 17/25] Updated for bulkcheckin function For issue #6057 --- app/Http/Controllers/Api/AssetsController.php | 23 ++++++++++++++----- 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/app/Http/Controllers/Api/AssetsController.php b/app/Http/Controllers/Api/AssetsController.php index f75adcb454be..21f4dbc222a0 100644 --- a/app/Http/Controllers/Api/AssetsController.php +++ b/app/Http/Controllers/Api/AssetsController.php @@ -371,12 +371,23 @@ public function selectlist(Request $request) 'assets.status_id' ])->with('model', 'assetstatus', 'assignedTo')->NotArchived(), 'company_id', 'assets'); - if ($request->filled('assetStatusType') && $request->input('assetStatusType') === 'RTD') { - $assets = $assets->RTD(); - } - - if ($request->filled('search')) { - $assets = $assets->AssignedSearch($request->input('search')); + if ($request->filled('assetStatusType')) { + switch ( $request->input('assetStatusType')){ + case 'RTD': + $assets = $assets->RTD(); + if ($request->filled('search')) { + $assets = $assets->AssignedSearch($request->input('search')); + } + break; + case 'Deployed': + $assets = $assets->Deployed(); + if ($request->filled('search')) { + $assets = $assets->DeployedSearch($request->input('search')); + } + break; + default: + break; + } } From 32e4cb94e3cf3151f6267a826f1c719204f80a99 Mon Sep 17 00:00:00 2001 From: jacobsen9026 Date: Sat, 9 Nov 2019 15:14:01 -0500 Subject: [PATCH 18/25] Start serachDeployed function This does not work yet. For issue #6057 --- app/Models/Asset.php | 59 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/app/Models/Asset.php b/app/Models/Asset.php index 07417347781c..41d4233a4583 100644 --- a/app/Models/Asset.php +++ b/app/Models/Asset.php @@ -1234,6 +1234,65 @@ public function scopeAssignedSearch($query, $search) } })->withTrashed()->whereNull("assets.deleted_at"); //workaround for laravel bug } + + + + + + /** + * Query builder scope to search on text for complex Bootstrap Tables API. + * + * @param \Illuminate\Database\Query\Builder $query Query builder instance + * @param text $search Search term + * + * @return \Illuminate\Database\Query\Builder Modified query builder + */ + public function scopeDeployedSearch($query, $search) + { + $search = explode(' OR ', $search); + + return $query->leftJoin('users as assets_users',function ($leftJoin) { + $leftJoin->on("assets_users.id", "!=", "assets.assigned_type") + ->where("assets.assigned_type", "=", User::class); + })->leftJoin('locations as assets_locations',function ($leftJoin) { + $leftJoin->on("assets_locations.id","!=","assets.assigned_type") + ->where("assets.assigned_type","=",Location::class); + })->leftJoin('assets as assigned_assets',function ($leftJoin) { + $leftJoin->on('assigned_assets.id', '!=', 'assets.assigned_type') + ->where('assets.assigned_type', '=', Asset::class); + })->where(function ($query) use ($search) { + foreach ($search as $search) { + $query->whereHas('model', function ($query) use ($search) { + $query->whereHas('category', function ($query) use ($search) { + $query->where(function ($query) use ($search) { + $query->where('categories.name', 'LIKE', '%'.$search.'%') + ->orWhere('models.name', 'LIKE', '%'.$search.'%') + ->orWhere('models.model_number', 'LIKE', '%'.$search.'%'); + }); + }); + })->orWhereHas('model', function ($query) use ($search) { + $query->whereHas('manufacturer', function ($query) use ($search) { + $query->where(function ($query) use ($search) { + $query->where('manufacturers.name', 'LIKE', '%'.$search.'%'); + }); + }); + })->orWhere(function ($query) use ($search) { + $query->where('assets_users.first_name', 'LIKE', '%'.$search.'%') + ->orWhere('assets_users.last_name', 'LIKE', '%'.$search.'%') + ->orWhereRaw('CONCAT('.DB::getTablePrefix().'assets_users.first_name," ",'.DB::getTablePrefix().'assets_users.last_name) LIKE ?', ["%$search%", "%$search%"]) + ->orWhere('assets_users.username', 'LIKE', '%'.$search.'%') + ->orWhere('assets_locations.name', 'LIKE', '%'.$search.'%') + ->orWhere('assigned_assets.name', 'LIKE', '%'.$search.'%'); + })->orWhere('assets.name', 'LIKE', '%'.$search.'%') + ->orWhere('assets.asset_tag', 'LIKE', '%'.$search.'%') + ->orWhere('assets.serial', 'LIKE', '%'.$search.'%') + ->orWhere('assets.order_number', 'LIKE', '%'.$search.'%') + ->orWhere('assets.notes', 'LIKE', '%'.$search.'%'); + } + + })->withTrashed()->whereNull("assets.deleted_at"); //workaround for laravel bug + } + /** * Query builder scope to search the department ID of users assigned to assets From 5e103801bae1a7d02b2cc2b43b89b25c43b92d2d Mon Sep 17 00:00:00 2001 From: jacobsen9026 Date: Sat, 9 Nov 2019 15:16:06 -0500 Subject: [PATCH 19/25] Bulk Checkin English Language reference For issue #6057 --- resources/lang/en/general.php | 1 + 1 file changed, 1 insertion(+) diff --git a/resources/lang/en/general.php b/resources/lang/en/general.php index 9b8bfbfaad0d..80e1292f390b 100644 --- a/resources/lang/en/general.php +++ b/resources/lang/en/general.php @@ -29,6 +29,7 @@ 'bad_data' => 'Nothing found. Maybe bad data?', 'bulkaudit' => 'Bulk Audit', 'bulkaudit_status' => 'Audit Status', + 'bulk_checkin' => 'Bulk Checkin', 'bulk_checkout' => 'Bulk Checkout', 'bystatus' => 'by Status', 'cancel' => 'Cancel', From 17aa72bf00783834b0a489c619c134cc353c4c5f Mon Sep 17 00:00:00 2001 From: jacobsen9026 Date: Sun, 10 Nov 2019 12:46:44 -0500 Subject: [PATCH 20/25] Bulk Checkin Layout Change button label to checkin --- resources/views/hardware/bulk-checkin.blade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/views/hardware/bulk-checkin.blade.php b/resources/views/hardware/bulk-checkin.blade.php index 60dd9d82ce1c..2edac1b676f2 100644 --- a/resources/views/hardware/bulk-checkin.blade.php +++ b/resources/views/hardware/bulk-checkin.blade.php @@ -66,7 +66,7 @@
    From ac70a4bf4c0a815a7842ce67bfa365103ea6a4c9 Mon Sep 17 00:00:00 2001 From: jacobsen9026 Date: Sun, 10 Nov 2019 12:48:26 -0500 Subject: [PATCH 21/25] Completed Deployed Search Query For issue #6057 --- app/Models/Asset.php | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/app/Models/Asset.php b/app/Models/Asset.php index 41d4233a4583..aea71c978683 100644 --- a/app/Models/Asset.php +++ b/app/Models/Asset.php @@ -1251,16 +1251,7 @@ public function scopeDeployedSearch($query, $search) { $search = explode(' OR ', $search); - return $query->leftJoin('users as assets_users',function ($leftJoin) { - $leftJoin->on("assets_users.id", "!=", "assets.assigned_type") - ->where("assets.assigned_type", "=", User::class); - })->leftJoin('locations as assets_locations',function ($leftJoin) { - $leftJoin->on("assets_locations.id","!=","assets.assigned_type") - ->where("assets.assigned_type","=",Location::class); - })->leftJoin('assets as assigned_assets',function ($leftJoin) { - $leftJoin->on('assigned_assets.id', '!=', 'assets.assigned_type') - ->where('assets.assigned_type', '=', Asset::class); - })->where(function ($query) use ($search) { + return $query->where(function ($query) use ($search) { foreach ($search as $search) { $query->whereHas('model', function ($query) use ($search) { $query->whereHas('category', function ($query) use ($search) { @@ -1276,13 +1267,6 @@ public function scopeDeployedSearch($query, $search) $query->where('manufacturers.name', 'LIKE', '%'.$search.'%'); }); }); - })->orWhere(function ($query) use ($search) { - $query->where('assets_users.first_name', 'LIKE', '%'.$search.'%') - ->orWhere('assets_users.last_name', 'LIKE', '%'.$search.'%') - ->orWhereRaw('CONCAT('.DB::getTablePrefix().'assets_users.first_name," ",'.DB::getTablePrefix().'assets_users.last_name) LIKE ?', ["%$search%", "%$search%"]) - ->orWhere('assets_users.username', 'LIKE', '%'.$search.'%') - ->orWhere('assets_locations.name', 'LIKE', '%'.$search.'%') - ->orWhere('assigned_assets.name', 'LIKE', '%'.$search.'%'); })->orWhere('assets.name', 'LIKE', '%'.$search.'%') ->orWhere('assets.asset_tag', 'LIKE', '%'.$search.'%') ->orWhere('assets.serial', 'LIKE', '%'.$search.'%') @@ -1294,6 +1278,7 @@ public function scopeDeployedSearch($query, $search) } + /** * Query builder scope to search the department ID of users assigned to assets * From 2de964c400694e2aac6bc9e30df1ec1316258930 Mon Sep 17 00:00:00 2001 From: jacobsen9026 Date: Sun, 10 Nov 2019 13:11:19 -0500 Subject: [PATCH 22/25] Update BulkAssetsController.php Add functionality for bulk checkin For issue #6057 --- .../Assets/BulkAssetsController.php | 83 +++++++++++++++++++ 1 file changed, 83 insertions(+) diff --git a/app/Http/Controllers/Assets/BulkAssetsController.php b/app/Http/Controllers/Assets/BulkAssetsController.php index 1727607c650c..9c44c2ffa4de 100644 --- a/app/Http/Controllers/Assets/BulkAssetsController.php +++ b/app/Http/Controllers/Assets/BulkAssetsController.php @@ -188,6 +188,19 @@ public function showCheckout() return view('hardware/bulk-checkout'); } + + /** + * Show Bulk Checkin Page + * @return View View to checkout multiple assets + */ + public function showCheckin() + { + $this->authorize('checkin', Asset::class); + // Filter out assets that are not checked out. + + return view('hardware/bulk-checkin'); + } + /** * Process Multiple Checkout Request @@ -252,4 +265,74 @@ public function storeCheckout(Request $request) return redirect()->to("hardware/bulk-checkout")->with('error', $e->getErrors()); } } + + /** + * Process Multiple Checkin Request + * @return View + */ + public function storeCheckin(Request $request) + { + try { + $admin = Auth::user(); + + //$target = $this->determineCheckinTarget(); + + if (!is_array($request->get('selected_assets'))) { + return redirect()->route('hardware/bulkcheckin')->withInput()->with('error', trans('admin/hardware/message.checkout.no_assets_selected')); + } + + $asset_ids = array_filter($request->get('selected_assets')); + + $checkin_at = date("Y-m-d H:i:s"); + if (($request->filled('checkin_at')) && ($request->get('checkin_at')!= date("Y-m-d"))) { + $checkin_at = e($request->get('checkin_at')); + } + + + $errors = []; + + + foreach ($asset_ids as $asset_id) { + $this->authorize('checkin', Asset::class); + $asset = Asset::findOrFail($asset_id); + $this->authorize('checkin', $asset); + + + $user = $asset->assignedUser; + if (is_null($target = $asset->assignedTo)) { + continue; + } + + $asset->expected_checkin = null; + $asset->last_checkout = null; + $asset->assigned_to = null; + $asset->assignedTo()->disassociate($asset); + $asset->accepted = null; + + + $asset->location_id = $asset->rtd_location_id; + + if ($request->filled('location_id')) { + $asset->location_id = $request->get('location_id'); + } + + + if ($asset->save()) { + $asset->logCheckin($target, e(request('note'))); + } + + } + + + if (!$errors) { + // Redirect to the new asset page + return redirect()->to("hardware")->with('success', trans('admin/hardware/message.checkin.success')); + } + // Redirect to the asset management page with error + return redirect()->to("hardware/bulk-checkin")->with('error', trans('admin/hardware/message.checkin.error'))->withErrors($errors); + } catch (ModelNotFoundException $e) { + return redirect()->to("hardware/bulk-checkin")->with('error', $e->getErrors()); + } + } + } From c1f7f0bc8d660a07801e71335ce6a0cce009340e Mon Sep 17 00:00:00 2001 From: jacobsen9026 Date: Sun, 10 Nov 2019 13:13:13 -0500 Subject: [PATCH 23/25] Update BulkAssetModelsController.php Removed functions that were placed in wrong file, moved to Assets/BulkAssetsController.php --- .../Controllers/BulkAssetModelsController.php | 72 +------------------ 1 file changed, 1 insertion(+), 71 deletions(-) diff --git a/app/Http/Controllers/BulkAssetModelsController.php b/app/Http/Controllers/BulkAssetModelsController.php index c5b9d3ee1c9a..8ca2785c4dcd 100644 --- a/app/Http/Controllers/BulkAssetModelsController.php +++ b/app/Http/Controllers/BulkAssetModelsController.php @@ -135,76 +135,6 @@ public function destroy() } - - /** - * Show Bulk Checkin Page - * @return View View to checkout multiple assets - */ - public function showCheckin() - { - $this->authorize('checkin', Asset::class); - // Filter out assets that are not checked out. - - return view('hardware/bulk-checkin'); - } - - - - - - /** - * Process Multiple Checkin Request - * @return View - */ - public function storeCheckin(Request $request) - { - try { - $admin = Auth::user(); - - $target = $this->determineCheckinTarget(); - - if (!is_array($request->get('selected_assets'))) { - return redirect()->route('hardware/bulkcheckin')->withInput()->with('error', trans('admin/hardware/message.checkout.no_assets_selected')); - } - - $asset_ids = array_filter($request->get('selected_assets')); - - $checkin_at = date("Y-m-d H:i:s"); - if (($request->filled('checkin_at')) && ($request->get('checkin_at')!= date("Y-m-d"))) { - $checkin_at = e($request->get('checkin_at')); - } - - - $errors = []; - DB::transaction(function () use ($target, $admin, $checkin_at, $errors, $asset_ids, $request) { - - foreach ($asset_ids as $asset_id) { - $asset = Asset::findOrFail($asset_id); - $this->authorize('checkin', $asset); - $error = $asset->checkIn($target, $admin, $checkin_at, e($request->get('note')), null); - - - //$asset->location_id = $target->location_id; - //$asset->unsetEventDispatcher(); - $asset->save(); - - - if ($error) { - array_merge_recursive($errors, $asset->getErrors()->toArray()); - } - } - }); - - if (!$errors) { - // Redirect to the new asset page - return redirect()->to("hardware")->with('success', trans('admin/hardware/message.checkin.success')); - } - // Redirect to the asset management page with error - return redirect()->to("hardware/bulk-checkin")->with('error', trans('admin/hardware/message.checkin.error'))->withErrors($errors); - } catch (ModelNotFoundException $e) { - return redirect()->to("hardware/bulk-checkin")->with('error', $e->getErrors()); - } - } - + } From d29098784e6518fcaab00433812cdeef1c010b27 Mon Sep 17 00:00:00 2001 From: jacobsen9026 Date: Sun, 10 Nov 2019 13:15:08 -0500 Subject: [PATCH 24/25] Update BulkAssetsController.php Update Comment --- app/Http/Controllers/Assets/BulkAssetsController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Controllers/Assets/BulkAssetsController.php b/app/Http/Controllers/Assets/BulkAssetsController.php index 9c44c2ffa4de..e2223f160b72 100644 --- a/app/Http/Controllers/Assets/BulkAssetsController.php +++ b/app/Http/Controllers/Assets/BulkAssetsController.php @@ -191,7 +191,7 @@ public function showCheckout() /** * Show Bulk Checkin Page - * @return View View to checkout multiple assets + * @return View View to checkin multiple assets */ public function showCheckin() { From f38151bd2693f79a49cfb5f4db36d67f8a68f429 Mon Sep 17 00:00:00 2001 From: jacobsen9026 Date: Sun, 10 Nov 2019 13:19:46 -0500 Subject: [PATCH 25/25] Added Bulk Checkin Title Reference For Issue #6057 --- resources/lang/en/admin/hardware/general.php | 1 + 1 file changed, 1 insertion(+) diff --git a/resources/lang/en/admin/hardware/general.php b/resources/lang/en/admin/hardware/general.php index e3afc7d2f1ea..240a29d9a4d1 100644 --- a/resources/lang/en/admin/hardware/general.php +++ b/resources/lang/en/admin/hardware/general.php @@ -3,6 +3,7 @@ return array( 'archived' => 'Archived', 'asset' => 'Asset', + 'bulk_checkin' => 'Checkin Assets', 'bulk_checkout' => 'Checkout Assets', 'checkin' => 'Checkin Asset', 'checkout' => 'Checkout Asset',