mirror of
https://github.com/snipe/snipe-it.git
synced 2024-09-20 07:47:41 -07:00
Refactor checkin alert
Signed-off-by: snipe <snipe@snipe.net>
This commit is contained in:
parent
103809b65f
commit
fe147adec3
|
@ -42,26 +42,32 @@ class SendExpectedCheckinAlerts extends Command
|
||||||
*/
|
*/
|
||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
$settings = Setting::getSettings();
|
$interval = $settings->audit_warning_days ?? 0;
|
||||||
$whenNotify = Carbon::now();
|
$today = Carbon::now();
|
||||||
$assets = Asset::with('assignedTo')->whereNotNull('assigned_to')->whereNotNull('expected_checkin')->where('expected_checkin', '<=', $whenNotify)->get();
|
$interval_date = $today->copy()->addDays($interval);
|
||||||
|
|
||||||
|
$settings = Setting::getSettings();
|
||||||
|
$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($whenNotify.' is deadline');
|
|
||||||
$this->info($assets->count().' assets');
|
|
||||||
|
|
||||||
foreach ($assets as $asset) {
|
foreach ($assets as $asset) {
|
||||||
if ($asset->assigned && $asset->checkedOutToUser()) {
|
if ($asset->assignedTo && (isset($asset->assignedTo->email)) && ($asset->assignedTo->email!='') && $asset->checkedOutToUser()) {
|
||||||
Log::info('Sending ExpectedCheckinNotification to ' . $asset->assigned->email);
|
$this->info('Sending User ExpectedCheckinNotification to: '.$asset->assignedTo->email);
|
||||||
$asset->assigned->notify((new ExpectedCheckinNotification($asset)));
|
$asset->assignedTo->notify((new ExpectedCheckinNotification($asset)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (($assets) && ($assets->count() > 0) && ($settings->alert_email != '')) {
|
if (($assets) && ($assets->count() > 0) && ($settings->alert_email != '')) {
|
||||||
// Send a rollup to the admin, if settings dictate
|
// Send a rollup to the admin, if settings dictate
|
||||||
$recipients = collect(explode(',', $settings->alert_email))->map(function ($item, $key) {
|
$recipients = collect(explode(',', $settings->alert_email))->map(function ($item) {
|
||||||
return new AlertRecipient($item);
|
return new AlertRecipient($item);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$this->info('Sending Admin ExpectedCheckinNotification to: '.$recipients);
|
||||||
\Notification::send($recipients, new ExpectedCheckinAdminNotification($assets));
|
\Notification::send($recipients, new ExpectedCheckinAdminNotification($assets));
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue