diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 34478d0c..e94c6ad4 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -20,7 +20,7 @@ $routes->get("updatajson", "EmpDataServiceController::updatajson"); $routes->get("view", "EmployeeController::viewECard/$1"); // $routes->get("exportQCRandRFQ", "LeadsController::exportQCRandRFQ"); $routes->get("smapletest", "ClientController::smapletest"); - +$routes->get("testMailAttachments", "ClientController::testMailAttachments"); $routes->post("add_advertise_image", "AppContentManagementController::add_advertise_image"); $routes->get("add_image_index", "AppContentManagementController::add_image_index"); @@ -74,7 +74,9 @@ $routes->group("/client", ["filter" => "authMVC"], function ($routes) { $routes->group("notification", ["filter" => "authMVC"], function ($routes) { $routes->post("create", "NotificationController::createNotification"); $routes->post("update_enable", "NotificationController::update_enable"); + $routes->post("add_attachment", "NotificationController::insertAttachmentsForMailTemplates"); $routes->get("getMailTemplateData/(:any)/(:any)", "NotificationController::getMailTemplateData/$1/$2"); + $routes->get("removeAttachment/(:any)", "NotificationController::removeAttachmentsForMailTemplates/$1"); }); $routes->group("general", ["filter" => "authMVC"], function ($routes) { @@ -302,6 +304,11 @@ $routes->group("/util", ["filter" => "authMVC"], function ($routes) { $routes->get("get_client_policy_list_for_remainder/(:any)", "EmployeeController::get_client_policy_list_for_remainder/$1"); $routes->get("get_client_branch_data/(:any)", "ClientController::get_client_branch_data/$1"); $routes->get("getLevelContects", "LeadsController::getLevelContects"); + $routes->get("get_emp_master_data_for_update/(:any)", "EmployeeController::get_emp_master_data_for_update/$1"); + $routes->get("send_mail_for_individual_employee_ecard/(:any)", "EmployeeController::send_mail_for_individual_employee_ecard/$1"); + $routes->post("update_emp_data", "EmployeeController::update_emp_data"); + $routes->get("checkDeletionGetDataFunction", "EmployeeController::checkDeletionGetDataFunction"); + }); $routes->group("policy_tranction", ["filter" => "authMVC"], function ($routes) { diff --git a/app/Controllers/ClientController.php b/app/Controllers/ClientController.php index 41291548..b937e835 100755 --- a/app/Controllers/ClientController.php +++ b/app/Controllers/ClientController.php @@ -118,11 +118,28 @@ class ClientController extends AdminController $this->leadsModel = new LeadsModel(); } - public function smapletest(){ - + public function smapletest() + { $headers = ['S.No','EMP ID','EMP NAME','DOB','GENDER','RELATIONSHIP','SUM INSURED','Date of Leaving','Policy End Date','No Of Days','Premium','Pro Rata Premium','GST','Total','Claim Status','ENDORSEMENT_ID']; $filePath = generateExcelWithHeader($headers); - echo "Excel file created at: $filePath"; + echo "Excel file created at: $filePath"; + } + + public function testMailAttachments($email = 'venkateshraman786@gmail.com') + { + $message = '

Request for Quotation (RFQ)

Dear {{RECIPIENT_NAME}},

We are reaching out to request a quotation for the following insurance coverage. Please review the details below and provide your quote at your earliest convenience.

RFQ Details

Client name{{CLIENT_NAME}}
Coverage Type{{POLICY_LONG_NAME}}
Policy Start Date{{POLICY_START_DATE}}
Policy Duration{{DURATION}}
Please note: Additional terms and details are included in the attachment for your reference.

Please feel free to reach out if you require any further information to prepare the quote. We look forward to receiving your proposal.

Best regards,

Nhance India Pvt Ltd

'; + + $attachments = [ + ["filePath" => ROOTPATH."public/sample_excel/sample_addition.xls","fileName" => "sample_addition.xls"], + ["filePath" => ROOTPATH."public/sample_excel/sample_inception.xls","fileName" => "sample_inception.xls"], + ["filePath" => ROOTPATH."public/assets/images/login_bg.jpg","fileName" => "login_bg.jpg"] + ]; + + $res = MailHelper::send_email(['mail' => $email, 'subject' => 'Mail Via Attachment Testing URL', 'message' => $message,'attachments' => $attachments]); + + print_rr($res); + echo '------------------------------------------------------------------------------------------'; + print_rr($attachments); } public function testingForReviewMail($client_id = 77, $emp_code = 'MGL-004', $mail_active = 0) //this function for only tsesting some logics not use for business logic diff --git a/app/Controllers/EmpDataServiceController.php b/app/Controllers/EmpDataServiceController.php index 04cdc654..ff8e0413 100755 --- a/app/Controllers/EmpDataServiceController.php +++ b/app/Controllers/EmpDataServiceController.php @@ -640,11 +640,14 @@ class EmpDataServiceController extends BaseController // echo '
';
         // print_r($ids); die;
 
-        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]);
-                return 0;
+        if($export_data['insurer_or_tpa'] == 'insurer') //check CD amt related issue for only insurer, not tpa
+        {
+            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]);
+                    return 0;
+                }
             }
         }
 
@@ -708,7 +711,6 @@ class EmpDataServiceController extends BaseController
             
         }
 
-
         $excel_data_info = generate_insurer_based_excel($excel_header_columns, $objects);
 
         // Generate Excel file
