A free open source IT asset/license management system
Added admin alert on expiring notifications
snipe8f64da5bc7f9
diff --git a/app/Console/Commands/SendExpectedCheckinAlerts.php b/app/Console/Commands/SendExpectedCheckinAlerts.phpindex 15594bee08..3c4b7ee523 100644--- a/app/Console/Commands/SendExpectedCheckinAlerts.php+++ b/app/Console/Commands/SendExpectedCheckinAlerts.php@@ -4,8 +4,10 @@ namespace App\Console\Commands;use App\Models\Asset;+use App\Models\Setting;use Illuminate\Console\Command;use App\Notifications\ExpectedCheckinNotification;+use App\Notifications\ExpectedCheckinAdminNotification;use Carbon\Carbon;class SendExpectedCheckinAlerts extends Command@@ -42,21 +44,28 @@ class SendExpectedCheckinAlerts extends Command*/public function fire(){-+ $settings = Setting::getSettings();$whenNotify = Carbon::now()->addDays(7);- $assets = Asset::with('assignedTo')->whereNotNull('expected_checkin')->where('expected_checkin', '<=', $whenNotify)->get();+ $assets = Asset::with('assignedTo')->whereNotNull('assigned_to')->whereNotNull('expected_checkin')->where('expected_checkin', '<=', $whenNotify)->get();$this->info($whenNotify.' is deadline');$this->info($assets->count().' assets');foreach ($assets as $asset) {- if ($asset->assignedTo && $asset->checkoutOutToUser()) {- $asset->assignedTo->notify((new ExpectedCheckinNotification($asset)));- //$this->info($asset);+ if ($asset->assigned && $asset->checkedOutToUser()) {+ $asset->assigned->notify((new ExpectedCheckinNotification($asset)));}}+ // Send a rollup to the admin, if settings dictate+ $recipient = new \App\Models\Recipients\AlertRecipient();++ if ($settings->alert_email!='') {+ $recipient->notify(new ExpectedCheckinAdminNotification($assets));+ }++diff --git a/app/Notifications/ExpectedCheckinAdminNotification.php b/app/Notifications/ExpectedCheckinAdminNotification.phpnew file mode 100644index 0000000000..6dd481ea1f--- /dev/null+++ b/app/Notifications/ExpectedCheckinAdminNotification.php@@ -0,0 +1,82 @@+<?php++namespace App\Notifications;++use App\Models\Setting;+use App\Models\SnipeModel;+use Illuminate\Bus\Queueable;+use Illuminate\Contracts\Queue\ShouldQueue;+use Illuminate\Notifications\Messages\MailMessage;+use Illuminate\Notifications\Notification;+use Illuminate\Support\Facades\Mail;+use Carbon\Carbon;++class ExpectedCheckinAdminNotification extends Notification+{+ use Queueable;+ /**+ * @var+ */+ private $params;++ /**+ * Create a new notification instance.+ *+ * @param $params+ */+ public function __construct($params)+ {+ $this->assets = $params;+ }++ /**+ * Get the notification's delivery channels.+ *+ * @param mixed $notifiable+ * @return array+ */+ public function via($notifiable)+ {+ $notifyBy = [];+ $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)+ {++ $message = (new MailMessage)->markdown('notifications.markdown.report-expected-checkins',+ [+ 'assets' => $this->assets,+ ])+ ->subject('Expected asset checkin report');++ return $message;+++ }++ /**+ * Get the array representation of the notification.+ *+ * @param mixed $notifiable+ * @return array+ */+ public function toArray($notifiable)+ {+ return [+ //+ ];+ }+}diff --git a/resources/views/notifications/markdown/report-expected-checkins.blade.php b/resources/views/notifications/markdown/report-expected-checkins.blade.phpnew file mode 100644index 0000000000..88b6eff4aa--- /dev/null+++ b/resources/views/notifications/markdown/report-expected-checkins.blade.php@@ -0,0 +1,21 @@+@component('mail::message')+# {{ trans('mail.hello') }},++The following {{ $assets->count() }} items are due to be checked in soon:++@component('mail::table')+| Asset Name | Asset Tag | Checked Out to | Expected Checkin |+| ------------- | ------------- |+@foreach ($assets as $asset)+@php+$checkin = \App\Helpers\Helper::getFormattedDateObject($asset->expected_checkin, 'date');+@endphp+| {{ $asset->name }} | [{{ $asset->asset_tag }}]({{ route('hardware.show', ['assetId' => $asset->id]) }}) | [{{ $asset->assigned->first_name }} {{ $asset->assigned->last_name }}]({{ route('users.show', ['user'=>$asset->assigned->id]) }}) | {{ $checkin['formatted'] }}+@endforeach+@endcomponent++Thanks,++{{ $snipeSettings->site_name }}++@endcomponentdiff --git a/resources/views/vendor/mail/html/footer.blade.php b/resources/views/vendor/mail/html/footer.blade.phpindex c3f9360abd..46dc4ccb26 100644--- a/resources/views/vendor/mail/html/footer.blade.php+++ b/resources/views/vendor/mail/html/footer.blade.php@@ -4,6 +4,12 @@<tr><td class="content-cell" align="center">{{ Illuminate\Mail\Markdown::parse($slot) }}++ @if ($snipeSettings->privacy_policy_link!='')+ <a href="{{ $snipeSettings->privacy_policy_link }}">{{ trans('admin/settings/general.privacy_policy') }}</a>+ @endif++</td></tr></table>diff --git a/resources/views/vendor/mail/html/header.blade.php b/resources/views/vendor/mail/html/header.blade.phpindex eefabab924..45ed4bd80e 100644--- a/resources/views/vendor/mail/html/header.blade.php+++ b/resources/views/vendor/mail/html/header.blade.php@@ -1,7 +1,22 @@<tr><td class="header">- <a href="{{ $url }}">- {{ $slot }}- </a>+ @if (($snipeSettings->show_images_in_email=='1' ) && ($snipeSettings::setupCompleted()))++ @if ($snipeSettings->brand == '3')+ @if ($snipeSettings->logo!='')+ <img class="navbar-brand-img logo" src="{{ url('/') }}/uploads/{{ $snipeSettings->logo }}">+ @endif+ {{ $snipeSettings->site_name }}++ @elseif ($snipeSettings->brand == '2')+ @if ($snipeSettings->logo!='')+ <img class="navbar-brand-img logo" src="{{ url('/') }}/uploads/{{ $snipeSettings->logo }}">+ @endif+ @else+ {{ $snipeSettings->site_name }}+ @endif+ @else+ Snipe-IT+ @endif</td></tr>diff --git a/resources/views/vendor/mail/html/layout.blade.php b/resources/views/vendor/mail/html/layout.blade.phpindex c7c629d4a4..948afcee9d 100644--- a/resources/views/vendor/mail/html/layout.blade.php+++ b/resources/views/vendor/mail/html/layout.blade.php@@ -50,6 +50,7 @@</tr>{{ $footer or '' }}+</table></td></tr>diff --git a/resources/views/vendor/mail/html/message.blade.php b/resources/views/vendor/mail/html/message.blade.phpindex b69b4387fc..5dfa2eb88e 100644--- a/resources/views/vendor/mail/html/message.blade.php+++ b/resources/views/vendor/mail/html/message.blade.php@@ -1,39 +1,39 @@@component('mail::layout')- {{-- Header --}}- @slot('header')- @component('mail::header', ['url' => config('app.url')])- @if (($snipeSettings->show_images_in_email=='1' ) && ($snipeSettings::setupCompleted()))+{{-- Header --}}+@slot('header')+@component('mail::header', ['url' => config('app.url')])+@if (($snipeSettings->show_images_in_email=='1' ) && ($snipeSettings::setupCompleted()))- @if ($snipeSettings->brand == '3')- @if ($snipeSettings->logo!='')- <img class="navbar-brand-img logo" src="{{ url('/') }}/uploads/{{ $snipeSettings->logo }}">- @endif- {{ $snipeSettings->site_name }}-- @elseif ($snipeSettings->brand == '2')- @if ($snipeSettings->logo!='')- <img class="navbar-brand-img logo" src="{{ url('/') }}/uploads/{{ $snipeSettings->logo }}">- @endif- @else- {{ $snipeSettings->site_name }}- @endif- @else- Snipe-it- @endif- @endcomponent- @endslot+@if ($snipeSettings->brand == '3')+@if ($snipeSettings->logo!='')+ <img class="navbar-brand-img logo" src="{{ url('/') }}/uploads/{{ $snipeSettings->logo }}">+@endif+{{ $snipeSettings->site_name }}- {{-- Body --}}- {{ $slot }}+@elseif ($snipeSettings->brand == '2')+@if ($snipeSettings->logo!='')+ <img class="navbar-brand-img logo" src="{{ url('/') }}/uploads/{{ $snipeSettings->logo }}">+@endif+@else+{{ $snipeSettings->site_name }}+@endif+@else+Snipe-IT+@endif+@endcomponent+@endslot- {{-- Subcopy --}}- @isset($subcopy)- @slot('subcopy')- @component('mail::subcopy')- {{ $subcopy }}- @endcomponent- @endslot- @endisset+{{-- Body --}}+{{ $slot }}++{{-- Subcopy --}}+@isset($subcopy)+@slot('subcopy')+@component('mail::subcopy')+{{ $subcopy }}+@endcomponent+@endslot+@endisset{{-- Footer --}}@slot('footer')@@ -45,9 +45,9 @@@endif@if ($snipeSettings->privacy_policy_link!='')-<a href="{{ $snipeSettings->privacy_policy_link }}">{{ trans('admin/settings/general.privacy_policy') }}</a>+[{{ $snipeSettings->privacy_policy_link }}]({{ trans('admin/settings/general.privacy_policy') }})@endif@endcomponent- @endslot+@endslot@endcomponentdiff --git a/resources/views/vendor/mail/markdown/message.blade.php b/resources/views/vendor/mail/markdown/message.blade.phpindex 25e0ab4a4f..09ffe0a59a 100644--- a/resources/views/vendor/mail/markdown/message.blade.php+++ b/resources/views/vendor/mail/markdown/message.blade.php@@ -2,13 +2,14 @@{{-- Header --}}@slot('header')@component('mail::header', ['url' => config('app.url')])- @if($snipeSettings::setupCompleted())+ @if (($snipeSettings->show_images_in_email=='1' ) && ($snipeSettings::setupCompleted()))+@if ($snipeSettings->brand == '3')@if ($snipeSettings->logo!='')<img class="navbar-brand-img logo" src="{{ url('/') }}/uploads/{{ $snipeSettings->logo }}">@endif{{ $snipeSettings->site_name }}-+@elseif ($snipeSettings->brand == '2')@if ($snipeSettings->logo!='')<img class="navbar-brand-img logo" src="{{ url('/') }}/uploads/{{ $snipeSettings->logo }}">@@ -17,7 +18,7 @@{{ $snipeSettings->site_name }}@endif@else- Snipe-it+ Snipe-IT@endif@endcomponent@endslotdiff --git a/resources/views/vendor/notifications/email.blade.php b/resources/views/vendor/notifications/email.blade.phpindex 039b33a396..2cad87a73b 100644--- a/resources/views/vendor/notifications/email.blade.php+++ b/resources/views/vendor/notifications/email.blade.php@@ -25,7 +25,7 @@ $style = [/* Masthead ----------------------- */- 'email-masthead' => 'padding: 25px 0; text-align: left;',+ 'email-masthead' => 'padding: 25px 0; text-align: center;','email-masthead_name' => 'font-size: 16px; font-weight: bold; color: #2F3133; text-decoration: none; text-shadow: 0 1px 0 white;','email-body' => 'width: 100%; margin: 0; padding: 0; border-top: 1px solid #EDEFF2; border-bottom: 1px solid #EDEFF2; background-color: #FFF;',@@ -57,6 +57,7 @@ $style = ['button--green' => 'background-color: #22BC66;','button--red' => 'background-color: #dc4d2f;','button--blue' => 'background-color: #3869D4;',+];?>@@ -71,12 +72,24 @@ $style = [<tr><td style="{{ $style['email-masthead'] }}">- @if ($snipeSettings->logo)- <img src="{{ url('/') }}/{{ $snipeSettings->logo }}">+ @if (($snipeSettings->show_images_in_email=='1' ) && ($snipeSettings::setupCompleted()))++ @if ($snipeSettings->brand == '3')+ @if ($snipeSettings->logo!='')+ <img class="navbar-brand-img logo" style="max-width: 50px;" src="{{ url('/') }}/uploads/{{ $snipeSettings->logo }}">+ @endif+ {{ $snipeSettings->site_name }}++ @elseif ($snipeSettings->brand == '2')+ @if ($snipeSettings->logo!='')+ <img class="navbar-brand-img logo" style="max-width: 50px;" src="{{ url('/') }}/uploads/{{ $snipeSettings->logo }}">+ @endif+ @else+ {{ $snipeSettings->site_name }}+ @endif+ @else+ Snipe-IT@endif- <a style="{{ $fontFamily }} {{ $style['email-masthead_name'] }}" href="{{ url('/') }}" target="_blank">- {{ $snipeSettings->site_name }}- </a></td></tr>