Merge pull request #18190 from grokability/improved-checkin-reminders
Improved overdue checkin alert
This commit is contained in:
@@ -9,6 +9,8 @@ use App\Notifications\ExpectedCheckinAdminNotification;
|
||||
use App\Notifications\ExpectedCheckinNotification;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Notification;
|
||||
use App\Helpers\Helper;
|
||||
|
||||
class SendExpectedCheckinAlerts extends Command
|
||||
{
|
||||
@@ -17,7 +19,7 @@ class SendExpectedCheckinAlerts extends Command
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'snipeit:expected-checkin';
|
||||
protected $signature = 'snipeit:expected-checkin {--with-output : Display the results in a table in your console in addition to sending the email}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
@@ -42,19 +44,47 @@ class SendExpectedCheckinAlerts extends Command
|
||||
public function handle()
|
||||
{
|
||||
$settings = Setting::getSettings();
|
||||
$interval = $settings->audit_warning_days ?? 0;
|
||||
$interval = $settings->due_checkin_days ?? 0;
|
||||
$today = Carbon::now();
|
||||
$interval_date = $today->copy()->addDays($interval);
|
||||
|
||||
$count = 0;
|
||||
|
||||
if (!$this->option('with-output')) {
|
||||
$this->info('Run this command with the --with-output option to see the full list in the console.');
|
||||
}
|
||||
|
||||
$assets = Asset::whereNull('deleted_at')->DueOrOverdueForCheckin($settings)->orderBy('assets.expected_checkin', 'desc')->get();
|
||||
|
||||
$this->info($assets->count().' assets must be checked in on or before '.$interval_date.' is deadline');
|
||||
$this->info($assets->count().' assets must be checked on or before '.Helper::getFormattedDateObject($interval_date, 'date', false));
|
||||
|
||||
|
||||
foreach ($assets as $asset) {
|
||||
if ($asset->assignedTo && (isset($asset->assignedTo->email)) && ($asset->assignedTo->email!='') && $asset->checkedOutToUser()) {
|
||||
$this->info('Sending User ExpectedCheckinNotification to: '.$asset->assignedTo->email);
|
||||
$asset->assignedTo->notify((new ExpectedCheckinNotification($asset)));
|
||||
$count++;
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->option('with-output')) {
|
||||
if (($assets) && ($assets->count() > 0) && ($settings->alert_email != '')) {
|
||||
$this->table(
|
||||
[
|
||||
trans('general.id'),
|
||||
trans('admin/hardware/form.tag'),
|
||||
trans('admin/hardware/form.model'),
|
||||
trans('general.model_no'),
|
||||
trans('general.purchase_date'),
|
||||
trans('admin/hardware/form.expected_checkin'),
|
||||
],
|
||||
$assets->map(fn($assets) => [
|
||||
trans('general.id') => $assets->id,
|
||||
trans('admin/hardware/form.tag') => $assets->asset_tag,
|
||||
trans('admin/hardware/form.model') => $assets->model->name,
|
||||
trans('general.model_no') => $assets->model->model_number,
|
||||
trans('general.purchase_date') => $assets->purchase_date_formatted,
|
||||
trans('admin/hardware/form.eol_date') => $assets->expected_checkin_formattedDate ? $assets->expected_checkin_formattedDate . ' (' . $assets->expected_checkin_diff_for_humans . ')' : '',
|
||||
])
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,10 +93,11 @@ class SendExpectedCheckinAlerts extends Command
|
||||
$recipients = collect(explode(',', $settings->alert_email))->map(function ($item) {
|
||||
return new AlertRecipient($item);
|
||||
});
|
||||
|
||||
$this->info('Sending Admin ExpectedCheckinNotification to: '.$settings->alert_email);
|
||||
\Notification::send($recipients, new ExpectedCheckinAdminNotification($assets));
|
||||
Notification::send($recipients, new ExpectedCheckinAdminNotification($assets));
|
||||
|
||||
}
|
||||
|
||||
$this->info('Sent checkin reminders to to '.$count.' users.');
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -408,6 +408,13 @@ class Asset extends Depreciable
|
||||
);
|
||||
}
|
||||
|
||||
protected function expectedCheckinDiffForHumans(): Attribute
|
||||
{
|
||||
return Attribute:: make(
|
||||
get: fn(mixed $value, array $attributes) => array_key_exists('expected_checkin', $attributes) ? Carbon::parse($this->expected_checkin)->diffForHumans() : null,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Establishes the asset -> company relationship
|
||||
*
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace App\Notifications;
|
||||
|
||||
use App\Helpers\Helper;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Notifications\Messages\MailMessage;
|
||||
use Illuminate\Notifications\Notification;
|
||||
@@ -47,14 +48,17 @@ class ExpectedCheckinNotification extends Notification
|
||||
*/
|
||||
public function toMail()
|
||||
{
|
||||
$today = Carbon::now();
|
||||
|
||||
$message = (new MailMessage)->markdown('notifications.markdown.expected-checkin',
|
||||
[
|
||||
'expected_checkin_date' => $this->params->expected_checkin,
|
||||
'date' => Helper::getFormattedDateObject($this->params->expected_checkin, 'date', false),
|
||||
'asset' => $this->params->display_name,
|
||||
'serial' => $this->params->serial,
|
||||
'asset_tag' => $this->params->asset_tag,
|
||||
])
|
||||
->subject(trans('mail.Expected_Checkin_Notification', ['name' => $this->params->display_name]));
|
||||
->subject(($today > $this->params->expected_checkin) ? trans('mail.Expected_Checkin_Notification_Pastdue', ['name' => $this->params->display_name]) : trans('mail.Expected_Checkin_Notification', ['name' => $this->params->display_name]));
|
||||
|
||||
return $message;
|
||||
}
|
||||
|
||||
@@ -519,7 +519,7 @@ class AssetPresenter extends Presenter
|
||||
|
||||
// Asset tag
|
||||
if ($this->asset_tag) {
|
||||
$str .= ' ('.$this->model->asset_tag.')';
|
||||
$str .= ' #'.$this->model->asset_tag;
|
||||
}
|
||||
|
||||
// Asset Model name
|
||||
|
||||
@@ -18,8 +18,10 @@ return [
|
||||
'Component_checkout_notification' => 'Component checked out',
|
||||
'Component_checkin_notification' => 'Component checked in',
|
||||
'Days' => 'Days',
|
||||
'Expected_Checkin_Date' => 'An asset checked out to you is due to be checked back in on :date',
|
||||
'Expected_Checkin_Date' => 'An asset checked out to you is due to be checked back in on :date.',
|
||||
'Expected_Checkin_Date_Past' => 'An asset checked out to you was due to be checked back in on :date.',
|
||||
'Expected_Checkin_Notification' => 'Reminder: :name checkin deadline approaching',
|
||||
'Expected_Checkin_Notification_Pastdue' => 'OVERDUE: :name is overdue for checkin',
|
||||
'Expected_Checkin_Report' => 'Expected asset checkin report',
|
||||
'Expiring_Assets_Report' => 'Expiring Assets Report',
|
||||
'Expiring_Licenses_Report' => 'Expiring Licenses Report',
|
||||
|
||||
@@ -1,14 +1,21 @@
|
||||
@component('mail::message')
|
||||
# {{ trans('mail.hello') }},
|
||||
|
||||
@if ($expected_checkin_date > now())
|
||||
{{ trans('mail.Expected_Checkin_Date', ['date' => $date]) }}
|
||||
@else
|
||||
{{ trans('mail.Expected_Checkin_Date_Past', ['date' => $date]) }}
|
||||
@endif
|
||||
|
||||
@if ((isset($asset)) && ($asset!=''))
|
||||
{{ trans('mail.asset_name') }} {{ $asset }}
|
||||
<strong>{{ trans('mail.asset_name') }}:</strong> {{ $asset }}
|
||||
|
||||
@endif
|
||||
{{ trans('mail.asset_tag') }} {{ $asset_tag }}
|
||||
<strong>{{ trans('mail.asset_tag') }}:</strong> {{ $asset_tag }}
|
||||
|
||||
@if (isset($serial))
|
||||
{{ trans('mail.serial') }}: {{ $serial }}
|
||||
<strong>{{ trans('mail.serial') }}:</strong> {{ $serial }}
|
||||
|
||||
@endif
|
||||
|
||||
**[{{ trans('mail.your_assets') }}]({{ route('view-assets') }})**
|
||||
|
||||
Reference in New Issue
Block a user