@@ -1667,6 +1669,7 @@ class EmpDataServiceController extends BaseController
 
         $file_id = $params['file_id'];
         $file = $this->batchFileModel->find($file_id);
+
         if (!$file) {
 
             $data = [
@@ -1697,7 +1700,6 @@ class EmpDataServiceController extends BaseController
                     ->where('insurer_id', $insurer_id['insurer_id'])
                     ->first();
 
-
         $get_policy_type = $this->clientPolicyModel
             ->select('policy_type.policy_type, policies.policy_type_id as policy_type_id')
             ->join('policies', 'policies.id = client_policy.policy_id')
@@ -1780,12 +1782,11 @@ class EmpDataServiceController extends BaseController
             'amount' => $totals,
         ]);
 
-
         $this->myLogger->logme('error', 'Inception Update TPA and UHID --    employee count : {data}', ['data' => $emp_count]);
         $this->myLogger->logme('error', 'Inception Update TPA and UHID --    batch file status : {data}', ['data' => $status_val]);
         $this->myLogger->logme('error', 'Inception Update TPA and UHID --    total amount for cash deposite : {data}', ['data' => $totals]);
 
-
+        //update CD transaction entry if only insurer
         if ($file['insurer_or_tpa'] == 'insurer') {
 
             $this->myLogger->logme('error', 'Inception Update TPA and UHID --    set  cashDepositCalculationForInception and sendMailForDownloadingECard in JOB QUEUE');
@@ -1817,15 +1818,20 @@ class EmpDataServiceController extends BaseController
                 'user_id' => $user_id,
             ]]);
 
+            // $this->cashDepositCalculationForInception($depositeData);
+            // $this->sendMailForDownloadingECard($emp_policy_ids);
+
+        }
+
+        //send ecard mail if the event is tpa only
+        if ($file['insurer_or_tpa'] == 'tpa') {
+
             if ($get_policy_type['policy_type_id'] != 1) {
 
                 $job_details  = new Jobs();
                 $r = Jobs::addJob(['job_name' => 'sendMailForDownloadingECard', 'payload' => $emp_policy_ids]);
             }
 
-            // $this->cashDepositCalculationForInception($depositeData);
-            // $this->sendMailForDownloadingECard($emp_policy_ids);
-
         }
 
         $file_data = $this->getDataByFileId($file_id, 'success');
@@ -2854,27 +2860,29 @@ class EmpDataServiceController extends BaseController
         $this->myLogger->logme('error', 'SI Enhancement Update Endorsement ID --      Employee count : {data}', ['data' => $emp_count]);
         $this->myLogger->logme('error', 'SI Enhancement Update Endorsement ID --      Batch File status : {data}', ['data' => $status_val]);
 
+        //call the cash deposite function
+        if ($file['insurer_or_tpa'] == 'insurer') {
+
+            $policy_name = $this->getPolicyNameUsingClientPolicyId($client_policy_id);
+            $job_details  = new Jobs();                             
+            $r = Jobs::addJob(['job_name' => 'cashDepositCalculationForSIEnhancement','payload' => [
+                'employeeIds' => $insertedIds,
+                'client_id' => $client_id,
+                'client_policy_id' => $client_policy_id,
+                'client_branch_id' => $client_branch_id,
+                'cd_ac_no' => $CD_Account_Number['cd_ac_no'] ?? null,
+                'endorsement_no' => $endorsement_id ?? null,
+                'count' => $emp_count,
+                'event_name' => $file['event_type'],
+                'policy_name' => $policy_name['policy_name'],
+                'user_id' => $user_id,
+            ]]);
+
+        }
 
         $file_data = $this->getDataByFileId($file_id, 'success');
         $this->setPullNotification($file_data);
 
-        //call the cash deposite function
-
-        $policy_name = $this->getPolicyNameUsingClientPolicyId($client_policy_id);
-        $job_details  = new Jobs();                             
-        $r = Jobs::addJob(['job_name' => 'cashDepositCalculationForSIEnhancement','payload' => [
-            'employeeIds' => $insertedIds,
-            'client_id' => $client_id,
-            'client_policy_id' => $client_policy_id,
-            'client_branch_id' => $client_branch_id,
-            'cd_ac_no' => $CD_Account_Number['cd_ac_no'] ?? null,
-            'endorsement_no' => $endorsement_id ?? null,
-            'count' => $emp_count,
-            'event_name' => $file['event_type'],
-            'policy_name' => $policy_name['policy_name'],
-            'user_id' => $user_id,
-        ]]);
-
         //import file to upload Google Drive
         // if(excelFileGDriveUpload($file_id, 'batch_file')){
         //     $this->myLogger->logme('error', 'SI Enhancement File Update Google Drive File Upload --    File Uploaded Successfully');
@@ -3381,28 +3389,27 @@ class EmpDataServiceController extends BaseController
         $this->myLogger->logme('error', 'Deletion Update Endorsement ID --      Employee count : {data}', ['data' => $emp_count]);
         $this->myLogger->logme('error', 'Deletion Update Endorsement ID --      Batch File status : {data}', ['data' => $status_val]);
 
