diff --git a/app/Http/Controllers/Api/AssetsController.php b/app/Http/Controllers/Api/AssetsController.php index c7055ecb8d..3c8ddbbd21 100644 --- a/app/Http/Controllers/Api/AssetsController.php +++ b/app/Http/Controllers/Api/AssetsController.php @@ -507,28 +507,35 @@ class AssetsController extends Controller * @since [v4.0] * @return JsonResponse */ - public function audit(Request $request, $id) { + public function audit(Request $request) { + $this->authorize('audit', Asset::class); - $rules = array( + 'asset_tag' => 'required', 'location_id' => 'exists:locations,id|nullable|numeric', 'next_audit_date' => 'date|nullable' ); - $validator = \Validator::make($request->all(), $rules); + $validator = Validator::make($request->all(), $rules); if ($validator->fails()) { return response()->json(Helper::formatStandardApiResponse('error', null, $validator->errors()->all())); } - $asset = Asset::findOrFail($id); - $asset->next_audit_date = $request->input('next_audit_date'); + $asset = Asset::where('asset_tag','=', $request->input('asset_tag'))->first(); - if ($asset->save()) { - $asset->logAudit(request('note'),request('location_id')); - return response()->json(Helper::formatStandardApiResponse('success', ['asset'=> e($asset->asset_tag)], trans('admin/hardware/message.audit.success'))); + + if ($asset) { + $asset->next_audit_date = $request->input('next_audit_date'); + if ($asset->save()) { + $log = $asset->logAudit(request('note'),request('location_id')); + return response()->json(Helper::formatStandardApiResponse('success', ['asset_tag'=> e($asset->asset_tag), 'note'=> e($request->input('note')), 'next_audit_date' => Helper::getFormattedDateObject($log->calcNextAuditDate())], trans('admin/hardware/message.audit.success'))); + } } + return response()->json(Helper::formatStandardApiResponse('error', ['asset_tag'=> e($request->input('asset_tag'))], 'Asset with tag '.$request->input('asset_tag').' not found')); + + diff --git a/app/Http/Controllers/AssetsController.php b/app/Http/Controllers/AssetsController.php index 666b441c53..c8f2ef5ed2 100755 --- a/app/Http/Controllers/AssetsController.php +++ b/app/Http/Controllers/AssetsController.php @@ -1238,6 +1238,16 @@ class AssetsController extends Controller return redirect()->to("hardware/bulk-checkout")->with('error', trans('admin/hardware/message.checkout.error'))->withErrors($errors); } + + public function quickScan(Request $request) + { + $this->authorize('audit', Asset::class); + $dt = Carbon::now()->addMonths(12)->toDateString(); + return view('hardware/quickscan')->with('next_audit_date', $dt)->with('locations_list', Helper::locationsList()); + } + + + public function audit(Request $request, $id) { $this->authorize('audit', Asset::class); diff --git a/app/Models/Actionlog.php b/app/Models/Actionlog.php index 260257125d..36603b4bad 100755 --- a/app/Models/Actionlog.php +++ b/app/Models/Actionlog.php @@ -154,31 +154,23 @@ class Actionlog extends SnipeModel } } - public function daysUntilNextAudit($monthInterval = null, $asset = null) { + public function daysUntilNextAudit($monthInterval = 12, $asset = null) { - // check for next_audit_date to override global - - if (!$monthInterval) { - $monthInterval = 12; - } + $now = Carbon::now(); $last_audit_date = $this->created_at; - $next_audit_days = $last_audit_date->diffInDays($last_audit_date->copy()->addMonth($monthInterval)); + $next_audit = $last_audit_date->addMonth($monthInterval); + $next_audit_days = $now->diffInDays($next_audit); // Override the default setting for interval if the asset has its own next audit date if (($asset) && ($asset->next_audit_date)) { $override_default_next = \Carbon::parse($asset->next_audit_date); - $suborder['payment_date'] = $override_default_next->format('M d Y'); - $next_audit_days = $last_audit_date->diffInDays($override_default_next); + $next_audit_days = $override_default_next->diffInDays($now); } return $next_audit_days; } - public function calcNextAuditDate($monthInterval = null, $asset = null) { - - if (!$monthInterval) { - $monthInterval = 12; - } + public function calcNextAuditDate($monthInterval = 12, $asset = null) { $last_audit_date = Carbon::parse($this->created_at); // If there is an asset-specific next date already given, diff --git a/resources/lang/en/general.php b/resources/lang/en/general.php index d3656d96e2..eb6409ddbb 100644 --- a/resources/lang/en/general.php +++ b/resources/lang/en/general.php @@ -25,6 +25,8 @@ 'avatar_upload' => 'Upload Avatar', 'back' => 'Back', 'bad_data' => 'Nothing found. Maybe bad data?', + 'bulkaudit' => 'Bulk Audit', + 'bulkaudit_status' => 'Audit Status', 'bulk_checkout' => 'Bulk Checkout', 'cancel' => 'Cancel', 'categories' => 'Categories', diff --git a/resources/views/hardware/quickscan.blade.php b/resources/views/hardware/quickscan.blade.php new file mode 100644 index 0000000000..c4beca85dd --- /dev/null +++ b/resources/views/hardware/quickscan.blade.php @@ -0,0 +1,198 @@ +@extends('layouts/default') + +{{-- Page title --}} +@section('title') + {{ trans('general.bulkaudit') }} + @parent +@stop + +{{-- Page content --}} +@section('content') + + + + +
+ {{ Form::open(['method' => 'POST', 'class' => 'form-horizontal', 'role' => 'form', 'id' => 'audit-form' ]) }} + +
+
+
+

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

+
+
+ {{csrf_field()}} + + +
+ {{ Form::label('asset_tag', trans('general.asset_tag'), array('class' => 'col-md-3 control-label', 'id' => 'audit_tag')) }} +
+
+ + +
+ {!! $errors->first('asset_tag', ' :message') !!} +
+
+ + + + +
+ {{ Form::label('location_id', trans('general.location'), array('class' => 'col-md-3 control-label')) }} +
+ {{ Form::select('location_id', $locations_list , Input::old('location_id'), array('class'=>'select2', 'id'=>'location_id', 'style'=>'width:100%')) }} + + {!! $errors->first('location_id', ' :message') !!} +
+
+ + + +
+ {{ Form::label('next_audit_date', trans('general.next_audit_date'), array('class' => 'col-md-3 control-label')) }} +
+
+ + +
+ {!! $errors->first('next_audit_date', ' :message') !!} +
+
+ + + +
+ {{ Form::label('note', trans('admin/hardware/form.notes'), array('class' => 'col-md-3 control-label')) }} +
+ + {!! $errors->first('note', ' :message') !!} +
+
+ + + +
+ + + + +
+ + + + {{Form::close()}} +
+
+ +
+
+ + + +@stop + + +@section('moar_scripts') + +@stop diff --git a/resources/views/layouts/default.blade.php b/resources/views/layouts/default.blade.php index 3d1351a354..88ac3edee3 100644 --- a/resources/views/layouts/default.blade.php +++ b/resources/views/layouts/default.blade.php @@ -414,6 +414,9 @@
  • @lang('general.asset_maintenances')
  • @lang('general.import-history')
  • @endcan + @can('audit', \App\Models\Asset::class) +
  • @lang('general.bulkaudit')
  • + @endcan @endcan diff --git a/routes/api.php b/routes/api.php index 78a6293087..5a9cb1a79a 100644 --- a/routes/api.php +++ b/routes/api.php @@ -214,7 +214,7 @@ Route::group(['prefix' => 'v1','namespace' => 'Api'], function () { Route::group(['prefix' => 'hardware'], function () { - Route::post('audit/{id}', [ + Route::post('audit', [ 'as' => 'api.asset.audit', 'uses' => 'AssetsController@audit' ]); diff --git a/routes/web/hardware.php b/routes/web/hardware.php index e9e1342824..51c1769b7c 100644 --- a/routes/web/hardware.php +++ b/routes/web/hardware.php @@ -12,6 +12,11 @@ Route::group( 'middleware' => ['auth']], function () { + Route::get( 'bulkaudit', [ + 'as' => 'assets.bulkaudit', + 'uses' => 'AssetsController@quickScan' + ]); + # Asset Maintenances Route::resource('maintenances', 'AssetMaintenancesController', [ 'parameters' => ['maintenance' => 'maintenance_id', 'asset' => 'asset_id'] @@ -128,6 +133,8 @@ Route::group( ]); + + });