From bc4fe88ac0e96d75f6433933698c6a287c70d30d Mon Sep 17 00:00:00 2001 From: Alex Janes Date: Sun, 19 Dec 2021 16:53:31 -0500 Subject: [PATCH] First version of bulk checkin --- app/Http/Controllers/Api/AssetsController.php | 71 ++++++- .../Controllers/Assets/AssetsController.php | 7 + resources/lang/en/general.php | 2 + .../hardware/quickscan-checkin.blade.php | 182 ++++++++++++++++++ resources/views/layouts/default.blade.php | 8 + routes/api.php | 7 + routes/web/hardware.php | 4 + 7 files changed, 280 insertions(+), 1 deletion(-) create mode 100644 resources/views/hardware/quickscan-checkin.blade.php diff --git a/app/Http/Controllers/Api/AssetsController.php b/app/Http/Controllers/Api/AssetsController.php index 614c61d7ba..d26780f4c4 100644 --- a/app/Http/Controllers/Api/AssetsController.php +++ b/app/Http/Controllers/Api/AssetsController.php @@ -835,7 +835,7 @@ class AssetsController extends Controller if ($request->filled('name')) { $asset->name = $request->input('name'); } - + $asset->location_id = $asset->rtd_location_id; if ($request->filled('location_id')) { @@ -855,6 +855,75 @@ class AssetsController extends Controller return response()->json(Helper::formatStandardApiResponse('success', ['asset'=> e($asset->asset_tag)], trans('admin/hardware/message.checkin.error'))); } + /** + * Bulk Checkin an asset + * This is the current solution to perform a bulk checkin based on an asset tag, rather than a regular checkin. + * This is due to the need to find the asset first based on the asset tag. + * + * @author [A. Gianotto] [] + * @param int $assetId + * @since [v4.0] + * @return JsonResponse + */ + public function bulkCheckin(Request $request) + { + $this->authorize('checkin', Asset::class); + $asset = Asset::with('assetstatus')->where('asset_tag', $request->input('asset_tag'))->first(); + + if($asset) { + \Log::debug('Asset Name: ' . $asset->name); + $this->authorize('checkin', $asset); + + + $target = $asset->assigned_to; + \Log::debug('Assigned User: ' . $asset->assigned_to); + if (is_null($target)) { + return response()->json(Helper::formatStandardApiResponse('error', ['asset_tag' => e($request->input('asset_tag'))], trans('admin/hardware/message.checkin.already_checked_in'))); + } + + $asset->expected_checkin = null; + $asset->last_checkout = null; + $asset->assigned_to = null; + $asset->assignedTo()->disassociate($asset); + $asset->accepted = null; + + if ($request->filled('name')) { + $asset->name = $request->input('name'); + } + + $asset->location_id = $asset->rtd_location_id; + + if ($request->filled('location_id')) { + $asset->location_id = $request->input('location_id'); + } + + if ($request->has('status_id')) { + $asset->status_id = $request->input('status_id'); + } + + if ($asset->save()) { + \Log::debug('Asset Saved'); + //event(new CheckoutableCheckedIn($asset, $target, Auth::user(), $request->input('note'))); + + return response()->json(Helper::formatStandardApiResponse('success', [ + 'asset_tag'=> e($asset->asset_tag) + ], trans('admin/hardware/message.checkin.success'))); + + //return response()->json(Helper::formatStandardApiResponse('success', ['asset' => e($asset->asset_tag)], trans('admin/hardware/message.checkin.success'))); + } + + return response()->json(Helper::formatStandardApiResponse('error', [ + 'asset_tag'=> e($request->input('asset_tag')) + ], trans('admin/hardware/message.checkin.error'))); + } + + return response()->json(Helper::formatStandardApiResponse('error', [ + 'asset_tag'=> e($request->input('asset_tag')) + ], 'Asset with tag '.e($request->input('asset_tag')).' not found')); + + return response()->json(Helper::formatStandardApiResponse('error', ['asset_tag'=> e($request->input('asset_tag'))], 'Asset with tag '.e($request->input('asset_tag')).' not found')); + } + /** * Mark an asset as audited diff --git a/app/Http/Controllers/Assets/AssetsController.php b/app/Http/Controllers/Assets/AssetsController.php index b985012c98..2125d1f6ba 100755 --- a/app/Http/Controllers/Assets/AssetsController.php +++ b/app/Http/Controllers/Assets/AssetsController.php @@ -761,6 +761,13 @@ class AssetsController extends Controller return view('hardware/quickscan')->with('next_audit_date', $dt); } + public function quickScanCheckin() + { + $this->authorize('checkin', Asset::class); + + return view('hardware/quickscan-checkin'); + } + public function audit($id) { $settings = Setting::getSettings(); diff --git a/resources/lang/en/general.php b/resources/lang/en/general.php index 2fd8e3e0e1..23d4fb58ff 100644 --- a/resources/lang/en/general.php +++ b/resources/lang/en/general.php @@ -30,6 +30,8 @@ 'bulkaudit' => 'Bulk Audit', 'bulkaudit_status' => 'Audit Status', 'bulk_checkout' => 'Bulk Checkout', + 'bulk_checkin' => 'Bulk Checkin', + 'bulk_checkin_status' => 'Bulk Checkin Status', 'bystatus' => 'by Status', 'cancel' => 'Cancel', 'categories' => 'Categories', diff --git a/resources/views/hardware/quickscan-checkin.blade.php b/resources/views/hardware/quickscan-checkin.blade.php new file mode 100644 index 0000000000..862585e9f8 --- /dev/null +++ b/resources/views/hardware/quickscan-checkin.blade.php @@ -0,0 +1,182 @@ +@extends('layouts/default') + +{{-- Page title --}} +@section('title') + {{ trans('general.bulk_checkin') }} + @parent +@stop + +{{-- Page content --}} +@section('content') + + + + + +
+ {{ Form::open(['method' => 'POST', 'class' => 'form-horizontal', 'role' => 'form', 'id' => 'checkin-form' ]) }} + +
+
+
+

{{ trans('general.bulk_checkin') }}

+
+
+ {{csrf_field()}} + + +
+ {{ Form::label('asset_tag', trans('general.asset_tag'), array('class' => 'col-md-3 control-label', 'id' => 'checkin_tag')) }} +
+
+ + +
+ {!! $errors->first('asset_tag', '') !!} +
+
+ + + @include ('partials.forms.edit.location-select', ['translated_name' => trans('general.location'), 'fieldname' => 'location_id']) + + + +
+
+ +
+
+ + + +
+ {{ Form::label('note', trans('admin/hardware/form.notes'), array('class' => 'col-md-3 control-label')) }} +
+ + {!! $errors->first('note', '') !!} +
+
+ + + +
+ + + + +
+ + + + {{Form::close()}} +
+ +
+ +
+ +
+ + +@stop + + +@section('moar_scripts') + +@stop diff --git a/resources/views/layouts/default.blade.php b/resources/views/layouts/default.blade.php index 9b41f14787..876bbfc109 100644 --- a/resources/views/layouts/default.blade.php +++ b/resources/views/layouts/default.blade.php @@ -480,6 +480,14 @@ @endcan
  •  
  • + @can('checkin', \App\Models\Asset::class) + + + {{ trans('general.bulk_checkin') }} + + + @endcan + @can('checkout', \App\Models\Asset::class) diff --git a/routes/api.php b/routes/api.php index 85895ec85e..255c6ec17b 100644 --- a/routes/api.php +++ b/routes/api.php @@ -467,6 +467,13 @@ Route::group(['prefix' => 'v1', 'middleware' => 'api'], function () { ] )->name('api.asset.checkin'); + Route::post('bulkcheckin', + [ + Api\AssetsController::class, + 'bulkcheckin' + ] + )->name('api.asset.bulkcheckin'); + Route::post('checkout', [ Api\AssetsController::class, diff --git a/routes/web/hardware.php b/routes/web/hardware.php index 2d83e386aa..465837b504 100644 --- a/routes/web/hardware.php +++ b/routes/web/hardware.php @@ -28,6 +28,10 @@ Route::group( [AssetsController::class, 'quickScan'] )->name('assets.bulkaudit'); + Route::get('bulkcheckin', + [AssetsController::class, 'quickScanCheckin'] + )->name('hardware/bulkcheckin'); + // Asset Maintenances Route::resource('maintenances', AssetMaintenancesController::class, [