From a832ea284cf6dcf38872d6aa9cbbeb3a5d68877b Mon Sep 17 00:00:00 2001 From: Gowtham M Date: Mon, 4 Aug 2025 11:35:15 +0530 Subject: [PATCH] GWM : tracker issue --- app/Controllers/PlanController.php | 4 +++- app/Helpers/common_helper.php | 5 ++++- app/Helpers/mail_helper.php | 19 ++++++++++++++++--- app/Helpers/status_helper.php | 4 +++- app/Models/PlanStatusModel.php | 8 ++++---- 5 files changed, 30 insertions(+), 10 deletions(-) diff --git a/app/Controllers/PlanController.php b/app/Controllers/PlanController.php index 7ab9177..fb7f86f 100644 --- a/app/Controllers/PlanController.php +++ b/app/Controllers/PlanController.php @@ -1475,6 +1475,8 @@ class PlanController extends ResourceController public function url() { + echo '
';
+        print_r(getPlanApproverAction(119)); die;
 
         return $this->generatePlanPdf(57, true);
         die;
@@ -1485,7 +1487,7 @@ class PlanController extends ResourceController
        
         echo '
';
         // sendPlanCreationMail(39);
-        print_r(getPlanApproverAction(52)); die;
+        
 
         // echo '
';
         // print_r(getAllowedClassForUser(2,4)['hotel']); die;
diff --git a/app/Helpers/common_helper.php b/app/Helpers/common_helper.php
index 7cfd57e..d02d7b9 100644
--- a/app/Helpers/common_helper.php
+++ b/app/Helpers/common_helper.php
@@ -130,7 +130,10 @@ if (!function_exists('isFlightTripDataChanged')) {
         }
 
         // Step 1: Fetch old data from the model
-        $oldData = $model->whereIn('flight_id', $flightIds)->where('is_active', 1)->findAll();
+        if(!empty($flightIds))
+            $oldData = $model->whereIn('flight_id', $flightIds)->where('is_active', 1)->findAll();
+        else
+            $oldData = [];
 
        
         if (!$oldData) {
diff --git a/app/Helpers/mail_helper.php b/app/Helpers/mail_helper.php
index 03229d0..b6da284 100644
--- a/app/Helpers/mail_helper.php
+++ b/app/Helpers/mail_helper.php
@@ -45,16 +45,24 @@ if (!function_exists('sendPlanCreationMail')) {
             if ($value['is_action_done'] == 1) { continue; }
             // Skip if action is None
             if ($value['action'] === 'None') { continue; }
+            // mail success check
+            if ($value['is_mail_send'] === 1) { continue; }
             // skip with below condition
             if($mailOn == 'send_mail_to_only_approver' && $action['parallel_process_from'] == 1){ continue; }
 
+           
+
            if($value['action'] == 'Approval'){ $template = 'plan_creation_approval_notification_to_approver'; }else if($value['action'] == 'Notification'){ $template = 'plan_creation_notification_to_approver'; }
             
             $userData = $userModel->where('user_id', $value['user_id'])->first();
 
             $url = urlButton($planId, $value['user_id']);
     
-            send_email($userData['org_id'] , $userData['email'], $template , $userData , $planData, $url);
+            $res = send_email($userData['org_id'] , $userData['email'], $template , $userData , $planData, $url);
+            if($res['status'] = 'success')
+            {
+                $planStatusModel->set([ $value['mail_send_key'] => 1 ])->where('plan_id', $planId)->where('is_active', 1)->update(); 
+            }
 
             // if action is notification update the action status as 1 (done)
             $parallelProcessValue =  $action['parallel_process_from'];
@@ -187,7 +195,6 @@ if (!function_exists('sendPlanUpdationMail')) {
         // Fetch user data
         $userData = $userModel->where('user_id', $userId)->first();
         
-
         // send mail to traveller
         send_email($planData['org_id'] , $userData['email'], 'plan_updation_notification_to_traveller' , $userData , $planData);
 
@@ -202,6 +209,8 @@ if (!function_exists('sendPlanUpdationMail')) {
              if ($value['is_action_done'] == 1) { continue; }
              // Skip if action is None
              if ($value['action'] === 'None') { continue; }
+             // mail success check
+             if ($value['is_mail_send'] === 1) { continue; }
 
             if($value['action'] == 'Approval'){ $template = 'plan_updation_approval_notification_to_approver'; }else if($value['action'] == 'Notification'){ $template = 'plan_updation_notification_to_approver'; }
             
@@ -209,7 +218,11 @@ if (!function_exists('sendPlanUpdationMail')) {
 
             $url = urlButton($planId, $value['user_id']);
     
-            send_email($userData['org_id'] , $userData['email'], $template , $userData , $planData, $url);
+            $res = send_email($userData['org_id'] , $userData['email'], $template , $userData , $planData, $url);     
+            if($res['status'] = 'success')
+            {
+                $planStatusModel->set([ $value['mail_send_key'] => 1 ])->where('plan_id', $planId)->where('is_active', 1)->update(); 
+            }
 
             // if action is notification update the action status as 1 (done)
             $parallelProcessValue =  $action['parallel_process_from'];
diff --git a/app/Helpers/status_helper.php b/app/Helpers/status_helper.php
index a72823f..e69d44d 100644
--- a/app/Helpers/status_helper.php
+++ b/app/Helpers/status_helper.php
@@ -161,7 +161,6 @@ if (!function_exists('palnStatusHandler')) {
         if ($is_data_edited == false) {
             log_message('info', "Creating new plan status for plan_id: {$plan_id}");
             $planStatusModel->insert($data);
-            echo $planStatusModel->db->getLastQuery();
         } else {
             $oldStatusData = $planStatusModel->where('plan_id', $plan_id)->where('is_active', 1)->first();
             if ($oldStatusData) {
@@ -743,6 +742,7 @@ if (!function_exists('getPlanApproverAction')) {
             $actionField = "{$field}_action";
             $idField = "{$field}_id";
             $doneField = "is_{$field}_action_done";
+            $mailField = "is_{$field}_mail_send";
 
             $record = $planStatusModel->where('plan_id', $plan_id)
                                     ->whereIn($actionField, ['Approval', 'Notification', 'None'])
@@ -761,6 +761,8 @@ if (!function_exists('getPlanApproverAction')) {
                         'where_key' => $idField,
                         'action_key' => $actionField,
                         'action_done_key' => $doneField,
+                        'mail_send_key' => $mailField,
+                        'is_mail_send' => $record[$mailField],
                     ];
                 }
             }
diff --git a/app/Models/PlanStatusModel.php b/app/Models/PlanStatusModel.php
index 5233fb3..0772ebb 100644
--- a/app/Models/PlanStatusModel.php
+++ b/app/Models/PlanStatusModel.php
@@ -12,10 +12,10 @@ class PlanStatusModel extends Model
     protected $allowedFields = [
         'plan_id',
         'service_id',
-        'a1_id', 'a1_action', 'is_a1_action_done', 'a1_reject_reason', 'a1_action_done_on','a1_action_done_by',
-        'a2_id', 'a2_action', 'is_a2_action_done', 'a2_reject_reason', 'a2_action_done_on','a2_action_done_by',
-        'a3_id', 'a3_action', 'is_a3_action_done', 'a3_reject_reason', 'a3_action_done_on','a3_action_done_by',
-        'a4_id', 'a4_action', 'is_a4_action_done', 'a4_reject_reason', 'a4_action_done_on','a4_action_done_by',
+        'a1_id', 'a1_action', 'is_a1_action_done', 'a1_reject_reason', 'a1_action_done_on','a1_action_done_by','is_a1_mail_send',
+        'a2_id', 'a2_action', 'is_a2_action_done', 'a2_reject_reason', 'a2_action_done_on','a2_action_done_by','is_a2_mail_send',
+        'a3_id', 'a3_action', 'is_a3_action_done', 'a3_reject_reason', 'a3_action_done_on','a3_action_done_by','is_a3_mail_send',
+        'a4_id', 'a4_action', 'is_a4_action_done', 'a4_reject_reason', 'a4_action_done_on','a4_action_done_by','is_a4_mail_send',
         'parallel_process_from',
         'is_active',
         'created_on', 'created_by'