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

Improve Audit Functionality #7580

Closed
wants to merge 25 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
57c2df1
Update AssetsController.php
jacobsen9026 Nov 5, 2019
030ae4e
Update AssetsController.php
jacobsen9026 Nov 5, 2019
4786281
Add Checkout on Audit Setting
jacobsen9026 Nov 8, 2019
2b8dce3
Add Checkout on Audit
jacobsen9026 Nov 8, 2019
f7101ee
Add checkout_on_audit lang
jacobsen9026 Nov 8, 2019
778a317
Add Checkout On Audit setting functionality
jacobsen9026 Nov 8, 2019
38d2fa2
Add checkout on audit setting functionality
jacobsen9026 Nov 8, 2019
35524e8
Forgot to provide settings object
jacobsen9026 Nov 8, 2019
f2a7215
Provide settings object for bulk audit
jacobsen9026 Nov 8, 2019
e5dfe8e
Fixed checkout on audit logic
jacobsen9026 Nov 8, 2019
7536ea4
Fix checkout on audit logic
jacobsen9026 Nov 8, 2019
1cc9108
Fix for Issue 7437
jacobsen9026 Nov 9, 2019
f87641e
Bulk Checkin Routes
jacobsen9026 Nov 9, 2019
f71511f
Bulk Checkin Menu Item
jacobsen9026 Nov 9, 2019
bb13109
Bulk Checkin Functions
jacobsen9026 Nov 9, 2019
c372d81
Bulk Checkin Layout
jacobsen9026 Nov 9, 2019
ce1787a
Updated for bulkcheckin function
jacobsen9026 Nov 9, 2019
32e4cb9
Start serachDeployed function
jacobsen9026 Nov 9, 2019
5e10380
Bulk Checkin English Language reference
jacobsen9026 Nov 9, 2019
17aa72b
Bulk Checkin Layout
jacobsen9026 Nov 10, 2019
ac70a4b
Completed Deployed Search Query
jacobsen9026 Nov 10, 2019
2de964c
Update BulkAssetsController.php
jacobsen9026 Nov 10, 2019
c1f7f0b
Update BulkAssetModelsController.php
jacobsen9026 Nov 10, 2019
d290987
Update BulkAssetsController.php
jacobsen9026 Nov 10, 2019
f38151b
Added Bulk Checkin Title Reference
jacobsen9026 Nov 10, 2019
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
31 changes: 24 additions & 7 deletions app/Http/Controllers/Api/AssetsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -371,12 +371,23 @@ public function selectlist(Request $request)
'assets.status_id'
])->with('model', 'assetstatus', 'assignedTo')->NotArchived(), 'company_id', 'assets');

if ($request->filled('assetStatusType') && $request->input('assetStatusType') === 'RTD') {
$assets = $assets->RTD();
}

