FIX_VOLO_ECARD_ISSUE
This commit is contained in:
parent
779e20a648
commit
d41c9ec946
@ -7727,14 +7727,16 @@ class EmployeeRestController extends AdminController
|
|||||||
|
|
||||||
$benefits = [];
|
$benefits = [];
|
||||||
if (!empty($termsArray['enrollment_display_key']) && is_array($termsArray['enrollment_display_key'])) {
|
if (!empty($termsArray['enrollment_display_key']) && is_array($termsArray['enrollment_display_key'])) {
|
||||||
$benefits = $termsArray['enrollment_display_key'];
|
$benefits = $this->normalizePolicyTermsKeys($termsArray['enrollment_display_key']);
|
||||||
} else {
|
} else {
|
||||||
$benefits = $this->policyTermsFiter($termsRaw, $ticketMeta['policy_group']);
|
$benefits = $this->normalizePolicyTermsKeys(
|
||||||
|
$this->policyTermsFiter($termsRaw, $ticketMeta['policy_group']) ?: []
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
$policyTerms = [];
|
$policyTerms = [];
|
||||||
if (!empty($termsArray['enrollment_display_key']) && is_array($termsArray['enrollment_display_key'])) {
|
if (!empty($termsArray['enrollment_display_key']) && is_array($termsArray['enrollment_display_key'])) {
|
||||||
$policyTerms = $termsArray['enrollment_display_key'];
|
$policyTerms = $this->normalizePolicyTermsKeys($termsArray['enrollment_display_key']);
|
||||||
}
|
}
|
||||||
|
|
||||||
$familyFloaters = $this->extractFamilyFloaters($termsArray);
|
$familyFloaters = $this->extractFamilyFloaters($termsArray);
|
||||||
@ -8027,6 +8029,36 @@ class EmployeeRestController extends AdminController
|
|||||||
return number_format((float) $amount, 0, '.', ',');
|
return number_format((float) $amount, 0, '.', ',');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Normalize enrollment_display_key terms:
|
||||||
|
* - "Room Rent Limit" => room_rent_limit
|
||||||
|
* - whitespace-only values => ""
|
||||||
|
*/
|
||||||
|
private function normalizePolicyTermsKeys(array $terms): array
|
||||||
|
{
|
||||||
|
$normalized = [];
|
||||||
|
|
||||||
|
foreach ($terms as $key => $value) {
|
||||||
|
$snakeKey = strtolower(trim((string) $key));
|
||||||
|
$snakeKey = preg_replace('/[^a-z0-9]+/', '_', $snakeKey);
|
||||||
|
$snakeKey = trim($snakeKey, '_');
|
||||||
|
|
||||||
|
if (is_string($value)) {
|
||||||
|
$value = trim($value);
|
||||||
|
} elseif (is_array($value)) {
|
||||||
|
$value = $this->normalizePolicyTermsKeys($value);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($snakeKey === '') {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$normalized[$snakeKey] = $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $normalized;
|
||||||
|
}
|
||||||
|
|
||||||
private function buildPremiumDetails(array $coveredMembers, int $policyTypeId): array
|
private function buildPremiumDetails(array $coveredMembers, int $policyTypeId): array
|
||||||
{
|
{
|
||||||
$siValue = 0;
|
$siValue = 0;
|
||||||
|
|||||||
@ -906,7 +906,7 @@ class VoloApiController extends BaseController
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* E-card PDF — returns a data URL the app can open, or null on failure.
|
* E-card PDF — saves base64 PDF to public/tmp and returns a downloadable URL, or null on failure.
|
||||||
*
|
*
|
||||||
* @param string|null $voloEmployeeId Volo/TPA employee or member id stored in employee_polices.tpa_id
|
* @param string|null $voloEmployeeId Volo/TPA employee or member id stored in employee_polices.tpa_id
|
||||||
*/
|
*/
|
||||||
@ -919,13 +919,15 @@ class VoloApiController extends BaseController
|
|||||||
}
|
}
|
||||||
|
|
||||||
$entityId = $this->resolveEntityId((string) $policy_no);
|
$entityId = $this->resolveEntityId((string) $policy_no);
|
||||||
|
log_message('error', 'VOLO - Ecard | entity id: ' . $entityId . ' | policy_no: ' . $policy_no . ' | voloEmployeeId: ' . $voloEmployeeId);
|
||||||
if ($entityId === null) {
|
if ($entityId === null) {
|
||||||
log_message('error', 'VOLO - Ecard | entity id not resolved | policy: ' . ($policy_no ?? ''));
|
log_message('error', 'VOLO - Ecard | entity id not resolved | policy: ' . ($policy_no ?? ''));
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
$res = $this->getEcardPdfRequest((string) $voloEmployeeId, $entityId);
|
$res = $this->getEcardPdfRequest((string) $emp_code, $entityId);
|
||||||
|
log_message('error', 'VOLO - Ecard | res: ' . json_encode($res));
|
||||||
if (empty($res['status']) || !is_array($res['data'])) {
|
if (empty($res['status']) || !is_array($res['data'])) {
|
||||||
log_message('error', 'VOLO - Ecard FAILED | ' . json_encode($res));
|
log_message('error', 'VOLO - Ecard FAILED | ' . json_encode($res));
|
||||||
|
|
||||||
@ -939,6 +941,38 @@ class VoloApiController extends BaseController
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 'data:application/pdf;base64,' . $body;
|
// Strip data-URI prefix if the API already included it.
|
||||||
|
if (stripos($body, 'base64,') !== false) {
|
||||||
|
$body = substr($body, strpos($body, 'base64,') + 7);
|
||||||
|
}
|
||||||
|
|
||||||
|
$pdfBinary = base64_decode($body, true);
|
||||||
|
if ($pdfBinary === false || $pdfBinary === '') {
|
||||||
|
log_message('error', 'VOLO - Ecard FAILED | base64 decode failed | emp_code: ' . ($emp_code ?? ''));
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$dir = FCPATH . 'tmp/';
|
||||||
|
if (!is_dir($dir) && !mkdir($dir, 0775, true) && !is_dir($dir)) {
|
||||||
|
log_message('error', 'VOLO - Ecard FAILED | cannot create dir: ' . $dir);
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$safeEmp = preg_replace('/[^A-Za-z0-9_-]/', '_', (string) $emp_code) ?: 'emp';
|
||||||
|
$fileName = 'volo_ecard_' . $safeEmp . '_' . time() . '_' . bin2hex(random_bytes(4)) . '.pdf';
|
||||||
|
$filePath = $dir . $fileName;
|
||||||
|
|
||||||
|
if (file_put_contents($filePath, $pdfBinary) === false) {
|
||||||
|
log_message('error', 'VOLO - Ecard FAILED | cannot write file: ' . $filePath);
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$downloadUrl = base_url('public/tmp/' . $fileName);
|
||||||
|
log_message('error', 'VOLO - Ecard SUCCESS | url: ' . $downloadUrl);
|
||||||
|
|
||||||
|
return $downloadUrl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user