diff --git a/app/Config/App.php b/app/Config/App.php index ec06b887..884c19f1 100644 --- a/app/Config/App.php +++ b/app/Config/App.php @@ -16,7 +16,7 @@ class App extends BaseConfig * * http://example.com/ */ - public string $baseURL = ''; + public string $baseURL = 'http://localhost/nhance/'; /** * Allowed Hostnames in the Site URL other than the hostname in the baseURL. diff --git a/app/Config/Database.php b/app/Config/Database.php index e2450ec1..388b1b03 100644 --- a/app/Config/Database.php +++ b/app/Config/Database.php @@ -51,10 +51,10 @@ class Database extends Config */ public array $tests = [ 'DSN' => '', - 'hostname' => '127.0.0.1', - 'username' => '', - 'password' => '', - 'database' => ':memory:', + 'hostname' => '119.18.54.85', + 'username' => 'venbaehn_nhance_user1', + 'password' => 'iM~X7(cR+}A-', + 'database' => 'venbaehn_nhance', 'DBDriver' => 'SQLite3', 'DBPrefix' => 'db_', // Needed to ensure we're working correctly with prefixes live. DO NOT REMOVE FOR CI DEVS 'pConnect' => false, diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 3a8d0e15..72310f66 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -33,7 +33,26 @@ $routes->group("/client", ["filter" => "authMVC"], function($routes){ $routes->get("list", "ClientController::index"); $routes->get("create", "ClientController::clientOnboarding"); + $routes->get('deposit/(:num)', 'ClientController::deposit/$1'); + // application/config/routes.php + +// Add a route for the view_Deposit method +$routes->get('view_deposit/(:num)', 'ClientController::view_Deposit/$1'); +$routes->get('createtransaction', 'ClientController::createtransaction'); + +$routes->post('save_deposit', 'ClientController::saveDeposit'); + + + + + + + // $routes->get('view_Deposit/(:num)/(:num)','ClientController/view_Deposit/$1/$2'); + + + $routes->get("list/(:any)", "ClientController::editClientOnboarding/$1"); + $routes->group("general", ["filter" => "authMVC"], function($routes){ $routes->post("create", "ClientController::createClientGeneralInfo"); @@ -49,22 +68,33 @@ $routes->group("/client", ["filter" => "authMVC"], function($routes){ $routes->group("relation", ["filter" => "authMVC"], function($routes){ $routes->post("create", "ClientController::createClientRelation"); $routes->post("edit", "ClientController::editClientRelation"); - }); + }); + $routes->group("policy", ["filter" => "authMVC"], function($routes){ $routes->post("create", "ClientController::createClientPolicy"); $routes->post("edit", "ClientController::editClientPolicy"); $routes->get("list/(:any)", "ClientController::getClientPolicyById/$1"); + $routes->post("policyGMCTerms", "ClientController::policyGMCTerms"); + $routes->get("getterms", "ClientController::getterms"); }); + $routes->group("kyc", ["filter" => "authMVC"], function($routes){ $routes->post("create", "ClientController::createClientKYCInfo"); $routes->post("edit", "ClientController::editClientKYCInfo"); $routes->get("list/(:any)", "ClientController::getKycDocsById/$1"); $routes->get("delete/(:any)", "ClientController::deleteClientKycDocs/$1"); }); + $routes->group("premimum", ["filter" => "authMVC"], function($routes){ $routes->post("create", "ClientController::createClientPolicyPremium"); $routes->post("edit", "ClientController::editClientPolicyPremium"); }); + + $routes->group("terms", ["filter" => "authMVC"], function($routes){ + $routes->post("gpa_create", "ClientController::policyGPATerms"); + $routes->post("edit", "ClientController::editClientPolicyPremium"); + }); + }); diff --git a/app/Controllers/ClientController.php b/app/Controllers/ClientController.php index 554c8a2f..5d5029bf 100644 --- a/app/Controllers/ClientController.php +++ b/app/Controllers/ClientController.php @@ -1,7 +1,7 @@ userModel = new UserModel(); $this->clientBranchModel = new ClientBranchModel(); $this->clientKYCDocsModel = new ClientKYCDocsModel(); + $this->clientDepositModel = new ClientDepositModel(); $this->clientPolicyModel = new ClientPolicyModel(); $this->clientRMModel = new ClientRMModel(); $this->insurerBranchModel = new InsurerBranchModel(); @@ -74,8 +77,11 @@ class ClientController extends AdminController $this->tpaModel = new TPAModel(); $this->stateModel = new StateModel(); $this->policyGridModel = new PolicyGridModel(); - $this->policyPremium1Model = new PolicyPremium1Model(); - $this->policyPremium2Model = new PolicyPremium2Model(); + $this->policyPremium1Model = new PolicyPremium1Model(); + $this->policyPremium2Model = new PolicyPremium2Model(); + $this->employeeModel = new EmployeeModel(); + + } public function index() @@ -116,6 +122,79 @@ class ClientController extends AdminController echo view('layout/footer'); } + // In your controller + public function deposit($id = null) + { + $headerData['page_name'] = 'Client Deposit'; + + $data['clientData'] = $this->clientPolicyModel->getinsurerswithclientid($id); + $data['depositsummary'] = $this->clientPolicyModel->getDepositlistsummary($id); + + // Fetch associated insurer names and balances + $balances = $this->clientPolicyModel->getBalances($id); + $data['balances'] = $balances; + + echo view('layout/header', $headerData); + echo view('client_deposit_list', $data); + echo view('layout/footer'); + } + + + +public function view_Deposit($insurerId) { + // Load your model to fetch data based on $clientId and $insurerId + $subTypeOptions = [ + 1 => 'Deposit', + 2 => 'Adjustment', + 3 => 'Deletion', + // Add more options as needed + ]; + $data['subTypeOptions'] = $subTypeOptions; + $headerData['page_name'] = 'Client Deposit'; + $data['insurerName']= $this->insurerModel->getInsurerName($insurerId); + $loggedInUserID = get_session_userid(); + // $data['clientData']= $this->clientPolicyModel->getinsurerswithinsurenceid($insurerId); + $clientId = $this->request->getGet('client_id'); + $data['depositdata']= $this->clientPolicyModel->getdepositData($clientId,$insurerId); + $data['clientData'] = $this->clientPolicyModel->getClientById($clientId); + $data['deposiamount'] = $this->clientPolicyModel->getDepositSummary($clientId, $insurerId); + + + // print_r($data['depositdata'] );die; + // Load the view for the new list page + echo view('layout/header', $headerData); + echo view('view_deposit',$data); + echo view('layout/footer'); +} + + + + +public function saveDeposit() +{ + // Retrieve form data from POST request + $loggedInUserID = get_session_userid(); + + // Prepare the array with data + $data = [ + 'amount' => $this->request->getPost('amount'), + 'sub_type_id' => $this->request->getPost('sub_type_id'), + 'client_id' => $this->request->getPost('client_id'), + 'insurer_id' => $this->request->getPost('insurer_id'), + 'description' => $this->request->getPost('description'), + 'transaction_type' => $this->request->getPost('transaction_type') ?: 'Credit', + 'updated_by' => 1, // You need to set the correct value for updated_by + ]; + + // Call the saveDeposit function from DepositHelper + $response = DepositHelper::saveDeposit($data, $loggedInUserID); + + // Return a boolean value based on success + return $this->response->setJSON(['success' => $response['success']]); +} + + + public function editClientOnboarding($id = null) { @@ -157,9 +236,11 @@ class ClientController extends AdminController $insert = $this->clientModel->insert($data); if($insert){ $client_data = $this->clientModel->where(['id' => $insert, 'is_active' => 1])->first(); - echo json_encode(array("status" => true , 'data' => $client_data)); + return $this->respond(['status' => true,'code' => 200,'data' => $client_data], 200); + }else{ - echo json_encode(array("status" => false)); + return $this->respond(['status' => false,'code' => 404,'message' => 'no data found'], 200); + } } @@ -171,9 +252,9 @@ class ClientController extends AdminController $data['updated_by'] = get_session_userid(); $update = $this->clientModel->update($id,$data); if($update){ - echo json_encode(array("status" => true , 'data' => $data)); + return $this->respond(['status' => true,'code' => 200,'data' => $data], 200); }else{ - echo json_encode(array("status" => false)); + return $this->respond(['status' => false,'code' => 404,'message' => 'no data found'], 200); } } @@ -192,9 +273,9 @@ class ClientController extends AdminController if($insert){ $kycDocs = $this->clientKYCDocsModel->where('client_id',$this->request->getPost('client_id'))->findAll(); - echo json_encode(array("status" => true , 'data' => $kycDocs, 'file_name' => $File)); + return $this->respond(['status' => true,'code' => 200,'data' => $kycDocs, 'file_name' => $File], 200); }else{ - echo json_encode(array("status" => false)); + return $this->respond(['status' => false,'code' => 404,'message' => 'no data found'], 200); } } @@ -213,9 +294,10 @@ class ClientController extends AdminController $insert = $this->clientKYCDocsModel->insert($data); if($insert){ $kycDocs = $this->clientKYCDocsModel->getKycDocsName($id); - echo json_encode(array("status" => true , 'data' => $kycDocs)); + return $this->respond(['status' => true,'code' => 200,'data' => $kycDocs], 200); }else{ - echo json_encode(array()); + return $this->respond(['status' => false,'code' => 404,'message' => 'no data found'], 200); + } } @@ -224,9 +306,9 @@ class ClientController extends AdminController $delete = $this->clientKYCDocsModel->where('kyc_doc_type_id', $id)->delete(); if($delete){ - echo json_encode(array("status" => true, 'id' => $id )); + return $this->respond(['status' => true,'code' => 200,'id' => $id], 200); }else{ - echo json_encode(array("status" => false)); + return $this->respond(['status' => false,'code' => 404,'message' => 'no data found'], 200); } } @@ -235,9 +317,9 @@ class ClientController extends AdminController $delete = $this->clientKYCDocsModel->where('id', $id)->delete(); if($delete){ - echo json_encode(array("status" => true, 'id' => $id )); + return $this->respond(['status' => true,'code' => 200,'id' => $id], 200); }else{ - echo json_encode(array("status" => false)); + return $this->respond(['status' => false,'code' => 404,'message' => 'no data found'], 200); } } @@ -271,9 +353,9 @@ class ClientController extends AdminController } if ($inserted) { - echo json_encode(array("status" => true, 'data' => $this->request->getPost())); + return $this->respond(['status' => true,'code' => 200,'data' => $this->request->getPost()], 200); } else { - echo json_encode(array("status" => false)); + return $this->respond(['status' => false,'code' => 404,'message' => 'no data found'], 200); } } @@ -323,9 +405,9 @@ class ClientController extends AdminController $lastQuery = $this->clientRMModel->getLastQuery(); if ($inserted) { - echo json_encode(array("status" => true, 'data' => $this->request->getPost(), "place" => 'edit')); + return $this->respond(['status' => true,'code' => 200,'data' => $this->request->getPost(), "place" => 'edit'], 200); } else { - echo json_encode(array("status" => false, "place" => 'edit')); + return $this->respond(['status' => false,'code' => 404,"place" => 'edit', 'message' => 'no data found'], 200); } } @@ -355,9 +437,9 @@ class ClientController extends AdminController if($insert){ $branchData = $this->clientBranchModel->where('client_id', $this->request->getPost('client_id'))->findAll(); - echo json_encode(array("status" => true , 'data' => $branchData)); + return $this->respond(['status' => true,'code' => 200,'data' => $branchData], 200); }else{ - echo json_encode(array("status" => false)); + return $this->respond(['status' => false,'code' => 404, 'message' => 'no data found'], 200); } } @@ -392,9 +474,9 @@ class ClientController extends AdminController if($insert){ $branchData = $this->clientBranchModel->where('client_id', $client_id)->findAll(); - echo json_encode(array("status" => true , 'data' => $branchData)); + return $this->respond(['status' => true,'code' => 200,'data' => $branchData], 200); }else{ - echo json_encode(array("status" => false)); + return $this->respond(['status' => false,'code' => 404, 'message' => 'no data found'], 200); } } @@ -419,12 +501,12 @@ class ClientController extends AdminController $data['client_id'] = $this->request->getPost('client_id'); - $data['insured'] = $this->request->getPost('insured'); $data['no_of_lives'] = $this->request->getPost('no_of_lives'); $data['policy_status'] = $this->request->getPost('policy_status'); $data['no_of_employees'] = $this->request->getPost('no_of_employees'); $data['earned_premium_date'] = change_date_format($this->request->getPost('earned_premium_date'), 'd-m-Y', 'Y-m-d'); - $data['claims_incurred_date'] = change_date_format($this->request->getPost('claims_incurred_date'), 'd-m-Y', 'Y-m-d'); $data['incurred_claims_ratio'] = $this->request->getPost('incurred_claims_ratio'); + $data['claims_incurred_date'] = change_date_format($this->request->getPost('claims_incurred_date'), 'd-m-Y', 'Y-m-d'); + $data['incurred_claims_ratio'] = $this->request->getPost('incurred_claims_ratio'); $data['no_lives_at_inception'] = $this->request->getPost('no_lives_at_inception'); $data['premium_paid_at_inception'] = $this->request->getPost('premium_paid_at_inception'); $data['claims_experience_for_last_3_years'] = $this->request->getPost('claims_experience_for_last_3_years'); @@ -442,9 +524,9 @@ class ClientController extends AdminController $insert = $this->clientPolicyModel->insert($data); if($insert){ $clientPoliceData = $this->clientPolicyModel->getClientPolicyByClientId($this->request->getPost('client_id')); - echo json_encode(array("status" => true , 'data' => $clientPoliceData, 'method' => 'CERATE')); + return $this->respond(['status' => true,'code' => 200,'data' => $clientPoliceData, 'method' => 'CERATE'], 200); }else{ - echo json_encode(array("status" => false)); + return $this->respond(['status' => false,'code' => 404, 'message' => 'no data found'], 200); } } @@ -494,13 +576,12 @@ class ClientController extends AdminController if($insert){ $clientPoliceData = $this->clientPolicyModel->getClientPolicyByClientId($client_id); - echo json_encode(array("status" => true , 'data' => $clientPoliceData , 'method' => 'EDIT')); + return $this->respond(['status' => true,'code' => 200,'data' => $clientPoliceData, 'method' => 'EDIT'], 200); }else{ - echo json_encode(array("status" => false)); + return $this->respond(['status' => false,'code' => 404, 'message' => 'no data found'], 200); } } - public function createClientPolicyPremium() { $policy_type = $this->request->getPost('policy_type'); @@ -572,9 +653,10 @@ class ClientController extends AdminController } if($insert){ - echo json_encode(array("status" => true , 'data' => $data)); + return $this->respond(['status' => true,'code' => 200,'data' => $data], 200); }else{ - echo json_encode(array("status" => false , 'data' => $data)); + return $this->respond(['status' => false,'code' => 404, 'data' => $data,'message' => 'no data found'], 200); + } } @@ -590,11 +672,11 @@ class ClientController extends AdminController $this->myLogger->logme('error','getKycDocsById function called'); if($id){ $kyc_docs_data = $this->kycDocsModel->where(['kyc_type_id' => $id, 'is_active' => 1])->findAll(); - echo json_encode(array("status" => true , 'data' => $kyc_docs_data)); $this->myLogger->logme('error','getKycDocs status TRUE'); + return $this->respond(['status' => true,'code' => 200,'data' => $kyc_docs_data], 200); }else{ - echo json_encode(array("status" => false)); $this->myLogger->logme('error','getKycDocs status FALSE'); + return $this->respond(['status' => false,'code' => 404, 'message' => 'no data found'], 200); } } @@ -603,9 +685,9 @@ class ClientController extends AdminController $this->myLogger->logme('error','getPolicesByInsurerId function called'); if($id){ $police_data = $this->policesModel->where(['insurer_id' => $id, 'is_active' => 1])->findAll(); - echo json_encode(array("status" => true , 'data' => $police_data)); + return $this->respond(['status' => true,'code' => 200,'data' => $police_data], 200); }else{ - echo json_encode(array("status" => false)); + return $this->respond(['status' => false,'code' => 404, 'message' => 'no data found'], 200); } } @@ -616,9 +698,9 @@ class ClientController extends AdminController if($id){ $branch_data = $this->clientBranchModel->where(['id' => $id, 'is_active' => 1])->first(); $branch_contact_data = $this->levelContactModel->where(['ref_id' => $id, 'contact_type'=>'client', 'is_active' => 1])->findAll(); - echo json_encode(array("status" => true , 'data' => $branch_data, 'contact' => $branch_contact_data)); + return $this->respond(['status' => true,'code' => 200,'data' => $branch_data, 'contact' => $branch_contact_data], 200); }else{ - echo json_encode(array("status" => false)); + return $this->respond(['status' => false,'code' => 404, 'message' => 'no data found'], 200); } } @@ -630,9 +712,9 @@ class ClientController extends AdminController $client_policy_data = $this->clientPolicyModel->where(['id' => $id, 'is_active' => 1])->first(); $insurer_id = $client_policy_data['insurer_id']; $polices = $this->policesModel->where(['insurer_id' => $insurer_id, 'is_active' => 1])->findAll(); - echo json_encode(array("status" => true , 'data' => $client_policy_data, 'policy' => $polices)); + return $this->respond(['status' => true,'code' => 200,'data' => $client_policy_data, "insurer_id" => $client_policy_data['insurer_id'], 'policy' => $polices], 200); }else{ - echo json_encode(array("status" => false)); + return $this->respond(['status' => false,'code' => 404, 'message' => 'no data found'], 200); } } @@ -643,6 +725,19 @@ class ClientController extends AdminController $policy_id = $this->request->getGet('policy_id'); $client_id = $this->request->getGet('client_id'); + $emp_count = $this->employeeModel ->join('client_policy cp',"employees.client_id = cp.client_id") + ->join('employee_polices ep',"cp.id = ep.client_policy_id AND employees.id = ep.employee_id") + ->where("employees.client_id",$client_id) + ->where("employees.emp_status",'active') + ->countAllResults(); + + if($emp_count = 0){ + $emp_count = true; + }else{ + $emp_count = false; + } + + $data = $this->policesModel->getPolicyPremium($policy_id); $pattern = '/gmc/i'; $subject = $data[0]->policy_type; @@ -654,18 +749,248 @@ class ClientController extends AdminController $results = $this->policyGridModel->like('policy_type', $search_term)->findAll(); if($search_term === 'GPA'){ - $premiumData = $this->policyPremium1Model->where(['client_id' => $client_id, 'client_policy_id' => $policy_id, 'is_active' => 1])->findAll(); }else{ $premiumData = $this->policyPremium2Model->where(['client_id' => $client_id, 'client_policy_id' => $policy_id, 'is_active' => 1])->findAll(); - } - // echo '
';
         // print_r($results);
         // print_r($data[0]->policy_type); die;