if ($request->filled('search')) {
$assets = $assets->AssignedSearch($request->input('search'));
if ($request->filled('assetStatusType')) {
switch ( $request->input('assetStatusType')){
case 'RTD':
$assets = $assets->RTD();
if ($request->filled('search')) {
$assets = $assets->AssignedSearch($request->input('search'));
}
break;
case 'Deployed':
$assets = $assets->Deployed();
if ($request->filled('search')) {
$assets = $assets->DeployedSearch($request->input('search'));
}
break;
default:
break;
}
}


Expand Down Expand Up @@ -753,6 +764,7 @@ public function checkin(Request $request, $asset_id)
public function audit(Request $request) {


$settings = Setting::getSettings();
$this->authorize('audit', Asset::class);
$rules = array(
'asset_tag' => 'required',
Expand Down Expand Up @@ -782,7 +794,12 @@ public function audit(Request $request) {

// Check to see if they checked the box to update the physical location,
// not just note it in the audit notes
if ($request->input('update_location')=='1') {
$target = Location::find($request->input('location_id'));
if ($settings->checkout_on_audit) {
if ((Location::find($asset->assignedTo['id']) != $target && $asset->assignedType() == Asset::LOCATION) || is_null($asset->assignedTo)) {
$asset->checkOut($target, Auth::user(), date('Y-m-d H:i:s'), '', 'Checked out on asset audit');
}
}else if ($request->input('update_location')=='1' && is_null($asset->assignedTo)) {
$asset->location_id = $request->input('location_id');
}

Expand Down
11 changes: 9 additions & 2 deletions app/Http/Controllers/Assets/AssetsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,7 @@ public function overdueForAudit()

public function auditStore(Request $request, $id)
{
$settings = Setting::getSettings();
$this->authorize('audit', Asset::class);

$rules = array(
Expand All @@ -759,8 +760,14 @@ public function auditStore(Request $request, $id)

// Check to see if they checked the box to update the physical location,
// not just note it in the audit notes
if ($request->input('update_location')=='1') {
\Log::debug('update location in audit');
$target = Location::find($request->input('location_id'));
if ($settings->checkout_on_audit) {
if ((Location::find($asset->assignedTo['id']) != $target && $asset->assignedType() == Asset::LOCATION) || is_null($asset->assignedTo)) {
$asset->checkOut($target, Auth::user(), date('Y-m-d H:i:s'), '', 'Checked out on asset audit');
}
}else if ($request->input('update_location')=='1' && is_null($asset->assignedTo)) {
$asset->location_id = $request->input('location_id');
\Log::debug('update location in audit');
$asset->location_id = $request->input('location_id');
}

Expand Down
83 changes: 83 additions & 0 deletions app/Http/Controllers/Assets/BulkAssetsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,19 @@ public function showCheckout()

return view('hardware/bulk-checkout');
}

/**
* Show Bulk Checkin Page
* @return View View to checkin multiple assets
*/
public function showCheckin()
{
$this->authorize('checkin', Asset::class);
// Filter out assets that are not checked out.

return view('hardware/bulk-checkin');
}


/**
* Process Multiple Checkout Request
Expand Down Expand Up @@ -252,4 +265,74 @@ public function storeCheckout(Request $request)
return redirect()->to("hardware/bulk-checkout")->with('error', $e->getErrors());
}
}

/**
* Process Multiple Checkin Request
* @return View
*/
public function storeCheckin(Request $request)
{
try {
$admin = Auth::user();

//$target = $this->determineCheckinTarget();

if (!is_array($request->get('selected_assets'))) {
return redirect()->route('hardware/bulkcheckin')->withInput()->with('error', trans('admin/hardware/message.checkout.no_assets_selected'));
}

$asset_ids = array_filter($request->get('selected_assets'));

$checkin_at = date("Y-m-d H:i:s");
if (($request->filled('checkin_at')) && ($request->get('checkin_at')!= date("Y-m-d"))) {
$checkin_at = e($request->get('checkin_at'));
}


$errors = [];


foreach ($asset_ids as $asset_id) {
$this->authorize('checkin', Asset::class);
$asset = Asset::findOrFail($asset_id);
$this->authorize('checkin', $asset);


$user = $asset->assignedUser;
if (is_null($target = $asset->assignedTo)) {
continue;
}

$asset->expected_checkin = null;
$asset->last_checkout = null;
$asset->assigned_to = null;
$asset->assignedTo()->disassociate($asset);
$asset->accepted = null;


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

if ($request->filled('location_id')) {
$asset->location_id = $request->get('location_id');
}


if ($asset->save()) {
$asset->logCheckin($target, e(request('note')));
}

}


if (!$errors) {
// Redirect to the new asset page
return redirect()->to("hardware")->with('success', trans('admin/hardware/message.checkin.success'));
}
// Redirect to the asset management page with error
return redirect()->to("hardware/bulk-checkin")->with('error', trans('admin/hardware/message.checkin.error'))->withErrors($errors);
} catch (ModelNotFoundException $e) {
return redirect()->to("hardware/bulk-checkin")->with('error', $e->getErrors());
}
}

}
2 changes: 2 additions & 0 deletions app/Http/Controllers/BulkAssetModelsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,5 +134,7 @@ public function destroy()
->with('error', trans('admin/models/message.bulkdelete.error'));

}



}
3 changes: 2 additions & 1 deletion app/Http/Controllers/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -327,13 +327,14 @@ public function postSettings(Request $request)

$setting->full_multiple_companies_support = $request->input('full_multiple_companies_support', '0');
$setting->unique_serial = $request->input('unique_serial', '0');
$setting->checkout_on_audit = $request->input('checkout_on_audit','0');
$setting->show_images_in_email = $request->input('show_images_in_email', '0');
$setting->show_archived_in_list = $request->input('show_archived_in_list', '0');
$setting->dashboard_message = $request->input('dashboard_message');
$setting->email_domain = $request->input('email_domain');
$setting->email_format = $request->input('email_format');
$setting->username_format = $request->input('username_format');
$setting->require_accept_signature = $request->input('require_accept_signature');
$setting->require_accept_signature = $request->input('require_accept_signature', '0');
if (! config('app.lock_passwords')) {
$setting->login_note = $request->input('login_note');
}
Expand Down
44 changes: 44 additions & 0 deletions app/Models/Asset.php
Original file line number Diff line number Diff line change
Expand Up @@ -1234,6 +1234,50 @@ public function scopeAssignedSearch($query, $search)
}
})->withTrashed()->whereNull("assets.deleted_at"); //workaround for laravel bug
}





