Merge remote-tracking branch 'origin/dev' into dev
This commit is contained in:
commit
47037483af
@ -660,18 +660,25 @@ class ClientController extends AdminController
|
|||||||
}
|
}
|
||||||
|
|
||||||
// In your controller
|
// In your controller
|
||||||
public function deposit($id = null, $requestFrom = null, $policyId = null)
|
public function deposit($ClientId = null, $requestFrom = null, $policyId = null)
|
||||||
{
|
{
|
||||||
$headerData['tab_name'] = 'Client Deposit';
|
$headerData['tab_name'] = 'Client Deposit';
|
||||||
$headerData['page_name'] = 'Clients';
|
$headerData['page_name'] = 'Clients';
|
||||||
|
|
||||||
$data['clientName'] = $this->clientModel->where('id', (int)$id)->find();
|
if (is_string($ClientId) && preg_match('/^[a-f0-9]{32}$/i', $ClientId))
|
||||||
$data['clientData'] = $this->clientPolicyModel->getinsurerswithclientid($id, $policyId);
|
{
|
||||||
|
$data['clientName'] = $this->clientModel->where('md5(id)', $ClientId)->find();
|
||||||
|
}else {
|
||||||
|
$data['clientName'] = $this->clientModel->where('id', $ClientId)->find();
|
||||||
|
}
|
||||||
|
|
||||||
$data['depositsummary'] = $this->clientPolicyModel->getDepositlistsummary($id);
|
|
||||||
|
$data['clientData'] = $this->clientPolicyModel->getinsurerswithclientid($ClientId, $policyId);
|
||||||
|
|
||||||
|
$data['depositsummary'] = $this->clientPolicyModel->getDepositlistsummary($ClientId);
|
||||||
|
|
||||||
// Fetch associated insurer names and balances
|
// Fetch associated insurer names and balances
|
||||||
$balances = $this->clientPolicyModel->getBalances($id);
|
$balances = $this->clientPolicyModel->getBalances($ClientId);
|
||||||
$data['balances'] = $balances;
|
$data['balances'] = $balances;
|
||||||
|
|
||||||
// dd($data);
|
// dd($data);
|
||||||
|
|||||||
@ -1665,10 +1665,10 @@ class EmployeeRestController extends AdminController
|
|||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
|
|
||||||
$client = $this->clientModel->where('id', $this->request->getGet('client_id'))->first();
|
$client = $this->clientModel->where('md5(id)', $this->request->getGet('client_id'))->first();
|
||||||
if (!empty($client)) {
|
if (!empty($client)) {
|
||||||
$client['client_logo'] = base_url() . 'public/uploads/logo/' . $client['client_logo'];
|
$client['client_logo'] = base_url() . 'public/uploads/logo/' . $client['client_logo'];
|
||||||
$clientPolicy = $this->clientPolicyModel->where('client_id', $this->request->getGet('client_id'))
|
$clientPolicy = $this->clientPolicyModel->where('md5(client_id)', $this->request->getGet('client_id'))
|
||||||
->where('client_branch_id', $this->request->getGet('client_branch_id'))->findAll();
|
->where('client_branch_id', $this->request->getGet('client_branch_id'))->findAll();
|
||||||
return $this->respond(['status' => 'success', 'code' => 200, 'data' => ['client' => $client, 'client_policy' => $clientPolicy]], 200);
|
return $this->respond(['status' => 'success', 'code' => 200, 'data' => ['client' => $client, 'client_policy' => $clientPolicy]], 200);
|
||||||
} else {
|
} else {
|
||||||
@ -2307,7 +2307,7 @@ class EmployeeRestController extends AdminController
|
|||||||
|
|
||||||
|
|
||||||
$ClientPolicyData = $this->clientPolicyModel->select('client_policy.id as client_policy_id , client_policy.client_id as client_id, client_policy.policy_type_id as policy_type_id, client_policy.is_addon as is_addon , client_policy.open_for_enrollment as OpenForEnrollment , client_policy.inception_type as inception_type, client_policy.policy_no as policy_no, client_policy.insurer_id as insurer_id, DATE_FORMAT(client_policy.policy_end_date, "%d-%m-%Y") AS policy_expiry_date ')
|
$ClientPolicyData = $this->clientPolicyModel->select('client_policy.id as client_policy_id , client_policy.client_id as client_id, client_policy.policy_type_id as policy_type_id, client_policy.is_addon as is_addon , client_policy.open_for_enrollment as OpenForEnrollment , client_policy.inception_type as inception_type, client_policy.policy_no as policy_no, client_policy.insurer_id as insurer_id, DATE_FORMAT(client_policy.policy_end_date, "%d-%m-%Y") AS policy_expiry_date ')
|
||||||
->where('client_policy.client_id', $this->request->getGet('client_id'))
|
->where('md5(client_policy.client_id)', $this->request->getGet('client_id'))
|
||||||
->where('client_policy.client_branch_id', $this->request->getGet('client_branch_id'))
|
->where('client_policy.client_branch_id', $this->request->getGet('client_branch_id'))
|
||||||
->where('client_policy.is_active', 1)
|
->where('client_policy.is_active', 1)
|
||||||
->where('client_policy.policy_status', $this->request->getGet('policy_status'))
|
->where('client_policy.policy_status', $this->request->getGet('policy_status'))
|
||||||
@ -2555,7 +2555,7 @@ class EmployeeRestController extends AdminController
|
|||||||
$builder->where('tm.is_active', 1);
|
$builder->where('tm.is_active', 1);
|
||||||
|
|
||||||
if ($client_id > 0) {
|
if ($client_id > 0) {
|
||||||
$builder->where('tm.client_id', $client_id);
|
$builder->where('md5(tm.client_id)', $client_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($from_date) && !empty($to_date)) {
|
if (!empty($from_date) && !empty($to_date)) {
|
||||||
@ -4468,7 +4468,21 @@ class EmployeeRestController extends AdminController
|
|||||||
return $this->respondCreated(['status' => false, 'message' => 'Client is required', 'data' => []]);
|
return $this->respondCreated(['status' => false, 'message' => 'Client is required', 'data' => []]);
|
||||||
}
|
}
|
||||||
|
|
||||||
$client_data = $this->clientModel->where('id', $post_data['client_id'])->first();
|
// Handle raw client_id vs MD5
|
||||||
|
if (is_string($post_data['client_id']) && preg_match('/^[a-f0-9]{32}$/i', $post_data['client_id'])) {
|
||||||
|
$client_data = $this->clientModel->where('MD5(id)', $post_data['client_id'])->first();
|
||||||
|
} else {
|
||||||
|
$client_data = $this->clientModel->where('id', $post_data['client_id'])->first();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(empty($client_data)){
|
||||||
|
return $this->respondCreated(['status' => false, 'message' => 'Invalid Client Id', 'data' => []]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$post_data['client_id'] = $client_data['id'];
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// print_r($client_data); die;
|
// print_r($client_data); die;
|
||||||
|
|
||||||
if($client_data['hr_file_processed_by'] == 1){
|
if($client_data['hr_file_processed_by'] == 1){
|
||||||
|
|||||||
@ -759,6 +759,8 @@ class RestAuthenticationController extends AdminController
|
|||||||
|
|
||||||
$decoded = json_decode($HRAccessData['allowed_modules'], true);
|
$decoded = json_decode($HRAccessData['allowed_modules'], true);
|
||||||
$getAllhrData[$key]['allowed_modules'] = $decoded;
|
$getAllhrData[$key]['allowed_modules'] = $decoded;
|
||||||
|
$HRAccessData['pre_client_id'] = md5($HRAccessData['pre_client_id']);
|
||||||
|
$HRAccessData['post_client_id'] = md5($HRAccessData['post_client_id']);
|
||||||
|
|
||||||
$token = JWTToken::encode($HRAccessData);
|
$token = JWTToken::encode($HRAccessData);
|
||||||
$getAllhrData[$key]['token'] = $token;
|
$getAllhrData[$key]['token'] = $token;
|
||||||
|
|||||||
@ -183,9 +183,14 @@ class ClientPolicyModel extends Model
|
|||||||
->join('clients', 'clients.id = client_policy.client_id')
|
->join('clients', 'clients.id = client_policy.client_id')
|
||||||
->join('insurers', 'insurers.id = client_policy.insurer_id')
|
->join('insurers', 'insurers.id = client_policy.insurer_id')
|
||||||
->join('insurer_branch', 'client_policy.insurer_branch_id = insurer_branch.id', 'left')
|
->join('insurer_branch', 'client_policy.insurer_branch_id = insurer_branch.id', 'left')
|
||||||
->join('cd_master', 'cd_master.insurer_id = insurers.id AND cd_master.client_id = client_policy.client_id')
|
->join('cd_master', 'cd_master.insurer_id = insurers.id AND cd_master.client_id = client_policy.client_id');
|
||||||
->where('client_policy.client_id', $id)
|
// ->where('client_policy.client_id', $id)
|
||||||
->where('cd_master.id = client_policy.cd_ac_pk')
|
if (is_string($id) && preg_match('/^[a-f0-9]{32}$/i', $id)) {
|
||||||
|
$builder->where('MD5(client_policy.client_id)', $id);
|
||||||
|
} else {
|
||||||
|
$builder->where('client_policy.client_id', $id);
|
||||||
|
}
|
||||||
|
$builder->where('cd_master.id = client_policy.cd_ac_pk')
|
||||||
->where('cd_master.is_active', 1)
|
->where('cd_master.is_active', 1)
|
||||||
->groupBy('client_policy.client_id')
|
->groupBy('client_policy.client_id')
|
||||||
->groupBy('client_policy.insurer_id')
|
->groupBy('client_policy.insurer_id')
|
||||||
@ -248,14 +253,33 @@ class ClientPolicyModel extends Model
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function getClientById($id)
|
// public function getClientById($id)
|
||||||
|
// {
|
||||||
|
// $query = $this->db->table('clients')->getWhere(['id' => $id]);
|
||||||
|
// // Debug statement
|
||||||
|
// return $query->getRow();
|
||||||
|
// }
|
||||||
|
|
||||||
|
public function getClientById($client_id)
|
||||||
{
|
{
|
||||||
$query = $this->db->table('clients')->getWhere(['id' => $id]);
|
if (empty($client_id)) {
|
||||||
// Debug statement
|
return null;
|
||||||
return $query->getRow();
|
}
|
||||||
|
|
||||||
|
$builder = $this->db->table('clients');
|
||||||
|
|
||||||
|
// MD5 vs normal ID check
|
||||||
|
if (is_string($client_id) && preg_match('/^[a-f0-9]{32}$/i', $client_id)) {
|
||||||
|
$builder->where('MD5(id)', $client_id);
|
||||||
|
} else {
|
||||||
|
$builder->where('id', $client_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $builder->get()->getRow();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public function getDepositData($clientId, $insurerId, $cd_ac_pk = null, $subTypeOptions = null)
|
public function getDepositData($clientId, $insurerId, $cd_ac_pk = null, $subTypeOptions = null)
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -285,9 +309,16 @@ class ClientPolicyModel extends Model
|
|||||||
->join('client_policy', 'client_policy.id = cash_deposit.client_policy_id', 'left')
|
->join('client_policy', 'client_policy.id = cash_deposit.client_policy_id', 'left')
|
||||||
->join('cd_master', 'cd_master.id = cash_deposit.cd_ac_pk', 'left')
|
->join('cd_master', 'cd_master.id = cash_deposit.cd_ac_pk', 'left')
|
||||||
// ->join('policies', 'policies.id = client_policy.policy_id', 'left')
|
// ->join('policies', 'policies.id = client_policy.policy_id', 'left')
|
||||||
->join('policy_type', 'policy_type.id = client_policy.policy_type_id', 'left')
|
->join('policy_type', 'policy_type.id = client_policy.policy_type_id', 'left');
|
||||||
->where('cash_deposit.client_id', $clientId)
|
// ->where('cash_deposit.client_id', $clientId)
|
||||||
->where('cash_deposit.insurer_id', $insurerId)
|
if (!empty($clientId)) {
|
||||||
|
if (is_string($clientId) && preg_match('/^[a-f0-9]{32}$/i', $clientId)) {
|
||||||
|
$query->where('MD5(cash_deposit.client_id)', $clientId);
|
||||||
|
} else {
|
||||||
|
$query->where('cash_deposit.client_id', $clientId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$query->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('cd_master.is_active', 1);
|
||||||
// ->where('cash_deposit.cd_ac_pk = cd_master.id')
|
// ->where('cash_deposit.cd_ac_pk = cd_master.id')
|
||||||
@ -300,12 +331,56 @@ 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
|
||||||
|
// $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 sub_type = 3 THEN amount ELSE 0 END) AS total_refund')
|
||||||
|
// ->where('client_id', $clientId)
|
||||||
|
// ->where('insurer_id', $insurerId)
|
||||||
|
// ->where('cd_ac_pk', $cd_ac_pk)
|
||||||
|
// ->where('cash_deposit.is_active', 1)
|
||||||
|
// ->get()
|
||||||
|
// ->getRow();
|
||||||
|
|
||||||
|
// // dd($this->db->getLastQuery());
|
||||||
|
// return $data;
|
||||||
|
// }
|
||||||
|
|
||||||
public function getDepositSummary($clientId, $insurerId, $cd_ac_pk)
|
public function getDepositSummary($clientId, $insurerId, $cd_ac_pk)
|
||||||
{
|
{
|
||||||
|
if (empty($clientId)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Build SAFE client condition (NO BINDS!)
|
||||||
|
if (is_string($clientId) && preg_match('/^[a-f0-9]{32}$/i', $clientId)) {
|
||||||
|
$clientCondition = 'MD5(client_id) = ' . $this->db->escape($clientId);
|
||||||
|
} else {
|
||||||
|
$clientCondition = 'client_id = ' . $this->db->escape($clientId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* -------------------------------------------------
|
||||||
|
Subquery: latest balance
|
||||||
|
------------------------------------------------- */
|
||||||
$subQuery = $this->db->table('cash_deposit')
|
$subQuery = $this->db->table('cash_deposit')
|
||||||
->select('balance')
|
->select('balance')
|
||||||
->where('client_id', $clientId)
|
->where($clientCondition, null, false)
|
||||||
->where('insurer_id', $insurerId)
|
->where('insurer_id', $insurerId)
|
||||||
->where('cd_ac_pk', $cd_ac_pk)
|
->where('cd_ac_pk', $cd_ac_pk)
|
||||||
->where('is_active', 1)
|
->where('is_active', 1)
|
||||||
@ -313,14 +388,15 @@ class ClientPolicyModel extends Model
|
|||||||
->limit(1)
|
->limit(1)
|
||||||
->getCompiledSelect();
|
->getCompiledSelect();
|
||||||
|
|
||||||
// Fetch the sum of credit and debit transactions and calculate the balance
|
/* -------------------------------------------------
|
||||||
|
Main query: totals
|
||||||
|
------------------------------------------------- */
|
||||||
$data = $this->db->table('cash_deposit')
|
$data = $this->db->table('cash_deposit')
|
||||||
->select("($subQuery) AS balance", false)
|
->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 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($clientCondition, null, false)
|
||||||
->where('insurer_id', $insurerId)
|
->where('insurer_id', $insurerId)
|
||||||
->where('cd_ac_pk', $cd_ac_pk)
|
->where('cd_ac_pk', $cd_ac_pk)
|
||||||
->where('cash_deposit.is_active', 1)
|
->where('cash_deposit.is_active', 1)
|
||||||
@ -330,6 +406,8 @@ class ClientPolicyModel extends Model
|
|||||||
// dd($this->db->getLastQuery());
|
// dd($this->db->getLastQuery());
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Inside your clientPolicyModel
|
// Inside your clientPolicyModel
|
||||||
// Inside your clientPolicyModel
|
// Inside your clientPolicyModel
|
||||||
// public function getDepositDataWithBalance($clientId, $insurerId)
|
// public function getDepositDataWithBalance($clientId, $insurerId)
|
||||||
@ -402,6 +480,35 @@ class ClientPolicyModel extends Model
|
|||||||
// ORDER BY cd.id DESC
|
// ORDER BY cd.id DESC
|
||||||
// ";
|
// ";
|
||||||
|
|
||||||
|
// $sql = "
|
||||||
|
// SELECT cd.insurer_id, cd.cd_ac_pk, cd.balance
|
||||||
|
// FROM cash_deposit cd
|
||||||
|
// JOIN cd_master cdm ON cdm.id = cd.cd_ac_pk
|
||||||
|
// JOIN (
|
||||||
|
// SELECT MAX(id) AS max_id
|
||||||
|
// FROM cash_deposit
|
||||||
|
// 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;
|
||||||
|
// ";
|
||||||
|
|
||||||
|
// $binds = ['id'=>(int)$id];
|
||||||
|
// return $this->db->query($sql,$binds)->getResult();
|
||||||
|
|
||||||
|
$whereClient = 'cd.client_id = :id:';
|
||||||
|
$subWhereClient = 'client_id = :id:';
|
||||||
|
|
||||||
|
$binds = ['id' => $id];
|
||||||
|
|
||||||
|
// 🔐 MD5 handling
|
||||||
|
if (is_string($id) && preg_match('/^[a-f0-9]{32}$/i', $id)) {
|
||||||
|
$whereClient = 'MD5(cd.client_id) = :id:';
|
||||||
|
$subWhereClient = 'MD5(client_id) = :id:';
|
||||||
|
}
|
||||||
|
|
||||||
$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
|
||||||
@ -409,16 +516,17 @@ class ClientPolicyModel extends Model
|
|||||||
JOIN (
|
JOIN (
|
||||||
SELECT MAX(id) AS max_id
|
SELECT MAX(id) AS max_id
|
||||||
FROM cash_deposit
|
FROM cash_deposit
|
||||||
WHERE is_active = 1 AND client_id = :id:
|
WHERE is_active = 1 AND {$subWhereClient}
|
||||||
GROUP BY insurer_id, cd_ac_pk
|
GROUP BY insurer_id, cd_ac_pk
|
||||||
) latest ON latest.max_id = cd.id
|
) latest ON latest.max_id = cd.id
|
||||||
JOIN insurers on cd.insurer_id = insurers.id
|
JOIN insurers ON cd.insurer_id = insurers.id
|
||||||
WHERE cd.is_active = 1 AND cd.client_id = :id: AND cdm.is_active = 1
|
WHERE cd.is_active = 1
|
||||||
ORDER BY cd.insurer_id;
|
AND {$whereClient}
|
||||||
|
AND cdm.is_active = 1
|
||||||
|
ORDER BY cd.insurer_id
|
||||||
";
|
";
|
||||||
|
|
||||||
$binds = ['id'=>(int)$id];
|
return $this->db->query($sql, $binds)->getResult();
|
||||||
return $this->db->query($sql,$binds)->getResult();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -295,7 +295,10 @@ class EmployeePolicyModel extends Model
|
|||||||
->orderBy('emp.emp_code', 'ASC')
|
->orderBy('emp.emp_code', 'ASC')
|
||||||
->orderBy('employee_polices.employee_id', 'ASC');
|
->orderBy('employee_polices.employee_id', 'ASC');
|
||||||
// Conditionally add where clauses
|
// Conditionally add where clauses
|
||||||
if ($client_id != 0 && !empty($client_id)) {
|
if (is_string($client_id) && preg_match('/^[a-f0-9]{32}$/i', $client_id)) {
|
||||||
|
// MD5 hash → compare using md5()
|
||||||
|
$result->where('md5(emp.client_id)', $client_id);
|
||||||
|
}else if ($client_id != 0 && !empty($client_id)) {
|
||||||
$result->where('emp.client_id', $client_id);
|
$result->where('emp.client_id', $client_id);
|
||||||
}
|
}
|
||||||
if ($branch_id != 0 && !empty($branch_id)) {
|
if ($branch_id != 0 && !empty($branch_id)) {
|
||||||
|
|||||||
@ -37,27 +37,67 @@ class InsurerModel extends Model
|
|||||||
->getResult();
|
->getResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// public function getInsurerName($insurerId, $client_id)
|
||||||
|
// {
|
||||||
|
// // Fetch the insurer name based on the insurer ID
|
||||||
|
// $query = $this->db->table('client_policy')
|
||||||
|
// ->select('insurers.id, insurers.name, cd_master.cd_ac_no as cd_master_account_no')
|
||||||
|
// ->join('insurers', 'insurers.id = client_policy.insurer_id')
|
||||||
|
// ->join('cd_master', 'cd_master.insurer_id = insurers.id AND cd_master.client_id = client_policy.client_id')
|
||||||
|
// ->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) {
|
||||||
|
// $result = $query->getRow();
|
||||||
|
// return $result;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// return null; // or handle accordingly if the insurer is not found
|
||||||
|
// }
|
||||||
|
|
||||||
public function getInsurerName($insurerId, $client_id)
|
public function getInsurerName($insurerId, $client_id)
|
||||||
{
|
{
|
||||||
// Fetch the insurer name based on the insurer ID
|
$builder = $this->db->table('client_policy')
|
||||||
$query = $this->db->table('client_policy')
|
->select('
|
||||||
->select('insurers.id, insurers.name, cd_master.cd_ac_no as cd_master_account_no')
|
insurers.id,
|
||||||
->join('insurers', 'insurers.id = client_policy.insurer_id')
|
insurers.name,
|
||||||
->join('cd_master', 'cd_master.insurer_id = insurers.id AND cd_master.client_id = client_policy.client_id')
|
cd_master.cd_ac_no AS cd_master_account_no
|
||||||
->where('client_policy.insurer_id', $insurerId)
|
')
|
||||||
->where('client_policy.client_id', $client_id)
|
->join('insurers', 'insurers.id = client_policy.insurer_id')
|
||||||
->where('cd_master.id = client_policy.cd_ac_pk')
|
->join(
|
||||||
->where('cd_master.is_active', 1)
|
'cd_master',
|
||||||
->get();
|
'cd_master.insurer_id = insurers.id
|
||||||
|
AND cd_master.client_id = client_policy.client_id
|
||||||
|
AND cd_master.id = client_policy.cd_ac_pk
|
||||||
|
AND cd_master.is_active = 1'
|
||||||
|
)
|
||||||
|
->where('client_policy.insurer_id', $insurerId);
|
||||||
|
|
||||||
if ($query->resultID->num_rows > 0) {
|
// Handle raw client_id vs MD5
|
||||||
$result = $query->getRow();
|
if (!empty($client_id)) {
|
||||||
return $result;
|
if (is_string($client_id) && preg_match('/^[a-f0-9]{32}$/i', $client_id)) {
|
||||||
|
$builder->where('MD5(client_policy.client_id)', $client_id);
|
||||||
|
} else {
|
||||||
|
$builder->where('client_policy.client_id', $client_id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return null; // or handle accordingly if the insurer is not found
|
$result = $builder
|
||||||
|
->groupBy([
|
||||||
|
'insurers.id',
|
||||||
|
'cd_master.cd_ac_no'
|
||||||
|
])
|
||||||
|
->limit(1)
|
||||||
|
->get()
|
||||||
|
->getRow();
|
||||||
|
|
||||||
|
return $result ?? null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function getInsurerTemplateByInsurerID($insurer_id)
|
public function getInsurerTemplateByInsurerID($insurer_id)
|
||||||
{
|
{
|
||||||
$insurer_data = $this->db->table('insurer_excel_export_template')
|
$insurer_data = $this->db->table('insurer_excel_export_template')
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user