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') + + + + +