diff --git a/app/Console/Commands/SendExpectedCheckinAlerts.php b/app/Console/Commands/SendExpectedCheckinAlerts.php new file mode 100644 index 0000000000..912f2975a7 --- /dev/null +++ b/app/Console/Commands/SendExpectedCheckinAlerts.php @@ -0,0 +1,64 @@ +addDays(7); + $assets = Asset::with('assigneduser')->whereNotNull('expected_checkin')->where('expected_checkin', '<=', $whenNotify)->get(); + + $this->info($whenNotify.' is deadline'); + $this->info($assets->count().' assets'); + + foreach ($assets as $asset) { + if ($asset->assigneduser) { + $asset->assigneduser->notify((new ExpectedCheckinNotification($asset))); + //$this->info($asset); + } + } + + + + + + } +} diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index ca86a418eb..d6de607fb8 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -17,6 +17,7 @@ class Kernel extends ConsoleKernel Commands\CreateAdmin::class, Commands\SendExpirationAlerts::class, Commands\SendInventoryAlerts::class, + Commands\SendExpectedCheckinAlerts::class, Commands\ObjectImportCommand::class, Commands\Versioning::class, Commands\SystemBackup::class, @@ -38,6 +39,7 @@ class Kernel extends ConsoleKernel $schedule->command('snipeit:inventory-alerts')->daily(); $schedule->command('snipeit:expiring-alerts')->daily(); + $schedule->command('snipeit:expected-checkins')->daily(); $schedule->command('snipeit:backup')->weekly(); $schedule->command('backup:clean')->daily(); } diff --git a/app/Models/Asset.php b/app/Models/Asset.php index 2da464c057..0cbc9b5f78 100644 --- a/app/Models/Asset.php +++ b/app/Models/Asset.php @@ -11,6 +11,7 @@ use Config; use Illuminate\Database\Eloquent\SoftDeletes; use Log; use Watson\Validating\ValidatingTrait; +use Illuminate\Notifications\Notifiable; /** * Model for Assets. @@ -20,7 +21,7 @@ use Watson\Validating\ValidatingTrait; class Asset extends Depreciable { protected $presenter = 'App\Presenters\AssetPresenter'; - use Loggable, Requestable, Presentable; + use Loggable, Requestable, Presentable, Notifiable; use SoftDeletes; const LOCATION = 'location'; diff --git a/app/Notifications/ExpectedCheckinNotification.php b/app/Notifications/ExpectedCheckinNotification.php new file mode 100644 index 0000000000..d1562832a2 --- /dev/null +++ b/app/Notifications/ExpectedCheckinNotification.php @@ -0,0 +1,86 @@ +params = $params; + } + + /** + * Get the notification's delivery channels. + * + * @param mixed $notifiable + * @return array + */ + public function via($notifiable) + { + $notifyBy = []; + $item = $this->params['item']; + + $notifyBy[]='mail'; + return $notifyBy; + } + + public function toSlack($notifiable) + { + + } + + /** + * Get the mail representation of the notification. + * + * @param mixed $asset + * @return \Illuminate\Notifications\Messages\MailMessage + */ + public function toMail($params) + { + $formatted_due = Carbon::parse($this->params->expected_checkin)->format('D, M j, Y'); + return (new MailMessage) + ->error() + ->subject('Reminder: '.$this->params->present()->name().' checkin deadline approaching') + ->line('Hi, '.$this->params->assignedto->first_name) + ->greeting('An asset checked out to you is due to be checked back in on '.$formatted_due.'.') + ->line('Asset: '.$this->params->present()->name()) + ->line('Serial: '.$this->params->serial) + ->line('Asset Tag: '.$this->params->asset_tag) + ->action('View Your Assets', route('view-assets')); + + + } + + /** + * Get the array representation of the notification. + * + * @param mixed $notifiable + * @return array + */ + public function toArray($notifiable) + { + return [ + // + ]; + } +}