diff --git a/app/Config/Routes.php b/app/Config/Routes.php index f9333b5d..77cf4c62 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -12,6 +12,8 @@ $routes->get('/swagger', 'SwaggerController::index', ['filter' => 'authMVC']); // Reminder Mail Notification $routes->get("reminder_mail", "NotificationController::reminder_mail"); +$routes->get("testing", "ClientController::Testing"); +$routes->get("update-policy-terms-for-corrections", "ClientController::updatePolicyTermsForCorrections"); $routes->post("add_advertise_image", "AppContentManagementController::add_advertise_image"); @@ -257,6 +259,7 @@ $routes->group("/util", ["filter" => "authMVC"], function ($routes) { $routes->get("getPolicyTerms/(:any)", "ClientController::getPolicyTerms/$1"); $routes->get("getPolicyTermsFormJson/(:any)", "ClientController::getPolicyTermsFormJson/$1"); $routes->get("checkHRNumber/(:any)", "ClientController::checkHRNumber/$1"); + $routes->get("check_addition_premium_JSON/(:any)", "ClientController::checkAdditionPremiumJSON/$1"); }); $routes->cli('cli/processjob', 'JobWorker::processJob'); diff --git a/app/Controllers/ChatBotController.php b/app/Controllers/ChatBotController.php index 6fd006c8..bb47fe6a 100644 --- a/app/Controllers/ChatBotController.php +++ b/app/Controllers/ChatBotController.php @@ -73,11 +73,10 @@ class ChatBotController extends AdminController public function getChatResponse() { - try { + // try { $request_for = $this->request->getGet('request_for'); $option = $this->request->getGet('option'); $is_option = $this->request->getGet('is_option'); - $custom_options = $this->request->getGet('custom_options'); $responseData = $this->ChatBotModel->where('request', $request_for) ->where('is_active', 1 ) @@ -89,18 +88,38 @@ class ChatBotController extends AdminController if(isset($option) && $option != 0){ $decodedData = json_decode($responseData['options'],true); - - $requestFor = $decodedData[$option]; + + + if (isset($decodedData[$option]) && $decodedData[$option] !== null) { - $responseData = $this->ChatBotModel->where('request', $requestFor) + $requestFor = $decodedData[$option]; + $responseData = $this->ChatBotModel->where('request', $requestFor) ->where('is_active', 1 ) ->first(); + + }else{ + + if( $request_for == 'Create claim'){ + $result = [ + 'request_for' => $request_for, + 'options' => json_decode($responseData['options'], true), + 'text' => "Enter Message", + 'is_option' => "0", + 'policy_id' => $option, + 'mobile_no' => $this->request->getGet('mobile_no') + ]; + + return $this->respond(['status' => 'success','code' => 200,'data' => $result ],200); + }else{ + + $result = $this->sendDefaultMessage(); + return $this->respond(['status' => 'success','code' => 200,'data' => $result ],200); + + } + } } - if(isset($custom_options)) - { - - } + if(isset($is_option) && $is_option == 0){ @@ -120,8 +139,38 @@ class ChatBotController extends AdminController }else{ + if( $request_for == 'Create claim' && $text == 'Enter Message'){ + + + $ticket = $this->claimTicket(); + + $ticket = json_decode($ticket,true); + + if (isset($ticket['success']) && $ticket['success'] == 1) { + + $result = [ + 'request_for' => $request_for, + 'options' => null, + 'text' => $ticket['message'].', Your Ticket id is '.$ticket['ticket_id'], + 'is_option' => "0" + ]; + }else{ + + $result = [ + 'request_for' => $request_for, + 'options' => null, + 'text' => $ticket['message'], + 'is_option' => "0" + ]; + } + + + return $this->respond(['status' => 'success','code' => 200,'data' => $result ],200); + }else{ + $result = $this->sendDefaultMessage(); return $this->respond(['status' => 'success','code' => 200,'data' => $result ],200); + } } @@ -145,9 +194,9 @@ class ChatBotController extends AdminController return $this->respond(['status' => 'failed','code' => 404,'data' => 'No Data'],404); } - } catch (\Throwable $th) { - return $this->respond(['status' => 'failed','code' => 500,'data' => $th],500); - } + // } catch (\Throwable $th) { + // return $this->respond(['status' => 'failed','code' => 500,'data' => $th],500); + // } } @@ -220,14 +269,15 @@ public function getAllPolicyByMobileNumber($mobileNo,$action) 'options' => $options[count($options) - 1], 'text' => null, 'is_option' => "1", - 'custom_options'=>'create_ticket' + 'mobile_no' => $mobileNo, ]; }else{ return [ 'request_for' => $this->request->getGet('request_for'), 'options' => null, 'text' => $text, - 'is_option' => "0" + 'is_option' => "0", + 'mobile_no' => $mobileNo, ]; } @@ -258,6 +308,64 @@ public function getAllPolicyByMobileNumber($mobileNo,$action) } +public function claimTicket() +{ + + + $employee = $this->employeeModel->where('mobile', $this->request->getGet('mobile_no'))->where('is_active', 1 )->first(); + if($employee){ + + $url = 'https://venbait.in/nhance/helpdesk/dev/api/tickets/create'; + + + $token = 'uncp8FvG310bEyYdV9MmStlo7KDRZ65fLWTeXCI2JzwPrNHjBqQhUiAgxsaO'; + $headers = [ + 'Token: ' . $token, + ]; + + // Form data + $data = [ + 'opener' => 'user', + 'department_id' => 2, + 'subject' => 'Claim Raised by Chat Bot', + 'body' => $this->request->getGet('value'), + 'policy_id' => $this->request->getGet('policy_id'), + 'emp_code' => $employee['emp_code'], + 'mobile_number' => $this->request->getGet('mobile_no'), + 'email' => 'adhavanvalli@gmail.com', + 'fullname' => $employee['name'], + ]; + + // Initialize cURL session + $ch = curl_init(); + + // Set cURL options + curl_setopt($ch, CURLOPT_URL, $url); + curl_setopt($ch, CURLOPT_POST, true); + curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data)); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); + + $response = curl_exec($ch); +return $response; + // Check for errors + // if (curl_errno($ch)) { + // $error = curl_error($ch); + // curl_close($ch); + // return ['status' => 'failed', 'response' => $error]; + // } else { + // // Close cURL session + // curl_close($ch); + // return ['status' => 'success', 'response' => $response]; + // } + + + }else{ + return ['status' => 'failed', 'response' => 'Employee Not Found']; + } +} + + } diff --git a/app/Controllers/ClientController.php b/app/Controllers/ClientController.php index 185ff9ce..e7e80b36 100644 --- a/app/Controllers/ClientController.php +++ b/app/Controllers/ClientController.php @@ -106,7 +106,47 @@ class ClientController extends AdminController } + + public function Testing() //this function for only tsesting some logics not use for business logic + { + $results = $this->clientPolicyModel + ->select('id, policy_terms') + ->where('policy_terms IS NOT NULL') + ->where('policy_terms <>', '') + ->whereNotIn('policy_type_id', [1, 6, 7]) + ->orderBy('id', 'desc') + ->get() + ->getResultArray(); + + foreach ($results as $key => $result) { + $client_policy_id = $result['id']; + $policy_terms = json_decode($result['policy_terms'], true); // true to get associative array + + if (isset($policy_terms['family_floaters'])) { + $family_floaters = $policy_terms['family_floaters']; + $parents = $family_floaters['parents'] ?? 0; + $parents_in_law = $family_floaters['parents-in-law'] ?? 0; + + if ($parents == 1 && $parents_in_law == 1) { + $policy_terms['family_floaters']['parents'] = 0; + $policy_terms['family_floaters']['parents-in-law'] = 0; + $policy_terms['family_floaters']['either-parents-pil'] = 2; + + $results[$key]['policy_terms'] = json_encode($policy_terms); + + // Update the policy_terms in the database + $this->clientPolicyModel + ->where('id', $client_policy_id) + ->set('policy_terms', $results[$key]['policy_terms']) + ->update(); + } + } + } + + dd($results); + } + public function index() { $this->myLogger->logme('error','Client list function called'); @@ -123,8 +163,8 @@ class ClientController extends AdminController // $this->loadLayout('client_onboarding', $data); } - - public function updateEmpAndPolicyStatus(){ + public function updateEmpAndPolicyStatus() + { $return = $this->clientPolicyModel->updateStatus(); $this->myLogger->logme('error', 'Client Policy Status Update Count: {data}', ['data' => $return['client']]); @@ -133,6 +173,59 @@ class ClientController extends AdminController } + public function updatePolicyTermsForCorrections(){ + + $results = $this->clientPolicyModel + ->select('id, policy_terms') + ->where('policy_terms IS NOT NULL') + ->where('policy_terms <>', '') + ->whereNotIn('policy_type_id', [1, 6, 7]) + ->orderBy('id', 'desc') + ->get() + ->getResultArray(); + + + $client_policy_ids = []; + foreach ($results as $key => $result) { + $client_policy_id = $result['id']; + $policy_terms = json_decode($result['policy_terms'], true); // true to get associative array + + if (isset($policy_terms['family_floaters'])) { + $family_floaters = $policy_terms['family_floaters']; + $parents = $family_floaters['parents'] ?? 0; + $parents_in_law = $family_floaters['parents-in-law'] ?? 0; + + if ($parents == 1 && $parents_in_law == 1) { + + $client_policy_ids[] = $client_policy_id; + + $policy_terms['family_floaters']['parents'] = 0; + $policy_terms['family_floaters']['parents-in-law'] = 0; + $policy_terms['family_floaters']['either-parents-pil'] = 2; + + + $results[$key]['policy_terms'] = json_encode($policy_terms); + + // Update the policy_terms in the database + $this->clientPolicyModel + ->where('id', $client_policy_id) + ->set('policy_terms', $results[$key]['policy_terms']) + ->update(); + } + } + } + + if(count($client_policy_ids) > 0){ + echo 'There are ' . count($client_policy_ids) . ' records to be updated.'; + echo '
'; + dd($client_policy_ids); + }else{ + echo 'There is no records to be update.'; + } + // dd($results); + + } + public function removeClient($id = null) { $this->myLogger->logme('error','Client Remove function called'); @@ -219,11 +312,12 @@ class ClientController extends AdminController // ]; $subTypeOptions = [ - 1 => 'Replenishment', + 1 => 'Replenishment By Client', 2 => 'Adjustment', 3 => 'Refund From Deletion', 4 => 'Debit', - 5 => 'Asset Policy', + 5 => 'Non EB', + 6 => 'Refund By Insurer', ]; $data['subTypeOptions'] = $subTypeOptions; @@ -355,7 +449,6 @@ class ClientController extends AdminController { $this->myLogger->logme('error','edit client general info function called'); $uploadFilePath = ROOTPATH . 'public/uploads/logo/'; - // print_r($this->request->getFile('client_logo'));die; $file_name = file_Upload($this->request->getFile('client_logo'), $uploadFilePath); $id = $this->request->getPost('PrimaryKey'); @@ -544,6 +637,11 @@ class ClientController extends AdminController $this->myLogger->logme('error','Client branch CREATE function called'); $data = $this->request->getPost(); + if (!isset($data['sez'])) { + $data['sez'] = 0; + } elseif ($data['sez']) { + $data['sez'] = 1; + } $data['created_by'] = get_session_userid(); $insert = $this->clientBranchModel->insert($data); @@ -579,6 +677,11 @@ class ClientController extends AdminController $id = $this->request->getPost('branch_id_primarykey'); $client_id = $this->request->getPost('client_id'); $data = $this->request->getPost(); + if (!isset($data['sez'])) { + $data['sez'] = 0; + } elseif ($data['sez']) { + $data['sez'] = 1; + } $data['updated_by'] = get_session_userid(); $insert = $this->clientBranchModel->update($id, $data); $this->myLogger->logme('error','Client branch EDITED by {data}', ['data' => get_session_userid()]); @@ -669,28 +772,28 @@ class ClientController extends AdminController $policy_terms = $this->clientPolicyModel->where('id', $this->request->getPost('base_policy'))->first(); - if ($this->request->getPost('is_addon') == 2 || $this->request->getPost('is_addon') == 3) { + // if ($this->request->getPost('is_addon') == 2 || $this->request->getPost('is_addon') == 3) { - if ($this->request->getPost('is_addon') == 3) { - $policyTerm = $policy_terms['policy_terms']; - $decoded_policyTerm = json_decode($policyTerm, true); - $decoded_policyTerm['family_floater'] = 0; - $decoded_policyTerm['family_floaters']['self'] = 0; - $decoded_policyTerm['family_floaters']['spouse'] = 0; - $decoded_policyTerm['family_floaters']['childrens'] = 0; - $decoded_policyTerm['family_floaters']['parents'] = 0; - $decoded_policyTerm['family_floaters']['parents-in-law'] = 0; - $decoded_policyTerm['family_floaters']['either-parents-pil'] = 0; + // if ($this->request->getPost('is_addon') == 3) { + // $policyTerm = $policy_terms['policy_terms']; + // $decoded_policyTerm = json_decode($policyTerm, true); + // $decoded_policyTerm['family_floater'] = 0; + // $decoded_policyTerm['family_floaters']['self'] = 0; + // $decoded_policyTerm['family_floaters']['spouse'] = 0; + // $decoded_policyTerm['family_floaters']['childrens'] = 0; + // $decoded_policyTerm['family_floaters']['parents'] = 0; + // $decoded_policyTerm['family_floaters']['parents-in-law'] = 0; + // $decoded_policyTerm['family_floaters']['either-parents-pil'] = 0; - $data['policy_terms'] = json_encode($decoded_policyTerm); - } else { + // $data['policy_terms'] = json_encode($decoded_policyTerm); + // } else { - if ($this->request->getPost('policy_type_id') != 3) { + // if ($this->request->getPost('policy_type_id') != 3) { - $data['policy_terms'] = $policy_terms['policy_terms']; - } - } - } + // $data['policy_terms'] = $policy_terms['policy_terms']; + // } + // } + // } $data['policy_no'] = $this->request->getPost('policy_no'); @@ -764,25 +867,25 @@ class ClientController extends AdminController $policy_terms = $this->clientPolicyModel->where('id', $this->request->getPost('base_policy'))->first(); - if ( $this->request->getPost('is_addon') == 2 || $this->request->getPost('is_addon') == 3) { - if ($this->request->getPost('is_addon') == 3) { - $policyTerm = $policy_terms['policy_terms']; - $decoded_policyTerm = json_decode($policyTerm, true); - $decoded_policyTerm['family_floater'] =0; - $decoded_policyTerm['family_floaters']['self'] =0; - $decoded_policyTerm['family_floaters']['spouse'] =0; - $decoded_policyTerm['family_floaters']['childrens'] =0; - $decoded_policyTerm['family_floaters']['parents'] =0; - $decoded_policyTerm['family_floaters']['parents-in-law'] =0; - $decoded_policyTerm['family_floaters']['either-parents-pil'] =0; + // if ( $this->request->getPost('is_addon') == 2 || $this->request->getPost('is_addon') == 3) { + // if ($this->request->getPost('is_addon') == 3) { + // $policyTerm = $policy_terms['policy_terms']; + // $decoded_policyTerm = json_decode($policyTerm, true); + // $decoded_policyTerm['family_floater'] =0; + // $decoded_policyTerm['family_floaters']['self'] =0; + // $decoded_policyTerm['family_floaters']['spouse'] =0; + // $decoded_policyTerm['family_floaters']['childrens'] =0; + // $decoded_policyTerm['family_floaters']['parents'] =0; + // $decoded_policyTerm['family_floaters']['parents-in-law'] =0; + // $decoded_policyTerm['family_floaters']['either-parents-pil'] =0; - $data['policy_terms'] = json_encode($decoded_policyTerm); - } else { - $data['policy_terms'] = $policy_terms['policy_terms']; - } + // $data['policy_terms'] = json_encode($decoded_policyTerm); + // } else { + // $data['policy_terms'] = $policy_terms['policy_terms']; + // } - } + // } // dd($data); $data['updated_by'] = get_session_userid(); @@ -1177,16 +1280,26 @@ class ClientController extends AdminController public function getClientPolicyById($id=null) { $this->myLogger->logme('error','getClientPolicyById function called'); + if($id){ $client_policy_data = $this->clientPolicyModel->where(['id' => $id, 'is_active' => 1])->first(); $insurer_id = $client_policy_data['insurer_id']; $client_id = $client_policy_data['client_id']; - $polices = $this->policesModel->where(['insurer_id' => $insurer_id, 'is_active' => 1])->findAll(); + + $base_policy_policy_type_id = 0; + if($client_policy_data['base_policy'] != null){ + $base_policy_policy_type_id = $this->clientPolicyModel->select('policy_type_id')->where(['id' => $client_policy_data['base_policy'], 'is_active' => 1])->first(); + } + + $polices = $this->policesModel + ->select('policies.*, policy_type.policy_type') + ->join('policy_type', 'policy_type.id = policies.policy_type_id') + ->where(['policies.insurer_id' => $insurer_id, 'policies.is_active' => 1]) + ->findAll(); $client_policy_list = $this->clientPolicyModel->getpolicyWithPattern( $client_id ); $cd_data = $this->CDMasterModel->where('client_id', $client_id)->where('insurer_id', $insurer_id)->findAll(); - - return $this->respond(['status' => true,'code' => 200, 'client_policy_list' => $client_policy_list, 'data' => $client_policy_data, 'cd_data' => $cd_data, "insurer_id" => $client_policy_data['insurer_id'], 'policy' => $polices], 200); + return $this->respond(['status' => true,'code' => 200, 'client_policy_list' => $client_policy_list, 'data' => $client_policy_data, 'cd_data' => $cd_data, "insurer_id" => $client_policy_data['insurer_id'], 'policy' => $polices, 'base_policy_type_id' => $base_policy_policy_type_id['policy_type_id']], 200); }else{ return $this->respond(['status' => false,'code' => 404, 'message' => 'no data found'], 200); } @@ -1416,9 +1529,9 @@ class ClientController extends AdminController $data['family_floaters']['parents-in-law'] =2; $data['family_floaters']['either-parents-pil'] =0; }else if($temp_family_floaters[$value] == '2EPORPIL'){ - $data['family_floaters']['parents'] =1; - $data['family_floaters']['parents-in-law'] =1; - $data['family_floaters']['either-parents-pil'] =0; + $data['family_floaters']['parents'] =0; + $data['family_floaters']['parents-in-law'] =0; + $data['family_floaters']['either-parents-pil'] =2; }else if($temp_family_floaters[$value] == 'EPORPIL'){ $data['family_floaters']['parents'] =0; $data['family_floaters']['parents-in-law'] =0; @@ -1514,6 +1627,7 @@ class ClientController extends AdminController $record = $this->clientPolicyModel->where('id', $client_policy_id)->first(); + // print_r($data);die; if ($record) { $update = $this->clientPolicyModel->update($client_policy_id, $dataa); @@ -2172,9 +2286,14 @@ class ClientController extends AdminController - public function get_cd_ac($client_id, $insurer_id){ + public function get_cd_ac($client_id, $insurer_id) + { - $cd_data = $this->CDMasterModel->where('client_id', $client_id)->where('insurer_id', $insurer_id)->findAll(); + $cd_data = $this->CDMasterModel + ->where('client_id', $client_id) + ->where('insurer_id', $insurer_id) + ->where('is_active', 1) + ->findAll(); if($cd_data){ return $this->respond(['status' => true, 'code' => 200, 'data' => $cd_data], 200); @@ -2209,7 +2328,8 @@ class ClientController extends AdminController } - public function checkPolicyType($policy_type_id, $client_branch_id, $client_id){ + public function checkPolicyType($policy_type_id, $client_branch_id, $client_id) + { $policyCount = $this->clientPolicyModel ->where('policy_type_id', $policy_type_id) @@ -2274,7 +2394,8 @@ class ClientController extends AdminController - public function getPolicyTermsFormJson($policy_type_id){ + public function getPolicyTermsFormJson($policy_type_id) + { $JSON = $this->policyTypeModel->where('id', $policy_type_id)->first(); return $this->respond(['status' => true, 'data' => $JSON], 200); @@ -2303,6 +2424,19 @@ class ClientController extends AdminController return $this->respond(['status' => false, 'data' => 0, 'message' => 'An error occurred while checking the mobile number. Please try again later.'], 500); } } + + public function checkAdditionPremiumJSON($client_id, $client_policy_id) + { + + $get_additional_rack_rate_relationship_json = $this->policyPremium2Model + ->where('client_id', $client_id) + ->where('client_policy_id', $client_policy_id) + ->where('is_active', 1) + ->where('additional_relationship IS NOT NULL', null, false) + ->countAllResults(); + + return $this->respond(['status' => true, 'data' => $get_additional_rack_rate_relationship_json, 'message' => "try"], 200); + } } \ No newline at end of file diff --git a/app/Controllers/MasterController.php b/app/Controllers/MasterController.php index 5d6ec3b9..0d7fde57 100644 --- a/app/Controllers/MasterController.php +++ b/app/Controllers/MasterController.php @@ -125,8 +125,6 @@ class MasterController extends AdminController } - - public function editInsurerOnboarding($id = null) { @@ -367,7 +365,6 @@ class MasterController extends AdminController // $this->loadLayout('insurer_onboarding', $data); } - public function tpaRemove($id = null) { $this->myLogger->logme('error','TPA Remove function called'); @@ -382,8 +379,6 @@ class MasterController extends AdminController } } - - public function removeTPABranch($id = null) { $this->myLogger->logme('error','TPA Branch Remove function called'); @@ -424,8 +419,6 @@ class MasterController extends AdminController } - - public function createTPAGeneralInfo() { @@ -483,12 +476,6 @@ class MasterController extends AdminController } } - - - - - - public function createTPABranch() { @@ -521,8 +508,6 @@ class MasterController extends AdminController } } - - public function editTPAOnboarding($id = null) { @@ -555,9 +540,6 @@ class MasterController extends AdminController } - - - public function editTPAGeneralInfo() { $this->myLogger->logme('error','edit TPA general info function called'); @@ -624,7 +606,6 @@ class MasterController extends AdminController } } - public function editTPAGet($id = null) { $this->myLogger->logme('error','Edit TPA Onboarding function called'); @@ -639,7 +620,6 @@ class MasterController extends AdminController exit(); } - public function editTPABranch() { $this->myLogger->logme('error','TPA branch CREATE function called'); @@ -680,7 +660,6 @@ class MasterController extends AdminController } } - public function tpaBranchList($id = null) { $this->myLogger->logme('error','TPA List function called'); @@ -693,14 +672,11 @@ class MasterController extends AdminController exit(); } - - - //Ends TPA Models + + //Start KYC - - public function kycList() { $this->myLogger->logme('error','KYC list function called'); diff --git a/app/Helpers/DepositHelper.php b/app/Helpers/DepositHelper.php index f6d14a7c..3565646e 100644 --- a/app/Helpers/DepositHelper.php +++ b/app/Helpers/DepositHelper.php @@ -94,7 +94,7 @@ class DepositHelper // $getLastBalanceQuery = "SELECT balance FROM cash_deposit WHERE client_id = ? AND insurer_id = ? ORDER BY created_at DESC LIMIT 1"; // $getLastBalanceParams = [$clientId, $insurerId]; - $getLastBalanceQuery = "SELECT balance FROM cash_deposit WHERE cd_ac_no = ? ORDER BY created_at DESC LIMIT 1"; + $getLastBalanceQuery = "SELECT balance FROM cash_deposit WHERE cd_ac_no = ? AND is_active = 1 ORDER BY created_at DESC LIMIT 1"; $getLastBalanceParams = [$cd_ac_no]; $lastBalance = $model->query($getLastBalanceQuery, $getLastBalanceParams)->getRow()->balance ?? null; @@ -103,7 +103,7 @@ class DepositHelper $cd_model = new ClientDepositModel(); - $getLastBalanceQuery = "SELECT opening_bal FROM cd_master WHERE client_id = ? AND insurer_id = ? AND cd_ac_no = ? ORDER BY created_at DESC LIMIT 1"; + $getLastBalanceQuery = "SELECT opening_bal FROM cd_master WHERE client_id = ? AND insurer_id = ? AND cd_ac_no = ? AND is_active = 1 ORDER BY created_at DESC LIMIT 1"; $getLastBalanceParams = [$clientId, $insurerId, $cd_ac_no]; $lastBalance = $cd_model->query($getLastBalanceQuery, $getLastBalanceParams)->getRow()->opening_bal ?? 0; diff --git a/app/Helpers/excel_import_export_helper.php b/app/Helpers/excel_import_export_helper.php index 65e44eaa..a86e5d80 100644 --- a/app/Helpers/excel_import_export_helper.php +++ b/app/Helpers/excel_import_export_helper.php @@ -3,6 +3,7 @@ use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Writer\Xlsx; use PhpOffice\PhpSpreadsheet\IOFactory; +use PhpOffice\PhpSpreadsheet\Reader\Exception as SpreadsheetReaderException; @@ -280,9 +281,9 @@ if (!function_exists('add_totals_row')) { $totalSum = 0; foreach ($data as $row) { - $gstSum += $row[18]; - $proRataPremiumSum += $row[19]; - $totalSum += $row[20]; + $gstSum += floatval($row[18]); + $proRataPremiumSum += floatval($row[19]); + $totalSum += floatval($row[20]); } // Add a new row with sums @@ -535,3 +536,439 @@ if (!function_exists('format_Excel_BasedOn_Client')) } } + + + +if(!function_exists('generate_excel_second_stage')){ + + function generate_excel_second_stage($headers, $data, $filename, $totals = null) + { + // Create a new Spreadsheet object + $spreadsheet = new Spreadsheet(); + + // Set the active sheet title + $spreadsheet->getActiveSheet()->setTitle('Sheet 1'); + + // Set headers into the spreadsheet + $headerValues = []; + foreach ($headers as $header) { + $headerValues[] = $header['column_name']; + } + $spreadsheet->getActiveSheet()->fromArray([$headerValues], null, 'A1'); + + // Set data into the spreadsheet + $dataValues = []; + $serialNumber = 0; // Initialize serial number + foreach ($data as $row) { + $serialNumber++; // Increment serial number for each row + + $rowData = []; + foreach ($headers as $header) { + $fieldName = $header['header_name']; + + if ($fieldName === 'index') { + $value = $serialNumber; + } else { + $value = $row->$fieldName ?? ''; + } + + $rowData[] = $value; + } + $dataValues[] = $rowData; + } + // dd($dataValues, $headerValues); + $spreadsheet->getActiveSheet()->fromArray($dataValues, null, 'A2'); + + // Add totals if specified + if ($totals === 1) { + // Call function to add totals row for inception + add_totals_row($spreadsheet, $data, $headers); + } else if ($totals === 2) { + // Call function to add totals row for deletion + add_totals_for_deletion($spreadsheet, $data); + } + + // Create Excel writer + $writer = new Xlsx($spreadsheet); + + try { + // Save Excel file to the specified path + $writer->save($filename); + return true; // Return true if file was successfully saved + } catch (\Exception $e) { + // Log or handle the exception + return false; // Return false if there was an error saving the file + } + } +} + + +if(!function_exists('generate_excel_third_stage')){ + + function generate_excel_third_stage($headers, $data, $filename, $totals = null) + { + // Create a new Spreadsheet object + $spreadsheet = new Spreadsheet(); + + // Set the active sheet title + $spreadsheet->getActiveSheet()->setTitle('Sheet 1'); + + $spreadsheet->getActiveSheet()->fromArray([$headers], null, 'A1'); + + $spreadsheet->getActiveSheet()->fromArray($data, null, 'A2'); + + // Add totals if specified + if ($totals === 1) { + // Call function to add totals row for inception + add_totals_row($spreadsheet, $data, $headers); + } else if ($totals === 2) { + // Call function to add totals row for deletion + add_totals_for_deletion($spreadsheet, $data); + } + + // Create Excel writer + $writer = new Xlsx($spreadsheet); + + try { + // Save Excel file to the specified path + $writer->save($filename); + return true; // Return true if file was successfully saved + } catch (\Exception $e) { + // Log or handle the exception + return false; // Return false if there was an error saving the file + } + } +} + + + +if(!function_exists('generate_insurer_based_excel')){ + + function generate_insurer_based_excel($excel_header_array, $excel_need_data){ + + usort($excel_header_array, function($a, $b) { + return $a['column_index'] <=> $b['column_index']; + }); + + + //construct HEADER + $headerValues = []; + foreach ($excel_header_array as $header) { + $headerValues[] = $header['column_name']; + } + + //construct EXCEL DATA + $dataValues = []; + $serialNumber = 0; // Initialize serial number + foreach ($excel_need_data as $row) { + $serialNumber++; + + $rowData = []; + foreach ($excel_header_array as $header) { + $fieldName = $header['header_name']; + + if ($fieldName === 'index') { + $value = $serialNumber; + } else { + $value = $row->$fieldName ?? ''; + } + + $rowData[] = $value; + } + $dataValues[] = $rowData; + } + + return ['header' => $headerValues, 'data' => $dataValues]; + } +} + + +if(!function_exists('read_first_row_of_excel')){ + + function read_first_row_of_excel($file) + { + if ($file->isValid() && !$file->hasMoved()) { + try { + $reader = IOFactory::createReaderForFile($file->getPathname()); + $spreadsheet = $reader->load($file->getPathname()); + + // Get the active sheet + $sheet = $spreadsheet->getActiveSheet(); + + // Initialize the data array + $data = []; + + // Iterate through rows to read data (only the first row) + $row = $sheet->getRowIterator()->current(); // Get the first row + $rowData = []; + foreach ($row->getCellIterator() as $cell) { + $rowData[] = $cell->getValue(); + } + $data = $rowData; // Assign the first row data to $data + + return $data; + + } catch (SpreadsheetReaderException $e) { + error_log('PhpSpreadsheet reader exception: ' . $e->getMessage()); + return $e->getMessage(); + } + } else { + return false; + } + } +} + + +if(!function_exists('query_construct_for_emp_policy_id')){ + function query_construct_for_emp_policy_id($employees, $col_index){ + + // Load the database connection + $db = \Config\Database::connect(); + + // Start building the query + $subQuery = ''; + foreach ($employees as $index => $employee) { + if ($index > 1) { + $subQuery .= " UNION ALL "; + } + if($index == 1){ + $row_id_alise = ' AS row_id,'; + $emp_name_alise = 'AS name,'; + $emp_code_alise = 'AS emp_code,'; + $emp_dob_alise = 'AS emp_dob,'; + $emp_gender_alise = 'AS emp_gender,'; + $pre_existing_alignments_alise = 'AS pre_existing_alignments,'; + $basic_cover_si_alise = 'AS basic_cover_si,'; + $emp_relationship_alise = 'AS emp_relationship,'; + $policy_end_date_alise = 'AS policy_end_date,'; + $days_alise = 'AS days,'; + $premium_alise = 'AS premium,'; + $rata_premimum_alise = 'AS rata_premimum,'; + $gst_alise = 'AS gst'; + }else{ + $row_id_alise = ','; + $emp_name_alise = ','; + $emp_code_alise = ','; + $emp_dob_alise = ','; + $emp_gender_alise = ','; + $pre_existing_alignments_alise = ','; + $basic_cover_si_alise = ','; + $emp_relationship_alise = ','; + $policy_end_date_alise = ','; + $days_alise = ','; + $premium_alise = ','; + $rata_premimum_alise = ','; + $gst_alise = ''; + } + $subQuery .= "SELECT " . intval($index) . $row_id_alise; + $subQuery .= "'" . $employee[$col_index['emp_name']] . "'" . $emp_name_alise; + $subQuery .= "'" . $employee[$col_index['emp_code']] . "'" . $emp_code_alise; + $subQuery .= "'" . $employee[$col_index['emp_dob']] . "'" . $emp_dob_alise; + $subQuery .= "'" . $employee[$col_index['emp_gender']] . "'" . $emp_gender_alise; + $subQuery .= "'" . $employee[$col_index['pre_existing_alignments']] . "'" . $pre_existing_alignments_alise; + $subQuery .= "'" . $employee[$col_index['basic_cover_si']] . "'" . $basic_cover_si_alise; + $subQuery .= "'" . $employee[$col_index['emp_relationship']] . "'" . $emp_relationship_alise; + $subQuery .= "'" . $employee[$col_index['policy_end_date']] . "'" . $policy_end_date_alise; + $subQuery .= "'" . $employee[$col_index['days']] . "'" . $days_alise; + $subQuery .= "'" . $employee[$col_index['premium']] . "'" . $premium_alise; + $subQuery .= "'" . $employee[$col_index['rata_premimum']] . "'" . $rata_premimum_alise; + $subQuery .= "'" . $employee[$col_index['gst']] . "'" . $gst_alise; + } + + // Complete the query + $mainQuery = " + SELECT + c.row_id, + c.emp_code, + c.name, + c.emp_dob, + c.emp_gender , + c.emp_relationship, + c.pre_existing_alignments, + c.basic_cover_si , + c.policy_end_date , + c.days , + c.premium , + c.rata_premimum , + c.gst, + + e.emp_code AS db_emp_code, + e.name AS db_name , + e.dob as db_dob, + e.gender as db_gender, + e.relationship as db_emp_relationship, + ep.pre_existing_alignments as db_pre_existing_alignments, + ep.basic_cover_si as db_basic_cover_si, + ep.policy_end_date as db_policy_end_date, + ep.days as db_days, + ep.premium as db_premium, + ep.rata_premimum as db_rata_premimum, + ep.gst as db_gst + + FROM ({$subQuery}) AS c + LEFT JOIN employees e + ON c.emp_code = e.emp_code + AND c.name = e.name + AND c.emp_dob = e.dob + AND c.emp_gender = e.gender + AND c.emp_relationship = e.relationship + + LEFT JOIN employee_polices ep + ON c.pre_existing_alignments = ep.pre_existing_alignments + AND c.basic_cover_si = ep.basic_cover_si + AND c.policy_end_date = ep.policy_end_date + AND c.days = ep.days + AND c.premium = ep.premium + AND c.rata_premimum = ep.rata_premimum + AND c.gst = ep.gst + + WHERE e.emp_code IS NOT NULL + AND e.name IS NOT NULL + AND e.dob IS NOT NULL + AND e.gender IS NOT NULL + AND e.relationship IS NOT NULL + AND ep.pre_existing_alignments IS NOT NULL + AND ep.basic_cover_si IS NOT NULL + AND ep.policy_end_date IS NOT NULL + AND ep.days IS NOT NULL + AND ep.premium IS NOT NULL + AND ep.rata_premimum IS NOT NULL + AND ep.gst IS NOT NULL + "; + + + // return $mainQuery; + // Execute the query + $query = $db->query($mainQuery); + $result = $query->getResultArray(); + return $result; + } +} + + +if(!function_exists('query_construct_second_stage')){ + function query_construct_second_stage($employees, $col_index){ + + // Load the database connection + $db = \Config\Database::connect(); + + // Start building the query + $subQuery = ''; + foreach ($employees as $index => $employee) { + if ($index > 1) { + $subQuery .= " UNION ALL "; + } + if($index == 1){ + $row_id_alise = ' AS row_id,'; + $emp_name_alise = 'AS name,'; + $emp_code_alise = 'AS emp_code,'; + $emp_dob_alise = 'AS emp_dob,'; + $emp_gender_alise = 'AS emp_gender,'; + $pre_existing_alignments_alise = 'AS pre_existing_alignments,'; + $basic_cover_si_alise = 'AS basic_cover_si,'; + $emp_relationship_alise = 'AS emp_relationship,'; + $policy_end_date_alise = 'AS policy_end_date,'; + $days_alise = 'AS days,'; + $premium_alise = 'AS premium,'; + $rata_premimum_alise = 'AS rata_premimum,'; + $gst_alise = 'AS gst'; + }else{ + $row_id_alise = ','; + $emp_name_alise = ','; + $emp_code_alise = ','; + $emp_dob_alise = ','; + $emp_gender_alise = ','; + $pre_existing_alignments_alise = ','; + $basic_cover_si_alise = ','; + $emp_relationship_alise = ','; + $policy_end_date_alise = ','; + $days_alise = ','; + $premium_alise = ','; + $rata_premimum_alise = ','; + $gst_alise = ''; + } + $subQuery .= "SELECT " . intval($index) . $row_id_alise; + $subQuery .= "'" . $employee[$col_index['emp_name']] . "'" . $emp_name_alise; + $subQuery .= "'" . $employee[$col_index['emp_code']] . "'" . $emp_code_alise; + $subQuery .= "'" . $employee[$col_index['emp_dob']] . "'" . $emp_dob_alise; + $subQuery .= "'" . $employee[$col_index['emp_gender']] . "'" . $emp_gender_alise; + $subQuery .= "'" . $employee[$col_index['pre_existing_alignments']] . "'" . $pre_existing_alignments_alise; + $subQuery .= "'" . $employee[$col_index['basic_cover_si']] . "'" . $basic_cover_si_alise; + $subQuery .= "'" . $employee[$col_index['emp_relationship']] . "'" . $emp_relationship_alise; + $subQuery .= "'" . $employee[$col_index['policy_end_date']] . "'" . $policy_end_date_alise; + $subQuery .= "'" . $employee[$col_index['days']] . "'" . $days_alise; + $subQuery .= "'" . $employee[$col_index['premium']] . "'" . $premium_alise; + $subQuery .= "'" . $employee[$col_index['rata_premimum']] . "'" . $rata_premimum_alise; + $subQuery .= "'" . $employee[$col_index['gst']] . "'" . $gst_alise; + } + + // Complete the query + $mainQuery = " + SELECT + c.row_id, + c.emp_code, + c.name, + c.emp_dob, + c.emp_gender , + c.emp_relationship, + c.pre_existing_alignments, + c.basic_cover_si , + c.policy_end_date , + c.days , + c.premium , + c.rata_premimum , + c.gst, + + e.emp_code AS db_emp_code, + e.name AS db_name , + e.dob as db_dob, + e.gender as db_gender, + e.relationship as db_emp_relationship, + ep.pre_existing_alignments as db_pre_existing_alignments, + ep.basic_cover_si as db_basic_cover_si, + ep.policy_end_date as db_policy_end_date, + ep.days as db_days, + ep.premium as db_premium, + ep.rata_premimum as db_rata_premimum, + ep.gst as db_gst + + FROM ({$subQuery}) AS c + LEFT JOIN employees e + ON c.emp_code = e.emp_code + AND c.name = e.name + AND c.emp_dob = e.dob + AND c.emp_gender = e.gender + AND c.emp_relationship = e.relationship + + LEFT JOIN employee_polices ep + ON c.pre_existing_alignments = ep.pre_existing_alignments + AND c.basic_cover_si = ep.basic_cover_si + AND c.policy_end_date = ep.policy_end_date + AND c.days = ep.days + AND c.premium = ep.premium + AND c.rata_premimum = ep.rata_premimum + AND c.gst = ep.gst + + WHERE e.emp_code IS NULL + AND e.name IS NULL + AND e.dob IS NULL + AND e.gender IS NULL + AND e.relationship IS NULL + AND ep.pre_existing_alignments IS NULL + AND ep.basic_cover_si IS NULL + AND ep.policy_end_date IS NULL + AND ep.days IS NULL + AND ep.premium IS NULL + AND ep.rata_premimum IS NULL + AND ep.gst IS NULL + "; + + + // return $mainQuery; + // Execute the query + $query = $db->query($mainQuery); + $result = $query->getResultArray(); + return $result; + } +} + diff --git a/app/Models/ClientBranchModel.php b/app/Models/ClientBranchModel.php index 1ace7a2a..c6083a49 100644 --- a/app/Models/ClientBranchModel.php +++ b/app/Models/ClientBranchModel.php @@ -19,6 +19,11 @@ class ClientBranchModel extends Model "created_by", "updated_by", "is_active", + "pincode", + "address1", + "address2", + "gst", + "sez", ]; public function getBranchAndContactByBranchId($branch_id){ diff --git a/app/Models/ClientPolicyModel.php b/app/Models/ClientPolicyModel.php index 8d2af103..b75ca69c 100644 --- a/app/Models/ClientPolicyModel.php +++ b/app/Models/ClientPolicyModel.php @@ -131,11 +131,12 @@ class ClientPolicyModel extends Model public function getinsurerswithclientid($id){ return $this->db->table('client_policy') - ->select('client_policy.*') + ->select('client_policy.*, cd_master.cd_ac_no') ->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') + ->join('cd_master', 'cd_master.insurer_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 @@ -195,6 +196,7 @@ class ClientPolicyModel extends Model ->join('policies', 'policies.id = client_policy.policy_id', 'left') ->where('cash_deposit.client_id', $clientId) ->where('cash_deposit.insurer_id', $insurerId) + ->where('cash_deposit.is_active', 1) ->orderBy('cash_deposit.id', 'DESC') ->get() ->getResult(); @@ -261,13 +263,25 @@ public function getBalances($clientId) 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(); + 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(); + ->select('cash_deposit.insurer_id, cash_deposit.cd_ac_no') + ->select('(SUM(CASE WHEN cash_deposit.transaction_type = \'Credit\' THEN cash_deposit.amount ELSE -cash_deposit.amount END) + cd_master.opening_bal) AS balance') + ->join('cd_master', 'cd_master.cd_ac_no = cash_deposit.cd_ac_no') + ->where('cash_deposit.client_id', $id) + ->groupBy(['cash_deposit.insurer_id', 'cash_deposit.cd_ac_no', 'cd_master.opening_bal']) + ->orderBy('cash_deposit.insurer_id', 'DESC') + ->orderBy('cash_deposit.cd_ac_no', 'DESC') + ->get() + ->getResult(); + } diff --git a/app/Models/InsurerModel.php b/app/Models/InsurerModel.php index 6c5d3617..f388b93b 100644 --- a/app/Models/InsurerModel.php +++ b/app/Models/InsurerModel.php @@ -23,21 +23,22 @@ class InsurerModel extends Model - public function getCreatedByUserName(){ + public function getCreatedByUserName() + { return $this->db->table('insurers') ->select('insurers.*') // ->select('user_profiles.first_name as user_name') // ->join('user_profiles', 'user_profiles.id = clients.created_by') ->get() - ->getResult(); - + ->getResult(); } public function getInsurerName($insurerId) { // Fetch the insurer name based on the insurer ID - $query = $this->select('id,name') - ->where('id', $insurerId) + $query = $this->select('insurers.id,insurers.name, cd_master.cd_ac_no') + ->join('cd_master', 'cd_master.insurer_id = insurers.id') + ->where('insurers.id', $insurerId) ->get(); if ($query->resultID->num_rows > 0) { @@ -47,19 +48,6 @@ class InsurerModel extends Model 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/cd_master_list.php b/app/Views/cd_master_list.php index 21e599ce..6f781f49 100644 --- a/app/Views/cd_master_list.php +++ b/app/Views/cd_master_list.php @@ -40,7 +40,7 @@ table.dataTable thead th { Insurer Name Opening Date CD Account No - Deposite Amount + Opening Amount Date/User Action @@ -85,7 +85,7 @@ table.dataTable thead th {
diff --git a/app/Views/client_branch.php b/app/Views/client_branch.php index 81b308e4..3ff68b11 100644 --- a/app/Views/client_branch.php +++ b/app/Views/client_branch.php @@ -51,7 +51,18 @@
-
+
+ + +
+
+ + +
+
+ +
+
-
+
-
+
+
+ + +
+
+ +
+
+ + +
+
+ + + +

@@ -83,13 +113,17 @@ name="name[]" id="name" required>
- - + +
+
+ + +
-
- - -
- - + +
- - + +
- - + +
diff --git a/app/Views/client_deposit_list.php b/app/Views/client_deposit_list.php index bb261f17..3df642a9 100644 --- a/app/Views/client_deposit_list.php +++ b/app/Views/client_deposit_list.php @@ -21,6 +21,7 @@ Insurer Name + CD Account Number Current Balance Action @@ -30,9 +31,9 @@ - - insurer_name;?> - + + insurer_name;?> + cd_ac_no;?> ₹ - View Deposit - - - -
diff --git a/app/Views/client_list.php b/app/Views/client_list.php index 2d84afdf..09850d79 100644 --- a/app/Views/client_list.php +++ b/app/Views/client_list.php @@ -58,7 +58,7 @@ table.dataTable thead th {