-        echo json_encode(array("status" => true , 'data' => $results, 'premiumData' => $premiumData));
+        return $this->respond(['status' => true,'code' => 200,'data' => $results, 'premiumData' => $premiumData, 'count' => $emp_count], 200);
+
+    }
+
+    public function policyGMCTerms()
+    {
+        
+        try {
+            $this->myLogger->logme('error','Terms CREATE function called');
+            // print_r($this->request->getPost());
+            $client_id = $this->request->getPost("client_id");
+            $policy_id = $this->request->getPost("policy_id");
+            $data['sum_insured']   =$this->request->getPost("sum_insured");
+            $data['family_floater']   =$this->request->getPost("family_floater");
+            // print_r($data['familyfloater']);
+            if (!$data['family_floater'] || $data['family_floater'] == 0) {
+                $data['corporatebuffer'] = "";
+                $data['family_floaters'] = "";
+            }else{
+                $data['corporatebuffer'] = $this->request->getPost("corporatebuffer");
+                $data['family_floaters'] = $this->request->getPost("family_floaters") ?? [];                
+            }
+
+            $data['waiverofpreexistingdiseases']   =$this->request->getPost("waiverofpreexistingdiseases");
+            if ($data['waiverofpreexistingdiseases'] == 1) {
+                $data['maternitycoverage']   =$this->request->getPost("maternitycoverage");
+                $data['twindelivery']   =$this->request->getPost("twindelivery");
+                $data['preandpostnatal']   =$this->request->getPost("preandpostnatal");
+                $data['babyday1cover']   =$this->request->getPost("babyday1cover");
+            }else{
+                $data['maternitycoverage']   ="";
+                $data['twindelivery']   ="";
+                $data['preandpostnatal']   ="";
+                $data['babyday1cover']   ="";
+            }
+            $data['9monthwaitingperiodwaived'] =$this->request->getPost("9monthwaitingperiodwaived");
+            $data['coverfromthedateofjoining'] =$this->request->getPost("coverfromthedateofjoining");
+            $data['waiverof1,2,3&4thyearexclusions'] =$this->request->getPost("waiverof1,2,3&4thyearexclusions");
+            $data['waiverof30dayswaitingperiod'] =$this->request->getPost("waiverof30dayswaitingperiod");
+            $data['prehospitalizationcover'] =$this->request->getPost("prehospitalizationcover");
+            // $data['posthospitalizationcover'] =$this->request->getPost("posthospitalizationcover");
+            $data['congenitaldiseasesinternal'] =$this->request->getPost("congenitaldiseasesinternal");
+            // $data['congenitaldiseasesexternal'] =$this->request->getPost("congenitaldiseasesexternal");
+            $data['copayzonewisecopay'] =$this->request->getPost("copayzonewisecopay");
+            $data['bioabsorbablestenttoriclensmultifocallens'] =$this->request->getPost("bioabsorbablestenttoriclensmultifocallens");
+            $data['roomrentlimit'] =$this->request->getPost("roomrentlimit");
+            $data['proportionatedeductionclause'] =$this->request->getPost("proportionatedeductionclause");
+            $data['nursingallowance'] =$this->request->getPost("nursingallowance");
+            $data['ailmentcapping'] =$this->request->getPost("ailmentcapping");
+            $data['ambulancecharges'] =$this->request->getPost("ambulancecharges");
+            $data['airambulance'] =$this->request->getPost("airambulance");
+            $data['familytransportationbenefit'] =$this->request->getPost("familytransportationbenefit");
+            $data['reasonableandcustomarycharges'] =$this->request->getPost("reasonableandcustomarycharges");
+            $data['ayudhtreatmentcover'] =$this->request->getPost("ayudhtreatmentcover");
+            $data['armdcovered'] =$this->request->getPost("armdcovered");
+            $data['suminsuredenhancement'] =$this->request->getPost("suminsuredenhancement");
+            $data['automaticsuminsuredreinstatement'] =$this->request->getPost("automaticsuminsuredreinstatement");
+            $data['additionalsicknessbenefit'] =$this->request->getPost("additionalsicknessbenefit");
+            $data['lasiksurgery'] =$this->request->getPost("lasiksurgery");
+            $data['midterminclusion'] =$this->request->getPost("midterminclusion");
+            $data['capd'] =$this->request->getPost("capd");
+            $data['organdonorexpenses'] =$this->request->getPost("organdonorexpenses");
+            $data['moderntreatmentsasperirdai'] =$this->request->getPost("moderntreatmentsasperirdai");
+            $data['Wellness'] =$this->request->getPost("Wellness");
+            $data['days_of_discharge'] =$this->request->getPost("days_of_discharge");
+            $data['days_from_dod'] =$this->request->getPost("days_from_dod");
+            $data['special_condition_label'] = $this->request->getPost("special_condition_label") ?? [];
+            $data['special_condition_input'] = $this->request->getPost("special_condition_input") ?? [];
+
+
+                $jsonData = json_encode($data);
+                $dataa = array(
+                    'policy_terms' => $jsonData,
+                    'client_id' => $client_id,
+                    'policy_id' => $policy_id
+                );
+
+            $record = $this->clientPolicyModel->where(['client_id' => $client_id, 'policy_id' => $policy_id])->first();
+
+            if ($record) {
+                $update = $this->clientPolicyModel->update($record['id'], $dataa);
+                if ($update) {
+                    return $this->respond(['status' => true,'code' => 200,'message' => 'Data updated successfully'], 200);
+                } else {
+                    return $this->respond(['status' => false,'code' => 404, 'message' => 'Failed to update data'], 200);
+                }
+            }else{
+                $insert = $this->clientPolicyModel->insert($dataa);        
+                if ($insert) {
+                    return $this->respond(['status' => true,'code' => 200,'message' => 'Data stored successfully'], 200);
+                } else {
+                    return $this->respond(['status' => false,'code' => 404, 'message' => 'Failed to store data'], 200);
+                }
+            }
+        } catch (\Exception $e) {
+
+            echo "Failed to insert data: " . $e->getMessage();
+            // Log the error
+            log_message('error', 'Failed to insert data: ' . $e->getMessage());
+        }
+        
+    }
+    
+    public function getterms()
+    {
+        $client_id = $this->request->getVar('client_id');
+        $policy_id = $this->request->getVar('policy_id');
+        $record    = $this->clientPolicyModel->where(['client_id' => $client_id, 'policy_id' => $policy_id])->first();
+        $emp_count = $this->employeeModel ->join('client_policy cp',"employees.client_id = cp.client_id")
+                                          ->join('employee_polices ep',"cp.id = ep.client_policy_id AND employees.id = ep.employee_id")
+                                          ->where("employees.client_id",$client_id)
+                                          ->where("employees.emp_status",'active')
+                                          ->countAllResults();
+        if($emp_count = 0){
+            $emp_count = true;
+        }else{
+            $emp_count = false;
+        }
+
+        if ($record) {
+            return $this->respond(['Status' => true,'code' => 200,'data' => $record['policy_terms'], 'count' => $emp_count], 200);
+        } else {
+            return $this->respond(['Status' => false,'code' => 200,'message' => 'Record not found.', 'count' => $emp_count], 200);
+        }
+
+    }
+
+    public function policyGPATerms()
+    {
+        
+        try {
+            $this->myLogger->logme('error','Policy GPA Terms CREATE function called');
+
+            // print_r($this->request->getPost());
+            $client_id = $this->request->getPost("client_id");
+            $policy_id = $this->request->getPost("policy_id");
+
+            $data['sumInsured2']   =$this->request->getPost("sumInsured2");
+            $data['totalSumInsured'] =$this->request->getPost("totalSumInsured");
+            $data['accidentalDeathBenefit'] =$this->request->getPost("accidentalDeathBenefit");
+            $data['permanentTotalDisablement'] =$this->request->getPost("permanentTotalDisablement");
+            $data['permanentPartialDisablement'] =$this->request->getPost("permanentPartialDisablement");
+            $data['temporaryTotalDisablementBenefit'] =$this->request->getPost("temporaryTotalDisablementBenefit");
+            $data['accidentalHospitalizationExpenses'] =$this->request->getPost("accidentalHospitalizationExpenses");
+            $data['childrenEducationWelfareFund'] =$this->request->getPost("childrenEducationWelfareFund");
+
+            $data['compassionateVisitExpenses']   =$this->request->getPost("compassionateVisitExpenses");
+            if ($data['compassionateVisitExpenses'] == 1) {
+                $data['compassionateVisitExpensesData']   =$this->request->getPost("compassionateVisitExpensesData");
+            }else{
+                $data['compassionateVisitExpensesData']   ="";
+            }
+
+            $data['brokenBoneExpenses']   = $this->request->getPost("brokenBoneExpenses");
+            if ($data['brokenBoneExpenses'] == 1) {
+                $data['brokenBoneExpensesData']   = $this->request->getPost("brokenBoneExpensesData");
+            }else{
+                $data['brokenBoneExpensesData']   ="";
+            }
+
+            $data['ambulanceCharges']   =$this->request->getPost("ambulanceCharges");
+            if ($data['ambulanceCharges'] == 1) {
+                $data['ambulanceChargesData']   =$this->request->getPost("ambulanceChargesData");
+            }else{
+                $data['ambulanceChargesData']   ="";
+            }
+
+            $data['burnExpenses']   = $this->request->getPost("burnExpenses");
+            if ($data['burnExpenses'] == 1) {
+                $data['burnExpensesData']   = $this->request->getPost("burnExpensesData");
+            }else{
+                $data['burnExpensesData']   = "";
+            }
+
+            $data['carriageOfDeadBody']   = $this->request->getPost("carriageOfDeadBody");
+            if ($data['carriageOfDeadBody'] == 1) {
+                $data['carriageOfDeadBodyData']   = $this->request->getPost("carriageOfDeadBodyData");
+            }else{
+                $data['carriageOfDeadBodyData']   = "";
+            }
+
+            $data['animalSnakeInsectBite'] = $this->request->getPost("animalSnakeInsectBite");
+            $data['terrorism']             = $this->request->getPost("terrorism");
+            $data['worldwideCover']        = $this->request->getPost("worldwideCover");
+
+
+            print_r($data);
+
+            // print_r($this->request->getPost());
+                // die();
+
+                $jsonData = json_encode($data);
+                $dataa = array(
+                    'policy_terms' => $jsonData,
+                    'client_id' => $client_id,
+                    'policy_id' => $policy_id
+                );
+            $record = $this->clientPolicyModel->where(['client_id' => $client_id, 'policy_id' => $policy_id])->first();
+            if ($record) {
+                $update = $this->clientPolicyModel->update($record['id'], $dataa);
+                if ($update) {
+                    return $this->respond(['status' => true,'code' => 200,'message' => 'Data updated successfully'], 200);
+                } else {
+                    return $this->respond(['status' => false,'code' => 404, 'message' => 'Failed to update data'], 200);
+                }
+            }else{
+                $insert = $this->clientPolicyModel->insert($dataa);        
+                if ($insert) {
+                    return $this->respond(['status' => true,'code' => 200,'message' => 'Data stored successfully'], 200);
+                } else {
+                    return $this->respond(['status' => false,'code' => 404, 'message' => 'Failed to store data'], 200);
+                }
+            }
+        } catch (\Exception $e) {
+            // Handle the exception
+            echo "Failed to insert data: " . $e->getMessage();
+            // Log the error
+            log_message('error', 'Failed to insert data: ' . $e->getMessage());
+        }
+        
+    }
+
+    public function getPolicyGPATerms(){
+
+        $client_id = $this->request->getVar('client_id');
+        $policy_id = $this->request->getVar('policy_id');
+        $record = $this->clientPolicyModel->where(['client_id' => $client_id, 'policy_id' => $policy_id])->first();
+
+        if ($record) {
+            echo $record['policy_terms'];
+            
+        } else {
+            echo "Record not found.";
+        }
 
     }
 
