FIX_API
This commit is contained in:
parent
6d3cf50442
commit
43ee415407
@ -1714,9 +1714,9 @@ class EmployeeRestController extends AdminController
|
|||||||
if ($value > 0 && $key != 'elders_count') {
|
if ($value > 0 && $key != 'elders_count') {
|
||||||
if ($value != 0 && $key === 'childrens') {
|
if ($value != 0 && $key === 'childrens') {
|
||||||
|
|
||||||
if ($value > 2) {
|
// if ($value > 2) {
|
||||||
$value = 2;
|
// $value = 2;
|
||||||
}
|
// }
|
||||||
|
|
||||||
for ($i = 1; $i <= $value; $i++) {
|
for ($i = 1; $i <= $value; $i++) {
|
||||||
$result[] = "child" . $i;
|
$result[] = "child" . $i;
|
||||||
@ -7199,9 +7199,9 @@ class EmployeeRestController extends AdminController
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Policy-wise employee details API.
|
* Policy-wise employee details API (chat context).
|
||||||
* Input: emp_code, client_id (numeric id or MD5 hash of id)
|
* Input: emp_code, client_id (numeric id or MD5 hash of id)
|
||||||
* Returns one object per enrolled active policy with members, claims, premium and terms.
|
* user_key format: {employee_id}_{client_id}
|
||||||
*/
|
*/
|
||||||
public function getEmployeePolicyWiseDetails()
|
public function getEmployeePolicyWiseDetails()
|
||||||
{
|
{
|
||||||
@ -7243,8 +7243,24 @@ class EmployeeRestController extends AdminController
|
|||||||
], 200);
|
], 200);
|
||||||
}
|
}
|
||||||
|
|
||||||
$employeeIds = array_column($employeeRows, 'id');
|
$selfEmployee = null;
|
||||||
$dayInterval = 10;
|
foreach ($employeeRows as $row) {
|
||||||
|
$rel = strtolower(trim((string) ($row['relationship'] ?? '')));
|
||||||
|
$floater = strtolower(trim((string) ($row['family_floater_key'] ?? '')));
|
||||||
|
if ($rel === 'self' || $floater === 'self') {
|
||||||
|
$selfEmployee = $row;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($selfEmployee === null) {
|
||||||
|
$selfEmployee = $employeeRows[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
$employeeId = (string) $selfEmployee['id'];
|
||||||
|
$clientIdStr = (string) $client_id;
|
||||||
|
$userKey = $employeeId . '_' . $clientIdStr;
|
||||||
|
$employeeIds = array_column($employeeRows, 'id');
|
||||||
|
$dayInterval = 10;
|
||||||
|
|
||||||
$enrolledPolicyIds = $this->employeePolicyModel
|
$enrolledPolicyIds = $this->employeePolicyModel
|
||||||
->select('client_policy_id')
|
->select('client_policy_id')
|
||||||
@ -7283,14 +7299,13 @@ class EmployeeRestController extends AdminController
|
|||||||
], 200);
|
], 200);
|
||||||
}
|
}
|
||||||
|
|
||||||
$result = [];
|
$policies = [];
|
||||||
foreach ($enrolledPolicies as $policy) {
|
foreach ($enrolledPolicies as $policy) {
|
||||||
$clientPolicyId = (int) $policy['id'];
|
$clientPolicyId = (int) $policy['id'];
|
||||||
$policyTypeId = (int) $policy['policy_type_id'];
|
$policyTypeId = (int) $policy['policy_type_id'];
|
||||||
|
$ticketMeta = $this->getPolicyTicketMeta($policyTypeId);
|
||||||
$ticketMeta = $this->getPolicyTicketMeta($policyTypeId);
|
$termsRaw = json_decode($policy['policy_terms'] ?? '{}');
|
||||||
$termsRaw = json_decode($policy['policy_terms'] ?? '{}');
|
$termsArray = json_decode($policy['policy_terms'] ?? '{}', true) ?: [];
|
||||||
$termsArray = json_decode($policy['policy_terms'] ?? '{}', true) ?: [];
|
|
||||||
|
|
||||||
$coveredMembers = $this->employeePolicyModel
|
$coveredMembers = $this->employeePolicyModel
|
||||||
->select('
|
->select('
|
||||||
@ -7298,22 +7313,10 @@ class EmployeeRestController extends AdminController
|
|||||||
employees.emp_code,
|
employees.emp_code,
|
||||||
employees.name,
|
employees.name,
|
||||||
employees.relationship,
|
employees.relationship,
|
||||||
employees.relationship_code,
|
|
||||||
employees.family_floater_key,
|
employees.family_floater_key,
|
||||||
employees.gender,
|
employees.gender,
|
||||||
employees.dob,
|
employees.dob,
|
||||||
employees.doj,
|
|
||||||
employees.email_personal,
|
|
||||||
employees.email_corporate,
|
|
||||||
employees.mobile,
|
|
||||||
employees.band,
|
|
||||||
employees.designation,
|
|
||||||
employees.unit,
|
|
||||||
employees.emp_status,
|
employees.emp_status,
|
||||||
employees.basic_pay,
|
|
||||||
employees.client_id,
|
|
||||||
employees.client_branch_id,
|
|
||||||
employee_polices.id AS emp_policy_id,
|
|
||||||
employee_polices.uhid,
|
employee_polices.uhid,
|
||||||
employee_polices.tpa_id,
|
employee_polices.tpa_id,
|
||||||
employee_polices.rand_string,
|
employee_polices.rand_string,
|
||||||
@ -7324,12 +7327,7 @@ class EmployeeRestController extends AdminController
|
|||||||
employee_polices.payable_employee,
|
employee_polices.payable_employee,
|
||||||
employee_polices.date_coverage,
|
employee_polices.date_coverage,
|
||||||
employee_polices.policy_end_date AS member_policy_end_date,
|
employee_polices.policy_end_date AS member_policy_end_date,
|
||||||
employee_polices.days,
|
employee_polices.status AS emp_policy_status
|
||||||
employee_polices.status AS emp_policy_status,
|
|
||||||
employee_polices.pre_existing_alignments,
|
|
||||||
employee_polices.claim_status,
|
|
||||||
employee_polices.date_of_exit,
|
|
||||||
employee_polices.reason_for_exit
|
|
||||||
')
|
')
|
||||||
->join('employees', 'employees.id = employee_polices.employee_id', 'left')
|
->join('employees', 'employees.id = employee_polices.employee_id', 'left')
|
||||||
->whereIn('employee_polices.employee_id', $employeeIds)
|
->whereIn('employee_polices.employee_id', $employeeIds)
|
||||||
@ -7343,52 +7341,56 @@ class EmployeeRestController extends AdminController
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$empDetails = $this->buildEmpDetailsByRelation($coveredMembers);
|
$premiumSummary = $this->buildPremiumDetails($coveredMembers, $policyTypeId);
|
||||||
$premiumDetails = $this->buildPremiumDetails($coveredMembers, $policyTypeId);
|
$claimsSummary = $this->getClaimsForPolicy($emp_code, $clientPolicyId);
|
||||||
$claimDetails = $this->getClaimsForPolicy($emp_code, $clientPolicyId);
|
$sumInsured = $premiumSummary['sum_insured'];
|
||||||
|
|
||||||
$displayTerms = [];
|
$benefits = [];
|
||||||
if (!empty($termsArray['enrollment_display_key'])) {
|
if (!empty($termsArray['enrollment_display_key']) && is_array($termsArray['enrollment_display_key'])) {
|
||||||
$displayTerms = $termsArray['enrollment_display_key'];
|
$benefits = $termsArray['enrollment_display_key'];
|
||||||
} else {
|
} else {
|
||||||
$displayTerms = $this->policyTermsFiter($termsRaw, $ticketMeta['policy_group']);
|
$benefits = $this->policyTermsFiter($termsRaw, $ticketMeta['policy_group']);
|
||||||
}
|
}
|
||||||
|
|
||||||
$result[] = [
|
$policyTerms = [];
|
||||||
'policy_details' => [
|
if (!empty($termsArray['enrollment_display_key']) && is_array($termsArray['enrollment_display_key'])) {
|
||||||
'client_id' => (int) $policy['client_id'],
|
$policyTerms = $termsArray['enrollment_display_key'];
|
||||||
'client_branch_id' => (int) $policy['client_branch_id'],
|
}
|
||||||
'client_policy_id' => $clientPolicyId,
|
|
||||||
'policy_no' => $policy['policy_no'],
|
$familyFloaters = $this->extractFamilyFloaters($termsArray);
|
||||||
'policy_type_id' => $policyTypeId,
|
$isFamilyFloater = true;
|
||||||
'policy_type' => $policy['policy_type'],
|
if (isset($termsArray['family_floater']) && strpos(strtolower((string) $termsArray['family_floater']), 'no') !== false) {
|
||||||
'policy_name' => $policy['policy_type'],
|
$isFamilyFloater = false;
|
||||||
'heading' => $policy['policy_long_name'],
|
}
|
||||||
'insurer_name' => $policy['insurer_name'],
|
|
||||||
'tpa_name' => $policy['tpa_name'],
|
$policies[] = [
|
||||||
'network_hospitals_url' => $policy['network_hospitals_url'],
|
'policy_type' => $policy['policy_type'],
|
||||||
'policy_start_date' => $this->convertDateFormatDisplay($policy['policy_start_date']),
|
'policy_no' => $policy['policy_no'],
|
||||||
'policy_end_date' => $this->convertDateFormatDisplay($policy['policy_end_date']),
|
'policy_name' => $policy['policy_type'],
|
||||||
'claims_grace_date' => $this->convertDateFormatDisplay($policy['claims_grace_date']),
|
'heading' => $policy['policy_long_name'],
|
||||||
'policy_status' => ((int) $policy['policy_status'] === 1) ? 'Active' : 'InActive',
|
'insurer_name' => $policy['insurer_name'],
|
||||||
'is_addon' => (int) $policy['is_addon'],
|
'tpa_name' => $policy['tpa_name'] ?: null,
|
||||||
'open_for_enrollment' => (int) ($policy['open_for_enrollment'] ?? 0),
|
'network_hospitals_url' => $policy['network_hospitals_url'] ?: null,
|
||||||
'inception_type' => $policy['inception_type'],
|
'policy_status' => ((int) $policy['policy_status'] === 1) ? 'Active' : 'Inactive',
|
||||||
'disclaimer' => $policy['disclaimer'],
|
'policy_start_date' => $this->convertDateFormatDisplay($policy['policy_start_date']),
|
||||||
'sum_insured_label' => $ticketMeta['sum_insured_label'],
|
'policy_end_date' => $this->convertDateFormatDisplay($policy['policy_end_date']),
|
||||||
'claim_subject' => $ticketMeta['claim_subject'],
|
'claims_grace_date' => $this->convertDateFormatDisplay($policy['claims_grace_date']),
|
||||||
'terms_and_conditions' => [
|
'sum_insured_label' => $ticketMeta['sum_insured_label'],
|
||||||
'raw' => $termsArray,
|
'sum_insured' => (string) $sumInsured,
|
||||||
'display' => $displayTerms,
|
'sum_insured_display' => $this->formatAmountDisplay($sumInsured),
|
||||||
],
|
'claim_subject' => $ticketMeta['claim_subject'],
|
||||||
'premium_details' => $premiumDetails,
|
'family_floater' => $isFamilyFloater,
|
||||||
'claim_details' => $claimDetails,
|
'family_floaters' => $familyFloaters,
|
||||||
'emp_details' => $empDetails,
|
'age_limits' => $this->extractAgeLimits($termsRaw),
|
||||||
],
|
'members' => $this->buildPolicyMembersList($coveredMembers),
|
||||||
|
'benefits' => $benefits ?: new \stdClass(),
|
||||||
|
'policy_terms' => $policyTerms ?: new \stdClass(),
|
||||||
|
'premium_summary' => $premiumSummary,
|
||||||
|
'claims_summary' => $claimsSummary,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (empty($result)) {
|
if (empty($policies)) {
|
||||||
return $this->respond([
|
return $this->respond([
|
||||||
'status' => 'failed',
|
'status' => 'failed',
|
||||||
'code' => 404,
|
'code' => 404,
|
||||||
@ -7400,10 +7402,23 @@ class EmployeeRestController extends AdminController
|
|||||||
return $this->respond([
|
return $this->respond([
|
||||||
'status' => 'success',
|
'status' => 'success',
|
||||||
'code' => 200,
|
'code' => 200,
|
||||||
'message' => 'Employee policy-wise details fetched successfully',
|
'message' => 'Policy chat context fetched successfully',
|
||||||
'data' => [
|
'data' => [
|
||||||
'policy_data' => $result,
|
'employee_id' => $employeeId,
|
||||||
'support' => $this->getClientSupportContacts((int) $client_id),
|
'client_id' => $clientIdStr,
|
||||||
|
'user_key' => $userKey,
|
||||||
|
'employee_summary' => [
|
||||||
|
'name' => $selfEmployee['name'] ?? null,
|
||||||
|
'emp_code' => $selfEmployee['emp_code'] ?? $emp_code,
|
||||||
|
'designation' => $selfEmployee['designation'] ?? null,
|
||||||
|
'band' => $selfEmployee['band'] ?? null,
|
||||||
|
'unit' => $selfEmployee['unit'] ?? null,
|
||||||
|
'emp_status' => $selfEmployee['emp_status'] ?? null,
|
||||||
|
'email_corporate' => $selfEmployee['email_corporate'] ?? null,
|
||||||
|
'mobile' => $selfEmployee['mobile'] ?? null,
|
||||||
|
],
|
||||||
|
'policies' => $policies,
|
||||||
|
'support' => $this->getClientSupportContacts((int) $client_id),
|
||||||
],
|
],
|
||||||
], 200);
|
], 200);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
@ -7479,148 +7494,159 @@ class EmployeeRestController extends AdminController
|
|||||||
{
|
{
|
||||||
if ($policyTypeId === 1) {
|
if ($policyTypeId === 1) {
|
||||||
return [
|
return [
|
||||||
'policy_group' => 'gpa',
|
'policy_group' => 'gpa',
|
||||||
'ticket_type_id' => 2,
|
'ticket_type_id' => 2,
|
||||||
'ticket_settled_status_id'=> 24,
|
'ticket_settled_status_id' => 24,
|
||||||
'claim_subject' => 'Claim GPA',
|
'claim_subject' => 'Claim GPA',
|
||||||
'sum_insured_label' => 'Sum Assured',
|
'sum_insured_label' => 'Sum Assured',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
if ($policyTypeId === 6) {
|
if ($policyTypeId === 6) {
|
||||||
return [
|
return [
|
||||||
'policy_group' => 'other',
|
'policy_group' => 'other',
|
||||||
'ticket_type_id' => 3,
|
'ticket_type_id' => 3,
|
||||||
'ticket_settled_status_id'=> 34,
|
'ticket_settled_status_id' => 34,
|
||||||
'claim_subject' => 'Claim EDLI',
|
'claim_subject' => 'Claim EDLI',
|
||||||
'sum_insured_label' => 'Sum Assured',
|
'sum_insured_label' => 'Sum Assured',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
if ($policyTypeId === 7) {
|
if ($policyTypeId === 7) {
|
||||||
return [
|
return [
|
||||||
'policy_group' => 'other',
|
'policy_group' => 'other',
|
||||||
'ticket_type_id' => 4,
|
'ticket_type_id' => 4,
|
||||||
'ticket_settled_status_id'=> 44,
|
'ticket_settled_status_id' => 44,
|
||||||
'claim_subject' => 'Claim GTLI',
|
'claim_subject' => 'Claim GTLI',
|
||||||
'sum_insured_label' => 'Sum Assured',
|
'sum_insured_label' => 'Sum Assured',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
if ($policyTypeId === 72) {
|
if ($policyTypeId === 72) {
|
||||||
return [
|
return [
|
||||||
'policy_group' => 'other',
|
'policy_group' => 'other',
|
||||||
'ticket_type_id' => 72,
|
'ticket_type_id' => 72,
|
||||||
'ticket_settled_status_id'=> 76,
|
'ticket_settled_status_id' => 76,
|
||||||
'claim_subject' => 'Claim OPD',
|
'claim_subject' => 'Claim OPD',
|
||||||
'sum_insured_label' => 'Sum Insured',
|
'sum_insured_label' => 'Sum Insured',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'policy_group' => 'gmc',
|
'policy_group' => 'gmc',
|
||||||
'ticket_type_id' => 1,
|
'ticket_type_id' => 1,
|
||||||
'ticket_settled_status_id'=> 11,
|
'ticket_settled_status_id' => 11,
|
||||||
'claim_subject' => 'Claim GMC',
|
'claim_subject' => 'Claim GMC',
|
||||||
'sum_insured_label' => 'Sum Insured',
|
'sum_insured_label' => 'Sum Insured',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
private function extractFamilyFloaters(array $termsArray): array
|
||||||
* Group covered members as:
|
|
||||||
* self => object, spouse/child/parent/parent_in_law/... => array
|
|
||||||
*/
|
|
||||||
private function buildEmpDetailsByRelation(array $coveredMembers): array
|
|
||||||
{
|
{
|
||||||
$empDetails = [
|
$floaters = $termsArray['family_floaters'] ?? [];
|
||||||
'self' => new \stdClass(),
|
if (!is_array($floaters)) {
|
||||||
|
$floaters = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
return [
|
||||||
|
'self' => $floaters['self'] ?? 0,
|
||||||
|
'spouse' => $floaters['spouse'] ?? 0,
|
||||||
|
'childrens' => $floaters['childrens'] ?? 0,
|
||||||
|
'parents' => $floaters['parents'] ?? 0,
|
||||||
|
'parents-in-law' => $floaters['parents-in-law'] ?? ($floaters['parents_in_law'] ?? 0),
|
||||||
|
'either-parents-pil' => $floaters['either-parents-pil'] ?? 0,
|
||||||
|
'elders_count' => $floaters['elders_count'] ?? null,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
private function extractAgeLimits($termsRaw): array
|
||||||
|
{
|
||||||
|
$defaults = [
|
||||||
|
'self' => ['min' => 18, 'max' => 60],
|
||||||
|
'spouse' => ['min' => 18, 'max' => 60],
|
||||||
|
'child' => ['min' => 0, 'max' => 25],
|
||||||
|
'elders' => ['min' => 18, 'max' => 60],
|
||||||
];
|
];
|
||||||
|
|
||||||
|
if (is_object($termsRaw) && isset($termsRaw->age_ratio) && is_object($termsRaw->age_ratio)) {
|
||||||
|
$ageRatio = $termsRaw->age_ratio;
|
||||||
|
return [
|
||||||
|
'self' => [
|
||||||
|
'min' => $ageRatio->self->min ?? $defaults['self']['min'],
|
||||||
|
'max' => $ageRatio->self->max ?? $defaults['self']['max'],
|
||||||
|
],
|
||||||
|
'spouse' => [
|
||||||
|
'min' => $ageRatio->spouse->min ?? $defaults['spouse']['min'],
|
||||||
|
'max' => $ageRatio->spouse->max ?? $defaults['spouse']['max'],
|
||||||
|
],
|
||||||
|
'child' => [
|
||||||
|
'min' => $ageRatio->child->min ?? $defaults['child']['min'],
|
||||||
|
'max' => $ageRatio->child->max ?? $defaults['child']['max'],
|
||||||
|
],
|
||||||
|
'elders' => [
|
||||||
|
'min' => $ageRatio->elders->min ?? $defaults['elders']['min'],
|
||||||
|
'max' => $ageRatio->elders->max ?? $defaults['elders']['max'],
|
||||||
|
],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $defaults;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function buildPolicyMembersList(array $coveredMembers): array
|
||||||
|
{
|
||||||
|
$members = [];
|
||||||
foreach ($coveredMembers as $member) {
|
foreach ($coveredMembers as $member) {
|
||||||
$relationKey = $this->normalizeRelationKey($member);
|
$members[] = $this->formatChatContextMember($member);
|
||||||
$memberData = $this->formatMemberDetails($member);
|
|
||||||
|
|
||||||
if ($relationKey === 'self') {
|
|
||||||
$empDetails['self'] = $memberData;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!isset($empDetails[$relationKey]) || !is_array($empDetails[$relationKey])) {
|
|
||||||
$empDetails[$relationKey] = [];
|
|
||||||
}
|
|
||||||
$empDetails[$relationKey][] = $memberData;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $empDetails;
|
usort($members, function ($a, $b) {
|
||||||
|
$order = ['self' => 0, 'spouse' => 1, 'son' => 2, 'daughter' => 3];
|
||||||
|
$aKey = strtolower((string) ($a['relationship'] ?? ''));
|
||||||
|
$bKey = strtolower((string) ($b['relationship'] ?? ''));
|
||||||
|
return ($order[$aKey] ?? 99) <=> ($order[$bKey] ?? 99);
|
||||||
|
});
|
||||||
|
|
||||||
|
return $members;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function normalizeRelationKey(array $member): string
|
private function formatChatContextMember(array $member): array
|
||||||
{
|
|
||||||
$floaterKey = strtolower(trim((string) ($member['family_floater_key'] ?? '')));
|
|
||||||
$floaterKey = preg_replace('/\d+/', '', $floaterKey);
|
|
||||||
|
|
||||||
if (in_array($floaterKey, ['self', 'spouse', 'child', 'parent', 'parent_in_law'], true)) {
|
|
||||||
return $floaterKey;
|
|
||||||
}
|
|
||||||
|
|
||||||
$relationship = trim((string) ($member['relationship'] ?? ''));
|
|
||||||
if (strcasecmp($relationship, 'Self') === 0) {
|
|
||||||
return 'self';
|
|
||||||
}
|
|
||||||
|
|
||||||
$mapped = $this->RelationshipMap($relationship);
|
|
||||||
if (!empty($mapped)) {
|
|
||||||
return $mapped;
|
|
||||||
}
|
|
||||||
|
|
||||||
$normalized = strtolower(str_replace([' ', '-'], '_', $relationship));
|
|
||||||
return $normalized !== '' ? $normalized : 'other';
|
|
||||||
}
|
|
||||||
|
|
||||||
private function formatMemberDetails(array $member): array
|
|
||||||
{
|
{
|
||||||
$eCardDownload = null;
|
$eCardDownload = null;
|
||||||
if (!empty($member['tpa_id']) && !empty($member['rand_string'])) {
|
if (!empty($member['tpa_id']) && !empty($member['rand_string'])) {
|
||||||
$eCardDownload = base_url('download-e-card/') . $member['rand_string'] . '/1';
|
$eCardDownload = base_url('download-e-card/') . $member['rand_string'] . '/1';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$basicCoverSi = $member['basic_cover_si'] ?? 0;
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'employee_id' => (int) ($member['employee_id'] ?? 0),
|
'name' => $member['name'] ?? null,
|
||||||
'emp_policy_id' => (int) ($member['emp_policy_id'] ?? 0),
|
'relationship' => $member['relationship'] ?? null,
|
||||||
'emp_code' => $member['emp_code'] ?? null,
|
'gender' => $member['gender'] ?? null,
|
||||||
'name' => $member['name'] ?? null,
|
'dob' => !empty($member['dob']) ? $this->convertDateFormatDMY($member['dob']) : null,
|
||||||
'relationship' => $member['relationship'] ?? null,
|
'emp_status' => $member['emp_status'] ?? null,
|
||||||
'relationship_code' => $member['relationship_code'] ?? null,
|
'basic_cover_si' => $basicCoverSi,
|
||||||
'family_floater_key' => $member['family_floater_key'] ?? null,
|
'basic_cover_si_display' => $this->formatAmountDisplay($basicCoverSi),
|
||||||
'gender' => $member['gender'] ?? null,
|
'premium' => $member['premium'] ?? null,
|
||||||
'dob' => !empty($member['dob']) ? $this->convertDateFormatDMY($member['dob']) : null,
|
'gst' => $member['gst'] ?? null,
|
||||||
'doj' => !empty($member['doj']) ? $this->convertDateFormatDMY($member['doj']) : null,
|
'payable_employee' => isset($member['payable_employee']) ? (int) $member['payable_employee'] : 0,
|
||||||
'email_personal' => $member['email_personal'] ?? null,
|
'date_coverage' => !empty($member['date_coverage']) ? $this->convertDateFormatDMY($member['date_coverage']) : null,
|
||||||
'email_corporate' => $member['email_corporate'] ?? null,
|
'member_policy_end_date' => !empty($member['member_policy_end_date']) ? $this->convertDateFormatDMY($member['member_policy_end_date']) : null,
|
||||||
'mobile' => $member['mobile'] ?? null,
|
'emp_policy_status' => $member['emp_policy_status'] ?? null,
|
||||||
'band' => $member['band'] ?? null,
|
'eCardDownload' => $eCardDownload,
|
||||||
'designation' => $member['designation'] ?? null,
|
|
||||||
'unit' => $member['unit'] ?? null,
|
|
||||||
'emp_status' => $member['emp_status'] ?? null,
|
|
||||||
'basic_pay' => $member['basic_pay'] ?? null,
|
|
||||||
'client_id' => isset($member['client_id']) ? (int) $member['client_id'] : null,
|
|
||||||
'client_branch_id' => isset($member['client_branch_id']) ? (int) $member['client_branch_id'] : null,
|
|
||||||
'uhid' => $member['uhid'] ?? null,
|
|
||||||
'tpa_id' => $member['tpa_id'] ?? null,
|
|
||||||
'eCardDownload' => $eCardDownload,
|
|
||||||
'basic_cover_si' => $member['basic_cover_si'] ?? 0,
|
|
||||||
'premium' => $member['premium'] ?? 0,
|
|
||||||
'rata_premimum' => $member['rata_premimum'] ?? 0,
|
|
||||||
'gst' => $member['gst'] ?? 0,
|
|
||||||
'payable_employee' => isset($member['payable_employee']) ? (int) $member['payable_employee'] : 0,
|
|
||||||
'date_coverage' => !empty($member['date_coverage']) ? $this->convertDateFormatDMY($member['date_coverage']) : null,
|
|
||||||
'member_policy_end_date' => !empty($member['member_policy_end_date']) ? $this->convertDateFormatDMY($member['member_policy_end_date']) : null,
|
|
||||||
'days' => $member['days'] ?? null,
|
|
||||||
'emp_policy_status' => $member['emp_policy_status'] ?? null,
|
|
||||||
'pre_existing_alignments' => $member['pre_existing_alignments'] ?? null,
|
|
||||||
'claim_status' => $member['claim_status'] ?? null,
|
|
||||||
'date_of_exit' => !empty($member['date_of_exit']) ? $this->convertDateFormatDMY($member['date_of_exit']) : null,
|
|
||||||
'reason_for_exit' => $member['reason_for_exit'] ?? null,
|
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function formatAmountDisplay($amount): string
|
||||||
|
{
|
||||||
|
if ($amount === null || $amount === '') {
|
||||||
|
return '0';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (function_exists('formatIndianCurrency')) {
|
||||||
|
return (string) formatIndianCurrency($amount);
|
||||||
|
}
|
||||||
|
|
||||||
|
return number_format((float) $amount, 0, '.', ',');
|
||||||
|
}
|
||||||
|
|
||||||
private function buildPremiumDetails(array $coveredMembers, int $policyTypeId): array
|
private function buildPremiumDetails(array $coveredMembers, int $policyTypeId): array
|
||||||
{
|
{
|
||||||
$siValue = 0;
|
$siValue = 0;
|
||||||
@ -7637,28 +7663,25 @@ class EmployeeRestController extends AdminController
|
|||||||
$rataTotal += (float) ($member['rata_premimum'] ?? 0);
|
$rataTotal += (float) ($member['rata_premimum'] ?? 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Match existing app behaviour: hide premium/gst for base GPA/GMC in summary views
|
|
||||||
$hidePremium = in_array($policyTypeId, [1, 2], true);
|
$hidePremium = in_array($policyTypeId, [1, 2], true);
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'sum_insured' => $siValue,
|
'sum_insured' => $siValue,
|
||||||
'total_premium' => $hidePremium ? 0 : round($premiumTotal),
|
'total_premium' => $hidePremium ? 0 : round($premiumTotal),
|
||||||
'total_gst' => $hidePremium ? 0 : round($gstTotal),
|
'total_gst' => $hidePremium ? 0 : round($gstTotal),
|
||||||
'total_rata_premium'=> $hidePremium ? 0 : round($rataTotal),
|
'total_rata_premium' => $hidePremium ? 0 : round($rataTotal),
|
||||||
'total_with_gst' => $hidePremium ? 0 : round($premiumTotal + $gstTotal),
|
'total_with_gst' => $hidePremium ? 0 : round($premiumTotal + $gstTotal),
|
||||||
'member_count' => count($coveredMembers),
|
'member_count' => count($coveredMembers),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getClaimsForPolicy(string $empCode, int $clientPolicyId): array
|
private function getClaimsForPolicy(string $empCode, int $clientPolicyId): array
|
||||||
{
|
{
|
||||||
$db = db_connect();
|
$db = db_connect();
|
||||||
$claims = $db->table('ticket_master tm')
|
$claims = $db->table('ticket_master tm')
|
||||||
->select([
|
->select([
|
||||||
'tm.id AS ticket_id',
|
'tm.id AS ticket_id',
|
||||||
'tm.claim_number AS claim_no',
|
'tm.claim_number AS claim_no',
|
||||||
'tm.ticket_type_id',
|
|
||||||
'tm.claim_status_id',
|
|
||||||
"CASE
|
"CASE
|
||||||
WHEN tcs.display_name IS NULL OR tcs.display_name = ''
|
WHEN tcs.display_name IS NULL OR tcs.display_name = ''
|
||||||
THEN tcs.claim_status
|
THEN tcs.claim_status
|
||||||
@ -7669,25 +7692,14 @@ class EmployeeRestController extends AdminController
|
|||||||
THEN tm.tpa_claim_type
|
THEN tm.tpa_claim_type
|
||||||
ELSE 'Reimbursement'
|
ELSE 'Reimbursement'
|
||||||
END AS claim_type",
|
END AS claim_type",
|
||||||
'tm.emp_name',
|
|
||||||
'tm.emp_code',
|
|
||||||
'tm.relationship',
|
|
||||||
'tm.insured_name',
|
'tm.insured_name',
|
||||||
|
'tm.relationship',
|
||||||
'tm.hospital_name',
|
'tm.hospital_name',
|
||||||
'tm.doa',
|
'tm.doa',
|
||||||
'tm.dod',
|
'tm.dod',
|
||||||
'tm.claim_amount',
|
'tm.claim_amount',
|
||||||
'tm.approved_amount',
|
'tm.approved_amount',
|
||||||
'tm.si_amt',
|
|
||||||
'tm.policy_no',
|
|
||||||
'tm.tpa_no',
|
|
||||||
'tm.client_policy_id',
|
|
||||||
'DATE_FORMAT(tm.created_at, "%d-%m-%Y") AS ticket_created_date',
|
|
||||||
'tm.raised_date',
|
|
||||||
'tm.registration_date',
|
|
||||||
'tm.approved_date',
|
|
||||||
'tm.settled_date',
|
'tm.settled_date',
|
||||||
'tm.denial_date',
|
|
||||||
'tm.denial_reason',
|
'tm.denial_reason',
|
||||||
'tm.utr_details',
|
'tm.utr_details',
|
||||||
])
|
])
|
||||||
@ -7699,18 +7711,37 @@ class EmployeeRestController extends AdminController
|
|||||||
->get()
|
->get()
|
||||||
->getResultArray();
|
->getResultArray();
|
||||||
|
|
||||||
|
$formattedClaims = [];
|
||||||
$totalClaimAmount = 0;
|
$totalClaimAmount = 0;
|
||||||
$totalApprovedAmount = 0;
|
$totalApprovedAmount = 0;
|
||||||
|
|
||||||
foreach ($claims as $claim) {
|
foreach ($claims as $claim) {
|
||||||
$totalClaimAmount += (float) ($claim['claim_amount'] ?? 0);
|
$totalClaimAmount += (float) ($claim['claim_amount'] ?? 0);
|
||||||
$totalApprovedAmount += (float) ($claim['approved_amount'] ?? 0);
|
$totalApprovedAmount += (float) ($claim['approved_amount'] ?? 0);
|
||||||
|
|
||||||
|
$formattedClaims[] = [
|
||||||
|
'ticket_id' => (string) ($claim['ticket_id'] ?? ''),
|
||||||
|
'claim_no' => $claim['claim_no'] ?? null,
|
||||||
|
'status' => $claim['status'] ?? null,
|
||||||
|
'claim_type' => $claim['claim_type'] ?? null,
|
||||||
|
'insured_name' => $claim['insured_name'] ?? null,
|
||||||
|
'relationship' => $claim['relationship'] ?? null,
|
||||||
|
'hospital_name' => $claim['hospital_name'] ?? null,
|
||||||
|
'doa' => $claim['doa'] ?? null,
|
||||||
|
'dod' => $claim['dod'] ?? null,
|
||||||
|
'claim_amount' => $claim['claim_amount'] ?? null,
|
||||||
|
'approved_amount' => $claim['approved_amount'] ?? null,
|
||||||
|
'settled_date' => $claim['settled_date'] ?? null,
|
||||||
|
'denial_reason' => $claim['denial_reason'] ?? null,
|
||||||
|
'utr_details' => $claim['utr_details'] ?? null,
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'count' => count($claims),
|
'count' => count($formattedClaims),
|
||||||
'total_claim_amount' => round($totalClaimAmount, 2),
|
'total_claim_amount' => round($totalClaimAmount, 2),
|
||||||
'total_approved_amount' => round($totalApprovedAmount, 2),
|
'total_approved_amount' => round($totalApprovedAmount, 2),
|
||||||
'claims' => $claims,
|
'claims' => $formattedClaims,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -252,6 +252,7 @@ class EmployeePolicyModel extends Model
|
|||||||
|
|
||||||
$result = $this->select([
|
$result = $this->select([
|
||||||
'employee_polices.*',
|
'employee_polices.*',
|
||||||
|
'employee_polices.tpa_id as uhid',
|
||||||
'policy_type.policy_type as policy_name',
|
'policy_type.policy_type as policy_name',
|
||||||
'im.short_name as insurer_short_name',
|
'im.short_name as insurer_short_name',
|
||||||
'ib.branch_name as insurer_branch_name',
|
'ib.branch_name as insurer_branch_name',
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user