From e957ce07034c40435f8a90cd4e739facaee8135a Mon Sep 17 00:00:00 2001 From: Ravi Gulhane Date: Fri, 30 Oct 2026 09:31:37 +0530 Subject: [PATCH] Changes --- .../NeblogisticreportController.php | 149 ++++++++++++++---- ...llocations_update_2026-10-28_aravind_m.sql | 92 +++++++++++ 2 files changed, 213 insertions(+), 28 deletions(-) create mode 100644 database/sql/incept_neb_allocations_update_2026-10-28_aravind_m.sql diff --git a/app/Http/Controllers/NeblogisticreportController.php b/app/Http/Controllers/NeblogisticreportController.php index 36c9ea6c..84ce6d0b 100644 --- a/app/Http/Controllers/NeblogisticreportController.php +++ b/app/Http/Controllers/NeblogisticreportController.php @@ -485,38 +485,54 @@ class NeblogisticreportController extends Controller $data = DB::table('neblogistic')->where('id', $params['record_id'])->first(); - + $emailWarnings = []; + if (isset($params['status'])) { if ($params['status'] == 'Rejected') { - - Mail::to($data->emp_email) - ->cc($data->abm_email) - ->send(new NeblogisticRejection((array)$data)); - Mail::to('ravigulhane1983@gmail.com')->send(new NeblogisticRejection((array)$data)); - - } - elseif (in_array($params['status'], ['Dispatched', 'Delivered'], true)) { + $rejectWarn = $this->sendNeblogisticMailSafely( + new NeblogisticRejection((array) $data), + $data->emp_email ?? null, + $data->abm_email ?? null, + ['id' => $data->id ?? null, 'mail' => 'rejection'] + ); + if ($rejectWarn !== null) { + $emailWarnings[] = $rejectWarn; + } + try { + Mail::to('ravigulhane1983@gmail.com')->send(new NeblogisticRejection((array) $data)); + } catch (\Throwable $e) { + Log::error('Neblogistic rejection debug email failed', [ + 'id' => $data->id ?? null, + 'message' => $e->getMessage(), + ]); + } + } elseif (in_array($params['status'], ['Dispatched', 'Delivered'], true)) { Log::info('Neblogistic status update email', [ 'data' => $data, ]); - // Send to TM (emp_email) - if (!empty($data->emp_email)) { - Mail::to($data->emp_email) - ->send(new NeblogisticStatusUpdate((array)$data, 'tm')); + $tmWarn = $this->sendNeblogisticMailSafely( + new NeblogisticStatusUpdate((array) $data, 'tm'), + $data->emp_email ?? null, + null, + ['id' => $data->id ?? null, 'mail' => 'status_tm'] + ); + if ($tmWarn !== null) { + $emailWarnings[] = $tmWarn; } - - // Send to ABM (abm_email) - if (!empty($data->abm_email)) { - Mail::to($data->abm_email) - ->send(new NeblogisticStatusUpdate((array)$data, 'abm')); + $abmWarn = $this->sendNeblogisticMailSafely( + new NeblogisticStatusUpdate((array) $data, 'abm'), + $data->abm_email ?? null, + null, + ['id' => $data->id ?? null, 'mail' => 'status_abm'] + ); + if ($abmWarn !== null) { + $emailWarnings[] = $abmWarn; } // Prevent cron from re-sending the same status email DB::table('neblogistic') ->where('id', $params['record_id']) ->update(['status_email_sent' => $params['status']]); - } else { - } } @@ -529,15 +545,22 @@ class NeblogisticreportController extends Controller $data->pin_code = $data->address_pin_code; $data->clinic_hospital_home_name = $data->clinic_hospital_name; - Mail::to($data->emp_email) - ->cc($data->abm_email) - ->send(new Neblogistic((array)$data)); + $editWarn = $this->sendNeblogisticMailSafely( + new Neblogistic((array) $data), + $data->emp_email ?? null, + $data->abm_email ?? null, + ['id' => $data->id ?? null, 'mail' => 'edit_notification'] + ); + if ($editWarn !== null) { + $emailWarnings[] = $editWarn; + } //Mail::to('arbaz@stratawiz.com')->send(new NeblogisticSupervisor((array)$data)); $user = Auth::user(); - - // echo "
";
-        // print_r($params);
+        $successMessage = 'Data Saved';
+        if (!empty($emailWarnings)) {
+            $successMessage .= '. ' . implode(' ', array_unique($emailWarnings));
+        }
 
         if(!$params['submission_id'] == ''){
         // return print_r($params);
@@ -546,7 +569,7 @@ class NeblogisticreportController extends Controller
             $history = LambdaRequest::signedrequest('post', 'form', 'formentity/submitform', $post, 120);
             Log::info('formsubmission after edit', [ 'history' => $history]);
             if ($history->status === 'success') {
-                return redirect()->back()->with('message', 'Data Saved');
+                return redirect()->back()->with('message', $successMessage);
             } else {
                 return redirect()->back()->with('error', 'Operation failed.');
             }
@@ -557,7 +580,7 @@ class NeblogisticreportController extends Controller
 
 
         if ($dataUpdate) {
-            return redirect()->back()->with('message', 'Data Saved');
+            return redirect()->back()->with('message', $successMessage);
         } else {
             return redirect()->back()->with('error', 'Operation failed.');
         }
@@ -2048,6 +2071,76 @@ class NeblogisticreportController extends Controller
         return is_object($response) && ($response->status ?? '') === 'success';
     }
 
+    /**
+     * True when value is a real mailbox (rejects empty / Vacant placeholders).
+     */
+    protected function isValidNeblogisticEmail($email): bool
+    {
+        $email = trim((string) $email);
+        if ($email === '' || stripos($email, 'vacant') !== false) {
+            return false;
+        }
+        return (bool) filter_var($email, FILTER_VALIDATE_EMAIL);
+    }
+
+    /**
+     * Send a mailable without letting invalid Vacant/CC addresses 500 the request.
+     * Returns a short user-facing warning, or null when send succeeded / nothing to warn.
+     *
+     * @param  mixed  $mailable
+     * @param  string|null  $to
+     * @param  string|null  $cc
+     * @param  array  $context
+     */
+    protected function sendNeblogisticMailSafely($mailable, $to, $cc = null, array $context = []): ?string
+    {
+        $validTo = $this->isValidNeblogisticEmail($to) ? trim((string) $to) : null;
+        $validCc = $this->isValidNeblogisticEmail($cc) ? trim((string) $cc) : null;
+        $warnings = [];
+
+        if ($to !== null && trim((string) $to) !== '' && $validTo === null) {
+            $warnings[] = 'Notification email was not sent because the recipient email is missing or invalid (e.g. Vacant).';
+            Log::warning('Neblogistic email skipped: invalid to address', $context + [
+                'to' => $to,
+                'cc' => $cc,
+            ]);
+        } elseif ($cc !== null && trim((string) $cc) !== '' && $validCc === null) {
+            $warnings[] = 'ABM notification was skipped because the ABM email is missing or invalid (e.g. Vacant).';
+            Log::warning('Neblogistic email CC skipped: invalid cc address', $context + [
+                'to' => $to,
+                'cc' => $cc,
+            ]);
+        }
+
+        if ($validTo === null) {
+            return $warnings[0] ?? 'Notification email was not sent because no valid recipient email was found.';
+        }
+
+        try {
+            $pending = Mail::to($validTo);
+            if ($validCc !== null) {
+                $pending->cc($validCc);
+            }
+            $pending->send($mailable);
+        } catch (\Swift_RfcComplianceException $e) {
+            Log::error('Neblogistic email RFC error', $context + [
+                'to' => $validTo,
+                'cc' => $validCc,
+                'message' => $e->getMessage(),
+            ]);
+            return 'Notification email could not be sent due to an invalid email address.';
+        } catch (\Throwable $e) {
+            Log::error('Neblogistic email failed', $context + [
+                'to' => $validTo,
+                'cc' => $validCc,
+                'message' => $e->getMessage(),
+            ]);
+            return 'Notification email could not be sent.';
+        }
+
+        return $warnings[0] ?? null;
+    }
+
     protected function normalizeNapPartition(?string $partition): string
     {
         $partition = trim((string) $partition);
diff --git a/database/sql/incept_neb_allocations_update_2026-10-28_aravind_m.sql b/database/sql/incept_neb_allocations_update_2026-10-28_aravind_m.sql
new file mode 100644
index 00000000..8a81bf64
--- /dev/null
+++ b/database/sql/incept_neb_allocations_update_2026-10-28_aravind_m.sql
@@ -0,0 +1,92 @@
+-- Nebulizers Allocation Data - 28102026 ARAVIND M.xlsx
+-- UPDATE incept_neb_allocations for 28 employees (sheet under ARAVIND M).
+-- Existing incept_neb_usage rows are left untouched.
+-- 27 rows differ from current DB (mostly control_d_qty); 144137 ARAVIND M unchanged.
+-- Sheet totals: Robust 332, Mini 395, Control D 319.
+START TRANSACTION;
+
+-- 144137 / ARAVIND M  Robust 11, Mini 5, Control D 0
+UPDATE incept_neb_allocations SET emp_name = 'ARAVIND M', designation = 'Area Business Manager', team = 'Neb - Arise', robust_qty = 11, mini_qty = 5, control_d_qty = 0, updated_at = '2026-10-28 00:00:00' WHERE emp_id = '144137';
+
+-- 179234 / Harish Kumar  Robust 0, Mini 10, Control D 0
+UPDATE incept_neb_allocations SET emp_name = 'Harish Kumar', designation = 'Therapy Manager', team = 'Neb - Arise', robust_qty = 0, mini_qty = 10, control_d_qty = 0, updated_at = '2026-10-28 00:00:00' WHERE emp_id = '179234';
+
+-- 147085 / Paladi Vikas  Robust 11, Mini 15, Control D 0
+UPDATE incept_neb_allocations SET emp_name = 'Paladi Vikas', designation = 'Therapy Manager', team = 'Neb 1', robust_qty = 11, mini_qty = 15, control_d_qty = 0, updated_at = '2026-10-28 00:00:00' WHERE emp_id = '147085';
+
+-- 149522 / Banty .  Robust 11, Mini 15, Control D 0
+UPDATE incept_neb_allocations SET emp_name = 'Banty .', designation = 'Therapy Manager', team = 'Neb 1', robust_qty = 11, mini_qty = 15, control_d_qty = 0, updated_at = '2026-10-28 00:00:00' WHERE emp_id = '149522';
+
+-- 173569 / Raghav Tiwari  Robust 11, Mini 15, Control D 0
+UPDATE incept_neb_allocations SET emp_name = 'Raghav Tiwari', designation = 'Therapy Manager', team = 'Neb 1', robust_qty = 11, mini_qty = 15, control_d_qty = 0, updated_at = '2026-10-28 00:00:00' WHERE emp_id = '173569';
+
+-- 176198 / Enukonda Vishwanth  Robust 11, Mini 15, Control D 0
+UPDATE incept_neb_allocations SET emp_name = 'Enukonda Vishwanth', designation = 'Therapy Manager', team = 'Neb 2', robust_qty = 11, mini_qty = 15, control_d_qty = 0, updated_at = '2026-10-28 00:00:00' WHERE emp_id = '176198';
+
+-- 165632 / Aashi Gupta  Robust 11, Mini 15, Control D 15
+UPDATE incept_neb_allocations SET emp_name = 'Aashi Gupta', designation = 'Therapy Manager', team = 'Neb 2', robust_qty = 11, mini_qty = 15, control_d_qty = 15, updated_at = '2026-10-28 00:00:00' WHERE emp_id = '165632';
+
+-- 168436 / Ashish Singh Chauhan  Robust 11, Mini 15, Control D 15
+UPDATE incept_neb_allocations SET emp_name = 'Ashish Singh Chauhan', designation = 'Therapy Manager', team = 'Neb 2', robust_qty = 11, mini_qty = 15, control_d_qty = 15, updated_at = '2026-10-28 00:00:00' WHERE emp_id = '168436';
+
+-- 169088 / Bharti Rajput  Robust 11, Mini 15, Control D 15
+UPDATE incept_neb_allocations SET emp_name = 'Bharti Rajput', designation = 'Therapy Manager', team = 'Neb 2', robust_qty = 11, mini_qty = 15, control_d_qty = 15, updated_at = '2026-10-28 00:00:00' WHERE emp_id = '169088';
+
+-- 169431 / Anamika Anni Shukla  Robust 11, Mini 15, Control D 15
+UPDATE incept_neb_allocations SET emp_name = 'Anamika Anni Shukla', designation = 'Therapy Manager', team = 'Neb 2', robust_qty = 11, mini_qty = 15, control_d_qty = 15, updated_at = '2026-10-28 00:00:00' WHERE emp_id = '169431';
+
+-- 170212 / Upender Yadav  Robust 11, Mini 15, Control D 15
+UPDATE incept_neb_allocations SET emp_name = 'Upender Yadav', designation = 'Therapy Manager', team = 'Neb 2', robust_qty = 11, mini_qty = 15, control_d_qty = 15, updated_at = '2026-10-28 00:00:00' WHERE emp_id = '170212';
+
+-- 170214 / Priyanshi Sharma  Robust 11, Mini 15, Control D 15
+UPDATE incept_neb_allocations SET emp_name = 'Priyanshi Sharma', designation = 'Therapy Manager', team = 'Neb 2', robust_qty = 11, mini_qty = 15, control_d_qty = 15, updated_at = '2026-10-28 00:00:00' WHERE emp_id = '170214';
+
+-- 170282 / Parshant Mavi  Robust 11, Mini 15, Control D 15
+UPDATE incept_neb_allocations SET emp_name = 'Parshant Mavi', designation = 'Therapy Manager', team = 'Neb 2', robust_qty = 11, mini_qty = 15, control_d_qty = 15, updated_at = '2026-10-28 00:00:00' WHERE emp_id = '170282';
+
+-- 171898 / Priyanshu Pandey  Robust 11, Mini 15, Control D 15
+UPDATE incept_neb_allocations SET emp_name = 'Priyanshu Pandey', designation = 'Therapy Manager', team = 'Neb 2', robust_qty = 11, mini_qty = 15, control_d_qty = 15, updated_at = '2026-10-28 00:00:00' WHERE emp_id = '171898';
+
+-- 172432 / Aditya Joshi  Robust 11, Mini 15, Control D 15
+UPDATE incept_neb_allocations SET emp_name = 'Aditya Joshi', designation = 'Therapy Manager', team = 'Neb 2', robust_qty = 11, mini_qty = 15, control_d_qty = 15, updated_at = '2026-10-28 00:00:00' WHERE emp_id = '172432';
+
+-- 176201 / Deepali shrivastav  Robust 11, Mini 15, Control D 15
+UPDATE incept_neb_allocations SET emp_name = 'Deepali shrivastav', designation = 'Therapy Manager', team = 'Neb 2', robust_qty = 11, mini_qty = 15, control_d_qty = 15, updated_at = '2026-10-28 00:00:00' WHERE emp_id = '176201';
+
+-- 177311 / Sakshi Kanojia  Robust 6, Mini 10, Control D 15
+UPDATE incept_neb_allocations SET emp_name = 'Sakshi Kanojia', designation = 'Management Trainee', team = 'Neb 2', robust_qty = 6, mini_qty = 10, control_d_qty = 15, updated_at = '2026-10-28 00:00:00' WHERE emp_id = '177311';
+
+-- 127020 / Pawan Panwar  Robust 16, Mini 15, Control D 15
+UPDATE incept_neb_allocations SET emp_name = 'Pawan Panwar', designation = 'Therapy Manager', team = 'Neb 2', robust_qty = 16, mini_qty = 15, control_d_qty = 15, updated_at = '2026-10-28 00:00:00' WHERE emp_id = '127020';
+
+-- 129394 / Rakesh Kumar  Robust 26, Mini 15, Control D 13
+UPDATE incept_neb_allocations SET emp_name = 'Rakesh Kumar', designation = 'Therapy Manager', team = 'Neb 2', robust_qty = 26, mini_qty = 15, control_d_qty = 13, updated_at = '2026-10-28 00:00:00' WHERE emp_id = '129394';
+
+-- 139813 / Rohit Dhall  Robust 24, Mini 15, Control D 15
+UPDATE incept_neb_allocations SET emp_name = 'Rohit Dhall', designation = 'Therapy Manager', team = 'Neb 2', robust_qty = 24, mini_qty = 15, control_d_qty = 15, updated_at = '2026-10-28 00:00:00' WHERE emp_id = '139813';
+
+-- 156360 / Akash Kumar Bharti  Robust 11, Mini 15, Control D 13
+UPDATE incept_neb_allocations SET emp_name = 'Akash Kumar Bharti', designation = 'Therapy Manager', team = 'Neb 2', robust_qty = 11, mini_qty = 15, control_d_qty = 13, updated_at = '2026-10-28 00:00:00' WHERE emp_id = '156360';
+
+-- 159248 / Ashok Kumar  Robust 11, Mini 15, Control D 15
+UPDATE incept_neb_allocations SET emp_name = 'Ashok Kumar', designation = 'Therapy Manager', team = 'Neb 2', robust_qty = 11, mini_qty = 15, control_d_qty = 15, updated_at = '2026-10-28 00:00:00' WHERE emp_id = '159248';
+
+-- 161573 / Amandeep .  Robust 21, Mini 15, Control D 15
+UPDATE incept_neb_allocations SET emp_name = 'Amandeep .', designation = 'Therapy Manager', team = 'Neb 2', robust_qty = 21, mini_qty = 15, control_d_qty = 15, updated_at = '2026-10-28 00:00:00' WHERE emp_id = '161573';
+
+-- 165238 / Ankit .  Robust 19, Mini 15, Control D 15
+UPDATE incept_neb_allocations SET emp_name = 'Ankit .', designation = 'Therapy Manager', team = 'Neb 2', robust_qty = 19, mini_qty = 15, control_d_qty = 15, updated_at = '2026-10-28 00:00:00' WHERE emp_id = '165238';
+
+-- 172211 / Punit Bhardwaj  Robust 11, Mini 15, Control D 15
+UPDATE incept_neb_allocations SET emp_name = 'Punit Bhardwaj', designation = 'Therapy Manager', team = 'Neb 2', robust_qty = 11, mini_qty = 15, control_d_qty = 15, updated_at = '2026-10-28 00:00:00' WHERE emp_id = '172211';
+
+-- 172442 / Sanjana Kumari  Robust 11, Mini 15, Control D 10
+UPDATE incept_neb_allocations SET emp_name = 'Sanjana Kumari', designation = 'Therapy Manager', team = 'Neb 2', robust_qty = 11, mini_qty = 15, control_d_qty = 10, updated_at = '2026-10-28 00:00:00' WHERE emp_id = '172442';
+
+-- 174034 / Nandan .  Robust 11, Mini 15, Control D 15
+UPDATE incept_neb_allocations SET emp_name = 'Nandan .', designation = 'Therapy Manager', team = 'Neb 2', robust_qty = 11, mini_qty = 15, control_d_qty = 15, updated_at = '2026-10-28 00:00:00' WHERE emp_id = '174034';
+
+-- 178614 / Digvijay Sagar  Robust 0, Mini 10, Control D 13
+UPDATE incept_neb_allocations SET emp_name = 'Digvijay Sagar', designation = 'Therapy Manager', team = 'Neb 2', robust_qty = 0, mini_qty = 10, control_d_qty = 13, updated_at = '2026-10-28 00:00:00' WHERE emp_id = '178614';
+
+COMMIT;