diff --git a/app/Helpers/DepositHelper.php b/app/Helpers/DepositHelper.php
new file mode 100644
index 00000000..a25aff9e
--- /dev/null
+++ b/app/Helpers/DepositHelper.php
@@ -0,0 +1,99 @@
+ $data['amount'],
+            'sub_type' => $data['sub_type_id'],
+            'client_id' => $data['client_id'],
+            'insurer_id' => $data['insurer_id'],
+            'description' => $data['description'],
+            'transaction_type' => $data['transaction_type'],
+            'is_active' => 1,
+            'created_by' => $loggedInUserID,
+            'updated_by' => $data['updated_by'],
+            'balance' => $newBalance, // Include the new balance in the data array
+        ];
+
+        // Insert data and get the insert ID
+        $insertId = $model->insert($insertData);
+
+        // Return the response
+        if ($insertId) {
+            return [
+                'success' => true,
+                'message' => 'Transaction saved successfully',
+                'insert_id' => $insertId,
+            ];
+        } else {
+            return [
+                'success' => false,
+                'message' => 'Failed to save transaction',
+            ];
+        }
+    }
+   /**
+     * Calculate the last balance based on client and insurer ID.
+     *
+     * @param int $clientId The client ID.
+     * @param int $insurerId The insurer ID.
+     *
+     * @return float The last known balance.
+     */
+    public static function calculateLastBalance(int $clientId, int $insurerId): float
+    {
+        $model = new ClientDepositModel();
+
+        $getLastBalanceQuery = "SELECT balance FROM cash_deposit WHERE client_id = ? AND insurer_id = ? ORDER BY created_at DESC LIMIT 1";
+        $getLastBalanceParams = [$clientId, $insurerId];
+
+        $lastBalance = $model->query($getLastBalanceQuery, $getLastBalanceParams)->getRow()->balance ?? 0;
+
+        return $lastBalance;
+    }
+}
+
+?>
diff --git a/app/Models/ClientDepositModel.php b/app/Models/ClientDepositModel.php
new file mode 100644
index 00000000..0f2573b5
--- /dev/null
+++ b/app/Models/ClientDepositModel.php
@@ -0,0 +1,29 @@
+getResult();
     }
 
