diff --git a/app/Http/Controllers/Api/AssetsController.php b/app/Http/Controllers/Api/AssetsController.php index a07f18662013..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; + } } @@ -753,6 +764,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', @@ -782,7 +794,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') { + $target = Location::find($request->input('location_id')); + if ($settings->checkout_on_audit) { + 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)) { $asset->location_id = $request->input('location_id'); } diff --git a/app/Http/Controllers/Assets/AssetsController.php b/app/Http/Controllers/Assets/AssetsController.php index 6025167a1547..de8c831f4845 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( @@ -759,8 +760,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') { - \Log::debug('update location in audit'); + $target = Location::find($request->input('location_id')); + if ($settings->checkout_on_audit) { + 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)) { + $asset->location_id = $request->input('location_id'); + \Log::debug('update location in audit'); $asset->location_id = $request->input('location_id'); } diff --git a/app/Http/Controllers/Assets/BulkAssetsController.php b/app/Http/Controllers/Assets/BulkAssetsController.php index 1727607c650c..e2223f160b72 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 checkin 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()); + } + } + } diff --git a/app/Http/Controllers/BulkAssetModelsController.php b/app/Http/Controllers/BulkAssetModelsController.php index f8c15d1ebdd7..8ca2785c4dcd 100644 --- a/app/Http/Controllers/BulkAssetModelsController.php +++ b/app/Http/Controllers/BulkAssetModelsController.php @@ -134,5 +134,7 @@ public function destroy() ->with('error', trans('admin/models/message.bulkdelete.error')); } + + } diff --git a/app/Http/Controllers/SettingsController.php b/app/Http/Controllers/SettingsController.php index 0af5eb7425cb..6ff6d4c26e04 100755 --- a/app/Http/Controllers/SettingsController.php +++ b/app/Http/Controllers/SettingsController.php @@ -327,13 +327,14 @@ 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'); $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'); } diff --git a/app/Models/Asset.php b/app/Models/Asset.php index 07417347781c..aea71c978683 100644 --- a/app/Models/Asset.php +++ b/app/Models/Asset.php @@ -1234,6 +1234,50 @@ 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->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('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 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', diff --git a/resources/lang/en/general.php b/resources/lang/en/general.php index 0399a53dab08..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', @@ -41,6 +42,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', diff --git a/resources/views/hardware/bulk-checkin.blade.php b/resources/views/hardware/bulk-checkin.blade.php new file mode 100644 index 000000000000..2edac1b676f2 --- /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') + + + + +