From 4fa7537a636a232fc1b99a1bcac6b07763a56a55 Mon Sep 17 00:00:00 2001 From: velz Date: Thu, 28 Nov 2024 18:04:02 +0530 Subject: [PATCH] FIX_ENROL_INSERT_EMPTY_ROW&INS_STMT_NULL_HANDLING --- app/Controllers/EmployeeServiceController.php | 245 +++++++++--------- .../PolicyTransactionController.php | 13 +- 2 files changed, 135 insertions(+), 123 deletions(-) diff --git a/app/Controllers/EmployeeServiceController.php b/app/Controllers/EmployeeServiceController.php index 6756e470..577232c2 100755 --- a/app/Controllers/EmployeeServiceController.php +++ b/app/Controllers/EmployeeServiceController.php @@ -1981,131 +1981,136 @@ public function employeesEnrollmentInsert($params) foreach ($excel_data as $key => $row) { - // dd($key.'-'.count($excel_data)); - $value = []; - $policy_data = []; - $temp_unit = ''; - if(empty($row[12])) + $is_row_empty = check_row_is_empty_or_null($row); + if(!$is_row_empty) { - $temp_unit = $existing_units[0]; - } - - $value['emp_code'] = $row[1]; - $value['name'] = $row[2]; - $value['doj'] = (!empty($row[3]) ? convert_string_to_date($row[3],'Y-m-d'): null); - $value['gender'] = $row[4]; - $value['relationship'] = ucfirst(trim($row[5])); - $value['dob'] = convert_string_to_date($row[6],'Y-m-d'); - $value['email_corporate'] = $row[7]; - $value['mobile'] = $row[8]; - $value['band'] = $row[10]; - $value['basic_pay'] = $row[11]; - $value['unit'] = $temp_unit; - $value['family_floater_key'] = null; - $value['client_id'] = $file['client_id']; - $value['client_branch_id'] = $file['client_branch_id']; - $value['file_id'] = $file_id; + $value = []; + $policy_data = []; + $temp_unit = ''; + if(empty($row[12])) + { + $temp_unit = $existing_units[0]; + } + + $value['emp_code'] = $row[1]; + $value['name'] = $row[2]; + $value['doj'] = (!empty($row[3]) ? convert_string_to_date($row[3],'Y-m-d'): null); + $value['gender'] = $row[4]; + $value['relationship'] = ucfirst(trim($row[5])); + $value['dob'] = convert_string_to_date($row[6],'Y-m-d'); + $value['email_corporate'] = $row[7]; + $value['mobile'] = $row[8]; + $value['band'] = $row[10]; + $value['basic_pay'] = $row[11]; + $value['unit'] = $temp_unit; + $value['family_floater_key'] = null; + $value['client_id'] = $file['client_id']; + $value['client_branch_id'] = $file['client_branch_id']; + $value['file_id'] = $file_id; - $value['temp']['emp_id'] = null; // dummy value for using exisitng funciton in model - if (strtolower(trim($value['relationship'])) === 'mother' || strtolower(trim($value['relationship'])) === 'father') { - $relation = 'parent'; - } else if(strtolower(trim($value['relationship'])) === 'son' || strtolower(trim($value['relationship'])) === 'daughter'){ - $relation = 'child'; - }else if(strtolower(trim($value['relationship'])) === 'father in law' || strtolower(trim($value['relationship'])) === 'mother in law'){ - $relation = 'parent_in_law'; - }else if(strtolower(trim($value['relationship'])) === 'spouse'){ - $relation = 'spouse'; - }else{ - $relation = 'self'; - } - $value['family_floater_key'] = $relation; - - $policy_data['basic_cover_si'] = $row[9]; - $policy_data['date_coverage'] = $row[13]; - $policy_data['client_policy_id'] = $file['policy_id']; - - $employee = $this->employeeModel->checkExistingEmployee($value,$file['client_branch_id']); - unset($value['temp']); - //save employee table - // dd($employee['id']); - if($employee !== null) - { - $value['updated_by'] = $file['created_by']; - $value['id'] = $employee['id']; - $value['emp_status'] = 'draft'; - - $log_message = 'Enrollment Update Employee - '.$employee['name'].'('.$employee['emp_code'].') with PK '.$employee['id']; - } - else - { - $value['emp_status'] = 'draft'; - $value['created_by'] = $file['created_by']; - $log_message = 'Enrollment Insert Employee- '.$value['name'] .'('.$value['emp_code'] .') with PK '; - } - - $this->employeeModel->save($value); - if (isset($value['id'])) - { $emp_id = $value['id']; } - else { $emp_id = $this->employeeModel->getInsertID(); - $log_message .= $emp_id; - } - - // $emp_id = $this->employeeModel->getInsertID(); - // if($emp_id != 0){ $log_message .= $emp_id; } - // else{ $emp_id = $employee['id']; } - - $this->myLogger->logme('error',$log_message); - - //save policy table - $employee_policy = $this->employeePolicyModel->checkExistingEmpPolicy(['employee_id' => $emp_id,'client_policy_id' => $file['policy_id']]); - if(count($employee_policy)) - { - $policy_data['updated_by'] = $file['created_by']; - $policy_data['id'] = $employee_policy[0]['id']; - $policy_data['status'] = 'draft'; - - $log_message = 'Update Employee Policy for '. $value['name'].'('. $value['emp_code'].') with PK- ' . $employee_policy[0]['id'] .' client policy ID '.$employee_policy[0]['client_policy_id'].' with SI '.$policy_data['basic_cover_si']; - // echo 'insert policy'; - } - else - { - $policy_data['employee_id'] = $emp_id; - $policy_data['client_policy_id'] = $file['policy_id']; - $policy_data['created_by'] = $file['created_by']; - $policy_data['status'] = 'draft'; - $log_message = 'Insert Employee Policy for '. $value['name'].'('. $value['emp_code'].') - client policy id -'. $file['policy_id'].' - with SI '.$policy_data['basic_cover_si']; - // echo 'update policy'; - } - - $this->employeePolicyModel->save($policy_data); - $emp_policy_id = $this->employeePolicyModel->getInsertID(); - $this->myLogger->logme('error',$log_message); - - //save email of self for send mail later - if (isset($notification) && $notification['enabled'] == 1 && $notification['mail_content'] != '') - { - if(strtolower($value['relationship']) == 'self' && $value['email_corporate'] != "") - { - $params['dataToInsert'] = $value; //holds employee master data - $params['notification'] = $notification; - $params['client_data'] = $client_details; - - //store email and mail content via helper to send notification - $emp_emails[] = sendMailNotification::sendMailNotification('member_welcome_mail', $params); - // Kint::dump($emp_emails); - // Kint::dump($key.'-'.count($excel_data)); - // if mail count is 20 send bulk mail and reset emp_emails variable - if (count($emp_emails) == 20 || $key == count($excel_data) ) { - $job_details = new Jobs(); - $r = Jobs::addJob(['job_name' => 'bulk_mail','payload' => $emp_emails]); - // echo 'Mail triggered'; - $emp_emails = []; - } - + $value['temp']['emp_id'] = null; // dummy value for using exisitng funciton in model + if (strtolower(trim($value['relationship'])) === 'mother' || strtolower(trim($value['relationship'])) === 'father') { + $relation = 'parent'; + } else if(strtolower(trim($value['relationship'])) === 'son' || strtolower(trim($value['relationship'])) === 'daughter'){ + $relation = 'child'; + }else if(strtolower(trim($value['relationship'])) === 'father in law' || strtolower(trim($value['relationship'])) === 'mother in law'){ + $relation = 'parent_in_law'; + }else if(strtolower(trim($value['relationship'])) === 'spouse'){ + $relation = 'spouse'; + }else{ + $relation = 'self'; } - } + $value['family_floater_key'] = $relation; + + $policy_data['basic_cover_si'] = $row[9]; + $policy_data['date_coverage'] = $row[13]; + $policy_data['client_policy_id'] = $file['policy_id']; + + $employee = $this->employeeModel->checkExistingEmployee($value,$file['client_branch_id']); + unset($value['temp']); + //save employee table + // dd($employee['id']); + if($employee !== null) + { + $value['updated_by'] = $file['created_by']; + $value['id'] = $employee['id']; + $value['emp_status'] = 'draft'; + + $log_message = 'Enrollment Update Employee - '.$employee['name'].'('.$employee['emp_code'].') with PK '.$employee['id']; + } + else + { + $value['emp_status'] = 'draft'; + $value['created_by'] = $file['created_by']; + $log_message = 'Enrollment Insert Employee- '.$value['name'] .'('.$value['emp_code'] .') with PK '; + } + + $this->employeeModel->save($value); + if (isset($value['id'])) + { $emp_id = $value['id']; } + else { $emp_id = $this->employeeModel->getInsertID(); + $log_message .= $emp_id; + } + + // $emp_id = $this->employeeModel->getInsertID(); + // if($emp_id != 0){ $log_message .= $emp_id; } + // else{ $emp_id = $employee['id']; } + + $this->myLogger->logme('error',$log_message); + + //save policy table + $employee_policy = $this->employeePolicyModel->checkExistingEmpPolicy(['employee_id' => $emp_id,'client_policy_id' => $file['policy_id']]); + if(count($employee_policy)) + { + $policy_data['updated_by'] = $file['created_by']; + $policy_data['id'] = $employee_policy[0]['id']; + $policy_data['status'] = 'draft'; + + $log_message = 'Update Employee Policy for '. $value['name'].'('. $value['emp_code'].') with PK- ' . $employee_policy[0]['id'] .' client policy ID '.$employee_policy[0]['client_policy_id'].' with SI '.$policy_data['basic_cover_si']; + // echo 'insert policy'; + } + else + { + $policy_data['employee_id'] = $emp_id; + $policy_data['client_policy_id'] = $file['policy_id']; + $policy_data['created_by'] = $file['created_by']; + $policy_data['status'] = 'draft'; + $log_message = 'Insert Employee Policy for '. $value['name'].'('. $value['emp_code'].') - client policy id -'. $file['policy_id'].' - with SI '.$policy_data['basic_cover_si']; + // echo 'update policy'; + } + + $this->employeePolicyModel->save($policy_data); + $emp_policy_id = $this->employeePolicyModel->getInsertID(); + $this->myLogger->logme('error',$log_message); + + //save email of self for send mail later + if (isset($notification) && $notification['enabled'] == 1 && $notification['mail_content'] != '') + { + if(strtolower($value['relationship']) == 'self' && $value['email_corporate'] != "") + { + $params['dataToInsert'] = $value; //holds employee master data + $params['notification'] = $notification; + $params['client_data'] = $client_details; + + //store email and mail content via helper to send notification + $emp_emails[] = sendMailNotification::sendMailNotification('member_welcome_mail', $params); + // Kint::dump($emp_emails); + // Kint::dump($key.'-'.count($excel_data)); + // if mail count is 20 send bulk mail and reset emp_emails variable + if (count($emp_emails) == 20 || $key == count($excel_data) ) { + $job_details = new Jobs(); + $r = Jobs::addJob(['job_name' => 'bulk_mail','payload' => $emp_emails]); + // echo 'Mail triggered'; + $emp_emails = []; + } + + } + } + }// endof if row is empty check } //end of for loop + + $this->fileModel->where('id', $file_id)->set(['status' => 'success','reason' => ''])->update(); $this->myLogger->logme("error",'{file_id} uploaded success',['file_id' => $file_id]); diff --git a/app/Controllers/PolicyTransactionController.php b/app/Controllers/PolicyTransactionController.php index 1c5526c6..f5f1a5b5 100644 --- a/app/Controllers/PolicyTransactionController.php +++ b/app/Controllers/PolicyTransactionController.php @@ -1730,11 +1730,11 @@ class PolicyTransactionController extends BaseController foreach ($excel_data as $excel_key => $excel_row) { $is_row_empty = check_row_is_empty_or_null($excel_row); - if($is_row_empty) + if(!$is_row_empty) { - continue; + break; } - + $is_source_found = 0; $policy_start_date = preg_replace('/^\p{Z}+|\p{Z}+$/u', '', $excel_row[4]);//policy_start_date from excel $policy_end_date = preg_replace('/^\p{Z}+|\p{Z}+$/u', '', $excel_row[5]);//policy_end_date from excel @@ -1773,6 +1773,7 @@ class PolicyTransactionController extends BaseController public function updateInsurerStatement($params) { + helper('excel_util_helper'); //get file info $file_id = $params['file_id']; $file = $this->insurerStatements->find($file_id); @@ -1826,6 +1827,12 @@ class PolicyTransactionController extends BaseController $data_to_update = []; foreach ($excel_data as $excel_key => $excel_row) { + $is_row_empty = check_row_is_empty_or_null($excel_row); + if(!$is_row_empty) + { + break; + } + $is_source_found = 0; $policy_start_date = preg_replace('/^\p{Z}+|\p{Z}+$/u', '', $excel_row[4]);//policy_start_date from excel $policy_end_date = preg_replace('/^\p{Z}+|\p{Z}+$/u', '', $excel_row[5]);//policy_end_date from excel