fixes checkout emails to location for assets and accessories"

This commit is contained in:
Godfrey M
2025-08-26 16:00:26 -07:00
parent 75995b2109
commit 8a74d21ede
3 changed files with 48 additions and 14 deletions
+36 -2
View File
@@ -3,6 +3,8 @@
namespace App\Mail;
use App\Models\Accessory;
use App\Models\Asset;
use App\Models\Location;
use App\Models\Setting;
use App\Models\User;
use Illuminate\Bus\Queueable;
@@ -41,7 +43,7 @@ class CheckoutAccessoryMail extends Mailable
return new Envelope(
from: $from,
subject: (trans('mail.Accessory_Checkout_Notification')),
subject: trans('mail.Accessory_Checkout_Notification'),
);
}
@@ -54,6 +56,17 @@ class CheckoutAccessoryMail extends Mailable
$eula = $this->item->getEula();
$req_accept = $this->item->requireAcceptance();
$accept_url = is_null($this->acceptance) ? null : route('account.accept.item', $this->acceptance);
$name = null;
if($this->target instanceof User){
$name = $this->target->display_name;
}
else if($this->target instanceof Asset){
$name = $this->target->assignedto?->display_name;
}
else if($this->target instanceof Location){
$name = $this->target->manager->name;
}
return new Content(
markdown: 'mail.markdown.checkout-accessory',
@@ -61,14 +74,35 @@ class CheckoutAccessoryMail extends Mailable
'item' => $this->item,
'admin' => $this->admin,
'note' => $this->note,
'target' => $this->target,
'target' => $name,
'eula' => $eula,
'req_accept' => $req_accept,
'accept_url' => $accept_url,
'checkout_qty' => $this->checkout_qty,
'introduction_line' => $this->introductionLine(),
],
);
}
private function introductionLine(): string
{
if ($this->target instanceof Location) {
return trans('mail.new_item_checked_location', ['location' => $this->target->name ]);
}
if ($this->requiresAcceptance()) {
return trans('mail.new_item_checked_with_acceptance');
}
if (!$this->requiresAcceptance()) {
return trans('mail.new_item_checked');
}
// we shouldn't get here but let's send a default message just in case
return trans('new_item_checked');
}
private function requiresAcceptance(): int|bool
{
return method_exists($this->item, 'requireAcceptance') ? $this->item->requireAcceptance() : 0;
}
/**
* Get the attachments for the message.
+10 -10
View File
@@ -78,16 +78,16 @@ class CheckoutAssetMail extends Mailable
$eula = method_exists($this->item, 'getEula') ? $this->item->getEula() : '';
$req_accept = $this->requiresAcceptance();
$fields = [];
$location = [false, ''];
$name = null;
if($this->target instanceof User){
$this->target = $this->target->display_name;
$name = $this->target->display_name;
}
else if($this->target instanceof Asset){
$this->target = $this->target->assignedto?->display_name;
$name = $this->target->assignedto?->display_name;
}
else if($this->target instanceof Location){
$location = [true, $this->target->name];
$this->target = $this->target->manager->name;
$name = $this->target->manager->name;
}
// Check if the item has custom fields associated with it
@@ -104,14 +104,14 @@ class CheckoutAssetMail extends Mailable
'admin' => $this->admin,
'status' => $this->item->assetstatus?->name,
'note' => $this->note,
'target' => $this->target,
'target' => $name,
'fields' => $fields,
'eula' => $eula,
'req_accept' => $req_accept,
'accept_url' => $accept_url,
'last_checkout' => $this->last_checkout,
'expected_checkin' => $this->expected_checkin,
'introduction_line' => $this->introductionLine($location),
'introduction_line' => $this->introductionLine(),
],
);
}
@@ -135,10 +135,10 @@ class CheckoutAssetMail extends Mailable
return trans('mail.unaccepted_asset_reminder');
}
private function introductionLine($location= null): string
private function introductionLine(): string
{
if ($this->firstTimeSending && $location[0]) {
return trans('mail.new_item_checked_location', ['location' => $location[1] ]);
if ($this->firstTimeSending && $this->target instanceof Location) {
return trans('mail.new_item_checked_location', ['location' => $this->target->name ]);
}
if ($this->firstTimeSending && $this->requiresAcceptance()) {
return trans('mail.new_item_checked_with_acceptance');
@@ -1,7 +1,7 @@
@component('mail::message')
# {{ trans('mail.hello') }}{{ $target->assignedto?->display_name ? ' ' . $target->assignedto->display_name . ',' : ',' }}
# {{ trans('mail.hello').' '.$target.','}}
{{ trans('mail.new_item_checked') }}
{{ $introduction_line }}
@if (($snipeSettings->show_images_in_email =='1') && $item->getImageUrl())
<center><img src="{{ $item->getImageUrl() }}" alt="Accessory" style="max-width: 570px;"></center>