-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14722 from Godmartinz/unaccepted_reminder_command
Adds a command to resend acceptance emails
- Loading branch information
Showing
4 changed files
with
191 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
<?php | ||
|
||
namespace App\Console\Commands; | ||
|
||
use App\Models\Asset; | ||
use App\Models\CheckoutAcceptance; | ||
use App\Models\Setting; | ||
use App\Models\User; | ||
use App\Notifications\CheckoutAssetNotification; | ||
use App\Notifications\CurrentInventory; | ||
use App\Notifications\UnacceptedAssetReminderNotification; | ||
use Illuminate\Console\Command; | ||
use Illuminate\Support\Facades\Notification; | ||
|
||
class SendAcceptanceReminder extends Command | ||
{ | ||
/** | ||
* The name and signature of the console command. | ||
* | ||
* @var string | ||
*/ | ||
protected $signature = 'snipeit:acceptance-reminder'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'This will resend users with unaccepted assets a reminder to accept or decline them.'; | ||
|
||
/** | ||
* Create a new command instance. | ||
* | ||
* @return void | ||
*/ | ||
public function __construct() | ||
{ | ||
parent::__construct(); | ||
} | ||
|
||
/** | ||
* Execute the console command. | ||
* | ||
* @return mixed | ||
*/ | ||
public function handle() | ||
{ | ||
$pending = CheckoutAcceptance::pending()->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.'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?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; | ||
$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 [ | ||
// | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
resources/views/notifications/markdown/asset-reminder.blade.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |