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['cd_ac_pk'] = $value->cd_ac_pk;
|
||||||
$temp['insurer_name'] = $value->insurer_name;
|
$temp['insurer_name'] = $value->insurer_name;
|
||||||
$temp['cd_master_account_no'] = $value->cd_master_account_no;
|
$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;
|
$temp['balance'] = $balance;
|
||||||
} else {
|
} else {
|
||||||
$temp['balance'] = "N/A";
|
$temp['balance'] = "N/A";
|
||||||
|
|||||||
@ -295,11 +295,23 @@ class ClientPolicyModel extends Model
|
|||||||
|
|
||||||
public function getDepositSummary($clientId, $insurerId, $cd_ac_pk)
|
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
|
// 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 = "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 = "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')
|
->select('SUM(CASE WHEN sub_type = 3 THEN amount ELSE 0 END) AS total_refund')
|
||||||
->where('client_id', $clientId)
|
->where('client_id', $clientId)
|
||||||
->where('insurer_id', $insurerId)
|
->where('insurer_id', $insurerId)
|
||||||
@ -307,6 +319,9 @@ class ClientPolicyModel extends Model
|
|||||||
->where('cash_deposit.is_active', 1)
|
->where('cash_deposit.is_active', 1)
|
||||||
->get()
|
->get()
|
||||||
->getRow();
|
->getRow();
|
||||||
|
|
||||||
|
// dd($this->db->getLastQuery());
|
||||||
|
return $data;
|
||||||
}
|
}
|
||||||
// Inside your clientPolicyModel
|
// Inside your clientPolicyModel
|
||||||
// Inside your clientPolicyModel
|
// Inside your clientPolicyModel
|
||||||
@ -347,7 +362,8 @@ class ClientPolicyModel extends Model
|
|||||||
|
|
||||||
foreach ($depositsummary as $summary) {
|
foreach ($depositsummary as $summary) {
|
||||||
$insurerId = $summary->insurer_id;
|
$insurerId = $summary->insurer_id;
|
||||||
$balances[$insurerId] = $summary;
|
$cd_ac_pk = $summary->cd_ac_pk;
|
||||||
|
$balances[$insurerId . '-'. $cd_ac_pk] = $summary;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $balances;
|
return $balances;
|
||||||
@ -366,20 +382,35 @@ class ClientPolicyModel extends Model
|
|||||||
// ->get()
|
// ->get()
|
||||||
// ->getResult();
|
// ->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 = "
|
$sql = "
|
||||||
SELECT cd.insurer_id, cd.cd_ac_pk, cd.balance
|
SELECT cd.insurer_id, cd.cd_ac_pk, cd.balance
|
||||||
FROM cash_deposit cd
|
FROM cash_deposit cd
|
||||||
INNER JOIN (
|
JOIN cd_master cdm ON cdm.id = cd.cd_ac_pk
|
||||||
SELECT insurer_id, MAX(id) AS max_id
|
JOIN (
|
||||||
|
SELECT MAX(id) AS max_id
|
||||||
FROM cash_deposit
|
FROM cash_deposit
|
||||||
WHERE client_id = ?
|
WHERE is_active = 1 AND client_id = $id
|
||||||
AND is_active = 1
|
GROUP BY insurer_id, cd_ac_pk
|
||||||
GROUP BY insurer_id
|
) latest ON latest.max_id = cd.id
|
||||||
) latest ON cd.insurer_id = latest.insurer_id AND cd.id = latest.max_id
|
JOIN insurers on cd.insurer_id = insurers.id
|
||||||
ORDER BY cd.id DESC
|
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>₹
|
<td>₹
|
||||||
<?php
|
<?php
|
||||||
$insurerId = $value->insurer_id;
|
$insurerId = $value->insurer_id;
|
||||||
|
$cd_ac_pk = $value->cd_ac_pk;
|
||||||
// Check if the balance information exists for the insurer
|
// Check if the balance information exists for the insurer
|
||||||
if (isset($balances[$insurerId])) {
|
if (isset($balances[$insurerId . '-'. $cd_ac_pk])) {
|
||||||
$balance = $balances[$insurerId]->balance;
|
$balance = $balances[$insurerId . '-'. $cd_ac_pk]->balance;
|
||||||
echo $balance;
|
echo $balance;
|
||||||
} else {
|
} else {
|
||||||
echo "N/A"; // Display "Not Available" if balance information is not present
|
echo "N/A"; // Display "Not Available" if balance information is not present
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user