diff --git a/app/Config/Routes.php b/app/Config/Routes.php index f7426af0..a6472417 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -21,6 +21,7 @@ $routes->get("view", "EmployeeController::viewECard/$1"); // $routes->get("exportQCRandRFQ", "LeadsController::exportQCRandRFQ"); $routes->get("smapletest", "ClientController::smapletest"); $routes->get("testMailAttachments", "ClientController::testMailAttachments"); +$routes->get("updatePolicyTermsKey", "ClientController::updatePolicyTermsKey"); $routes->post("add_advertise_image", "AppContentManagementController::add_advertise_image"); $routes->get("add_image_index", "AppContentManagementController::add_image_index"); @@ -314,6 +315,7 @@ $routes->group("/util", ["filter" => "authMVC"], function ($routes) { $routes->get('log_list', 'EmployeeController::listLogs'); $routes->get('view_log/(:any)', 'EmployeeController::viewLog/$1'); $routes->get('download_log/(:any)', 'EmployeeController::downloadLog/$1'); + $routes->post('checkDuplicateTableFieldValue', 'ClientController::checkDuplicateTableFieldValue'); }); $routes->group("policy_tranction", ["filter" => "authMVC"], function ($routes) { @@ -323,6 +325,7 @@ $routes->group("policy_tranction", ["filter" => "authMVC"], function ($routes) { $routes->post("create", "PolicyTransactionController::createInceptionPolicy"); $routes->get("list/(:any)", "PolicyTransactionController::getInceptionDataForEdit/$1"); $routes->get("remove/(:any)", "PolicyTransactionController::removeCDMaster/$1"); + $routes->get("removePolicyTransaction/(:any)", "PolicyTransactionController::removePolicyTransaction/$1"); }); $routes->group("endorsement", ["filter" => "authMVC"], function ($routes) { diff --git a/app/Controllers/ClientController.php b/app/Controllers/ClientController.php index 7da74a72..06f29c30 100755 --- a/app/Controllers/ClientController.php +++ b/app/Controllers/ClientController.php @@ -118,6 +118,23 @@ class ClientController extends AdminController $this->leadsModel = new LeadsModel(); } + public function checkDuplicateTableFieldValue() + { + $table = $this->request->getPost('table'); + $field = $this->request->getPost('field'); + $value = $this->request->getPost('value'); + + // Load the database if not already loaded + $db = db_connect(); + + // Perform the query + $builder = $db->table($table); + $isDuplicate = $builder->where($field, $value)->countAllResults() > 0; + + // Return the result + return $this->response->setJSON(['isDuplicate' => $isDuplicate]); + } + public function smapletest() { $headers = [ @@ -3562,4 +3579,101 @@ class ClientController extends AdminController dd($result); } + public function updatePolicyTermsKey() + { + + $data = $this->clientPolicyModel + ->where("policy_terms IS NOT NULL AND policy_terms <> ''") + ->where('policy_type_id', 2) + ->where('is_active', 1) + ->findAll(); + + for ($i = 0; $i < count($data); $i++) { + + if (isset($data[$i]['policy_terms']) && !empty($data[$i]['policy_terms'])) { + $policyTerms = json_decode($data[$i]['policy_terms'], true); + } else { + continue; + } + + // Set default value of copayzonewisecopay to "empty" + $ans = isset($policyTerms['copayzonewisecopay']) ? $policyTerms['copayzonewisecopay'] : 'empty'; + + + // Initialize an empty array for the ordered policy terms + $orderedPolicyTerms = []; + + // Add copayzonewisecopay and copayzonewisecopaydata if they exist_ + if (isset($policyTerms['copayzonewisecopay'])) { + + $orderedPolicyTerms['copayzonewisecopay'] = $policyTerms['copayzonewisecopay']; + $orderedPolicyTerms['co_pay_details'] = isset($policyTerms['co_pay_details']) ? $policyTerms['co_pay_details'] : ''; + } + + + // Add ailmentcapping and ailmentcappingdata if they exist_ + if (isset($policyTerms['ailmentcapping'])) { + $orderedPolicyTerms['ailmentcapping'] = $policyTerms['ailmentcapping']; + $orderedPolicyTerms['ailment_capping_details'] = isset($policyTerms['ailment_capping_details']) ? $policyTerms['ailment_capping_details'] : ''; + } + + + // Now add the rest of the policy terms that are not copayzonewisecopay, copayzonewisecopaydata, ailmentcapping, or ailmentcapping_data_ + foreach ($policyTerms as $key => $value) { + if (!in_array($key, ['copayzonewisecopay', 'co_pay_details', 'ailmentcapping', 'ailment_capping_details'])) { + $orderedPolicyTerms[$key] = $value; + } + } + + + // Re-encode the ordered policy terms + $updatedPolicyTerms = json_encode($orderedPolicyTerms); + + + // Update the policyterms in the database_ + $this->clientPolicyModel->update($data[$i]['id'], ['policy_terms' => $updatedPolicyTerms]); + + + // Handle different conditions for copayzonewisecopay + if (strtolower($ans) == "nil" || $ans == 0) { + // If copayzonewisecopay is "nil" or 0, reset it to 0 and add copayzonewisecopaydata as empty_ + if (isset($orderedPolicyTerms['copayzonewisecopay'])) { + $orderedPolicyTerms['copayzonewisecopay'] = 0; + $orderedPolicyTerms['co_pay_details'] = ""; + } + + + // Rebuild the array after modification + foreach ($policyTerms as $key => $value) { + if (!in_array($key, ['copayzonewisecopay', 'co_pay_details'])) { + $orderedPolicyTerms[$key] = $value; + } + } + + + $updatedPolicyTerms = json_encode($orderedPolicyTerms); + $this->clientPolicyModel->update($data[$i]['id'], ['policy_terms' => $updatedPolicyTerms]); + continue; + } elseif ($ans != 'empty' && $ans !== 'Nil' && $ans !== null && $ans != '' && $ans != 0) { + // If copayzonewisecopay has a valid value, update it + if (isset($orderedPolicyTerms['copayzonewisecopay'])) { + $orderedPolicyTerms['copayzonewisecopay'] = 1; + $orderedPolicyTerms['co_pay_details'] = $ans; + } + + + // Rebuild the array after modification + foreach ($policyTerms as $key => $value) { + if (!in_array($key, ['copayzonewisecopay', 'co_pay_details'])) { + $orderedPolicyTerms[$key] = $value; + } + } + + + $updatedPolicyTerms = json_encode($orderedPolicyTerms); + $this->clientPolicyModel->update($data[$i]['id'], ['policy_terms' => $updatedPolicyTerms]); + } + } + } + } diff --git a/app/Controllers/PolicyTransactionController.php b/app/Controllers/PolicyTransactionController.php index 1c5526c6..452aa207 100644 --- a/app/Controllers/PolicyTransactionController.php +++ b/app/Controllers/PolicyTransactionController.php @@ -690,6 +690,7 @@ class PolicyTransactionController extends BaseController ->join('client_policy', 'policy_transaction.client_policy_id = client_policy.id', 'left') ->join('policy_type', 'client_policy.policy_type_id = policy_type.id', 'left') ->where('policy_transaction.id', $id) + ->where('policy_transaction.is_active', 1) ->first(); // $data['policy_issue_date'] = (isset($data['policy_issue_date']) && $data['policy_issue_date'] !== null && $data['policy_issue_date'] !== '') @@ -810,6 +811,21 @@ class PolicyTransactionController extends BaseController } + public function removePolicyTransaction($id) + { + if ($id) { + + $data['is_active'] = 0; + $this->policyTransactionModel->where('id', $id)->set($data)->update(); + $this->PTCOShareDetailsModel->where('pt_id', $id)->set($data)->update(); + return $this->respond(['status' => true, 'code' => 200, 'message' => 'Policy Transaction removed successfully'], 200); + + } else { + + return $this->respond(['status' => false, 'code' => 404, 'message' => 'Failed to remove policy transaction'], 200); + } + } + //------------------------------------------------------------------------------------------------ // Policy Transaction Endorsement @@ -962,6 +978,7 @@ class PolicyTransactionController extends BaseController ->where('action_type', 'inception') ->where('client_id', $this->request->getPost('client_id')) ->where('client_policy_id', $this->request->getPost('client_policy_id')) + ->where('policy_transaction.is_active', 1) ->first(); $data['tsi'] = generate_tsi_code($issue_type['issue_type'] ?? 1); @@ -1089,6 +1106,7 @@ class PolicyTransactionController extends BaseController ->join('clients', 'clients.id = policy_transaction.client_id') ->join('client_policy', 'policy_transaction.client_policy_id = client_policy.id', 'left') ->where('policy_transaction.id', $id) + ->where('policy_transaction.is_active', 1) ->first(); // $data['policy_start_date'] = empty($data['policy_start_date']) ? '' : date('d/m/Y', strtotime($data['s_date'])); @@ -1278,6 +1296,8 @@ class PolicyTransactionController extends BaseController ->join('pt_co_share_details', 'policy_transaction.id = pt_co_share_details.pt_id') ->join('insurer_statements', 'pt_co_share_details.statement_id = insurer_statements.id') ->where('policy_transaction.id', $pt_id) + ->where('policy_transaction.is_active', 1) + ->where('pt_co_share_details.is_active', 1) ->where('pt_co_share_details.statement_id IS NOT NULL') ->where('insurer_statements.invoice_no IS NOT NULL') ->countAllResults(); diff --git a/app/Models/PolicyTransactionModel.php b/app/Models/PolicyTransactionModel.php index 3fa28edd..ba54a5ce 100644 --- a/app/Models/PolicyTransactionModel.php +++ b/app/Models/PolicyTransactionModel.php @@ -386,7 +386,11 @@ class PolicyTransactionModel extends Model $builder->orderBy('policy_transaction.id', 'desc'); - return $builder->get()->getResultArray(); + $result = $builder->get()->getResultArray(); + + // dd($this->db->getLastQuery()); + + return $result; } public function getEndorsementTranctionListData($start_date = 0, $end_date = 0, $client_id = 0, $insurer_id = 0, $policy_type_id = 0, $date_type = 0, $issuer = 0, $status = 0) diff --git a/app/Views/layout/footer.php b/app/Views/layout/footer.php index 39b2f769..bef8a1fc 100755 --- a/app/Views/layout/footer.php +++ b/app/Views/layout/footer.php @@ -862,6 +862,69 @@ } + + \ No newline at end of file diff --git a/app/Views/policy_transaction_inception_form.php b/app/Views/policy_transaction_inception_form.php index 4f6c0f36..2097e3a9 100644 --- a/app/Views/policy_transaction_inception_form.php +++ b/app/Views/policy_transaction_inception_form.php @@ -317,7 +317,7 @@