nhance/app/Views/view_policy_terms.php

98 lines
3.0 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<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 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 = '';
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) ;
}
$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
}
}
?>