+
     public function getPolicyTermsJson($client_id,$policy_id)
     {
         return $this->select('policy_terms')
@@ -106,4 +106,125 @@ class ClientPolicyModel extends Model
              ->getResult();
 
     }
+
+    public function getinsurerswithclientid($id){
+
+        return $this->db->table('client_policy')
+        ->select('client_policy.*')
+        ->select('insurers.name as insurer_name, insurers.short_name as insurer_short')
+        ->select('clients.client_name as client_name')
+        ->join('clients','clients.id=client_policy.client_id')
+        ->join('insurers', 'insurers.id = client_policy.insurer_id')
+        ->where('client_policy.client_id', $id)
+        ->groupBy('client_policy.insurer_id') 
+        ->groupBy('client_policy.client_id', $id)  // Group by insurer_id
+        ->get()
+        ->getResult();
+    }
+  
+    public function getinsurerswithinsurenceid($insurerId){
+
+        return $this->db->table('client_policy')
+        ->select('client_policy.*')
+        ->select('insurers.name as insurer_name, insurers.short_name as insurer_short')
+        ->select('clients.client_name as clientname, clients.short_name as clientshort')
+        ->join('insurers', 'insurers.id = client_policy.insurer_id')
+        ->join('clients', 'clients.id = client_policy.client_id')
+        ->where('client_policy.insurer_id', $insurerId)
+        ->groupBy('client_policy.client_id') // Group by insurer_id
+        ->get()
+        ->getResult();
+    }
+    public function getClientById($id) {
+        $query = $this->db->table('clients')->getWhere(['id' => $id]);
+     // Debug statement
+        return $query->getRow();
+    }
+    public function getDepositData($clientId, $insurerId)
+    {
+        // Fetch the deposit data based on client and insurer IDs
+        return $this->db->table('cash_deposit')
+            ->select('cash_deposit.*')
+            ->select('insurers.name as insurer_name, insurers.short_name as insurer_short')
+            ->select('clients.client_name as clientname, clients.short_name as clientshort')
+            ->select('user_profiles.first_name as username')
+             ->join('user_profiles','user_profiles.id=cash_deposit.created_by')
+            ->join('insurers', 'insurers.id = cash_deposit.insurer_id')
+            ->join('clients', 'clients.id = cash_deposit.client_id')
+           
+            ->where('cash_deposit.client_id', $clientId)
+            ->where('cash_deposit.insurer_id', $insurerId) // Add this line to filter by insurer_id
+            ->get()
+            ->getResult();
+    }
+    public function getDepositSummary($clientId, $insurerId)
+{
+    // Fetch the sum of credit and debit transactions and calculate the balance
+    return $this->db->table('cash_deposit')
+        ->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)
+        ->get()
+        ->getRow();
+}
+// Inside your clientPolicyModel
+// Inside your clientPolicyModel
+// public function getDepositDataWithBalance($clientId, $insurerId)
+// {
+//     // Fetch deposit data with balance information
+//     $builder = $this->db->table('cash_deposit');
+//     $builder->select('id, created_at,  description, sub_type, amount, transaction_type');
+
+//     $builder->where('client_id', $clientId);
+//     $builder->where('insurer_id', $insurerId);
+//     $builder->orderBy('created_at', 'asc');
+
+//     $depositData = $builder->get()->getResult();
+
+//     $currentBalance = 0;
+
+//     foreach ($depositData as $transaction) {
+//         if ($transaction->transaction_type == 'Credit') {
+//             $currentBalance += $transaction->amount;
+//         } elseif ($transaction->transaction_type == 'Debit') {
+//             $currentBalance -= $transaction->amount;
+//         }
+
+//         $transaction->balance = $currentBalance;
+//     }
+
+//     return $depositData;
+// }
+
+
+
+
+public function getBalances($clientId)
+{
+    $depositsummary = $this->getDepositlistsummary($clientId);
+    $balances = [];
+
+    foreach ($depositsummary as $summary) {
+        $insurerId = $summary->insurer_id;
+        $balances[$insurerId] = $summary;
+    }
+
+    return $balances;
+}
+
+public function getDepositlistsummary($id)
+{
+    return $this->db->table('cash_deposit')
+        ->select('insurer_id')
+        ->select('SUM(CASE WHEN transaction_type = "Credit" THEN amount ELSE -amount END) AS balance')
+        ->where('client_id', $id)
+        ->groupBy('insurer_id')
+        ->get()
+        ->getResult();
+}
+
+
 }
