diff --git a/app/Console/Commands/SendExpectedCheckinAlerts.php b/app/Console/Commands/SendExpectedCheckinAlerts.php index 15594bee0..3c4b7ee52 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.php new file mode 100644 index 000000000..6dd481ea1 --- /dev/null +++ b/app/Notifications/ExpectedCheckinAdminNotification.php @@ -0,0 +1,82 @@ +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.php new file mode 100644 index 000000000..88b6eff4a --- /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 }} + +@endcomponent diff --git a/resources/views/vendor/mail/html/footer.blade.php b/resources/views/vendor/mail/html/footer.blade.php index c3f9360ab..46dc4ccb2 100644 --- a/resources/views/vendor/mail/html/footer.blade.php +++ b/resources/views/vendor/mail/html/footer.blade.php @@ -4,6 +4,12 @@ {{ Illuminate\Mail\Markdown::parse($slot) }} + + @if ($snipeSettings->privacy_policy_link!='') + {{ trans('admin/settings/general.privacy_policy') }} + @endif + + diff --git a/resources/views/vendor/mail/html/header.blade.php b/resources/views/vendor/mail/html/header.blade.php index eefabab92..45ed4bd80 100644 --- a/resources/views/vendor/mail/html/header.blade.php +++ b/resources/views/vendor/mail/html/header.blade.php @@ -1,7 +1,22 @@ - - {{ $slot }} - + @if (($snipeSettings->show_images_in_email=='1' ) && ($snipeSettings::setupCompleted())) + + @if ($snipeSettings->brand == '3') + @if ($snipeSettings->logo!='') + + @endif + {{ $snipeSettings->site_name }} + + @elseif ($snipeSettings->brand == '2') + @if ($snipeSettings->logo!='') + + @endif + @else + {{ $snipeSettings->site_name }} + @endif + @else + Snipe-IT + @endif diff --git a/resources/views/vendor/mail/html/layout.blade.php b/resources/views/vendor/mail/html/layout.blade.php index c7c629d4a..948afcee9 100644 --- a/resources/views/vendor/mail/html/layout.blade.php +++ b/resources/views/vendor/mail/html/layout.blade.php @@ -50,6 +50,7 @@ {{ $footer or '' }} + diff --git a/resources/views/vendor/mail/html/message.blade.php b/resources/views/vendor/mail/html/message.blade.php index b69b4387f..5dfa2eb88 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!='') - - @endif - {{ $snipeSettings->site_name }} - - @elseif ($snipeSettings->brand == '2') - @if ($snipeSettings->logo!='') - - @endif - @else - {{ $snipeSettings->site_name }} - @endif - @else - Snipe-it - @endif - @endcomponent - @endslot +@if ($snipeSettings->brand == '3') +@if ($snipeSettings->logo!='') + +@endif +{{ $snipeSettings->site_name }} - {{-- Body --}} - {{ $slot }} +@elseif ($snipeSettings->brand == '2') +@if ($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!='') -{{ trans('admin/settings/general.privacy_policy') }} +[{{ $snipeSettings->privacy_policy_link }}]({{ trans('admin/settings/general.privacy_policy') }}) @endif @endcomponent - @endslot +@endslot @endcomponent diff --git a/resources/views/vendor/mail/markdown/message.blade.php b/resources/views/vendor/mail/markdown/message.blade.php index 25e0ab4a4..09ffe0a59 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!='') @endif {{ $snipeSettings->site_name }} - + @elseif ($snipeSettings->brand == '2') @if ($snipeSettings->logo!='') @@ -17,7 +18,7 @@ {{ $snipeSettings->site_name }} @endif @else - Snipe-it + Snipe-IT @endif @endcomponent @endslot diff --git a/resources/views/vendor/notifications/email.blade.php b/resources/views/vendor/notifications/email.blade.php index 039b33a39..2cad87a73 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 = [ - @if ($snipeSettings->logo) - + @if (($snipeSettings->show_images_in_email=='1' ) && ($snipeSettings::setupCompleted())) + + @if ($snipeSettings->brand == '3') + @if ($snipeSettings->logo!='') + + @endif + {{ $snipeSettings->site_name }} + + @elseif ($snipeSettings->brand == '2') + @if ($snipeSettings->logo!='') + + @endif + @else + {{ $snipeSettings->site_name }} + @endif + @else + Snipe-IT @endif - - {{ $snipeSettings->site_name }} -