First version of bulk checkin

This commit is contained in:
Alex Janes 2021-12-19 16:53:31 -05:00
parent 4ca2252e3b
commit bc4fe88ac0
7 changed files with 280 additions and 1 deletions

View file

@ -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] [<snipe@snipe.net>]
* @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

View file

@ -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();

View file

@ -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',

View file

@ -0,0 +1,182 @@
@extends('layouts/default')
{{-- Page title --}}
@section('title')
{{ trans('general.bulk_checkin') }}
@parent
@stop
{{-- Page content --}}
@section('content')
<style>
.input-group {
padding-left: 0px !important;
}
</style>
<div class="row">
{{ Form::open(['method' => 'POST', 'class' => 'form-horizontal', 'role' => 'form', 'id' => 'checkin-form' ]) }}
<!-- left column -->
<div class="col-md-6">
<div class="box box-default">
<div class="box-header with-border">
<h2 class="box-title"> {{ trans('general.bulk_checkin') }} </h2>
</div>
<div class="box-body">
{{csrf_field()}}
<!-- Asset Tag -->
<div class="form-group {{ $errors->has('asset_tag') ? 'error' : '' }}">
{{ Form::label('asset_tag', trans('general.asset_tag'), array('class' => 'col-md-3 control-label', 'id' => 'checkin_tag')) }}
<div class="col-md-9">
<div class="input-group date col-md-5" data-date-format="yyyy-mm-dd">
<input type="text" class="form-control" name="asset_tag" id="asset_tag" value="{{ Request::old('asset_tag') }}">
</div>
{!! $errors->first('asset_tag', '<span class="alert-msg" aria-hidden="true"><i class="fas fa-times" aria-hidden="true"></i> :message</span>') !!}
</div>
</div>
<!-- Locations -->
@include ('partials.forms.edit.location-select', ['translated_name' => trans('general.location'), 'fieldname' => 'location_id'])
<!-- Update location -->
<div class="form-group">
<div class="col-sm-offset-3 col-md-9">
<label>
<input type="checkbox" value="1" name="update_location" class="minimal" {{ Request::old('update_location') == '1' ? ' checked="checked"' : '' }}> Update asset location
</label> <a href="#" class="text-dark-gray" tabindex="0" role="button" data-toggle="popover" data-trigger="focus" title="<i class='far fa-life-ring'></i> More Info" data-html="true" data-content="Checking this box will edit the asset record to reflect this new location. Leaving it unchecked will simply note the location in the checkin log.<br><br>Note that is this asset is checked out, it will not change the location of the person, asset or location it is checked out to."><i class="far fa-life-ring"></i></a>
</div>
</div>
<!-- Note -->
<div class="form-group {{ $errors->has('note') ? 'error' : '' }}">
{{ Form::label('note', trans('admin/hardware/form.notes'), array('class' => 'col-md-3 control-label')) }}
<div class="col-md-8">
<textarea class="col-md-6 form-control" id="note" name="note">{{ old('note') }}</textarea>
{!! $errors->first('note', '<span class="alert-msg" aria-hidden="true"><i class="fas fa-times" aria-hidden="true"></i> :message</span>') !!}
</div>
</div>
</div> <!--/.box-body-->
<div class="box-footer">
<a class="btn btn-link" href="{{ route('hardware.index') }}"> {{ trans('button.cancel') }}</a>
<button type="submit" id="checkin_button" class="btn btn-success pull-right"><i class="fas fa-check icon-white" aria-hidden="true"></i> {{ trans('general.checkin') }}</button>
</div>
</div>
{{Form::close()}}
</div> <!--/.col-md-6-->
<div class="col-md-6">
<div class="box box-default" id="checkedin-div" style="display: none">
<div class="box-header with-border">
<h2 class="box-title"> {{ trans('general.bulk_checkin_status') }} (<span id="checkin-counter">0</span> assets checked in) </h2>
</div>
<div class="box-body">
<table id="checkedin" class="table table-striped snipe-table">
<thead>
<tr>
<th>{{ trans('general.asset_tag') }}</th>
<th>{{ trans('general.bulk_checkin_status') }}</th>
<th></th>
</tr>
<tr id="checkin-loader" style="display: none;">
<td colspan="3">
<i class="fas fa-spinner spin" aria-hidden="true"></i> Processing...
</td>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
</div>
</div>
</div>
@stop
@section('moar_scripts')
<script nonce="{{ csrf_token() }}">
$("#checkin-form").submit(function (event) {
$('#checkedin-div').show();
$('#checkin-loader').show();
event.preventDefault();
var form = $("#checkin-form").get(0);
var formData = $('#checkin-form').serializeArray();
$.ajax({
url: "{{ route('api.asset.bulkcheckin') }}",
type : 'POST',
headers: {
"X-Requested-With": 'XMLHttpRequest',
"X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr('content')
},
dataType : 'json',
data : formData,
success : function (data) {
if (data.status == 'success') {
$('#checkedin tbody').prepend("<tr class='success'><td>" + data.payload.asset_tag + "</td><td>" + data.messages + "</td><td><i class='fas fa-check text-success'></i></td></tr>");
incrementOnSuccess();
} else {
handlecheckinFail(data);
}
$('input#asset_tag').val('');
},
error: function (data) {
handlecheckinFail(data);
},
complete: function() {
$('#checkin-loader').hide();
}
});
return false;
});
function handlecheckinFail (data) {
if (data.payload.asset_tag) {
var asset_tag = data.payload.asset_tag;
} else {
var asset_tag = '';
}
if (data.messages) {
var messages = data.messages;
} else {
var messages = '';
}
$('#checkedin tbody').prepend("<tr class='danger'><td>" + asset_tag + "</td><td>" + messages + "</td><td><i class='fas fa-times text-danger'></i></td></tr>");
}
function incrementOnSuccess() {
var x = parseInt($('#checkin-counter').html());
y = x + 1;
$('#checkin-counter').html(y);
}
$("#checkin_tag").focus();
</script>
@stop

View file

@ -480,6 +480,14 @@
@endcan
<li class="divider">&nbsp;</li>
@can('checkin', \App\Models\Asset::class)
<li{!! (Request::is('hardware/bulkcheckin') ? ' class="active"' : '') !!}>
<a href="{{ route('hardware/bulkcheckin') }}">
{{ trans('general.bulk_checkin') }}
</a>
</li>
@endcan
@can('checkout', \App\Models\Asset::class)
<li{!! (Request::is('hardware/bulkcheckout') ? ' class="active"' : '') !!}>
<a href="{{ route('hardware/bulkcheckout') }}">

View file

@ -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,

View file

@ -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, [