From 36d686f7a4644306c6f5f6ff86ac18299984a22b Mon Sep 17 00:00:00 2001 From: "venkatesh.r" Date: Mon, 2 Feb 2026 17:58:56 +0530 Subject: [PATCH 01/23] FIX_MD5 --- app/Controllers/EmployeeRestController.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php index e60cc86a..22b1b263 100755 --- a/app/Controllers/EmployeeRestController.php +++ b/app/Controllers/EmployeeRestController.php @@ -3625,6 +3625,12 @@ class EmployeeRestController extends AdminController $get_docs_name = $this->request->getPost('claim_doc_names') ?? []; $policy_transaction_id = $this->request->getPost('policy_transaction_id') ?? null; + + if (is_string($received_data['client_id']) && preg_match('/^[a-f0-9]{32}$/i', $received_data['client_id'])) { + $client_data = $this->clientModel->where('MD5(id)', $received_data['client_id'])->first(); + $received_data['client_id'] = $client_data['id'] ?? null; + } + $client_policy_data = $this->clientPolicyModel->where('id', $received_data['client_policy_id'] ?? null)->first(); $isduplicate = checkDuplicateClaim([ From e70245ff7791a919db91032539b9b312a0e81fb1 Mon Sep 17 00:00:00 2001 From: "venkatesh.r" Date: Mon, 2 Feb 2026 20:27:07 +0530 Subject: [PATCH 02/23] FEAT_CREATE_PT_AND_PCSD_ENTRY_WHILE_CLIENT_POLICY_CREATE --- app/Config/Routes.php | 6 +- app/Controllers/ClientController.php | 63 ++++++++----------- app/Controllers/EmployeeRestController.php | 2 +- .../policy_transaction_inception_list.php | 2 +- 4 files changed, 32 insertions(+), 41 deletions(-) diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 1bc86af6..f830a3a3 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -37,7 +37,6 @@ $routes->get("view", "EmployeeController::viewECard/$1"); $routes->get("checkWellnessOnboardStatus/(:any)", "EmployeeController::checkWellnessOnboardStatus/$1"); $routes->get("initiateWellnessOnboard/(:any)", "EmployeeController::initiateWellnessOnboard/$1"); $routes->get("exportQCRandRFQ/(:any)", "LeadsController::exportQCRandRFQ/$1"); -$routes->get("smapletest", "ClientController::smapletest"); $routes->get("testMailAttachments", "ClientController::testMailAttachments"); $routes->get("updatePolicyTermsKey", "ClientController::updatePolicyTermsKey"); $routes->get("updateRemainderDate", "ClientController::updateRemainderDate"); @@ -560,6 +559,8 @@ $routes->group("/api", ["filter" => "authJWT"], function ($routes) { $routes->get("getSSORedirectUrl", "ApiServiceController::getSSORedirectUrl"); $routes->get("getEmployeePolicy", "EmployeeRestController::getEmployeePolicy"); +$routes->get("downloadCdSplitUpFile", "EmployeeRestController::downloadCdSplitUpFile"); + $routes->group("employeeRest", ['filter' => ['appSignature'] ], function ($routes) { @@ -604,7 +605,7 @@ $routes->group("employeeRest", ['filter' => ['appSignature'] ], function ($route }); - $routes->group("employeeRest", ["filter" => ['GlobalPostFileUploadGuard', 'appSignature', 'authJWT']], function ($routes) { +$routes->group("employeeRest", ["filter" => ['GlobalPostFileUploadGuard', 'appSignature', 'authJWT']], function ($routes) { $routes->post('logout', 'RestAuthenticationController::logout'); @@ -686,7 +687,6 @@ $routes->group("employeeRest", ['filter' => ['appSignature'] ], function ($route // get insurer and policy type $routes->get("getPolicyTypeAndInsurer", "EmployeeRestController::getPolicyTypeAndInsurer"); - $routes->get("downloadCdSplitUpFile", "EmployeeRestController::downloadCdSplitUpFile"); $routes->get("getExcelFileErrors/(:any)", "EmployeeController::getExcelFileErrors/$1"); }); diff --git a/app/Controllers/ClientController.php b/app/Controllers/ClientController.php index 8ba51997..70f9ee8b 100755 --- a/app/Controllers/ClientController.php +++ b/app/Controllers/ClientController.php @@ -141,6 +141,7 @@ class ClientController extends AdminController $isDuplicate = $this->clientModel->isDuplicateByClientBranch($value, $field, $clientId, $branchId); return $this->response->setJSON(['isDuplicate' => $isDuplicate]); } + public function checkDuplicateTableFieldValue() { $table = $this->request->getPost('table'); @@ -162,35 +163,6 @@ class ClientController extends AdminController return $this->response->setJSON(['isDuplicate' => $isDuplicate]); } - public function smapletest() - { - $headers = [ - 'S.No', - 'NAME OF EMP/DEP', - 'EMP ID', - // 'EMP/DEP TYPE', - // 'RELATIONSHIP CODE', - 'DOB', - 'GENDER', - 'PRE EXISTING AILMENTS', - 'BASIC COVER SI', - 'DATE OF COVERAGE', - 'AGE', - 'RELATIONSHIP', - 'REMARKS', - 'POLICY END DATE', - 'NO OF DAYS', - 'TPA ID', - 'UHID', - // 'PREMIUM', - 'PRO RATA PREMIUM', - 'GST', - 'TOTAL AMOUNT' - ]; - $filePath = generateExcelWithHeader($headers); - echo "Excel file created at: $filePath"; - } - public function testMailAttachments($email = 'venkateshraman786@gmail.com') { $message = ''; @@ -510,7 +482,6 @@ class ClientController extends AdminController // $this->loadLayout('client_onboarding', $data); } - public function typeList($id = null) { try { @@ -547,7 +518,6 @@ class ClientController extends AdminController } } - public function updateEmpAndPolicyStatus() { $return = $this->clientPolicyModel->updateStatus(); @@ -2088,6 +2058,7 @@ class ClientController extends AdminController $sanitized_post_data['enrolment_visibility'] = $sanitized_post_data['enrolment_visibility'] ?? null ? 1 : 0; $sanitized_post_data['is_lgbtq'] = $sanitized_post_data['is_lgbtq'] ?? null ? 1 : 0; $sanitized_post_data['wellness_vendor_id'] = !empty($sanitized_post_data['wellness_vendor_id']) ? $sanitized_post_data['wellness_vendor_id'] : null; + $sanitized_post_data['cd_ac_pk'] = $sanitized_post_data['cd_ac_no'] ?? null; if ($policy_type_id == 1 || $policy_type_id == 2 || $policy_type_id == 6 || $policy_type_id == 7) { @@ -2126,6 +2097,8 @@ class ClientController extends AdminController $insert = $this->clientPolicyModel->insert($sanitized_post_data); if ($insert) { + // this function to create a policy transaction entry at the time of client policy create + $this->createPolicyTransactionInceptionEntry($insert, $sanitized_post_data); $clientPoliceData = $this->clientPolicyModel->getClientPolicyByClientId($sanitized_post_data['client_id']); $clientPoliceData['role'] = get_role_id(); return $this->respond(['status' => true, 'code' => 200, 'data' => $clientPoliceData, 'client_id' => $client_id, 'method' => 'CERATE', 'post_data' => $insert], 200); @@ -2310,6 +2283,28 @@ class ClientController extends AdminController } } + public function createPolicyTransactionInceptionEntry($client_policy_id, $data) + { + $data['action_type'] = 'inception'; + $data['client_policy_id'] = $client_policy_id; + $data['entry_from'] = 3; + $data['issuer_branch'] = 1; + $data['issuer'] = 2; + $data['status'] = 'completed'; + $data['renewal_date'] = $data['policy_end_date']; + $insert = $this->policyTransactionModel->insert($data); + + if($insert){ + + $pcsd_data['pt_id'] = $insert; + $pcsd_data['insurer_id'] = $data['insurer_id'] ?? null; + $pcsd_data['insurer_branch_id'] = $data['insurer_branch_id'] ?? null; + + $this->PTCOShareDetailsModel->insert($pcsd_data); + } + return $insert; + } + // Save Rack Rate function @@ -2843,7 +2838,6 @@ class ClientController extends AdminController } } - private function updatePTCoShareTableEntry($policy_transaction_data, $old_client_policy_data, $data) { $updated_ids = []; @@ -2889,9 +2883,6 @@ class ClientController extends AdminController ]; } - - - public function uploadVehicleFile($params = null) { $this->myLogger->logme('error', 'uploadVehicleFile function called'); @@ -6463,7 +6454,7 @@ class ClientController extends AdminController // $res = $EmpDataServiceController->importInceptionUpdateTPAandUHID(['file_id' => 310]); dd($res);//for live // $res = $EmpDataServiceController->getInceptionBasePremium(["13332","13333","13334","13335","13336"]); dd($res);//for live // $res = $EmpDataServiceController->getDeletionBasePremium(["13248","13250","13249","13247"], json_decode('{"employeeIds":["13248","13250","13249","13247"],"client_id":"3927","client_policy_id":"6183","client_branch_id":"1874","cd_ac_no":"CD9751909505","endorsement_no":"END1238","count":4,"event_name":"deletion","policy_name":"GMC","user_id":"48"}', true)); dd($res);//for live - // $res = $EmpDataServiceController->makeEntryForBDSPolicyTransaction(json_decode('{"client_policy_id":"6187","endorsement_no":null,"emp_count":5,"action_type":"inception","no_of_insured":3,"no_of_dependent":0}', true)); dd($res);//for live + // $res = $EmpDataServiceController->makeEntryForBDSPolicyTransaction(json_decode('{"client_policy_id":"6187","endorsement_no":"000000001","emp_count":5,"action_type":"addition","no_of_insured":3,"no_of_dependent":0, "base_premium" : "1000", "gst" : "180", "policy_issue_date" : "2025-12-31"}', true)); dd($res);//for live // $res = $EmpDataServiceController->sendMailForDownloadingECard(['ids' => $ids, 'client_policy_id' => $client_policy_id]); // $res = $this->employeePolicyModel->getDeletionEmployeeDataForExportExcel($batch_data, 1); dd($result); // $res = $this->employeePolicyModel->getSIEnhancementEmployeesDataForExportExcel($batch_data, 1); diff --git a/app/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php index 22b1b263..59c5224e 100755 --- a/app/Controllers/EmployeeRestController.php +++ b/app/Controllers/EmployeeRestController.php @@ -4854,7 +4854,7 @@ class EmployeeRestController extends AdminController THEN hr_file_upload.status ELSE CONCAT(UCASE(LEFT(f.status, 1)), LCASE(SUBSTRING(f.status, 2))) END AS status, - '1' as file_error_status + '0' as file_error_status ", false) ->join('clients c', 'c.id = hr_file_upload.client_id AND c.is_active = 1', 'left') ->join('client_branch cb', 'cb.id = hr_file_upload.client_branch_id AND cb.is_active = 1', 'left') diff --git a/app/Views/policy_transaction_inception_list.php b/app/Views/policy_transaction_inception_list.php index 37166f8a..cc850c55 100644 --- a/app/Views/policy_transaction_inception_list.php +++ b/app/Views/policy_transaction_inception_list.php @@ -316,7 +316,7 @@ table.dataTable tbody td { $row){ ?> - + From 8f8b082f8cb78091ede0da8b38480a59a6c07197 Mon Sep 17 00:00:00 2001 From: "venkatesh.r" Date: Mon, 2 Feb 2026 21:47:41 +0530 Subject: [PATCH 03/23] FEAT_HR_NOTIFICATION --- app/Controllers/ClientController.php | 23 ++- app/Controllers/EmpDataServiceController.php | 52 +++--- app/Controllers/EmployeeController.php | 49 +++-- app/Controllers/NotificationController.php | 3 +- app/Views/notification.php | 178 ++++++++++++++++++- 5 files changed, 261 insertions(+), 44 deletions(-) diff --git a/app/Controllers/ClientController.php b/app/Controllers/ClientController.php index 70f9ee8b..9cf2030c 100755 --- a/app/Controllers/ClientController.php +++ b/app/Controllers/ClientController.php @@ -648,7 +648,7 @@ class ClientController extends AdminController // echo "
";
         // print_r($data); die;
-        $data['placeHolders'] = ['member_name', 'nhance_logo', 'tpa_id', 'ecard_download_link', 'client_logo', 'policy_no', 'member_summary', 'app_link', 'post_enrollment_app_link', 'client_name'];
+        $data['placeHolders'] = ['hr_name', 'member_name', 'nhance_logo', 'tpa_id', 'ecard_download_link', 'client_logo', 'policy_no', 'member_summary', 'app_link', 'post_enrollment_app_link', 'client_name'];
 
         // dd($data['placeHolders']);
 
@@ -952,7 +952,7 @@ class ClientController extends AdminController
                 }, $rawList)) : [];
         $editData['client_policy']['role'] = get_role_id();
         $editData['notification'] = $this->notificationModel->select('template_name,enabled')->where('client_id', $id)->findAll();
-        $editData['placeHolders'] = ['member_name', 'member_mobile', 'nhance_logo', 'tpa_id', 'ecard_download_link', 'client_logo', 'policy_no', 'member_summary', 'app_link', 'post_enrollment_app_link', 'client_name'];
+        $editData['placeHolders'] = ['hr_name', 'member_name', 'member_mobile', 'nhance_logo', 'tpa_id', 'ecard_download_link', 'client_logo', 'policy_no', 'member_summary', 'app_link', 'post_enrollment_app_link', 'client_name'];
         $editData['api_data'] = $this->clientApi->where("client_id", $id)->where("is_active", 1)->first();
         // dd($editData);
 
@@ -8728,6 +8728,8 @@ class ClientController extends AdminController
         $member_ecard_mail_template              = $this->notificationModel->where('client_id', NULL)->where('template_name', 'member_ecard_mail')->get()->getResultArray()[0] ?? [];
 
         $member_common_mail_template             = $this->notificationModel->where('client_id', NULL)->where('template_name', 'member_common_mail')->get()->getResultArray()[0] ?? [];
+        
+        $hr_cd_insufficient_balance_mail_template  = $this->notificationModel->where('client_id', NULL)->where('template_name', 'hr_cd_insufficient_balance_mail')->get()->getResultArray()[0] ?? [];
 
         $default_member_welcome_mail_template = [
             'client_id'        => $client_id,
@@ -8799,6 +8801,20 @@ class ClientController extends AdminController
             'mail_content_copy' => null
         ];
 
+        $hr_cd_insufficient_balance_mail_template = [
+            'client_id'        => $client_id,
+            'template_name'    => 'hr_cd_insufficient_balance_mail',
+            'subject'          => $hr_cd_insufficient_balance_mail_template['subject'] ?? '',
+            'mail_content'     => $hr_cd_insufficient_balance_mail_template['mail_content'] ?? '',
+            'mail_content_json' => $hr_cd_insufficient_balance_mail_template['mail_content_json'] ?? '',
+
+            'created_by'       => get_session_userid(),
+            'created_at'       => date('Y-m-d H:i:s'),
+            'updated_by'       => null,
+            'updated_at'       => date('Y-m-d H:i:s'),
+            'mail_content_copy' => null
+        ];
+
         $this->myLogger->logme('error', 'Default Mail Template Data ' . json_encode([
             $default_member_welcome_mail_template,
             $default_member_remainder_mail_template,
@@ -8812,7 +8828,8 @@ class ClientController extends AdminController
             $default_member_remainder_mail_template,
             $default_member_review_and_summary_mail_template,
             $default_member_ecard_mail_template,
-            $default_member_common_mail_template
+            $default_member_common_mail_template,
+            $hr_cd_insufficient_balance_mail_template,
         ]);
 
 
diff --git a/app/Controllers/EmpDataServiceController.php b/app/Controllers/EmpDataServiceController.php
index f6cfb67a..cff84df8 100755
--- a/app/Controllers/EmpDataServiceController.php
+++ b/app/Controllers/EmpDataServiceController.php
@@ -734,17 +734,23 @@ class EmpDataServiceController extends BaseController
         if($export_data['insurer_or_tpa'] == 'insurer')
         {
             if (!empty($cash_balance)) {
-                if ((int) $cash_balance['balance']  < (int) $rounded_totals) {
-                    $this->myLogger->logme('error', 'Inception export failed due to insufficient deposit amount.');
-                    $this->myLogger->logme('error', 'Inception export failed due to insufficient deposit amount.  CASH BALANCE : {balance}  and  TOTAL AMOUNT : {total}', ['balance' => $cash_balance['balance'], 'total' => $totals]);
-                    session()->set('cd_balance', false);
-                    session()->set('cd_amount', $cash_balance['balance']);
-                    session()->set('excel_file_amt', $rounded_totals);
+                if ((int) $cash_balance['balance'] < (int) $totals) {
+                    clear_cd_balance_session(); // Clear old junk first
+                    
+                    $cd_session_data = json_encode([
+                        'cd_balance' => false, 
+                        'cd_amount' => $cash_balance['balance'], 
+                        'excel_file_amt' => $totals
+                    ]);
+                    
+                    session()->set('cd_balance_info', $cd_session_data);
+                    session()->set('cd_balance', 'insufficient'); // Use a string status for clarity
+                    
+                    $hr_data = $this->getHrdataForInsufficientMailSend($export_data['client_branch_id']);
+                    session()->set('hr_data', json_encode(['client_id' => $export_data['client_id'], 'hr_data' => $hr_data]));
                 }else{
-                    session()->set('cd_balance', true);
-                    session()->set('cd_amount', $cash_balance['balance']);
-                    session()->set('excel_file_amt', $rounded_totals);
-
+                    session()->set('cd_balance', 'sufficient'); // Use a string status for clarity
+                    session()->set('cd_balance_info', null);
                 }
             }
         }
@@ -1065,17 +1071,23 @@ class EmpDataServiceController extends BaseController
             if($export_data['insurer_or_tpa'] != 'tpa')// check overal emp premium amt with cd balance only for insurer export, not tpa export
             { 
                 if (!empty($cash_balance)) {
-                    if ((int) $cash_balance['balance']  < (int) $totals) {
-                        $this->myLogger->logme('error', 'Inception export failed due to insufficient deposit amount.');
-                        $this->myLogger->logme('error', 'Inception export failed due to insufficient deposit amount.  CASH BALANCE : {balance}  and  TOTAL AMOUNT : {total}', ['balance' => $cash_balance['balance'], 'total' => $totals]);
-                        session()->set('cd_balance', false);
-                        session()->set('cd_amount', $cash_balance['balance']);
-                        session()->set('excel_file_amt', $totals);
+                    if ((int) $cash_balance['balance'] < (int) $totals) {
+                        clear_cd_balance_session(); // Clear old junk first
+                        
+                        $cd_session_data = json_encode([
+                            'cd_balance' => false, 
+                            'cd_amount' => $cash_balance['balance'], 
+                            'excel_file_amt' => $totals
+                        ]);
+                        
+                        session()->set('cd_balance_info', $cd_session_data);
+                        session()->set('cd_balance', 'insufficient'); // Use a string status for clarity
+                        
+                        $hr_data = $this->getHrdataForInsufficientMailSend($export_data['client_branch_id']);
+                        session()->set('hr_data', json_encode(['client_id' => $export_data['client_id'], 'hr_data' => $hr_data]));
                     }else{
-                        session()->set('cd_balance', true);
-                        session()->set('cd_amount', $cash_balance['balance']);
-                        session()->set('excel_file_amt', $totals);
-
+                        session()->set('cd_balance', 'sufficient'); // Use a string status for clarity
+                        session()->set('cd_balance_info', null);
                     }
                 }
             }
diff --git a/app/Controllers/EmployeeController.php b/app/Controllers/EmployeeController.php
index db0468ae..d3cd3d25 100755
--- a/app/Controllers/EmployeeController.php
+++ b/app/Controllers/EmployeeController.php
@@ -31,6 +31,7 @@ use App\Models\UserModel;
 use App\Models\PartnerEndorsementRequestModel;
 use App\Models\TpaApiDataModel;
 use App\Models\LevelContactModel;
+use App\Models\NotificationModel;
 
 
 use App\Controllers\Jobs;
@@ -4555,29 +4556,39 @@ class EmployeeController extends AdminController
 
         $client_data = $this->clientModel->where('is_active', 1)->where('id', $post_data['client_id'])->first();
 
-        $common['mail_type'] = "insufficient_cd_balance_by_hr";
+        if(empty($client_data)){
+            return $this->respond(['status' => false, 'code' => 404, 'message' => 'No client found'], 200);
+        }
+
+        $notificationModal = new NotificationModel();
+        $notification_data = $notificationModal
+                ->where('client_id', $post_data['client_id'])
+                ->where('template_name', 'hr_cd_insufficient_balance_mail')
+                ->where('is_active', 1)
+                ->first();
+
+        if(empty($notification_data)){
+            return $this->respond(['status' => false, 'code' => 404, 'message' => 'No template found'], 200);
+        }
+
+        if(empty($notification_data['subject']) || empty($notification_data['mail_content'])){
+            return $this->respond(['status' => false, 'code' => 404, 'message' => 'Template subject or mail content is empty'], 200);
+        }
+    
+        if(empty($notification_data['enabled']) || $notification_data['enabled'] != 1){
+            return $this->respond(['status' => false, 'code' => 404, 'message' => 'Template is disabled'], 200);
+
+        }
+
+        $common['mail_type'] = "hr_cd_insufficient_balance_mail";
         $common['client_id'] = $post_data['client_id'];
-        $subject = 'Insufficient CD Balance Notification';
-        $mail_content = '
-            Dear {{HR_NAME}},
-
-            Greetings from Nhance.
-
-            We would like to inform you that the CD balance for {{CLIENT_NAME}} is currently low / insufficient, which may impact further processing of insurance-related activities.
-
-            Kindly request you to credit the required amount at the earliest to avoid any service disruption.
-
-            Please let us know once the amount is credited, or if you need any clarification from our end.
-
-            Thank you for your support and cooperation.
-        ';
-
+        $subject = $notification_data['subject'];
+        $mail_content = $notification_data['mail_content'];
 
         foreach ($post_data['mails'] as $hr_id => $hr_data) {
 
-            $mail_content = str_ireplace('{{HR_NAME}}', $hr_data['name'], $mail_content);
-            $mail_content = str_ireplace('{{CLIENT_NAME}}', $client_data['client_name'], $mail_content);
-
+            $mail_content = str_ireplace('{{hr_name}}', $hr_data['name'], $mail_content);
+            $mail_content = str_ireplace('{{client_name}}', $client_data['client_name'], $mail_content);
             $res = MailHelper::send_email(['mail' => $hr_data['mail'], 'subject' => $subject, 'message' => $mail_content, 'common' => $common]);
         }
 
diff --git a/app/Controllers/NotificationController.php b/app/Controllers/NotificationController.php
index b0e5b4cf..8014f0c5 100755
--- a/app/Controllers/NotificationController.php
+++ b/app/Controllers/NotificationController.php
@@ -94,7 +94,8 @@ class NotificationController extends AdminController
             'member_ecard_mail_btn',
             'member_review_and_summary_mail_btn',
             'account_maneger_summary_mail_btn',
-            'client_hr_summary_mail_btn'
+            'client_hr_summary_mail_btn',
+            'hr_cd_insufficient_balance_mail_btn',
         ];
         $data = [];
         $emptyTemplate = [];
diff --git a/app/Views/notification.php b/app/Views/notification.php
index 93e8213e..7948a3a4 100755
--- a/app/Views/notification.php
+++ b/app/Views/notification.php
@@ -131,6 +131,8 @@
                 $member_review_and_summary_mail = 0;
                 $account_maneger_summary_mail = 0;
                 $client_hr_summary_mail = 0;
+                $hr_cd_insufficient_balance_mail = 0;
+
                 if (isset($notification)) {
                     foreach ($notification as $value) {
 
@@ -161,6 +163,10 @@
                         if ($value['template_name'] == 'client_hr_summary_mail') {
                             $client_hr_summary_mail = $value['enabled'];
                         }
+
+                        if ($value['template_name'] == 'hr_cd_insufficient_balance_mail') {
+                            $hr_cd_insufficient_balance_mail = $value['enabled'];
+                        }
                     }
                 }
                 ?>

@@ -265,6 +271,7 @@ +
@@ -283,6 +290,26 @@
+
+ + +
+
+
+ + HR CD Insufficient Balance Mail +
+
+ + + +
+
+ +
@@ -988,6 +1015,89 @@ + + +