diff --git a/app/Config/Routes.php b/app/Config/Routes.php index f7426af0..a6472417 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -21,6 +21,7 @@ $routes->get("view", "EmployeeController::viewECard/$1"); // $routes->get("exportQCRandRFQ", "LeadsController::exportQCRandRFQ"); $routes->get("smapletest", "ClientController::smapletest"); $routes->get("testMailAttachments", "ClientController::testMailAttachments"); +$routes->get("updatePolicyTermsKey", "ClientController::updatePolicyTermsKey"); $routes->post("add_advertise_image", "AppContentManagementController::add_advertise_image"); $routes->get("add_image_index", "AppContentManagementController::add_image_index"); @@ -314,6 +315,7 @@ $routes->group("/util", ["filter" => "authMVC"], function ($routes) { $routes->get('log_list', 'EmployeeController::listLogs'); $routes->get('view_log/(:any)', 'EmployeeController::viewLog/$1'); $routes->get('download_log/(:any)', 'EmployeeController::downloadLog/$1'); + $routes->post('checkDuplicateTableFieldValue', 'ClientController::checkDuplicateTableFieldValue'); }); $routes->group("policy_tranction", ["filter" => "authMVC"], function ($routes) { @@ -323,6 +325,7 @@ $routes->group("policy_tranction", ["filter" => "authMVC"], function ($routes) { $routes->post("create", "PolicyTransactionController::createInceptionPolicy"); $routes->get("list/(:any)", "PolicyTransactionController::getInceptionDataForEdit/$1"); $routes->get("remove/(:any)", "PolicyTransactionController::removeCDMaster/$1"); + $routes->get("removePolicyTransaction/(:any)", "PolicyTransactionController::removePolicyTransaction/$1"); }); $routes->group("endorsement", ["filter" => "authMVC"], function ($routes) { diff --git a/app/Controllers/ClientController.php b/app/Controllers/ClientController.php index 7da74a72..7b8e9cf8 100755 --- a/app/Controllers/ClientController.php +++ b/app/Controllers/ClientController.php @@ -118,6 +118,23 @@ class ClientController extends AdminController $this->leadsModel = new LeadsModel(); } + public function checkDuplicateTableFieldValue() + { + $table = $this->request->getPost('table'); + $field = $this->request->getPost('field'); + $value = $this->request->getPost('value'); + + // Load the database if not already loaded + $db = db_connect(); + + // Perform the query + $builder = $db->table($table); + $isDuplicate = $builder->where($field, $value)->countAllResults() > 0; + + // Return the result + return $this->response->setJSON(['isDuplicate' => $isDuplicate]); + } + public function smapletest() { $headers = [ @@ -3562,4 +3579,84 @@ class ClientController extends AdminController dd($result); } + public function updatePolicyTermsKey() + { + + $data = $this->clientPolicyModel + ->where("policy_terms IS NOT NULL AND policy_terms <> ''") + ->where('policy_type_id', 2) + ->where('is_active', 1) + ->findAll(); + + for ($i = 0; $i < count($data); $i++) { + + if (isset($data[$i]['policy_terms']) && !empty($data[$i]['policy_terms'])) { + $policyTerms = json_decode($data[$i]['policy_terms'], true); + } else { + continue; + } + + // Set default value of copayzonewisecopay to "empty" + $ans = isset($policyTerms['copayzonewisecopay']) ? $policyTerms['copayzonewisecopay'] : 'empty'; + + // Initialize an empty array for the ordered policy terms + $orderedPolicyTerms = []; + + // Add copayzonewisecopay and copayzonewisecopaydata if they exist_ + if (isset($policyTerms['copayzonewisecopay'])) { + + if(!isset($policyTerms['co_pay_details'])){ + + $co_pay_details_value = ""; + if (strtolower($ans) == "nil" || $ans == 0) { + $policyTerms['copayzonewisecopay'] = 0; + $co_pay_details_value = ""; + } elseif ($ans != 'empty' && $ans !== 'Nil' && $ans !== null && $ans != '' && $ans != 0) { + $policyTerms['copayzonewisecopay'] = 1; + $co_pay_details_value = $ans; + } + + $co_pay_index = array_search('copayzonewisecopay', array_keys($policyTerms)); + $orderedPolicyTerms[] = [ + "key" => "co_pay_details", + "value" => $co_pay_details_value, + "position" => $co_pay_index + 1, + ]; + + unset($policyTerms['optionalparentalcopay']); + + } + } + + // Add ailmentcapping and ailmentcappingdata if they exist_ + if (isset($policyTerms['ailmentcapping'])) { + if(!isset($policyTerms['ailment_capping_details'])){ + $aliment_index = array_search('ailmentcapping', array_keys($policyTerms)); + $orderedPolicyTerms[] = [ + "key" => "ailment_capping_details", + "value" => "", + "position" => $aliment_index + 2, + ]; + } + } + + foreach ($orderedPolicyTerms as $term) { + $position = $term['position']; + $key = $term['key']; + $value = $term['value']; // Insert the key-value pair at the specified index + $policyTerms = array_merge( + array_slice($policyTerms, 0, $position, true), + [$key => $value], + array_slice($policyTerms, $position, null, true) + ); + } + + // Re-encode the ordered policy terms + $updatedPolicyTerms = json_encode($policyTerms); + + // dd($orderedPolicyTerms, $updatedPolicyTerms); + $this->clientPolicyModel->update($data[$i]['id'], ['policy_terms' => $updatedPolicyTerms]); + } + } + } diff --git a/app/Controllers/EmployeeController.php b/app/Controllers/EmployeeController.php index c308d65f..9afb44b2 100755 --- a/app/Controllers/EmployeeController.php +++ b/app/Controllers/EmployeeController.php @@ -734,11 +734,16 @@ class EmployeeController extends AdminController employees.emp_status, auth_history.user_type') ->join('employees', $client_id .'= employees.client_id AND ' . $branch_id . '= employees.client_branch_id', 'left') ->join('auth_history', 'employees.id = auth_history.user_id AND "employee" = auth_history.user_type', 'left') + ->where('employees.is_active', 1) + ->where('employees.emp_status !=', 'truncated') + ->groupBy('employees.id') ->findAll(); $groupedData = []; $employeeId = ''; + foreach ($results as $row) { + if($employeeId != $row['employee_id']){ $employeeId = $row['employee_id']; }else{ @@ -751,7 +756,8 @@ class EmployeeController extends AdminController $employeeUserType = $row['user_type']; - if ($employeeId !== null && $employeeRelationship == 'Self') { + // if ($employeeId !== null && $employeeRelationship == 'Self') { + if ($employeeId !== null) { // Append employee info to the branch's employees list $groupedData[] = [ 'employee_id' => $employeeId, diff --git a/app/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php index 0684f727..9453a767 100755 --- a/app/Controllers/EmployeeRestController.php +++ b/app/Controllers/EmployeeRestController.php @@ -695,6 +695,7 @@ class EmployeeRestController extends AdminController $decodedPayload = json_decode(base64_decode(explode('.', $token)[1]), true); // get the employee id from token $employee_id = $decodedPayload['id']; + // $employee_id = 1; $client_policy = $this->clientPolicyModel->where('id', $policy_id)->where('client_id', $client_id)->where('client_branch_id', $client_branch_id)->first(); if ($client_policy) { $policy = $this->policesModel->where('id', $client_policy['policy_id'])->first(); @@ -875,7 +876,10 @@ class EmployeeRestController extends AdminController $basic_cover_si[]= $basic_cover_si_value; } } + $count = 0; + $wholeData=[];// Initialize an empty array to store employee email. + for ($a=0; $a 0) { - $job_details = new Jobs(); - $r = Jobs::addJob(['job_name' => 'bulk_mail','payload' => $wholeData]); - $wholeData = []; - $count = 0; - } - } + + // if($count == 20 || $a == count($dataToInsert)-1){ + // if (count($wholeData) > 0) { + // $job_details = new Jobs(); + // $r = Jobs::addJob(['job_name' => 'bulk_mail','payload' => $wholeData]); + // $wholeData = []; + // $count = 0; + // } + // } // if ($dataToInsert[$a]['email_corporate'] != null || $dataToInsert[$a]['email_corporate'] != '' && $dataToInsert[$a]['relationship'] == 'Self') { } } + + // for bulk mail queue job push + if (!empty($wholeData) && count($wholeData) > 0) { + + $wholeData = array_chunk($wholeData, 20); + + foreach ($wholeData as $key => $value) { + $job_details = new Jobs(); + $r = Jobs::addJob(['job_name' => 'bulk_mail', 'payload' => $value]); + } + } + $this->fileModel->where('id', $file_id)->set(['status' => 'success','reason' => '','error_data' => ''])->update(); return $this->respond(['status' => 'success', 'code' => 200, 'message' => "Success" ], 200); }else{ @@ -2502,7 +2519,7 @@ class EmployeeRestController extends AdminController public function storeFireBase() { - // try { + try { $json = $this->request->getJSON(); $firebase_token = $json->firebase_token; $mobile = $json->mobile; @@ -2548,39 +2565,39 @@ class EmployeeRestController extends AdminController } else { return $this->respond(['status' => 'failed', 'code' => 404, 'message' => 'Employee not found'], 404); } - // } catch (\Throwable $th) { - // log_message('error', 'An error occurred: ' . $th->getMessage()); - // return $this->respond(['status' => 'failed', 'code' => 500, 'message' => 'An error occurred', 'error' => $th->getMessage()], 500); - // } - } - - - - - - public function sendPushNotification() - { - $deviceToken = 'cMVKESh8QzqIl8nh_yqbcl:APA91bHKm87Sh1goVJNKZtctV4etgLMQboI0eyDVn3MH1yf9cO-2RtQRlFnKLdataOxosoxm7a4JvATKjfI1_Bids46mGw5m8zesp90mR4odCbD_cJtGmBeMYt4hssSY0YtAht1emK_H'; - $title = 'Nhance'; - $body = 'All your policy enrolled successfully ..!'; - - // Initialize Firebase with the service account - $firebase = (new Factory) - ->withServiceAccount(APPPATH . 'Config/google-services.json') - ->createMessaging(); - - $notification = Notification::create($title, $body); - $message = CloudMessage::withTarget('token', $deviceToken) - ->withNotification($notification); - - try { - $firebase->send($message); - return $this->response->setJSON(['status' => 'success']); - } catch (MessagingException $e) { - //return $this->response->setJSON(['status' => 'error', 'message' => $e->getMessage()]); - log_message('error', $e->getMessage()); + } catch (\Throwable $th) { + log_message('error', 'An error occurred: ' . $th->getMessage()); + return $this->respond(['status' => 'failed', 'code' => 500, 'message' => 'An error occurred', 'error' => $th->getMessage()], 500); } } + + + + + + // public function sendPushNotification() + // { + // $deviceToken = 'cMVKESh8QzqIl8nh_yqbcl:APA91bHKm87Sh1goVJNKZtctV4etgLMQboI0eyDVn3MH1yf9cO-2RtQRlFnKLdataOxosoxm7a4JvATKjfI1_Bids46mGw5m8zesp90mR4odCbD_cJtGmBeMYt4hssSY0YtAht1emK_H'; + // $title = 'Nhance'; + // $body = 'All your policy enrolled successfully ..!'; + + // // Initialize Firebase with the service account + // $firebase = (new Factory) + // ->withServiceAccount(APPPATH . 'Config/google-services.json') + // ->createMessaging(); + + // $notification = Notification::create($title, $body); + // $message = CloudMessage::withTarget('token', $deviceToken) + // ->withNotification($notification); + + // try { + // $firebase->send($message); + // return $this->response->setJSON(['status' => 'success']); + // } catch (MessagingException $e) { + // //return $this->response->setJSON(['status' => 'error', 'message' => $e->getMessage()]); + // log_message('error', $e->getMessage()); + // } + // } diff --git a/app/Controllers/EmployeeServiceController.php b/app/Controllers/EmployeeServiceController.php index 577232c2..1eb7322c 100755 --- a/app/Controllers/EmployeeServiceController.php +++ b/app/Controllers/EmployeeServiceController.php @@ -1979,6 +1979,9 @@ public function employeesEnrollmentInsert($params) // dd($notification); $client_details = $this->clientModel->where('id', $file['client_id'])->first(); + + $emp_emails = []; // Initialize an empty array to store employee email. + foreach ($excel_data as $key => $row) { $is_row_empty = check_row_is_empty_or_null($row); @@ -2008,17 +2011,103 @@ public function employeesEnrollmentInsert($params) $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['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['family_floater_key'] = $relation; @@ -2109,7 +2198,18 @@ public function employeesEnrollmentInsert($params) }// endof if row is empty check } //end of for loop - + + + // for bulk mail queue job push + if (!empty($emp_emails) && count($emp_emails) > 0) { + + $emp_emails = array_chunk($emp_emails, 20); + + foreach ($emp_emails as $key => $value) { + $job_details = new Jobs(); + $r = Jobs::addJob(['job_name' => 'bulk_mail', 'payload' => $value]); + } + } $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 f5f1a5b5..e2e70696 100644 --- a/app/Controllers/PolicyTransactionController.php +++ b/app/Controllers/PolicyTransactionController.php @@ -690,6 +690,7 @@ class PolicyTransactionController extends BaseController ->join('client_policy', 'policy_transaction.client_policy_id = client_policy.id', 'left') ->join('policy_type', 'client_policy.policy_type_id = policy_type.id', 'left') ->where('policy_transaction.id', $id) + ->where('policy_transaction.is_active', 1) ->first(); // $data['policy_issue_date'] = (isset($data['policy_issue_date']) && $data['policy_issue_date'] !== null && $data['policy_issue_date'] !== '') @@ -810,6 +811,21 @@ class PolicyTransactionController extends BaseController } + public function removePolicyTransaction($id) + { + if ($id) { + + $data['is_active'] = 0; + $this->policyTransactionModel->where('id', $id)->set($data)->update(); + $this->PTCOShareDetailsModel->where('pt_id', $id)->set($data)->update(); + return $this->respond(['status' => true, 'code' => 200, 'message' => 'Policy Transaction removed successfully'], 200); + + } else { + + return $this->respond(['status' => false, 'code' => 404, 'message' => 'Failed to remove policy transaction'], 200); + } + } + //------------------------------------------------------------------------------------------------ // Policy Transaction Endorsement @@ -962,6 +978,7 @@ class PolicyTransactionController extends BaseController ->where('action_type', 'inception') ->where('client_id', $this->request->getPost('client_id')) ->where('client_policy_id', $this->request->getPost('client_policy_id')) + ->where('policy_transaction.is_active', 1) ->first(); $data['tsi'] = generate_tsi_code($issue_type['issue_type'] ?? 1); @@ -1089,6 +1106,7 @@ class PolicyTransactionController extends BaseController ->join('clients', 'clients.id = policy_transaction.client_id') ->join('client_policy', 'policy_transaction.client_policy_id = client_policy.id', 'left') ->where('policy_transaction.id', $id) + ->where('policy_transaction.is_active', 1) ->first(); // $data['policy_start_date'] = empty($data['policy_start_date']) ? '' : date('d/m/Y', strtotime($data['s_date'])); @@ -1278,6 +1296,8 @@ class PolicyTransactionController extends BaseController ->join('pt_co_share_details', 'policy_transaction.id = pt_co_share_details.pt_id') ->join('insurer_statements', 'pt_co_share_details.statement_id = insurer_statements.id') ->where('policy_transaction.id', $pt_id) + ->where('policy_transaction.is_active', 1) + ->where('pt_co_share_details.is_active', 1) ->where('pt_co_share_details.statement_id IS NOT NULL') ->where('insurer_statements.invoice_no IS NOT NULL') ->countAllResults(); diff --git a/app/Controllers/RestAuthenticationController.php b/app/Controllers/RestAuthenticationController.php index bed2e473..14b61d7d 100755 --- a/app/Controllers/RestAuthenticationController.php +++ b/app/Controllers/RestAuthenticationController.php @@ -73,7 +73,9 @@ class RestAuthenticationController extends AdminController $employeeData = $this->employeeModel->where('mobile', $mobile_number) ->where('relationship', 'self') - ->where('is_active', 1)->first(); + ->where('emp_status !=', 'truncated') + ->where('is_active', 1) + ->first(); if ($employeeData) { @@ -137,7 +139,8 @@ class RestAuthenticationController extends AdminController $HrData = $this->hrModel->where('mobile', $mobile_number) ->where('contact_type', 'client') - ->where('is_active', 1)->first(); + ->where('is_active', 1) + ->first(); if ($HrData) { diff --git a/app/Models/PolicyTransactionModel.php b/app/Models/PolicyTransactionModel.php index 3fa28edd..ba54a5ce 100644 --- a/app/Models/PolicyTransactionModel.php +++ b/app/Models/PolicyTransactionModel.php @@ -386,7 +386,11 @@ class PolicyTransactionModel extends Model $builder->orderBy('policy_transaction.id', 'desc'); - return $builder->get()->getResultArray(); + $result = $builder->get()->getResultArray(); + + // dd($this->db->getLastQuery()); + + return $result; } public function getEndorsementTranctionListData($start_date = 0, $end_date = 0, $client_id = 0, $insurer_id = 0, $policy_type_id = 0, $date_type = 0, $issuer = 0, $status = 0) diff --git a/app/Views/enrollment_list.php b/app/Views/enrollment_list.php index 3d37096a..edbdd473 100755 --- a/app/Views/enrollment_list.php +++ b/app/Views/enrollment_list.php @@ -180,6 +180,7 @@ SNO Name Emp Code + Relationship Enroled Logged-In @@ -336,6 +337,7 @@ index + 1, employee.employee_name, employee.emp_code, + employee.relationship, enrolled, loggedIn ]); diff --git a/app/Views/layout/footer.php b/app/Views/layout/footer.php index 39b2f769..bef8a1fc 100755 --- a/app/Views/layout/footer.php +++ b/app/Views/layout/footer.php @@ -862,6 +862,69 @@ } + + \ No newline at end of file diff --git a/app/Views/policy_transaction_inception_form.php b/app/Views/policy_transaction_inception_form.php index 4f6c0f36..2097e3a9 100644 --- a/app/Views/policy_transaction_inception_form.php +++ b/app/Views/policy_transaction_inception_form.php @@ -317,7 +317,7 @@