FIX_CD_DEPOSIT_SUMMARY_AND_TRANSACTION : RV
This commit is contained in:
parent
cd2f69e1dc
commit
ce8308c898
@ -2406,8 +2406,9 @@ class EmployeeRestController extends AdminController
|
||||
$temp['cd_ac_pk'] = $value->cd_ac_pk;
|
||||
$temp['insurer_name'] = $value->insurer_name;
|
||||
$temp['cd_master_account_no'] = $value->cd_master_account_no;
|
||||
if (isset($result['balances'][$temp['insurer_id']])) {
|
||||
$balance = $result['balances'][$temp['insurer_id']]->balance;
|
||||
|
||||
if (isset($result['balances'][$temp['insurer_id'].'-'.$temp['cd_ac_pk']])) {
|
||||
$balance = $result['balances'][$temp['insurer_id'].'-'.$temp['cd_ac_pk']]->balance;
|
||||
$temp['balance'] = $balance;
|
||||
} else {
|
||||
$temp['balance'] = "N/A";
|
||||
|
||||
@ -295,11 +295,23 @@ class ClientPolicyModel extends Model
|
||||
|
||||
public function getDepositSummary($clientId, $insurerId, $cd_ac_pk)
|
||||
{
|
||||
|
||||
$subQuery = $this->db->table('cash_deposit')
|
||||
->select('balance')
|
||||
->where('client_id', $clientId)
|
||||
->where('insurer_id', $insurerId)
|
||||
->where('cd_ac_pk', $cd_ac_pk)
|
||||
->where('is_active', 1)
|
||||
->orderBy('id', 'DESC')
|
||||
->limit(1)
|
||||
->getCompiledSelect();
|
||||
|
||||
// Fetch the sum of credit and debit transactions and calculate the balance
|
||||
return $this->db->table('cash_deposit')
|
||||
$data = $this->db->table('cash_deposit')
|
||||
->select("($subQuery) AS balance", false)
|
||||
->select('SUM(CASE WHEN transaction_type = "Credit" THEN amount ELSE 0 END) AS total_credit')
|
||||
->select('SUM(CASE WHEN transaction_type = "Debit" THEN amount ELSE 0 END) AS total_withdraw')
|
||||
->select('SUM(CASE WHEN transaction_type = "Credit" THEN amount ELSE -amount END) AS balance')
|
||||
// ->select('SUM(CASE WHEN transaction_type = "Credit" THEN amount ELSE -amount END) AS balance')
|
||||
->select('SUM(CASE WHEN sub_type = 3 THEN amount ELSE 0 END) AS total_refund')
|
||||
->where('client_id', $clientId)
|
||||
->where('insurer_id', $insurerId)
|
||||
@ -307,6 +319,9 @@ class ClientPolicyModel extends Model
|
||||
->where('cash_deposit.is_active', 1)
|
||||
->get()
|
||||
->getRow();
|
||||
|
||||
// dd($this->db->getLastQuery());
|
||||
return $data;
|
||||
}
|
||||
// Inside your clientPolicyModel
|
||||
// Inside your clientPolicyModel
|
||||
@ -347,7 +362,8 @@ class ClientPolicyModel extends Model
|
||||
|
||||
foreach ($depositsummary as $summary) {
|
||||
$insurerId = $summary->insurer_id;
|
||||
$balances[$insurerId] = $summary;
|
||||
$cd_ac_pk = $summary->cd_ac_pk;
|
||||
$balances[$insurerId . '-'. $cd_ac_pk] = $summary;
|
||||
}
|
||||
|
||||
return $balances;
|
||||
@ -366,20 +382,35 @@ class ClientPolicyModel extends Model
|
||||
// ->get()
|
||||
// ->getResult();
|
||||
|
||||
// $sql = "
|
||||
// SELECT cd.insurer_id, cd.cd_ac_pk, cd.balance
|
||||
// FROM cash_deposit cd
|
||||
// INNER JOIN (
|
||||
// SELECT insurer_id, MAX(id) AS max_id
|
||||
// FROM cash_deposit
|
||||
// WHERE client_id = ?
|
||||
// AND is_active = 1
|
||||
// GROUP BY insurer_id
|
||||
// ) latest ON cd.insurer_id = latest.insurer_id AND cd.id = latest.max_id
|
||||
// ORDER BY cd.id DESC
|
||||
// ";
|
||||
|
||||
$sql = "
|
||||
SELECT cd.insurer_id, cd.cd_ac_pk, cd.balance
|
||||
FROM cash_deposit cd
|
||||
INNER JOIN (
|
||||
SELECT insurer_id, MAX(id) AS max_id
|
||||
JOIN cd_master cdm ON cdm.id = cd.cd_ac_pk
|
||||
JOIN (
|
||||
SELECT MAX(id) AS max_id
|
||||
FROM cash_deposit
|
||||
WHERE client_id = ?
|
||||
AND is_active = 1
|
||||
GROUP BY insurer_id
|
||||
) latest ON cd.insurer_id = latest.insurer_id AND cd.id = latest.max_id
|
||||
ORDER BY cd.id DESC
|
||||
WHERE is_active = 1 AND client_id = $id
|
||||
GROUP BY insurer_id, cd_ac_pk
|
||||
) latest ON latest.max_id = cd.id
|
||||
JOIN insurers on cd.insurer_id = insurers.id
|
||||
WHERE cd.is_active = 1 AND cd.client_id = $id AND cdm.is_active = 1
|
||||
ORDER BY cd.insurer_id;
|
||||
";
|
||||
|
||||
return $this->db->query($sql, [$id])->getResult();
|
||||
return $this->db->query($sql)->getResult();
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -38,9 +38,10 @@
|
||||
<td>₹
|
||||
<?php
|
||||
$insurerId = $value->insurer_id;
|
||||
$cd_ac_pk = $value->cd_ac_pk;
|
||||
// Check if the balance information exists for the insurer
|
||||
if (isset($balances[$insurerId])) {
|
||||
$balance = $balances[$insurerId]->balance;
|
||||
if (isset($balances[$insurerId . '-'. $cd_ac_pk])) {
|
||||
$balance = $balances[$insurerId . '-'. $cd_ac_pk]->balance;
|
||||
echo $balance;
|
||||
} else {
|
||||
echo "N/A"; // Display "Not Available" if balance information is not present
|
||||
|
||||
Loading…
Reference in New Issue
Block a user