De-norm last audit date so we can display it in the asset listing

This commit is contained in:
snipe 2017-12-12 03:03:43 -08:00
parent c5c46b7283
commit c816870083
7 changed files with 103 additions and 1 deletions

View file

@ -72,6 +72,8 @@ class AssetsController extends Controller
'updated_at',
'purchase_date',
'purchase_cost',
'last_audit_date',
'next_audit_date',
'warranty_months',
];
@ -675,7 +677,11 @@ class AssetsController extends Controller
if ($asset) {
// We don't want to log this as a normal update, so let's bypass that
$asset->unsetEventDispatcher();
$asset->next_audit_date = $request->input('next_audit_date');
$asset->last_audit_date = date('Y-m-d h:i:s');
if ($asset->save()) {
$log = $asset->logAudit(request('note'),request('location_id'));
return response()->json(Helper::formatStandardApiResponse('success', [

View file

@ -535,6 +535,14 @@ class ReportsController extends Controller
$header[] = trans('general.updated_at');
}
if ($request->has('last_audit_date')) {
$header[] = trans('general.last_audit');
}
if ($request->has('next_audit_date')) {
$header[] = trans('general.next_audit_date');
}
if ($request->has('notes')) {
$header[] = trans('general.notes');
}
@ -709,6 +717,14 @@ class ReportsController extends Controller
$row[] = ($asset->updated_at) ? $asset->updated_at : '';
}
if ($request->has('last_audit_date')) {
$row[] = ($asset->last_audit_date) ? $asset->last_audit_date : '';
}
if ($request->has('next_audit_date')) {
$row[] = ($asset->next_audit_date) ? $asset->next_audit_date : '';
}
if ($request->has('notes')) {
$row[] = ($asset->notes) ? $asset->notes : '';
}

View file

@ -69,6 +69,8 @@ class AssetsTransformer
'warranty_expires' => ($asset->warranty_months > 0) ? Helper::getFormattedDateObject($asset->warranty_expires, 'date') : null,
'created_at' => Helper::getFormattedDateObject($asset->created_at, 'datetime'),
'updated_at' => Helper::getFormattedDateObject($asset->updated_at, 'datetime'),
'last_audit_date' => Helper::getFormattedDateObject($asset->last_audit_date, 'datetime'),
'next_audit_date' => Helper::getFormattedDateObject($asset->next_audit_date, 'date'),
'deleted_at' => Helper::getFormattedDateObject($asset->deleted_at, 'datetime'),
'purchase_date' => Helper::getFormattedDateObject($asset->purchase_date, 'date'),
'last_checkout' => Helper::getFormattedDateObject($asset->last_checkout, 'datetime'),

View file

@ -49,7 +49,9 @@ class Asset extends Depreciable
'deleted_at',
'purchase_date',
'last_checkout',
'expected_checkin'
'expected_checkin',
'last_audit_date',
'next_audit_date'
];
@ -68,6 +70,7 @@ class Asset extends Depreciable
'status' => 'integer',
'purchase_cost' => 'numeric|nullable',
'next_audit_date' => 'date|nullable',
'last_audit_date' => 'date|nullable',
];
/**

View file

@ -201,6 +201,20 @@ class AssetPresenter extends Presenter
"visible" => false,
"title" => trans('admin/hardware/form.expected_checkin'),
"formatter" => "dateDisplayFormatter"
], [
"field" => "last_audit_date",
"searchable" => false,
"sortable" => true,
"visible" => false,
"title" => trans('general.last_audit'),
"formatter" => "dateDisplayFormatter"
], [
"field" => "next_audit_date",
"searchable" => false,
"sortable" => true,
"visible" => false,
"title" => trans('general.next_audit_date'),
"formatter" => "dateDisplayFormatter"
],
];

View file

@ -0,0 +1,49 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
use App\Models\Actionlog;
use App\Models\Asset;
class NormalizeAssetLastAuditDate extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('assets', function (Blueprint $table) {
$table->datetime('last_audit_date')->after('assigned_type')->nullable()->default(null);
});
// Grab the latest info from the Actionlog table where the action is 'audit'
$audits = Actionlog::selectRaw('MAX(created_at) AS created_at, item_id')->where('action_type', 'audit')->where('item_type', Asset::class)->groupBy('item_id')->orderBy('created_at', 'desc')->get();
if ($audits) {
foreach ($audits as $audit) {
$assets = Asset::where('id', $audit->item_id)->first();
$assets->last_audit_date = $audit->created_at;
$assets->unsetEventDispatcher();
$assets->save();
}
}
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('assets', function (Blueprint $table) {
$table->dropColumn('last_audit_date');
});
}
}

View file

@ -176,6 +176,18 @@
{{ trans('general.updated_at') }}
</label>
</div>
<div class="checkbox col-md-12">
<label>
{{ Form::checkbox('last_audit_date', '1', '1', ['class' => 'minimal']) }}
{{ trans('general.last_audit') }}
</label>
</div>
<div class="checkbox col-md-12">
<label>
{{ Form::checkbox('next_audit_date', '1', '1', ['class' => 'minimal']) }}
{{ trans('general.next_audit_date') }}
</label>
</div>
<div class="checkbox col-md-12">
<label>
{{ Form::checkbox('notes', '1', '1', ['class' => 'minimal']) }}