2017-08-31 21:18:05 -07:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
|
|
|
|
use App\Models\Asset;
|
2021-06-10 13:15:52 -07:00
|
|
|
use App\Models\Recipients\AlertRecipient;
|
2018-05-08 05:27:03 -07:00
|
|
|
use App\Models\Setting;
|
|
|
|
use App\Notifications\ExpectedCheckinAdminNotification;
|
2018-09-26 14:07:41 -07:00
|
|
|
use App\Notifications\ExpectedCheckinNotification;
|
2017-08-31 21:18:05 -07:00
|
|
|
use Carbon\Carbon;
|
2018-09-26 14:07:41 -07:00
|
|
|
use Illuminate\Console\Command;
|
2017-08-31 21:18:05 -07:00
|
|
|
|
|
|
|
class SendExpectedCheckinAlerts extends Command
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* The console command name.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $name = 'snipeit:expected-checkin';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The console command description.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $description = 'Check for overdue or upcoming expected checkins.';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new command instance.
|
|
|
|
*/
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
parent::__construct();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Execute the console command.
|
|
|
|
*
|
|
|
|
* @return mixed
|
|
|
|
*/
|
2018-07-25 01:28:44 -07:00
|
|
|
public function handle()
|
2017-08-31 21:18:05 -07:00
|
|
|
{
|
2024-05-02 04:37:41 -07:00
|
|
|
$settings = Setting::getSettings();
|
2024-04-26 13:10:54 -07:00
|
|
|
$interval = $settings->audit_warning_days ?? 0;
|
|
|
|
$today = Carbon::now();
|
|
|
|
$interval_date = $today->copy()->addDays($interval);
|
2024-05-02 04:37:41 -07:00
|
|
|
|
2024-04-26 13:10:54 -07:00
|
|
|
$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');
|
2017-08-31 21:18:05 -07:00
|
|
|
|
|
|
|
|
|
|
|
foreach ($assets as $asset) {
|
2024-04-26 13:10:54 -07:00
|
|
|
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)));
|
2017-08-31 21:18:05 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-26 14:07:41 -07:00
|
|
|
if (($assets) && ($assets->count() > 0) && ($settings->alert_email != '')) {
|
|
|
|
// Send a rollup to the admin, if settings dictate
|
2024-04-26 13:10:54 -07:00
|
|
|
$recipients = collect(explode(',', $settings->alert_email))->map(function ($item) {
|
2018-09-26 14:07:41 -07:00
|
|
|
return new AlertRecipient($item);
|
|
|
|
});
|
2024-04-26 13:10:54 -07:00
|
|
|
|
2024-04-26 13:26:00 -07:00
|
|
|
$this->info('Sending Admin ExpectedCheckinNotification to: '.$settings->alert_email);
|
2020-10-23 04:46:26 -07:00
|
|
|
\Notification::send($recipients, new ExpectedCheckinAdminNotification($assets));
|
2024-04-26 13:10:54 -07:00
|
|
|
|
2018-05-08 05:27:03 -07:00
|
|
|
}
|
2017-08-31 21:18:05 -07:00
|
|
|
}
|
|
|
|
}
|