diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 3d1630be..bb09d35b 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -50,6 +50,7 @@ $routes->get("updatajson", "EmpDataServiceController::updatajson"); $routes->get("view", "EmployeeController::viewECard/$1"); $routes->get("checkWellnessOnboardStatus/(:any)", "EmployeeController::checkWellnessOnboardStatus/$1"); $routes->get("initiateWellnessOnboard/(:any)", "EmployeeController::initiateWellnessOnboard/$1"); +$routes->get("resetWellnessOnboard/(:any)", "EmployeeController::resetWellnessOnboard/$1"); $routes->get("exportQCRandRFQ/(:any)", "LeadsController::exportQCRandRFQ/$1"); $routes->get("testMailAttachments", "ClientController::testMailAttachments"); $routes->get("updatePolicyTermsKey", "ClientController::updatePolicyTermsKey"); diff --git a/app/Controllers/ClientController.php b/app/Controllers/ClientController.php index d14c8de7..7a3a89a1 100755 --- a/app/Controllers/ClientController.php +++ b/app/Controllers/ClientController.php @@ -6652,7 +6652,7 @@ class ClientController extends AdminController // Check in Enrollment (client_policy) $client_policy_data = $this->clientPolicyModel ->where('is_active', 1) - ->where('policy_status', 1) + // ->where('policy_status', 1) ->where('TRIM(policy_no)', $policy_no) ->first(); @@ -7312,6 +7312,8 @@ class ClientController extends AdminController // dd($res); $employeeController = new EmployeeController(); + // $payload = json_decode('{"client_policy_id":"6272"}', true); + // $response = $employeeController->initiateWellnessOnboardJob($payload); dd($response); // $response = $employeeController->getEmployeeEcardFromTmpFolderAndZipToS3(json_decode('{"batch_no":2,"last_emp_policy_id":"13218","folder_name":"bulk_ecards_IOCL-77448855996699885555_2026-02-05_09-32-22","processed_in_this_batch_data_count":7,"pdf_count":0,"hr_id":"1"}', true)); // $response = $employeeController->bulkEcardDownloadAsZipFromS3(json_decode('{"client_policy_id":"6066","hr_id":"1"}', true)); // dd($response); diff --git a/app/Controllers/EmployeeController.php b/app/Controllers/EmployeeController.php index 3688f759..c345330c 100755 --- a/app/Controllers/EmployeeController.php +++ b/app/Controllers/EmployeeController.php @@ -896,7 +896,7 @@ class EmployeeController extends AdminController session()->setFlashdata('success', 'File Uploaded Successfully File is being validated.'); return redirect()->to(base_url('employee/upload')); } else { - session()->setFlashdata($return['status'], $return['message']); + session()->setFlashdata($return['status'] ?? 'error', $return['message'] ?? 'Something went wrong! Try Later'); return redirect()->to(base_url('employee/upload')); } } else if ($event_type == 'correction') { @@ -3622,7 +3622,22 @@ class EmployeeController extends AdminController public function checkWellnessOnboardStatus($client_policy_id) - { + { + + + $fetch_onboarded_employees = $this->request->getGet('fetch_onboarded_employees') ?? false; + + if($fetch_onboarded_employees){ + $data = $this->employeePolicyModel->select('employee_polices.*') + ->where('employee_polices.is_active', 1) + ->where('employee_polices.status', 'active') + ->where('employee_polices.client_policy_id', $client_policy_id) + ->where('employee_polices.wellness_onboard !=', '0') + ->findAll(); + return $this->respond(['status' => true, 'code' => 200, 'data' => count($data)], 200); + } + + // echo $client_policy_id;die(); $data = $this->employeePolicyModel->select('employee_polices.*,emp.name,emp.relationship,emp.emp_code,emp.name,emp.email_corporate,emp.mobile,emp.dob,cp.policy_no,cp.wellness_plan_id,cp.wellness_vendor_id,cp.policy_start_date as cp_policy_start_date,cp.policy_end_date,cls.short_name') ->join('client_policy cp', 'cp.id = employee_polices.client_policy_id') @@ -3656,9 +3671,9 @@ class EmployeeController extends AdminController // return $this->respond(['status' => true, 'code' => 200, 'message' => 'Inception and Member data comparision skiped successfully!'], 200); } - public function initiateWellnessOnboard($client_policy_id) + public function initiateWellnessOnboard($client_policy_id, $emp_code = null) { - $r = Jobs::addJob(['job_name' => 'initiateWellnessOnboardJob','payload' => ['client_policy_id' => $client_policy_id]]); + $r = Jobs::addJob(['job_name' => 'initiateWellnessOnboardJob','payload' => ['client_policy_id' => $client_policy_id, 'emp_code' => $emp_code ?? null ]]); // $this->initiateWellnessOnboardJob(['client_policy_id' => $client_policy_id]); return $this->respond(['status' => true, 'code' => 200, 'message' => 'Process started'], 200); } @@ -3774,6 +3789,7 @@ class EmployeeController extends AdminController public function initiateWellnessOnboardJob($arr) { $client_policy_id = $arr['client_policy_id'] ?? null; + $emp_code = $arr['emp_code'] ?? null; if (!$client_policy_id) { log_message('error', '[WellnessOnboard] Missing client_policy_id in payload'); @@ -3789,7 +3805,7 @@ class EmployeeController extends AdminController // ---------------------------------------------------------------- // 1. FETCH DATA // ---------------------------------------------------------------- - $data = $this->employeePolicyModel + $query = $this->employeePolicyModel ->select('employee_polices.*, emp.name, emp.relationship, emp.emp_code, emp.email_corporate, emp.mobile, emp.dob, emp.gender, @@ -3817,8 +3833,13 @@ class EmployeeController extends AdminController ->orWhere('cp.wellness_vendor_id =', 0) ->groupEnd() ->where('cp.policy_status', 1) - ->where('cp.is_active', 1) - ->findAll($perPage, $offset); + ->where('cp.is_active', 1); + + if(!empty($emp_code)){ + $query->where('emp.emp_code', trim($emp_code)); + } + + $data = $query->findAll($perPage, $offset); // ---------------------------------------------------------------- // 2. NO DATA FOUND @@ -3852,7 +3873,7 @@ class EmployeeController extends AdminController foreach ($families as $empCode => $members) { $familiesPayload[$empCode] = $this->buildFamilyPayload($empCode, $members); } - log_message('error', "[WellnessOnboard] Page {$page} API calls done. Families processed: " . json_encode($familiesPayload)); + log_message('error', "[WellnessOnboard] Page {$page} API calls done. Families processed: " . json_encode($familiesPayload)); // ---------------------------------------------------------------- // 5. SEND TO WELLNESS API // ---------------------------------------------------------------- @@ -3885,6 +3906,33 @@ class EmployeeController extends AdminController return true; } + public function resetWellnessOnboard($client_policy_id, $emp_code = null) + { + if(!empty($emp_code)){ + + $employees = db_connect()->table('employees') + ->select('id') + ->where('emp_code', trim($emp_code)) + ->get() + ->getResult(); + + if (!empty($employees)) { + $employeeIds = array_column($employees, 'id'); + + $this->employeePolicyModel + ->where('client_policy_id', $client_policy_id) + ->whereIn('employee_id', $employeeIds) + ->set('wellness_onboard', '0') + ->update(); + } + + } else { + $this->employeePolicyModel->where('client_policy_id', $client_policy_id)->set('wellness_onboard', '0')->update(); + } + + return $this->respond(['status' => true, 'code' => 200, 'message' => 'Wellness onboard resetted successfully'], 200); + } + # ------------------ FUNCTION TO BUILD FAMILY PAYLOAD ------------------ diff --git a/app/Controllers/LeadsController.php b/app/Controllers/LeadsController.php index 0b1fc090..49412b34 100644 --- a/app/Controllers/LeadsController.php +++ b/app/Controllers/LeadsController.php @@ -2288,6 +2288,8 @@ class LeadsController extends BaseController // 'Insurer' => $rfq_data['insurer_name'] ?? " - ", // 'TPA' => $rfq_data['tpa_name'] ?? " - ", 'Policy Type' => $this->leadType[$rfq_data['lead_type']] ?? "", + 'Mortality Experience for last 3 years' => $claim_history == "1" ? "Mentioned in Claims sheet" : "Nil", + ]; }else { diff --git a/app/Controllers/TicketController.php b/app/Controllers/TicketController.php index 4e219a4a..4421fb71 100644 --- a/app/Controllers/TicketController.php +++ b/app/Controllers/TicketController.php @@ -968,6 +968,58 @@ class TicketController extends BaseController return $extra_fields; } + /** + * Overlay conditional `required` rules onto a base validation rule-set based on the + * submitted `claim_status_id`. For example, when claim_status_id is a "Settled" status + * (11/24/34/44), fields like `utr_details` and `settled_date` are promoted from + * `permit_empty` to `required` so the request is rejected when they are blank. + * + * Letter URL fields (`approved_letter`, `settle_letter`) accept an alternative PDF + * upload, so they are intentionally not promoted here; that pairing is enforced by + * the upload validation flow. `approved_description` stays optional to match the + * existing UI contract. + */ + private function applyClaimStatusConditionalRules(array $rules): array + { + $claimStatusId = (int) $this->request->getPost('claim_status_id'); + if ($claimStatusId <= 0) { + return $rules; + } + + if (!isset($this->extraFields[$claimStatusId]) || !is_array($this->extraFields[$claimStatusId])) { + return $rules; + } + + $requiredFields = $this->extraFields[$claimStatusId]; + $skipFields = ['approved_letter', 'settle_letter', 'approved_description']; + + foreach ($requiredFields as $field) { + if (in_array($field, $skipFields, true) || !isset($rules[$field])) { + continue; + } + + $existingRules = $rules[$field]['rules'] ?? ''; + $parts = $existingRules === '' + ? [] + : array_values(array_filter(array_map('trim', explode('|', $existingRules)), function ($part) { + return $part !== '' && $part !== 'permit_empty'; + })); + + if (!in_array('required', $parts, true)) { + array_unshift($parts, 'required'); + } + $rules[$field]['rules'] = implode('|', array_unique($parts)); + + if (!isset($rules[$field]['errors']) || !is_array($rules[$field]['errors'])) { + $rules[$field]['errors'] = []; + } + $label = $rules[$field]['label'] ?? ucwords(str_replace('_', ' ', $field)); + $rules[$field]['errors']['required'] = $label . ' is required for the selected claim status.'; + } + + return $rules; + } + public function view_ticket($ticket_id) { // $ticket_data = $this->ticketMasterModel->where('id', $ticket_id)->where('is_active', 1)->first(); @@ -1456,6 +1508,8 @@ class TicketController extends BaseController ]; } + $rules = $this->applyClaimStatusConditionalRules($rules); + if (!$this->validate($rules)) { return $this->response->setStatusCode(400)->setJSON([ 'status' => false, @@ -1944,6 +1998,9 @@ class TicketController extends BaseController 'return_remark' => ['label' => 'Return Remark','rules' => 'permit_empty','errors' => []], ]; } + + $rules = $this->applyClaimStatusConditionalRules($rules); + if (!$this->validate($rules)) { return $this->response->setStatusCode(400)->setJSON([ 'status' => false, @@ -3053,7 +3110,7 @@ class TicketController extends BaseController } } - public function getLastMatchedStatus($incoming_form_values, $old_ticket_data) + public function getLastMatchedStatusOld($incoming_form_values, $old_ticket_data) { if (empty($incoming_form_values) || !isset($incoming_form_values['claim_status_id']) || !isset($incoming_form_values['extra_fields_array_for_validate'])) { return null; @@ -3122,6 +3179,71 @@ class TicketController extends BaseController return $lastMatchedStatus; } + public function getLastMatchedStatus($incoming_form_values, $old_ticket_data) + { + // Preserve the incoming claim_status_id (if any) as the safe fallback so callers + // never accidentally nullify the status when validation inputs are missing. + $incomingStatus = $incoming_form_values['claim_status_id'] ?? null; + + if (empty($incoming_form_values) || !isset($incoming_form_values['extra_fields_array_for_validate'])) { + return $incomingStatus; + } + + $lastMatchedStatus = $incomingStatus; + + $statusMapping = json_decode($incoming_form_values['extra_fields_array_for_validate'], true); + if (!is_array($statusMapping) || empty($statusMapping)) { + return $incomingStatus; + } + + // Drop transitional / aggregate statuses that should never be auto-selected. + $removeKeys = is_array($this->removeArrayKey) ? $this->removeArrayKey : []; + $statusMapping = array_diff_key($statusMapping, $removeKeys); + + $oldStatusId = is_array($old_ticket_data) ? ($old_ticket_data['claim_status_id'] ?? null) : null; + + $skipFields = ['approved_description']; + + foreach ($statusMapping as $status => $requiredFields) { + if (empty($requiredFields)) { + continue; + } + + // Skip the current/old status — we only advance forward to a newer status. + if ($oldStatusId !== null && (int) $status === (int) $oldStatusId) { + continue; + } + + if (!is_array($requiredFields)) { + $requiredFields = [$requiredFields]; + } + + $allFieldsMatched = true; + foreach ($requiredFields as $field) { + if (in_array($field, $skipFields, true)) { + continue; + } + + if (!isset($incoming_form_values[$field]) || $incoming_form_values[$field] === '' || $incoming_form_values[$field] === null) { + $allFieldsMatched = false; + break; + } + } + + if ($allFieldsMatched) { + $lastMatchedStatus = $status; + } + } + + // When a TPA number is present, promote the base "registered" statuses + // (1 -> 2 for standard, 67 -> 68 for the alternate flow). + if (!empty($incoming_form_values['tpa_no']) && in_array((int) $lastMatchedStatus, [1, 67], true)) { + $lastMatchedStatus = ((int) $lastMatchedStatus === 1) ? 2 : 68; + } + + return $lastMatchedStatus; + } + public function getPolicyStartDate() { @@ -3560,7 +3682,7 @@ class TicketController extends BaseController { $fileId = $this->claimFilesModel->insert([ 'ticket_id' => $ticketId, - 'ticket_type' => $ticketTypeId, + // 'ticket_type' => $ticketTypeId, 'file_type' => 3, 'doc_name' => $docName, 'file_name' => $uploadedFile['file_name'], diff --git a/app/Models/UserModel.php b/app/Models/UserModel.php index 32272925..8f62c9ae 100755 --- a/app/Models/UserModel.php +++ b/app/Models/UserModel.php @@ -133,6 +133,7 @@ class UserModel extends Model ->select('user_profiles.*') ->select('roles.role as user_role') ->join('roles', 'roles.id = user_profiles.role') + ->where('user_profiles.is_active', 1) ->get() ->getResultArray(); } @@ -143,13 +144,26 @@ class UserModel extends Model ->select('roles.role as user_role') ->join('roles', 'roles.id = user_profiles.role') ->join('user_teams', 'user_teams.user_id = user_profiles.id') + ->where('user_profiles.is_active', 1) ->get() ->getResultArray(); + // The user_teams join produces one row per (user, team) pair, so users + // belonging to multiple teams appear multiple times. Collapse to one + // row per user while keeping a team_id from [6, 7] when available, so + // the existing in_array($user['team_id'], [6, 7]) checks in the views + // continue to work correctly. + $deduped = []; + foreach ($data as $row) { + $userId = $row['id']; + if (!isset($deduped[$userId])) { + $deduped[$userId] = $row; + } elseif (in_array($row['team_id'], [6, 7])) { + $deduped[$userId]['team_id'] = $row['team_id']; + } + } - // dd($data); - - return $data; + return array_values($deduped); } } diff --git a/app/Views/batch_list.php b/app/Views/batch_list.php index 5ebdebc5..61d395e7 100755 --- a/app/Views/batch_list.php +++ b/app/Views/batch_list.php @@ -34,7 +34,7 @@ if (!empty($batch_list) && is_array($batch_list)) { $countStr = ($file['count'] ?? null) === null ? '-' : (string) $file['count']; $batch_col_max_len[9] = max($batch_col_max_len[9], mb_strlen($countStr)); $batch_col_max_len[10] = max($batch_col_max_len[10], mb_strlen((string) format_indian_number($file['amount']))); - $userTime = change_date_format($file['created_at'] ?? '', 'Y-m-d H:i:s', 'd M Y h:i a') + $userTime = change_date_format($file['created_at'] ?? '', 'Y-m-d H:i:s', 'd/m/Y h:i a') . ' by ' . get_username($file['created_by'] ?? ''); $batch_col_max_len[11] = max($batch_col_max_len[11], mb_strlen($userTime)); @@ -350,7 +350,7 @@ for ($i = 0; $i < $batch_col_count; $i++) { - by + by diff --git a/app/Views/bds_dump_file_list.php b/app/Views/bds_dump_file_list.php index b56448fa..2ea6207a 100644 --- a/app/Views/bds_dump_file_list.php +++ b/app/Views/bds_dump_file_list.php @@ -49,7 +49,7 @@ - ' . $file['user_name'] . '' ?> + ' . $file['user_name'] . '' ?> diff --git a/app/Views/cd_master_add_modal.php b/app/Views/cd_master_add_modal.php index e73b807f..29597a75 100644 --- a/app/Views/cd_master_add_modal.php +++ b/app/Views/cd_master_add_modal.php @@ -107,13 +107,50 @@ var isCdMasterPage = ; console.log("isCdMasterPage", isCdMasterPage); + function formatCdOpeningDateForInput(inputDate) { + if (!inputDate || String(inputDate).trim() === '') { + return ''; + } + var str = String(inputDate).trim(); + var iso = str.match(/^(\d{4})-(\d{2})-(\d{2})/); + if (iso) { + return iso[3] + '/' + iso[2] + '/' + iso[1]; + } + var dmy = str.match(/^(\d{1,2})[-\/](\d{1,2})[-\/](\d{4})$/); + if (dmy) { + var day = ('0' + dmy[1]).slice(-2); + var month = ('0' + dmy[2]).slice(-2); + return day + '/' + month + '/' + dmy[3]; + } + return str; + } + + function cdOpeningDateForSubmit(inputDate) { + var formatted = formatCdOpeningDateForInput(inputDate); + if (!formatted) { + return inputDate || ''; + } + var parts = formatted.split('/'); + return parts[0] + '-' + parts[1] + '-' + parts[2]; + } + + var openingDatePicker; + $(document).ready(function(){ - var openingDatePicker = flatpickr("#opening_date", { - dateFormat: "d-m-Y", + openingDatePicker = flatpickr("#opening_date", { + dateFormat: "d/m/Y", allowInput: false }); + $('#con-close-modal').on('shown.bs.modal', function() { + var val = $('#opening_date').val(); + if (val) { + var formatted = formatCdOpeningDateForInput(val); + openingDatePicker.setDate(formatted, false); + } + }); + if(isCdMasterPage == true){ $('#cd_client_id').select2(); $('#insurer_id_for_cd').select2(); @@ -172,6 +209,10 @@ } let formData = new FormData($('#CDMasterForm')[0]); + var openingDate = formData.get('opening_date'); + if (openingDate) { + formData.set('opening_date', cdOpeningDateForSubmit(openingDate)); + } console.log("formData", formData); let url = ''; diff --git a/app/Views/cd_master_list.php b/app/Views/cd_master_list.php index 1314066a..1bd8dc4e 100755 --- a/app/Views/cd_master_list.php +++ b/app/Views/cd_master_list.php @@ -15,12 +15,12 @@ foreach ($CD_Master_Data as $index => $row) { $cdm_col_max_len[1] = max($cdm_col_max_len[1], mb_strlen($clientCell)); $cdm_col_max_len[2] = max($cdm_col_max_len[2], mb_strlen((string) ($row['insurer_name'] ?? ''))); $cdm_col_max_len[3] = max($cdm_col_max_len[3], mb_strlen((string) ($row['insurer_branch_name'] ?? ''))); - $od = ! empty($row['opening_date']) ? date('d-m-Y', strtotime((string) $row['opening_date'])) : ''; + $od = ! empty($row['opening_date']) ? date('d/m/Y', strtotime((string) $row['opening_date'])) : ''; $cdm_col_max_len[4] = max($cdm_col_max_len[4], mb_strlen($od)); $cdm_col_max_len[5] = max($cdm_col_max_len[5], mb_strlen((string) ($row['cd_ac_no'] ?? ''))); $cdm_col_max_len[6] = max($cdm_col_max_len[6], mb_strlen((string) ($row['opening_bal'] ?? ''))); $du = ! empty($row['created_at']) - ? (date('d-M-Y h:i A', strtotime((string) $row['created_at'])) . ' by ' . ($row['user_name'] ?? '')) + ? (date('d/m/Y h:i A', strtotime((string) $row['created_at'])) . ' by ' . ($row['user_name'] ?? '')) : ''; $cdm_col_max_len[7] = max($cdm_col_max_len[7], mb_strlen($du)); $cdm_col_max_len[8] = max($cdm_col_max_len[8], 4); @@ -118,10 +118,10 @@ $cdm_col_width_px = nhance_dt_column_widths_px($cdm_header_labels, $cdm_col_max_ ( ) - + -
by +
by //
@@ -2187,7 +2187,7 @@ // // //
// //
@@ -2245,7 +2245,7 @@ } function getClaimHistoryLabel(leadType) { - return String(leadType) === '1' ? 'Mortality Claims' : 'Claims History'; + return String(leadType) === '1' ? 'Mortality Experience' : 'Claims Experience'; } function shouldShowClaimHistorySwitch(leadType, policyTypeId) { @@ -2304,7 +2304,7 @@ @@ -2361,7 +2361,7 @@ @@ -2381,7 +2381,7 @@ diff --git a/app/Views/leads_non_eb.php b/app/Views/leads_non_eb.php index d13ecb49..dd046a61 100644 --- a/app/Views/leads_non_eb.php +++ b/app/Views/leads_non_eb.php @@ -400,7 +400,7 @@ var pageBackButton = ' @@ -906,11 +906,11 @@ var pageBackButton = '" class="topbar-icon diff --git a/app/Views/non_eb_claim_list.php b/app/Views/non_eb_claim_list.php index f4622ffe..2136c661 100644 --- a/app/Views/non_eb_claim_list.php +++ b/app/Views/non_eb_claim_list.php @@ -64,7 +64,7 @@ - + diff --git a/app/Views/policy_transaction_endorsement_form.php b/app/Views/policy_transaction_endorsement_form.php index e203c8cb..d78428db 100644 --- a/app/Views/policy_transaction_endorsement_form.php +++ b/app/Views/policy_transaction_endorsement_form.php @@ -181,7 +181,7 @@ } - +
@@ -297,7 +297,7 @@
- +
@@ -326,7 +326,7 @@
- +
@@ -757,6 +757,9 @@ // console.log('tpa',tpa); $('#policy_no').val(policy_no); + if (typeof window.clearEndorsementExcludedFieldsValidation === 'function') { + window.clearEndorsementExcludedFieldsValidation('#endorsement_form_id'); + } $('#insurer_id').val(insurer); $('#tpa').val(tpa).change(); // $('#cd_ac_no').val(cd_ac_no); @@ -1206,6 +1209,9 @@ $('#policy_no').val(res.data.policy_no); $('#action_type').val(res.data.action_type); $('#endorsement_no').val(res.data.endorsement_no); + if (typeof window.clearEndorsementExcludedFieldsValidation === 'function') { + window.clearEndorsementExcludedFieldsValidation('#endorsement_form_id'); + } $('#data_received_date').val(res.data.data_received_date); $('#policy_issue_date').val(res.data.policy_issue_date); $('#emp_count').val(res.data.emp_count); diff --git a/app/Views/policy_transaction_endorsement_form_2.php b/app/Views/policy_transaction_endorsement_form_2.php index e61df749..d39f421b 100644 --- a/app/Views/policy_transaction_endorsement_form_2.php +++ b/app/Views/policy_transaction_endorsement_form_2.php @@ -195,7 +195,7 @@ } - +