FIX_POLICY_TRANSACTION_REMOVE : RV

This commit is contained in:
VENKATESHWARAN 2025-07-23 12:18:03 +05:30
parent c12fa35557
commit 25754f089f

View File

@ -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()
{