Skip to content

A free open source IT asset/license management system

fixes checkout emails to location for assets and accessories"

Godfrey M8a74d21eded7
diff --git a/app/Mail/CheckoutAccessoryMail.php b/app/Mail/CheckoutAccessoryMail.php
index 64c02e31ed..92ce84a2d6 100644
--- a/app/Mail/CheckoutAccessoryMail.php
+++ b/app/Mail/CheckoutAccessoryMail.php
@@ -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.
diff --git a/app/Mail/CheckoutAssetMail.php b/app/Mail/CheckoutAssetMail.php
index 81b4ec35b5..0dcd568bab 100644
--- a/app/Mail/CheckoutAssetMail.php
+++ b/app/Mail/CheckoutAssetMail.php
@@ -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');
diff --git a/resources/views/mail/markdown/checkout-accessory.blade.php b/resources/views/mail/markdown/checkout-accessory.blade.php
index 900a5b17a9..ecca7036df 100644
--- a/resources/views/mail/markdown/checkout-accessory.blade.php
+++ b/resources/views/mail/markdown/checkout-accessory.blade.php
@@ -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>