Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added #10454: Quick Scan Checkin #10455

Merged
merged 16 commits into from
Feb 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 26 additions & 17 deletions app/Http/Controllers/Api/AssetsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ class AssetsController extends Controller
*/
public function index(Request $request, $audit = null)
{

\Log::debug(Route::currentRouteName());


Expand Down Expand Up @@ -328,8 +327,6 @@ public function index(Request $request, $audit = null)
}]);
}




/**
* Here we're just determining which Transformer (via $transformer) to use based on the
Expand All @@ -354,9 +351,8 @@ public function showByTag(Request $request, $tag)

return (new AssetsTransformer)->transformAsset($asset, $request);
}
return response()->json(Helper::formatStandardApiResponse('error', null, 'Asset not found'), 200);


return response()->json(Helper::formatStandardApiResponse('error', null, 'Asset not found'), 200);
}

/**
Expand Down Expand Up @@ -717,7 +713,6 @@ public function restore($assetId = null)
$logaction->logaction('restored');

return response()->json(Helper::formatStandardApiResponse('success', null, trans('admin/hardware/message.restore.success')));


}
return response()->json(Helper::formatStandardApiResponse('error', null, trans('admin/hardware/message.does_not_exist')), 200);
Expand Down Expand Up @@ -821,8 +816,8 @@ public function checkin(Request $request, $asset_id)
$this->authorize('checkin', $asset);


$user = $asset->assignedUser;
if (is_null($target = $asset->assignedTo)) {
$target = $asset->assignedTo;
if (is_null($target)) {
return response()->json(Helper::formatStandardApiResponse('error', ['asset'=> e($asset->asset_tag)], trans('admin/hardware/message.checkin.already_checked_in')));
}

Expand All @@ -835,7 +830,7 @@ public function checkin(Request $request, $asset_id)
if ($request->filled('name')) {
$asset->name = $request->input('name');
}

$asset->location_id = $asset->rtd_location_id;

if ($request->filled('location_id')) {
Expand All @@ -852,7 +847,28 @@ public function checkin(Request $request, $asset_id)
return response()->json(Helper::formatStandardApiResponse('success', ['asset'=> 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.error')));
return response()->json(Helper::formatStandardApiResponse('error', ['asset'=> e($asset->asset_tag)], trans('admin/hardware/message.checkin.error')));
adagioajanes marked this conversation as resolved.
Show resolved Hide resolved
}

/**
* Checkin an asset by asset tag
*
* @author [A. Janes] [<[email protected]>]
* @since [v6.0]
* @return JsonResponse
*/
public function checkinByTag(Request $request)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other than using javascript to get the asset id by asset tag, this was the cleanest way of doing it in my mind. I'd rather the page not rely on a javascript call to get the asset id before pressing enter.

Thoughts?

{
$this->authorize('checkin', Asset::class);
$asset = Asset::where('asset_tag', $request->input('asset_tag'))->first();

if($asset) {
return $this->checkin($request, $asset->id);
}

return response()->json(Helper::formatStandardApiResponse('error', [
'asset'=> e($request->input('asset_tag'))
], 'Asset with tag '.e($request->input('asset_tag')).' not found'));
}


Expand All @@ -866,8 +882,6 @@ public function checkin(Request $request, $asset_id)
*/
public function audit(Request $request)
{


$this->authorize('audit', Asset::class);
$rules = [
'asset_tag' => 'required',
Expand Down Expand Up @@ -915,11 +929,6 @@ public function audit(Request $request)
}

return response()->json(Helper::formatStandardApiResponse('error', ['asset_tag'=> e($request->input('asset_tag'))], 'Asset with tag '.e($request->input('asset_tag')).' not found'));





}


Expand Down
7 changes: 7 additions & 0 deletions app/Http/Controllers/Assets/AssetsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -761,6 +761,13 @@ public function quickScan()
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();
Expand Down
1 change: 1 addition & 0 deletions resources/lang/en/admin/hardware/general.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
'archived' => 'Archived',
'asset' => 'Asset',
'bulk_checkout' => 'Checkout Assets',
'bulk_checkin' => 'Checkin Assets',
'checkin' => 'Checkin Asset',
'checkout' => 'Checkout Asset',
'clone' => 'Clone Asset',
Expand Down
2 changes: 2 additions & 0 deletions resources/lang/en/general.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,8 @@
'qty' => 'QTY',
'quantity' => 'Quantity',
'quantity_minimum' => 'You have :count items below or almost below minimum quantity levels',
'quickscan_checkin' => 'Quick Scan Checkin',
'quickscan_checkin_status' => 'Checkin Status',
'ready_to_deploy' => 'Ready to Deploy',
'recent_activity' => 'Recent Activity',
'remaining' => 'Remaining',
Expand Down
171 changes: 171 additions & 0 deletions resources/views/hardware/quickscan-checkin.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
@extends('layouts/default')

{{-- Page title --}}
@section('title')
{{ trans('general.quickscan_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('admin/hardware/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'])

<!-- 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.quickscan_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.quickscan_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.checkinbytag') }}",
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 + "</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) {
var asset = data.payload.asset;
} else {
var asset = '';
}
if (data.messages) {
var messages = data.messages;
} else {
var messages = '';
}
$('#checkedin tbody').prepend("<tr class='danger'><td>" + asset + "</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
8 changes: 8 additions & 0 deletions resources/views/layouts/default.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,14 @@
@endcan

<li class="divider">&nbsp;</li>
@can('checkin', \App\Models\Asset::class)
<li{!! (Request::is('hardware/quickscancheckin') ? ' class="active"' : '') !!}>
<a href="{{ route('hardware/quickscancheckin') }}">
{{ trans('general.quickscan_checkin') }}
</a>
</li>
@endcan

@can('checkout', \App\Models\Asset::class)
<li{!! (Request::is('hardware/bulkcheckout') ? ' class="active"' : '') !!}>
<a href="{{ route('hardware/bulkcheckout') }}">
Expand Down
7 changes: 7 additions & 0 deletions routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,13 @@
]
)->name('api.asset.checkin');

Route::post('checkinbytag',
[
Api\AssetsController::class,
'checkinbytag'
]
)->name('api.asset.checkinbytag');

Route::post('checkout',
[
Api\AssetsController::class,
Expand Down
4 changes: 4 additions & 0 deletions routes/web/hardware.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ function () {
[AssetsController::class, 'quickScan']
)->name('assets.bulkaudit');

Route::get('quickscancheckin',
[AssetsController::class, 'quickScanCheckin']
)->name('hardware/quickscancheckin');

// Asset Maintenances
Route::resource('maintenances',
AssetMaintenancesController::class, [
Expand Down