adds reminder notification constructor and updates markdown

This commit is contained in:
Godfrey M 2024-05-23 12:47:02 -07:00
parent 8a0afae90f
commit d3ab152d30
4 changed files with 95 additions and 43 deletions

View file

@ -8,6 +8,7 @@ use App\Models\Setting;
use App\Models\User; use App\Models\User;
use App\Notifications\CheckoutAssetNotification; use App\Notifications\CheckoutAssetNotification;
use App\Notifications\CurrentInventory; use App\Notifications\CurrentInventory;
use App\Notifications\UnacceptedAssetReminderNotification;
use Illuminate\Console\Command; use Illuminate\Console\Command;
use Illuminate\Support\Facades\Notification; use Illuminate\Support\Facades\Notification;
@ -52,7 +53,7 @@ class SendAcceptanceReminder extends Command
->get(); ->get();
$count = 0; $count = 0;
$unacceptedAssets = $pending $unacceptedAssetGroups = $pending
->filter(function($acceptance) { ->filter(function($acceptance) {
return $acceptance->checkoutable_type == 'App\Models\Asset'; return $acceptance->checkoutable_type == 'App\Models\Asset';
}) })
@ -62,28 +63,32 @@ class SendAcceptanceReminder extends Command
->groupBy(function($item) { ->groupBy(function($item) {
return $item['acceptance']->assignedTo ? $item['acceptance']->assignedTo->id : ''; return $item['acceptance']->assignedTo ? $item['acceptance']->assignedTo->id : '';
}); });
$no_mail_address = []; $no_mail_address = [];
foreach($unacceptedAssets as $unacceptedAsset) { foreach($unacceptedAssetGroups as $unacceptedAssetGroup) {
if ($unacceptedAsset['acceptance']->assignedTo->email == ''){ $item_count = $unacceptedAssetGroup->count();
$no_mail_address[] = $unacceptedAsset['checkoutable']->assignedTo->present()->fullName; foreach ($unacceptedAssetGroup as $unacceptedAsset) {
} // if ($unacceptedAsset['acceptance']->assignedTo->email == ''){
// $no_mail_address[] = $unacceptedAsset['checkoutable']->assignedTo->present()->fullName;
// }
if ($unacceptedAsset['acceptance']->assignedTo) { if ($unacceptedAsset['acceptance']->assignedTo) {
if (!$unacceptedAsset['acceptance']->assignedTo->locale) { if (!$unacceptedAsset['acceptance']->assignedTo->locale) {
Notification::locale(Setting::getSettings()->locale)->send( Notification::locale(Setting::getSettings()->locale)->send(
$unacceptedAsset['acceptance']->assignedTo, $unacceptedAsset['acceptance']->assignedTo,
new CheckoutAssetNotification($unacceptedAsset['assetItem'], $unacceptedAsset['acceptance']->assignedTo, $unacceptedAsset['assetItem']->adminuser, $unacceptedAsset['acceptance'], '') new UnacceptedAssetReminderNotification($unacceptedAsset['assetItem'], $count)
); );
} else { } else {
Notification::send( Notification::send(
$unacceptedAsset['acceptance']->assignedTo, $unacceptedAsset['acceptance']->assignedTo,
new CheckoutAssetNotification($unacceptedAsset['assetItem'], $unacceptedAsset['acceptance']->assignedTo, $unacceptedAsset['assetItem']->adminuser, $unacceptedAsset['acceptance'], '') new UnacceptedAssetReminderNotification($unacceptedAsset, $item_count)
); );
} }
$count++; $count++;
} }
} }
}
if (!empty($no_mail_address)) { if (!empty($no_mail_address)) {
foreach($no_mail_address as $user) { foreach($no_mail_address as $user) {

View file

@ -0,0 +1,69 @@
<?php
namespace App\Notifications;
use App\Models\Asset;
use App\Models\User;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;
class UnacceptedAssetReminderNotification extends Notification
{
use Queueable;
/**
* Create a new notification instance.
*
* @return void
*/
public function __construct($checkout_info, $count)
{
$this->count = $count;
$this->target = $checkout_info['acceptance']->assignedTo;
}
/**
* Get the notification's delivery channels.
*
* @param mixed $notifiable
* @return array
*/
public function via()
{
return ['mail'];
}
/**
* Get the mail representation of the notification.
*
* @param mixed $notifiable
* @return \Illuminate\Notifications\Messages\MailMessage
*/
public function toMail()
{
$message = (new MailMessage)->markdown('notifications.markdown.asset-reminder',
[
'count' => $this->count,
'assigned_to' => $this->target->present()->fullName,
'link' => route('account.accept')
])
->subject(trans('mail.unaccepted_asset_reminder'));
return $message;
}
/**
* Get the array representation of the notification.
*
* @param mixed $notifiable
* @return array
*/
public function toArray($notifiable)
{
return [
//
];
}
}

View file

@ -56,6 +56,7 @@ return [
'i_have_read' => 'I have read and agree to the terms of use, and have received this item.', 'i_have_read' => 'I have read and agree to the terms of use, and have received this item.',
'inventory_report' => 'Inventory Report', 'inventory_report' => 'Inventory Report',
'item' => 'Item:', 'item' => 'Item:',
'item_checked_reminder' => 'This is a reminder that you currently have :count items checked out to you that you have not accepted or declined. Please <a href=":link">click here</a> to review your items.',
'license_expiring_alert' => 'There is :count license expiring in the next :threshold days.|There are :count licenses expiring in the next :threshold days.', 'license_expiring_alert' => 'There is :count license expiring in the next :threshold days.|There are :count licenses expiring in the next :threshold days.',
'link_to_update_password' => 'Please click on the following link to update your :web password:', 'link_to_update_password' => 'Please click on the following link to update your :web password:',
'login' => 'Login:', 'login' => 'Login:',
@ -86,6 +87,7 @@ return [
'upcoming-audits' => 'There is :count asset that is coming up for audit within :threshold days.|There are :count assets that are coming up for audit within :threshold days.', 'upcoming-audits' => 'There is :count asset that is coming up for audit within :threshold days.|There are :count assets that are coming up for audit within :threshold days.',
'user' => 'User', 'user' => 'User',
'username' => 'Username', 'username' => 'Username',
'unaccepted_asset_reminder' => 'You have Unnaccepted Assets.',
'welcome' => 'Welcome :name', 'welcome' => 'Welcome :name',
'welcome_to' => 'Welcome to :web!', 'welcome_to' => 'Welcome to :web!',
'your_assets' => 'View Your Assets', 'your_assets' => 'View Your Assets',

View file

@ -1,31 +1,7 @@
@component('mail::message') @component('mail::message')
# {{ trans('mail.hello') }}, # {{ trans('mail.hello') }} {{ $assigned_to}},
{{ $intro_text }}. {{ trans('mail.item_checked_reminder', ['link' => $link, 'count' => $count]) }}
@component('mail::table')
| | |
| ------------- | ------------- |
| **{{ trans('mail.user') }}** | {{ $assigned_to }} |
@if (isset($accepted_date))
| **{{ ucfirst(trans('general.accepted')) }}** | {{ $accepted_date }} |
@endif
@if (isset($declined_date))
| **{{ ucfirst(trans('general.declined')) }}** | {{ $declined_date }} |
@endif
@if ((isset($item_tag)) && ($item_tag!=''))
| **{{ trans('mail.asset_tag') }}** | {{ $item_tag }} |
@endif
@if ((isset($item_model)) && ($item_model!=''))
| **{{ trans('mail.asset_name') }}** | {{ $item_model }} |
@endif
@if (isset($item->model))
| **{{ trans('general.asset_model') }}** | {{ $item->model->name }} |
@endif
@if (isset($item_serial))
| **{{ trans('mail.serial') }}** | {{ $item_serial }} |
@endif
@endcomponent
{{ trans('mail.best_regards') }} {{ trans('mail.best_regards') }}