fixed query, fixed no email logic, needs new markdown

This commit is contained in:
Godfrey M 2024-05-21 09:42:00 -07:00
parent c658a0fcb4
commit 8a0afae90f
2 changed files with 54 additions and 4 deletions

View file

@ -44,18 +44,30 @@ class SendAcceptanceReminder extends Command
*/
public function handle()
{
$acceptances = CheckoutAcceptance::pending()->where('checkoutable_type', 'App\Models\Asset')->with(['assignedTo', 'checkoutable.assignedTo', 'checkoutable.model', 'checkoutable.adminuser'])->get();
$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;
$unacceptedAssets = $acceptances
$unacceptedAssets = $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($unacceptedAssets as $unacceptedAsset) {
if ($unacceptedAsset['acceptance']->assignedTo->email == ''){
$no_mail_address[] = $unacceptedAsset['checkoutable']->assignedTo->present()->fullName;
}
if ($unacceptedAsset['acceptance']->assignedTo) {
if (!$unacceptedAsset['acceptance']->assignedTo->locale) {
@ -73,8 +85,12 @@ class SendAcceptanceReminder extends Command
}
}
if ($unacceptedAsset['acceptance']->assignedTo->email == ''){
return "no email";
if (!empty($no_mail_address)) {
foreach($no_mail_address as $user) {
return $user.' has no email.';
}
}

View file

@ -0,0 +1,34 @@
@component('mail::message')
# {{ trans('mail.hello') }},
{{ $intro_text }}.
@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') }}
{{ $snipeSettings->site_name }}
@endcomponent