/**
* Query builder scope to search on text for complex Bootstrap Tables API.
*
* @param \Illuminate\Database\Query\Builder $query Query builder instance
* @param text $search Search term
*
* @return \Illuminate\Database\Query\Builder Modified query builder
*/
public function scopeDeployedSearch($query, $search)
{
$search = explode(' OR ', $search);

return $query->where(function ($query) use ($search) {
foreach ($search as $search) {
$query->whereHas('model', function ($query) use ($search) {
$query->whereHas('category', function ($query) use ($search) {
$query->where(function ($query) use ($search) {
$query->where('categories.name', 'LIKE', '%'.$search.'%')
->orWhere('models.name', 'LIKE', '%'.$search.'%')
->orWhere('models.model_number', 'LIKE', '%'.$search.'%');
});
});
})->orWhereHas('model', function ($query) use ($search) {
$query->whereHas('manufacturer', function ($query) use ($search) {
$query->where(function ($query) use ($search) {
$query->where('manufacturers.name', 'LIKE', '%'.$search.'%');
});
});
})->orWhere('assets.name', 'LIKE', '%'.$search.'%')
->orWhere('assets.asset_tag', 'LIKE', '%'.$search.'%')
->orWhere('assets.serial', 'LIKE', '%'.$search.'%')
->orWhere('assets.order_number', 'LIKE', '%'.$search.'%')
->orWhere('assets.notes', 'LIKE', '%'.$search.'%');
}

})->withTrashed()->whereNull("assets.deleted_at"); //workaround for laravel bug
}



/**
* Query builder scope to search the department ID of users assigned to assets
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 @@ -3,6 +3,7 @@
return array(
'archived' => 'Archived',
'asset' => 'Asset',
'bulk_checkin' => 'Checkin Assets',
'bulk_checkout' => 'Checkout Assets',
'checkin' => 'Checkin Asset',
'checkout' => 'Checkout 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 @@ -29,6 +29,7 @@
'bad_data' => 'Nothing found. Maybe bad data?',
'bulkaudit' => 'Bulk Audit',
'bulkaudit_status' => 'Audit Status',
'bulk_checkin' => 'Bulk Checkin',
'bulk_checkout' => 'Bulk Checkout',
'bystatus' => 'by Status',
'cancel' => 'Cancel',
Expand All @@ -41,6 +42,7 @@
'checkin_from' => 'Checkin from',
'checkout' => 'Checkout',
'checkouts_count' => 'Checkouts',
'checkout_on_audit' => 'Checkout on Audit',
'checkins_count' => 'Checkins',
'user_requests_count' => 'Requests',
'city' => 'City',
Expand Down
93 changes: 93 additions & 0 deletions resources/views/hardware/bulk-checkin.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
@extends('layouts/default')

{{-- Page title --}}
@section('title')
{{ trans('admin/hardware/general.bulk_checkin') }}
@parent
@stop

{{-- Page content --}}
@section('content')

<style>
.input-group {
padding-left: 0px !important;
}
</style>


<div class="row">
<!-- left column -->
<div class="col-md-7">
<div class="box box-default">
<div class="box-header with-border">
<h3 class="box-title"> {{ trans('admin/hardware/form.tag') }} </h3>
</div>
<div class="box-body">
<form class="form-horizontal" method="post" action="" autocomplete="off">
{{ csrf_field() }}



<!-- Checkout/Checkin Date -->
<div class="form-group{{ $errors->has('checkin_at') ? ' has-error' : '' }}">
{{ Form::label('checkin_at', trans('admin/hardware/form.checkin_date'), array('class' => 'col-md-3 control-label')) }}
<div class="col-md-8">
<div class="input-group col-md-5 required">
<div class="input-group date" data-provide="datepicker" data-date-format="yyyy-mm-dd" data-autoclose="true">
<input type="text" class="form-control" placeholder="{{ trans('general.select_date') }}" name="checkin_at" id="checkin_at" value="{{ Input::old('checkin_at', date('Y-m-d')) }}">
<span class="input-group-addon"><i class="fa fa-calendar"></i></span>
</div>
{!! $errors->first('checkin_at', '<span class="alert-msg"><i class="fa fa-times"></i> :message</span>') !!}
</div>
</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">{{ Input::old('note') }}</textarea>
{!! $errors->first('note', '<span class="alert-msg"><i class="fa fa-times"></i> :message</span>') !!}
</div>
</div>

@include ('partials.forms.edit.asset-select', [
'translated_name' => trans('general.assets'),
'fieldname' => 'selected_assets[]',
'multiple' => true,
'select_id' => 'assigned_assets_select',
'asset_status_type' => 'Deployed',
])

</div> <!--./box-body-->
<div class="box-footer">
<a class="btn btn-link" href="{{ URL::previous() }}"> {{ trans('button.cancel') }}</a>
<button type="submit" class="btn btn-success pull-right"><i class="fa fa-check icon-white"></i> {{ trans('general.checkin') }}</button>
</div>
</div>
</form>
</div> <!--/.col-md-7-->

<!-- right column -->
<div class="col-md-5" id="current_assets_box" style="display:none;">
<div class="box box-primary">
<div class="box-header with-border">
<h3 class="box-title">{{ trans('admin/users/general.current_assets') }}</h3>
</div>
<div class="box-body">
<div id="current_assets_content">
</div>
</div>
</div>
</div>
</div>
@stop

@section('moar_scripts')
@include('partials/assets-assigned')

@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 @@ -439,6 +439,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') }}">
Expand Down
Loading