Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 39 additions & 8 deletions app/Console/Commands/SendExpectedCheckinAlerts.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
use App\Notifications\ExpectedCheckinNotification;
use Carbon\Carbon;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Notification;
use App\Helpers\Helper;

class SendExpectedCheckinAlerts extends Command
{
Expand All @@ -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.
Expand All @@ -42,19 +44,47 @@ public function __construct()
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 . ')' : '',
])
);
}
}

Expand All @@ -63,10 +93,11 @@ public function handle()
$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.');

}
}
7 changes: 7 additions & 0 deletions app/Models/Asset.php
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,13 @@ protected function expectedCheckinFormattedDate(): Attribute
);
}

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
*
Expand Down
6 changes: 5 additions & 1 deletion app/Notifications/ExpectedCheckinNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -47,14 +48,17 @@ public function via()
*/
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;
}
Expand Down
2 changes: 1 addition & 1 deletion app/Presenters/AssetPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ public function fullName()

// Asset tag
if ($this->asset_tag) {
$str .= ' ('.$this->model->asset_tag.')';
$str .= ' #'.$this->model->asset_tag;
}

// Asset Model name
Expand Down
4 changes: 3 additions & 1 deletion resources/lang/en-US/mail.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@
'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',
Expand Down
Original file line number Diff line number Diff line change
@@ -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') }})**
Expand Down
Loading