FIX_CD_TRANSACTION_SUMMERY_QUERY : RV
This commit is contained in:
parent
95b801018d
commit
c13ba6d3db
@ -281,7 +281,8 @@ class ClientPolicyModel extends Model
|
||||
->join('policy_type', 'policy_type.id = client_policy.policy_type_id', 'left')
|
||||
->where('cash_deposit.client_id', $clientId)
|
||||
->where('cash_deposit.insurer_id', $insurerId)
|
||||
->where('cash_deposit.is_active', 1);
|
||||
->where('cash_deposit.is_active', 1)
|
||||
->where('cd_master.is_active', 1);
|
||||
// ->where('cash_deposit.cd_ac_pk = cd_master.id')
|
||||
if(!empty($cd_ac_pk)){
|
||||
$query->where('cash_deposit.cd_ac_pk', $cd_ac_pk);
|
||||
@ -354,15 +355,32 @@ class ClientPolicyModel extends Model
|
||||
|
||||
public function getDepositlistsummary($id)
|
||||
{
|
||||
return $this->db->table('cash_deposit')
|
||||
->select('insurer_id, cd_ac_pk')
|
||||
->select('SUM(CASE WHEN transaction_type = "Credit" THEN amount ELSE -amount END) AS balance')
|
||||
->where('client_id', $id)
|
||||
->where('is_active', 1)
|
||||
->groupBy('insurer_id')
|
||||
// ->groupBy('cd_ac_pk')
|
||||
->get()
|
||||
->getResult();
|
||||
// return $this->db->table('cash_deposit')
|
||||
// ->select('insurer_id, cd_ac_pk, balance')
|
||||
// // ->select('SUM(CASE WHEN transaction_type = "Credit" THEN amount ELSE -amount END) AS balance')
|
||||
// ->where('client_id', $id)
|
||||
// ->where('is_active', 1)
|
||||
// ->orderBy('id', 'desc')
|
||||
// ->groupBy('insurer_id')
|
||||
// // ->groupBy('cd_ac_pk')
|
||||
// ->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
|
||||
";
|
||||
|
||||
return $this->db->query($sql, [$id])->getResult();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -47,6 +47,7 @@ class InsurerModel extends Model
|
||||
->where('client_policy.insurer_id', $insurerId)
|
||||
->where('client_policy.client_id', $client_id)
|
||||
->where('cd_master.id = client_policy.cd_ac_pk')
|
||||
->where('cd_master.is_active', 1)
|
||||
->get();
|
||||
|
||||
if ($query->resultID->num_rows > 0) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user