diff --git a/app/Controllers/EmployeeServiceController.php b/app/Controllers/EmployeeServiceController.php index e48dbc76..1eb7322c 100755 --- a/app/Controllers/EmployeeServiceController.php +++ b/app/Controllers/EmployeeServiceController.php @@ -1984,30 +1984,33 @@ 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') { @@ -2106,10 +2109,97 @@ public function employeesEnrollmentInsert($params) // } } - } + $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 + // for bulk mail queue job push if (!empty($emp_emails) && count($emp_emails) > 0) { @@ -2121,7 +2211,6 @@ public function employeesEnrollmentInsert($params) } } - $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 452aa207..e2e70696 100644 --- a/app/Controllers/PolicyTransactionController.php +++ b/app/Controllers/PolicyTransactionController.php @@ -1750,11 +1750,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 @@ -1793,6 +1793,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); @@ -1846,6 +1847,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