From 25754f089f69c55601fdf2774b7e5be1145e151a Mon Sep 17 00:00:00 2001 From: "venkatesh.r" Date: Wed, 23 Jul 2025 12:18:03 +0530 Subject: [PATCH] FIX_POLICY_TRANSACTION_REMOVE : RV --- app/Controllers/ClientController.php | 33 ++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/app/Controllers/ClientController.php b/app/Controllers/ClientController.php index d8cf5c71..10aeea5f 100755 --- a/app/Controllers/ClientController.php +++ b/app/Controllers/ClientController.php @@ -1436,21 +1436,54 @@ class ClientController extends AdminController ->where('employees.emp_status', 'active') ->where('employees.is_active', 1) ->countAllResults(); + if ($emp_details == 0) { $update = $this->clientPolicyModel->where('id', $id)->set($data)->update(); if ($update) { + + $policy_transaction_update = $this->deactivatePolicyTransactionsPolicy($id); + return $this->respond(['status' => true, 'code' => 200], 200); } else { return $this->respond(['status' => false, 'code' => 404, 'message' => 'Failed to remove policy'], 200); } + } else { return $this->respond(['status' => false, 'code' => 404, 'message' => 'The policy has active employees'], 200); } } + public function deactivatePolicyTransactionsPolicy($clientPolicyId) + { + // Deactivate policy_transaction records + $this->policyTransactionModel + ->where('client_policy_id', $clientPolicyId) + ->set(['is_active' => 0]) + ->update(); + + // Get related policy_transaction IDs + $transactionIds = $this->policyTransactionModel + ->select('id') + ->where('client_policy_id', $clientPolicyId) + ->findAll(); + + $ids = array_column($transactionIds, 'id'); + + // Deactivate related pt_co_share records + if (!empty($ids)) { + $this->PTCOShareDetailsModel + ->whereIn('pt_id', $ids) + ->set(['is_active' => 0]) + ->update(); + } + } + + + + public function createClientPolicyPremium() {