+        //call the cash deposite function
+        if ($file['insurer_or_tpa'] == 'insurer') {
+            $policy_name = $this->getPolicyNameUsingClientPolicyId($client_policy_id);
+            $job_details  = new Jobs();
+            $r = Jobs::addJob(['job_name' => 'cashDepositCalculationForDeletion', 'payload' => [
+                'employeeIds' => $employee_policy_table_primaryKey,
+                'client_id' => $client_id,
+                'client_policy_id' => $client_policy_id,
+                'client_branch_id' => $client_branch_id,
+                'cd_ac_no' => $CD_Account_Number['cd_ac_no'] ?? null,
+                'endorsement_no' => $endorsement_id ?? null,
+                'count' => $emp_count,
+                'event_name' => $file['event_type'],
+                'policy_name' => $policy_name['policy_name'],
+                'user_id' => $user_id,
+            ]]);
+        }
 
         $file_data = $this->getDataByFileId($file_id, 'success');
         $this->setPullNotification($file_data);
 
-        //call the cash deposite function
-
-        $policy_name = $this->getPolicyNameUsingClientPolicyId($client_policy_id);
-
-        $job_details  = new Jobs();
-        $r = Jobs::addJob(['job_name' => 'cashDepositCalculationForDeletion', 'payload' => [
-            'employeeIds' => $employee_policy_table_primaryKey,
-            'client_id' => $client_id,
-            'client_policy_id' => $client_policy_id,
-            'client_branch_id' => $client_branch_id,
-            'cd_ac_no' => $CD_Account_Number['cd_ac_no'] ?? null,
-            'endorsement_no' => $endorsement_id ?? null,
-            'count' => $emp_count,
-            'event_name' => $file['event_type'],
-            'policy_name' => $policy_name['policy_name'],
-            'user_id' => $user_id,
-        ]]);
-
         //import file to upload Google Drive
         // if(excelFileGDriveUpload($file_id, 'batch_file')){
         //     $this->myLogger->logme('error', 'Deletion File Update Google Drive File Upload --    File Uploaded Successfully');
@@ -4224,7 +4231,7 @@ class EmpDataServiceController extends BaseController
         return true;
     }
 
-    public function sendMailForDownloadingECard(array $ids)
+    public function sendMailForDownloadingECard(array $ids, $single_mail = null)
     {
         
         $this->myLogger->logme('error', 'sendMailForDownloadingECard - function called');
@@ -4269,7 +4276,6 @@ class EmpDataServiceController extends BaseController
 
                             $this->myLogger->logme('error', 'sendMailForDownloadingECard - Send Bulk Mail function inside if condition ',);
 
-
                             $rand_string =  $get_emp_email_and_other_details['rand_string'];
                             $tpa_id =  $get_emp_email_and_other_details['tpa_id'];
 
@@ -4284,14 +4290,21 @@ class EmpDataServiceController extends BaseController
 
                             if (isset($get_emp_email_and_other_details['email_corporate']) && !empty($get_emp_email_and_other_details['email_corporate']) && $get_emp_email_and_other_details['relationship'] == 'Self') {
                                 $wholeData[] = sendMailNotification::sendMailNotification('member_ecard_mail', $params);
-
                                 // print_r($wholeData);die;
                                 $count++;
                             }
 
                             $counts++;
-                            
+
+                            $this->myLogger->logme('error', 'sendMailForDownloadingECard - counts : {data}', ['data' => $counts]);
+                            $this->myLogger->logme('error', 'sendMailForDownloadingECard - count : {data}', ['data' => $count]);
+                            $this->myLogger->logme('error', 'sendMailForDownloadingECard - ids count : {data}', ['data' => count($ids)]);
+                            $this->myLogger->logme('error', 'sendMailForDownloadingECard - whole count : {data}', ['data' => count($wholeData)]);
+
                             if ($count == 20 || $counts == count($ids) - 1) {
+
+                                $this->myLogger->logme('error', 'sendMailForDownloadingECard - ids count : {data}', ['data' => count($ids)]);
+
                                 if(count($wholeData) > 0){
 
                                     $this->myLogger->logme('error', 'sendMailForDownloadingECard - create a job to bulk mail',);
@@ -4302,6 +4315,27 @@ class EmpDataServiceController extends BaseController
                                     $count = 0;
 
                                 }
+                            }else{
+
+                                // for view member individual employee send self and self family ecard 
+                                if($single_mail){
+
+                                    if(count($wholeData) > 0){
+
+                                        $this->myLogger->logme('error', 'sendMailForDownloadingECard - create a job for single mail to bulk mail function',);
+    
+                                        $mail_send_return =  MailHelper::send_email($wholeData[0]);
+                                        $this->myLogger->logme("info", $mail_send_return);
+                                        return $mail_send_return;
+
+                                        // $job_details  = new Jobs();
+                                        // $r = Jobs::addJob(['job_name' => 'bulk_mail', 'payload' => $wholeData]);
+                                        // $wholeData = [];
+                                        // $count = 0;
+    
+                                    }
+
+                                }
 
                             }
 
@@ -4322,6 +4356,7 @@ class EmpDataServiceController extends BaseController
                 $this->myLogger->logme('error', 'sendMailForDownloadingECard - the client notification setup not created or not enabled the E-Card Notification');
                 return false;
             }
