From 28d31f9c7da17f16e814e15fef01cff04aec7370 Mon Sep 17 00:00:00 2001 From: "venkatesh.r" Date: Tue, 10 Jun 2025 19:17:45 +0530 Subject: [PATCH] FIX_LIVE_ISSUES : RV --- app/Controllers/ClientController.php | 16 +++++++--- app/Controllers/EmpDataServiceController.php | 33 +++++++++++++------- app/Controllers/LeadsController.php | 2 +- app/Helpers/DepositHelper.php | 4 +-- app/Models/ClientPolicyModel.php | 8 +++-- app/Models/EmployeePolicyModel.php | 4 +-- 6 files changed, 43 insertions(+), 24 deletions(-) diff --git a/app/Controllers/ClientController.php b/app/Controllers/ClientController.php index 35acba3c..f256d374 100755 --- a/app/Controllers/ClientController.php +++ b/app/Controllers/ClientController.php @@ -665,7 +665,8 @@ class ClientController extends AdminController $data['insurerName'] = $this->insurerModel->getInsurerName($insurerId, $clientId); $data['depositdata'] = $this->clientPolicyModel->getdepositData($clientId, $insurerId, $cd_ac_pk); $data['clientData'] = $this->clientPolicyModel->getClientById($clientId); - $data['deposiamount'] = $this->clientPolicyModel->getDepositSummary($clientId, $insurerId); + $data['deposiamount'] = $this->clientPolicyModel->getDepositSummary($clientId, $insurerId, $cd_ac_pk); + $data['cd_ac_pk'] = $cd_ac_pk; // dd($data); @@ -690,9 +691,16 @@ class ClientController extends AdminController ->where('insurer_id', $insurer_id) ->where('is_active', 1) ->first(); - // Prepare the array with data - $date = \DateTime::createFromFormat('d/m/Y', $record_date); - $record_date = $date->format('Y-m-d'); + + + if(!empty($record_date)){ + // Prepare the array with data + $date = \DateTime::createFromFormat('d/m/Y', $record_date); + $record_date = $date->format('Y-m-d'); + }else{ + $record_date = null; + } + $data = [ 'amount' => $this->request->getPost('amount'), 'sub_type_id' => $this->request->getPost('sub_type_id'), diff --git a/app/Controllers/EmpDataServiceController.php b/app/Controllers/EmpDataServiceController.php index a7cadc9e..3dbf91d5 100755 --- a/app/Controllers/EmpDataServiceController.php +++ b/app/Controllers/EmpDataServiceController.php @@ -3541,20 +3541,29 @@ class EmpDataServiceController extends BaseController // return ['status' => 'error', 'message' => 'Employees table data is empty or null.']; // } - // Check if $employee_policy_table_data is null or empty - if (empty($employee_policy_table_data)) { - return ['status' => 'error', 'message' => 'Employee policy table data is empty or null.']; - } + if ($file['insurer_or_tpa'] == 'insurer') { - // Check if $emp_endorsement_table_data is null or empty - if (empty($emp_endorsement_table_data)) { - return ['status' => 'error', 'message' => 'Employee endorsement table data is empty or null.']; - } + // Check if $employee_policy_table_data is null or empty + if (empty($employee_policy_table_data)) { + $this->batchFileModel->update($file_id, [ + 'status' => "failed", + ]); + return ['status' => 'error', 'message' => 'Employee policy table data is empty or null.']; + } - // $this->employeeModel->updateBatch($employees_table_data, 'id'); - $this->employeePolicyModel->updateBatch($employee_policy_table_data, 'id'); - $this->employeePolicyModel->bulkUpdateForEndorsement($emp_endorsement_table_data); - $this->storeEndorsementNumber($file_id, $endorsement_id, $enrollment_file_id); + // Check if $emp_endorsement_table_data is null or empty + if (empty($emp_endorsement_table_data)) { + $this->batchFileModel->update($file_id, [ + 'status' => "failed", + ]); + return ['status' => 'error', 'message' => 'Employee endorsement table data is empty or null.']; + } + + // $this->employeeModel->updateBatch($employees_table_data, 'id'); + $this->employeePolicyModel->updateBatch($employee_policy_table_data, 'id'); + $this->employeePolicyModel->bulkUpdateForEndorsement($emp_endorsement_table_data); + $this->storeEndorsementNumber($file_id, $endorsement_id, $enrollment_file_id); + } // Update batch file status and amount $this->batchFileModel->update($file_id, [ diff --git a/app/Controllers/LeadsController.php b/app/Controllers/LeadsController.php index 7692b3d3..fc14bdc8 100644 --- a/app/Controllers/LeadsController.php +++ b/app/Controllers/LeadsController.php @@ -448,7 +448,7 @@ class LeadsController extends BaseController 'source_policy_start_date' => $data['source_policy_start_date'] ?? null, 'source_policy_end_date' => $data['source_policy_end_date'] ?? null, - 'claim_history' => $data['claim_history'] + 'claim_history' => $data['claim_history'] ?? 0 ]; } // print_r($processedData);die(); diff --git a/app/Helpers/DepositHelper.php b/app/Helpers/DepositHelper.php index 5137cc5c..9549f8a1 100755 --- a/app/Helpers/DepositHelper.php +++ b/app/Helpers/DepositHelper.php @@ -102,10 +102,10 @@ class DepositHelper // $getLastBalanceParams = [$clientId, $insurerId]; if(empty($cd_ac_pk)){ - $getLastBalanceQuery = "SELECT balance FROM cash_deposit WHERE cd_ac_no = ? AND is_active = 1 ORDER BY created_at DESC LIMIT 1"; + $getLastBalanceQuery = "SELECT balance FROM cash_deposit WHERE cd_ac_no = ? AND is_active = 1 ORDER BY id DESC LIMIT 1"; $getLastBalanceParams = [$cd_ac_no]; }else{ - $getLastBalanceQuery = "SELECT balance FROM cash_deposit WHERE cd_ac_pk = ? AND is_active = 1 ORDER BY created_at DESC LIMIT 1"; + $getLastBalanceQuery = "SELECT balance FROM cash_deposit WHERE cd_ac_pk = ? AND is_active = 1 ORDER BY id DESC LIMIT 1"; $getLastBalanceParams = [$cd_ac_pk]; } diff --git a/app/Models/ClientPolicyModel.php b/app/Models/ClientPolicyModel.php index c6801878..59f05958 100755 --- a/app/Models/ClientPolicyModel.php +++ b/app/Models/ClientPolicyModel.php @@ -257,7 +257,7 @@ class ClientPolicyModel extends Model } - public function getDepositSummary($clientId, $insurerId) + public function getDepositSummary($clientId, $insurerId, $cd_ac_pk) { // Fetch the sum of credit and debit transactions and calculate the balance return $this->db->table('cash_deposit') @@ -267,6 +267,7 @@ class ClientPolicyModel extends Model ->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(); @@ -319,11 +320,12 @@ class ClientPolicyModel extends Model public function getDepositlistsummary($id) { return $this->db->table('cash_deposit') - ->select('insurer_id') + ->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') + // ->groupBy('cd_ac_pk') ->get() ->getResult(); } diff --git a/app/Models/EmployeePolicyModel.php b/app/Models/EmployeePolicyModel.php index b5369144..dc0be3ab 100755 --- a/app/Models/EmployeePolicyModel.php +++ b/app/Models/EmployeePolicyModel.php @@ -1061,10 +1061,10 @@ class EmployeePolicyModel extends Model } $status_condition = "{$insurer_or_tpa}" === 'tpa' - ? "employee_polices.status = 'active' AND employees.emp_status = 'active'" + ? "employee_polices.status = 'inactive' AND employees.emp_status = 'active'" : "employee_polices.status = 'active' AND employees.emp_status = 'active'"; - $endorsement_condition = "{$insurer_or_tpa}" === 'tpa' ? "AND (a.endorsement_id IS NULL OR a.endorsement_id = '')" : "AND (a.endorsement_id IS NULL OR a.endorsement_id = '')"; + $endorsement_condition = "{$insurer_or_tpa}" === 'tpa' ? "AND (a.endorsement_id IS NOT NULL OR a.endorsement_id != '')" : "AND (a.endorsement_id IS NULL OR a.endorsement_id = '')"; $query = $this->db->query(" SELECT DISTINCT