From fc0a9592d31b9404da44cd56211a96ba6c021622 Mon Sep 17 00:00:00 2001 From: velz Date: Fri, 6 Dec 2024 10:40:18 +0530 Subject: [PATCH 1/7] CHANGE_REMOVED_SI_IN_FLOATER_POLICY --- app/Controllers/EmployeeRestController.php | 2 +- app/Helpers/sendMailNotification.php | 4 ++-- app/Models/EmployeeModel.php | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php index df90fccd..747b272d 100755 --- a/app/Controllers/EmployeeRestController.php +++ b/app/Controllers/EmployeeRestController.php @@ -346,7 +346,7 @@ class EmployeeRestController extends AdminController ->where('client_policy_id',$value['policy_details']['client_policy_id'] ) ->where('employee_id' , $value['temp']['emp_id'] ) ->where('is_active', 1 ) - ->set(array('premium'=> $value['policy_details']['premium'] , 'rata_premimum'=> $value['policy_details']['rata_premimum'] , 'gst'=> $value['policy_details']['gst'] )) + ->set(array('basic_cover_si' => $value['policy_details']['basic_cover_si'],'premium'=> $value['policy_details']['premium'] , 'rata_premimum'=> $value['policy_details']['rata_premimum'] , 'gst'=> $value['policy_details']['gst'] )) ->update(); } diff --git a/app/Helpers/sendMailNotification.php b/app/Helpers/sendMailNotification.php index e6b6edf9..26ee4af5 100755 --- a/app/Helpers/sendMailNotification.php +++ b/app/Helpers/sendMailNotification.php @@ -282,11 +282,11 @@ class sendMailNotification $premium = ''; $gst_forself = ''; - if(checkFamilyFloaters($policy_premium_data, $client_policy_data, $inner_item)){ + // if(checkFamilyFloaters($policy_premium_data, $client_policy_data, $inner_item)){ $si = '₹ ' .format_indian_number($inner_item['basic_cover_si']); $premium = '₹ ' .format_indian_number(round($inner_item['premium'])); $gst_forself = '₹ ' .format_indian_number(round($inner_item['gst'])); - } + // } $temp_data .= ''; $temp_data .= '' . $inner_item['name'] . ($inner_item['relationship'] == 'Self' ? ' (' . $inner_item['emp_code'] . ')' : '') . ''; diff --git a/app/Models/EmployeeModel.php b/app/Models/EmployeeModel.php index edffa781..9fd8fbdb 100755 --- a/app/Models/EmployeeModel.php +++ b/app/Models/EmployeeModel.php @@ -149,7 +149,7 @@ class EmployeeModel extends Model { return $this->db->table('employee_polices') - ->select(' policy_type.long_name as Policy_Name , client_policy.policy_terms as Policy_Terms, client_policy.client_id as ClientId, client_policy.policy_id as PolicyId,client_policy.id as ClientPolicyId, client_policy.open_for_enrollment as OpenForEnrollment, client_policy.is_member_modify_allowed, client_policy.disclaimer,client_policy.policy_type_id , employee_polices.tpa_id as tpa_id , employee_polices.rand_string as rand_string') // Select all columns from both tables + ->select(' policy_type.long_name as Policy_Name , client_policy.policy_terms as Policy_Terms, client_policy.client_id as ClientId, client_policy.policy_id as PolicyId,client_policy.id as ClientPolicyId, client_policy.open_for_enrollment as OpenForEnrollment,client_policy.disclaimer,client_policy.policy_type_id , employee_polices.tpa_id as tpa_id , employee_polices.rand_string as rand_string') // Select all columns from both tables ->join('client_policy', 'client_policy.id = employee_polices.client_policy_id') ->join('policy_type', 'policy_type.id = client_policy.policy_type_id') ->where('client_policy.policy_status', 1) From 01b30e4360222d3fae7dba87f1d32eb6c0dba61e Mon Sep 17 00:00:00 2001 From: Srinivas-Saravanan Date: Fri, 6 Dec 2024 10:44:31 +0530 Subject: [PATCH 2/7] FEAT_MAIL SENT HISTORY ADDED --- Job_Queue.txt | 1 + app/Controllers/MasterController.php | 12 ++-- app/Helpers/GmailResponseHandler.php | 94 ++++++++++++++++++++++++++++ app/Helpers/JWTToken.php | 2 +- app/Helpers/MailHelper.php | 23 ++++--- app/Models/GmailSentHistoryModel.php | 11 ++++ job_queue | 1 + phpqueue.bat | 42 +++++++++++++ phpqueue.pid | 1 + phpqueue.sh | 56 +++++++++++++++++ phpsetvariable.sh | 13 ++++ 11 files changed, 243 insertions(+), 13 deletions(-) create mode 100755 Job_Queue.txt create mode 100644 app/Helpers/GmailResponseHandler.php create mode 100644 app/Models/GmailSentHistoryModel.php create mode 100755 job_queue create mode 100644 phpqueue.bat create mode 100644 phpqueue.pid create mode 100755 phpqueue.sh create mode 100755 phpsetvariable.sh diff --git a/Job_Queue.txt b/Job_Queue.txt new file mode 100755 index 00000000..56a6051c --- /dev/null +++ b/Job_Queue.txt @@ -0,0 +1 @@ +1 \ No newline at end of file diff --git a/app/Controllers/MasterController.php b/app/Controllers/MasterController.php index 1599bac2..a875e437 100755 --- a/app/Controllers/MasterController.php +++ b/app/Controllers/MasterController.php @@ -30,6 +30,8 @@ use App\Models\StateModel; use App\Models\PolicyTypeModel; use App\Models\CDMasterModel; use App\Models\ClientDepositModel; +use App\Models\EmployeePolicyModel; +use App\Models\FileModel; use App\Models\InsurerExcelExportTemplateModel; use App\Models\SettingsModel; use App\Models\VehicleModel; @@ -1574,7 +1576,7 @@ class MasterController extends AdminController $to = $this->request->getPost('to'); $subject = $this->request->getPost('subject'); $mail_content = $this->request->getPost('content'); - + $common = ['mail_type'=>'test_mail_ui']; /*****CHOOSE ANY ONE AT A TIME, COMMENT ANOTHER ONE******/ /*****CALLING DIRECLT USING LIB******/ @@ -1591,7 +1593,7 @@ class MasterController extends AdminController /*****CALLING DIRECLT USING LIB******/ /*****CALLING VIA MAIL HELPER******/ - $res = MailHelper::send_email(['mail' => $to, 'subject' => $subject, 'message' => $mail_content]); + $res = MailHelper::send_email(['mail' => $to, 'subject' => $subject,'common'=>$common ,'message' => $mail_content]); return $this->respond(['status' => 'success','code' => 200,'data' => $res],200); /*****CALLING VIA MAIL HELPER******/ @@ -1623,10 +1625,10 @@ class MasterController extends AdminController ["filePath" => ROOTPATH."public/sample_excel/sample_inception.xls","fileName" => "sample_inception.xls"], ["filePath" => ROOTPATH."public/assets/images/login_bg.jpg","fileName" => "login_bg.jpg"] ]; - - + $common = ['mail_type'=>'test_mail_cli']; $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]); + $res = MailHelper::send_email(['mail' => $email_id, 'subject' => 'Mail Via CLI', 'message' => $message,'attachments' => $attachments,'common'=>$common]); + echo "Inside the master controller"; print_r($res); } diff --git a/app/Helpers/GmailResponseHandler.php b/app/Helpers/GmailResponseHandler.php new file mode 100644 index 00000000..27347b94 --- /dev/null +++ b/app/Helpers/GmailResponseHandler.php @@ -0,0 +1,94 @@ +store_gmail_response_data($params); + $this->gmail_response_logger($params); + + } + catch(Exception $e) + { + + $error = $e->getMessage(); + echo "An Error Occured" . $error; + log_message('error',$error); + + } + } + + + public function store_gmail_response_data($params){ + // foreach ($params as $key => $value){ + // $prepare_data = [ + // $key => $value + // ]; + // } + // $data = [ + // 'email' => isset($params['params']['mail']) ? $params['params']['mail'] : null, + // 'bcc' => isset($params['params']['bcc']) ? json_encode($params['params']['bcc']) : null, + // 'cc' => isset($params['params']['cc']) ? json_encode($params['params']['cc']) : null, + // 'message' => isset($params['params']['message']) ? $params['params']['message'] : null, + // 'attachments' => isset($params['params']['attachments']) ? json_encode($params['params']['attachments']) : null, + // 'client_id' => isset($params['params']['common']['client_id']) ? $params['params']['common']['client_id'] : null, + // 'client_branch_id' => isset($params['params']['common']['client_branch_id']) ? $params['params']['common']['client_branch_id'] : null, + // 'client_policy_id' => isset($params['params']['common']['client_policy_id']) ? $params['params']['common']['client_policy_id'] : null, + // 'employee_policy_id' => isset($params['params']['common']['employee_policy_id']) ? $params['params']['common']['employee_policy_id'] : null, + // 'employee_id' => isset($params['params']['common']['employee_id']) ? $params['params']['common']['employee_id'] : null, + // 'mail_type' => isset($params['params']['common']['mail_type']) ? $params['params']['common']['mail_type'] : null, + // 'gmail_api_status' => isset($params['gmail_api']['status']) ? $params['gmail_api']['status'] : null, + // 'gmail_api_id' => isset($params['gmail_api']['data']['id']) ? $params['gmail_api']['data']['id'] : null + // ]; + // Initialize data array + $data = []; + // print_r($params['params']['common']);die(); + if (isset($params['params']['common'])) { + foreach ($params['params']['common'] as $key => $value) { + $data[$key] = isset($value) ? $value : null; + } + unset($params['params']['common']); + } + if (isset($params['params'])){ + foreach($params['params'] as $key => $value){ + $arr = ['bcc','cc','attachments']; + if(in_array($key,$arr)){ + $data[$key] = isset($value)?json_encode($value):null; + }else{ + $data[$key] = isset($value)?$value:null; + } + } + } + if(isset($params['gmail_api']['status']) && $params['gmail_api']['status'] == 1 ){ + $data['gmail_api_status'] = isset($params['gmail_api']['status']) ? $params['gmail_api']['status'] : null; + $data['gmail_api_id'] = isset($params['gmail_api']['data']['id']) ? $params['gmail_api']['data']['id'] : null; + $data['received_message'] = isset($params['gmail_api']['data']['labelIds']) ? json_encode($params['gmail_api']['data']['labelIds']) : null; + + } + elseif(isset($params['gmail_api']['status']) && $params['gmail_api']['status'] == false ){ + $data['gmail_api_status'] = $params['gmail_api']['status']; + if(isset($params['gmail_api']['data'])){ + $data['received_message'] = json_encode($params['gmail_api']['data']); + } + } + + $gmailModel = new GmailSentHistoryModel(); + $save_status = $gmailModel->insert($data); + + + } + + public function gmail_response_logger($params){ + + } + + +} \ No newline at end of file diff --git a/app/Helpers/JWTToken.php b/app/Helpers/JWTToken.php index 196bdaca..41d76b5c 100755 --- a/app/Helpers/JWTToken.php +++ b/app/Helpers/JWTToken.php @@ -11,7 +11,7 @@ use Firebase\JWT\SignatureInvalidException; // use Psr\Http\Message\RequestInterface; use CodeIgniter\HTTP\RequestInterface; use ReflectionClass; - +use Exception; use App\Models\EmployeeModel; use App\Models\LevelContactModel; diff --git a/app/Helpers/MailHelper.php b/app/Helpers/MailHelper.php index 0bc21c46..78f5983b 100755 --- a/app/Helpers/MailHelper.php +++ b/app/Helpers/MailHelper.php @@ -11,7 +11,6 @@ use PHPMailer\PHPMailer\Exception; use App\Models\JobModel; - class MailHelper { public static function send_email_smtp($params) @@ -94,7 +93,7 @@ class MailHelper $subject = $params['subject']; $message = $params['message']; $attachments = isset($params['attachments']) && count($params['attachments']) ? $params['attachments'] : []; - + $common = isset($params['common'])?$params['common']:''; //check BCC mail if (isset($params['bcc'])) { $bcc = $params['bcc']; @@ -118,26 +117,36 @@ class MailHelper if(isset($params['reply_to']) && !empty($params['reply_to'])){ $reply_to = $params['reply_to']; } + $MailDataHelper = new GmailResponseHandler(); + $res['params'] = $params; try { - $res = $gmailapi->sendMessage($emaill, $subject, $message, 'no-reply@nhanceindia.in', $reply_to, $cc, $bcc,$attachments); - - if($res['status']) + $res['gmail_api'] = $gmailapi->sendMessage($emaill, $subject, $message, 'no-reply@nhanceindia.in', $reply_to, $cc, $bcc,$attachments); + if($res['gmail_api']['status']) { + $response = $res; + // $MailDataHelper->receive_and_distribute_param_to_functions($response); return json_encode(['status' => 'success','code' => 200, 'message'=>('Email Sent Successfully...'.$emaill),'data' => $res,],200); } else { $myLogger->logme('error', "mail sent failed - $emaill"); + $response = $res; + // $MailDataHelper->receive_and_distribute_param_to_functions($response); return json_encode(['status' => 'failed','code' => 404,'message'=>( 'Email Sent Failed...' . $emaill ),'data' => $res ],404); } } catch (Exception $e) { - $msg = $e->getMessage(); + $msg['error'] = $e->getMessage(); + $msg['params'] = $params; $myLogger->logme('error', "mail sent failed - $msg"); + $response = $msg; + // $MailDataHelper->receive_and_distribute_param_to_functions($response); return json_encode(['status' => 'failed','code' => 500,'data' => $msg],500); - } + } + + } diff --git a/app/Models/GmailSentHistoryModel.php b/app/Models/GmailSentHistoryModel.php new file mode 100644 index 00000000..9a0ae8ea --- /dev/null +++ b/app/Models/GmailSentHistoryModel.php @@ -0,0 +1,11 @@ +nul + if not errorlevel 1 ( + echo phpqueue.bat is already running. Exiting. + exit /b + ) +) + +REM Write the current process ID (PID) to the PID file +echo %PROCESS_ID% > "%PID_FILE%" + +REM Main loop +:loop +REM Check if the Job_Queue file exists +if not exist "%JOB_QUEUE_FILE%" ( + echo Job Queue file not found. + exit /b +) + +REM Read the value of Job_Queue from the file +set /p Job_Queue=<%JOB_QUEUE_FILE% + +if "%Job_Queue%"=="1" ( + REM Run PHP job processing + php "%ROOT_DIR%htdocs/nhance/public/index.php" cli/processjob +) else ( + echo No job to process. +) + +REM Sleep for 1 second before the next iteration +timeout /T 1 >nul +goto loop diff --git a/phpqueue.pid b/phpqueue.pid new file mode 100644 index 00000000..db08d2ac --- /dev/null +++ b/phpqueue.pid @@ -0,0 +1 @@ +575 diff --git a/phpqueue.sh b/phpqueue.sh new file mode 100755 index 00000000..f1e7176b --- /dev/null +++ b/phpqueue.sh @@ -0,0 +1,56 @@ +!/bin/bash +while true; do + echo "Running job at $(date)" + /usr/bin/php /opt/lampp/htdocs/nhance/public/index.php cli/processjob + !/bin/bash +!/bin/bash + +# Read the Job_Queue variable from the temporary file +#!/bin/bash + +#!/bin/bash + +#!/bin/bash + +# Define the root directory for the project and PID file path +#!/bin/bash + +# Define paths +# ROOT_DIR=$(dirname "$(realpath "$0")") +# JOB_QUEUE_FILE="$ROOT_DIR/job_queue" +# PID_FILE="$ROOT_DIR/phpqueue.pid" + + +# # Check if the script is already running +# if [[ -f "$PID_FILE" ]] && kill -0 "$(cat $PID_FILE)" 2>/dev/null; then +# echo "phpqueue.sh is already running. Exiting." +# exit 1 +# fi + +# # Write the current process ID (PID) to the PID file +# echo $$ > "$PID_FILE" + +# # Ensure the PID file is removed on script exit +# trap "rm -f $PID_FILE" EXIT + +# # Main loop +# while true; do +# # Check if the Job_Queue file exists +# if [[ ! -f "$JOB_QUEUE_FILE" ]]; then +# echo "Job Queue file not found." +# exit 1 +# fi + +# # Read the value of Job_Queue from the file +# Job_Queue=$(cat "$JOB_QUEUE_FILE") + +# if [[ "$Job_Queue" -eq 1 ]]; then +# /usr/bin/php /opt/lampp/htdocs/nhance/public/index.php cli/processjob +# else +# echo "No job to process." +# fi + +# # Sleep for 1 second before the next iteration +# sleep 1 +# done + diff --git a/phpsetvariable.sh b/phpsetvariable.sh new file mode 100755 index 00000000..69c1b0ac --- /dev/null +++ b/phpsetvariable.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +# Validate input argument +# if [[ "$1" == "1" ]]; then +# echo "1" > /opt/lampp/htdocs/nhance/Job_Queue +# echo "Job Queue variable has been set to: 1" +# elif [[ "$1" == "0" ]]; then +# echo "0" > /opt/lampp/htdocs/nhance/Job_Queue +# echo "Job Queue variable has been set to: 0" +# else +# echo "Invalid argument. Use 1 to enable the queue or 0 to disable it." +# exit 1 +# fi From a552e06adfa71e31ea3ce72b381803a469e9abfb Mon Sep 17 00:00:00 2001 From: Srinivas-Saravanan Date: Fri, 6 Dec 2024 10:47:20 +0530 Subject: [PATCH 3/7] FEAT_GMAIL RESPONSE HELPER ADDED --- Job_Queue.txt | 1 - job_queue | 1 - phpqueue.bat | 42 ------------------------------------------ phpqueue.pid | 1 - phpsetvariable.sh | 13 ------------- 5 files changed, 58 deletions(-) delete mode 100755 Job_Queue.txt delete mode 100755 job_queue delete mode 100644 phpqueue.bat delete mode 100644 phpqueue.pid delete mode 100755 phpsetvariable.sh diff --git a/Job_Queue.txt b/Job_Queue.txt deleted file mode 100755 index 56a6051c..00000000 --- a/Job_Queue.txt +++ /dev/null @@ -1 +0,0 @@ -1 \ No newline at end of file diff --git a/job_queue b/job_queue deleted file mode 100755 index c2270834..00000000 --- a/job_queue +++ /dev/null @@ -1 +0,0 @@ -0 \ No newline at end of file diff --git a/phpqueue.bat b/phpqueue.bat deleted file mode 100644 index 5247ccff..00000000 --- a/phpqueue.bat +++ /dev/null @@ -1,42 +0,0 @@ -@echo off -setlocal enabledelayedexpansion - -REM Get the directory of the current script -set "ROOT_DIR=%~dp0" -set "JOB_QUEUE_FILE=%ROOT_DIR%job_queue" -set "PID_FILE=%ROOT_DIR%phpqueue.pid" - -REM Check if the script is already running -if exist "%PID_FILE%" ( - for /f "tokens=*" %%i in (%PID_FILE%) do set PID=%%i - tasklist /fi "PID eq !PID!" | findstr /i "!PID!" >nul - if not errorlevel 1 ( - echo phpqueue.bat is already running. Exiting. - exit /b - ) -) - -REM Write the current process ID (PID) to the PID file -echo %PROCESS_ID% > "%PID_FILE%" - -REM Main loop -:loop -REM Check if the Job_Queue file exists -if not exist "%JOB_QUEUE_FILE%" ( - echo Job Queue file not found. - exit /b -) - -REM Read the value of Job_Queue from the file -set /p Job_Queue=<%JOB_QUEUE_FILE% - -if "%Job_Queue%"=="1" ( - REM Run PHP job processing - php "%ROOT_DIR%htdocs/nhance/public/index.php" cli/processjob -) else ( - echo No job to process. -) - -REM Sleep for 1 second before the next iteration -timeout /T 1 >nul -goto loop diff --git a/phpqueue.pid b/phpqueue.pid deleted file mode 100644 index db08d2ac..00000000 --- a/phpqueue.pid +++ /dev/null @@ -1 +0,0 @@ -575 diff --git a/phpsetvariable.sh b/phpsetvariable.sh deleted file mode 100755 index 69c1b0ac..00000000 --- a/phpsetvariable.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/bash - -# Validate input argument -# if [[ "$1" == "1" ]]; then -# echo "1" > /opt/lampp/htdocs/nhance/Job_Queue -# echo "Job Queue variable has been set to: 1" -# elif [[ "$1" == "0" ]]; then -# echo "0" > /opt/lampp/htdocs/nhance/Job_Queue -# echo "Job Queue variable has been set to: 0" -# else -# echo "Invalid argument. Use 1 to enable the queue or 0 to disable it." -# exit 1 -# fi From c6f06828e01b475227ef4beb77d13db6be92bf7c Mon Sep 17 00:00:00 2001 From: Srinivas-Saravanan Date: Sat, 7 Dec 2024 14:44:44 +0530 Subject: [PATCH 4/7] FEAT_ECARD SENT STATUS FLAG ADDED --- app/Controllers/ClientController.php | 6 +-- app/Controllers/DashboardController.php | 14 +++++-- app/Controllers/EmployeeController.php | 2 +- app/Controllers/EmployeeServiceController.php | 2 +- app/Helpers/GmailResponseHandler.php | 39 +++++++++++++++++-- app/Helpers/MailHelper.php | 12 +++--- app/Models/EmployeePolicyModel.php | 3 +- 7 files changed, 59 insertions(+), 19 deletions(-) diff --git a/app/Controllers/ClientController.php b/app/Controllers/ClientController.php index efcd633e..6191c995 100755 --- a/app/Controllers/ClientController.php +++ b/app/Controllers/ClientController.php @@ -181,7 +181,7 @@ class ClientController extends AdminController print_rr($attachments); } - public function testingForReviewMail($client_id = 77, $emp_code = 'EMP001-K1', $mail_active = 0) //this function for only tsesting some logics not use for business logic + public function testingForReviewMail($client_id = 77, $emp_code = 'EMP001-K1', $mail_active = 1) //this function for only tsesting some logics not use for business logic { $client_policy_ids = $this->employeeModel @@ -3708,8 +3708,8 @@ class ClientController extends AdminController public function sendextraparam(){ - $employeeRestController = new EmployeeServiceController(); - $employeeRestController->employeesEnrollmentInsert(['file_id' => 683]); + // $employeeRestController = new EmployeeServiceController(); + // $employeeRestController->employeesEnrollmentInsert(['file_id' => 715]); // $dashBoardController = new DashboardController(); // $client_policy_data = $this->clientPolicyModel->getPolicyDetailsForRemainder($client_id=159, $client_branch_id=126); diff --git a/app/Controllers/DashboardController.php b/app/Controllers/DashboardController.php index 1a8c8382..b4843a59 100755 --- a/app/Controllers/DashboardController.php +++ b/app/Controllers/DashboardController.php @@ -417,8 +417,9 @@ class DashboardController extends AdminController // Send the mail notification $mail_result = sendMailNotification::sendMailNotification('member_reminder_mail', $params); + // dd($mail_result); // $this->myLogger->logme('error', 'Mail sent result: ' . json_encode($mail_result)); - $reminder_whole_mail[] = $mail_result; + $reminder_whole_mail[] = $mail_result[0]; } } } else { @@ -483,7 +484,7 @@ class DashboardController extends AdminController // Send the mail notification $mail_result = sendMailNotification::sendMailNotification('member_reminder_mail', $params); // $this->myLogger->logme('error', 'Mail sent result: ' . json_encode($mail_result)); - $reminder_whole_mail[] = $mail_result; + $reminder_whole_mail[] = $mail_result[0]; } } } else { @@ -496,14 +497,14 @@ class DashboardController extends AdminController } // dd($reminder_whole_mail); + // print_rr($reminder_whole_mail); die; // Process and queue bulk emails if (!empty($reminder_whole_mail) && count($reminder_whole_mail) > 0) { $reminder_whole_mail = array_chunk($reminder_whole_mail, 20); - foreach ($reminder_whole_mail as $key => $value) { - $job_details = new Jobs(); + // $job_details = new Jobs(); $r = Jobs::addJob(['job_name' => 'bulk_mail', 'payload' => $value]); } } @@ -517,6 +518,8 @@ class DashboardController extends AdminController public function sendManualReminder($client_id, $client_branch_id) { + $this->myLogger->logme('error','Log Works'); + $this->myLogger->logme('error', "sendManualRemainder called with client_id: {$client_id}, client_branch_id: {$client_branch_id}"); $client_policy_data = $this->clientPolicyModel->getPolicyDetailsForRemainder($client_id, $client_branch_id); @@ -526,6 +529,8 @@ class DashboardController extends AdminController if ($client_policy_data) { $result = $this->sendRemainderMail($client_policy_data); + log_message('error',json_encode($result)); + $this->myLogger->logme('error',$result); $this->myLogger->logme('error', "Manual Remainder Mail sending result: " . ($result ? 'success' : 'failure')); if ($result) { @@ -552,6 +557,7 @@ class DashboardController extends AdminController { return $this->respond(['status' => false, 'code' => 400, 'message' => 'No template found','message2' => 'Failed' ], 200); } + $emp_data = $this->employeePolicyModel->getEmployeePolicyForEcard($policy_id); if(count($emp_data) == 0) diff --git a/app/Controllers/EmployeeController.php b/app/Controllers/EmployeeController.php index 02c01d34..75893afd 100755 --- a/app/Controllers/EmployeeController.php +++ b/app/Controllers/EmployeeController.php @@ -108,7 +108,7 @@ class EmployeeController extends AdminController emp_name : $filterData['emp_name'] ?? null, status : $filterData['status'] ?? [], ); - + log_message('error',json_encode($data['employees'])); // Set getData in $data array with the processed $filterData $data['getData'] = $filterData; } diff --git a/app/Controllers/EmployeeServiceController.php b/app/Controllers/EmployeeServiceController.php index 7297c26c..953d270b 100755 --- a/app/Controllers/EmployeeServiceController.php +++ b/app/Controllers/EmployeeServiceController.php @@ -2095,7 +2095,7 @@ public function getFileMetaDataByFileId($file_id, $status = 'success'){ $params['dataToInsert'] = $value; //holds employee master data $params['notification'] = $notification; $params['client_data'] = $client_details; - + $params['common'] = []; //store email and mail content via helper to send notification $emp_emails[] = sendMailNotification::sendMailNotification('member_welcome_mail', $params); } diff --git a/app/Helpers/GmailResponseHandler.php b/app/Helpers/GmailResponseHandler.php index 27347b94..f2cb07f7 100644 --- a/app/Helpers/GmailResponseHandler.php +++ b/app/Helpers/GmailResponseHandler.php @@ -2,10 +2,19 @@ namespace App\Helpers; +use App\Models\EmployeePolicyModel; use App\Models\GmailSentHistoryModel; use Exception; + class GmailResponseHandler{ + private $myLogger; + + public function __construct() + { + $this->myLogger = \Config\Services::mylogger(); + + } public function receive_and_distribute_param_to_functions($params) @@ -14,6 +23,7 @@ class GmailResponseHandler{ $this->store_gmail_response_data($params); $this->gmail_response_logger($params); + $this->client_id_flag_setter($params); } catch(Exception $e) @@ -81,13 +91,34 @@ class GmailResponseHandler{ } $gmailModel = new GmailSentHistoryModel(); - $save_status = $gmailModel->insert($data); - - + $save_status = $gmailModel->insert($data); } - public function gmail_response_logger($params){ + public function gmail_response_logger($params) + { + $this->myLogger->logme('error',json_encode($params)); + } + public function client_id_flag_setter($params) + { + try{ + if (isset($params['params']['common']['mail_type'])){ + if($params['params']['common']['mail_type'] == 'member_ecard_mail'){ + $employeePolicyModel = new EmployeePolicyModel(); + $update_status = $employeePolicyModel->where('id',$params['params']['common']['employee_policy_id'])->set('ecard_sent_status',1)->update(); + if($update_status){ + $this->myLogger->logme('error',"ecard_sent_status updated for ".$params['params']['common']['employee_policy_id']); + }else{ + $this->myLogger->logme('error','ecard_sent_status failed to update'); + } + } + + } + } + catch(Exception $e){ + $error = $e->getMessage(); + $this->myLogger->logme('error','An Error Occured - '.$error); + } } diff --git a/app/Helpers/MailHelper.php b/app/Helpers/MailHelper.php index 78f5983b..6116bc0c 100755 --- a/app/Helpers/MailHelper.php +++ b/app/Helpers/MailHelper.php @@ -126,14 +126,14 @@ class MailHelper if($res['gmail_api']['status']) { $response = $res; - // $MailDataHelper->receive_and_distribute_param_to_functions($response); + $MailDataHelper->receive_and_distribute_param_to_functions($response); return json_encode(['status' => 'success','code' => 200, 'message'=>('Email Sent Successfully...'.$emaill),'data' => $res,],200); } else { $myLogger->logme('error', "mail sent failed - $emaill"); $response = $res; - // $MailDataHelper->receive_and_distribute_param_to_functions($response); + $MailDataHelper->receive_and_distribute_param_to_functions($response); return json_encode(['status' => 'failed','code' => 404,'message'=>( 'Email Sent Failed...' . $emaill ),'data' => $res ],404); } @@ -142,7 +142,7 @@ class MailHelper $msg['params'] = $params; $myLogger->logme('error', "mail sent failed - $msg"); $response = $msg; - // $MailDataHelper->receive_and_distribute_param_to_functions($response); + $MailDataHelper->receive_and_distribute_param_to_functions($response); return json_encode(['status' => 'failed','code' => 500,'data' => $msg],500); } @@ -152,7 +152,7 @@ class MailHelper public static function bulk_mail(array $mails = []) { - // print_r();die; + // print_r($mails);die; $model = new JobModel(); $start = microtime(true); $runtime= 0; @@ -165,7 +165,9 @@ class MailHelper return json_encode(['status' => 'success','code' => 200, 'message'=>'Email Sent Successfully...'],200); } catch (\Throwable $th) { - return json_encode(['status' => 'failed','code' => 500],500); + $error = $th->getMessage(); + log_message('error',$error); + return json_encode(['status' => 'failed','code' => 500,'error'=>$error],500); } } diff --git a/app/Models/EmployeePolicyModel.php b/app/Models/EmployeePolicyModel.php index 2d285bb6..6708da05 100755 --- a/app/Models/EmployeePolicyModel.php +++ b/app/Models/EmployeePolicyModel.php @@ -33,6 +33,7 @@ class EmployeePolicyModel extends Model "rand_string", "is_active", "claim_status", + 'ecard_sent_status' ]; // Callbacks @@ -125,7 +126,6 @@ class EmployeePolicyModel extends Model ->join('client_branch', 'emp.client_branch_id = client_branch.id') //cm - client master ->orderBy('emp.emp_code', 'ASC') ->orderBy('employee_polices.employee_id', 'ASC'); - // Conditionally add where clauses if ($client_id != 0 && !empty($client_id)) { $result->where('emp.client_id', $client_id); @@ -194,6 +194,7 @@ class EmployeePolicyModel extends Model $result->where('employee_polices.is_active', 1) ->where('employee_polices.status', 'active') ->where('employee_polices.tpa_id is not null') + ->where('employee_polices.ecard_sent_status',0) ->where('emp.relationship','Self'); return $result->findAll(); From 8a319604f7e23d6f72257e9ca89b52ffda8ded90 Mon Sep 17 00:00:00 2001 From: velz Date: Mon, 9 Dec 2024 09:15:04 +0530 Subject: [PATCH 5/7] FIX_DATE_FORMAT_NEW_FUNC --- app/Controllers/EmployeeServiceController.php | 4 +- app/Helpers/excel_util_helper.php | 29 ++++--- app/Helpers/utility_helper.php | 87 ++++++++++++++++++- 3 files changed, 106 insertions(+), 14 deletions(-) diff --git a/app/Controllers/EmployeeServiceController.php b/app/Controllers/EmployeeServiceController.php index 7297c26c..b743247d 100755 --- a/app/Controllers/EmployeeServiceController.php +++ b/app/Controllers/EmployeeServiceController.php @@ -1980,7 +1980,9 @@ public function getFileMetaDataByFileId($file_id, $status = 'success'){ $policy_details = $this->clientPolicyModel->where('id', $file['policy_id'])->first(); // dd($policy_details); - + + //get policy slab rates + $slab_details = $this->policiesModel->getPolicySlabRatesForEmpOnboard($file['policy_id'],$file['client_id']); foreach ($excel_data as $key => $row) { $is_row_empty = check_row_is_empty_or_null($row); diff --git a/app/Helpers/excel_util_helper.php b/app/Helpers/excel_util_helper.php index 9a27ab9b..76cf51a3 100755 --- a/app/Helpers/excel_util_helper.php +++ b/app/Helpers/excel_util_helper.php @@ -1209,7 +1209,7 @@ if (!function_exists('premium_calculation_manager')) $employee_received_si = $default_si == null ? $emp_data['policy_details']['basic_cover_si'] : $default_si; foreach ($temp_slab_rates as $skey => $slab_value) { - if($slab_value['si'] == $employee_received_si && $slab_value['unit'] == $emp_data['unit'] && (($slab_value['premium_type'] == 1 && ( strtolower($emp_data['relationship']) == 'self' || $emp_data['temp']['acting_self'] ) ) || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null) )) + if($slab_value['si'] == $employee_received_si && $slab_value['unit'] == $emp_data['unit'] && (($slab_value['premium_type'] == 1 && ( strtolower($emp_data['relationship']) == 'self' || $emp_data['temp']['acting_self'] ) ) || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null || $slab_value['premium_type'] == 3 ) )) { $emp_data['policy_details']['basic_cover_si'] = $slab_value['si']; $emp_data['policy_details']['date_coverage'] = (isset($emp_data['policy_details']['date_coverage']) ? $emp_data['policy_details']['date_coverage'] : $policy_terms['policy_start_date']); @@ -1232,7 +1232,7 @@ if (!function_exists('premium_calculation_manager')) foreach ($temp_slab_rates as $skey => $slab_value) { $age = calculate_days_bw_dates(from_date: $emp_data['dob'])->y; - if($slab_value['si'] == $employee_received_si && $slab_value['unit'] == $emp_data['unit'] && ($slab_value['age_from'] <= $age && $slab_value['age_to'] >= $age) && (($slab_value['premium_type'] == 1 && ( strtolower($emp_data['relationship']) == 'self' || $emp_data['temp']['acting_self'] ) ) || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null) )) + if($slab_value['si'] == $employee_received_si && $slab_value['unit'] == $emp_data['unit'] && ($slab_value['age_from'] <= $age && $slab_value['age_to'] >= $age) && (($slab_value['premium_type'] == 1 && ( strtolower($emp_data['relationship']) == 'self' || $emp_data['temp']['acting_self'] ) ) || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null || $slab_value['premium_type'] == 3) )) { // dd($slab_value); $emp_data['policy_details']['basic_cover_si'] = $slab_value['si']; @@ -1253,7 +1253,7 @@ if (!function_exists('premium_calculation_manager')) foreach ($temp_slab_rates as $skey => $slab_value) { $age = calculate_days_bw_dates(from_date: $emp_data['dob'])->y; - if($slab_value['si'] == $employee_received_si && $slab_value['unit'] == $emp_data['unit'] && ($slab_value['age_from'] <= $age && $slab_value['age_to'] >= $age) && (($slab_value['premium_type'] == 1 && ( strtolower($emp_data['relationship']) == 'self' || $emp_data['temp']['acting_self'] ) ) || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null) )) + if($slab_value['si'] == $employee_received_si && $slab_value['unit'] == $emp_data['unit'] && ($slab_value['age_from'] <= $age && $slab_value['age_to'] >= $age) && (($slab_value['premium_type'] == 1 && ( strtolower($emp_data['relationship']) == 'self' || $emp_data['temp']['acting_self'] ) ) || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null || $slab_value['premium_type'] == 3 ) )) { $emp_data['policy_details']['basic_cover_si'] = $slab_value['si']; $emp_data['policy_details']['date_coverage'] = (isset($emp_data['policy_details']['date_coverage']) ? $emp_data['policy_details']['date_coverage'] : $policy_terms['policy_start_date']); @@ -1273,7 +1273,7 @@ if (!function_exists('premium_calculation_manager')) foreach ($temp_slab_rates as $skey => $slab_value) { $age = calculate_days_bw_dates(from_date: $emp_data['dob'])->y; - if($slab_value['si'] == $employee_received_si && $slab_value['unit'] == $emp_data['unit'] && ($slab_value['age_from'] <= $age && $slab_value['age_to'] >= $age) && (($slab_value['premium_type'] == 1 && ( strtolower($emp_data['relationship']) == 'self' || $emp_data['temp']['acting_self'] ) ) || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null) )) + if($slab_value['si'] == $employee_received_si && $slab_value['unit'] == $emp_data['unit'] && ($slab_value['age_from'] <= $age && $slab_value['age_to'] >= $age) && (($slab_value['premium_type'] == 1 && ( strtolower($emp_data['relationship']) == 'self' || $emp_data['temp']['acting_self'] ) ) || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null || $slab_value['premium_type'] == 3) )) { // echo $emp_data['name']; $emp_data['policy_details']['basic_cover_si'] = $slab_value['si']; @@ -1295,7 +1295,7 @@ if (!function_exists('premium_calculation_manager')) foreach ($temp_slab_rates as $skey => $slab_value) { $age = calculate_days_bw_dates(from_date: $emp_data['dob'])->y; - if($slab_value['si'] == $employee_received_si && $slab_value['unit'] == $emp_data['unit'] && ($slab_value['age_from'] <= $age && $slab_value['age_to'] >= $age) && (($slab_value['premium_type'] == 1 && ( strtolower($emp_data['relationship']) == 'self' || $emp_data['temp']['acting_self'] ) ) || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null) )) + if($slab_value['si'] == $employee_received_si && $slab_value['unit'] == $emp_data['unit'] && ($slab_value['age_from'] <= $age && $slab_value['age_to'] >= $age) && (($slab_value['premium_type'] == 1 && ( strtolower($emp_data['relationship']) == 'self' || $emp_data['temp']['acting_self'] ) ) || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null || $slab_value['premium_type'] == 3) )) { $emp_data['policy_details']['basic_cover_si'] = $slab_value['si']; $emp_data['policy_details']['date_coverage'] = (isset($emp_data['policy_details']['date_coverage']) ? $emp_data['policy_details']['date_coverage'] : $policy_terms['policy_start_date']); @@ -1317,7 +1317,7 @@ if (!function_exists('premium_calculation_manager')) foreach ($temp_slab_rates as $skey => $slab_value) { - if($slab_value['grade'] == $employee_received_band && $slab_value['unit'] == $emp_data['unit'] && $slab_value['si'] == $employee_received_si && (($slab_value['premium_type'] == 1 && ( strtolower($emp_data['relationship']) == 'self' || $emp_data['temp']['acting_self'] ) ) || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null) )) + if($slab_value['grade'] == $employee_received_band && $slab_value['unit'] == $emp_data['unit'] && $slab_value['si'] == $employee_received_si && (($slab_value['premium_type'] == 1 && ( strtolower($emp_data['relationship']) == 'self' || $emp_data['temp']['acting_self'] ) ) || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null || $slab_value['premium_type'] == 3) )) { // $emp_data['policy_details']['basic_cover_si'] = $slab_value['si']; $emp_data['policy_details']['basic_cover_si'] = $slab_value['si']; @@ -1339,7 +1339,7 @@ if (!function_exists('premium_calculation_manager')) foreach ($temp_slab_rates as $skey => $slab_value) { - if($slab_value['si'] == $employee_received_si && $slab_value['unit'] == $emp_data['unit'] && (($slab_value['premium_type'] == 1 && ( strtolower($emp_data['relationship']) == 'self' || $emp_data['temp']['acting_self'] )) || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null) )) + if($slab_value['si'] == $employee_received_si && $slab_value['unit'] == $emp_data['unit'] && (($slab_value['premium_type'] == 1 && ( strtolower($emp_data['relationship']) == 'self' || $emp_data['temp']['acting_self'] )) || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null || $slab_value['premium_type'] == 3) )) { $emp_data['policy_details']['basic_cover_si'] = $slab_value['si']; $emp_data['policy_details']['date_coverage'] = (isset($emp_data['policy_details']['date_coverage']) ? $emp_data['policy_details']['date_coverage'] : $policy_terms['policy_start_date']); @@ -1366,7 +1366,7 @@ if (!function_exists('premium_calculation_manager')) if( $slab_value['si'] == $employee_received_si && $slab_value['unit'] == $emp_data['unit'] && ($slab_value['age_from'] <= $max_age && $slab_value['age_to'] >= $max_age) && (($slab_value['premium_type'] == 1 && - ( strtolower($emp_data['relationship']) == 'self' || $emp_data['temp']['acting_self'] )) || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null) ) ) + ( strtolower($emp_data['relationship']) == 'self' || $emp_data['temp']['acting_self'] )) || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null || $slab_value['premium_type'] == 3) ) ) { $emp_data['policy_details']['basic_cover_si'] = $employee_received_si; $emp_data['policy_details']['date_coverage'] = isset($emp_data['policy_details']['date_coverage']) ? $emp_data['policy_details']['date_coverage'] : $policy_terms['policy_start_date']; @@ -1391,7 +1391,7 @@ if (!function_exists('premium_calculation_manager')) { if($slab_value['si'] == $employee_received_si && $slab_value['grade'] == $employee_received_band && $slab_value['unit'] == $emp_data['unit'] && (($slab_value['premium_type'] == 1 && - ( strtolower($emp_data['relationship']) == 'self' || $emp_data['temp']['acting_self'] )) || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null) )) + ( strtolower($emp_data['relationship']) == 'self' || $emp_data['temp']['acting_self'] )) || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null || $slab_value['premium_type'] == 3) )) { //calculate premium based on count // echo $emp_data['name']; @@ -1420,7 +1420,7 @@ if (!function_exists('premium_calculation_manager')) $emp_data['policy_details']['basic_cover_si'] = null; foreach ($temp_slab_rates as $skey => $slab_value) { - if( $slab_value['si'] == $employee_received_si && $slab_value['unit'] == $emp_data['unit'] && ((($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null) && $slab_value['relationship'] == $employee_relationship) || ($slab_value['premium_type'] == 1 && ( strtolower($emp_data['relationship']) == 'self' || $emp_data['temp']['acting_self'] ) )) ) + if( $slab_value['si'] == $employee_received_si && $slab_value['unit'] == $emp_data['unit'] && ((($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null || $slab_value['premium_type'] == 3) && $slab_value['relationship'] == $employee_relationship) || ($slab_value['premium_type'] == 1 && ( strtolower($emp_data['relationship']) == 'self' || $emp_data['temp']['acting_self'] ) )) ) { $emp_data['policy_details']['basic_cover_si'] = $employee_received_si; @@ -1445,7 +1445,7 @@ if (!function_exists('premium_calculation_manager')) $age = calculate_days_bw_dates(from_date: $emp_data['dob'])->y; foreach ($temp_slab_rates as $skey => $slab_value) { - if( $slab_value['si'] == $employee_received_si && $slab_value['unit'] == $emp_data['unit'] && ($slab_value['age_from'] <= $age && $slab_value['age_to'] >= $age) && ((($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null) && $slab_value['relationship'] == $employee_relationship) || ($slab_value['premium_type'] == 1 && ( strtolower($emp_data['relationship']) == 'self' || $emp_data['temp']['acting_self'] ) )) ) + if( $slab_value['si'] == $employee_received_si && $slab_value['unit'] == $emp_data['unit'] && ($slab_value['age_from'] <= $age && $slab_value['age_to'] >= $age) && ((($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null || $slab_value['premium_type'] == 3) && $slab_value['relationship'] == $employee_relationship) || ($slab_value['premium_type'] == 1 && ( strtolower($emp_data['relationship']) == 'self' || $emp_data['temp']['acting_self'] ) )) ) { $emp_data['policy_details']['basic_cover_si'] = $employee_received_si; @@ -1466,6 +1466,13 @@ if (!function_exists('premium_calculation_manager')) default: $myLogger->logme('error',($emp_data['emp_code'].'-'.$emp_data['name'].' - grid type not found')); } + + //this if condition for premium calculated & premium type 3 (familiy floater but premium calculated every individual implemented later) then remove si amount only for dependents (not self) + if($is_match_found && strtolower($emp_data['relationship']) != 'self' && $temp_slab_rates[0]['premium_type'] == 3) + { + //set dependent si to 0 + $emp_data['policy_details']['basic_cover_si'] = 0; + } if(!$is_match_found) { $age = calculate_days_bw_dates(from_date: $emp_data['dob'])->y; diff --git a/app/Helpers/utility_helper.php b/app/Helpers/utility_helper.php index fe345717..ca339500 100755 --- a/app/Helpers/utility_helper.php +++ b/app/Helpers/utility_helper.php @@ -24,9 +24,9 @@ if (!function_exists('generate_uuid')) { } } -if (!function_exists('change_date_format')) { +if (!function_exists('change_date_format2')) { - function change_date_format($data, $source_format, $output_format) + function change_date_format2($data, $source_format, $output_format) { $data = trim($data); // echo $data, $source_format, $output_format;return true; @@ -501,3 +501,86 @@ if (!function_exists('isJsonString')) { return (json_last_error() === JSON_ERROR_NONE); // Check if the last JSON error is "no error" } } + +if (!function_exists('isValidDate')) { + function isValidDate($date, $format) { + $parsed_date = DateTime::createFromFormat($format, $date); + return $parsed_date && $parsed_date->format($format) === $date; + } +} + + +if (!function_exists('change_date_format')) +{ + + function change_date_format($date_str, $source_format = null, $output_format = 'Y-m-d') { + + $date_str = trim($date_str); + // Allowed date formats + $allowed_formats = [ + // Day Month Year (clear unambiguous formats) + 'd M Y', // 01 Dec 2024 + 'd-M-Y', // 01-Dec-2024 + 'd/M/Y', // 01/Dec/2024 + 'd.M.Y', // 01.Dec.2024 + 'd,M,Y', // 01,Dec,2024 + + // Month Day Year (clear unambiguous formats) + 'M d Y', // Dec 01 2024 + 'M-d-Y', // Dec-01-2024 + 'M/d/Y', // Dec/01/2024 + 'M.d.Y', // Dec.01.2024 + 'M,d,Y', // Dec,01,2024 + + // Year Month Day (clear unambiguous formats) + 'Y M d', // 2024 Dec 01 + 'Y-M-d', // 2024-Dec-01 + 'Y/M/d', // 2024/Dec/01 + 'Y.M.d', // 2024.Dec.01 + 'Y,M,d', // 2024,Dec,01 + + // Year Numeric Month Numeric Day + 'Y-m-d', // 2024-12-01 + 'Y/m/d', // 2024/12/01 + 'Y.m.d', // 2024.12.01 + 'Y,m,d', // 2024,12,01 + ]; + + try { + // Case 1: Source and Output formats are provided + if ($source_format !== null && $output_format !== null) { + $date = DateTime::createFromFormat($source_format, $date_str); + if (!$date) { + throw new Exception("Invalid date string for source format: $source_format"); + } + return $date->format($output_format); + } + + // Case 2: Source format is provided, Output format is null + if ($source_format !== null && $output_format === null) { + $date = DateTime::createFromFormat($source_format, $date_str); + if (!$date) { + throw new Exception("Invalid date string for source format: $source_format"); + } + return $date->format('Y-m-d'); // MySQL default format + } + + // Case 3: Source format is null, auto-detect format + if ($source_format === null) { + foreach ($allowed_formats as $format) { + if (isValidDate($date_str, $format)) { + $date = DateTime::createFromFormat($format, $date_str); + return $date->format($output_format); // Default is MySQL format + } + } + // If no format matches, throw an exception + $allowed_placeholders = implode(', ', $allowed_formats); + throw new Exception("Invalid date string format. Allowed formats: $allowed_placeholders"); + } + } catch (Exception $e) { + return "Error: " . $e->getMessage(); + } + + return null; + } +} From fbefc7468ec4e961af74a6babbf3656db50bf2d0 Mon Sep 17 00:00:00 2001 From: "venkatesh.r" Date: Mon, 9 Dec 2024 09:27:38 +0530 Subject: [PATCH 6/7] CHANGES_REMINDER_MAIL_AND_POLICY_GRID_AND_OTHERS : RV --- app/Config/Routes.php | 1 + app/Controllers/ClientController.php | 4 +- app/Controllers/DashboardController.php | 206 ++++++++++++++++-------- app/Controllers/EmployeeController.php | 13 +- app/Helpers/sendMailNotification.php | 79 ++------- app/Models/ClientPolicyModel.php | 17 +- app/Views/client_policy.php | 18 ++- app/Views/enrollment_list.php | 87 ++++++++-- app/Views/policy_grid.php | 71 +++++--- 9 files changed, 307 insertions(+), 189 deletions(-) diff --git a/app/Config/Routes.php b/app/Config/Routes.php index aba39a78..9becf234 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -26,6 +26,7 @@ $routes->get("updateRemainderDate", "ClientController::updateRemainderDate"); $routes->get("sendCroneRemainderMail", "DashboardController::sendCroneRemainderMail"); $routes->get("sendextraparam", "ClientController::sendextraparam"); // $routes->post("iAgreeForAddOn", "EmployeeRestController::iAgreeForAddOn"); +// $routes->get("sendCroneRemainderMail", "DashboardController::sendCroneRemainderMail"); $routes->post("add_advertise_image", "AppContentManagementController::add_advertise_image"); $routes->get("add_image_index", "AppContentManagementController::add_image_index"); diff --git a/app/Controllers/ClientController.php b/app/Controllers/ClientController.php index efcd633e..64fad6e8 100755 --- a/app/Controllers/ClientController.php +++ b/app/Controllers/ClientController.php @@ -2442,11 +2442,11 @@ class ClientController extends AdminController $termsData = json_decode($termsData['policy_terms']); - if (isset($termsData->sum_insured) && empty($termsData->sum_insured)) { + if (isset($termsData->sum_insured) && $termsData->sum_insured == "" && $termsData->sum_insured == null) { return $this->respond(['status' => false, 'code' => 200, 'message' => 'The Policy terms Sum Insured field is empty', 'data' => $record], 200); } - if (isset($termsData->SumInsured) && empty($termsData->sum_insured)) { + if (isset($termsData->sumInsured2) && $termsData->sumInsured2 == "" && $termsData->sumInsured2 == null) { return $this->respond(['status' => false, 'code' => 200, 'message' => 'The Policy terms Sum Insured field is empty'], 200); } diff --git a/app/Controllers/DashboardController.php b/app/Controllers/DashboardController.php index 1a8c8382..12c43199 100755 --- a/app/Controllers/DashboardController.php +++ b/app/Controllers/DashboardController.php @@ -365,41 +365,81 @@ class DashboardController extends AdminController foreach ($client_policy_data as $client_policy) { - if (empty($send_mail_for_manual_or_crone)) { + // Fetch client data + $client_data = $this->clientModel->find($client_policy['client_id']); - // Fetch client data - $client_data = $this->clientModel->find($client_policy['client_id']); + // Fetch notification settings + $notification_data = $this->notificationModel + ->where('client_id', $client_policy['client_id']) + ->where('template_name', 'member_reminder_mail') + ->first(); - // Fetch notification settings - $notification_data = $this->notificationModel - ->where('client_id', $client_policy['client_id']) - ->where('template_name', 'member_reminder_mail') - ->first(); + if ($notification_data && $notification_data['enabled'] == 1 && !empty($notification_data['mail_content'])) { - // $this->myLogger->logme('error', 'Notification data fetched: ' . json_encode($notification_data)); + //manaual + if (empty($send_mail_for_manual_or_crone)) { - // Check if notification should be sent - if ($notification_data && $notification_data['enabled'] == 1 && !empty($notification_data['mail_content'])) { + // Check if notification should be sent $this->myLogger->logme('error', 'Notification should be sent for client policy ID: ' . $client_policy['id']); - // Fetch all employees related to the client policy - $employees = $this->employeePolicyModel - ->select('employees.*, employee_polices.id as emp_policy_id') - ->join('employees', 'employee_polices.employee_id = employees.id', 'left') - ->where('employee_polices.client_policy_id', $client_policy['id']) - ->where('employees.emp_status', 'draft') - ->where('employees.is_active', 1) - ->where('employee_polices.status', 'draft') - ->where('employee_polices.is_active', 1) - ->where('employees.relationship', 'Self') - ->findAll(); + $employees = []; + if (in_array($client_policy['policy_type_id'], [2, 4]) || ($client_policy['policy_type_id'] == 3 && $client_policy['is_addon'] == 1)) { - // dd($employees); + // Fetch all employees related to the client policy + $employees = $this->employeePolicyModel + ->select('employees.*, employee_polices.id as emp_policy_id') + ->join('employees', 'employee_polices.employee_id = employees.id', 'left') + ->where('employee_polices.client_policy_id', $client_policy['id']) + ->where('employees.is_active', 1) + ->where('employee_polices.is_active', 1) + ->where('employees.emp_status', 'draft') + ->where('employee_polices.status', 'draft') + ->where('employees.relationship', 'Self') + ->where("employees.email_corporate IS NOT NULL AND employees.email_corporate != ''") + ->findAll(); + + // dd($employees, 'first'); + + } else if (($client_policy['policy_type_id'] == 3 && $client_policy['is_addon'] == 3) || $client_policy['policy_type_id'] == 5) { + + $empDependentData = $this->employeePolicyModel + ->select('employees.*, employee_polices.id as emp_policy_id') + ->join('employees', 'employee_polices.employee_id = employees.id', 'left') + ->where('employee_polices.client_policy_id', $client_policy['id']) + ->where('employees.is_active', 1) + ->where('employee_polices.is_active', 1) + ->where('employees.emp_status', 'draft') + ->where('employee_polices.status', 'draft') + ->where('employees.relationship !=', 'Self') + ->findAll(); + + $empCodes = array_column($empDependentData, 'emp_code'); + + // dd($empDependentData, $empCodes,'second'); + + if (!empty($empCodes)) { + + $empSelfData = $this->employeePolicyModel + ->select('employees.*, employee_polices.id as emp_policy_id') + ->join('employees', 'employee_polices.employee_id = employees.id', 'left') + ->whereIn('employees.emp_code', $empCodes) + ->where('employees.is_active', 1) + ->where('employee_polices.is_active', 1) + ->where('employees.relationship', 'Self') + ->where("employees.email_corporate IS NOT NULL AND employees.email_corporate != ''") + ->findAll(); + + $employees = array_merge($employees, $empSelfData); + } + } + + // dd($employees); // Process each employee - foreach ($employees as $employee) { + if (!empty($employees) && count($employees) > 0) { + + foreach ($employees as $employee) { - if ($employee['emp_status'] == 'draft' && $employee['relationship'] == 'Self') { $this->myLogger->logme('error', 'Employee status and relationship check passed for employee ID: ' . $employee['id']); // Mail params @@ -407,8 +447,8 @@ class DashboardController extends AdminController $params['client_data'] = $client_data; $params['notification_data'] = $notification_data; $params['common'] = [ - 'client_id' => $client_policy['client_id'], - 'client_branch_id' => $client_policy['client_branch_id'], + 'client_id' => $client_policy['client_id'], + 'client_branch_id' => $client_policy['client_branch_id'], 'client_policy_id' => $client_policy['id'], 'employee_policy_id' => $employee['emp_policy_id'], 'employee_id' => $employee['id'], @@ -421,50 +461,76 @@ class DashboardController extends AdminController $reminder_whole_mail[] = $mail_result; } } - } else { - $this->myLogger->logme('error', 'Notification was not sent for Client Policy ID: ' . $client_policy['id']); - $this->myLogger->logme('error', 'Notification setup not found or not enabled'); - } - } else { - $currentDate = date('d'); - $remainder_dates = explode(",", $client_policy['reminder_date']); + } else { // crone - foreach ($remainder_dates as $date) { + if (!empty($client_policy['reminder_date'])) { - if ($currentDate == $date) { + $currentDate = date('d'); + $remainder_dates = explode(",", $client_policy['reminder_date']); - $client_data = $this->clientModel->find($client_policy['client_id']); + foreach ($remainder_dates as $date) { - // Fetch notification settings - $notification_data = $this->notificationModel - ->where('client_id', $client_policy['client_id']) - ->where('template_name', 'member_reminder_mail') - ->first(); + if ($currentDate == $date) { - // Check if notification should be sent - if ($notification_data && $notification_data['enabled'] == 1 && !empty($notification_data['mail_content'])) { + $this->myLogger->logme('error', 'Notification should be sent for client policy ID: ' . $client_policy['id']); - // echo '4'; + // Fetch all employees related to the client policy + $employees = []; + if (in_array($client_policy['policy_type_id'], [2, 4]) || ($client_policy['policy_type_id'] == 3 && $client_policy['is_addon'] == 1)) { - $this->myLogger->logme('error', 'Notification should be sent for client policy ID: ' . $client_policy['id']); + $employees = $this->employeePolicyModel + ->select('employees.*, employee_polices.id as emp_policy_id') + ->join('employees', 'employee_polices.employee_id = employees.id', 'left') + ->where('employee_polices.client_policy_id', $client_policy['id']) + ->where('employees.is_active', 1) + ->where('employee_polices.is_active', 1) + ->where('employees.emp_status', 'draft') + ->where('employee_polices.status', 'draft') + ->where('employees.relationship', 'Self') + ->where("employees.email_corporate IS NOT NULL AND employees.email_corporate != ''") + ->findAll(); - // Fetch all employees related to the client policy - $employees = $this->employeePolicyModel - ->select('employees.*, employee_polices.id as emp_policy_id') - ->join('employees', 'employee_polices.employee_id = employees.id', 'left') - ->where('employee_polices.client_policy_id', $client_policy['id']) - ->where('employees.emp_status', 'draft') - ->where('employees.is_active', 1) - ->where('employee_polices.status', 'draft') - ->where('employee_polices.is_active', 1) - ->where('employees.relationship', 'Self') - ->findAll(); + // dd($employees, 'first'); - // Process each employee - foreach ($employees as $employee) { + } else if (($client_policy['policy_type_id'] == 3 && $client_policy['is_addon'] == 3) || $client_policy['policy_type_id'] == 5) { + + $empDependentData = $this->employeePolicyModel + ->select('employees.*, employee_polices.id as emp_policy_id') + ->join('employees', 'employee_polices.employee_id = employees.id', 'left') + ->where('employee_polices.client_policy_id', $client_policy['id']) + ->where('employees.is_active', 1) + ->where('employee_polices.is_active', 1) + ->where('employees.emp_status', 'draft') + ->where('employee_polices.status', 'draft') + ->where('employees.relationship !=', 'Self') + ->findAll(); + + $empCodes = array_column($empDependentData, 'emp_code'); + + // dd($empDependentData, $empCodes,'second'); + + if (!empty($empCodes)) { + + $empSelfData = $this->employeePolicyModel + ->select('employees.*, employee_polices.id as emp_policy_id') + ->join('employees', 'employee_polices.employee_id = employees.id', 'left') + ->whereIn('employees.emp_code', $empCodes) + ->where('employees.is_active', 1) + ->where('employee_polices.is_active', 1) + ->where('employees.relationship', 'Self') + ->where("employees.email_corporate IS NOT NULL AND employees.email_corporate != ''") + ->findAll(); + + $employees = array_merge($employees, $empSelfData); + } + } + + // dd($employees); + + // Process each employee + foreach ($employees as $employee) { - if ($employee['emp_status'] == 'draft' && $employee['relationship'] == 'Self') { $this->myLogger->logme('error', 'Employee status and relationship check passed for employee ID: ' . $employee['id']); // Mail params @@ -472,8 +538,8 @@ class DashboardController extends AdminController $params['client_data'] = $client_data; $params['notification_data'] = $notification_data; $params['common'] = [ - 'client_id' => $client_policy['client_id'], - 'client_branch_id' => $client_policy['client_branch_id'], + 'client_id' => $client_policy['client_id'], + 'client_branch_id' => $client_policy['client_branch_id'], 'client_policy_id' => $client_policy['id'], 'employee_policy_id' => $employee['emp_policy_id'], 'employee_id' => $employee['id'], @@ -485,13 +551,19 @@ class DashboardController extends AdminController // $this->myLogger->logme('error', 'Mail sent result: ' . json_encode($mail_result)); $reminder_whole_mail[] = $mail_result; } + } - } else { - // echo '5'; - $this->myLogger->logme('error', 'Notification not sent for client policy ID: ' . $client_policy['id']); } + + } else { + $this->myLogger->logme('error', "SEND REMAINDER CRONE --- Remainder date is empty()"); } } + + } else { + + $this->myLogger->logme('error', 'Notification setup not found or not enabled'); + $this->myLogger->logme('error', 'Notification was not sent for this Client ID: ' . $client_policy['client_id']); } } @@ -515,11 +587,11 @@ class DashboardController extends AdminController } } - public function sendManualReminder($client_id, $client_branch_id) + public function sendManualReminder($client_id, $client_branch_id, $client_policy_id = null) { $this->myLogger->logme('error', "sendManualRemainder called with client_id: {$client_id}, client_branch_id: {$client_branch_id}"); - $client_policy_data = $this->clientPolicyModel->getPolicyDetailsForRemainder($client_id, $client_branch_id); + $client_policy_data = $this->clientPolicyModel->getPolicyDetailsForRemainder($client_id, $client_branch_id, $client_policy_id); // print_r($client_policy_data); die; // print_r($this->clientPolicyModel->getLastQuery()); die; // $this->myLogger->logme('error', "Policy details fetched: " . json_encode($client_policy_data)); diff --git a/app/Controllers/EmployeeController.php b/app/Controllers/EmployeeController.php index 02c01d34..36650609 100755 --- a/app/Controllers/EmployeeController.php +++ b/app/Controllers/EmployeeController.php @@ -711,16 +711,25 @@ class EmployeeController extends AdminController public function enrollmentClientList() { $data = []; - $client_list = $this->clientModel->findAll(); - $branch_list = $this->clientBranchModel->findAll(); + $client_list = $this->clientModel->where('clients.is_active', 1)->findAll(); + $branch_list = $this->clientBranchModel->where('client_branch.is_active', 1)->findAll(); + $policy_list = $this->clientPolicyModel + ->select('client_policy.*, policy_type.policy_type') + ->join('policy_type', 'client_policy.policy_type_id = policy_type.id') + ->where('client_policy.is_active', 1) + ->findAll(); + $data['client_list'] = $client_list; $data['branch_list'] = $branch_list; + $data['policy_list'] = $policy_list; // Get session data if available $data['selected_client_id'] = session()->get('client_id'); $data['selected_branch_id'] = session()->get('branch_id'); $data['selected_type'] = session()->get('type'); + // dd($data); + $this->myLogger->logme('error', 'list called'); return $this->loadLayout('enrollment_list', $data); diff --git a/app/Helpers/sendMailNotification.php b/app/Helpers/sendMailNotification.php index e6b6edf9..48402825 100755 --- a/app/Helpers/sendMailNotification.php +++ b/app/Helpers/sendMailNotification.php @@ -81,76 +81,18 @@ class sendMailNotification $mail_content = str_replace("[[nhance_logo]]", "Nhance Logo", $mail_content); $mail_content = str_replace("[[client_logo]]", "Client Logo", $mail_content); $mail_content = str_replace("[[app_link]]", "Review Details", $mail_content); - if ($emp_data && (isset($notification_data) && $notification_data['enabled'] == 1)) { - if(isset($emp_data['relationship'])){ - if ($emp_data['relationship'] == 'Self') { - if(count($emp_data) > 0){ - $mail =''; - if ($emp_data['relationship'] == 'Self') { - $employee_name =$emp_data['name']; - $employee_mobile_no =$emp_data['mobile']; - $mail_content = str_replace("[[member_name]]", $employee_name, $mail_content); - $mail_content = str_replace("[[member_mobile]]", $employee_mobile_no, $mail_content); - $mail = $emp_data['email_corporate']; - } - } - }else{ - $mail =''; - } - - }else{ - $employee_name =$emp_data['name']; - $employee_mobile_no =$emp_data['mobile']; - $mail_content = str_replace("[[member_name]]", $employee_name, $mail_content); - $mail_content = str_replace("[[member_mobile]]", $employee_mobile_no, $mail_content); - $mail = $emp_data['email_corporate']; - } - - if (isset($mail) && !empty($mail)) { - $wholeData[] = ['mail' => $mail, 'subject' => $subject,'message'=> $mail_content, 'bcc'=> $client_data['common_mails'], 'reply_to' => $client_data['reply_to'], 'common' => $common]; - } + - }else{ - - foreach ($emp_data as $key => $value) { - if ($value['relationship'] != 'Self') { - $emp_data = $EmployeeModel->where('client_id', $client_data['id'])->where('emp_code', $value['emp_code'])->where('is_active',1)->findAll(); - if(count($emp_data) > 1){ - $mail =''; - foreach ($emp_data as $key => $values) { - if ($value['relationship'] == 'Self') { - $employee_name =$values['name']; - $employee_mobile_no =$values['mobile']; - $mail_content = str_replace("[[member_name]]", $employee_name, $mail_content); - $mail_content = str_replace("[[member_mobile]]", $employee_mobile_no, $mail_content); - $mail = $values['email_corporate']; - } - } - }else{ - $mail =''; - } - }else{ - $employee_name =$value['name']; - $employee_mobile_no =$value['mobile']; - $mail_content = str_replace("[[member_name]]", $employee_name, $mail_content); - $mail_content = str_replace("[[member_mobile]]", $employee_mobile_no, $mail_content); - $mail = $value['email_corporate']; - } - if (isset($mail) && !empty($mail)) { - $wholeData[] = ['mail' => $mail, 'subject' => $subject,'message'=> $mail_content, 'bcc'=> $client_data['common_mails'], 'reply_to' => $client_data['reply_to'], 'common' => $common]; - } - } - } + $employee_name =$emp_data['name']; + $employee_mobile_no =$emp_data['mobile']; + $mail_content = str_replace("[[member_name]]", $employee_name, $mail_content); + $mail_content = str_replace("[[member_mobile]]", $employee_mobile_no, $mail_content); + $mail = $emp_data['email_corporate']; - if (count($wholeData) < 1) { - $wholeData = []; - } + $wholeData = ['mail' => $mail, 'subject' => $subject,'message'=> $mail_content, 'bcc'=> $client_data['common_mails'], 'reply_to' => $client_data['reply_to'], 'common' => $common]; return $wholeData; - // }else{ - // return "false"; - // } } else if($action == 'member_ecard_mail'){ @@ -269,6 +211,8 @@ class sendMailNotification } //end of getting policy premium data + // dd($policy_premium_data); + $policy_name = $inner_item['policy_name']; if ($inner_item['relationship'] == 'Self') { @@ -282,11 +226,12 @@ class sendMailNotification $premium = ''; $gst_forself = ''; - if(checkFamilyFloaters($policy_premium_data, $client_policy_data, $inner_item)){ + // if(checkFamilyFloaters($policy_premium_data, $client_policy_data, $inner_item)){ + $si = '₹ ' .format_indian_number($inner_item['basic_cover_si']); $premium = '₹ ' .format_indian_number(round($inner_item['premium'])); $gst_forself = '₹ ' .format_indian_number(round($inner_item['gst'])); - } + // } $temp_data .= ''; $temp_data .= '' . $inner_item['name'] . ($inner_item['relationship'] == 'Self' ? ' (' . $inner_item['emp_code'] . ')' : '') . ''; diff --git a/app/Models/ClientPolicyModel.php b/app/Models/ClientPolicyModel.php index aac8cd01..7ed17d10 100755 --- a/app/Models/ClientPolicyModel.php +++ b/app/Models/ClientPolicyModel.php @@ -390,21 +390,26 @@ public function getCliendDataForExcelFileName($client_policy_id){ } //for this using in CRONE JOB -public function getPolicyDetailsForRemainder($client_id = null, $branch_id = null) +public function getPolicyDetailsForRemainder($client_id = null, $branch_id = null, $policy_id = null) { $builder = $this->table('client_policy') - ->where('client_policy.is_addon', 1) - ->where('client_policy.open_for_enrollment', 1) - ->where('client_policy.inception_type', 2) ->where('client_policy.is_active', 1) ->where('client_policy.policy_status', 1) - ->whereIn('client_policy.policy_type_id', [2, 3]); - + // ->where('client_policy.is_addon', 1) + // ->where('client_policy.inception_type', 2) + ->where('client_policy.open_for_enrollment', 1); + if ($client_id && $branch_id) { $builder->where('client_policy.client_id', $client_id) ->where('client_policy.client_branch_id', $branch_id); } + if(empty($policy_id)){ + $builder->whereIn('client_policy.policy_type_id', [2, 3, 4, 5]); + }else{ + $builder->where('client_policy.id', $policy_id); + } + return $builder->get()->getResultArray(); } diff --git a/app/Views/client_policy.php b/app/Views/client_policy.php index fd4a01a5..7a3b3911 100755 --- a/app/Views/client_policy.php +++ b/app/Views/client_policy.php @@ -175,14 +175,14 @@ -
+
@@ -827,11 +827,11 @@ } // Member Modify Data Enable or Disable - if (res.data.is_member_modify_allowed == 1) { - $('#is_member_modify_allowed').prop('checked', true); - } else { - $('#is_member_modify_allowed').prop('checked', false); - } + // if (res.data.is_member_modify_allowed == 1) { + // $('#is_member_modify_allowed').prop('checked', true); + // } else { + // $('#is_member_modify_allowed').prop('checked', false); + // } // if (res.data.is_addon != '1' && res.data.is_addon != '0') { @@ -1199,7 +1199,9 @@ } else if (input) { // console.log( 'input type step 2', typeof input); // Handle the case where input is a string - number = parseFloat(input.replace(/,/g, ''), 10); + // number = parseFloat(input.replace(/,/g, ''), 10); + number = parseFloat(String(input).replace(/,/g, ''), 10); + } else { // Handle the case where input is undefined or null number = NaN; // or handle as needed diff --git a/app/Views/enrollment_list.php b/app/Views/enrollment_list.php index edbdd473..d88a4619 100755 --- a/app/Views/enrollment_list.php +++ b/app/Views/enrollment_list.php @@ -17,7 +17,7 @@ /* background-color: #eb7a76; */ background-color: darkgrey; /* padding-bottom: 1px; */ - padding-top: 10px; + /* padding-top: 10px; */ } #tickets-table_filter { @@ -59,24 +59,31 @@
-
+
+
+ +
+
- +
-
+ -
+
- +
@@ -84,7 +91,7 @@
-
@@ -234,6 +241,7 @@
\ No newline at end of file diff --git a/app/Views/policy_gmc_terms.php b/app/Views/policy_gmc_terms.php index b7e6c9a8..ff2b1925 100755 --- a/app/Views/policy_gmc_terms.php +++ b/app/Views/policy_gmc_terms.php @@ -107,7 +107,7 @@
-
+
@@ -116,9 +116,9 @@
-
+
-
+
@@ -126,16 +126,16 @@
-
+
Yes No
-
+
-
+
@@ -143,12 +143,16 @@ + + + + @@ -162,6 +166,8 @@ + +
Min Age:
Max Age:
Is Payable by employee:
Spouse:
Min Age:
Max Age:
Is Payable by employee:
Children:
Min Age:
Max Age:
Is Payable by employee:
@@ -192,6 +198,8 @@
Elders Count:
Min Age:
Max Age:
+ Is Payable by employee: + @@ -202,7 +210,7 @@
-
+
@@ -406,7 +414,7 @@