FIX_BDS_REPORT
This commit is contained in:
parent
84a6a619e9
commit
e547cf84bc
@ -3060,55 +3060,55 @@
|
|||||||
// dd($this->db->getLastQuery());
|
// dd($this->db->getLastQuery());
|
||||||
|
|
||||||
|
|
||||||
foreach ($result as $key => &$row) {
|
// foreach ($result as $key => &$row) {
|
||||||
|
|
||||||
// If both rewards and billed amount are zero, remove the row
|
// // If both rewards and billed amount are zero, remove the row
|
||||||
if (
|
// if (
|
||||||
($row['reward'] ?? 0) == 0.00 &&
|
// ($row['reward'] ?? 0) == 0.00 &&
|
||||||
($row['billed_amt'] ?? 0) == 0.00
|
// ($row['billed_amt'] ?? 0) == 0.00
|
||||||
) {
|
// ) {
|
||||||
unset($result[$key]); // ✅ correct way
|
// unset($result[$key]); // ✅ correct way
|
||||||
}
|
// }
|
||||||
|
|
||||||
// If rewards exist, zero the IRDA amount
|
// // If rewards exist, zero the IRDA amount
|
||||||
// if (($row['reward'] ?? 0) != 0.00) {
|
// // if (($row['reward'] ?? 0) != 0.00) {
|
||||||
// $row['total_irda_amt'] = '0.00';
|
// // $row['total_irda_amt'] = '0.00';
|
||||||
// $row['billed_amt'] = $row['reward'];
|
// // $row['billed_amt'] = $row['reward'];
|
||||||
// }
|
// // }
|
||||||
|
|
||||||
$reward = (float) ($row['reward'] ?? 0);
|
// $reward = (float) ($row['reward'] ?? 0);
|
||||||
|
|
||||||
if ($reward > 0) {
|
// if ($reward > 0) {
|
||||||
$row['total_irda_amt'] = '0.00';
|
// $row['total_irda_amt'] = '0.00';
|
||||||
$row['billed_amt'] = $reward;
|
// $row['billed_amt'] = $reward;
|
||||||
}
|
// }
|
||||||
|
|
||||||
}
|
// }
|
||||||
unset($row);
|
// unset($row);
|
||||||
|
|
||||||
// $result = array_values($result);
|
// // $result = array_values($result);
|
||||||
|
|
||||||
usort($result, function ($a, $b) {
|
// usort($result, function ($a, $b) {
|
||||||
|
|
||||||
// First: group by policy_issue_date
|
// // First: group by policy_issue_date
|
||||||
if ($a['policy_issue_month'] === $b['policy_issue_month']) {
|
// if ($a['policy_issue_month'] === $b['policy_issue_month']) {
|
||||||
|
|
||||||
// Priority order for action_type
|
// // Priority order for action_type
|
||||||
$priority = [
|
// $priority = [
|
||||||
'Policy' => 1,
|
// 'Policy' => 1,
|
||||||
'Endorsement' => 2,
|
// 'Endorsement' => 2,
|
||||||
'Rewards' => 3
|
// 'Rewards' => 3
|
||||||
];
|
// ];
|
||||||
|
|
||||||
$aPriority = $priority[$a['action_type']] ?? 99;
|
// $aPriority = $priority[$a['action_type']] ?? 99;
|
||||||
$bPriority = $priority[$b['action_type']] ?? 99;
|
// $bPriority = $priority[$b['action_type']] ?? 99;
|
||||||
|
|
||||||
return $aPriority <=> $bPriority;
|
// return $aPriority <=> $bPriority;
|
||||||
}
|
// }
|
||||||
|
|
||||||
// Otherwise sort by policy_issue_date
|
// // Otherwise sort by policy_issue_date
|
||||||
return strtotime($a['policy_issue_month']) <=> strtotime($b['policy_issue_month']);
|
// return strtotime($a['policy_issue_month']) <=> strtotime($b['policy_issue_month']);
|
||||||
});
|
// });
|
||||||
|
|
||||||
// dd($result);
|
// dd($result);
|
||||||
|
|
||||||
@ -3141,6 +3141,57 @@
|
|||||||
// $result = array_values($filtered);
|
// $result = array_values($filtered);
|
||||||
// dd($result);
|
// dd($result);
|
||||||
|
|
||||||
|
$keys = [];
|
||||||
|
$filtered = [];
|
||||||
|
|
||||||
|
foreach ($result as $row) {
|
||||||
|
|
||||||
|
// Normalize endorsement number
|
||||||
|
$endorsement_number = !empty($row['endorsement_no'])? $row['endorsement_no'] : '-';
|
||||||
|
|
||||||
|
// $month = $row['policy_issue_month'];
|
||||||
|
$reward = (float) ($row['reward'] ?? 0);
|
||||||
|
// $billed_amt = (float) ($row['billed_amt'] ?? 0);
|
||||||
|
|
||||||
|
// if (
|
||||||
|
// ($monthCount[$month] ?? 0) > 1 &&
|
||||||
|
// $reward == 0.00 &&
|
||||||
|
// $billed_amt == 0.00
|
||||||
|
// ) {
|
||||||
|
// continue;
|
||||||
|
// }
|
||||||
|
|
||||||
|
if ($reward > 0 && ($row['billed_amt'] ?? 0) == 0.00) {
|
||||||
|
$row['total_irda_amt'] = '0.00';
|
||||||
|
$row['billed_amt'] = $reward;
|
||||||
|
$rewardFlag = 'R'; // Reward row
|
||||||
|
} else {
|
||||||
|
$rewardFlag = 'N'; // Normal row
|
||||||
|
}
|
||||||
|
|
||||||
|
// ✅ Stable & deterministic key
|
||||||
|
$key = implode('|', [
|
||||||
|
$row['statement_month'],
|
||||||
|
$row['insurer_name'],
|
||||||
|
$row['policy_no'],
|
||||||
|
$endorsement_number,
|
||||||
|
$rewardFlag
|
||||||
|
]);
|
||||||
|
|
||||||
|
// Prefer "statement uploaded"
|
||||||
|
if ($row['statement_uploaded'] === 'statement uploaded') {
|
||||||
|
$filtered[$key] = $row;
|
||||||
|
$keys[$key] = true;
|
||||||
|
}
|
||||||
|
// Keep no-statement only if uploaded not present
|
||||||
|
elseif (!isset($keys[$key])) {
|
||||||
|
$filtered[$key] = $row;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reindex for output
|
||||||
|
$result = array_values($filtered);
|
||||||
|
|
||||||
// --------------------------------------------------------------------------------------------------------
|
// --------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user