diff --git a/app/Console/Commands/SendAcceptanceReminder.php b/app/Console/Commands/SendAcceptanceReminder.php new file mode 100644 index 000000000000..dd9e59f611d0 --- /dev/null +++ b/app/Console/Commands/SendAcceptanceReminder.php @@ -0,0 +1,105 @@ +where('checkoutable_type', 'App\Models\Asset') + ->whereHas('checkoutable', function($query) { + $query->where('archived', 0); + }) + ->with(['assignedTo', 'checkoutable.assignedTo', 'checkoutable.model', 'checkoutable.adminuser']) + ->get(); + + $count = 0; + $unacceptedAssetGroups = $pending + ->filter(function($acceptance) { + return $acceptance->checkoutable_type == 'App\Models\Asset'; + }) + ->map(function($acceptance) { + return ['assetItem' => $acceptance->checkoutable, 'acceptance' => $acceptance]; + }) + ->groupBy(function($item) { + return $item['acceptance']->assignedTo ? $item['acceptance']->assignedTo->id : ''; + }); + + $no_mail_address = []; + + foreach($unacceptedAssetGroups as $unacceptedAssetGroup) { + $item_count = $unacceptedAssetGroup->count(); + 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->locale) { + Notification::locale(Setting::getSettings()->locale)->send( + $unacceptedAsset['acceptance']->assignedTo, + new UnacceptedAssetReminderNotification($unacceptedAsset['assetItem'], $count) + ); + } else { + Notification::send( + $unacceptedAsset['acceptance']->assignedTo, + new UnacceptedAssetReminderNotification($unacceptedAsset, $item_count) + ); + } + $count++; + } + } + } + + if (!empty($no_mail_address)) { + foreach($no_mail_address as $user) { + return $user.' has no email.'; + } + + + } + + + + $this->info($count.' users notified.'); + } +} diff --git a/app/Notifications/UnacceptedAssetReminderNotification.php b/app/Notifications/UnacceptedAssetReminderNotification.php new file mode 100644 index 000000000000..e05b007033cf --- /dev/null +++ b/app/Notifications/UnacceptedAssetReminderNotification.php @@ -0,0 +1,73 @@ +count = $count; + $this->target = $checkout_info['acceptance']->assignedTo; + $this->acceptance = $checkout_info['acceptance']; + + } + + /** + * 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() + { + $accept_url = route('account.accept'); + $message = (new MailMessage)->markdown('notifications.markdown.asset-reminder', + [ + 'count' => $this->count, + 'assigned_to' => $this->target->present()->fullName, + 'link' => route('account.accept'), + 'accept_url' => $accept_url, + ]) + ->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 [ + // + ]; + } +} diff --git a/resources/lang/en-US/mail.php b/resources/lang/en-US/mail.php index 759ff0f5e8b2..706f92bbec02 100644 --- a/resources/lang/en-US/mail.php +++ b/resources/lang/en-US/mail.php @@ -56,6 +56,7 @@ 'i_have_read' => 'I have read and agree to the terms of use, and have received this item.', 'inventory_report' => 'Inventory Report', '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 click the link below to confirm your decision.', '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:', 'login' => 'Login:', @@ -86,6 +87,7 @@ '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', 'username' => 'Username', + 'unaccepted_asset_reminder' => 'You have Unaccepted Assets.', 'welcome' => 'Welcome :name', 'welcome_to' => 'Welcome to :web!', 'your_assets' => 'View Your Assets', diff --git a/resources/views/notifications/markdown/asset-reminder.blade.php b/resources/views/notifications/markdown/asset-reminder.blade.php new file mode 100644 index 000000000000..408c3847f4c7 --- /dev/null +++ b/resources/views/notifications/markdown/asset-reminder.blade.php @@ -0,0 +1,11 @@ +@component('mail::message') + # {{ trans('mail.hello') }} {{ $assigned_to}}, + + {{trans('mail.item_checked_reminder', ['count' => $count])}} + [{{ trans('general.click_here')}}]({{$accept_url}}) + + {{ trans('mail.best_regards') }} + + {{ $snipeSettings->site_name }} + +@endcomponent