This commit is contained in:
VENKATESHWARAN 2025-08-14 10:34:25 +05:30
parent 898508781d
commit 9834fc4e7f
2 changed files with 385 additions and 83 deletions

View File

@ -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' => '<b>Self</b>',
// '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' => '<b style="color : #000;">Self</b>',
'spouse' => '<b style="color : #000;">Spouse</b>',
'childrens' => '<b style="color : #000;">Childrens</b>',
'parents' => '<b style="color : #000;">Parents</b>',
'parents-in-law' => '<b style="color : #000;">Parents-in-law</b>',
'either-parents-pil' => '<b style="color : #000;">Either Parents/PIL</b>',
'elders_count' => '<b style="color : #000;">Total Elders Count</b>'
];
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[] = "<b style='color : #000;'>" . ucfirst($person) . "</b> - <b> Min </b>: {$age['min']}, <b> Max </b> : {$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[] = "<b style='color : #000;'>" . ucfirst($person) . "</b> : " . ($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('/(?<!^)[A-Z]/', ' $0', $key); // camelCase → space
$label = ucwords(str_replace('_', ' ', $label)); // snake_case → space & capitalize
// echo "2";
}
$result[$label] = $value == 1 ? "Yes" : ($value == 0 ? "No" : $value);
}
// return count($result);
// return $data;
return $result;
}

View File

