diff --git a/app/Controllers/ClientController.php b/app/Controllers/ClientController.php index e42266d2..d5370b02 100755 --- a/app/Controllers/ClientController.php +++ b/app/Controllers/ClientController.php @@ -5969,6 +5969,8 @@ class ClientController extends AdminController // $emp_data = $this->employeePolicyModel->getEmployeePolicyForEcard(12); // $ids = array_column($emp_data, 'id'); + // $client_policy_id = 5062; + // $ids = [408518,408519,408520,408521,408522,408523,408524,408525,408526,408527,408528,408529,408530,408531,408532,408533,408534,408535,408536,408537,408538,408539,408540,408541,408542,408543,408544,408545,408546,408547,408548,408549,408550,408551,408552,408553,408554,408555,408556,408557,408558,408559,408560,408561,408562,408563,408564,408565,408566,408567,408568,408569,408570,408571,408572,408573,408574,408575,408576,408577,408578,408579,408580,408581,408582,408583,408584,408585,408586,408587,408588,408589,408590,408591,408592,408593,408594,408595,408596,408597,408598,408599,408600,408601,408602,408603,408604,408605,408606,408607,408608,408609,408610,408611,408612,408613,408614,408615,408616,408617,408618,408619,408620,408621,408622,408623,408624,408625,408626,408627,408628,408629,408630,408631,408632,408633,408634,408635,408636,408637,408638,408639,408640,408641,408642,408643]; $EmpDataServiceController = new EmpDataServiceController(); // $res = $EmpDataServiceController->generateExcelForDeletion($batch_data); dd($return); die; @@ -5983,7 +5985,7 @@ class ClientController extends AdminController // $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->sendMailForDownloadingECard($ids); + // $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); // return $this->downloadInsurerExcelExport($batch_data); diff --git a/app/Controllers/DashboardController.php b/app/Controllers/DashboardController.php index 369f9444..8958c26d 100755 --- a/app/Controllers/DashboardController.php +++ b/app/Controllers/DashboardController.php @@ -710,7 +710,7 @@ class DashboardController extends AdminController // print_r(($ids)); die; // print_r($this->clientPolicyModel->getLastQuery()); die; // $this->myLogger->logme('error', "Policy details fetched: " . json_encode($client_policy_data)); - Jobs::addJob(['job_name' => 'sendMailForDownloadingECard', 'payload' => $ids]); + Jobs::addJob(['job_name' => 'sendMailForDownloadingECard', 'payload' => ['ids' => $ids, 'client_policy_id' => $policy_id]]); // $empEmpDataServiceController = new EmpDataServiceController(); // $empEmpDataServiceController->sendMailForDownloadingECard($ids); diff --git a/app/Controllers/EmpDataServiceController.php b/app/Controllers/EmpDataServiceController.php index 986a3fcd..8fa5f4bb 100755 --- a/app/Controllers/EmpDataServiceController.php +++ b/app/Controllers/EmpDataServiceController.php @@ -2204,7 +2204,7 @@ class EmpDataServiceController extends BaseController if ($get_policy_type['policy_type_id'] != 1) { $job_details = new Jobs(); - $r = Jobs::addJob(['job_name' => 'sendMailForDownloadingECard', 'payload' => $emp_policy_ids]); + $r = Jobs::addJob(['job_name' => 'sendMailForDownloadingECard', 'payload' => ['ids' => $emp_policy_ids, 'client_policy_id' => $client_policy_id]]); } } @@ -4866,15 +4866,24 @@ class EmpDataServiceController extends BaseController return true; } - public function sendMailForDownloadingECard(array $ids, $single_mail = null) - { + public function sendMailForDownloadingECard($params, $single_mail = null) + { + // dd($params); $this->myLogger->logme('info', 'sendMailForDownloadingECard - Function called'); + + $ids = $params['ids'] ?? null; + $client_policy_id = $params['client_policy_id'] ?? null; if (empty($ids)) { $this->myLogger->logme('error', 'sendMailForDownloadingECard - employee_policy_ids are empty'); - return false; + return ['status' => false , 'message' => 'employee_policy_ids are empty']; } - + + if (empty($client_policy_id)) { + $this->myLogger->logme('error', 'sendMailForDownloadingECard - client_policy_id are empty'); + return ['status' => false , 'message' => 'client_policy_id are empty']; + } + $temp_id = $ids[0]; $get_client_info = $this->employeePolicyModel @@ -4897,10 +4906,11 @@ class EmpDataServiceController extends BaseController if (!$get_client_info) { $this->myLogger->logme('error', 'sendMailForDownloadingECard - No client information found for the first ID'); - return false; + return ['status' => false , 'message' => 'No client information found for the first ID']; } - + $client_data = $this->clientModel->where('id', $get_client_info['client_id'])->first(); + $notification = $this->notificationModel ->where('client_id', $get_client_info['client_id']) ->where('template_name', 'member_ecard_mail') @@ -4908,9 +4918,143 @@ class EmpDataServiceController extends BaseController if (empty($notification) || $notification['enabled'] != 1) { $this->myLogger->logme('error', 'sendMailForDownloadingECard - Notification setup not enabled or missing for E-Card Notification'); - return false; + return ['status' => false , 'message' => 'Notification setup not enabled or missing for E-Card Notification']; } - + + $client_policy_data = $this->clientPolicyModel->where('id', $client_policy_id)->first(); + // print_rr($client_policy_data); die; + + // this for handle the GMC - Parants to send the E-Card mail + if($client_policy_data['policy_type_id'] == 3 && $client_policy_data['is_addon'] == 3){ + + $this->myLogger->logme('error', 'sendMailForDownloadingECard - Processing the GMC - Patents E-Card Mail send'); + + try { + + $emp_details = $this->employeePolicyModel + ->select(" + employees.id as emp_id, + employees.client_id, + employees.client_branch_id, + employees.relationship, + employees.emp_code, + employees.email_corporate, + employees.name, + employees.mobile, + employee_polices.basic_cover_si, + + ( + SELECT self_data.email_corporate + FROM employees AS self_data + WHERE self_data.is_active = 1 + AND self_data.emp_status = 'active' + AND self_data.family_floater_key = 'self' + AND self_data.emp_code = employees.emp_code + LIMIT 1 + ) AS self_mail, + + cp.policy_type_id, + cp.is_addon, + cp.policy_no, + + employee_polices.id as emp_policy_id, + employee_polices.client_policy_id, + employee_polices.rand_string, + employee_polices.tpa_id + ") + ->join('employees', 'employees.id = employee_polices.employee_id') + ->join('client_policy cp', 'employee_polices.client_policy_id = cp.id') + ->where('employees.emp_status', 'active') + ->where('employees.is_active', 1) + ->where('employee_polices.status', 'active') + ->where('employee_polices.is_active', 1) + ->whereIn('employee_polices.id', $ids) + ->groupBy('employees.emp_code') + ->findAll(); + + // dd($emp_details); + + if (!empty($emp_details)) { + + $count = 0; + $processedCount = 0; + $wholeData = []; + + foreach ($emp_details as $emp_value) { + + $this->myLogger->logme('error', 'sendMailForDownloadingECard - Processing send mail for the employee_policy_id: {id}', ['id' => $emp_value['emp_policy_id']]); + + if (!empty($emp_value['self_mail'])) { + + $params = [ + 'rand_string' => $emp_value['rand_string'], + 'tpa_id' => $emp_value['tpa_id'], + 'notification' => $notification, + 'client_data' => $client_data, + 'get_emp_email_and_other_details' => $emp_value, + + 'id' => $emp_value['emp_id'], + 'emp_code' => $emp_value['emp_code'], + 'policy_no' => $emp_value['policy_no'], + 'client_policy_id' => $emp_value['client_policy_id'], + ]; + + if(empty($single_mail)){ + $params['all_member'] = 1; + } + + $params['common'] = [ + 'client_id' => $emp_value['client_id'], + 'client_branch_id' => $emp_value['client_branch_id'], + 'client_policy_id' => $emp_value['client_policy_id'], + 'employee_policy_id' => $emp_value['emp_policy_id'], + 'employee_id' => $emp_value['emp_id'], + 'mail_type' => 'member_ecard_mail', + ]; + + $wholeData[] = sendMailNotification::sendMailNotification('member_ecard_mail', $params); + $count++; + + }else{ + $this->myLogger->logme('error', 'sendMailForDownloadingECard - process skiped - self mail not found for the dependent employee_policy_id: {id}', ['id' => $emp_value['emp_policy_id']]); + } + + $processedCount++; + + // Send batch emails or handle single email + if ($count == 20 || $processedCount == count($ids)) { + if (!empty($wholeData)) { + if ($single_mail == 1) { + $this->myLogger->logme('error', 'sendMailForDownloadingECard - Sending single mail'); + $mail_result = MailHelper::send_email($wholeData[0]); + $this->myLogger->logme('info', 'sendMailForDownloadingECard - Single mail result: {result}', ['result' => $mail_result]); + return ['status' => true , 'data' =>$mail_result, 'message' => 'Email processing completed']; + } else { + $this->myLogger->logme('error', 'sendMailForDownloadingECard - Creating a job for bulk mail'); + Jobs::addJob(['job_name' => 'bulk_mail', 'payload' => $wholeData]); + $wholeData = []; + $count = 0; + } + } + } + + } + + $this->myLogger->logme('error', 'sendMailForDownloadingECard - Email processing completed'); + return ['status' => true , 'message' => 'Email processing completed']; + + }else{ + $this->myLogger->logme('error', 'sendMailForDownloadingECard - Employee Data not found'); + return ['status' => false , 'message' => 'Employee Data not found']; + } + + } catch (\Exception $e) { + $this->myLogger->logme('error', 'sendMailForDownloadingECard - Exception occurred: {message}', ['message' => $e->getMessage()]); + return ['status' => false , 'message' => 'Exception occurred' . $e->getMessage()]; + } + + } + try { $this->myLogger->logme('error', 'sendMailForDownloadingECard - Inside try block'); @@ -4985,6 +5129,8 @@ class EmpDataServiceController extends BaseController $wholeData[] = sendMailNotification::sendMailNotification('member_ecard_mail', $params); // $wholeMailData[] = sendMailNotification::sendMailNotification('member_ecard_mail', $params); $count++; + }else{ + $this->myLogger->logme('error', 'sendMailForDownloadingECard - process skiped - Self not found : {id}', ['id' => $id]); } $processedCount++; @@ -4996,7 +5142,7 @@ class EmpDataServiceController extends BaseController $this->myLogger->logme('error', 'sendMailForDownloadingECard - Sending single mail'); $mail_result = MailHelper::send_email($wholeData[0]); $this->myLogger->logme('info', 'sendMailForDownloadingECard - Single mail result: {result}', ['result' => $mail_result]); - return $mail_result; + return ['status' => true , 'data' =>$mail_result, 'message' => 'Email processing completed']; } else { $this->myLogger->logme('error', 'sendMailForDownloadingECard - Creating a job for bulk mail'); Jobs::addJob(['job_name' => 'bulk_mail', 'payload' => $wholeData]); @@ -5011,11 +5157,11 @@ class EmpDataServiceController extends BaseController // dd($wholeMailData); $this->myLogger->logme('error', 'sendMailForDownloadingECard - Email processing completed'); - return true; + return ['status' => true , 'message' => 'Email processing completed']; } catch (\Exception $e) { $this->myLogger->logme('error', 'sendMailForDownloadingECard - Exception occurred: {message}', ['message' => $e->getMessage()]); - return false; + return ['status' => false , 'message' => 'Exception occurred' . $e->getMessage()]; } } diff --git a/app/Controllers/EmployeeController.php b/app/Controllers/EmployeeController.php index 39298198..dc72314e 100755 --- a/app/Controllers/EmployeeController.php +++ b/app/Controllers/EmployeeController.php @@ -2564,16 +2564,16 @@ class EmployeeController extends AdminController } } - public function send_mail_for_individual_employee_ecard($id) + public function send_mail_for_individual_employee_ecard($id, $client_policy_id) { $ids[] = $id; $empDataServiceController = new EmpDataServiceController(); - $result = $empDataServiceController->sendMailForDownloadingECard($ids, 1); + $result = $empDataServiceController->sendMailForDownloadingECard(['ids' => $ids, 'client_policy_id' => $client_policy_id], 1); - if ($result) { - return $this->respond(['status' => true,'code' => 200,'message' => 'Mail sent successfully', 'result' => $result,], 200); + if (isset($result['status']) && $result['status'] == true) { + 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); + return $this->respond(['status' => false, 'code' => 404, 'message' => 'Failed to sent mail.', 'result' => $result], 200); } } diff --git a/app/Controllers/MediAssistApiController.php b/app/Controllers/MediAssistApiController.php index e0be4976..266862d2 100644 --- a/app/Controllers/MediAssistApiController.php +++ b/app/Controllers/MediAssistApiController.php @@ -393,7 +393,7 @@ class MediAssistApiController extends BaseController // send e-card if(!empty($employee_policy_ids)){ log_message('error', "sendMailForDownloadingECard JOB PUSHED."); - Jobs::addJob(['job_name' => 'sendMailForDownloadingECard', 'payload' => $employee_policy_ids]); + Jobs::addJob(['job_name' => 'sendMailForDownloadingECard', 'payload' => ['ids' => $employee_policy_ids, 'client_policy_id' => $client_policy_id]]); } // update file table status after the tpa id successfully updated diff --git a/app/Views/employee_data_list.php b/app/Views/employee_data_list.php index 9bdc75d5..3e3178b6 100755 --- a/app/Views/employee_data_list.php +++ b/app/Views/employee_data_list.php @@ -203,7 +203,7 @@ - Send E-Card Mail + Send E-Card Mail @@ -553,7 +553,7 @@ }); } - function send_mail_for_individual_employee_ecard(id){ + function send_mail_for_individual_employee_ecard(id, client_policy_id){ Swal.fire({ title: "Do you want to send Ecard Mail?", @@ -570,7 +570,7 @@ $.ajax({ - url: ''+id, + url: ''+id + '/' + client_policy_id, type: "GET", dataType: 'json', success: function (res) {