From ab67c48352654b06da681e55a1a524fb33365ee9 Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Mon, 2 Dec 2024 13:03:09 -0800 Subject: [PATCH 1/4] fix unaccepted assets report resend acceptance --- app/Http/Controllers/ReportsController.php | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/app/Http/Controllers/ReportsController.php b/app/Http/Controllers/ReportsController.php index 0d4bb936b2..303d608e15 100644 --- a/app/Http/Controllers/ReportsController.php +++ b/app/Http/Controllers/ReportsController.php @@ -3,6 +3,7 @@ namespace App\Http\Controllers; use App\Helpers\Helper; +use App\Mail\CheckoutAssetMail; use App\Models\Accessory; use App\Models\Actionlog; use App\Models\Asset; @@ -18,6 +19,7 @@ use App\Notifications\CheckoutAssetNotification; use Carbon\Carbon; use Illuminate\Http\Request; use Illuminate\Http\Response; +use Illuminate\Support\Facades\Mail; use Illuminate\Support\Facades\Notification; use \Illuminate\Contracts\View\View; use League\Csv\Reader; @@ -1152,20 +1154,12 @@ class ReportsController extends Controller } // Only send notification if assigned - if ($assetItem->assignedTo) { + if ($assetItem->assignedTo->email) { + Mail::to($assetItem->assignedTo->email)->send((new CheckoutAssetMail($assetItem, $assetItem->assignedTo, $logItem->user, $logItem->note, $acceptance))->locale($assetItem->assignedTo?->locale)); - if (!$assetItem->assignedTo->locale) { - Notification::locale(Setting::getSettings()->locale)->send( - $assetItem->assignedTo, - new CheckoutAssetNotification($assetItem, $assetItem->assignedTo, $logItem->user, $acceptance, $logItem->note) - ); } else { - Notification::send( - $assetItem->assignedTo, - new CheckoutAssetNotification($assetItem, $assetItem->assignedTo, $logItem->user, $acceptance, $logItem->note) - ); + Mail::to($assetItem->assignedTo->email)->send((new CheckoutAssetMail($assetItem, $assetItem->assignedTo, $logItem->user, $logItem->note, $acceptance))); } - } if ($assetItem->assignedTo->email == ''){ return redirect()->route('reports/unaccepted_assets')->with('error', trans('general.no_email')); From 983b78edd936752727bb2a35ea6af595eb593497 Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Mon, 2 Dec 2024 14:27:04 -0800 Subject: [PATCH 2/4] add property check --- app/Http/Controllers/ReportsController.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/ReportsController.php b/app/Http/Controllers/ReportsController.php index 303d608e15..51484fe216 100644 --- a/app/Http/Controllers/ReportsController.php +++ b/app/Http/Controllers/ReportsController.php @@ -1154,14 +1154,14 @@ class ReportsController extends Controller } // Only send notification if assigned - if ($assetItem->assignedTo->email) { + if ($assetItem->assignedTo?->email) { Mail::to($assetItem->assignedTo->email)->send((new CheckoutAssetMail($assetItem, $assetItem->assignedTo, $logItem->user, $logItem->note, $acceptance))->locale($assetItem->assignedTo?->locale)); } else { Mail::to($assetItem->assignedTo->email)->send((new CheckoutAssetMail($assetItem, $assetItem->assignedTo, $logItem->user, $logItem->note, $acceptance))); } - if ($assetItem->assignedTo->email == ''){ + if ($assetItem->assignedTo?->email == ''){ return redirect()->route('reports/unaccepted_assets')->with('error', trans('general.no_email')); } From de41def2b323d8f9227f56b6a84380f9039beb00 Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Thu, 5 Dec 2024 10:15:57 -0800 Subject: [PATCH 3/4] fixed conditionals --- app/Http/Controllers/ReportsController.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/app/Http/Controllers/ReportsController.php b/app/Http/Controllers/ReportsController.php index 51484fe216..fa454cbc01 100644 --- a/app/Http/Controllers/ReportsController.php +++ b/app/Http/Controllers/ReportsController.php @@ -1152,13 +1152,14 @@ class ReportsController extends Controller } $logItem = $logItem_res[0]; } - + $email = $assetItem->assignedTo?->email; + $locale = $assetItem->assignedTo?->locale; // Only send notification if assigned - if ($assetItem->assignedTo?->email) { - Mail::to($assetItem->assignedTo->email)->send((new CheckoutAssetMail($assetItem, $assetItem->assignedTo, $logItem->user, $logItem->note, $acceptance))->locale($assetItem->assignedTo?->locale)); + if ($locale && $email) { + Mail::to($email)->send((new CheckoutAssetMail($assetItem, $assetItem->assignedTo, $logItem->user, $logItem->note, $acceptance))->locale($locale)); - } else { - Mail::to($assetItem->assignedTo->email)->send((new CheckoutAssetMail($assetItem, $assetItem->assignedTo, $logItem->user, $logItem->note, $acceptance))); + } elseif ($email) { + Mail::to($email)->send((new CheckoutAssetMail($assetItem, $assetItem->assignedTo, $logItem->user, $logItem->note, $acceptance))); } if ($assetItem->assignedTo?->email == ''){ From f6b9ae6aee4f2e3f3062f4f2e26dca6b2bf6e993 Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Thu, 5 Dec 2024 10:18:35 -0800 Subject: [PATCH 4/4] missed a spot --- app/Http/Controllers/ReportsController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Controllers/ReportsController.php b/app/Http/Controllers/ReportsController.php index fa454cbc01..03f7ec1c3f 100644 --- a/app/Http/Controllers/ReportsController.php +++ b/app/Http/Controllers/ReportsController.php @@ -1162,7 +1162,7 @@ class ReportsController extends Controller Mail::to($email)->send((new CheckoutAssetMail($assetItem, $assetItem->assignedTo, $logItem->user, $logItem->note, $acceptance))); } - if ($assetItem->assignedTo?->email == ''){ + if ($email == ''){ return redirect()->route('reports/unaccepted_assets')->with('error', trans('general.no_email')); }