+
         } else {
 
             $this->myLogger->logme('error', 'sendMailForDownloadingECard - employee_policy_ids are empty');
diff --git a/app/Controllers/EmployeeController.php b/app/Controllers/EmployeeController.php
index 2770ea29..810798af 100755
--- a/app/Controllers/EmployeeController.php
+++ b/app/Controllers/EmployeeController.php
@@ -93,8 +93,10 @@ class EmployeeController extends AdminController
             $filterData = $this->request->getGet();
         
             // Convert the status field to an array if it exists in the request data
-            if (isset($filterData['status'])) {
+            if (isset($filterData['status']) && !empty($filterData['status'])) {
                 $filterData['status'] = explode(",", $filterData['status']);
+            }else{
+                $filterData['status'] = [];
             }
         
             // Fetch employees with the modified $filterData array
@@ -272,7 +274,7 @@ class EmployeeController extends AdminController
         //for TPA/insurer upload
         $data['events'] = ['inception' => 'Inception (Employee + Dependents)', 'missed_inception' => 'Missed Inception (Employee + Dependents)', 'addition' => 'Addition (Employee + Dependents)', 'dependent_addition' => 'Dependent Addition (Only Dependents)', 'deletion' => 'Deletion', 'correction' => 'Correction', 'si_enhancement' => 'SI Enhancement'];
         //for inception upload
-        $data['actions'] = ['inception' => 'Inception (Employee + Dependents)',  'missed_inception' => 'Missed Inception (Employee + Dependents)', 'addition' => 'Addition (Employee + Dependents)', 'dependent_addtion' => 'Dependent Addition (Only Dependents)', 'deletion' => 'Deletion', 'correction' => 'Correction', 'si_enhancement' => 'SI Enhancement','enrollment' => 'Enrolment'];
+        $data['actions'] = ['inception' => 'Inception (Employee + Dependents)',  'missed_inception' => 'Missed Inception (Employee + Dependents)', 'addition' => 'Addition (Employee + Dependents)', 'dependent_addition' => 'Dependent Addition (Only Dependents)', 'deletion' => 'Deletion', 'correction' => 'Correction', 'si_enhancement' => 'SI Enhancement','enrollment' => 'Enrolment'];
 
         $data['import_or_export'] = ['import' => 'Import', 'export' => 'Export'];
         $data['insurer_or_tpa'] = ['insurer' => 'Insurer', 'tpa' => 'TPA'];
@@ -1709,4 +1711,79 @@ class EmployeeController extends AdminController
         return $this->respond(['status' => true, 'code' => 200, 'data' => $policies], 200);
 
     }
+
+
+    //-------- Edit individual employee and View & Send E-card  -----------------------------------------------------------------------------------------
+
+    public function get_emp_master_data_for_update($id)
+    {
+        $employee_data = $this->employeeModel->select("employees.*, DATE_FORMAT(dob, '%d/%m/%Y') AS formatted_dob,")->where('id', $id)->first();
+
+        if ($employee_data) {
+            return $this->respond(['status' => true,'code' => 200,'data' => $employee_data,], 200);
+        } else {
+            return $this->respond(['status' => false, 'code' => 404, 'message' => 'No data found.'], 404);
+        }
+    }
+
+    public function update_emp_data()
+    {
+        $data = $this->request->getPost();
+        
+        $data['dob'] = date('Y-m-d', strtotime($data['dob']));
+    
+        // Fetch current employee data
+        $employee_data = $this->employeeModel->where('id', $data['employee_primary_id'])->first();
+    
+        if ($employee_data['relationship'] == 'Self') {
+
+            if ($employee_data['gender'] != $data['gender']) {
+
+                $spouse_gender = ($data['gender'] == 'M') ? 'F' : 'M';
+                $this->employeeModel
+                    ->where('emp_code', $employee_data['emp_code'])
+                    ->where('relationship', 'Spouse')
+                    ->set(['gender' => $spouse_gender])
+                    ->update();
+            }
+        }
+    
+        // Update the employee data
+        $result = $this->employeeModel->where('id', $data['employee_primary_id'])->set($data)->update();
+    
+        if ($result) {
+            return $this->respond(['status' => true, 'code' => 200, 'data' => $data, 'message' => 'Employee updated successfully'], 200);
+        } else {
+            return $this->respond(['status' => false, 'code' => 404, 'message' => 'Failed to update employee.'], 404);
+        }
+    }
+    
+    public function send_mail_for_individual_employee_ecard($id)
+    {   
+        $ids[] = $id;
+        $empDataServiceController = new EmpDataServiceController();
+        $result = $empDataServiceController->sendMailForDownloadingECard($ids, 1);
+
+        if ($result) {
+            return $this->respond(['status' => true,'code' => 200,'message' => 'Mail sent successfully', 'result' => $result,], 200);
+        } else {
+            return $this->respond(['status' => false, 'code' => 404, 'message' => 'Failed to sent mail.'], 404);
+        }
+    }
+
+    public function checkDeletionGetDataFunction()
+    {   
+        $batch_data = [
+            'client_id' => 77,
+            'client_policy_id' => 203,
+            'client_branch_id' => 53,
+            'insurer_or_tpa' => 'tpa',
+        ];
+
+        $result = $this->employeePolicyModel->getDeletionEmployeeDataForExportExcel($batch_data);
+
+        print_rr($result); die;
+    }
+    
+
 }
