Skip to content

Commit 49ecc93

Browse files
authored
Merge pull request #17999 from grokability/updated-audit-report
Improved upcoming audit email layout and cli feedback
2 parents 1a3b221 + 1735fb6 commit 49ecc93

File tree

4 files changed

+103
-40
lines changed

4 files changed

+103
-40
lines changed

app/Console/Commands/SendUpcomingAuditReport.php

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function handle()
4747
$today = Carbon::now();
4848
$interval_date = $today->copy()->addDays($interval);
4949

50-
$assets = Asset::whereNull('deleted_at')->dueOrOverdueForAudit($settings)->orderBy('assets.next_audit_date', 'desc')->get();
50+
$assets = Asset::whereNull('deleted_at')->dueOrOverdueForAudit($settings)->orderBy('assets.next_audit_date', 'asc')->get();
5151
$this->info($assets->count() . ' assets must be audited in on or before ' . $interval_date . ' is deadline');
5252

5353

@@ -61,6 +61,28 @@ public function handle()
6161

6262
$this->info('Sending Admin SendUpcomingAuditNotification to: ' . $settings->alert_email);
6363
Mail::to($recipients)->send(new SendUpcomingAuditMail($assets, $settings->audit_warning_days));
64+
65+
$this->table(
66+
[
67+
trans('general.id'),
68+
trans('general.name'),
69+
trans('general.last_audit'),
70+
trans('general.next_audit_date'),
71+
trans('mail.Days'),
72+
trans('mail.supplier'),
73+
trans('mail.assigned_to'),
74+
75+
],
76+
$assets->map(fn($item) => [
77+
trans('general.id') => $item->id,
78+
trans('general.name') => $item->display_name,
79+
trans('general.last_audit') => $item->last_audit_formatted_date,
80+
trans('general.next_audit_date') => $item->next_audit_formatted_date,
81+
trans('mail.Days') => round($item->next_audit_diff_in_days),
82+
trans('mail.supplier') => $item->supplier ? $item->supplier->name : '',
83+
trans('mail.assigned_to') => $item->assignedTo ? $item->assignedTo->display_name : '',
84+
])
85+
);
6486
}
6587

6688
}

app/Models/Asset.php

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,54 @@ protected function warrantyExpiresDiffForHumans(): Attribute
308308

309309
}
310310

311+
312+
protected function lastAuditFormattedDate(): Attribute
313+
{
314+
315+
return Attribute:: make(
316+
get: fn(mixed $value, array $attributes) => Helper::getFormattedDateObject($this->last_audit_date, 'datetime', false)
317+
);
318+
}
319+
320+
protected function lastAuditDiff(): Attribute
321+
{
322+
return Attribute:: make(
323+
get: fn(mixed $value, array $attributes) => $this->warrantyExpires ? round((Carbon::now()->diffInDays($this->warrantyExpires))) : null,
324+
);
325+
326+
}
327+
328+
protected function lastAuditDiffForHumans(): Attribute
329+
{
330+
return Attribute:: make(
331+
get: fn(mixed $value, array $attributes) => $attributes['last_audit_date'] ? Carbon::parse($attributes['last_audit_date'])->diffForHumans() : null,
332+
);
333+
334+
}
335+
336+
protected function nextAuditFormattedDate(): Attribute
337+
{
338+
339+
return Attribute:: make(
340+
get: fn(mixed $value, array $attributes) => Helper::getFormattedDateObject($this->next_audit_date, 'date', false)
341+
);
342+
}
343+
344+
protected function nextAuditDiffInDays(): Attribute
345+
{
346+
return Attribute:: make(
347+
get: fn(mixed $value, array $attributes) => $attributes['next_audit_date'] ? Carbon::now()->diffInDays($attributes['next_audit_date']) : null,
348+
);
349+
}
350+
351+
protected function nextAuditDiffForHumans(): Attribute
352+
{
353+
return Attribute:: make(
354+
get: fn(mixed $value, array $attributes) => $attributes['next_audit_date'] ? Carbon::parse($attributes['next_audit_date'])->diffForHumans() : null,
355+
);
356+
357+
}
358+
311359
protected function eolDate(): Attribute
312360
{
313361

@@ -326,6 +374,7 @@ protected function eolDate(): Attribute
326374
}
327375

328376

