Skip to content

Commit

Permalink
Removed a bunch of redundant code I created from the API
Browse files Browse the repository at this point in the history
  • Loading branch information
adagioajanes committed Dec 19, 2021
1 parent bc4fe88 commit 29da4f4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 81 deletions.
63 changes: 7 additions & 56 deletions app/Http/Controllers/Api/AssetsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -821,8 +821,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 Down Expand Up @@ -852,15 +852,15 @@ 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')));
}

/**
* 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 the current solution to perform a bulk api 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] [<[email protected]>]
* @author [A. Janes] [<[email protected]>]
* @param int $assetId
* @since [v4.0]
* @return JsonResponse
Expand All @@ -871,57 +871,12 @@ public function bulkCheckin(Request $request)
$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 $this->checkin($request, $asset->id);
}

return response()->json(Helper::formatStandardApiResponse('error', [
'asset_tag'=> e($request->input('asset_tag'))
'asset'=> 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'));
}


Expand Down Expand Up @@ -985,10 +940,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
30 changes: 5 additions & 25 deletions resources/views/hardware/quickscan-checkin.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,26 +45,6 @@
@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">
Expand Down Expand Up @@ -137,7 +117,7 @@
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>");
$('#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);
Expand All @@ -157,17 +137,17 @@
});
function handlecheckinFail (data) {
if (data.payload.asset_tag) {
var asset_tag = data.payload.asset_tag;
if (data.payload.asset) {
var asset = data.payload.asset;
} else {
var asset_tag = '';
var asset = '';
}
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>");
$('#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() {
Expand Down

0 comments on commit 29da4f4

Please sign in to comment.