@ -1,97 +1,208 @@
<br>
<!-- <br>
<p style="color:black;">
<b>Policy Terms</b>
</p>
<br>
<?php
// ✅ Format keys: underscores to spaces, each word capitalized
function readable_key($key) {
$key = str_replace('_', ' ', $key);
return ucwords($key);
}
// // ✅ Format keys: underscores to spaces, each word capitalized
// function readable_key($key) {
// $key = str_replace('_', ' ', $key);
// return ucwords($key);
// }
// ✅ Format values: 0 = NO, 1 = YES, >1 = number as-is
function format_value($value) {
if (is_numeric($value)) {
if ($value == 0) return 'No';
if ($value == 1) return 'Yes';
}
return $value;
}
// // ✅ Format values: 0 = NO, 1 = YES, >1 = number as-is
// function format_value($value) {
// if (is_numeric($value)) {
// if ($value == 0) return 'No';
// if ($value == 1) return 'Yes';
// }
// return $value;
// }
// ✅ Recursively render nested keyvalue pairs
function nestedKeyValuePair($data) {
$output = '';
// // ✅ Recursively render nested keyvalue pairs
// function nestedKeyValuePair($data) {
// $output = '';
foreach ($data as $key => $value) {
$label = readable_key($key);
$output .= "<span style='color:black;'> : <b>$label</b>";
// foreach ($data as $key => $value) {
// $label = readable_key($key);
// $output .= "<span style='color:black;'> : <b>$label</b>";
if (is_array($value)) {
$output .= "<span style='margin-left: 10px;'>" . nestedKeyValuePair($value) . "</span>";
} else {
$formattedValue = format_value($value);
$output .= " : " . htmlspecialchars($formattedValue) ;
}
// if (is_array($value)) {
// $output .= "<span style='margin-left: 10px;'>" . nestedKeyValuePair($value) . "</span>";
// } else {
// $formattedValue = format_value($value);
// $output .= " : " . htmlspecialchars($formattedValue) ;
// }
$output .= "</span>";
// $output .= "</span>";
// }
// return $output;
// }
// if (isset($policy_terms['policy_terms']) && is_array($policy_terms['policy_terms'])) {
// // ✅ Merge multiple_sum_insured with sum_insured
// if (
// isset($policy_terms['policy_terms']['multiple_sum_insured']) &&
// is_array($policy_terms['policy_terms']['multiple_sum_insured'])
// ) {
// $sum_insured_values = implode(' , ', $policy_terms['policy_terms']['multiple_sum_insured']);
// $original_sum = isset($policy_terms['policy_terms']['sum_insured'])
// ? $policy_terms['policy_terms']['sum_insured']
// : '';
// $policy_terms['policy_terms']['sum_insured'] = $original_sum . " , " . $sum_insured_values;
// unset($policy_terms['policy_terms']['multiple_sum_insured']);
// }
// // ✅ Display each policy term
// foreach ($policy_terms['policy_terms'] as $key => $value) {
// if ($key === "age_ratio" || $key === "enrollment_display_key") {
// continue; // Skip excluded keys
// }
// // Normalize specific raw keys (if needed)
// if ($key === 'waiverof30dayswaitingperiod') {
// $key = 'Waiver_of_30_days_waiting_period';
// }
// if ($key === 'suminsuredenhancement') {
// $key = 'sum_insured_enhancement';
// }
// // Readable label
// $label = readable_key($key);
// $nesetedValues = "";
// ?>
// <div class="row">
// <div class="form-group col-3">
// <p style="color:black;"><b><?php //echo htmlspecialchars($label); ?>:</b></p>
// </div>
// <div class="form-group col-6">
// <?php
// if (is_array($value)) {
// $nesetedValues .= nestedKeyValuePair($value) .",";
// echo "$nesetedValues";
// } else {
// $formattedValue = format_value($value);
// echo "<p style='color:black;'>: " . htmlspecialchars($formattedValue) . "</p>";
// }
// ?>
// </div>
// </div>
// <?php
// }
// }
?> -->
<style>
.policy-terms-container {
border: 1px solid #ddd;
border-radius: 8px;
background-color: #fafafa;
padding: 20px;
max-width: 1200px;
margin: 20px auto;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
return $output;
}
if (isset($policy_terms['policy_terms']) && is_array($policy_terms['policy_terms'])) {
// ✅ Merge multiple_sum_insured with sum_insured
if (
isset($policy_terms['policy_terms']['multiple_sum_insured']) &&
is_array($policy_terms['policy_terms']['multiple_sum_insured'])
) {
$sum_insured_values = implode(' , ', $policy_terms['policy_terms']['multiple_sum_insured']);
$original_sum = isset($policy_terms['policy_terms']['sum_insured'])
? $policy_terms['policy_terms']['sum_insured']
: '';
$policy_terms['policy_terms']['sum_insured'] = $original_sum . " , " . $sum_insured_values;
unset($policy_terms['policy_terms']['multiple_sum_insured']);
.policy-row {
display: flex;
border-bottom: 1px solid #eee;
padding: 12px 0;
align-items: center;
}
// ✅ Display each policy term
foreach ($policy_terms['policy_terms'] as $key => $value) {
if ($key === "age_ratio" || $key === "enrollment_display_key") {
continue; // Skip excluded keys
}
.policy-row:last-child {
border-bottom: none;
}
// Normalize specific raw keys (if needed)
if ($key === 'waiverof30dayswaitingperiod') {
$key = 'Waiver_of_30_days_waiting_period';
}
if ($key === 'suminsuredenhancement') {
$key = 'sum_insured_enhancement';
}
.policy-label {
flex: 0 0 40%;
padding-right: 20px;
}
// Readable label
$label = readable_key($key);
$nesetedValues = "";
?>
<div class="row">
<div class="form-group col-3">
<p style="color:black;"><b><?php echo htmlspecialchars($label); ?>:</b></p>
</div>
<div class="form-group col-6">
<?php
if (is_array($value)) {
$nesetedValues .= nestedKeyValuePair($value) .",";
echo "$nesetedValues";
} else {
$formattedValue = format_value($value);
echo "<p style='color:black;'>: " . htmlspecialchars($formattedValue) . "</p>";
}
?>
.policy-label label {
font-weight: 600;
color: #333;
font-size: 14px;
margin: 0;
text-transform: capitalize;
}
.policy-value {
flex: 1;
padding-left: 20px;
border-left: 1px solid #eee;
}
.policy-value span {
color: #555;
font-size: 14px;
line-height: 1.4;
}
.no-terms-container {
border: 1px solid #ddd;
border-radius: 8px;
background-color: #f9f9f9;
padding: 40px;
text-align: center;
max-width: 800px;
margin: 20px auto;
}
.no-terms-message span {
color: #666;
font-size: 16px;
font-style: italic;
}
/* Responsive design */
@media (max-width: 768px) {
.policy-row {
flex-direction: column;
align-items: flex-start;
}
.policy-label {
flex: none;
padding-right: 0;
padding-bottom: 8px;
width: 100%;
}
.policy-value {
flex: none;
padding-left: 0;
border-left: none;
border-top: 1px solid #eee;
padding-top: 8px;
width: 100%;
}
}
</style>
<?php if(isset($policy_terms)) { ?>
<div class="policy-terms-container">
<?php foreach($policy_terms as $key => $value){ ?>
<div class="policy-row">
<div class="policy-label">
<label><?= htmlspecialchars($key) ?></label>
</div>
<div class="policy-value">
<span><?= $value ?></span>
</div>
</div>
<?php } ?>
</div>
<?php } else { ?>
<div class="no-terms-container">
<div class="no-terms-message">
<span>No Terms Found</span>
</div>
<?php
}
}
?>
</div>
<?php } ?>