Added scope for both overdue and upcoming

This commit is contained in:
snipe 2019-05-05 22:13:30 -04:00
parent 00a8a2aff3
commit e4a298ca2a
4 changed files with 26 additions and 3 deletions

View file

@ -58,7 +58,7 @@ class SendUpcomingAuditReport extends Command
// Assets due for auditing
$assets = Asset::whereNotNull('next_audit_date')
->dueForAudit($settings)
->DueOrOverdueForAudit($settings)
->orderBy('last_audit_date', 'asc')->get();
if ($assets->count() > 0) {

View file

@ -153,7 +153,7 @@ class AssetsController extends Controller
switch ($audit) {
case 'due':
$assets->DueForAudit($settings);
$assets->DueOrOverdueForAudit($settings);
break;
case 'overdue':
$assets->overdueForAudit($settings);

View file

@ -850,6 +850,29 @@ class Asset extends Depreciable
->NotArchived();
}
/**
* Query builder scope for Assets that are due for auditing OR overdue, based on the assets.next_audit_date
* and settings.audit_warning_days.
*
* This is/will be used in the artisan command snipeit:upcoming-audits and also
* for an upcoming API call for retrieving a report on assets that will need to be audited.
*
* @author A. Gianotto <snipe@snipe.net>
* @since v4.5.17
* @param Setting $settings
*
* @return \Illuminate\Database\Query\Builder Modified query builder
*/
public function scopeDueOrOverdueForAudit($query, $settings)
{
return $query->whereNotNull('assets.next_audit_date')
->whereRaw("DATE_SUB(assets.next_audit_date, INTERVAL $settings->audit_warning_days DAY) <= '".Carbon::now()."'")
->where('assets.archived', '=', 0)
->NotArchived();
}
/**
* Query builder scope for Archived assets
*

View file

@ -9,7 +9,7 @@
@php
$next_audit_date = \App\Helpers\Helper::getFormattedDateObject($asset->next_audit_date, 'date', false);
$last_audit_date = \App\Helpers\Helper::getFormattedDateObject($asset->last_audit_date, 'date', false);
$diff = Carbon::parse($next_audit_date)->diffInDays(Carbon::now());
$diff = Carbon::parse(Carbon::now())->diffInDays($next_audit_date, false);
$icon = ($diff <= 7) ? '🚨' : (($diff <= 14) ? '⚠️' : ' ');
@endphp
|{{ $icon }}| [{{ $asset->present()->name }}]({{ route('hardware.show', $asset->id) }}) | {{ $last_audit_date }}| {{ $next_audit_date }} | {{ $diff }} | {{ ($asset->supplier ? e($asset->supplier->name) : '') }}|{{ ($asset->assignedTo ? $asset->assignedTo->present()->name() : '') }}