mirror of
https://github.com/snipe/snipe-it.git
synced 2024-11-09 23:24:06 -08:00
Added admin alert on expiring notifications
This commit is contained in:
parent
6d8af3d9c0
commit
8f64da5bc7
|
@ -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));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
82
app/Notifications/ExpectedCheckinAdminNotification.php
Normal file
82
app/Notifications/ExpectedCheckinAdminNotification.php
Normal 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 [
|
||||
//
|
||||
];
|
||||
}
|
||||
}
|
|
@ -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
|
|
@ -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>
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -50,6 +50,7 @@
|
|||
</tr>
|
||||
|
||||
{{ $footer or '' }}
|
||||
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
|
|
|
@ -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
|
||||
@endcomponent
|
||||
|
|
|
@ -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
|
||||
@endslot
|
||||
|
|
|
@ -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>
|
||||
|
||||
|
|
Loading…
Reference in a new issue