diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 041caaa3..ba34cea6 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -213,7 +213,7 @@ $routes->group("/master", ["filter" => "authMVC"], function ($routes) { $routes->post("create", "MasterController::createCDMasterData"); $routes->post("edit", "MasterController::editCDMasterData"); $routes->get("list/(:any)", "MasterController::getCDMasterDataByID/$1"); - // $routes->get("remove/(:any)", "MasterController::policyTypeRemove/$1"); + $routes->get("remove/(:any)", "MasterController::removeCDMaster/$1"); }); }); @@ -248,6 +248,7 @@ $routes->group("/util", ["filter" => "authMVC"], function ($routes) { $routes->get("check_policy_type/(:any)", "ClientController::checkPolicyType/$1"); $routes->get("getPolicyTerms/(:any)", "ClientController::getPolicyTerms/$1"); $routes->get("getPolicyTermsFormJson/(:any)", "ClientController::getPolicyTermsFormJson/$1"); + $routes->get("checkHRNumber/(:any)", "ClientController::checkHRNumber/$1"); }); $routes->cli('cli/processjob', 'JobWorker::processJob'); @@ -271,9 +272,9 @@ $routes->group("/api", ["filter" => "authJWT"], function ($routes) { - +$routes->get("getChatResponse", "ChatBotController::getChatResponse"); $routes->group("employeeRest", ["filter" => "authJWT"], function ($routes) { - + $routes->get("getChatResponse", "ChatBotController::getChatResponse"); $routes->get("getEmployeeProfile", "EmployeeRestController::getEmployeeProfile"); $routes->post("employeeUpload", "EmployeeRestController::employeeUpload"); $routes->get("relationshipList", "EmployeeRestController::relationshipList"); @@ -304,6 +305,9 @@ $routes->group("employeeRest", ["filter" => "authJWT"], function ($routes) { $routes->get("getAdvertisementImage", "EmployeeRestController::getAdvertisementImage"); }); + + + $routes->post("sendEmail", "EmployeeRestController::send_email"); diff --git a/app/Controllers/ChatBotController.php b/app/Controllers/ChatBotController.php new file mode 100644 index 00000000..d048ada7 --- /dev/null +++ b/app/Controllers/ChatBotController.php @@ -0,0 +1,118 @@ +myLogger = \Config\Services::mylogger(); + $this->employeeModel = new EmployeeModel(); + $this->employeePolicyModel = new EmployeePolicyModel(); + $this->clientModel = new ClientModel(); + $this->clientRMModel = new ClientRMModel(); + $this->policesModel = new PolicesModel(); + $this->relationshipModel = new RelationshipModel(); + $this->fileModel= new FileModel(); + $this->clientPolicyModel = new ClientPolicyModel(); + $this->policyPremium1Model = new PolicyPremium1Model(); + $this->policyPremium2Model = new PolicyPremium2Model(); + $this->policyTypeModel = new PolicyTypeModel(); + $this->notificationModel = new NotificationModel(); + $this->userModel = new UserModel(); + $this->feContentModel = new FEContentModel(); + $this->addImgModel = new AddImgModel(); + $this->ChatBotModel = new ChatBotModel(); + } + + + public function getChatResponse() + { + // try { + $request_for = $this->request->getGet('request_for'); + $option = $this->request->getGet('option'); + + $requestData = $this->ChatBotModel->where('request', $request_for) + ->where('is_active', 1 ) + ->first(); + + if ($requestData) { + + + + if($option != 0){ + + $decodedData = json_decode($requestData['options'],true); + + $requestFor = $decodedData[$request_for][$option]; + + $requestData = $this->ChatBotModel->where('request', $requestFor) + ->where('is_active', 1 ) + ->first(); + } + + + $result = ['request_for'=>$requestData['request'],'options'=>json_decode($requestData['options'],true)]; + return $this->respond(['status' => 'success','code' => 200,'data' => $result ],200); + + + + + } else { + + return $this->respond(['status' => 'failed','code' => 404,'data' => 'No Data'],404); + } + // } catch (\Throwable $th) { + // return $this->respond(['status' => 'failed','code' => 500,'data' => $th],500); + // } + } + + + +} + diff --git a/app/Controllers/ClientController.php b/app/Controllers/ClientController.php index 86556e52..01f35d7c 100644 --- a/app/Controllers/ClientController.php +++ b/app/Controllers/ClientController.php @@ -301,9 +301,9 @@ class ClientController extends AdminController $editData['client_kyc'] = $this->clientKYCDocsModel->where('client_id', $id)->findAll(); $editData['client_branch'] = $this->clientBranchModel->where(['client_id' => $id, 'is_active' => 1])->findAll(); $editData['client_relation'] = $this->clientRMModel->where(['client_id' => $id, 'is_active' => 1])->findAll(); - // dd('Hi'); + $editData['client_branch']['role'] = get_role_id(); $clientPoliceData = $this->clientPolicyModel->getClientPolicyByClientId($id); - // dd($this->clientPolicyModel->getLastQuery()); + foreach ($clientPoliceData as $key => $value) { $clientPoliceData[$key]->policy_start_date = date('d-M-Y', strtotime($value->policy_start_date)); @@ -311,12 +311,10 @@ class ClientController extends AdminController } $editData['client_policy'] = $clientPoliceData; - - $editData['notification'] =$this->notificationModel->select('template_name,enabled')->where('client_id',$id)->findAll(); $editData['placeHolders'] = ['member_name','nhance_logo','tpa_id','ecard_download_link', 'client_logo', 'policy_no', 'member_summary', 'app_link', 'post_enrollment_app_link', 'client_name']; - + // dd($editData); echo view('layout/header', $headerData); echo view('client_onboarding', $editData); echo view('layout/footer'); @@ -565,6 +563,7 @@ class ClientController extends AdminController if($insert){ $branchData = $this->clientBranchModel->where('client_id', $this->request->getPost('client_id'))->findAll(); + $branchData['role'] = get_role_id(); return $this->respond(['status' => true,'code' => 200,'data' => $branchData], 200); }else{ return $this->respond(['status' => false,'code' => 404, 'message' => 'no data found'], 200); @@ -1907,7 +1906,7 @@ class ClientController extends AdminController "sum_insured" => "Sum Insured", "family_floater" => "Family Floater", "family_floaters" => "Family Floaters", - "member_count" => "Elders Count:", + "elders_count" => "Elders Count:", "other_member_min_age" => "Min Age:", "other_member_max_age" => "Min Age:", "waiverofpreexistingdiseases" => "Waiver of Pre-existing Diseases", @@ -2067,19 +2066,27 @@ class ClientController extends AdminController } else if (array_key_exists($key, $mapping)) { $transformedData[$mapping[$key]] = $value; } else if ($key == 'special_condition_label') { - - foreach ($value as $key => $value) { - $transformedData[$value] = $data['special_condition_input'][$key]; + + if (is_array($value)) { + foreach ($value as $key => $value) { + $transformedData[$value] = $data['special_condition_input'][$key]; + } } - } else if ($key == 'gpa_special_condition_label') { - foreach ($value as $key => $value) { - $transformedData[$value] = $data['gpa_special_condition_input'][$key]; + } else if ($key == 'gpa_special_condition_label') { + if (is_array($value)) { + foreach ($value as $key => $value) { + $transformedData[$value] = $data['gpa_special_condition_input'][$key]; + } + } + } else if ($key == 'other_special_condition_label') { + if (is_array($value)) { + foreach ($value as $key => $value) { + $transformedData[$value] = $data['other_special_condition_label'][$key]; + } } } else if ($key == 'age_ratio') { - if (isset($data['sumInsured2'])) { - $transformedData['Self'] = "(Min: " . $data['age_ratio']['self']['min'] . ", Max: " . $data['age_ratio']['self']['max'] . ")"; } } else { @@ -2199,7 +2206,7 @@ class ClientController extends AdminController } - public function checkPolicyType($client_policy_id, $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) @@ -2217,23 +2224,52 @@ class ClientController extends AdminController } - public function getPolicyTerms($client_policy_id){ - + public function getPolicyTerms($client_policy_id) + { $policy_terms = $this->clientPolicyModel->where('id', $client_policy_id)->first(); - - if(isset($policy_terms['policy_terms']) && $policy_terms['policy_terms'] != null){ - - $JSON = json_decode($policy_terms['policy_terms']); - $si = $JSON->sum_insured ?? $JSON->sumInsured2; - $multi_si = $JSON->multiple_sum_insured; - $multi_si[] = $si; - }else{ - $$multi_si = []; + + if (!$policy_terms) { + return $this->respond(['status' => false, 'error' => 'Policy not found'], 404); } - - return $this->respond(['status' => true, 'data'=>$multi_si], 200); + + if (is_array($policy_terms)) { + if (!isset($policy_terms['policy_terms'])) { + return $this->respond(['status' => false, 'error' => 'Policy terms not found in array'], 500); + } + $JSON = json_decode($policy_terms['policy_terms']); + } elseif (is_object($policy_terms)) { + if (!isset($policy_terms->policy_terms)) { + return $this->respond(['status' => false, 'error' => 'Policy terms not found in object'], 500); + } + $JSON = json_decode($policy_terms->policy_terms); + } else { + return $this->respond(['status' => false, 'error' => 'Unexpected data type for policy terms'], 500); + } + + if (!$JSON) { + return $this->respond(['status' => false, 'error' => 'Invalid JSON format in policy terms'], 500); + } + + $multi_si = []; + + if (isset($JSON->sum_insured) && !empty($JSON->sum_insured)) { + $multi_si[] = $JSON->sum_insured; + } elseif (isset($JSON->sumInsured2) && !empty($JSON->sumInsured2)) { + $multi_si[] = $JSON->sumInsured2; + } + + if (isset($JSON->multiple_sum_insured) && is_array($JSON->multiple_sum_insured)) { + foreach ($JSON->multiple_sum_insured as $msi) { + if (!empty($msi)) { + $multi_si[] = $msi; + } + } + } + + return $this->respond(['status' => true, 'data' => $multi_si], 200); } - + + public function getPolicyTermsFormJson($policy_type_id){ @@ -2246,4 +2282,24 @@ class ClientController extends AdminController } + public function checkHRNumber($mobileNumber) + { + try { + $mobileNumberCount = $this->levelContactModel + ->join('client_branch', 'client_branch.id = level_contacts.ref_id') + ->join('clients', 'clients.id = client_branch.client_id') + ->where('clients.is_active', 1) + ->where('client_branch.is_active', 1) + ->where('level_contacts.is_active', 1) + ->where('level_contacts.contact_type', 'client') + ->where('level_contacts.mobile', $mobileNumber) + ->countAllResults(); + return $this->respond(['status' => true, 'data' => $mobileNumberCount, 'message' => "try"], 200); + } catch (\Exception $e) { + log_message('error', 'Error checking mobile number: ' . $e->getMessage()); + return $this->respond(['status' => false, 'data' => 0, 'message' => 'An error occurred while checking the mobile number. Please try again later.'], 500); + } + } + + } \ No newline at end of file diff --git a/app/Controllers/EmpDataServiceController.php b/app/Controllers/EmpDataServiceController.php index 3cb36091..96537b76 100644 --- a/app/Controllers/EmpDataServiceController.php +++ b/app/Controllers/EmpDataServiceController.php @@ -140,15 +140,30 @@ class EmpDataServiceController extends BaseController // Fetch employee data for export from the database $objects = $this->employeePolicyModel->getInceptionEmployeeDataForExportExcel($export_data); - $insurer_id = $this->clientPolicyModel->where('id', $export_data['client_policy_id'])->first(); - $cash_balance = $this->clientDepositModel->where('client_id', $export_data['client_id'])->where('insurer_id', $insurer_id['insurer_id'])->orderBy('id', 'DESC')->first(); + $policy_details = $this->clientPolicyModel->where('id', $export_data['client_policy_id'])->first(); - if($cash_balance == null){ + // dd($export_data, $policy_details['cd_ac_no']); + + if ($policy_details['cd_ac_no'] == null) { + // dd("The policy does not have a CD account number"); + $this->myLogger->logme('error', 'The policy does not have a CD account number.'); + return 5; + } + + $cash_balance = $this->clientDepositModel->where('cd_ac_no', $policy_details['cd_ac_no'])->orderBy('id', 'DESC')->first(); + + if ($cash_balance == null) { + + $balance = $this->CDMasterModel + ->where('client_id', $export_data['client_id']) + ->where('insurer_id', $policy_details['insurer_id']) + ->where('cd_ac_no', $policy_details['cd_ac_no']) + ->first(); - $balance = $this->CDMasterModel->where('client_id', $export_data['client_id'])->where('insurer_id', $insurer_id['insurer_id'])->orderBy('id', 'DESC')->first(); $cash_balance['balance'] = $balance['opening_bal']; } + // dd($cash_balance); // Calculate the total amount from the objects $totals = array_reduce($objects, function ($carry, $item) { @@ -158,9 +173,8 @@ class EmpDataServiceController extends BaseController $totals = round($totals, 2); if (!empty($cash_balance)) { - + if ((int) $cash_balance['balance'] < (int) $totals) { - $this->myLogger->logme('error', 'Inception export failed due to insufficient deposit amount.'); $this->myLogger->logme('error', 'Inception export failed due to insufficient deposit amount. CASH BALANCE : {balance} and TOTAL AMOUNT : {total}', ['balance' => $cash_balance['balance'], 'total' => $totals]); return 0; @@ -363,6 +377,26 @@ class EmpDataServiceController extends BaseController $ids = []; $objects = $this->employeePolicyModel->getSIEnhancementEmployeesDataForExportExcel($export_data); + $policy_details = $this->clientPolicyModel->where('id', $export_data['client_policy_id'])->first(); + + if ($policy_details['cd_ac_no'] == null) { + $this->myLogger->logme('error', 'The policy does not have a CD account number.'); + return 1; + } + + $cash_balance = $this->clientDepositModel->where('cd_ac_no', $policy_details['cd_ac_no'])->orderBy('id', 'DESC')->first(); + + if ($cash_balance == null) { + + $balance = $this->CDMasterModel + ->where('client_id', $export_data['client_id']) + ->where('insurer_id', $policy_details['insurer_id']) + ->where('cd_ac_no', $policy_details['cd_ac_no']) + ->first(); + + $cash_balance['balance'] = $balance['opening_bal']; + } + $totals = 0; foreach ($objects as $obj) { @@ -374,6 +408,14 @@ class EmpDataServiceController extends BaseController // echo '
';
// print_r($ids); die;
+ if (!empty($cash_balance)) {
+ if ((int) $cash_balance['balance'] < (int) $rounded_totals) {
+ $this->myLogger->logme('error', 'Inception export failed due to insufficient deposit amount.');
+ $this->myLogger->logme('error', 'Inception export failed due to insufficient deposit amount. CASH BALANCE : {balance} and TOTAL AMOUNT : {total}', ['balance' => $cash_balance['balance'], 'total' => $totals]);
+ return 0;
+ }
+ }
+
$count = count($objects);
$export_data['count'] = $count;
$export_data['amount'] = $rounded_totals;
@@ -545,7 +587,7 @@ class EmpDataServiceController extends BaseController
}
-
+ //not in use
public function generateExcelForAdditionAndDependentAddition($export_data)
{
$ids = [];
@@ -628,7 +670,7 @@ class EmpDataServiceController extends BaseController
}
}
}
-
+ //end not in use
/**
* The below functions are Imports data from an Excel file for :
@@ -2788,7 +2830,7 @@ class EmpDataServiceController extends BaseController
//Endorsement Addition and Dependent Addition
-
+ //not in use
public function AdditionAndDependentAddition($params)
{
@@ -3179,6 +3221,7 @@ class EmpDataServiceController extends BaseController
}
+ //end not in use
/**
* The below functions are Calculates and records cash deposits for employee policies at inception.
diff --git a/app/Controllers/EmployeeController.php b/app/Controllers/EmployeeController.php
index 80571810..ae32b9a4 100644
--- a/app/Controllers/EmployeeController.php
+++ b/app/Controllers/EmployeeController.php
@@ -79,13 +79,16 @@ class EmployeeController extends AdminController
$data['employees'] = $this->employeePolicyModel->getEmployeePolicy(
client_id: $filterData['client_id'],
policy_id: $filterData['policy_id'],
- status: $filterData['status'],
- branch_id: $filterData['branch_id']
+ branch_id: $filterData['branch_id'],
+ emp_code : $filterData['emp_code'],
+ emp_name : $filterData['emp_name'],
+ status : $filterData['status'],
);
$data['getData'] = $filterData;
}
+ // dd($this->request->getGet());
$this->myLogger->logme('error', 'list called');
$this->loadLayout('employee_list', $data);
}
@@ -408,10 +411,15 @@ class EmployeeController extends AdminController
$return = $empDataServiceController->generateExcelForAdditionandInception($batch_data);
- if ($return == 0) {
+ if ($return === 0) {
session()->setFlashdata('error', "Insufficient deposit amount.");
return redirect()->to(base_url('employee/upload'));
+
+ }else if($return === 5){
+
+ session()->setFlashdata('error', "The policy does not have a CD account number.");
+ return redirect()->to(base_url('employee/upload'));
}
if (!$return) {
@@ -439,10 +447,14 @@ class EmployeeController extends AdminController
$return = $empDataServiceController->generateExcelForSIEnhancement($batch_data);
- if ($return == 0) {
+ if ($return === 0) {
session()->setFlashdata('error', "Insufficient deposit amount.");
return redirect()->to(base_url('employee/upload'));
+ }else if($return === 5){
+
+ session()->setFlashdata('error', "The policy does not have a CD account number.");
+ return redirect()->to(base_url('employee/upload'));
}
if (!$return) {
@@ -1056,33 +1068,34 @@ class EmployeeController extends AdminController
public function viewECard()
{
- $this->loadLayout('ecard_template/default_ecard');
+ // $this->loadLayout('ecard_template/default_ecard');
- // Load the session library if it's not autoloaded
- // $session = \Config\Services::session();
-
- // Access session data
- $sessionData = session()->get();
-
- // Check if session data exists and if expiration time is set
- if (!empty($sessionData) && isset($sessionData['isLoggedIn']) && isset($sessionData['session_expiration'])) {
- // Get the session expiration timestamp
- $expirationTimestamp = $sessionData['session_expiration'];
-
- // Get the current timestamp
- $currentTimestamp = time();
-
- // Check if the current time is greater than the expiration time
- if ($currentTimestamp > $expirationTimestamp) {
- // Session has expired
- echo "Session has expired";
- } else {
- // Session is active
- echo "Session is active";
- }
- } else {
- // Session data is not set or session is not started
- echo "Session is not started or data is not set";
+ $empDataServiceController = new EmpDataServiceController();
+ $file_name = generate_filename("TCS", 'inception', 'export', 'insurer', 'policy', 'branch');
+
+ $batch_data = [
+ 'client_id' => 12,
+ 'client_policy_id' => 12,
+ 'client_branch_id' => 1,
+ 'insurer_or_tpa' => 'insurer',
+ 'event_type' => 'inception',
+ 'actions' => 'export',
+ 'file_name' => $file_name,
+ ];
+
+ $return = $empDataServiceController->generateExcelForAdditionandInception($batch_data);
+
+ if ($return == 0) {
+
+ dd('error', "Insufficient deposit amount.");
+
+ }else if($return == 1){
+
+ dd('error', "The policy does not have a CD account number.");
+ }
+
+ if (!$return) {
+ dd('error', "No data was found");
}
}
diff --git a/app/Controllers/MasterController.php b/app/Controllers/MasterController.php
index 04f1e336..5d6ec3b9 100644
--- a/app/Controllers/MasterController.php
+++ b/app/Controllers/MasterController.php
@@ -1123,13 +1123,7 @@ class MasterController extends AdminController
public function CDMasterList()
{
- $data['CD_Master_Data'] = $this->CDMasterModel
- ->select('cd_master.*, clients.client_name, clients.short_name, insurers.name as insurer_name, user_profiles.first_name as user_name')
- ->join('clients', 'clients.id = cd_master.client_id')
- ->join('insurers', 'insurers.id = cd_master.insurer_id')
- ->join('user_profiles', 'user_profiles.id = cd_master.created_by')
- ->where('cd_master.is_active', 1)
- ->findAll();
+ $data['CD_Master_Data'] = $this->CDMasterModel->getCDMasterList();
$data['insurers'] = $this->insurerModel->findAll();
$data['clients'] = $this->clientModel->findAll();
$this->loadLayout('cd_master_list', $data);
@@ -1217,4 +1211,18 @@ class MasterController extends AdminController
}
}
+
+ public function removeCDMaster($id){
+
+ $this->myLogger->logme('error','CDMaster Remove function called');
+ $data['updated_by'] = get_session_userid();
+ $data['is_active'] = 0;
+ $update = $this->CDMasterModel->where('id', $id)->set($data)->update();
+ if($update){
+ return $this->respond(['status' => true,'code' => 200], 200);
+ }else{
+ return $this->respond(['status' => false,'code' => 404], 200);
+ }
+ }
+
}
\ No newline at end of file
diff --git a/app/Helpers/DepositHelper.php b/app/Helpers/DepositHelper.php
index 7d3c713d..f6d14a7c 100644
--- a/app/Helpers/DepositHelper.php
+++ b/app/Helpers/DepositHelper.php
@@ -33,7 +33,7 @@ class DepositHelper
public static function saveDeposit(array $data, int $loggedInUserID): array
{
// Retrieve the last known balance
- $lastBalance = self::calculateLastBalance($data['client_id'], $data['insurer_id']);
+ $lastBalance = self::calculateLastBalance($data['client_id'], $data['insurer_id'], $data['cd_ac_no']);
// Calculate the new balance based on the transaction type
$newBalance = self::calculateBalance(
@@ -87,24 +87,26 @@ class DepositHelper
*
* @return float The last known balance.
*/
- public static function calculateLastBalance(int $clientId, int $insurerId): float
+ public static function calculateLastBalance(int $clientId, int $insurerId, $cd_ac_no): 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];
+ // $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;
+ $getLastBalanceQuery = "SELECT balance FROM cash_deposit WHERE cd_ac_no = ? ORDER BY created_at DESC LIMIT 1";
+ $getLastBalanceParams = [$cd_ac_no];
- if(!$lastBalance){
+ $lastBalance = $model->query($getLastBalanceQuery, $getLastBalanceParams)->getRow()->balance ?? null;
+
+ if(empty($lastBalance) && $lastBalance == null){
$cd_model = new ClientDepositModel();
- $getLastBalanceQuery = "SELECT opening_bal FROM cd_master WHERE client_id = ? AND insurer_id = ? ORDER BY created_at DESC LIMIT 1";
- $getLastBalanceParams = [$clientId, $insurerId];
+ $getLastBalanceQuery = "SELECT opening_bal FROM cd_master WHERE client_id = ? AND insurer_id = ? AND cd_ac_no = ? ORDER BY created_at DESC LIMIT 1";
+ $getLastBalanceParams = [$clientId, $insurerId, $cd_ac_no];
$lastBalance = $cd_model->query($getLastBalanceQuery, $getLastBalanceParams)->getRow()->opening_bal ?? 0;
-
}
return $lastBalance;
diff --git a/app/Helpers/utility_helper.php b/app/Helpers/utility_helper.php
index 2dbcb1ce..87945e48 100644
--- a/app/Helpers/utility_helper.php
+++ b/app/Helpers/utility_helper.php
@@ -239,3 +239,12 @@ if (!function_exists('get_username')) {
}
+if (!function_exists('get_role_id')) {
+ function get_role_id() {
+
+ $role_id = get_session_userdata()->role;
+ return $role_id;
+ }
+}
+
+
diff --git a/app/Models/CDMasterModel.php b/app/Models/CDMasterModel.php
index 491d1007..0e5c39a1 100644
--- a/app/Models/CDMasterModel.php
+++ b/app/Models/CDMasterModel.php
@@ -61,4 +61,26 @@ class CDMasterModel extends Model
return $data;
}
+ public function getCDMasterList(){
+
+ $query = $this->db->table('cd_master')
+ ->select('cd_master.*, clients.client_name, clients.short_name, insurers.name AS insurer_name, user_profiles.first_name AS user_name, IFNULL(cd_ac_counts.cd_ac_no_count, 0) AS cd_ac_no_count')
+ ->join('clients', 'clients.id = cd_master.client_id')
+ ->join('insurers', 'insurers.id = cd_master.insurer_id')
+ ->join('user_profiles', 'user_profiles.id = cd_master.created_by')
+ ->join(
+ '(SELECT cd_master.cd_ac_no, COUNT(client_policy.cd_ac_no) AS cd_ac_no_count
+ FROM cd_master
+ JOIN client_policy ON client_policy.cd_ac_no = cd_master.cd_ac_no
+ GROUP BY cd_master.cd_ac_no) AS cd_ac_counts',
+ 'cd_ac_counts.cd_ac_no = cd_master.cd_ac_no',
+ 'left'
+ )
+ ->where('cd_master.is_active', 1)
+ ->get();
+
+ $result = $query->getResultArray();
+ return $result;
+ }
+
}
diff --git a/app/Models/ChatBotModel.php b/app/Models/ChatBotModel.php
new file mode 100644
index 00000000..caae27a5
--- /dev/null
+++ b/app/Models/ChatBotModel.php
@@ -0,0 +1,22 @@
+
\ No newline at end of file
diff --git a/app/Models/ClientPolicyModel.php b/app/Models/ClientPolicyModel.php
index a339b142..a69cf852 100644
--- a/app/Models/ClientPolicyModel.php
+++ b/app/Models/ClientPolicyModel.php
@@ -77,12 +77,14 @@ class ClientPolicyModel extends Model
->select('insurer_branch.branch_name as insurer_branch_name, insurer_branch.branch_code as insurer_branch_code')
->select('tpa_branch.branch_name as tpa_branch_name, tpa_branch.branch_code as tpa_branch_code')
->select('policy_type.policy_type as policy_type_name')
+ ->select('client_branch.branch_name as branch_name')
->join('insurers', 'insurers.id = client_policy.insurer_id')
->join('insurer_branch', 'client_policy.insurer_branch_id = insurer_branch.id')
->join('tpa', 'tpa.id = client_policy.tpa_id', 'left')
->join('tpa_branch', 'client_policy.tpa_branch_id = tpa_branch.id', 'left')
->join('policies', 'policies.id = client_policy.policy_id')
->join('policy_type', 'policy_type.id = policies.policy_type_id')
+ ->join('client_branch', 'client_branch.id = client_policy.client_branch_id')
->where('client_policy.client_id', $client_id)
->where('client_policy.policy_status', 1)
->where('client_policy.is_active', 1)
diff --git a/app/Models/EmployeePolicyModel.php b/app/Models/EmployeePolicyModel.php
index 2dcac592..15bf295d 100644
--- a/app/Models/EmployeePolicyModel.php
+++ b/app/Models/EmployeePolicyModel.php
@@ -76,31 +76,68 @@ class EmployeePolicyModel extends Model
}
// -----------------------------------------------------------------------------------------------------
- public function getEmployeePolicy($client_id,$policy_id,$status,$branch_id)
+ public function getEmployeePolicy($client_id = 0, $policy_id=0, $status=0, $branch_id=0, $emp_code="", $emp_name="")
{
- $result = $this->select(['employee_polices.*','pm.name as policy_name','im.short_name as insurer_short_name','ib.branch_name as insurer_branch_name','ib.branch_code as insurer_branch_code','tpam.name as tpa_name','tpam.short_name as tpa_short_name','tpab.branch_code as tpa_branch_code','cm.client_name','cm.short_name as client_short_name','emp.relationship','emp.relationship_code','emp.change_event','emp.emp_code','emp.name','emp.email_corporate','emp.dob','emp.gender','emp.emp_status','emp.is_active as emp_is_active','emp.mobile as mobile'])
- ->join('employees emp', 'employee_polices.employee_id = emp.id')
- ->join('client_policy cp', 'employee_polices.client_policy_id = cp.id') //cp - client policy
- ->join('policies pm', 'cp.policy_id = pm.id') //pm - policy master
- ->join('insurers im', 'cp.insurer_id = im.id') //im - insurar master
- ->join('insurer_branch ib', 'cp.insurer_branch_id = ib.id') //ib - insurar branch
- ->join('tpa tpam', 'cp.tpa_id = tpam.id','left') //tpam - tpa master
- ->join('tpa_branch tpab', 'cp.tpa_branch_id = tpab.id','left') //tpab - tpa brach
- ->join('clients cm', 'cp.client_id = cm.id') //cm - client master
- ->where('emp.client_id',$client_id)
- ->where('emp.client_branch_id',$branch_id)
- ->where('employee_polices.is_active',1)
- ->where('emp.is_active',1)
- ->where('employee_polices.client_policy_id',$policy_id)
- ->orderBy('emp.emp_code','ASC')->orderBy('employee_polices.employee_id','ASC');
-
-
- if($status != 0 && !empty($status)){
+
+ $result = $this->select([
+ 'employee_polices.*',
+ 'pm.name as policy_name',
+ 'im.short_name as insurer_short_name',
+ 'ib.branch_name as insurer_branch_name',
+ 'ib.branch_code as insurer_branch_code',
+ 'tpam.name as tpa_name',
+ 'tpam.short_name as tpa_short_name',
+ 'tpab.branch_code as tpa_branch_code',
+ 'cm.client_name',
+ 'cm.short_name as client_short_name',
+ 'emp.relationship',
+ 'emp.relationship_code',
+ 'emp.change_event',
+ 'emp.emp_code',
+ 'emp.name',
+ 'emp.email_corporate',
+ 'emp.dob',
+ 'emp.gender',
+ 'emp.emp_status',
+ 'emp.is_active as emp_is_active',
+ 'emp.mobile as mobile'
+ ])
+ ->join('employees emp', 'employee_polices.employee_id = emp.id')
+ ->join('client_policy cp', 'employee_polices.client_policy_id = cp.id') //cp - client policy
+ ->join('policies pm', 'cp.policy_id = pm.id') //pm - policy master
+ ->join('insurers im', 'cp.insurer_id = im.id') //im - insurer master
+ ->join('insurer_branch ib', 'cp.insurer_branch_id = ib.id') //ib - insurer branch
+ ->join('tpa tpam', 'cp.tpa_id = tpam.id', 'left') //tpam - tpa master
+ ->join('tpa_branch tpab', 'cp.tpa_branch_id = tpab.id', 'left') //tpab - tpa branch
+ ->join('clients cm', 'cp.client_id = cm.id') //cm - client master
+ ->orderBy('emp.emp_code', 'ASC')
+ ->orderBy('employee_polices.employee_id', 'ASC');
+
+ // Conditionally add where clauses
+ if ($client_id !=0 && !empty($client_id)) {
+ $result->where('emp.client_id', $client_id);
+ }
+ if ($branch_id !=0 && !empty($branch_id)) {
+ $result->where('emp.client_branch_id', $branch_id);
+ }
+ if ($policy_id !=0 && !empty($policy_id)) {
+ $result->where('employee_polices.client_policy_id', $policy_id);
+ }
+ if ($status !=0 && !empty($status)) {
$result->where('employee_polices.status', $status);
}
+ if (!empty($emp_code)) {
+ $result->where('emp.emp_code', $emp_code);
+ }
+ if (!empty($emp_name)) {
+ $result->like('emp.name', $emp_name);
+ }
- $result = $result->findAll();
- return ($result);
+ // Always check these conditions
+ $result->where('employee_polices.is_active', 1)
+ ->where('emp.is_active', 1);
+
+ return $result->findAll();
}
diff --git a/app/Views/cd_master_list.php b/app/Views/cd_master_list.php
index 7a001b39..21e599ce 100644
--- a/app/Views/cd_master_list.php
+++ b/app/Views/cd_master_list.php
@@ -58,12 +58,12 @@ table.dataTable thead th {
@@ -290,4 +290,50 @@ table.dataTable thead th {
})
+
+function removeCDMaster(element) {
+
+ Swal.fire({
+ title: "Are you sure?",
+ text: "You need to remove this CD.",
+ icon: "info",
+ showCancelButton: true,
+ confirmButtonColor: "#3085d6",
+ confirmButtonText: "Yes",
+ }).then((result) => {
+
+ if (result.isConfirmed) {
+ var id = element.getAttribute('data-id');
+ var form_action = '= base_url("master/cash_deposite/remove/") ?>' + id;
+ $.ajax({
+ url: form_action,
+ type: "GET",
+ dataType: 'json',
+ processData: false,
+ contentType: false,
+ success: function(res) {
+ // console.log(res.status == true);
+ if(res){
+ if (res.status == true) {
+ toastr.success('CD removed successfully.', 'success');
+ location.reload();
+ } else {
+ toastr.warning('Failed to remove CD.', 'warning');
+ }
+ }
+ },
+ error: function (xhr, status, error) {
+ console.error(xhr.responseText);
+ console.error(status, error);
+ $('.loader').fadeOut();
+ $('.loader-mask').delay(350).fadeOut('slow');
+ console.log('Something Wrong!', 'warning');
+ }
+ });
+ }
+
+ });
+
+}
+
\ No newline at end of file
diff --git a/app/Views/client_branch.php b/app/Views/client_branch.php
index 93ea7137..81b308e4 100644
--- a/app/Views/client_branch.php
+++ b/app/Views/client_branch.php
@@ -1,11 +1,12 @@
-
+
-
+
-
-
+
+
@@ -23,52 +24,51 @@
-
+
-
+
-