377+
329378
protected function eolFormattedDate(): Attribute
330379
{
331380
return Attribute:: make(

app/Models/SnipeModel.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,22 +32,22 @@ protected function purchaseDateFormatted(): Attribute
3232
protected function expiresDiffInDays(): Attribute
3333
{
3434
return Attribute:: make(
35-
get: fn(mixed $value, array $attributes) => $attributes['expiration_date'] ? Carbon::now()->diffInDays($attributes['expiration_date']) : null,
35+
get: fn(mixed $value, array $attributes) => in_array('expiration_date', $attributes) ? Carbon::now()->diffInDays($attributes['expiration_date']) : null,
3636
);
3737
}
3838

3939

4040
protected function expiresDiffForHumans(): Attribute
4141
{
4242
return Attribute:: make(
43-
get: fn(mixed $value, array $attributes) => $attributes['expiration_date'] ? Carbon::parse($attributes['expiration_date'])->diffForHumans() : null,
43+
get: fn(mixed $value, array $attributes) => in_array('expiration_date', $attributes) ? Carbon::parse($attributes['expiration_date'])->diffForHumans() : null,
4444
);
4545
}
4646

4747
protected function expiresFormattedDate(): Attribute
4848
{
4949
return Attribute:: make(
50-
get: fn(mixed $value, array $attributes) => $attributes['expiration_date'] ? Helper::getFormattedDateObject($attributes['expiration_date'], 'date', false) : null,
50+
get: fn(mixed $value, array $attributes) => in_array('expiration_date', $attributes) ? Helper::getFormattedDateObject($attributes['expiration_date'], 'date', false) : null,
5151
);
5252
}
5353

Lines changed: 28 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,35 @@
11
@component('mail::message')
22

3-
### {{ trans_choice('mail.upcoming-audits', $assets->count(), ['count' => $assets->count(), 'threshold' => $threshold]) }}
4-
5-
6-
<table style="width:100%">
7-
<thead>
8-
<tr>
9-
<th style="vertical-align: top"> </th>
10-
<th style="vertical-align: top">{{ trans('mail.name') }}</th>
11-
<th style="vertical-align: top">{{ trans('general.last_audit') }}</th>
12-
<th style="vertical-align: top">{{ trans('general.next_audit_date') }}</th>
13-
<th style="vertical-align: top">{{ trans('mail.Days') }}</th>
14-
<th style="vertical-align: top">{{ trans('mail.supplier') }}</th>
15-
<th style="vertical-align: top">{{ trans('mail.assigned_to') }}</th>
16-
<th style="vertical-align: top">{{ trans('general.notes') }}</th>
17-
</tr>
18-
3+
{{ trans_choice('mail.upcoming-audits', $assets->count(), ['count' => $assets->count(), 'threshold' => $threshold]) }}
194

5+
<x-mail::table>
6+
| | | |
7+
| ------------- | ------------- | ------------- |
208
@foreach ($assets as $asset)
21-
@php
22-
$next_audit_date = Helper::getFormattedDateObject($asset->next_audit_date, 'date', false);
23-
$last_audit_date = Helper::getFormattedDateObject($asset->last_audit_date, 'date', false);
24-
$diff = (int) Carbon::parse(Carbon::now())->diffInDays($asset->next_audit_date, true);
25-
$icon = ($diff <= 7) ? '🚨' : (($diff <= 14) ? '⚠️' : ' ');
26-
@endphp
27-
28-
<tr>
29-
<td style="vertical-align: top">{{ $icon }}</td>
30-
<td style="vertical-align: top"><a href="{{ route('hardware.show', $asset->id) }}">{{ $asset->display_name }}</a></td>
31-
<td style="vertical-align: top">{{ $last_audit_date }}</td>
32-
<td style="vertical-align: top">{{ $next_audit_date }}</td>
33-
<td style="vertical-align: top">{{ $diff }}</td>
34-
<td style="vertical-align: top">{{ ($asset->supplier ? e($asset->supplier->name) : '') }}</td>
35-
<td style="vertical-align: top">{{ ($asset->assignedTo ? $asset->display_name : '') }}</td>
36-
<td style="vertical-align: top">{!! nl2br(e($asset->notes)) !!}</td>
37-
</tr>
38-
9+
| {{ ($asset->next_audit_diff_in_days <= 7) ? '🚨' : (($asset->next_audit_diff_in_days <= 14) ? '⚠️' : '⚠️') }} **{{ trans('mail.name') }}** | <a href="{{ route('hardware.show', $asset->id) }}">{{ $asset->display_name }}</a> |
10+
@if ($asset->serial)
11+
| **{{ trans('general.serial_number') }}** | {{ $asset->serial }} |
12+
@endif
13+
@if ($asset->purchase_date)
14+
| **{{ trans('general.purchase_date') }}** | {{ $asset->purchase_date_formatted }} |
15+
@endif
16+
@if ($asset->last_audit_date)
17+
| **{{ trans('general.last_audit') }}** | {{ $asset->last_audit_formatted_date }} ({{ $asset->last_audit_diff_for_humans }}) |
18+
@endif
19+
@if ($asset->next_audit_date)
20+
| **{{ trans('general.next_audit_date') }}** | {{ $asset->next_audit_formatted_date }} ({{ $asset->next_audit_diff_for_humans }}) |
21+
@endif
22+
@if ($asset->supplier)
23+
| **{{ trans('mail.supplier') }}** | {{ ($asset->supplier ? e($asset->supplier->name) : '') }} |
24+
@endif
25+
@if ($asset->assignedTo)
26+
| **{{ trans('mail.assigned_to') }}** | {{ e($asset->assignedTo->present()->display_name) }} |
27+
@endif
28+
| <hr> | <hr> |
3929
@endforeach
40-
</table>
41-
30+
</x-mail::table>
4231

32+
<x-mail::button :url="route('assets.audit.due')">
33+
{{ trans_choice('general.audit_due_days', $threshold, ['days' => $threshold]) }}
34+
</x-mail::button>
4335
@endcomponent

0 commit comments

Comments
 (0)