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;
|
2023-12-18 17:14:03 -08:00
|
|
|
use Illuminate\Support\Facades\Log;
|
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
|
|
|
{
|
2021-06-10 13:15:52 -07:00
|
|
|
$settings = Setting::getSettings();
|
2024-01-15 08:11:31 -08:00
|
|
|
$whenNotify = Carbon::now();
|
2021-06-10 13:15:52 -07:00
|
|
|
$assets = Asset::with('assignedTo')->whereNotNull('assigned_to')->whereNotNull('expected_checkin')->where('expected_checkin', '<=', $whenNotify)->get();
|
2017-08-31 21:18:05 -07:00
|
|
|
|
2021-06-10 13:15:52 -07:00
|
|
|
$this->info($whenNotify.' is deadline');
|
|
|
|
$this->info($assets->count().' assets');
|
2017-08-31 21:18:05 -07:00
|
|
|
|
|
|
|
foreach ($assets as $asset) {
|
2018-09-26 14:07:41 -07:00
|
|
|
if ($asset->assigned && $asset->checkedOutToUser()) {
|
2023-12-18 17:14:03 -08:00
|
|
|
Log::info('Sending ExpectedCheckinNotification to ' . $asset->assigned->email);
|
2018-05-08 05:27:03 -07:00
|
|
|
$asset->assigned->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
|
|
|
|
$recipients = collect(explode(',', $settings->alert_email))->map(function ($item, $key) {
|
|
|
|
return new AlertRecipient($item);
|
|
|
|
});
|
2020-10-23 04:46:26 -07:00
|
|
|
\Notification::send($recipients, new ExpectedCheckinAdminNotification($assets));
|
2018-05-08 05:27:03 -07:00
|
|
|
}
|
2017-08-31 21:18:05 -07:00
|
|
|
}
|
|
|
|
}
|