Added admin alert on expiring notifications

This commit is contained in:
snipe 2018-05-08 05:27:03 -07:00
parent 6d8af3d9c0
commit 8f64da5bc7
9 changed files with 199 additions and 51 deletions

View file

@ -4,8 +4,10 @@ namespace App\Console\Commands;
use App\Models\Asset; use App\Models\Asset;
use App\Models\Setting;
use Illuminate\Console\Command; use Illuminate\Console\Command;
use App\Notifications\ExpectedCheckinNotification; use App\Notifications\ExpectedCheckinNotification;
use App\Notifications\ExpectedCheckinAdminNotification;
use Carbon\Carbon; use Carbon\Carbon;
class SendExpectedCheckinAlerts extends Command class SendExpectedCheckinAlerts extends Command
@ -42,21 +44,28 @@ class SendExpectedCheckinAlerts extends Command
*/ */
public function fire() public function fire()
{ {
$settings = Setting::getSettings();
$whenNotify = Carbon::now()->addDays(7); $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($whenNotify.' is deadline');
$this->info($assets->count().' assets'); $this->info($assets->count().' assets');
foreach ($assets as $asset) { foreach ($assets as $asset) {
if ($asset->assignedTo && $asset->checkoutOutToUser()) { if ($asset->assigned && $asset->checkedOutToUser()) {
$asset->assignedTo->notify((new ExpectedCheckinNotification($asset))); $asset->assigned->notify((new ExpectedCheckinNotification($asset)));
//$this->info($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));
}

View file

@ -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 [
//
];
}
}

View file

@ -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

View file

@ -4,6 +4,12 @@
<tr> <tr>
<td class="content-cell" align="center"> <td class="content-cell" align="center">
{{ Illuminate\Mail\Markdown::parse($slot) }} {{ 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> </td>
</tr> </tr>
</table> </table>

View file

@ -1,7 +1,22 @@
<tr> <tr>
<td class="header"> <td class="header">
<a href="{{ $url }}"> @if (($snipeSettings->show_images_in_email=='1' ) && ($snipeSettings::setupCompleted()))
{{ $slot }}
</a> @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> </td>
</tr> </tr>

View file

@ -50,6 +50,7 @@
</tr> </tr>
{{ $footer or '' }} {{ $footer or '' }}
</table> </table>
</td> </td>
</tr> </tr>

View file

@ -18,7 +18,7 @@
{{ $snipeSettings->site_name }} {{ $snipeSettings->site_name }}
@endif @endif
@else @else
Snipe-it Snipe-IT
@endif @endif
@endcomponent @endcomponent
@endslot @endslot
@ -45,7 +45,7 @@
@endif @endif
@if ($snipeSettings->privacy_policy_link!='') @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 @endif
@endcomponent @endcomponent

View file

@ -2,7 +2,8 @@
{{-- Header --}} {{-- Header --}}
@slot('header') @slot('header')
@component('mail::header', ['url' => config('app.url')]) @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->brand == '3')
@if ($snipeSettings->logo!='') @if ($snipeSettings->logo!='')
<img class="navbar-brand-img logo" src="{{ url('/') }}/uploads/{{ $snipeSettings->logo }}"> <img class="navbar-brand-img logo" src="{{ url('/') }}/uploads/{{ $snipeSettings->logo }}">
@ -17,7 +18,7 @@
{{ $snipeSettings->site_name }} {{ $snipeSettings->site_name }}
@endif @endif
@else @else
Snipe-it Snipe-IT
@endif @endif
@endcomponent @endcomponent
@endslot @endslot

View file

@ -25,7 +25,7 @@ $style = [
/* Masthead ----------------------- */ /* 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-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;', '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--green' => 'background-color: #22BC66;',
'button--red' => 'background-color: #dc4d2f;', 'button--red' => 'background-color: #dc4d2f;',
'button--blue' => 'background-color: #3869D4;', 'button--blue' => 'background-color: #3869D4;',
]; ];
?> ?>
@ -71,12 +72,24 @@ $style = [
<tr> <tr>
<td style="{{ $style['email-masthead'] }}"> <td style="{{ $style['email-masthead'] }}">
@if ($snipeSettings->logo) @if (($snipeSettings->show_images_in_email=='1' ) && ($snipeSettings::setupCompleted()))
<img src="{{ url('/') }}/{{ $snipeSettings->logo }}">
@if ($snipeSettings->brand == '3')
@if ($snipeSettings->logo!='')
<img class="navbar-brand-img logo" style="max-width: 50px;" src="{{ url('/') }}/uploads/{{ $snipeSettings->logo }}">
@endif @endif
<a style="{{ $fontFamily }} {{ $style['email-masthead_name'] }}" href="{{ url('/') }}" target="_blank">
{{ $snipeSettings->site_name }} {{ $snipeSettings->site_name }}
</a>
@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
</td> </td>
</tr> </tr>