Skip to content

Commit 16420b1

Browse files
committed
Audit Log Number under Days to next Audit [sc-28530]
Signed-off-by: snipe <[email protected]>
1 parent 62f66e7 commit 16420b1

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

app/Models/Actionlog.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -293,16 +293,22 @@ public function logaction($actiontype)
293293
public function daysUntilNextAudit($monthInterval = 12, $asset = null)
294294
{
295295
$now = Carbon::now();
296-
$last_audit_date = $this->created_at;
297-
$next_audit = $last_audit_date->addMonth($monthInterval);
298-
$next_audit_days = $now->diffInDays($next_audit);
296+
$last_audit_date = $this->created_at; // this is the action log's created at, not the asset itself
297+
$next_audit = $last_audit_date->addMonth($monthInterval); // this actually *modifies* the $last_audit_date
298+
$next_audit_days = round($now->diffInDays($next_audit, true));
299+
$override_default_next = $next_audit;
299300

300301
// Override the default setting for interval if the asset has its own next audit date
301302
if (($asset) && ($asset->next_audit_date)) {
302-
$override_default_next = \Carbon::parse($asset->next_audit_date);
303-
$next_audit_days = $override_default_next->diffInDays($now);
303+
$override_default_next = Carbon::parse($asset->next_audit_date);
304+
$next_audit_days = round($override_default_next->diffInDays($now, true));
304305
}
305306

307+
// Show as negative number if the next audit date is before the audit date we're looking at
308+
if ($this->created_at > $override_default_next) {
309+
$next_audit_days = '-'.$next_audit_days;
310+
}
311+
306312
return $next_audit_days;
307313
}
308314

resources/views/reports/audit.blade.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,12 @@ class="table table-striped snipe-table"
3535
<thead>
3636
<tr>
3737
<th class="col-sm-1" data-field="file" data-visible="false" data-formatter="auditImageFormatter">{{ trans('admin/hardware/table.image') }}</th>
38-
<th class="col-sm-2" data-field="created_at" data-formatter="dateDisplayFormatter" data-sortable="true" data-searchable="true">{{ trans('general.audit') }}</th>
39-
<th class="col-sm-2" data-field="created_by" data-sortable="true" data-searchable="true" data-formatter="usersLinkObjFormatter">{{ trans('general.admin') }}</th>
38+
<th class="col-sm-2" data-field="created_by" data-sortable="true" data-searchable="true" data-formatter="usersLinkObjFormatter">{{ trans('general.created_by') }}</th>
4039
<th class="col-sm-2" data-field="item" data-sortable="true" data-searchable="true" data-formatter="polymorphicItemFormatter">{{ trans('general.item') }}</th>
4140
<th class="col-sm-1" data-field="location" data-sortable="true" data-searchable="true" data-formatter="locationsLinkObjFormatter">{{ trans('general.location') }}</th>
41+
<th class="col-sm-2" data-field="created_at" data-formatter="dateDisplayFormatter" data-sortable="true" data-searchable="true">{{ trans('general.last_audit') }}</th>
4242
<th class="col-sm-2" data-field="next_audit_date" data-formatter="dateDisplayFormatter">{{ trans('general.next_audit_date') }}</th>
4343
<th class="col-sm-1" data-field="days_to_next_audit">{{ trans('general.days_to_next_audit') }}</th>
44-
4544
<th class="col-sm-2" data-field="note" data-sortable="true" data-searchable="true">{{ trans('general.notes') }}</th>
4645
</tr>
4746
</thead>

0 commit comments

Comments
 (0)