diff --git a/app/Controllers/EmployeeServiceController.php b/app/Controllers/EmployeeServiceController.php
index f697a04a..c4565c6c 100755
--- a/app/Controllers/EmployeeServiceController.php
+++ b/app/Controllers/EmployeeServiceController.php
@@ -1049,7 +1049,7 @@ class EmployeeServiceController extends AdminController
                             //check self avaialbe  either same policy DB level(i.e.) gMC parents
                             if($file['action'] == 'dependent_addition' || ($policy_details['policy_type_id'] == 3 && !$is_self_available_in_policy_terms)) // 3 is GMC parents as base policy not as dep addon)
                             {
-                               $self_details = $this->employeeModel->getEmpFamilybyEmpCode(emp_code: $emp_id,client_id: $file['client_id'],emp_status: ['active'],policy_status:['active'],client_branch_id:[ $file['client_branch_id'] ]);
+                               $self_details = $this->employeeModel->getEmpFamilybyEmpCode(emp_code: trim($emp_id),client_id: $file['client_id'],emp_status: ['active'],policy_status:['active'],client_branch_id:[ $file['client_branch_id'] ],relationship:['self']);
                                // dd($self_details);
                                 if(!count($self_details))
                                 {
diff --git a/app/Controllers/MasterController.php b/app/Controllers/MasterController.php
index a4927e3d..13305f50 100755
--- a/app/Controllers/MasterController.php
+++ b/app/Controllers/MasterController.php
@@ -1611,18 +1611,26 @@ class MasterController extends AdminController
          // $gmailapi = \Config\Services::gmailapi();
          $message = '

Request for Quotation (RFQ)

Dear {{RECIPIENT_NAME}},

We are reaching out to request a quotation for the following insurance coverage. Please review the details below and provide your quote at your earliest convenience.

RFQ Details

Client name{{CLIENT_NAME}}
Coverage Type{{POLICY_LONG_NAME}}
Policy Start Date{{POLICY_START_DATE}}
Policy Duration{{DURATION}}
Please note: Additional terms and details are included in the attachment for your reference.

Please feel free to reach out if you require any further information to prepare the quote. We look forward to receiving your proposal.

Best regards,

Nhance India Pvt Ltd

'; + // $attachments = [ + // ["filePath" => WRITEPATH."uploads/excel/sample/correction.xls","fileName" => "correction.xls"], + // ["filePath" => WRITEPATH."uploads/excel/sample/deletion.xls","fileName" => "deletion.xls"], + // ["filePath" => "C:\\Users\\Venba\\Desktop\\IQ.pdf","fileName" => "Questions.pdf"], + // ["filePath" => "C:\\Users\\Venba\\Desktop\\config_age.png","fileName" => "config_age.png"] + // ]; + $attachments = [ - ["filePath" => WRITEPATH."uploads/excel/sample/correction.xls","fileName" => "correction.xls"], - ["filePath" => WRITEPATH."uploads/excel/sample/deletion.xls","fileName" => "deletion.xls"], - ["filePath" => "C:\\Users\\Venba\\Desktop\\IQ.pdf","fileName" => "Questions.pdf"], - ["filePath" => "C:\\Users\\Venba\\Desktop\\config_age.png","fileName" => "config_age.png"] + ["filePath" => ROOTPATH."public/sample_excel/sample_addition.xls","fileName" => "sample_addition.xls"], + ["filePath" => ROOTPATH."public/sample_excel/sample_inception.xls","fileName" => "sample_inception.xls"], + ["filePath" => ROOTPATH."public/assets/images/login_bg.jpg","fileName" => "login_bg.jpg"] ]; + $email_id = CLI::getOption('to') ? CLI::getOption('to') : $email_id; $res = MailHelper::send_email(['mail' => $email_id, 'subject' => 'Mail Via CLI', 'message' => $message,'attachments' => $attachments]); print_r($res); } + public function testCheckBounceMails() { $gmailapi = \Config\Services::gmailapi(); @@ -1661,7 +1669,9 @@ class MasterController extends AdminController 'uploads' => ROOTPATH . 'public/uploads', 'add_image_upload' => ROOTPATH . 'public/uploads/add_image_upload/',//adverdisement images for enrollment app 'logo' => ROOTPATH . 'public/uploads/logo/', - 'template_bg' => ROOTPATH . 'public/uploads/template_bg/' + 'template_bg' => ROOTPATH . 'public/uploads/template_bg/', + 'attachments' => WRITEPATH . 'uploads/attachments/', + ]; foreach ($folders as $folderName => $folderPath) { diff --git a/app/Controllers/NotificationController.php b/app/Controllers/NotificationController.php index ff666cef..a3c8efe9 100755 --- a/app/Controllers/NotificationController.php +++ b/app/Controllers/NotificationController.php @@ -16,6 +16,7 @@ use App\Models\NotificationModel; use App\Models\ClientModel; use App\Models\EmployeeModel; use App\Models\UserModel; +use App\Models\MailAttachmentModel; use App\Helpers\sendMailNotification; use App\Helpers\MailHelper; @@ -26,12 +27,14 @@ class NotificationController extends AdminController protected $myLogger; protected $notificationModel; protected $clientModel; + protected $MailAttachmentModel; public function __construct() { $this->myLogger = \Config\Services::mylogger(); $this->notificationModel = new NotificationModel(); $this->clientModel = new ClientModel(); + $this->MailAttachmentModel = new MailAttachmentModel(); } // This is for Template Name Camel Case to Snake Case for store in DB @@ -52,16 +55,21 @@ class NotificationController extends AdminController $notificationModel = new NotificationModel(); $find_notification = $notificationModel->where('client_id',$form_data['client_id'])->where('template_name',$form_data['template_name'])->first(); + if ($find_notification) { + $id = $find_notification['id']; $form_data['updated_by'] = get_session_userid(); $notificationModel->update($id,$form_data); $complete = "Update"; + }else{ + $form_data['created_by'] = get_session_userid(); $notificationModel->insert($form_data); $complete = "Inserted"; } + return json_encode($complete); } @@ -111,8 +119,11 @@ class NotificationController extends AdminController public function getMailTemplateData($template_name,$client_id) { $notificationModel = new NotificationModel(); - $value = $notificationModel->where('client_id',$client_id)->where('template_name',$template_name)->first(); + if($value){ + $value['data'] = $this->MailAttachmentModel->where('notification_id', $value['id'])->where('is_active', 1)->findAll(); + } + // return $this->respond(['status' => true, 'code' => 200, '' => 'Attachment deleted successfully'], 200); return json_encode($value); } @@ -198,4 +209,74 @@ class NotificationController extends AdminController } } + + public function insertAttachmentsForMailTemplates() + { + $form_data = $this->request->getPost(); + + // Check if client_id and template_name are provided + if (empty($form_data['client_id']) || empty($form_data['template_name'])) { + return $this->respond(['status' => false, 'code' => 400, 'message' => 'Client ID and template name are required.'], 400); + } + + // Attempt to find the notification + $find_notification = $this->notificationModel->where('client_id', $form_data['client_id']) + ->where('template_name', $form_data['template_name']) + ->first(); + + if (!$find_notification) { + return $this->respond(['status' => false, 'code' => 404, 'message' => 'Notification data not found.'], 404); + } + + // Define upload path and attempt file upload + $uploadFilePath = WRITEPATH . 'uploads/attachments'; + $uploadedFile = $this->request->getFile('file'); + $fileName = file_Upload($uploadedFile, $uploadFilePath); // Assume file_Upload handles file saving + + if ($fileName) { + // Prepare data for insertion + $data = [ + 'notification_id' => $find_notification['id'], + 'file_name' => $fileName, + 'file_path' => 'uploads/attachments/' . $fileName, + ]; + + + // Insert file attachment record + if ($this->MailAttachmentModel->insert($data)) { + // Retrieve active attachments to return in response + $attachment_data = $this->MailAttachmentModel->where('is_active', 1)->findAll(); + return $this->respond([ + 'status' => true, + 'code' => 200, + 'data' => $attachment_data, + 'message' => 'File uploaded successfully' + ], 200); + } else { + return $this->respond(['status' => false, 'code' => 500, 'message' => 'Failed to save file attachment data.'], 500); + } + } else { + return $this->respond(['status' => false, 'code' => 400, 'message' => 'File upload failed.'], 400); + } + } + + public function removeAttachmentsForMailTemplates($id, $client_id, $template_name) + { + $attachment_data_for_unlink_file = $this->MailAttachmentModel->where('id', $id)->first(); + $file_path = WRITEPATH . $attachment_data_for_unlink_file['file_path']; + + if ($this->MailAttachmentModel->where('id', $id)->delete()) { + + unlink($file_path); + + $find_notification = $this->notificationModel->where('client_id', $client_id)->where('template_name', $template_name)->first(); + $attachmentDatas = $this->MailAttachmentModel->where('notification_id', $find_notification['id'])->where('is_active', 1)->findAll(); + + return $this->respond(['status' => true, 'code' => 200, 'message' => 'Attachment deleted successfully', 'data' => $attachmentDatas], 200); + + } else { + return $this->respond(['status' => false, 'code' => 404, 'message' => 'The Client has active policy'], 200); + } + } + } \ No newline at end of file diff --git a/app/Helpers/sendMailNotification.php b/app/Helpers/sendMailNotification.php index 6a729c56..31114293 100755 --- a/app/Helpers/sendMailNotification.php +++ b/app/Helpers/sendMailNotification.php @@ -10,6 +10,7 @@ use App\Models\UserModel; use App\Models\EmployeeModel; use App\Models\PolicyPremium1Model; use App\Models\PolicyPremium2Model; +use App\Models\MailAttachmentModel; class sendMailNotification { @@ -22,6 +23,21 @@ class sendMailNotification $notification = $params['notification']; $client_data = $params['client_data']; + $mailAttachmentModel = new MailAttachmentModel(); + $attachment_data = $mailAttachmentModel + ->select('file_path, file_name') + ->where('notification_id', $notification['id']) + ->where('is_active', 1) + ->findAll(); + + $attachments = []; + foreach ($attachment_data as $data) { + $attachments[] = [ + "filePath" => WRITEPATH . $data['file_path'], + "fileName" => $data['file_name'] + ]; + } + $mail = $dataToInsert['email_corporate']; $subject = $notification['subject']; $app_link = $_ENV['App_Url']; @@ -37,7 +53,7 @@ class sendMailNotification $mail_content = str_replace("[[app_link]]", "Review Details", $mail_content); if ($dataToInsert['relationship'] == 'Self' && $mail != null || $mail != '') { - $wholeData = ['mail' => $mail, 'subject' => $subject,'message'=> $mail_content,'bcc'=> $client_data['common_mails'], 'reply_to' => $client_data['reply_to']]; + $wholeData = ['mail' => $mail, 'subject' => $subject,'message'=> $mail_content,'bcc'=> $client_data['common_mails'], 'reply_to' => $client_data['reply_to'], 'attachments' => $attachments]; } return $wholeData; @@ -799,7 +815,24 @@ class sendMailNotification $mail = $params['test_mail']; $mail_content = $notification['mail_content']; - $subject = $notification['subject']; + $subject = $notification['subject']; + + $mailAttachmentModel = new MailAttachmentModel(); + $attachment_data = $mailAttachmentModel + ->select('file_path, file_name') + ->where('notification_id', $notification['id']) + ->where('is_active', 1) + ->findAll(); + + $attachments = []; + foreach ($attachment_data as $data) { + $attachments[] = [ + "filePath" => WRITEPATH . $data['file_path'], + "fileName" => $data['file_name'] + ]; + } + + // print_r($attachments); die; $employee_name = 'John Doe'; @@ -816,7 +849,7 @@ class sendMailNotification $mail_content = str_replace("[[app_link]]", "Review Details", $mail_content); if ($mail != null || $mail != '') { - $wholeData = ['mail' => $mail, 'subject' => $subject,'message'=> $mail_content,'bcc'=> $client_data['common_mails'], 'reply_to' => $client_data['reply_to']]; + $wholeData = ['mail' => $mail, 'subject' => $subject,'message'=> $mail_content,'bcc'=> $client_data['common_mails'], 'reply_to' => $client_data['reply_to'], 'attachments' => $attachments]; } return $wholeData; diff --git a/app/Models/EmployeePolicyModel.php b/app/Models/EmployeePolicyModel.php index 00dff6ca..688b8abf 100755 --- a/app/Models/EmployeePolicyModel.php +++ b/app/Models/EmployeePolicyModel.php @@ -76,7 +76,7 @@ class EmployeePolicyModel extends Model } // ---------------------------------------------------------------------------------------------------------- - public function getEmployeePolicy($client_id = 0, $policy_id=0, $status=0, $branch_id=0, $emp_code="", $emp_name="") + public function getEmployeePolicy($client_id = 0, $policy_id=0, $status=[], $branch_id=0, $emp_code="", $emp_name="") { // dd($status); @@ -91,6 +91,7 @@ class EmployeePolicyModel extends Model 'tpab.branch_code as tpa_branch_code', 'cm.client_name', 'cm.short_name as client_short_name', + 'emp.id as employee_primary_id', 'emp.relationship', 'emp.relationship_code', 'emp.change_event', @@ -98,6 +99,7 @@ class EmployeePolicyModel extends Model 'emp.name', 'emp.email_corporate', 'emp.dob', + 'DATE_FORMAT(emp.dob, "%d/%m/%Y") AS formatted_dob', 'emp.gender', 'emp.emp_status', 'emp.is_active as emp_is_active', @@ -552,6 +554,27 @@ class EmployeePolicyModel extends Model $client_branch_id = $ref_data['client_branch_id']; $insurer_or_tpa = $ref_data['insurer_or_tpa']; + $get_insurer_id_from_client_policy = $this->db->table('client_policy') + ->select('insurer_id') + ->where('id', $client_policy_id) + ->get() + ->getRowArray(); + + $add_one_day = 0; + + if (!empty($get_insurer_id_from_client_policy)) { + + $get_the_insurer_add_one_for_delete = $this->db->table('insurers') + ->select('deletion_add_day') + ->where('id', $get_insurer_id_from_client_policy['insurer_id']) + ->get() + ->getRowArray(); + + if (!empty($get_the_insurer_add_one_for_delete) && $get_the_insurer_add_one_for_delete['deletion_add_day'] == 1) { + $add_one_day = 1; + } + } + $query = $this->db->query(" SELECT DISTINCT a.id as endorsement_primarykey, @@ -591,10 +614,10 @@ class EmployeePolicyModel extends Model deletiondata.reasonforexit, deletiondata.status, - DATEDIFF(employee_polices.policy_end_date, deletiondata.dateofexit) + 1 AS no_of_days, - ROUND((employee_polices.rata_premimum * (DATEDIFF(employee_polices.policy_end_date, deletiondata.dateofexit) + 1)) / 365, 2) AS pro_rata_premium, - ROUND(((employee_polices.rata_premimum * (DATEDIFF(employee_polices.policy_end_date, deletiondata.dateofexit) + 1)) / 365) * 0.18, 2) AS gst, - ROUND(((employee_polices.rata_premimum * (DATEDIFF(employee_polices.policy_end_date, deletiondata.dateofexit) + 1)) / 365) + (((employee_polices.rata_premimum * (DATEDIFF(employee_polices.policy_end_date, deletiondata.dateofexit) + 1)) / 365) * 0.18), 2) AS total + DATEDIFF(employee_polices.policy_end_date, deletiondata.dateofexit) + '$add_one_day' AS no_of_days, + ROUND((employee_polices.rata_premimum * (DATEDIFF(employee_polices.policy_end_date, deletiondata.dateofexit) + $add_one_day)) / 365, 2) AS pro_rata_premium, + ROUND(((employee_polices.rata_premimum * (DATEDIFF(employee_polices.policy_end_date, deletiondata.dateofexit) + $add_one_day)) / 365) * 0.18, 2) AS gst, + ROUND(((employee_polices.rata_premimum * (DATEDIFF(employee_polices.policy_end_date, deletiondata.dateofexit) + $add_one_day)) / 365) + (((employee_polices.rata_premimum * (DATEDIFF(employee_polices.policy_end_date, deletiondata.dateofexit) + $add_one_day)) / 365) * 0.18), 2) AS total FROM emp_endorsement a LEFT JOIN diff --git a/app/Models/MailAttachmentModel.php b/app/Models/MailAttachmentModel.php new file mode 100644 index 00000000..74519d65 --- /dev/null +++ b/app/Models/MailAttachmentModel.php @@ -0,0 +1,56 @@ +(₹)Premium (₹)Pro Rata
Premium (₹)GST + Action @@ -135,6 +136,26 @@ + + + @@ -159,9 +180,11 @@ + Total + @@ -170,7 +193,82 @@ + + + + diff --git a/app/Views/insurer_or_tpa_data.php b/app/Views/insurer_or_tpa_data.php index 4882ceb2..5c77af6c 100755 --- a/app/Views/insurer_or_tpa_data.php +++ b/app/Views/insurer_or_tpa_data.php @@ -458,8 +458,6 @@ }); - - if (Array.isArray(foundPolicies) && foundPolicies.length === 0) { appendPolicies2(foundPolicies); @@ -551,15 +549,27 @@ //-------------------------------------------------------------------------------------- $('#insurer_or_tpa').change(function(){ + var insurer_or_tpa = $(this).val() var policy_value = $('#policy').val() var event_type_data = $('#event_type_data').val(); + var action_type = $('#action_type').val() + console.log('policy_value', policy_value) - if(insurer_or_tpa == 'tpa' || event_type_data == 0){ + // if(insurer_or_tpa == 'tpa' || event_type_data == 0){ + if(insurer_or_tpa == 'tpa'){ + $("#event_type").removeAttr("multiple"); $("#event_type").attr("name", "event_type"); $("#event_type").select2('destroy'); + + }else if(insurer_or_tpa == 'insurer' && action_type == 'import'){ + + $("#event_type").removeAttr("multiple"); + $("#event_type").attr("name", "event_type"); + $("#event_type").select2('destroy'); + }else{ if(policy_value != 0){ $("#event_type").attr("multiple", "multiple"); @@ -570,15 +580,26 @@ }) ; $('#action_type').change(function(){ - var insurer_or_tpa = $(this).val() + var action_type = $(this).val() var policy_value = $('#policy').val() + var insurer_or_tpa = $('#insurer_or_tpa').val() + var event_type_data = $('#event_type_data').val(); console.log('policy_value', policy_value) - if(insurer_or_tpa == 'import' || event_type_data == 0){ + // if(insurer_or_tpa == 'import' || event_type_data == 0){ + if(action_type == 'import'){ + $("#event_type").removeAttr("multiple"); $("#event_type").attr("name", "event_type"); $("#event_type").select2('destroy'); + + } else if(action_type == 'export' && insurer_or_tpa == 'tpa'){ + + $("#event_type").removeAttr("multiple"); + $("#event_type").attr("name", "event_type"); + $("#event_type").select2('destroy'); + }else{ if(policy_value != 0){ $("#event_type").attr("multiple", "multiple"); @@ -588,12 +609,15 @@ } }) - $(document).ready(function(){ $('#policy').change(function(){ + var policy_value = $(this).val() - if(policy_value == 0){ + var insurer_or_tpa = $('insurer_or_tpa').val() + var action_type = $('action_type').val() + + if(policy_value == 0 || insurer_or_tpa == 'tpa' || action_type == 'import'){ $("#event_type").removeAttr("multiple"); $("#event_type").attr("name", "event_type"); $("#event_type").select2('destroy'); diff --git a/app/Views/layout/header.php b/app/Views/layout/header.php index 9ad74bc1..ee423b08 100755 --- a/app/Views/layout/header.php +++ b/app/Views/layout/header.php @@ -656,12 +656,12 @@ - + diff --git a/app/Views/notification.php b/app/Views/notification.php index 6b15116a..c9bdb5e5 100755 --- a/app/Views/notification.php +++ b/app/Views/notification.php @@ -30,32 +30,32 @@ $account_maneger_summary_mail = 0; $client_hr_summary_mail = 0; if(isset($notification)){ - foreach($notification as $value){ - - if ($value['template_name'] == 'member_welcome_mail') { - $member_welcome_mail = $value['enabled']; - } + foreach($notification as $value){ + + if ($value['template_name'] == 'member_welcome_mail') { + $member_welcome_mail = $value['enabled']; + } - if ($value['template_name'] == 'member_reminder_mail') { - $member_reminder_mail = $value['enabled']; - } + if ($value['template_name'] == 'member_reminder_mail') { + $member_reminder_mail = $value['enabled']; + } - if ($value['template_name'] == 'member_ecard_mail') { - $member_ecard_mail = $value['enabled']; - } + if ($value['template_name'] == 'member_ecard_mail') { + $member_ecard_mail = $value['enabled']; + } - if ($value['template_name'] == 'member_review_and_summary_mail') { - $member_review_and_summary_mail = $value['enabled']; - } + if ($value['template_name'] == 'member_review_and_summary_mail') { + $member_review_and_summary_mail = $value['enabled']; + } - if ($value['template_name'] == 'account_maneger_summary_mail') { - $account_maneger_summary_mail = $value['enabled']; - } + if ($value['template_name'] == 'account_maneger_summary_mail') { + $account_maneger_summary_mail = $value['enabled']; + } - if ($value['template_name'] == 'client_hr_summary_mail') { - $client_hr_summary_mail = $value['enabled']; + if ($value['template_name'] == 'client_hr_summary_mail') { + $client_hr_summary_mail = $value['enabled']; + } } - } } ?>

@@ -197,7 +197,7 @@