diff --git a/app/Models/InsurerModel.php b/app/Models/InsurerModel.php
index 6e6b7a1f..77ad5d49 100644
--- a/app/Models/InsurerModel.php
+++ b/app/Models/InsurerModel.php
@@ -30,4 +30,33 @@ class InsurerModel extends Model
         ->getResult();
     
     }
-}
+    public function getInsurerName($insurerId)
+    {
+        // Fetch the insurer name based on the insurer ID
+        $query = $this->select('id,name')
+            ->where('id', $insurerId)
+            ->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 getdepositData($id)
+    // {
+    //     // Fetch the insurer name based on the insurer ID
+    //     $query = $this->db->table('cash_deposit')
+          
+          
+    //         ->get()
+
+     
+    //         ->getResult();
+          
+    //     }
+          
+        }
+
+        
\ No newline at end of file
diff --git a/app/Views/add_transaction.php b/app/Views/add_transaction.php
new file mode 100644
index 00000000..c8c64190
--- /dev/null
+++ b/app/Views/add_transaction.php
@@ -0,0 +1,67 @@
+
+    
\ No newline at end of file
diff --git a/app/Views/client_basic_info.php b/app/Views/client_basic_info.php
index 9df58db2..c7a54c83 100644
--- a/app/Views/client_basic_info.php
+++ b/app/Views/client_basic_info.php
@@ -139,6 +139,9 @@ $(document).ready(function () {
             form_action = '';
         }
 
+        $('.loader').fadeIn();
+        $('.loader-mask').fadeIn();
+
         var formData = new FormData($('#general_form')[0]);
         var OptionsHTML1 = ''
 
@@ -150,20 +153,29 @@ $(document).ready(function () {
             processData: false,
             contentType: false,
             success: function(res) {
+
+                if(res){
+                    setTimeout(function() {
+                        
+                        $('.loader').fadeOut();
+                        $('.loader-mask').delay(350).fadeOut('slow');
+                        $('#kyc_tab').click();
+                        var message = (PrimaryKey === '') ? 'Client General Info Created successfully' : 'Client General Info Updated successfully';
+                        toastr.success(message, 'Success');
+
+                    }, 1000);
+                }
                 
-                console.log(res);
                 $('#client_id').val(res.data.id);
                 $('#client_id_relation').val(res.data.id);
+                $('#relation_PrimaryKey').val(res.data.id);
                 $('#client_id_branch').val(res.data.id);
                 $('#branch_PrimaryKey').val(res.data.id);
                 $('#client_id_policy').val(res.data.id);
                 $('#policy_PrimaryKey').val(res.data.id);
                 $('#client_id_kyc').val(res.data.id);
+                $('#kyc_PrimaryKey').val(res.data.id);
                 $('#entity_type').val(res.data.entity_type_id);
-                $('#kyc_tab').click();
-
-                var message = (PrimaryKey === '') ? 'Client General Info Created successfully' : 'Client General Info Updated successfully';
-                toastr.success(message, 'Success');
 
                 $.ajax({
                     url: '' + res.data.entity_type_id,
diff --git a/app/Views/client_branch.php b/app/Views/client_branch.php
index 23dc8c51..dee42779 100644
--- a/app/Views/client_branch.php
+++ b/app/Views/client_branch.php
@@ -237,6 +237,9 @@ $(document).ready(function () {
 
         if (isValid) {
 
+            $('.loader').fadeIn();
+            $('.loader-mask').fadeIn();
+
             var formData = new FormData($('#branch_form')[0]);
 
             $.ajax({
@@ -247,9 +250,21 @@ $(document).ready(function () {
                 processData: false,
                 contentType: false,
                 success: function(res) {
-                    console.log(res);
-                    var message = (branch_PrimaryKey === '') ? 'Client General Info Created successfully' : 'Client General Info Updated successfully';
-                    toastr.success(message, 'Success');
+
+                    if(res){
+                        setTimeout(function() {
+                            
+                            $('.loader').fadeOut();
+                            $('.loader-mask').delay(350).fadeOut('slow');
+                            $('#add_branch').hide();
+                            $('#branch_table').show();
+                            $('.btnBack').hide();
+                            $('#btnBranchAdd').show();
+                            var message = (branch_PrimaryKey === '') ? 'Client Branch Created successfully' : 'Client Branch Updated successfully';
+                            toastr.success(message, 'Success');                        
+                        }, 1000);
+                    }
+
                     $('#branch_list tr').remove();
                     var branchTableInsert = ''
                     $.each(res.data, function(index, item) {
@@ -262,10 +277,7 @@ $(document).ready(function () {
                         `;   
                     });
                     $('#branch_list').append(branchTableInsert); 
-                    $('#add_branch').hide();
-                    $('#branch_table').show();
-                    $('.btnBack').hide();
-                    $('#btnBranchAdd').show();
+
                 },
                 error: function (xhr, status, error) {
                     console.error(xhr.responseText);
diff --git a/app/Views/client_deposit_list.php b/app/Views/client_deposit_list.php
new file mode 100644
index 00000000..2d48ccc6
--- /dev/null
+++ b/app/Views/client_deposit_list.php
@@ -0,0 +1,97 @@
+
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + +
Insurer NameCurrent BalanceAction
+ + + insurer_name;?> + + ₹ + insurer_id; + + // Check if the balance information exists for the insurer + if (isset($balances[$insurerId])) { + $balance = $balances[$insurerId]->balance; + echo $balance; + } else { + echo "N/A"; // Display "Not Available" if balance information is not present + } + ?> + + + insurer_id}?client_id={$value->client_id}"); ?>"> + View Deposit + +
+
+
+
+
+ + + \ No newline at end of file diff --git a/app/Views/client_kyc.php b/app/Views/client_kyc.php index 154e5d06..9ea8fbea 100644 --- a/app/Views/client_kyc.php +++ b/app/Views/client_kyc.php @@ -105,7 +105,9 @@ $(document).on('click', '.submit', function(e) { e.preventDefault(); - kycPrimaryKey = $('#kyc_PrimaryKey').val(); + // kycPrimaryKey = $('#kyc_PrimaryKey').val(); + kycPrimaryKey = $('#client_id_kyc').val(); + var form = $(this).closest('form'); var formData = new FormData(form[0]); @@ -149,8 +151,8 @@ processData: false, contentType: false, success: function (res) { - res = JSON.parse(res) - console.log(res); + // res = JSON.parse(res) + // console.log(res); form.trigger('reset') $.each(res.data, function (index, item) { @@ -168,8 +170,6 @@ }); }); - ; - if(kycPrimaryKey !== ''){ $.ajax({ @@ -203,8 +203,10 @@ } }); + var table = ''; var data = ; + console.log(data) $('#other_docs tr').remove(); $.each(data, function(index, item) { @@ -221,14 +223,15 @@ }); $('#other_docs').append(table); + $.each(data, function(index, item) { // console.log(item.kyc_doc_type_id); // console.log('name_' + item.kyc_doc_type_id); // console.log(document.getElementById('name_' + item.kyc_doc_type_id)); setTimeout(function() { - $('#name_'+item.kyc_doc_type_id).show(); - $('#name_'+item.kyc_doc_type_id).html(item.file_name); - $('#form_'+item.kyc_doc_type_id).hide(); + $('#name_'+item.id).show(); + $('#name_'+item.id).html(item.file_name); + $('#form_'+item.id).hide(); }, 1000); }); diff --git a/app/Views/client_list.php b/app/Views/client_list.php index fb454c59..09a34662 100644 --- a/app/Views/client_list.php +++ b/app/Views/client_list.php @@ -38,6 +38,11 @@ diff --git a/app/Views/client_onboarding.php b/app/Views/client_onboarding.php index 92d70c6a..bd5248f2 100644 --- a/app/Views/client_onboarding.php +++ b/app/Views/client_onboarding.php @@ -36,12 +36,15 @@ body {
-

Client Onboarding

+

Client Onboarding

+ +
+