diff --git a/app/Controllers/TicketController.php b/app/Controllers/TicketController.php index 5e119628..95a4bbe2 100644 --- a/app/Controllers/TicketController.php +++ b/app/Controllers/TicketController.php @@ -829,11 +829,25 @@ class TicketController extends BaseController $data['ticket_data'] = $ticket_data; $data['acms'] = $this->employeeModel->getAcmUsingClientID($ticket_data['client_id']); - $raw_json = $this->ticketMasterModel->getPolicyTermsJson($ticket_id) ; - - $decoded_top = json_decode($raw_json ?? "", true) ?? []; - $data['policy_terms'] = $this->recursive_json_decode($decoded_top); + // do not remove this + // $raw_json = $this->ticketMasterModel->getPolicyTermsJson($ticket_id) ; + // $decoded_top = json_decode($raw_json ?? "", true) ?? []; + // $data['policy_terms'] = $this->recursive_json_decode($decoded_top); + + $policy_data = $this->ticketMasterModel + ->select('client_policy.policy_terms') + ->join('client_policy', 'ticket_master.client_policy_id = client_policy.id') + ->where('client_policy.is_active', 1) + ->where('ticket_master.is_active', 1) + ->where('ticket_master.id', $ticket_id) + ->first(); + + if(isset($policy_data['policy_terms']) && !empty($policy_data['policy_terms'])){ + $terms = json_decode($policy_data['policy_terms'], true); + $data['policy_terms'] = $this->convertTermsToDisplay($terms); + // print_rr($data); die; + } return $this->loadLayout('ticket_edit_onbording', $data); } @@ -2232,7 +2246,8 @@ class TicketController extends BaseController } } - public function recursive_json_decode($input) { + public function recursive_json_decode($input) + { if (is_string($input)) { $decoded = json_decode($input, true); if (json_last_error() === JSON_ERROR_NONE) { @@ -2251,6 +2266,182 @@ class TicketController extends BaseController return $input; } + function convertTermsToDisplay(array $data) + { + $result = []; + + $LableKeys = [ + "sum_insured" => "Sum Insured", + "family_floater" => "Family Floater", + "family_floaters" => "Family Floater Details", + "age_ratio" => "Age Ratio", + "is_payable_employee" => "Payable by Employee", + "waiverofpreexistingdiseases" => "Waivers of Pre Existing Diseases", + "waiverof1,2,3&4thyearexclusions" => "Waivers of 1, 2, 3 & 4th Year Exclusions", + "waiverof30dayswaitingperiod" => "Waivers of 30 Days Waiting Period", + "waiver_of_90_days_waiting_period" => "Waiver of 90 Days Waiting Period", + "waiver_of_other_waiting_periods" => "Waiver of Other Waiting Periods", + "maternity_benefit" => "Maternity Benefit", + "9monthwaitingperiodwaived" => "9 Month Waiting Period Waived", + "maternitycoverage" => "Maternity Coverage", + "twindelivery" => "Twin Delivery", + "well_baby_well_mother_expenses" => "Well Baby & Well Mother Expenses", + "preandpostnatal" => "Pre and Post Natal", + "infertility_treatment_coverage" => "Infertility Treatment Coverage", + "babyday1cover" => "Baby Day 1 Cover", + "coverfromthedateofjoining" => "Cover from the Date of Joining", + "mid_term_addition_of_new_born_newly_wedded_spouse" => "Mid Term Addition of New Born / Newly Wedded Spouse", + "prehospitalizationcover" => "Pre Hospitalization Cover", + "posthospitalizationcover" => "Post Hospitalization Cover", + "congenitaldiseasesinternal" => "Congenital Diseases - Internal", + "congenitaldiseasesexternal" => "Congenital Diseases - External", + "copayzonewisecopay" => "Co-Pay (Zone Wise)", + "roomrentlimit" => "Room Rent Limit", + "icu_limit" => "ICU Limit", + "proportionatedeductionclause" => "Proportionate Deduction Clause", + "ailmentcapping" => "Ailment Capping", + "ailment_capping_details" => "Ailment Capping Details", + "corporatebuffer" => "Corporate Buffer", + "non_admissible_contingency_corporate_buffer" => "Non-Admissible Contingency Corporate Buffer", + "ambulancecharges" => "Ambulance Charges", + "airambulance" => "Air Ambulance", + "reasonableandcustomarycharges" => "Reasonable and Customary Charges", + "daycaretreatment" => "Day Care Treatment", + "lasiksurgery" => "Lasik Surgery", + "ayudhtreatmentcover" => "Ayudh Treatment Cover", + "moderntreatmentsasperirdai" => "Modern Treatments as per IRDAI", + "opd_treatment" => "OPD Treatment", + "days_of_discharge" => "Days of Discharge", + "days_from_dod" => "Days from Date of Discharge", + "terrorism" => "Terrorism Cover", + "widower_cover" => "Widower Cover", + "breavement_cover" => "Breavement Cover", + "suminsuredenhancement" => "Sum Insured Enhancement", + "special_condition_label" => "Special Condition Label", + "special_condition_input" => "Special Condition Input" + ]; + + // // 1. Family Floaters + // $floatersMap = [ + // 'self' => 'Self', + // 'spouse' => 'Spouse', + // 'childrens' => 'Childrens', + // 'parents' => 'Parents', + // 'parents-in-law' => 'Parents-in-law', + // 'either-parents-pil' => 'Either Parents/PIL', + // 'elders_count' => 'Elders' + // ]; + + // 1. Family Floaters + $floatersMap = [ + 'self' => 'Self', + 'spouse' => 'Spouse', + 'childrens' => 'Childrens', + 'parents' => 'Parents', + 'parents-in-law' => 'Parents-in-law', + 'either-parents-pil' => 'Either Parents/PIL', + 'elders_count' => 'Total Elders Count' + ]; + + if(isset($data['family_floaters'])){ + $floatersOutput = []; + foreach ($floatersMap as $key => $label) { + if (isset($data['family_floaters'][$key])) { + $val = $data['family_floaters'][$key]; + $floatersOutput[] = "$label : " . ($val > 0 ? $val : 'No'); + } + } + $data['family_floaters'] = implode(', ', $floatersOutput); + } + + // 2. Age Ratio + if (!empty($data['age_ratio'])) { + $ageOutput = []; + foreach ($data['age_ratio'] as $person => $age) { + if (isset($age['min']) && isset($age['max'])) { + // $ageOutput[] = ucfirst($person) . " - Min : {$age['min']}, Max : {$age['max']}"; + $ageOutput[] = "" . ucfirst($person) . " - Min : {$age['min']}, Max : {$age['max']}"; + } + } + $data['age_ratio'] = implode(', ', $ageOutput); + } + + // 3. Is Payable Employee + if (!empty($data['is_payable_employee'])) { + $payableOutput = []; + foreach ($data['is_payable_employee'] as $person => $status) { + // $payableOutput[] = ucfirst($person) . " : " . ($status ? 'Yes' : 'No'); + $payableOutput[] = "" . ucfirst($person) . " : " . ($status ? 'Yes' : 'No'); + } + $data['is_payable_employee'] = implode(', ', $payableOutput); + } + + // 4. Remove the Enrollment display key + if(isset($data['enrollment_display_key'])){ + unset($data['enrollment_display_key']); + } + + // 5. Merge the Sum Insured value if the multiple sum insured exists + if(isset($data['multiple_sum_insured'])){ + if($data['sumInsured2']){ + $data['sumInsured2'] = $data['sumInsured2'] . ", " . implode(", ", $data['multiple_sum_insured']); + }else{ + $data['sum_insured'] = $data['sum_insured'] . ", " . implode(", ", $data['multiple_sum_insured']); + } + unset($data['multiple_sum_insured']); + } + + // 6. Add the special condition to key value pair + + if(!empty($data['special_condition_label'])){ + foreach ($data['special_condition_label'] as $key => $value) { + if($value != "" && $value != null) { + $data[$value] = $data['special_condition_input'][$key]; + } + } + }//GMC + + if(!empty($data['gpa_special_condition_label'])){ + foreach ($data['gpa_special_condition_label'] as $key => $value) { + if($value != "" && $value != null) { + $data[$value] = $data['gpa_special_condition_input'][$key]; + } + } + }//GPA + + // 7. Remove the special condition keys + unset($data['special_condition_label']); + unset($data['special_condition_input']); + unset($data['gpa_special_condition_label']); + unset($data['gpa_special_condition_input']); + + if(isset($data['sumInsured2'])){ + $firstItem = ["Sum Insured" => $data['sumInsured2']]; + unset($data['sumInsured2']); + $data = $firstItem + $data; + } + + // 8. Change the key name to lable name + $result = []; + foreach ($data as $key => $value) { + + // $label = isset($LableKeys[$key]) ? $LableKeys[$key] : $key; + if (isset($LableKeys[$key])) { + $label = $LableKeys[$key]; + // echo "1"; + } else { + // Handle camelCase first, then snake_case + $label = preg_replace('/(? + + + + + +
+ $value){ ?> +
+
+ +
+
+ +
+ +
+ +
+
+ No Terms Found
- +
+ + +