mirror of
https://github.com/snipe/snipe-it.git
synced 2025-10-30 03:42:35 +00:00
Limit the email to 30 records, added optional --with-output
This commit is contained in:
parent
2b4986571c
commit
9d8f251fc4
@ -16,7 +16,7 @@ class SendUpcomingAuditReport extends Command
|
|||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $signature = 'snipeit:upcoming-audits';
|
protected $signature = 'snipeit:upcoming-audits {--with-output : Display the results in a table in your console in addition to sending the email}';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The console command description.
|
* The console command description.
|
||||||
@ -47,20 +47,38 @@ class SendUpcomingAuditReport extends Command
|
|||||||
$today = Carbon::now();
|
$today = Carbon::now();
|
||||||
$interval_date = $today->copy()->addDays($interval);
|
$interval_date = $today->copy()->addDays($interval);
|
||||||
|
|
||||||
$assets = Asset::whereNull('deleted_at')->dueOrOverdueForAudit($settings)->orderBy('assets.next_audit_date', 'asc')->get();
|
$assets_query = Asset::whereNull('deleted_at')->dueOrOverdueForAudit($settings)->orderBy('assets.next_audit_date', 'asc')->with('supplier');
|
||||||
$this->info($assets->count() . ' assets must be audited in on or before ' . $interval_date . ' is deadline');
|
$asset_count = $assets_query->count();
|
||||||
|
$this->info(number_format($asset_count) . ' assets must be audited in on or before ' . $interval_date);
|
||||||
|
|
||||||
|
|
||||||
if ((count($assets) !== 0) && ($assets->count() > 0) && ($settings->alert_email != '')) {
|
|
||||||
|
if ($asset_count > 0) {
|
||||||
|
|
||||||
|
$assets_for_email = $assets_query->limit(30)->get();
|
||||||
|
|
||||||
// Send a rollup to the admin, if settings dictate
|
// Send a rollup to the admin, if settings dictate
|
||||||
|
if ($settings->alert_email != '') {
|
||||||
|
|
||||||
$recipients = collect(explode(',', $settings->alert_email))
|
$recipients = collect(explode(',', $settings->alert_email))
|
||||||
->map(fn($item) => trim($item))
|
->map(fn($item) => trim($item))
|
||||||
->filter(fn($item) => !empty($item))
|
->filter(fn($item) => !empty($item))
|
||||||
->all();
|
->all();
|
||||||
|
|
||||||
|
Mail::to($recipients)->send(new SendUpcomingAuditMail($assets_for_email, $settings->audit_warning_days, $asset_count));
|
||||||
|
$this->info('Audit notification sent to: ' . $settings->alert_email);
|
||||||
|
|
||||||
$this->info('Sending Admin SendUpcomingAuditNotification to: ' . $settings->alert_email);
|
} else {
|
||||||
Mail::to($recipients)->send(new SendUpcomingAuditMail($assets, $settings->audit_warning_days));
|
$this->info('There is no admin alert email set so no email will be sent.');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if ($this->option('with-output')) {
|
||||||
|
|
||||||
|
|
||||||
|
// Get the full list if the user wants output in the console
|
||||||
|
$assets_for_output = $assets_query->limit(null)->get();
|
||||||
|
|
||||||
$this->table(
|
$this->table(
|
||||||
[
|
[
|
||||||
@ -73,7 +91,7 @@ class SendUpcomingAuditReport extends Command
|
|||||||
trans('mail.assigned_to'),
|
trans('mail.assigned_to'),
|
||||||
|
|
||||||
],
|
],
|
||||||
$assets->map(fn($item) => [
|
$assets_for_output->map(fn($item) => [
|
||||||
trans('general.id') => $item->id,
|
trans('general.id') => $item->id,
|
||||||
trans('general.name') => $item->display_name,
|
trans('general.name') => $item->display_name,
|
||||||
trans('general.last_audit') => $item->last_audit_formatted_date,
|
trans('general.last_audit') => $item->last_audit_formatted_date,
|
||||||
@ -85,5 +103,11 @@ class SendUpcomingAuditReport extends Command
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
$this->info('There are no assets due for audit in the next ' . $interval . ' days.');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -17,10 +17,11 @@ class SendUpcomingAuditMail extends Mailable
|
|||||||
/**
|
/**
|
||||||
* Create a new message instance.
|
* Create a new message instance.
|
||||||
*/
|
*/
|
||||||
public function __construct($params, $threshold)
|
public function __construct($params, $threshold, $total)
|
||||||
{
|
{
|
||||||
$this->assets = $params;
|
$this->assets = $params;
|
||||||
$this->threshold = $threshold;
|
$this->threshold = $threshold;
|
||||||
|
$this->total = $total;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -32,7 +33,7 @@ class SendUpcomingAuditMail extends Mailable
|
|||||||
|
|
||||||
return new Envelope(
|
return new Envelope(
|
||||||
from: $from,
|
from: $from,
|
||||||
subject: trans_choice('mail.upcoming-audits', $this->assets->count(), ['count' => $this->assets->count(), 'threshold' => $this->threshold]),
|
subject: trans_choice('mail.upcoming-audits', $this->total, ['count' => $this->total, 'threshold' => $this->threshold]),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -49,6 +50,7 @@ class SendUpcomingAuditMail extends Mailable
|
|||||||
with: [
|
with: [
|
||||||
'assets' => $this->assets,
|
'assets' => $this->assets,
|
||||||
'threshold' => $this->threshold,
|
'threshold' => $this->threshold,
|
||||||
|
'total' => $this->total,
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -350,6 +350,7 @@ return [
|
|||||||
'login_disabled' => 'Login Disabled',
|
'login_disabled' => 'Login Disabled',
|
||||||
'audit_due' => 'Due for Audit',
|
'audit_due' => 'Due for Audit',
|
||||||
'audit_due_days' => '{}Assets Due or Overdue for Audit|[1]Assets Due or Overdue for Audit Within a Day|[2,*]Assets Due or Overdue for Audit Within :days Days',
|
'audit_due_days' => '{}Assets Due or Overdue for Audit|[1]Assets Due or Overdue for Audit Within a Day|[2,*]Assets Due or Overdue for Audit Within :days Days',
|
||||||
|
'audit_due_days_view_all' => '{}Assets Due or Overdue for Audit|[1]View All Assets Due or Overdue for Audit Within a Day|[2,*]View All Assets Due or Overdue for Audit Within :days Days',
|
||||||
'checkin_due' => 'Due for Checkin',
|
'checkin_due' => 'Due for Checkin',
|
||||||
'checkin_overdue' => 'Overdue for Checkin',
|
'checkin_overdue' => 'Overdue for Checkin',
|
||||||
'checkin_due_days' => '{}Due for Checkin|[1]Assets Due for Checkin Within :days Day|[2,*]Assets Due for Checkin Within :days Days',
|
'checkin_due_days' => '{}Due for Checkin|[1]Assets Due for Checkin Within :days Day|[2,*]Assets Due for Checkin Within :days Days',
|
||||||
|
|||||||
@ -100,7 +100,8 @@ return [
|
|||||||
'the_following_item' => 'The following item has been checked in: ',
|
'the_following_item' => 'The following item has been checked in: ',
|
||||||
'to_reset' => 'To reset your :web password, complete this form:',
|
'to_reset' => 'To reset your :web password, complete this form:',
|
||||||
'type' => 'Type',
|
'type' => 'Type',
|
||||||
'upcoming-audits' => 'There is :count asset that is coming up for audit within :threshold days.|There are :count assets that are coming up for audit within :threshold days.',
|
'upcoming-audits' => 'There is :count asset that is coming up for audit within :threshold days.|There are :count assets that are coming up for audit within :threshold days. ',
|
||||||
|
'upcoming-audits_click' => 'This email may not contain the full list so as not to exceed email size limits. Click on the button below to view all assets due for audit.',
|
||||||
'user' => 'User',
|
'user' => 'User',
|
||||||
'username' => 'Username',
|
'username' => 'Username',
|
||||||
'unaccepted_asset_reminder' => 'Reminder: You have Unaccepted Assets.',
|
'unaccepted_asset_reminder' => 'Reminder: You have Unaccepted Assets.',
|
||||||
|
|||||||
@ -1,12 +1,17 @@
|
|||||||
@component('mail::message')
|
@component('mail::message')
|
||||||
|
|
||||||
{{ trans_choice('mail.upcoming-audits', $assets->count(), ['count' => $assets->count(), 'threshold' => $threshold]) }}
|
{{ trans_choice('mail.upcoming-audits', $total, ['count' => $total, 'threshold' => $threshold]) }}
|
||||||
|
{{ trans('mail.upcoming-audits_click') }}
|
||||||
|
|
||||||
|
<x-mail::button :url="route('assets.audit.due')">
|
||||||
|
{{ trans_choice('general.audit_due_days_view_all', $threshold, ['days' => $threshold]) }}
|
||||||
|
</x-mail::button>
|
||||||
|
|
||||||
<x-mail::table>
|
<x-mail::table>
|
||||||
| | | |
|
| | | |
|
||||||
| ------------- | ------------- | ------------- |
|
| ------------- | ------------- | ------------- |
|
||||||
@foreach ($assets as $asset)
|
@foreach ($assets as $asset)
|
||||||
| {{ ($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> |
|
| {{ ($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> (<a href="{{ route('asset.audit.create', $asset->id) }}">{{ trans('general.audit') }}</a>)|
|
||||||
@if ($asset->serial)
|
@if ($asset->serial)
|
||||||
| **{{ trans('general.serial_number') }}** | {{ $asset->serial }} |
|
| **{{ trans('general.serial_number') }}** | {{ $asset->serial }} |
|
||||||
@endif
|
@endif
|
||||||
@ -33,6 +38,6 @@
|
|||||||
</x-mail::table>
|
</x-mail::table>
|
||||||
|
|
||||||
<x-mail::button :url="route('assets.audit.due')">
|
<x-mail::button :url="route('assets.audit.due')">
|
||||||
{{ trans_choice('general.audit_due_days', $threshold, ['days' => $threshold]) }}
|
{{ trans_choice('general.audit_due_days_view_all', $threshold, ['days' => $threshold]) }}
|
||||||
</x-mail::button>
|
</x-mail::button>
|
||||||
@endcomponent
|
@endcomponent
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user