diff --git a/.gitignore b/.gitignore
index 1f8cb67a..2e2d6962 100644
--- a/.gitignore
+++ b/.gitignore
@@ -22,6 +22,9 @@ writable/debugbar/*
writable/**/*.db
writable/**/*.sqlite
+writable/e_card_template/*
+!writable/e_card_template/.gitkeep
+
vendor/
build/
diff --git a/README.md b/README.md
index 8eaa7d72..b56458c2 100644
--- a/README.md
+++ b/README.md
@@ -1,61 +1,11 @@
# CodeIgniter 4 Framework
-## What is CodeIgniter?
+## Unit Testing
-CodeIgniter is a PHP full-stack web framework that is light, fast, flexible and secure.
-More information can be found at the [official site](https://codeigniter.com).
+From command propmt run the following cmds
-This repository holds the distributable version of the framework.
-It has been built from the
-[development repository](https://github.com/codeigniter4/CodeIgniter4).
+`php vendor/bin/phpunit tests\unit\GridType11PremiumCalculationTest.php`
-More information about the plans for version 4 can be found in [CodeIgniter 4](https://forum.codeigniter.com/forumdisplay.php?fid=28) on the forums.
+Run speeific method
-The user guide corresponding to the latest version of the framework can be found
-[here](https://codeigniter4.github.io/userguide/).
-
-## Important Change with index.php
-
-`index.php` is no longer in the root of the project! It has been moved inside the *public* folder,
-for better security and separation of components.
-
-This means that you should configure your web server to "point" to your project's *public* folder, and
-not to the project root. A better practice would be to configure a virtual host to point there. A poor practice would be to point your web server to the project root and expect to enter *public/...*, as the rest of your logic and the
-framework are exposed.
-
-**Please** read the user guide for a better explanation of how CI4 works!
-
-## Repository Management
-
-We use GitHub issues, in our main repository, to track **BUGS** and to track approved **DEVELOPMENT** work packages.
-We use our [forum](http://forum.codeigniter.com) to provide SUPPORT and to discuss
-FEATURE REQUESTS.
-
-This repository is a "distribution" one, built by our release preparation script.
-Problems with it can be raised on our forum, or as issues in the main repository.
-
-## Contributing
-
-We welcome contributions from the community.
-
-Please read the [*Contributing to CodeIgniter*](https://github.com/codeigniter4/CodeIgniter4/blob/develop/CONTRIBUTING.md) section in the development repository.
-
-## Server Requirements
-
-PHP version 7.4 or higher is required, with the following extensions installed:
-
-- [intl](http://php.net/manual/en/intl.requirements.php)
-- [mbstring](http://php.net/manual/en/mbstring.installation.php)
-
-> **Warning**
-> The end of life date for PHP 7.4 was November 28, 2022. If you are
-> still using PHP 7.4, you should upgrade immediately. The end of life date
-> for PHP 8.0 will be November 26, 2023.
-
-Additionally, make sure that the following extensions are enabled in your PHP:
-
-- json (enabled by default - don't turn it off)
-- [mysqlnd](http://php.net/manual/en/mysqlnd.install.php) if you plan to use MySQL
-- [libcurl](http://php.net/manual/en/curl.requirements.php) if you plan to use the HTTP\CURLRequest library
-
-- first test release
+`php vendor/bin/phpunit tests\unit\PremiumCalculationTest.php --filter testPremiumCalculationWithPrimaryRackRateAndAdditionalRackRate`
diff --git a/app/Config/Filters.php b/app/Config/Filters.php
index 40324597..0855ec3e 100644
--- a/app/Config/Filters.php
+++ b/app/Config/Filters.php
@@ -11,6 +11,7 @@ use CodeIgniter\Filters\SecureHeaders;
use App\Filters\AuthMVC;
use App\Filters\HttpRequestLog;
+use App\Filters\CloseDbConnection;
use App\Filters\AuthJWT;
@@ -32,7 +33,8 @@ class Filters extends BaseConfig
'secureheaders' => SecureHeaders::class,
'authMVC' => AuthMVC::class,
'HttpRequestLog' => HttpRequestLog::class,
- 'authJWT' => AuthJWT::class
+ 'authJWT' => AuthJWT::class,
+ 'CloseDbConnection' => CloseDbConnection::class
];
/**
@@ -49,8 +51,7 @@ class Filters extends BaseConfig
// 'invalidchars',
],
'after' => [
- // 'HttpRequestLog',
- //'authMVC',
+ 'CloseDbConnection'
// 'secureheaders',
],
];
diff --git a/app/Config/Routes.php b/app/Config/Routes.php
index 4f395843..7917751a 100644
--- a/app/Config/Routes.php
+++ b/app/Config/Routes.php
@@ -19,15 +19,10 @@ $routes->get('/logout', 'LoginController::logout');
$routes->get('/oauth2callback', 'LoginController::receiveGoogleOAuthResponse');
$routes->get('/auth/google', 'LoginController::initiateGoogleOAuth');
$routes->get('/update-emp-policy-status', 'ClientController::updateEmpAndPolicyStatus');
-$routes->get('download-e-card/(:segment)', 'EmployeeController::generateIDCardForEmployee/$1');
+$routes->get('download-e-card/(:any)', 'EmployeeController::generateIDCardForEmployee/$1');
$routes->get('download-kyc-docs/(:segment)', 'ClientController::downloadKYCDocument/$1');
-$routes->get('get-notification', 'DashboardController::getDashboardNotifications');
-$routes->get('acknowledge-notification/(:segment)', 'DashboardController::acknowledgeMessage/$1');
-
-
-
$routes->group("/user", ["filter" => "authMVC"], function ($routes) {
$routes->post("create", "UserController::create");
$routes->get("create", "UserController::create");
@@ -41,6 +36,9 @@ $routes->group("/user", ["filter" => "authMVC"], function ($routes) {
$routes->group("/dashboard", ["filter" => "authMVC"], function ($routes) {
$routes->get("view", "DashboardController::dashboard");
+ $routes->get('get-notification', 'DashboardController::getDashboardNotifications');
+ $routes->get('acknowledge-notification/(:segment)', 'DashboardController::acknowledgeMessage/$1');
+ $routes->get('get-pending-action', 'PendingActionsController::getPendingActions');
});
@@ -233,6 +231,9 @@ $routes->group("/util", ["filter" => "authMVC"], function ($routes) {
$routes->get("preview-card/(:any)", "EmployeeController::previewTemplate/$1");
$routes->get("export-import-error-list/(:any)", "EmployeeController::errorListExportImport/$1");
$routes->get("has_policy_config_completed/(:any)", "EmployeeController::hasPolicyConfigCompleted/$1");
+ $routes->get("get-client-branch/(:any)", "ClientController::getClientBranch/$1");
+ $routes->get("get-client-details/(:any)", "ClientController::getClientAllDetailsByUsingClientID/$1");
+ $routes->get("delete-additional-rack-rate/(:any)", "ClientController::deleteAdditionalRackRate/$1");
});
$routes->cli('cli/processjob', 'JobWorker::processJob');
@@ -240,6 +241,7 @@ $routes->cli('cli/processjobs', 'JobWorker::processJobs');
$routes->get("processjob", "JobWorker::processJob");
+
//Employee login api's
$routes->post("/employeeRest/verifyEmployeeNumber", "RestAuthenticationController::verifyEmployeeWithMobileNumber");
$routes->post("/employeeRest/getVerifiedUserData", "RestAuthenticationController::getVerifiedUserData");
@@ -255,12 +257,6 @@ $routes->group("/api", ["filter" => "authJWT"], function ($routes) {
-$routes->get("/getEmployeeProfile", "EmployeeRestController::getEmployeeProfile/$1");
-$routes->post("/editEmployeeProfile", "EmployeeRestController::editEmployeeProfile");
-$routes->post("/calculatePremium", "EmployeeRestController::calculatePremium");
-
-
-
$routes->group("employeeRest", ["filter" => "authJWT"], function ($routes) {
@@ -290,11 +286,14 @@ $routes->group("employeeRest", ["filter" => "authJWT"], function ($routes) {
$routes->get("getEmployeeOldPolicy", "EmployeeRestController::getEmployeeOldPolicy");
$routes->get("getEmployeeActiveOrInactivePolicy", "EmployeeRestController::getEmployeeActiveOrInactivePolicy");
+ $routes->get("getFEContent", "EmployeeRestController::getFEContent");
+ $routes->get("getAdvertisementImage", "EmployeeRestController::getAdvertisementImage");
});
$routes->post("sendEmail", "EmployeeRestController::send_email");
+
diff --git a/app/Config/Session.php b/app/Config/Session.php
index 591aefdc..e077df64 100644
--- a/app/Config/Session.php
+++ b/app/Config/Session.php
@@ -40,8 +40,7 @@ class Session extends BaseConfig
* The number of SECONDS you want the session to last.
* Setting to 0 (zero) means expire when the browser is closed.
*/
- // public int $expiration = 7200;
- public int $expiration = 86400; //24 Hours
+ public int $expiration = 7200;
/**
* --------------------------------------------------------------------------
diff --git a/app/Controllers/ClientController.php b/app/Controllers/ClientController.php
index 54f6a1f1..52b3dbca 100644
--- a/app/Controllers/ClientController.php
+++ b/app/Controllers/ClientController.php
@@ -98,12 +98,13 @@ class ClientController extends AdminController
public function index()
{
-
$this->myLogger->logme('error','Client list function called');
$headerData['page_name'] = 'Client List';
$data['clientList'] = $this->clientModel->getCreatedByUserName();
$data['client_rm'] = $this->clientRMModel->getAllClientRM();
+ // dd($data);
+
echo view('layout/header', $headerData);
echo view('client_list', $data);
echo view('layout/footer');
@@ -168,8 +169,9 @@ class ClientController extends AdminController
// echo "
";
// print_r($data); die;
- $data['placeHolders'] = ['member_name','nhance_logo','tpa_id','ecard_download_link', 'client_logo', 'policy_no', 'member_summary', 'app_link', 'client_name'];
+ $data['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($data['placeHolders']);
echo view('layout/header', $headerData);
echo view('client_onboarding', $data);
@@ -282,7 +284,7 @@ class ClientController extends AdminController
$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', 'client_name'];
+ $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'];
echo view('layout/header', $headerData);
@@ -584,6 +586,19 @@ class ClientController extends AdminController
$this->myLogger->logme('error','Client policy CREATE function called');
+ $policy_type_id = $this->request->getPost('policy_type_id');
+ $client_branch_id = $this->request->getPost('client_branch_id');
+
+ $policyCount = $this->clientPolicyModel
+ ->where('policy_type_id', $policy_type_id)
+ ->where('client_branch_id', $client_branch_id)
+ ->countAllResults();
+
+ if($policyCount > 0 ){
+ $clientPoliceData = $this->clientPolicyModel->getClientPolicyByClientId($this->request->getPost('client_id'));
+ return $this->respond(['status' => 'policy_exist','code' => 200,'data' => $clientPoliceData, 'method' => 'CERATE'], 200);
+ }
+
$insurerValue = (string) $this->request->getPost('insurer');
list($insurerBranchId, $insurerId) = explode('-', $insurerValue);
$client_id = $this->request->getPost('client_id');
@@ -623,6 +638,7 @@ class ClientController extends AdminController
$data['base_policy'] = $this->request->getPost('base_policy');
$data['policy_status'] = 1;
$data['inception_type'] = $this->request->getPost('inception_type') ? 2 : 1;
+ $data['client_branch_id'] = $this->request->getPost('client_branch_id');
@@ -717,6 +733,8 @@ class ClientController extends AdminController
$data['base_policy'] = $this->request->getPost('base_policy');
$data['policy_status'] = 1;
$data['inception_type'] = $this->request->getPost('inception_type') ? 2 : 1;
+ $data['client_branch_id'] = $this->request->getPost('client_branch_id');
+
$policy_terms = $this->clientPolicyModel->where('id', $this->request->getPost('base_policy'))->first();
@@ -766,22 +784,43 @@ class ClientController extends AdminController
public function createClientPolicyPremium()
{
+
+ // echo json_encode(['key' => $this->request->getPost()]); die;
+
try {
$policy_type = $this->request->getPost('policy_type');
$client_id = $this->request->getPost('client_id');
$client_policy_id = $this->request->getPost('client_policy_id');
- // $premium_type = $this->request->getPost('premium_type');
+ $premium_type = $this->request->getPost('premium_type');
if (!empty($client_id) && $client_id != null) {
$client_policy_data = $this->clientPolicyModel->where('id', $client_policy_id)->first();
$client_id = $client_policy_data['client_id'];
}
$policy_grid_id = $this->request->getPost('policy_grid_id');
+ $rack_rate_type = $this->request->getPost('rack_rate_type');
- if($policy_grid_id == 10 || $policy_grid_id == 11){
- $premium_type = 1;
- }else{
- $premium_type = 2;
- }
+ $self = $this->request->getPost('self') ? 1 : 0;
+ $spouse = $this->request->getPost('spouse')? 1 : 0;
+ $childrens = $this->request->getPost('childrens')? 1 : 0;
+ $parents = $this->request->getPost('parents')? 1 : 0;
+ $parents_in_law = $this->request->getPost('parents-in-law')? 1 : 0;
+ $either_parents_pil = $this->request->getPost('either-parents-pil')? 1 : 0;
+
+ $relation_data['self'] = $self;
+ $relation_data['spouse'] = $spouse;
+ $relation_data['childrens'] = $childrens;
+ $relation_data['parents'] = $parents;
+ $relation_data['parents-in-law'] = $parents_in_law;
+ $relation_data['either-parents-pil'] = $either_parents_pil;
+
+
+ $jsonDataForRelation = json_encode($relation_data);
+
+ // if($policy_grid_id == 10 || $policy_grid_id == 11){
+ // $premium_type = 1;
+ // }else{
+ // $premium_type = 2;
+ // }
$si_or_bp = $this->request->getPost('si_or_bp');
$basic_multiplier = str_replace(',', '', $this->request->getPost('basic_multiplier'));
@@ -794,6 +833,11 @@ class ClientController extends AdminController
$data['client_policy_id'] = $client_policy_id;
$data['policy_grid_id'] = $policy_grid_id;
$data['premium_type'] = $premium_type;
+ $data['rack_rate_type'] = $rack_rate_type;
+
+ if($rack_rate_type == 1){
+ $data['additional_relationship'] = $jsonDataForRelation;
+ }
$premium = [];
@@ -801,7 +845,7 @@ class ClientController extends AdminController
if ($policy_grid_id == '1' || $policy_grid_id == '2') {
$this->policyPremium1Model->where('client_id', $client_id)->where('client_policy_id', $client_policy_id)->set('is_active', 0)->update();
} else {
- $this->policyPremium2Model->where('client_id', $client_id)->where('client_policy_id', $client_policy_id)->set('is_active', 0)->update();
+ $this->policyPremium2Model->where('client_id', $client_id)->where('client_policy_id', $client_policy_id)->where('rack_rate_type', $rack_rate_type)->set('is_active', 0)->update();
}
@@ -908,6 +952,9 @@ class ClientController extends AdminController
$premium = $this->request->getPost('6_premium[]');
+
+ print_r($premium);
+
$sum_insure = $this->request->getPost('6_si');
$age_from = $this->request->getPost('6_age_from[]');
$age_to = $this->request->getPost('6_age_to[]');
@@ -1118,19 +1165,25 @@ class ClientController extends AdminController
$self = $policy_terms_data->family_floaters;
}
- $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", $record['client_id'])
- ->where("employees.emp_status", 'active')
+ // $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", $record['client_id'])
+ // ->where("employees.emp_status", 'active')
+ // ->where("ep.status", 'active')
+ // ->where("employees.is_active", 1)
+ // ->where("ep.is_active", 1)
+ // ->countAllResults();
+
+
+ $emp_count = $this->employeePolicyModel
+ ->join('client_policy cp', "cp.id = employee_polices.client_policy_id")
+ ->where("employee_polices.client_policy_id", $client_policy_id)
+ ->where("employee_polices.status", 'active')
+ ->where("employee_polices.is_active", 1)
->countAllResults();
-
- $data = $this->employeePolicyModel->select('employee_polices.id')
- ->where('employee_polices.is_active', 1)
- ->where('employee_polices.client_policy_id', $client_policy_id)
- ->findAll();
-
- $emp_count = count($data);
+ // $emp_count = count($data);
// if($emp_count == 0){
// $emp_count = true;
@@ -1164,6 +1217,11 @@ class ClientController extends AdminController
$premiumData = "";
}
+
+
+
+
+
// echo '';
// print_r($premiumData); die;
@@ -1176,24 +1234,25 @@ class ClientController extends AdminController
if ($search_term === 'GMC') {
- $resultss = [];
+ // $resultss = [];
+ $resultss = $results;
- try {
- foreach ($results as $index => $record) {
- // if ($self->self == 1 && $self->spouse == 0 && $self->childrens == 0 && $self->parents == 0 && $self->{'parents-in-law'} == 0 && $self->{'either-parents-pil'} == 0 && $family_floater == 0) {
- if ($family_floater == 1) {
- if ($index == '7' || $index == '8' || $index == '9' || $index == '10') {
- $resultss[$index] = $record;
- }
- } else {
- if ($index == '0' || $index == '1' || $index == '2' || $index == '3' || $index == '4' || $index == '5' || $index == '6') {
- $resultss[$index] = $record;
- }
- }
- }
- } catch (\Exception $e) {
- $resultss = $results; // Reset $resultss to an empty array if an exception occurs
- }
+ // try {
+ // foreach ($results as $index => $record) {
+ // // if ($self->self == 1 && $self->spouse == 0 && $self->childrens == 0 && $self->parents == 0 && $self->{'parents-in-law'} == 0 && $self->{'either-parents-pil'} == 0 && $family_floater == 0) {
+ // if ($family_floater == 1) {
+ // if ($index == '7' || $index == '8' || $index == '9' || $index == '10') {
+ // $resultss[$index] = $record;
+ // }
+ // } else {
+ // if ($index == '0' || $index == '1' || $index == '2' || $index == '3' || $index == '4' || $index == '5' || $index == '6') {
+ // $resultss[$index] = $record;
+ // }
+ // }
+ // }
+ // } catch (\Exception $e) {
+ // $resultss = $results; // Reset $resultss to an empty array if an exception occurs
+ // }
@@ -1219,19 +1278,28 @@ class ClientController extends AdminController
$premiumDataa = $premiumData;
}
- // print_r($premiumData);die;
+ // $premium1 = [];
+ // $premium2 = [];
- // print_r($data[0]->policy_type); die;
- // echo "hello";
- // return json_encode($premiumData);
+ // foreach ($premiumDataa as $key => $item) {
+ // if ($item['rack_rate_type'] == 0) {
+ // $premium1[] = $item;
+ // } elseif ($item['rack_rate_type'] == 1) {
+ // $premium2[] = $item;
+ // }
+ // }
+
+ // print_r($premium1);
+ // print_r($premium2); die;
+
+ return $this->respond(['status' => true, 'code' => 200, 'data' => $resultss, 'premiumData' => json_encode($premiumDataa), 'count' => $emp_count, 'policy_name' => $policy_name, 'family_floater' => $family_floater, 'self' => $self, 'client_policy_id' => $client_policy_id], 200);
- return $this->respond(['status' => true, 'code' => 200, 'data' => $resultss, 'premiumData' => json_encode($premiumDataa), 'count' => $emp_count, 'policy_name' => $policy_name, 'family_floater' => $family_floater, 'self' => $self], 200);
} else if ($search_term === 'GPA') {
- return $this->respond(['status' => true, 'code' => 200, 'data' => $results, 'premiumData' => json_encode($premiumData), 'count' => $emp_count, 'policy_name' => $policy_name, 'family_floater' => $family_floater, 'self' => $self], 200);
+ return $this->respond(['status' => true, 'code' => 200, 'data' => $results, 'premiumData' => json_encode($premiumData), 'count' => $emp_count, 'policy_name' => $policy_name, 'family_floater' => $family_floater, 'self' => $self, 'client_policy_id' => $client_policy_id], 200);
} else {
- return $this->respond(['status' => false, 'code' => 200, 'data' => $results, 'premiumData' => json_encode($premiumData), 'count' => $emp_count, 'policy_name' => $policy_name, 'family_floater' => $family_floater, 'self' => $self], 200);
+ return $this->respond(['status' => false, 'code' => 200, 'data' => $results, 'premiumData' => json_encode($premiumData), 'count' => $emp_count, 'policy_name' => $policy_name, 'family_floater' => $family_floater, 'self' => $self, 'client_policy_id' => $client_policy_id], 200);
}
}
@@ -1703,4 +1771,354 @@ class ClientController extends AdminController
return "File not found.";
}
}
+
+
+ public function getClientBranch($client_id){
+
+ $branchs = $this->clientBranchModel
+ ->select('*')
+ ->where('client_id',$client_id)
+ ->findAll();
+
+ return $this->respond(['status' => true,'code' => 200, 'data' => $branchs], 200);
+
+
+ }
+
+ public function getClientAllDetailsByUsingClientID($client_id)
+ {
+
+ $db = \Config\Database::connect();
+
+ $builder = $db->table('clients');
+ $builder->select('
+ policies.name as policy_name,
+ policy_type.policy_type,
+ insurers.name as insurer_name,
+ insurers.short_name as insurer_short_name,
+ tpa.name as tpa_name,
+ tpa.short_name as tpa_short_name,
+ client_policy.policy_terms,
+
+ DATE_FORMAT(client_policy.policy_start_date, "%d-%b-%Y") as policy_start_date,
+ DATE_FORMAT(client_policy.policy_end_date, "%d-%b-%Y") as policy_end_date,
+
+ CASE
+ WHEN client_policy.base_policy IS NULL THEN "Not Appear"
+ WHEN client_policy.base_policy = 0 THEN "Not Appear"
+ ELSE (SELECT policies.name
+ FROM client_policy AS base_client_policy
+ JOIN policies ON policies.id = base_client_policy.policy_id
+ WHERE base_client_policy.id = client_policy.base_policy)
+ END as base_policy_name,
+
+ CASE
+ WHEN client_policy.is_addon = 1 THEN "Base Policy"
+ WHEN client_policy.is_addon = 2 THEN "SI Topup"
+ WHEN client_policy.is_addon = 3 THEN "Dependent Addon"
+ ELSE "n/a"
+ END as is_addon,
+
+ CASE
+ WHEN client_policy.policy_status = 1 THEN "Active"
+ WHEN client_policy.policy_status = 0 THEN "Expired"
+ ELSE "n/a"
+ END as policy_status,
+
+ CASE
+ WHEN client_policy.inception_type = 1 THEN "File Upload"
+ WHEN client_policy.inception_type = 2 THEN "Enrollment"
+ ELSE "n/a"
+ END as inception_type,
+
+ CASE
+ WHEN client_policy.open_for_enrollment = 1 THEN "Open"
+ WHEN client_policy.open_for_enrollment = 0 THEN "Closed"
+ ELSE "n/a"
+ END as open_for_enrollment,
+ client_branch.branch_name
+
+ ', false);
+ $builder->join('client_policy', 'client_policy.client_id = clients.id');
+ $builder->join('client_branch', 'client_policy.client_branch_id = client_branch.id');
+ $builder->join('policies', 'policies.id = client_policy.policy_id');
+ $builder->join('policy_type', 'policy_type.id = policies.policy_type_id');
+ $builder->join('insurers', 'insurers.id = client_policy.insurer_id');
+ $builder->join('tpa', 'tpa.id = client_policy.tpa_id');
+ $builder->where('clients.is_active', 1);
+ $builder->where('client_policy.is_active', 1);
+ $builder->where('policies.is_active', 1);
+ $builder->where('policy_type.is_active', 1);
+ $builder->where('client_policy.policy_status', 1);
+ $builder->where('clients.id', $client_id);
+
+ $query = $builder->get();
+ $client_policy = $query->getResultArray();
+
+ $gmc_keys = [
+ "sum_insured" => "Sum Insured",
+ "family_floater" => "Family Floater",
+ "family_floaters" => "Family Floaters",
+ "member_count" => "Elders Count:",
+ "other_member_min_age" => "Min Age:",
+ "other_member_max_age" => "Min Age:",
+ "waiverofpreexistingdiseases" => "Waiver of Pre-existing Diseases",
+ "9monthwaitingperiodwaived" => "9-month waiting Period –waived",
+ "coverfromthedateofjoining" => "Cover from the date of Joining",
+ "waiverof1,2,3&4thyearexclusions" => "Waiver of 1, 2, 3 & 4th year Exclusions",
+ "waiverof30dayswaitingperiod" => "Waiver of 30 days waiting period",
+ "prehospitalizationcover" => "Pre Hospitalization Cover",
+ "congenitaldiseasesinternal" => "Congenital Diseases - Internal",
+ "copayzonewisecopay" => "Co-Pay/Zone wise Co Pay",
+ "bioabsorbablestenttoriclensmultifocallens" => "Bio absorbable stent / Toric lens/ Multi Focal lens",
+ "roomrentlimit" => "Room Rent Limit",
+ "proportionatedeductionclause" => "Proportionate Deduction Clause",
+ "nursingallowance" => "Nursing Allowance",
+ "ailmentcapping" => "Ailment capping",
+ "ambulancecharges" => "Ambulance Charges",
+ "airambulance" => "Air Ambulance",
+ "familytransportationbenefit" => "Family Transportation Benefit",
+ "reasonableandcustomarycharges" => "Reasonable and Customary Charges",
+ "daycaretreatment" => "Day Care Treatment",
+ "ayudhtreatmentcover" => "AYUSH treatment cover",
+ "armdcovered" => "ARMD Covered",
+ "suminsuredenhancement" => "Sum Insured enhancement",
+ "automaticsuminsuredreinstatement" => "Automatic Sum Insured reinstatement",
+ "additionalsicknessbenefit" => "Additional Sickness Benefit",
+ "lasiksurgery" => "Lasik Surgery",
+ "midterminclusion" => "Mid Term inclusion",
+ "capd" => "CAPD",
+ "organdonorexpenses" => "Organ donor expenses",
+ "moderntreatmentsasperirdai" => "Modern treatments as per IRDAI",
+ "Wellness" => "Wellness",
+ "days_of_discharge" => "Claim Intimation Clause",
+ "days_from_dod" => "Claim Submission",
+ "cataract" => "Cataract"
+ ];
+
+ $gpa_keys = [
+ "sumInsured2" => "Sum Insured",
+ "totalSumInsured" => "Total Sum Assured",
+ "self" => "Self",
+ "self_min_age" => "Min Age",
+ "self_max_age" => "Max Age",
+ "accidentalDeathBenefit" => "Accidental Death Benefit",
+ "permanentTotalDisablement" => "Permanent Total Disablement",
+ "permanentPartialDisablement" => "Permanent Partial Disablement",
+ "temporaryTotalDisablementBenefit" => "Temporary Total Disablement benefit",
+ "accidentalHospitalizationExpenses" => "Accidental Hospitalization Expenses",
+ "childrenEducationWelfareFund" => "Children Education Welfare Fund",
+ "compassionateVisitExpenses" => "Compassionate Visit Expenses",
+ "compassionateVisitExpensesData" => "Compassionate Visit Expenses Data",
+ "brokenBoneExpenses" => "Broken Bone Expenses",
+ "brokenBoneExpensesData" => "Broken Bone Expenses Data",
+ "ambulanceCharges" => "Ambulance charges",
+ "ambulanceChargesData" => "Ambulance charges Data",
+ "burnExpenses" => "Burn Expenses",
+ "burnExpensesData" => "Burn Expenses Data",
+ "carriageOfDeadBody" => "Carriage of Dead Body",
+ "carriageOfDeadBodyData" => "Carriage of Dead Body Data",
+ "animalSnakeInsectBite" => "Animal/Snake/Insect bite",
+ "terrorism" => "Terrorism",
+ "worldwideCover" => "Worldwide Cover"
+ ];
+
+
+
+
+ foreach ($client_policy as $key => $value) {
+
+ $policy_terms = json_decode($value['policy_terms'], true);
+
+ $mapping = $gmc_keys;
+ if ($value['policy_type'] == 'GPA') {
+ $mapping = $gpa_keys;
+ }
+
+ $client_policy[$key]['policy_terms'] = $this->transformArray($policy_terms, $mapping);
+ }
+
+
+
+
+ $data['client_policy'] = $client_policy;
+
+
+
+
+ $data['client_branch'] = $this->clientModel
+
+ ->select('
+
+ client_branch.branch_name,
+ client_branch.branch_code,
+ client_branch.city,
+ level_contacts.name as hr_name,
+ level_contacts.designation,
+ level_contacts.mobile,
+ level_contacts.email
+ ')
+ ->join('client_branch', 'client_branch.client_id = clients.id')
+ ->join('level_contacts', 'level_contacts.ref_id = client_branch.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('clients.id', $client_id)
+ ->get()->getResultArray();
+
+
+ $data['client'] = $this->clientModel
+ ->select('clients.*, states.state as state')
+ ->join('states', 'states.id = clients.state')
+ ->where('clients.id', $client_id)->first();
+
+
+ $client_rm = $this->clientRMModel
+ ->select('client_rm.*, user_profiles.first_name as user_name')
+ ->join('user_profiles', 'user_profiles.id = client_rm.user_id')
+ ->where('client_id', $client_id)->get()->getResultArray();
+
+
+ $account_managers = [];
+ $managers = [];
+ $heads = [];
+
+ foreach ($client_rm as $key => $value) {
+ if ($value['level'] == 3) {
+ $account_managers[] = $value['user_name'];
+ } elseif ($value['level'] == 2) {
+ $managers[] = $value['user_name'];
+ } elseif ($value['level'] == 1) {
+ $heads[] = $value['user_name'];
+ }
+ }
+
+ $data['account_managers'] = $account_managers;
+ $data['managers'] = $managers;
+ $data['heads'] = $heads;
+
+ // dd($data);
+ //$this->loadLayout('client_info', $data);
+
+
+ $html = view('client_info', $data);
+ return $this->respond(['status' => true,'code' => 200, 'data' => $html], 200);
+
+ }
+
+
+
+ public function transformArray($data, $mapping)
+ {
+
+ // dd($data);
+ $transformedData = [];
+
+ if (!is_array($data)) {
+ return json_encode($transformedData, JSON_PRETTY_PRINT);
+ }
+
+ foreach ($data as $key => $value) {
+ if ($key == 'family_floaters') {
+ $transformedData[$key] = $this->transformFamilyFloaters($value, $data);
+ } 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];
+ }
+ } else if ($key == 'gpa_special_condition_label') {
+
+ foreach ($value as $key => $value) {
+ $transformedData[$value] = $data['gpa_special_condition_input'][$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 {
+ $transformedData[$key] = $value;
+ }
+ }
+
+ return json_encode($transformedData, JSON_PRETTY_PRINT);
+ }
+
+
+ public function transformFamilyFloaters($familyFloaters, $json)
+ {
+ $result = [];
+
+ $min = $json['age_ratio']['self'];
+ $max = $json['age_ratio']['self'];
+
+ $spouse_min = $json['age_ratio']['spouse'];
+ $spouse_max = $json['age_ratio']['spouse'];
+
+ $child_min = $json['age_ratio']['child'];
+ $child_max = $json['age_ratio']['child'];
+
+ $elders_min = $json['age_ratio']['elders'];
+ $elders_max = $json['age_ratio']['elders'];
+
+ foreach ($familyFloaters as $key => $value) {
+ if ($value !== 0) {
+ switch ($key) {
+ case 'self':
+ $result[] = "Self (Min: {$min['min']}, Max: {$max['max']})";
+ break;
+ case 'spouse':
+ $result[] = "Spouse (Min: {$spouse_min['min']}, Max: {$spouse_max['max']})";
+ break;
+ case 'childrens':
+ $result[] = "Children(s) - $value (Min: {$child_min['min']}, Max: {$child_max['max']})";
+ break;
+ case 'parents':
+ $result[] = "Parent(s) - $value (Min: {$elders_min['min']}, Max: {$elders_max['max']})";
+ break;
+ case 'parents-in-law':
+ $result[] = "Parents-in-Law - $value (Min: {$elders_min['min']}, Max: {$elders_max['max']})";
+ break;
+ case 'either-parents-pil':
+ $result[] = "Either Parents Nor Parents-in-Law - $value (elders_min: {$elders_min['min']}, Max: {$elders_max['max']})";
+ break;
+ }
+ }
+ }
+
+ return implode(", ", $result);
+ }
+
+
+ public function deleteAdditionalRackRate($client_id, $client_policy_id, $rack_rate_type)
+ {
+ try {
+ $result = $this->policyPremium2Model
+ ->where('client_id', $client_id)
+ ->where('client_policy_id', $client_policy_id)
+ ->where('rack_rate_type', $rack_rate_type)
+ ->set('is_active', 0)
+ ->update();
+
+ if (!$result) {
+
+ return $this->respond(['status' => false,'code' => 200, 'message' => 'Failed to update the record.'], 200);
+ }
+ } catch (\Exception $e) {
+
+ log_message('error', $e->getMessage());
+ return $this->respond(['status' => false,'code' => 200, 'message' => 'Failed to update the record.'], 200);
+
+ }
+
+ return $this->respond(['status' => true,'code' => 200, 'message' => 'Additionaly Rack Rate Data Remove Successfully'], 200);
+ }
+
+
+
+
}
\ No newline at end of file
diff --git a/app/Controllers/DashboardController.php b/app/Controllers/DashboardController.php
index 1378abbf..8642c0a5 100644
--- a/app/Controllers/DashboardController.php
+++ b/app/Controllers/DashboardController.php
@@ -18,11 +18,14 @@ class DashboardController extends AdminController
use ResponseTrait;
protected $messageModel;
protected $userMessageModel;
+ protected $myLogger;
public function __construct()
{
+ set_session_context('Dashboard');
$this->messageModel = new MessageModel();
$this->userMessageModel = new UserMessageModel();
+ $this->myLogger = \Config\Services::mylogger();
}
public function dashboard()
@@ -34,15 +37,20 @@ class DashboardController extends AdminController
public function getDashboardNotifications()
{
- //pull notofications to dashboard especially for file upload cases
+ // Pull notifications for the dashboard, especially for file upload cases.
$userId = get_session_userid();
$roleId = 5;
$teamId = 1;
-
- $messages = $this->messageModel->getMessagesForUser($userId, $roleId, $teamId);
-
- return $this->respond($messages);
+
+ if ($userId != null && $roleId != null && $teamId != null) {
+ $messages = $this->messageModel->getMessagesForUser($userId, $roleId, $teamId);
+ return $this->respond(['status' => true, 'code' => 200, 'message' => $messages], 200);
+ } else {
+ $this->myLogger->logme('error', 'The session is not set correctly. USER_ID : {user_id}, ROLE_ID : {role_id}, TEAM_ID : {team_id}', ['user_id' => $userId, 'role_id' => $roleId, 'team_id' => $teamId]);
+ return $this->respond(['status' => false, 'code' => 404, 'message' => 'No data found'], 200);
+ }
}
+
public function acknowledgeMessage($messageId)
{
diff --git a/app/Controllers/EmpDataServiceController.php b/app/Controllers/EmpDataServiceController.php
index b0814d11..1b3fa587 100644
--- a/app/Controllers/EmpDataServiceController.php
+++ b/app/Controllers/EmpDataServiceController.php
@@ -111,7 +111,7 @@ class EmpDataServiceController extends BaseController
$batch_list_data['batch_code'] = $params['batch_code'];
$batch_list_data['emp_policy_id'] = $value['primaryKey'];
- $batch_list_data['created_by'] = get_session_userid();
+ $batch_list_data['created_by'] = $params['user_id'];
$this->batchListModel->insert($batch_list_data);
}
@@ -133,33 +133,33 @@ class EmpDataServiceController extends BaseController
public function generateExcelForAdditionandInception($export_data)
{
- $return = $this->removeOldExportInfoFromBatchFile($export_data);
-
// 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();
- $totals = 0;
- foreach ($objects as $key => $value) {
+ // Calculate the total amount from the objects
+ $totals = array_reduce($objects, function ($carry, $item) {
+ return $carry + $item->total;
+ }, 0);
- $totals += $value->total;
- }
+ $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;
}
- } else {
- // return 0;
}
+ $this->removeOldExportInfoFromBatchFile($export_data);
+
+
// Log the count of exported data
$count = count($objects);
$export_data['count'] = $count;
@@ -171,6 +171,8 @@ class EmpDataServiceController extends BaseController
// If no data is found for export, return false
if ($count == 0) {
+
+ $this->myLogger->logme('error', 'No Record found. TPA ID or UHID are Alread Updated. Correction export data count : {data}', ['data' => $count]);
return false;
}
@@ -212,30 +214,35 @@ class EmpDataServiceController extends BaseController
// If Excel generation is successful
if ($success) {
-
- // Batch files and list entry
- // $return = $this->batchFilesAndBatchListEntry($export_data, $objects);
-
$random_number_count = 4;
$export_data['batch_code'] = generate_random_string($random_number_count);
$export_data['created_by'] = get_session_userid();
-
+
$insert = $this->batchFileModel->insert($export_data);
$batch_file_batch_code = $this->batchFileModel->where('id', $insert)->first();
$batch_code = $batch_file_batch_code['batch_code'];
// $this->insertBatchList(['batch_code' => $batch_code, 'batch_list_data' => $objects ]);
- $job_details = new Jobs();
- $r = Jobs::addJob(['job_name' => 'insertBatchList','payload' => ['batch_code' => $batch_code, 'batch_list_data' => $objects ]]);
+ $job_details = new Jobs();
+ $r = Jobs::addJob(['job_name' => 'insertBatchList', 'payload' => ['batch_code' => $batch_code, 'user_id' => get_session_userid(), 'batch_list_data' => $objects]]);
// If batch operation is successful
if (true) {
+
+ // Clear the output buffer to avoid any unwanted output
+ if (ob_get_level()) {
+ ob_end_clean();
+ }
+
// Set headers for Excel file download
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
- header('Content-Disposition: attachment;filename="' . $export_data['file_name'] . '"');
- header('Cache-Control: max-age=0');
+ header('Content-Disposition: attachment; filename="' . $export_data['file_name'] . '"');
+ header('Content-Transfer-Encoding: binary');
+ header('Cache-Control: must-revalidate');
+ header('Pragma: public');
+ header('Expires: 0');
// Output file contents
rewind($tempFile);
@@ -247,7 +254,7 @@ class EmpDataServiceController extends BaseController
return true; // Excel file successfully generated and exported
} else {
-
+
return false; // Batch operation failed
}
}
@@ -266,17 +273,19 @@ class EmpDataServiceController extends BaseController
$ids[] = $obj->id;
}
- // echo '';
- // print_r($objects); die;
-
$count = count($objects);
$export_data['count'] = $count;
+ $export_data['status'] = 'success';
$this->myLogger->logme('error', 'Correction export data count : {data}', ['data' => $count]);
if ($count == 0) {
- return false;
+ $this->myLogger->logme('error', 'No Record found. Endorsement ID Alread Updated. Correction export data count : {data}', ['data' => $count]);
+ return false;
}
+ $this->removeOldExportInfoFromBatchFile($export_data);
+
+
$this->myLogger->logme('error', 'Correction export file name : {data}', ['data' => $export_data['file_name']]);
$correction_data = transform_objects_to_array_for_correction($objects);
@@ -302,7 +311,11 @@ class EmpDataServiceController extends BaseController
$value = generate_excel($headers, $correction_data, $tempFile);
if ($value) {
+
+
+
$return = $this->batchFilesAndBatchListEntry($export_data, $objects);
+
if ($return) {
foreach ($ids as $key => $id) {
@@ -312,7 +325,6 @@ class EmpDataServiceController extends BaseController
}
}
-
// Set the appropriate headers for Excel file download
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="' . $export_data['file_name'] . '"');
@@ -329,7 +341,6 @@ class EmpDataServiceController extends BaseController
return true;
} else {
-
return false;
}
}
@@ -347,6 +358,7 @@ class EmpDataServiceController extends BaseController
$ids[] = $obj->endorsement_primarykey;
$totals += $obj->total;
}
+
$rounded_totals = round($totals, 2);
// echo '';
// print_r($ids); die;
@@ -354,13 +366,17 @@ class EmpDataServiceController extends BaseController
$count = count($objects);
$export_data['count'] = $count;
$export_data['amount'] = $rounded_totals;
+ $export_data['status'] = 'success';
$this->myLogger->logme('error', 'SI_Enhancement export data count : {data}', ['data' => $count]);
if ($count == 0) {
+
+ $this->myLogger->logme('error', 'No Record found. Endorsement ID Alread Updated. SI_Enhancement export data count : {data}', ['data' => $count]);
return false;
}
+ $this->removeOldExportInfoFromBatchFile($export_data);
$this->myLogger->logme('error', 'SI_Enhancement export file name : {data}', ['data' => $export_data['file_name']]);
$si_data = transform_objects_to_array_for_si_enhancement($objects);
@@ -440,21 +456,21 @@ class EmpDataServiceController extends BaseController
$totals += $obj->total;
}
$rounded_totals = round($totals, 2);
- // echo '';
- // print_r($ids);
- // print_r($objects); die;
$count = count($objects);
$export_data['count'] = $count;
$export_data['amount'] = $rounded_totals;
-
+ $export_data['status'] = 'success';
$this->myLogger->logme('error', 'Deletion export data count : {data}', ['data' => $count]);
if ($count == 0) {
+
+ $this->myLogger->logme('error', 'No Record found. Endorsement ID Alread Updated. Deletion export data count : {data}', ['data' => $count]);
return false;
}
+ $this->removeOldExportInfoFromBatchFile($export_data);
$this->myLogger->logme('error', 'Deletion export file name : {data}', ['data' => $export_data['file_name']]);
$si_data = transform_objects_to_array_for_deletion($objects);
@@ -519,6 +535,90 @@ class EmpDataServiceController extends BaseController
+ public function generateExcelForAdditionAndDependentAddition($export_data)
+ {
+ $ids = [];
+
+ $objects = $this->employeePolicyModel->getCorrectionEmployeesDataForExportExcel($export_data);
+
+ foreach ($objects as $obj) {
+ $ids[] = $obj->id;
+ }
+
+ $count = count($objects);
+ $export_data['count'] = $count;
+ $export_data['status'] = 'success';
+ $this->myLogger->logme('error', 'Addition And Dependent Addition export data count : {data}', ['data' => $count]);
+
+ if ($count == 0) {
+ $this->myLogger->logme('error', 'No Record found. Endorsement ID Alread Updated. Correction export data count : {data}', ['data' => $count]);
+ return false;
+ }
+
+ $this->removeOldExportInfoFromBatchFile($export_data);
+
+
+ $this->myLogger->logme('error', 'Addition And Dependent Addition export file name : {data}', ['data' => $export_data['file_name']]);
+
+ $correction_data = transform_objects_to_array_for_correction($objects);
+
+ $headers = [
+ 'Emp Code',
+ 'RISK ID',
+ 'NAME OF EMP/DEP',
+ 'EMP/DEP TYPE',
+ 'RELATION',
+ 'DOB',
+ 'GENDER',
+ 'Wrong Data',
+ 'Correct Data',
+ 'Remarks',
+ 'Endorsement_Id'
+ ];
+
+ // Create a temporary file in memory
+ $tempFile = tmpfile();
+
+ // Generate Excel file with the temporary file
+ $value = generate_excel($headers, $correction_data, $tempFile);
+
+ if ($value) {
+
+
+
+ $return = $this->batchFilesAndBatchListEntry($export_data, $objects);
+
+ if ($return) {
+
+ foreach ($ids as $key => $id) {
+ $group_key = $this->empEndorsementModel->select('group_key')->where('id', $id)->first();
+ if ($group_key) {
+ $this->empEndorsementModel->where('group_key', $group_key)->set('status', 'inprogress')->update();
+ }
+ }
+
+ // Set the appropriate headers for Excel file download
+ header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
+ header('Content-Disposition: attachment;filename="' . $export_data['file_name'] . '"');
+ header('Cache-Control: max-age=0');
+
+ // Rewind the temporary file pointer
+ rewind($tempFile);
+
+ // Output the contents of the temporary file to the browser
+ fpassthru($tempFile);
+
+ // Close and remove the temporary file
+ fclose($tempFile);
+
+ return true;
+ } else {
+ return false;
+ }
+ }
+ }
+
+
/**
* The below functions are Imports data from an Excel file for :
* - Inception
@@ -539,47 +639,24 @@ class EmpDataServiceController extends BaseController
* - 0 if the provided data is incomplete or incorrect.
*/
- public function importExcelDataForInception($import_data)
- {
-
- $file = $import_data['file'];
-
- $is_moved = $file->move(WRITEPATH . 'uploads/import_excel');
- $filename = $file->getName();
- $this->myLogger->logme('error', 'Inception Import file name : {data}', ['data' => $filename]);
-
-
- $random_number_count = 4;
- $import_data['batch_code'] = generate_random_string($random_number_count);
- $import_data['created_by'] = get_session_userid();
- $import_data['status'] = 'pending';
- $import_data['file_name'] = $filename;
-
- $insert = $this->batchFileModel->insert($import_data);
-
- $file_id['file_id'] = $insert;
-
- $job_details = new Jobs();
- $r = Jobs::addJob(['job_name' => 'importInceptionFileValidation','payload' => ['file_id' => $insert]]);
-
- return 1;
- }
+ //Endorsement Inception
public function importInceptionFileValidation($params)
{
- $this->myLogger->logme('info', 'importInceptionFileValidation called');
+ $this->myLogger->logme('info', 'Inception File Validation -- Function called');
$file_id = $params['file_id'];
- $this->myLogger->logme('error', 'importInceptionFileValidation batch file table primary id : {data}', ['data' => $file_id]);
+ $this->myLogger->logme('error', 'Inception File Validation -- Batch File Table Primary ID : {data}', ['data' => $file_id]);
$file = $this->batchFileModel->where('id', $file_id)->first();
$client_id = $file['client_id'];
$client_policy_id = $file['client_policy_id'];
+ $client_branch_id = $file['client_branch_id'];
$batch_code = $file['batch_code'];
-
+ $user_id = $file['created_by'];
$insurer_or_tpa = $file['insurer_or_tpa'];
if ($insurer_or_tpa == 'tpa') {
@@ -592,9 +669,29 @@ class EmpDataServiceController extends BaseController
$file_name_with_path = WRITEPATH . "/uploads/import_excel/" . $file['file_name'];
$excel_data = $this->readExcelFileToArray($file_name_with_path);
+ $excel_header = $excel_data[0];
unset($excel_data[0]);
array_pop($excel_data);
+ $inceptionHeader = ['S.No', 'NAME OF EMP/DEP','EMP ID','EMP/DEP TYPE','RELATION','DOB','GENDER','PRE EXISTING AILMENTS','BASIC COVER SI','DATE OF COVERAGE','AGE','RELATIONSHIP','REMARKS','POLICY END DATE','NO OF DAYS','TPA ID','UHID','PREMIUM','PR0 RATA PREMIUM','GST','TOTAL'];
+
+ foreach ($inceptionHeader as $key => $value) {
+ if($excel_header[$key] != $value){
+ $data = [
+ 'status' => 'failed-5',
+ ];
+
+ $this->batchFileModel->where('id', $file_id)->set($data)->update();
+
+ $file_data = $this->getDataByFileId($file_id, 'failure');
+ $this->setPullNotification($file_data);
+
+ $this->myLogger->logme('error', 'Inception File Validation -- Upload the worng excel file');
+ return ['status' => 'error', 'message' => 'Upload the worng excel file'];
+ }
+ }
+
+
$emp_count = count($excel_data);
$employee_data = $this->employeePolicyModel
@@ -626,11 +723,14 @@ class EmpDataServiceController extends BaseController
->join('employees', 'employees.id = employee_polices.employee_id')
->where('employee_polices.client_policy_id', $client_policy_id)
->where('employees.client_id', $client_id)
+ ->where('employees.client_branch_id', $client_branch_id)
->where("employee_polices.{$id} IS NULL OR employee_polices.{$id} = ''")
+ ->where('employee_polices.is_active', 1)
+ ->where('employee_polices.status', 'active')
+ ->where('employees.is_active', 1)
+ ->where('employees.emp_status', 'active')
->findAll();
- // echo '';
- // print_r($employee_data); die;
if ($employee_data == null || empty($employee_data)) {
@@ -642,12 +742,12 @@ class EmpDataServiceController extends BaseController
];
$this->batchFileModel->where('id', $file_id)->set($data)->update();
- $this->myLogger->logme('error', 'importInceptionFileValidation TPAID already updated');
+ $this->myLogger->logme('error', 'Inception File Validation -- TPAID already updated');
$file_data = $this->getDataByFileId($file_id, 'failure');
$this->setPullNotification($file_data);
- return 'The list of employees provided has already been updated with the TPA ID, or this is not the correct file';
+ return ['status' => 'error', 'message' => 'The list of employees provided has already been updated with the TPA ID, or this is not the correct file'];
} else if ($insurer_or_tpa == 'insurer') {
@@ -656,23 +756,23 @@ class EmpDataServiceController extends BaseController
];
$this->batchFileModel->where('id', $file_id)->set($data)->update();
- $this->myLogger->logme('error', 'importInceptionFileValidation UHID already updated');
+ $this->myLogger->logme('error', 'Inception File Validation -- UHID already updated');
$file_data = $this->getDataByFileId($file_id, 'failure');
$this->setPullNotification($file_data);
- return 'The list of employees provided has already been updated with the UHID, or this is not the correct file';
+ return ['status' => 'error', 'message' =>'The list of employees provided has already been updated with the UHID, or this is not the correct file'];
}
- $this->myLogger->logme('error', 'importInceptionFileValidation UHID or TPAID already updated or the uploadedfile is not correct');
+ $this->myLogger->logme('error', 'Inception File Validation -- UHID or TPAID already updated or the uploadedfile is not correct');
}
$excel_data_count = count($excel_data);
$emp_data_count = count($employee_data);
- $this->myLogger->logme('error', 'importInceptionFileValidation excel file count : {data}', ['data' => $excel_data_count]);
- $this->myLogger->logme('error', 'importInceptionFileValidation database count : {data}', ['data' => $emp_data_count]);
+ $this->myLogger->logme('error', 'Inception File Validation -- Excel File count : {data}', ['data' => $excel_data_count]);
+ $this->myLogger->logme('error', 'Inception File Validation -- Database count : {data}', ['data' => $emp_data_count]);
// dd($excel_data_count, $emp_data_count);
@@ -683,7 +783,7 @@ class EmpDataServiceController extends BaseController
$status = 'in-progress-partially';
$partially_updated_data = 'Expected : ' . $emp_data_count . ', ' . 'Updated : ' . $excel_data_count . ', ' . 'difference : ' . $difference;
- $this->myLogger->logme('error', 'importInceptionFileValidation excel file count partially : {data}', ['data' => $partially_updated_data]);
+ $this->myLogger->logme('error', 'Inception File Validation -- excel file count partially : {data}', ['data' => $partially_updated_data]);
}
@@ -695,12 +795,12 @@ class EmpDataServiceController extends BaseController
];
$this->batchFileModel->where('id', $file_id)->set($data)->update();
- $this->myLogger->logme('error', 'importInceptionFileValidation excel file count ( {excel} ) exceeds db count ( {db} )', ['db' => $emp_data_count, 'excel' => $excel_data_count]);
+ $this->myLogger->logme('error', 'Inception File Validation -- Excel File Count ( {excel} ) exceeds db count ( {db} )', ['db' => $emp_data_count, 'excel' => $excel_data_count]);
$file_data = $this->getDataByFileId($file_id, 'failure');
$this->setPullNotification($file_data);
- return 'The Excel record count exceeds the DB record count. excel file count : ' . $excel_data_count . 'db count : ' . $emp_data_count;
+ return ['status' => 'error', 'message' =>'The Excel record count exceeds the DB record count. excel file count : ' . $excel_data_count . 'db count : ' . $emp_data_count];
}
@@ -872,15 +972,11 @@ class EmpDataServiceController extends BaseController
$error_count = count($errors);
$json_errors = json_encode($errors);
- // echo $json_errors; die;
-
$missing_id_count = count($missing_id);
$json_missing_id = json_encode($missing_id);
// dd($error_count, $missing_id_count, $json_errors, $json_missing_id);
- // dd($batch_list_id);
-
if ($missing_id_count > 0) {
$data = [
@@ -895,14 +991,14 @@ class EmpDataServiceController extends BaseController
$file_data = $this->getDataByFileId($file_id, 'failure');
$this->setPullNotification($file_data);
- return 'The TPA ID column is either partially or entirely empty.';
+ return ['status' => 'error', 'message' =>'The TPA ID column is either partially or entirely empty.'];
} else if ($insurer_or_tpa == 'insurer') {
$file_data = $this->getDataByFileId($file_id, 'failure');
$this->setPullNotification($file_data);
- return 'The UHID column is either partially or entirely empty.';
+ return ['status' => 'error', 'message' =>'The UHID column is either partially or entirely empty.'];
}
}
@@ -914,8 +1010,11 @@ class EmpDataServiceController extends BaseController
'status' => 'failed',
];
+ $file_data = $this->getDataByFileId($file_id, 'failure');
+ $this->setPullNotification($file_data);
+
$this->batchFileModel->where('id', $file_id)->set($data)->update();
- return 0;
+ return ['status' => 'error', 'message' => 'Inception File Validation Failed Excel and Database Data are Mismatching'];
} else {
@@ -933,6 +1032,7 @@ class EmpDataServiceController extends BaseController
$data = [
'emp_policy_id' => $value,
'batch_code' => $batch_code,
+ 'created_by' => $user_id
];
$insert = $this->batchListModel->insert($data);
@@ -944,9 +1044,10 @@ class EmpDataServiceController extends BaseController
$job_details = new Jobs();
$r = Jobs::addJob(['job_name' => 'importInceptionUpdateTPAandUHID','payload' => ['file_id' => $file_id]]);
-
// $this->importInceptionUpdateTPAandUHID(['file_id' => $file_id]);
+ return ['status' => 'error', 'message' => 'Inception File Validation Successfully Completed'];
+
}
}
@@ -955,38 +1056,49 @@ class EmpDataServiceController extends BaseController
public function importInceptionUpdateTPAandUHID($params)
{
- $this->myLogger->logme('error', 'importInceptionUpdateTPAandUHID called');
+ $this->myLogger->logme('error', 'Inception Update TPA and UHID -- Function called');
$file_id = $params['file_id'];
$file = $this->batchFileModel->find($file_id);
if (!$file) {
+
$data = [
'status' => 'failed-4',
];
$this->batchFileModel->where('id', $file_id)->set($data)->update();
- $this->myLogger->logme('error', 'importInceptionUpdateTPAandUHID the Physical file not found - file id : {data}', ['data' => $file_id]);
+ $this->myLogger->logme('error', 'Inception Update TPA and UHID -- The Physical file not found -- File id : {data}', ['data' => $file_id]);
$file_data = $this->getDataByFileId($file_id, 'failure');
$this->setPullNotification($file_data);
- return 'importInceptionUpdateTPAandUHID the Physical file not found'; // Return error code if file not found
+ return ['status' => 'error', 'message' => 'Inception Update TPA and UHID -- The Physical file not found']; // Return error code if file not found
}
$client_id = $file['client_id'];
$client_policy_id = $file['client_policy_id'];
+ $client_branch_id = $file['client_branch_id'];
$insurer_or_tpa = $file['insurer_or_tpa'];
$status = $file['status'];
$batch_code = $file['batch_code'];
$user_id = $file['created_by'];
+
+ $get_policy_type = $this->clientPolicyModel
+ ->select('policy_type.policy_type, policies.policy_type_id as policy_type_id')
+ ->join('policies', 'policies.id = client_policy.policy_id')
+ ->join('policy_type', 'policy_type.id = policies.policy_type_id')
+ ->where('client_policy.id', $client_policy_id)
+ ->first();
+
+
$status_val = 'success';
if ($status == 'in-progress-partially') {
$status_val = 'partially success';
}
- $this->myLogger->logme('error', 'importInceptionUpdateTPAandUHID file name : {data}', ['data'=> $file['file_name']]);
+ $this->myLogger->logme('error', 'Inception Update TPA and UHID -- file name : {data}', ['data' => $file['file_name']]);
$file_name_with_path = WRITEPATH . "/uploads/import_excel/" . $file['file_name'];
@@ -995,27 +1107,31 @@ class EmpDataServiceController extends BaseController
array_pop($excel_data); // Remove footer row
$totals = 0;
- $empty_emp_tpa_uh_ids = [];
+ $emp_policy_ids = [];
+ $emp_details = [];
+ $tpa_id = [];
+ $uhid = [];
+
$emp_count = count($excel_data);
$db = \Config\Database::connect();
+
foreach ($excel_data as $key => $value) {
$name = $value[1];
$emp_code = $value[2];
- $tpa_id = $value[15];
- $uhid = $value[16];
+ $tpa_id[] = $value[15];
+ $uhid[] = $value[16];
$amount = $value[20];
- $totals += $amount;
+ $totals = $totals + $amount;
-
- // Execute the query
$query = $db->table('employee_polices');
$query->select('employee_polices.id');
$query->join('employees', 'employees.id = employee_polices.employee_id');
$query->where('employee_polices.client_policy_id', $client_policy_id);
$query->where('employees.client_id', $client_id);
+ $query->where('employees.client_branch_id', $client_branch_id);
$query->where('employees.name', $name);
$query->where('employees.emp_code', $emp_code);
if ($file['insurer_or_tpa'] == 'tpa') {
@@ -1026,43 +1142,20 @@ class EmpDataServiceController extends BaseController
$query->where('(employee_polices.uhid IS NULL OR employee_polices.uhid = "")');
}
$query->where('employee_polices.is_active', 1);
+ $query->where('employee_polices.status', 'active');
+ $query->where('employees.is_active', 1);
+ $query->where('employees.emp_status', 'active');
$query->limit(1);
- // Get the result
$result = $query->get()->getRowArray();
if (isset($result['id']) && $result['id'] !== null) {
- $empty_emp_tpa_uh_ids[] = $result['id'];
+ $emp_policy_ids[] = $result['id']; //for cash deposite
+ $emp_details[] = array('id' => $result['id'], 'tpa_id' => $value[15], 'uhid' => $value[16]);
}
-
-
-
- $sql = "
- UPDATE employee_polices
- JOIN employees ON employees.id = employee_polices.employee_id
- SET tpa_id = ?
- WHERE employees.name = ?
- AND employees.emp_code = ?
- AND employee_polices.client_policy_id = ?
- AND (employee_polices.tpa_id IS NULL OR employee_polices.tpa_id = '')";
-
- $params = [$tpa_id, $name, $emp_code, $client_policy_id];
- $db->query($sql, $params);
-
-
-
- $sql = "
- UPDATE employee_polices
- JOIN employees ON employees.id = employee_polices.employee_id
- SET employee_polices.uhid = ?
- WHERE employees.name = ?
- AND employees.emp_code = ?
- AND employee_polices.client_policy_id = ?
- AND (employee_polices.uhid IS NULL OR employee_polices.uhid = '')";
-
- $params = [$uhid, $name, $emp_code, $client_policy_id];
- $db->query($sql, $params);
}
+ $return = $this->employeePolicyModel->bulkUpdate($emp_details);
+
// Update batch file status and amount
$this->batchFileModel->update($file_id, [
'count' => $emp_count,
@@ -1071,21 +1164,21 @@ class EmpDataServiceController extends BaseController
]);
- $this->myLogger->logme('error', 'importInceptionUpdateTPAandUHID employee count : {data}', ['data'=> $emp_count]);
- $this->myLogger->logme('error', 'importInceptionUpdateTPAandUHID batch file status : {data}', ['data'=> $status_val]);
- $this->myLogger->logme('error', 'importInceptionUpdateTPAandUHID total amount for cash deposite : {data}', ['data'=> $totals]);
-
+ $this->myLogger->logme('error', 'Inception Update TPA and UHID -- employee count : {data}', ['data' => $emp_count]);
+ $this->myLogger->logme('error', 'Inception Update TPA and UHID -- batch file status : {data}', ['data' => $status_val]);
+ $this->myLogger->logme('error', 'Inception Update TPA and UHID -- total amount for cash deposite : {data}', ['data' => $totals]);
if ($file['insurer_or_tpa'] == 'tpa') {
- $this->myLogger->logme('error', 'importInceptionUpdateTPAandUHID set cashDepositCalculationForInception and sendMailForDownloadingECard in JOB QUEUE');
+ $this->myLogger->logme('error', 'Inception Update TPA and UHID -- set cashDepositCalculationForInception and sendMailForDownloadingECard in JOB QUEUE');
$policy_name = $this->getPolicyNameUsingClientPolicyId($client_policy_id);
$depositeData = [
- 'employeeIds' => $empty_emp_tpa_uh_ids,
+ 'employeeIds' => $emp_policy_ids,
'client_id' => $client_id,
'client_policy_id' => $client_policy_id,
+ 'client_branch_id' => $client_branch_id,
'count' => $emp_count,
'event' => $file['event_type'],
'policy_name' => $policy_name['policy_name'],
@@ -1094,614 +1187,1958 @@ class EmpDataServiceController extends BaseController
- $job_details = new Jobs();
- $r = Jobs::addJob(['job_name' => 'cashDepositCalculationForInception','payload' => [
- 'employeeIds' => $empty_emp_tpa_uh_ids,
+ $job_details = new Jobs();
+ $r = Jobs::addJob(['job_name' => 'cashDepositCalculationForInception', 'payload' => [
+ 'employeeIds' => $emp_policy_ids,
'client_id' => $client_id,
'client_policy_id' => $client_policy_id,
+ 'client_branch_id' => $client_branch_id,
'count' => $emp_count,
'event' => $file['event_type'],
'policy_name' => $policy_name['policy_name'],
'user_id' => $user_id,
]]);
-
- $job_details = new Jobs();
- $r = Jobs::addJob(['job_name' => 'sendMailForDownloadingECard','payload' => $empty_emp_tpa_uh_ids]);
+ if ($get_policy_type['policy_type_id'] != 1) {
+
+ $job_details = new Jobs();
+ $r = Jobs::addJob(['job_name' => 'sendMailForDownloadingECard', 'payload' => $emp_policy_ids]);
+ }
// $this->cashDepositCalculationForInception($depositeData);
- // $this->sendMailForDownloadingECard($empty_emp_tpa_uh_ids);
+ // $this->sendMailForDownloadingECard($emp_policy_ids);
}
$file_data = $this->getDataByFileId($file_id, 'success');
$this->setPullNotification($file_data);
- return 'Import Inception Updated '. $status_val . '- Updated Count : ' . $emp_count;
+
+ return 'Import Inception Updated ' . $status_val . '- Updated Count : ' . $emp_count;
}
+ //Endorsement Correction
-
- public function importExcelDataForCorrection($import_data)
+ public function importCorrectionValidation($params)
{
- $client_id = $import_data['client_id'];
- $client_policy_id = $import_data['client_policy_id'];
- $file = $import_data['file'];
+ $this->myLogger->logme('error', 'Correction File Validation -- Function called');
- $data = $this->readExcelToArray($file);
- unset($data[0]);
- $count = count($data);
+ $file_id = $params['file_id'];
+ $file = $this->batchFileModel->where('id', $file_id)->first();
- $missing_id = [];
- $empty_emp_tpa_uh_ids = [];
- foreach ($data as $key => $value) {
+ $client_id = $file['client_id'];
+ $client_policy_id = $file['client_policy_id'];
+ $client_branch_id = $file['client_branch_id'];
+ $batch_code = $file['batch_code'];
+ $user_id = $file['created_by'];
- try {
-
- if ($value[10] === null) {
- $missing_id[] = $key + 1;
- }
-
- $emp_code = $value[0];
- $uhid = $value[1];
- $endorsement_id = $value[10] != null ? $value[10] : '';
-
- $db = \Config\Database::connect();
-
- // Execute the query
- $query = $db->table('emp_endorsement')
- ->select('emp_endorsement.id')
- ->join('employees', 'employees.id = emp_endorsement.pk')
- ->join('employee_polices', 'employee_polices.employee_id = employees.id')
- ->where('employee_polices.client_policy_id', $client_policy_id)
- ->where('employees.client_id', $client_id)
- ->where('employee_polices.uhid', $uhid)
- ->where('employees.emp_code', $emp_code)
- ->where('(emp_endorsement.endorsement_id IS NULL OR emp_endorsement.endorsement_id = "")')
- ->groupBy('emp_endorsement.group_key')
- ->limit(1);
-
- // Get the result
- $result = $query->get()->getRowArray();
- if (isset($result['id']) && $result['id'] !== null) {
- $empty_emp_tpa_uh_ids[] = $result['id'];
- }
- } catch (\Exception $e) {
- // Handle the exception here
- return 0;
- }
- }
-
- $missing_id_count = count($missing_id);
- $empty_id_count = count($empty_emp_tpa_uh_ids);
-
- // if($missing_id_count != $count){
-
- // return 2;
- // }
-
- if ($missing_id_count != 0) {
-
- return 2;
- }
-
- // if($empty_emp_tpa_uh_ids != $count){
-
- // return 3;
- // }
-
- if ($empty_id_count == 0) {
-
- return 3;
- }
-
- // dd($count, $missing_id, $missing_id_count, $empty_id_count, $data, $empty_emp_tpa_uh_ids);
-
-
- $is_moved = $file->move(WRITEPATH . 'uploads/import_excel');
- $filename = $file->getName();
-
- $this->myLogger->logme('error', 'Correction Import file name : {data}', ['data' => $filename]);
- $random_number_count = 4;
- $batch_code = generate_random_string($random_number_count);
- $this->myLogger->logme('error', 'Correction Import BATCH CODE : {data}', ['data' => $batch_code]);
-
-
- $import_data['batch_code'] = $batch_code;
- $import_data['created_by'] = get_session_userid();
- $import_data['file_name'] = $filename;
- $insert = $this->batchFileModel->insert($import_data);
- $batch_file_batch_code = $this->batchFileModel->where('id', $insert)->first();
-
- $batch_code_for_batch_list['batch_code'] = $batch_file_batch_code['batch_code'];
- $batch_code_for_batch_list['created_by'] = get_session_userid();
-
- $file_name_with_path = WRITEPATH . "/uploads/import_excel/" . $batch_file_batch_code['file_name'];
+ $file_name_with_path = WRITEPATH . "/uploads/import_excel/" . $file['file_name'];
if (!file_exists($file_name_with_path)) {
- return 2;
+
+ $this->myLogger->logme('error', 'Correction File Validation -- The Physical file not found');
+ $this->myLogger->logme('error', 'Correction File Validation -- File Name : {data}', ['data' => $file['file_name']]);
+ $this->myLogger->logme('error', 'Correction File Validation -- File Path : {data}', ['data' => $file_name_with_path]);
+
+ return 'The Physical file not found';
}
- $data = read_excel_file_to_array($file_name_with_path);
- unset($data[0]);
- $count = count($data);
- $this->batchFileModel->where('id', $insert)->set('count', $count)->update();
- foreach ($data as $key => $value) {
+ $excel_data = $this->readExcelFileToArray($file_name_with_path);
+ $excel_header = $excel_data[0];
+ unset($excel_data[0]);
- if (!empty($value) && isset($value[10])) {
-
- $emp_code = $value[0];
- $uhid = $value[1];
- $endorsement_id = $value[10] != null ? $value[10] : '';
-
- $val = $this->employeePolicyModel
- ->select('employees.id')
- ->join('employees', 'employees.id = employee_polices.employee_id')
- ->where('employee_polices.client_policy_id', $client_policy_id)
- ->where('employees.client_id', $client_id)
- ->where('employee_polices.uhid', $uhid)
- ->where('employees.emp_code', $emp_code)
- ->where('employees.is_active', 1)
- ->first();
-
- $batch_code_for_batch_list['emp_policy_id'] = $val['id'];
- $this->batchListModel->insert($batch_code_for_batch_list);
-
- // $this->employeePolicyModel->updateCorrectionData($emp_code, $uhid, $endorsement_id);
-
- $queryData = $this->empEndorsementModel->select('emp_endorsement.*, employees.id as emp_id')
- ->join('employees', 'employees.id = emp_endorsement.pk')
- ->join('employee_polices', 'employee_polices.employee_id = employees.id')
- ->where('employees.emp_code', $emp_code)
- ->where('employees.client_id', $client_id)
- ->where('employee_polices.client_policy_id', $client_policy_id)
- ->where('employee_polices.uhid', $uhid)
- ->get()
- ->getResultArray();
-
- // dd($queryData);
-
- foreach ($queryData as $endorsementData) {
-
- $emp_endoresment_id = $endorsementData['id'];
- $emp_id = $endorsementData['emp_id'];
- $field_name = $endorsementData['field_name'];
- $new_value = $endorsementData['new_value'];
- $endoresment_udate_data = [
- 'endorsement_id' => $endorsement_id,
- 'status' => 'complete',
- ];
- $this->empEndorsementModel->where('id', $emp_endoresment_id)->set($endoresment_udate_data)->update();
- $this->employeeModel->where('id', $emp_id)->set($field_name, $new_value)->update();
- }
-
- // $query = $this->employeePolicyModel->getLastQuery();
- // echo $query . "
";
- } else {
-
- return 0;
- }
- }
+ $headers = ['Emp Code','RISK ID','NAME OF EMP/DEP','EMP/DEP TYPE','RELATION','DOB','GENDER','Wrong Data','Correct Data','Remarks','Endorsement_Id'];
- return 1;
- }
-
-
- public function importExcelDataForSIEnhancement($import_data)
- {
-
- $client_id = $import_data['client_id'];
- $client_policy_id = $import_data['client_policy_id'];
- $file = $import_data['file'];
-
- $data = $this->readExcelToArray($file);
- unset($data[0]);
- $count = count($data);
-
-
- $missing_id = [];
- $empty_emp_tpa_uh_ids = [];
- $totals = 0;
- foreach ($data as $key => $value) {
-
- try {
- if ($value[19] === null) {
- $missing_id[] = $key + 1;
- }
-
- $totals += $value[18];
-
- $emp_name = $value[1];
- $emp_code = $value[2];
- $endorsement_id = $value[19] != null ? $value[19] : '';
-
- $db = \Config\Database::connect();
-
- // Execute the query
- $query = $db->table('emp_endorsement')
- ->select('emp_endorsement.id')
- ->join('employee_polices', 'employee_polices.id = emp_endorsement.pk')
- ->join('employees', 'employees.emp_code = emp_endorsement.emp_code')
- ->where('employees.emp_code', $emp_code)
- ->where('employees.name', $emp_name)
- ->where('employees.client_id', $client_id)
- ->where('emp_endorsement.actions', 'si')
- ->where('employee_polices.client_policy_id', $client_policy_id)
- ->where('(emp_endorsement.endorsement_id IS NULL OR emp_endorsement.endorsement_id = "")')
- ->groupBy('emp_endorsement.group_key');
-
- // Get the result
- $result = $query->get()->getRowArray();
- if (isset($result['id']) && $result['id'] !== null) {
- $empty_emp_tpa_uh_ids[] = $result['id'];
- }
- } catch (\Exception $e) {
- // Handle the exception here
- return 0;
- }
- }
- $rounded_totals = round($totals, 2);
-
- $missing_id_count = count($missing_id);
- $empty_id_count = count($empty_emp_tpa_uh_ids);
-
- // if($missing_id_count != $count){
-
- // return 2;
- // }
-
- if ($missing_id_count != 0) {
-
- return 2;
- }
-
- // if($empty_emp_tpa_uh_ids != $count){
-
- // return 3;
- // }
-
- if ($empty_id_count == 0) {
-
- return 3;
- }
-
- // dd($count, $missing_id, $missing_id_count, $empty_id_count, $data, $empty_emp_tpa_uh_ids);
-
- $is_moved = $file->move(WRITEPATH . 'uploads/import_excel');
- $filename = $file->getName();
-
- $this->myLogger->logme('error', 'SI_Enhancement Import file name : {data}', ['data' => $filename]);
- $random_number_count = 4;
- $batch_code = generate_random_string($random_number_count);
- $this->myLogger->logme('error', 'SI_Enhancement Import BATCH CODE : {data}', ['data' => $batch_code]);
-
-
- $import_data['batch_code'] = $batch_code;
- $import_data['created_by'] = get_session_userid();
- $import_data['file_name'] = $filename;
- $import_data['amount'] = $rounded_totals;
- $insert = $this->batchFileModel->insert($import_data);
- $batch_file_batch_code = $this->batchFileModel->where('id', $insert)->first();
-
- $batch_code_for_batch_list['batch_code'] = $batch_file_batch_code['batch_code'];
- $batch_code_for_batch_list['created_by'] = get_session_userid();
-
- $file_name_with_path = WRITEPATH . "/uploads/import_excel/" . $batch_file_batch_code['file_name'];
-
- if (!file_exists($file_name_with_path)) {
- return 2;
- }
-
- $data = read_excel_file_to_array($file_name_with_path);
- unset($data[0]);
- $count = count($data);
- $this->batchFileModel->where('id', $insert)->set('count', $count)->update();
- $employeeIds = [];
- foreach ($data as $key => $value) {
-
- if (!empty($value) && isset($value[19])) {
-
- $emp_name = $value[1];
- $emp_code = $value[2];
- // echo $emp_name .'-'. $emp_code; die;
- $endorsement_id = $value[19] != null ? $value[19] : '';
-
- $updateData = [
- 'emp_code' => $emp_code,
- 'client_id' => $client_id,
- 'client_policy_id' => $client_policy_id,
- 'emp_name' => $emp_name,
- 'endorsement_id' => $endorsement_id,
+ foreach ($headers as $key => $value) {
+ if($excel_header[$key] != $value){
+ $data = [
+ 'status' => 'failed-5',
];
- $this->employeePolicyModel->updateEndoresmentIdForSIEnhancement($updateData);
+ $this->batchFileModel->where('id', $file_id)->set($data)->update();
- $queryData = $this->employeePolicyModel
- ->select('employee_polices.*')
- ->join('employees', 'employee_polices.employee_id = employees.id')
- ->where('employees.emp_code', $emp_code)
- ->where('employees.name', $emp_name)
- ->where('employees.client_id', $client_id)
- ->where('employee_polices.client_policy_id', $client_policy_id)
- ->where('employee_polices.is_active', 1)
- ->first();
+ $file_data = $this->getDataByFileId($file_id, 'failure');
+ $this->setPullNotification($file_data);
- $queryData['is_active'] = 0;
- $this->employeePolicyModel->save($queryData);
-
- unset($queryData['id']);
- unset($queryData['created_by']);
- unset($queryData['created_at']);
- unset($queryData['updated_by']);
- unset($queryData['updated_at']);
- unset($queryData['is_active']);
-
- $queryData['basic_cover_si'] = $value[8];
- $queryData['premium'] = $value[14];
- $queryData['si_enhancement_date'] = $value[10];
- $queryData['rata_premimum'] = $value[16];
- $queryData['gst'] = $value[17];
- $queryData['created_by'] = get_session_userid();
-
- //new insert
- $this->employeePolicyModel->save($queryData);
-
- $val = $this->employeePolicyModel
- ->select('employee_polices.id')
- ->join('employees', 'employees.id = employee_polices.employee_id')
- ->where('employee_polices.client_policy_id', $client_policy_id)
- ->where('employees.client_id', $client_id)
- ->where('employees.name', $emp_name)
- ->where('employees.emp_code', $emp_code)
- ->where('employee_polices.is_active', 1)
- ->first();
-
- if ($val !== null) {
- $id = $val['id'];
- $batch_code_for_batch_list['emp_policy_id'] = $id;
- $this->batchListModel->insert($batch_code_for_batch_list);
- array_push($employeeIds, $id);
- }
- } else {
-
- return 0;
+ $this->myLogger->logme('error', 'Correction File Validation -- Upload the worng excel file');
+ return ['status' => 'error', 'message' => 'Upload the worng excel file'];
}
}
- $policy_name = $this->getPolicyNameUsingClientPolicyId($client_policy_id);
- $depositeData = [
- 'employeeIds' => $employeeIds,
- 'client_id' => $client_id,
- 'client_policy_id' => $client_policy_id,
- 'count' => $count,
- 'event' => $import_data['event_type'],
- 'policy_name' => $policy_name['policy_name'],
- ];
- // dd($depositeData);
- $this->cashDepositCalculationForSIEnhancement($depositeData);
- return 1;
+ $endorsement_data = $this->empEndorsementModel
+ ->select("
+ emp_endorsement.id,
+ emp_endorsement.pk,
+ emp_endorsement.emp_code,
+ emp_endorsement.endorsement_id,
+ emp_endorsement.old_value,
+ emp_endorsement.new_value,
+ emp_endorsement.field_name,
+ emp_endorsement.remarks,
+ emp_endorsement.actions,
+ employees.id AS primaryKey,
+ employees.name AS emp_name,
+ employees.dob AS emp_dob,
+ employees.gender AS emp_gender,
+ employees.client_id AS emp_client_id,
+ 'Has Define' AS emp_type,
+ employee_polices.uhid,
+ employees.relationship_code
+ ")
+ ->join("employees", "employees.id = emp_endorsement.pk", "left")
+ ->join("employee_polices", "employees.id = employee_polices.employee_id", "left")
+ ->where("employees.client_id", $client_id)
+ ->where("employee_polices.client_policy_id", $client_policy_id)
+ ->where("employees.client_branch_id", $client_branch_id)
+ ->where("employees.is_active", 1)
+ ->where("employees.emp_status", "active")
+ ->where("emp_endorsement.actions", "c")
+ ->where("(emp_endorsement.endorsement_id IS NULL OR emp_endorsement.endorsement_id = '')")
+ ->findAll();
+
+
+
+ // dd($endorsement_data, $excel_data);
+
+
+ if ($endorsement_data == null || empty($endorsement_data)) {
+
+ $data = [
+ 'status' => 'failed-1',
+ ];
+
+ $this->batchFileModel->where('id', $file_id)->set($data)->update();
+ $this->myLogger->logme('error', 'correctionFileValidation ENDORSEMENT ID already updated');
+
+ $file_data = $this->getDataByFileId($file_id, 'failure');
+ $this->setPullNotification($file_data);
+
+ return 'The list of employees provided has already been updated with the ENDORSEMENT ID, or this is not the correct file';
+
+ $this->myLogger->logme('error', 'correctionFileValidation ENDORSEMENT ID already updated or the uploadedfile is not correct');
+ }
+
+ $excel_data_count = count($excel_data);
+ $endorsement_data_count = count($endorsement_data);
+
+ $this->myLogger->logme('error', 'correctionFileValidation excel file count : {data}', ['data' => $excel_data_count]);
+ $this->myLogger->logme('error', 'correctionFileValidation database count : {data}', ['data' => $endorsement_data_count]);
+
+
+ $difference = $endorsement_data_count - $excel_data_count;
+
+ $status = 'in-progress';
+ if ($excel_data_count < $endorsement_data_count) {
+
+ $status = 'in-progress-partially';
+ $partially_updated_data = 'Expected : ' . $endorsement_data_count . ', ' . 'Updated : ' . $excel_data_count . ', ' . 'difference : ' . $difference;
+ $this->myLogger->logme('error', 'correctionFileValidation excel file count partially : {data}', ['data' => $partially_updated_data]);
+ }
+
+
+
+ if ($endorsement_data_count < $excel_data_count) {
+
+ $data = [
+ 'status' => 'failed-3',
+ ];
+
+ $this->batchFileModel->where('id', $file_id)->set($data)->update();
+ $this->myLogger->logme('error', 'correctionFileValidation excel file count ( {excel} ) exceeds db count ( {db} )', ['db' => $endorsement_data_count, 'excel' => $excel_data_count]);
+
+ $file_data = $this->getDataByFileId($file_id, 'failure');
+ $this->setPullNotification($file_data);
+
+ return 'The Excel record count exceeds the DB record count. excel file count : ' . $excel_data_count . 'db count : ' . $endorsement_data_count;
+ }
+
+
+ $errors = []; // Initialize an array to store errors
+ $missing_id = [];
+ $batch_list_id = [];
+
+ foreach ($endorsement_data as $key => $endorsement_value) {
+
+ $key = $key + 1;
+
+ if (!isset($excel_data[$key])) {
+ break;
+ }
+
+
+ if ($excel_data[$key][10] === null) {
+ $missing_id[$key][] = [
+ 'row' => $key,
+ 'column' => 10,
+ ];
+ }
+
+
+ if ($endorsement_value['emp_name'] != $excel_data[$key][2]) {
+ $errors[$key][] = [
+ 'row' => $key,
+ 'column' => 2,
+ 'db_data' => $endorsement_value['emp_name'],
+ 'excel_data' => $excel_data[$key][2]
+ ];
+ }
+
+ if ($endorsement_value['emp_code'] != $excel_data[$key][0]) {
+ $errors[$key][] = [
+ 'row' => $key,
+ 'column' => 0,
+ 'db_data' => $endorsement_value['emp_code'],
+ 'excel_data' => $excel_data[$key][0]
+ ];
+ }
+
+ if ($endorsement_value['emp_dob'] != $excel_data[$key][5]) {
+ $errors[$key][] = [
+ 'row' => $key,
+ 'column' => 5,
+ 'db_data' => $endorsement_value['emp_dob'],
+ 'excel_data' => $excel_data[$key][5]
+ ];
+ }
+
+ if ($endorsement_value['emp_gender'] != $excel_data[$key][6]) {
+ $errors[$key][] = [
+ 'row' => $key,
+ 'column' => 6,
+ 'db_data' => $endorsement_value['emp_gender'],
+ 'excel_data' => $excel_data[$key][6]
+ ];
+ }
+
+ if ($endorsement_value['old_value'] != $excel_data[$key][7]) {
+ $errors[$key][] = [
+ 'row' => $key,
+ 'column' => 7,
+ 'db_data' => $endorsement_value['old_value'],
+ 'excel_data' => $excel_data[$key][7]
+ ];
+ }
+
+ if ($endorsement_value['new_value'] != $excel_data[$key][8]) {
+ $errors[$key][] = [
+ 'row' => $key,
+ 'column' => 8,
+ 'db_data' => $endorsement_value['new_value'],
+ 'excel_data' => $excel_data[$key][8]
+ ];
+ }
+
+
+
+ if ($endorsement_value['uhid'] != $excel_data[$key][1]) {
+ $errors[$key][] = [
+ 'row' => $key,
+ 'column' => 1,
+ 'db_data' => $endorsement_value['uhid'],
+ 'excel_data' => $excel_data[$key][1]
+ ];
+ }
+
+ $batch_list_id[] = $endorsement_value['primaryKey'];
+ }
+
+
+ $error_count = count($errors);
+ $json_errors = json_encode($errors);
+
+
+ $missing_id_count = count($missing_id);
+ $json_missing_id = json_encode($missing_id);
+
+ // dd($error_count, $missing_id_count, $json_errors, $json_missing_id, $batch_list_id);
+
+
+ if ($missing_id_count > 0) {
+
+ $data = [
+
+ 'count' => $endorsement_data_count,
+ 'error_data' => $json_missing_id,
+ 'status' => 'failed',
+ ];
+
+ $this->batchFileModel->where('id', $file_id)->set($data)->update();
+
+ $file_data = $this->getDataByFileId($file_id, 'failure');
+ $this->setPullNotification($file_data);
+
+ return 'The ENDORSEMENT ID column is either partially or entirely empty.';
+
+ }
+
+
+ if ($error_count > 0) {
+
+ $data = [
+
+ 'count' => $endorsement_data_count,
+ 'error_data' => $json_errors,
+ 'status' => 'failed',
+ ];
+
+ $this->batchFileModel->where('id', $file_id)->set($data)->update();
+ return 'Correction Validation Failed';
+
+ } else {
+
+ $data = [
+ 'count' => $endorsement_data_count,
+ 'status' => $status,
+ 'error_data' => $partially_updated_data ?? null,
+ ];
+
+ $this->batchFileModel->where('id', $file_id)->set($data)->update();
+
+
+ foreach ($batch_list_id as $key => $value) {
+
+ $data = [
+ 'emp_policy_id' => $value,
+ 'batch_code' => $batch_code,
+ 'created_by' => $user_id,
+ ];
+
+ $insert = $this->batchListModel->insert($data);
+ }
+
+
+ $job_details = new Jobs();
+ $r = Jobs::addJob(['job_name' => 'importCorrectionUpdateEndorsementID','payload' => ['file_id' => $file_id]]);
+
+ // $this->importCorrectionUpdateEndorsementID(['file_id' => $file_id]);
+
+ return 'Correction Validation Success';
+ }
}
- public function importExcelDataForDeletion($import_data)
+ public function importCorrectionUpdateEndorsementID($params){
+
+ $this->myLogger->logme('error', 'importCorrectionUpdateEndorsementID called');
+
+ $file_id = $params['file_id'];
+ $file = $this->batchFileModel->find($file_id);
+ if (!$file) {
+
+ $data = [
+ 'status' => 'failed-4',
+ ];
+
+ $this->batchFileModel->where('id', $file_id)->set($data)->update();
+ $this->myLogger->logme('error', 'importCorrectionUpdateEndorsementID the Physical file not found - file id : {data}', ['data' => $file_id]);
+
+ $file_data = $this->getDataByFileId($file_id, 'failure');
+ $this->setPullNotification($file_data);
+
+ return 'importCorrectionUpdateEndorsementID the Physical file not found'; // Return error code if file not found
+ }
+
+ $client_id = $file['client_id'];
+ $client_policy_id = $file['client_policy_id'];
+ $client_branch_id = $file['client_branch_id'];
+ $insurer_or_tpa = $file['insurer_or_tpa'];
+ $status = $file['status'];
+ $batch_code = $file['batch_code'];
+ $user_id = $file['created_by'];
+
+
+ $status_val = 'success';
+ if ($status == 'in-progress-partially') {
+
+ $status_val = 'partially success';
+ }
+
+ $this->myLogger->logme('error', 'importCorrectionUpdateEndorsementID file name : {data}', ['data'=> $file['file_name']]);
+
+ $file_name_with_path = WRITEPATH . "/uploads/import_excel/" . $file['file_name'];
+ $excel_data = $this->readExcelFileToArray($file_name_with_path);
+ unset($excel_data[0]);
+
+ $emp_ids = [];
+ $emp_details = [];
+ $endorsement_id = [];
+ $endorsement_details = [];
+
+ $emp_count = count($excel_data);
+ $db = \Config\Database::connect();
+
+
+ foreach ($excel_data as $key => $value) {
+
+ $emp_code = $value[0];
+ $old_value = $value[7];
+ $endorsement_id[] = $value[10];
+ $uhid = $value[1];
+
+
+ $result = $this->empEndorsementModel
+ ->select('emp_endorsement.*, employees.id as emp_id')
+ ->join('employees', 'employees.id = emp_endorsement.pk')
+ ->join('employee_polices', 'employee_polices.employee_id = employees.id')
+ ->where('employees.emp_code', $emp_code)
+ ->where('employees.client_id', $client_id)
+ ->where('employees.client_branch_id', $client_branch_id)
+ ->where('employee_polices.client_policy_id', $client_policy_id)
+ ->where('employee_polices.uhid', $uhid)
+ ->where('emp_endorsement.old_value', $old_value)
+
+ ->where('employee_polices.is_active', 1)
+ ->where('employee_polices.status', 'active')
+ ->where('employees.is_active', 1)
+ ->where('employees.emp_status', 'active')
+ ->first();
+
+ if (isset($result['id']) && $result['id'] !== null) {
+
+ // return $result;
+ $emp_details[] = array('id' => $result['emp_id'], $result['field_name'] => $value[8]);
+ $endorsement_details[] = array('group_key' => $result['group_key'], 'id' => $result['id'], 'endorsement_id' => $value[10], 'status' => 'complete');
+ }
+
+ }
+
+ // return [$emp_details, $endorsement_details];
+
+ $this->empEndorsementModel->updateBatch($endorsement_details, 'group_key');
+ $this->employeePolicyModel->bulkUpdateForCorrection($emp_details);
+
+ // Update batch file status and amount
+ $this->batchFileModel->update($file_id, [
+ 'count' => $emp_count,
+ 'status' => $status_val,
+ ]);
+
+
+ $this->myLogger->logme('error', 'importCorrectionUpdateEndorsementID employee count : {data}', ['data'=> $emp_count]);
+ $this->myLogger->logme('error', 'importCorrectionUpdateEndorsementID batch file status : {data}', ['data'=> $status_val]);
+
+
+ $file_data = $this->getDataByFileId($file_id, 'success');
+ $this->setPullNotification($file_data);
+
+
+ return 'Import Correction Updated '. $status_val . '- Updated Count : ' . $emp_count;
+
+ }
+
+
+
+
+ //Endorsement SIEnhancement
+
+ public function importSIEnhancementValidation($params)
+ {
+ $file_id = $params['file_id'];
+ $file = $this->batchFileModel->where('id', $file_id)->first();
+
+ $client_id = $file['client_id'];
+ $client_policy_id = $file['client_policy_id'];
+ $client_branch_id = $file['client_branch_id'];
+ $batch_code = $file['batch_code'];
+ $user_id = $file['created_by'];
+
+
+ $file_name_with_path = WRITEPATH . "/uploads/import_excel/" . $file['file_name'];
+
+ if (!file_exists($file_name_with_path)) {
+ return 'The Physical file not found';
+ }
+
+ $excel_data = $this->readExcelFileToArray($file_name_with_path);
+ $excel_header = $excel_data[0];
+ unset($excel_data[0]);
+
+
+ $headers = ['S.No','NAME OF EMP/DEP','EMP ID','EMP/DEP TYPE','RELATION','DOB','GENDER','PRE EXISTING AILMENTS','BASIC COVER SI','Old Sum Insured','Date of Coverage','Policy End Date','No Of Days','Old SI Premium','New SI premium','Difference premium','Pro Rata Premium','GST','Total','ENDORSEMENT_ID'];
+
+
+ foreach ($headers as $key => $value) {
+ if($excel_header[$key] != $value){
+ $data = [
+ 'status' => 'failed-5',
+ ];
+
+ $this->batchFileModel->where('id', $file_id)->set($data)->update();
+
+ $file_data = $this->getDataByFileId($file_id, 'failure');
+ $this->setPullNotification($file_data);
+
+ $this->myLogger->logme('error', 'SI Enhancement File Validation -- Upload the worng excel file');
+ return ['status' => 'error', 'message' => 'Upload the worng excel file'];
+ }
+ }
+
+
+ $db = \Config\Database::connect();
+
+ // Raw SQL query
+ $sql = "
+ SELECT
+ a.id as endorsement_primarykey,
+ a.group_key,
+ employee_polices.id AS primaryKey,
+ employees.id AS emp_primary,
+ employees.name AS emp_name,
+ employees.emp_code AS emp_code,
+ employees.dob AS emp_dob,
+ employees.gender AS emp_gender,
+ employees.relationship_code AS emp_relationship_code,
+ 'Has Define' AS emp_type,
+ employee_polices.uhid AS risk_id,
+ employee_polices.pre_existing_alignments,
+ employee_polices.policy_end_date,
+ employee_polices.basic_cover_si as old_basic_cover_si,
+ employee_polices.rata_premimum as old_si_premium,
+ sidata.new_basic_cover_si,
+ sidata.new_si_premium,
+ sidata.date_of_coverage,
+ DATEDIFF(employee_polices.policy_end_date, sidata.date_of_coverage) + 1 AS no_of_days,
+ sidata.new_si_premium - employee_polices.rata_premimum AS difference_premium,
+ ROUND((sidata.new_si_premium - employee_polices.rata_premimum) * (DATEDIFF(employee_polices.policy_end_date, sidata.date_of_coverage) + 1) / 365, 2) AS pro_rata_premimum,
+ ROUND(((sidata.new_si_premium - employee_polices.rata_premimum) * (DATEDIFF(employee_polices.policy_end_date, sidata.date_of_coverage) + 1) / 365) * 0.18, 2) AS gst,
+ ((sidata.new_si_premium - employee_polices.rata_premimum) * (DATEDIFF(employee_polices.policy_end_date, sidata.date_of_coverage) + 1) / 365) + ROUND(((sidata.new_si_premium - employee_polices.rata_premimum) * (DATEDIFF(employee_polices.policy_end_date, sidata.date_of_coverage) + 1) / 365) * 0.18, 2) AS total
+ FROM
+ emp_endorsement a
+ LEFT JOIN
+ employees ON employees.emp_code = a.emp_code
+ LEFT JOIN
+ employee_polices ON employees.id = employee_polices.employee_id
+ LEFT JOIN (
+ SELECT
+ aa.emp_code,
+ aa.new_value as new_basic_cover_si,
+ bb.new_value as new_si_premium,
+ cc.new_value as date_of_coverage
+ FROM (
+ SELECT
+ a1.emp_code,
+ a1.field_name,
+ a1.new_value
+ FROM
+ emp_endorsement as a1
+ WHERE
+ a1.field_name = 'basic_cover_si'
+ ) aa
+ LEFT JOIN (
+ SELECT
+ b1.emp_code,
+ b1.field_name,
+ b1.new_value
+ FROM
+ emp_endorsement as b1
+ WHERE
+ b1.field_name = 'premium'
+ ) bb ON aa.emp_code = bb.emp_code
+ LEFT JOIN (
+ SELECT
+ c1.emp_code,
+ c1.field_name,
+ c1.new_value
+ FROM
+ emp_endorsement as c1
+ WHERE
+ c1.field_name = 'si_enhancement_date'
+ ) cc ON aa.emp_code = cc.emp_code
+ ) as sidata ON a.emp_code = sidata.emp_code
+ WHERE
+ employee_polices.client_policy_id = '$client_policy_id'
+ AND employees.client_branch_id = '$client_branch_id'
+ AND employee_polices.is_active = '1'
+ AND (a.endorsement_id IS NULL OR a.endorsement_id = '')
+ AND a.actions = 'si'
+ GROUP BY group_key
+ ";
+
+ // Execute the query
+ $query = $db->query($sql);
+
+ // Fetch the results
+ $endorsement_data = $query->getResultArray();
+
+
+
+ // dd($endorsement_data, $excel_data);
+
+
+ if ($endorsement_data == null || empty($endorsement_data)) {
+
+ $data = [
+ 'status' => 'failed-1',
+ ];
+
+ $this->batchFileModel->where('id', $file_id)->set($data)->update();
+ $this->myLogger->logme('error', 'SI Enhancement_File Validation -- ENDORSEMENT ID already updated or the uploadedfile is not correct');
+
+ $file_data = $this->getDataByFileId($file_id, 'failure');
+ $this->setPullNotification($file_data);
+
+ return 'The list of employees provided has already been updated with the ENDORSEMENT ID, or this is not the correct file';
+ }
+
+ $excel_data_count = count($excel_data);
+ $endorsement_data_count = count($endorsement_data);
+
+ $this->myLogger->logme('error', 'SI Enhancement_File Validation -- Excel file count : {data}', ['data' => $excel_data_count]);
+ $this->myLogger->logme('error', 'SI Enhancement File Validation -- Database count : {data}', ['data' => $endorsement_data_count]);
+
+
+ $difference = $endorsement_data_count - $excel_data_count;
+
+ $status = 'in-progress';
+ if ($excel_data_count < $endorsement_data_count) {
+
+ $status = 'in-progress-partially';
+ $partially_updated_data = 'Expected : ' . $endorsement_data_count . ', ' . 'Updated : ' . $excel_data_count . ', ' . 'difference : ' . $difference;
+ $this->myLogger->logme('error', 'SI Enhancement File Validation -- excel file count partially : {data}', ['data' => $partially_updated_data]);
+ }
+
+
+
+ if ($endorsement_data_count < $excel_data_count) {
+
+ $data = [
+ 'status' => 'failed-3',
+ ];
+
+ $this->batchFileModel->where('id', $file_id)->set($data)->update();
+ $this->myLogger->logme('error', 'SI_Enhancement_FileValidation excel file count ( {excel} ) exceeds db count ( {db} )', ['db' => $endorsement_data_count, 'excel' => $excel_data_count]);
+
+ $file_data = $this->getDataByFileId($file_id, 'failure');
+ $this->setPullNotification($file_data);
+
+ return 'The Excel record count exceeds the DB record count. excel file count : ' . $excel_data_count . 'db count : ' . $endorsement_data_count;
+ }
+
+
+ $errors = []; // Initialize an array to store errors
+ $missing_id = [];
+ $batch_list_id = [];
+
+ foreach ($endorsement_data as $key => $endorsement_value) {
+
+ $key = $key + 1;
+
+ if (!isset($excel_data[$key])) {
+ break;
+ }
+
+
+ if ($excel_data[$key][19] === null) {
+ $missing_id[$key][] = [
+ 'row' => $key,
+ 'column' => 19,
+ ];
+ }
+
+
+ if ($endorsement_value['emp_name'] != $excel_data[$key][1]) {
+ $errors[$key][] = [
+ 'row' => $key,
+ 'column' => 1,
+ 'db_data' => $endorsement_value['emp_name'],
+ 'excel_data' => $excel_data[$key][1]
+ ];
+ }
+
+ if ($endorsement_value['emp_code'] != $excel_data[$key][2]) {
+ $errors[$key][] = [
+ 'row' => $key,
+ 'column' => 2,
+ 'db_data' => $endorsement_value['emp_code'],
+ 'excel_data' => $excel_data[$key][2]
+ ];
+ }
+
+ if ($endorsement_value['emp_relationship_code'] != $excel_data[$key][4]) {
+ $errors[$key][] = [
+ 'row' => $key,
+ 'column' => 4,
+ 'db_data' => $endorsement_value['emp_relationship_code'],
+ 'excel_data' => $excel_data[$key][4]
+ ];
+ }
+
+ if ($endorsement_value['emp_dob'] != $excel_data[$key][5]) {
+ $errors[$key][] = [
+ 'row' => $key,
+ 'column' => 5,
+ 'db_data' => $endorsement_value['emp_dob'],
+ 'excel_data' => $excel_data[$key][5]
+ ];
+ }
+
+ if ($endorsement_value['emp_gender'] != $excel_data[$key][6]) {
+ $errors[$key][] = [
+ 'row' => $key,
+ 'column' => 6,
+ 'db_data' => $endorsement_value['emp_gender'],
+ 'excel_data' => $excel_data[$key][6]
+ ];
+ }
+
+
+ if ($endorsement_value['pre_existing_alignments'] != $excel_data[$key][7]) {
+ $errors[$key][] = [
+ 'row' => $key,
+ 'column' => 7,
+ 'db_data' => $endorsement_value['pre_existing_alignments'],
+ 'excel_data' => $excel_data[$key][7]
+ ];
+ }
+
+ if ($endorsement_value['new_basic_cover_si'] != $excel_data[$key][8]) {
+ $errors[$key][] = [
+ 'row' => $key,
+ 'column' => 8,
+ 'db_data' => $endorsement_value['new_basic_cover_si'],
+ 'excel_data' => $excel_data[$key][8]
+ ];
+ }
+
+ if ($endorsement_value['old_basic_cover_si'] != $excel_data[$key][9]) {
+ $errors[$key][] = [
+ 'row' => $key,
+ 'column' => 9,
+ 'db_data' => $endorsement_value['old_basic_cover_si'],
+ 'excel_data' => $excel_data[$key][9]
+ ];
+ }
+
+
+
+ if ($endorsement_value['date_of_coverage'] != $excel_data[$key][10]) {
+ $errors[$key][] = [
+ 'row' => $key,
+ 'column' => 10,
+ 'db_data' => $endorsement_value['date_of_coverage'],
+ 'excel_data' => $excel_data[$key][10]
+ ];
+ }
+
+ if ($endorsement_value['policy_end_date'] != $excel_data[$key][11]) {
+ $errors[$key][] = [
+ 'row' => $key,
+ 'column' => 11,
+ 'db_data' => $endorsement_value['policy_end_date'],
+ 'excel_data' => $excel_data[$key][11]
+ ];
+ }
+
+ if ($endorsement_value['no_of_days'] != $excel_data[$key][12]) {
+ $errors[$key][] = [
+ 'row' => $key,
+ 'column' => 12,
+ 'db_data' => $endorsement_value['no_of_days'],
+ 'excel_data' => $excel_data[$key][12]
+ ];
+ }
+
+ if ($endorsement_value['old_si_premium'] != $excel_data[$key][13]) {
+ $errors[$key][] = [
+ 'row' => $key,
+ 'column' => 13,
+ 'db_data' => $endorsement_value['old_si_premium'],
+ 'excel_data' => $excel_data[$key][13]
+ ];
+ }
+
+ if ($endorsement_value['new_si_premium'] != $excel_data[$key][14]) {
+ $errors[$key][] = [
+ 'row' => $key,
+ 'column' => 14,
+ 'db_data' => $endorsement_value['new_si_premium'],
+ 'excel_data' => $excel_data[$key][14]
+ ];
+ }
+
+ if ($endorsement_value['difference_premium'] != $excel_data[$key][15]) {
+ $errors[$key][] = [
+ 'row' => $key,
+ 'column' => 15,
+ 'db_data' => $endorsement_value['difference_premium'],
+ 'excel_data' => $excel_data[$key][15]
+ ];
+ }
+
+ if ($endorsement_value['pro_rata_premimum'] != $excel_data[$key][16]) {
+ $errors[$key][] = [
+ 'row' => $key,
+ 'column' => 16,
+ 'db_data' => $endorsement_value['pro_rata_premimum'],
+ 'excel_data' => $excel_data[$key][16]
+ ];
+ }
+
+ if ($endorsement_value['gst'] != $excel_data[$key][17]) {
+ $errors[$key][] = [
+ 'row' => $key,
+ 'column' => 17,
+ 'db_data' => $endorsement_value['gst'],
+ 'excel_data' => $excel_data[$key][17]
+ ];
+ }
+
+ $batch_list_id[] = $endorsement_value['primaryKey'];
+ }
+
+
+ $error_count = count($errors);
+ $json_errors = json_encode($errors);
+
+
+ $missing_id_count = count($missing_id);
+ $json_missing_id = json_encode($missing_id);
+
+ // dd($error_count, $missing_id_count, $json_errors, $json_missing_id, $batch_list_id);
+
+
+ if ($missing_id_count > 0) {
+
+ $data = [
+
+ 'count' => $endorsement_data_count,
+ 'error_data' => $json_missing_id,
+ 'status' => 'failed',
+ ];
+
+ $this->batchFileModel->where('id', $file_id)->set($data)->update();
+
+ $file_data = $this->getDataByFileId($file_id, 'failure');
+ $this->setPullNotification($file_data);
+
+ return 'The ENDORSEMENT ID column is either partially or entirely empty.';
+ }
+
+
+ if ($error_count > 0) {
+
+ $data = [
+
+ 'count' => $endorsement_data_count,
+ 'error_data' => $json_errors,
+ 'status' => 'failed',
+ ];
+
+ $this->batchFileModel->where('id', $file_id)->set($data)->update();
+ return 'SI ENHANCEMENT File Validation Failed';
+ } else {
+
+ $data = [
+ 'count' => $endorsement_data_count,
+ 'status' => $status,
+ 'error_data' => $partially_updated_data ?? null,
+ ];
+
+ $this->batchFileModel->where('id', $file_id)->set($data)->update();
+
+
+ foreach ($batch_list_id as $key => $value) {
+
+ $data = [
+ 'emp_policy_id' => $value,
+ 'batch_code' => $batch_code,
+ 'created_by' => $user_id,
+ ];
+
+ $insert = $this->batchListModel->insert($data);
+ }
+
+
+ $job_details = new Jobs();
+ $r = Jobs::addJob(['job_name' => 'importSIEnhancementUpdateEndorsementID', 'payload' => ['file_id' => $file_id]]);
+
+ // $this->importSIEnhancementUpdateEndorsementID(['file_id' => $file_id]);
+ return 'SI Enhancement_File Validation -- Success';
+ }
+ }
+
+
+ public function importSIEnhancementUpdateEndorsementID($params)
{
- $client_id = $import_data['client_id'];
- $client_policy_id = $import_data['client_policy_id'];
- $file = $import_data['file'];
+ $this->myLogger->logme('error', 'SI Enhancement Update Endorsement ID -- Function called');
+
+ $file_id = $params['file_id'];
+ $file = $this->batchFileModel->find($file_id);
+ if (!$file) {
+
+ $data = [
+ 'status' => 'failed-4',
+ ];
+
+ $this->batchFileModel->where('id', $file_id)->set($data)->update();
+ $this->myLogger->logme('error', 'SI Enhancement Update Endorsement ID -- The Physical file not found -- File id : {data}', ['data' => $file_id]);
+
+ $file_data = $this->getDataByFileId($file_id, 'failure');
+ $this->setPullNotification($file_data);
+
+ return 'SI Enhancement Update Endorsement ID -- The Physical file not found'; // Return error code if file not found
+ }
+
+ $client_id = $file['client_id'];
+ $client_policy_id = $file['client_policy_id'];
+ $client_branch_id = $file['client_branch_id'];
+ $status = $file['status'];
+ $batch_code = $file['batch_code'];
+ $user_id = $file['created_by'];
- $data = $this->readExcelToArray($file);
- unset($data[0]);
- array_pop($data);
- $count = count($data);
+ $status_val = 'success';
+ if ($status == 'in-progress-partially') {
+ $status_val = 'partially success';
+ }
- $missing_id = [];
- $empty_emp_tpa_uh_ids = [];
+ $this->myLogger->logme('error', 'SI Enhancement Update Endorsement ID -- file name : {data}', ['data' => $file['file_name']]);
+
+ $file_name_with_path = WRITEPATH . "/uploads/import_excel/" . $file['file_name'];
+ $excel_data = $this->readExcelFileToArray($file_name_with_path);
+ unset($excel_data[0]);
+
+ $emp_count = count($excel_data); //excel file count
+
+ $emp_policy_ids = [];
+ $employeeIds = [];
+ $emp_details = [];
+ $endorsement_id = [];
+ $endorsement_details = [];
$totals = 0;
- foreach ($data as $key => $value) {
- try {
+ foreach ($excel_data as $key => $value) {
- if ($value[15] === null) {
- $missing_id[] = $key + 1;
- }
+ $emp_name = $value[1];
+ $emp_code = $value[2];
+ $endorsement_id[] = $value[19];
+ $totals += $value[18];
- $totals += $value[13];
- $emp_name = $value[2]; //employee name
- $emp_code = $value[1]; //employee code
- $date_of_exit = $value[7]; // date of releving
- $endorsement_id = $value[15] != null ? $value[15] : ''; //endorsement id
+ $result = $this->empEndorsementModel
- $db = \Config\Database::connect();
+ ->select('emp_endorsement.*, employees.id as emp_id, employee_polices.id as emp_policy_id')
+ ->join('employee_polices', 'employee_polices.id = emp_endorsement.pk')
+ ->join('employees', 'employees.emp_code = emp_endorsement.emp_code')
+ ->where('employees.emp_code', $emp_code)
+ ->where('employees.name', $emp_name)
+ ->where('employees.client_id', $client_id)
+ ->where('employees.client_branch_id', $client_branch_id)
+ ->where('emp_endorsement.actions', 'si')
+ ->where('employee_polices.client_policy_id', $client_policy_id)
+ ->where('employee_polices.is_active', 1)
+ ->where('employee_polices.status', 'active')
+ ->where('employees.is_active', 1)
+ ->where('employees.emp_status', 'active')
+ ->where('(emp_endorsement.endorsement_id IS NULL OR emp_endorsement.endorsement_id = "")')
+ ->groupBy('emp_endorsement.group_key')
+ ->first();
- // Execute the query
- $query = $db->table('emp_endorsement')
- ->select('emp_endorsement.id')
- ->join('employee_polices', 'employee_polices.id = emp_endorsement.pk')
- ->join('employees', 'employees.emp_code = emp_endorsement.emp_code')
- ->where('employees.emp_code', $emp_code)
- ->where('employees.name', $emp_name)
- ->where('employees.client_id', $client_id)
- ->where('emp_endorsement.actions', 'd')
- ->where('employee_polices.client_policy_id', $client_policy_id)
- ->where('(emp_endorsement.endorsement_id IS NULL OR emp_endorsement.endorsement_id = "")')
- ->groupBy('emp_endorsement.group_key');
-
- $result = $query->get()->getRowArray();
- if (isset($result['id']) && $result['id'] !== null) {
- $empty_emp_tpa_uh_ids[] = $result['id'];
- }
- } catch (\Exception $e) {
- // Handle the exception here
- return 0;
+ if (isset($result['id']) && $result['id'] !== null) {
+ $emp_policy_ids[] = array('id' => $result['emp_policy_id'], 'is_active' => 0);
+ $employeeIds[] = $result['emp_policy_id'];
+ $endorsement_details[] = array('id' => $result['id'], 'group_key' => $result['group_key'], 'endorsement_id' => $value[19], 'status' => 'complete');
}
+
+ $empData = $this->employeePolicyModel
+ ->select('employee_polices.*')
+ ->join('employees', 'employee_polices.employee_id = employees.id')
+ ->where('employees.emp_code', $emp_code)
+ ->where('employees.name', $emp_name)
+ ->where('employees.client_id', $client_id)
+ ->where('employees.client_branch_id', $client_branch_id)
+ ->where('employee_polices.client_policy_id', $client_policy_id)
+ ->where('employee_polices.is_active', 1)
+ ->where('employee_polices.status', 'active')
+ ->where('employees.is_active', 1)
+ ->where('employees.emp_status', 'active')
+ ->first();
+
+ unset($empData['id'], $empData['created_by'], $empData['created_at'], $empData['updated_by'], $empData['updated_at'], $empData['is_active']);
+
+ $empData['basic_cover_si'] = $value[8];
+ $empData['premium'] = $value[14];
+ $empData['si_enhancement_date'] = $value[10];
+ $empData['rata_premimum'] = $value[16];
+ $empData['gst'] = $value[17];
+ $empData['created_by'] = $user_id;
+
+ $emp_details[] = $empData;
}
$rounded_totals = round($totals, 2);
- $missing_id_count = count($missing_id);
- $empty_id_count = count($empty_emp_tpa_uh_ids);
- // if($missing_id_count != $count){
+ // dd($emp_policy_ids, $emp_details, $endorsement_details);
- // return 2;
- // }
+ $this->employeePolicyModel->updateBatch($emp_policy_ids, 'id');
- if ($missing_id_count != 0) {
-
- return 2;
+ $db = \Config\Database::connect();
+ $db->transStart();
+
+ $this->employeePolicyModel->insertBatch($emp_details);
+
+ $insertedIds = [];
+ $startId = $db->insertID(); // Get the first inserted ID
+
+ for ($i = 0; $i < count($emp_details); $i++) {
+ $insertedIds[] = $startId + $i;
}
-
- // if($empty_emp_tpa_uh_ids != $count){
-
- // return 3;
+
+ $db->transComplete();
+
+ // if ($db->transStatus() === FALSE) {
+ // // Handle the error, rollback, etc.
+ // } else {
+ // // Transaction successful
+ // print_r($insertedIds); // This will print the array of inserted IDs
// }
+
+ $this->employeePolicyModel->bulkUpdateForEndorsement($endorsement_details);
- if ($empty_id_count == 0) {
-
- return 3;
- }
-
- // dd($count, $missing_id_count, $empty_id_count, $data, $empty_emp_tpa_uh_ids);
-
- $is_moved = $file->move(WRITEPATH . 'uploads/import_excel');
- $filename = $file->getName();
-
- $this->myLogger->logme('error', 'Deletion Import file name : {data}', ['data' => $filename]);
- $random_number_count = 4;
- $batch_code = generate_random_string($random_number_count);
- $this->myLogger->logme('error', 'Deletion Import BATCH CODE : {data}', ['data' => $batch_code]);
+ // Update batch file status and amount
+ $this->batchFileModel->update($file_id, [
+ 'count' => $emp_count,
+ 'status' => $status_val,
+ 'amount' => $rounded_totals,
+ ]);
- $import_data['batch_code'] = $batch_code;
- $import_data['created_by'] = get_session_userid();
- $import_data['file_name'] = $filename;
- $import_data['amount'] = $rounded_totals;
- $insert = $this->batchFileModel->insert($import_data);
- $batch_file_batch_code = $this->batchFileModel->where('id', $insert)->first();
+ $this->myLogger->logme('error', 'SI Enhancement Update Endorsement ID -- Employee count : {data}', ['data' => $emp_count]);
+ $this->myLogger->logme('error', 'SI Enhancement Update Endorsement ID -- Batch File status : {data}', ['data' => $status_val]);
- $batch_code_for_batch_list['batch_code'] = $batch_file_batch_code['batch_code'];
- $batch_code_for_batch_list['created_by'] = get_session_userid();
- $file_name_with_path = WRITEPATH . "/uploads/import_excel/" . $batch_file_batch_code['file_name'];
+ $file_data = $this->getDataByFileId($file_id, 'success');
+ $this->setPullNotification($file_data);
+
+ //call the cash deposite function
+
+ $policy_name = $this->getPolicyNameUsingClientPolicyId($client_policy_id);
+ $job_details = new Jobs();
+ $r = Jobs::addJob(['job_name' => 'cashDepositCalculationForSIEnhancement','payload' => [
+ 'employeeIds' => $insertedIds,
+ 'client_id' => $client_id,
+ 'client_policy_id' => $client_policy_id,
+ 'client_branch_id' => $client_branch_id,
+ 'count' => $emp_count,
+ 'event' => $file['event_type'],
+ 'policy_name' => $policy_name['policy_name'],
+ 'user_id' => $user_id,
+ ]]);
+
+ return 'SI Enhancement Update Endorsement ID -- ' . $status_val . '-- Updated Count : ' . $emp_count;
+ }
+
+
+
+ //Endorsement Deletion
+
+ public function importDeletionValidation($params)
+ {
+ $file_id = $params['file_id'];
+ $file = $this->batchFileModel->where('id', $file_id)->first();
+
+ $client_id = $file['client_id'];
+ $client_policy_id = $file['client_policy_id'];
+ $client_branch_id = $file['client_branch_id'];
+ $batch_code = $file['batch_code'];
+ $user_id = $file['created_by'];
+
+
+ $file_name_with_path = WRITEPATH . "/uploads/import_excel/" . $file['file_name'];
if (!file_exists($file_name_with_path)) {
- return 2;
+ return 'The Physical file not found';
}
- $data = read_excel_file_to_array($file_name_with_path);
- unset($data[0]);
- array_pop($data);
+ $excel_data = $this->readExcelFileToArray($file_name_with_path);
+ $excel_header = $excel_data[0];
+ unset($excel_data[0]);
+ array_pop($excel_data);
- $count = count($data);
- $this->batchFileModel->where('id', $insert)->set('count', $count)->update();
-
- $employeeIds = [];
- foreach ($data as $key => $value) {
-
- if (!empty($value) && isset($value[15])) {
-
- $emp_name = $value[2]; //employee name
- $emp_code = $value[1]; //employee code
- $date_of_exit = $value[7]; // date of releving
-
- // echo $emp_name .'-'. $emp_code .'-'. $date_of_exit; die;
- $endorsement_id = $value[15] != null ? $value[15] : ''; //endorsement id
-
- $val = $this->employeePolicyModel
- ->select('employee_polices.id')
- ->join('employees', 'employees.id = employee_polices.employee_id')
- ->where('employee_polices.client_policy_id', $client_policy_id)
- ->where('employees.client_id', $client_id)
- ->where('employees.name', $emp_name)
- ->where('employees.emp_code', $emp_code)
- ->where('employee_polices.is_active', 1)
- ->first();
+ $headers = ['S.No','EMP ID','EMP NAME','DOB','GENDER','RELATIONSHIP','SUM INSURED','Date of Leaving','Policy End Date','No Of Days','Premium','Pro Rata Premium','GST','Total','Claim Status','ENDORSEMENT_ID'];
- if ($val !== null) {
-
- $id = $val['id'];
- $batch_code_for_batch_list['emp_policy_id'] = $id;
- $this->batchListModel->insert($batch_code_for_batch_list);
- array_push($employeeIds, $id);
- }
-
- // $updateData = [
- // 'emp_code' =>$emp_code,
- // 'client_id' =>$client_id,
- // 'client_policy_id' =>$client_policy_id,
- // 'emp_name' =>$emp_name,
- // 'endorsement_id' =>$endorsement_id,
- // ];
-
- // $this->employeePolicyModel->updateEndoresmentIdForDeletion($updateData);
-
- $deletionDataForEmployee = $this->empEndorsementModel
- ->select('emp_endorsement.new_value, emp_endorsement.id as ee_id, employees.id')
- ->join('employees', 'emp_endorsement.emp_code = employees.emp_code')
- ->join('employee_polices', 'employee_polices.employee_id = employees.id')
- ->where('emp_endorsement.emp_code', $emp_code)
- ->where('employees.client_id', $client_id)
- ->where('employee_polices.client_policy_id', $client_policy_id)
- ->where('emp_endorsement.name', $emp_name)
- ->where('emp_endorsement.field_name', 'emp_status')
- ->first();
-
- $deletionDataForEmployee['updated_by'] = get_session_userid();
- $this->employeeModel->save($deletionDataForEmployee);
-
- $e_Data = [
- 'endorsement_id' => $endorsement_id,
- 'status' => 'complete',
- ];
- $group_key = $this->empEndorsementModel->select('group_key')->where('id', $deletionDataForEmployee['ee_id'])->first();
- $this->empEndorsementModel->where('group_key', $group_key)->set($e_Data)->update();
-
- $fetchData = [
- 'emp_code' => $emp_code,
- 'client_policy_id' => $client_policy_id,
- 'emp_name' => $emp_name,
+ foreach ($headers as $key => $value) {
+ if($excel_header[$key] != $value){
+ $data = [
+ 'status' => 'failed-5',
];
- $deletionDataForEmployeePolicy = $this->employeePolicyModel->fetchEmpEndorsementData($fetchData);
- $deletionDataForEmployeePolicy['updated_by'] = get_session_userid();
- $this->employeePolicyModel->save($deletionDataForEmployeePolicy);
+ $this->batchFileModel->where('id', $file_id)->set($data)->update();
- // $query = $this->employeePolicyModel->getLastQuery();
- // echo $query . "
";
+ $file_data = $this->getDataByFileId($file_id, 'failure');
+ $this->setPullNotification($file_data);
- } else {
-
- return 0;
+ $this->myLogger->logme('error', 'Deletion File Validation -- Upload the worng excel file');
+ return ['status' => 'error', 'message' => 'Upload the worng excel file'];
}
}
- $policy_name = $this->getPolicyNameUsingClientPolicyId($client_policy_id);
- $depositeData = [
- 'employeeIds' => $employeeIds,
- 'client_id' => $client_id,
- 'client_policy_id' => $client_policy_id,
- 'count' => $count,
- 'event' => $import_data['event_type'],
- 'policy_name' => $policy_name['policy_name'],
- ];
+ $db = \Config\Database::connect();
+
+ $sql = "
+ SELECT DISTINCT
+ a.id as endorsement_primarykey,
+ a.group_key,
+ employee_polices.id as primaryKey,
+ employees.name AS emp_name,
+ employees.emp_code AS emp_code,
+ employees.dob AS emp_dob,
+ employees.gender AS emp_gender,
+ employees.relationship AS emp_relationship,
+ 'Has Define' as emp_type,
+
+ employee_polices.basic_cover_si,
+ employee_polices.uhid as risk_id,
+ employee_polices.policy_end_date,
+ employee_polices.rata_premimum as premium,
+
+
+ deletiondata.empstatus,
+ deletiondata.changeevent,
+ deletiondata.dateofexit,
+ deletiondata.reasonforexit,
+ deletiondata.status,
+
+ DATEDIFF(employee_polices.policy_end_date, deletiondata.dateofexit) AS no_of_days,
+ ROUND((employee_polices.rata_premimum * DATEDIFF(employee_polices.policy_end_date, deletiondata.dateofexit)) / 365, 2) AS pro_rata_premium,
+ ROUND(((employee_polices.rata_premimum * DATEDIFF(employee_polices.policy_end_date, deletiondata.dateofexit)) / 365) * 0.18, 2) AS gst,
+ ROUND(((employee_polices.rata_premimum * DATEDIFF(employee_polices.policy_end_date, deletiondata.dateofexit)) / 365) + (((employee_polices.rata_premimum * DATEDIFF(employee_polices.policy_end_date, deletiondata.dateofexit)) / 365) * 0.18), 2) AS total
+ FROM
+ emp_endorsement a
+ LEFT JOIN
+ employees ON a.emp_code = employees.emp_code and a.pk = employees.id
+ LEFT JOIN
+ employee_polices ON employees.id = employee_polices.employee_id
+
+ LEFT JOIN(
+
+ select aa.emp_code, aa.new_value as 'empstatus', bb.new_value as 'changeevent', cc.new_value as 'dateofexit', dd.new_value as 'reasonforexit', ee.new_value as 'status' from
+
+ ( SELECT a1.emp_code, a1.field_name, a1.new_value from emp_endorsement as a1 where a1.field_name = 'emp_status') aa
+ left join
+ ( SELECT b1.emp_code, b1.field_name, b1.new_value from emp_endorsement as b1 where b1.field_name = 'change_event') bb on aa.emp_code = bb.emp_code
+ left join
+ ( SELECT c1.emp_code, c1.field_name, c1.new_value from emp_endorsement as c1 where c1.field_name = 'date_of_exit') cc on aa.emp_code = cc.emp_code
+ left join
+ ( SELECT d1.emp_code, d1.field_name, d1.new_value from emp_endorsement as d1 where d1.field_name = 'reason_for_exit') dd on aa.emp_code = dd.emp_code
+ left JOIN
+ ( SELECT e1.emp_code, e1.field_name, e1.new_value from emp_endorsement as e1 where e1.field_name = 'status') ee on aa.emp_code = ee.emp_code
+
+ ) as deletiondata on a.emp_code = deletiondata.emp_code
+
+ WHERE employee_polices.client_policy_id = '$client_policy_id'
+ AND employees.client_branch_id = '$client_branch_id'
+ AND a.actions = 'd'
+ AND employee_polices.is_active = 1
+ AND employee_polices.status = 'active'
+ AND employees.is_active = 1
+ AND employees.emp_status = 'active'
+ AND (a.endorsement_id IS NULL OR a.endorsement_id = '')
+ group by group_key
+ ";
+
+ $query = $db->query($sql);
+ $endorsement_data = $query->getResultArray();
+
+
+ if ($endorsement_data == null || empty($endorsement_data)) {
+
+ $data = [
+ 'status' => 'failed-1',
+ ];
+
+ $this->batchFileModel->where('id', $file_id)->set($data)->update();
+ $this->myLogger->logme('error', 'Deletion File Validation ENDORSEMENT ID already updated');
+
+ $file_data = $this->getDataByFileId($file_id, 'failure');
+ $this->setPullNotification($file_data);
+
+ return 'The list of employees provided has already been updated with the ENDORSEMENT ID, or this is not the correct file';
+ $this->myLogger->logme('error', 'Deletion File Validation ENDORSEMENT ID already updated or the uploadedfile is not correct');
+ }
+
+ $excel_data_count = count($excel_data);
+ $endorsement_data_count = count($endorsement_data);
+
+ $this->myLogger->logme('error', 'Deletion File Validation excel file count : {data}', ['data' => $excel_data_count]);
+ $this->myLogger->logme('error', 'Deletion File Validation database count : {data}', ['data' => $endorsement_data_count]);
+
+
+ $difference = $endorsement_data_count - $excel_data_count;
+
+ $status = 'in-progress';
+ if ($excel_data_count < $endorsement_data_count) {
+
+ $status = 'in-progress-partially';
+ $partially_updated_data = 'Expected : ' . $endorsement_data_count . ', ' . 'Updated : ' . $excel_data_count . ', ' . 'difference : ' . $difference;
+ $this->myLogger->logme('error', 'Deletion File Validation excel file count partially : {data}', ['data' => $partially_updated_data]);
+ }
+
+
+
+ if ($endorsement_data_count < $excel_data_count) {
+
+ $data = [
+ 'status' => 'failed-3',
+ ];
+
+ $this->batchFileModel->where('id', $file_id)->set($data)->update();
+ $this->myLogger->logme('error', 'Deletion File Validation excel file count ( {excel} ) exceeds db count ( {db} )', ['db' => $endorsement_data_count, 'excel' => $excel_data_count]);
+
+ $file_data = $this->getDataByFileId($file_id, 'failure');
+ $this->setPullNotification($file_data);
+
+ return 'The Excel record count exceeds the DB record count. excel file count : ' . $excel_data_count . ' db count : ' . $endorsement_data_count;
+ }
+
+
+ $errors = []; // Initialize an array to store errors
+ $missing_id = [];
+ $batch_list_id = [];
+
+ foreach ($endorsement_data as $key => $endorsement_value) {
+
+ $key = $key + 1;
+
+ if (!isset($excel_data[$key])) {
+ break;
+ }
+
+
+ if ($excel_data[$key][15] === null) {
+ $missing_id[$key][] = [
+ 'row' => $key,
+ 'column' => 15,
+ ];
+ }
+
+
+ if ($endorsement_value['emp_name'] != $excel_data[$key][2]) {
+ $errors[$key][] = [
+ 'row' => $key,
+ 'column' => 2,
+ 'db_data' => $endorsement_value['emp_name'],
+ 'excel_data' => $excel_data[$key][2]
+ ];
+ }
+
+ if ($endorsement_value['emp_code'] != $excel_data[$key][1]) {
+ $errors[$key][] = [
+ 'row' => $key,
+ 'column' => 1,
+ 'db_data' => $endorsement_value['emp_code'],
+ 'excel_data' => $excel_data[$key][1]
+ ];
+ }
+
+ if ($endorsement_value['emp_dob'] != $excel_data[$key][3]) {
+ $errors[$key][] = [
+ 'row' => $key,
+ 'column' => 3,
+ 'db_data' => $endorsement_value['emp_dob'],
+ 'excel_data' => $excel_data[$key][3]
+ ];
+ }
+
+ if ($endorsement_value['emp_gender'] != $excel_data[$key][4]) {
+ $errors[$key][] = [
+ 'row' => $key,
+ 'column' => 4,
+ 'db_data' => $endorsement_value['emp_gender'],
+ 'excel_data' => $excel_data[$key][4]
+ ];
+ }
+
+
+ if ($endorsement_value['emp_relationship'] != $excel_data[$key][5]) {
+ $errors[$key][] = [
+ 'row' => $key,
+ 'column' => 5,
+ 'db_data' => $endorsement_value['emp_relationship'],
+ 'excel_data' => $excel_data[$key][5]
+ ];
+ }
+
+ if ($endorsement_value['basic_cover_si'] != $excel_data[$key][6]) {
+ $errors[$key][] = [
+ 'row' => $key,
+ 'column' => 6,
+ 'db_data' => $endorsement_value['basic_cover_si'],
+ 'excel_data' => $excel_data[$key][6]
+ ];
+ }
+
+ if ($endorsement_value['dateofexit'] != $excel_data[$key][7]) {
+ $errors[$key][] = [
+ 'row' => $key,
+ 'column' => 7,
+ 'db_data' => $endorsement_value['dateofexit'],
+ 'excel_data' => $excel_data[$key][7]
+ ];
+ }
+
+ if ($endorsement_value['policy_end_date'] != $excel_data[$key][8]) {
+ $errors[$key][] = [
+ 'row' => $key,
+ 'column' => 8,
+ 'db_data' => $endorsement_value['policy_end_date'],
+ 'excel_data' => $excel_data[$key][8]
+ ];
+ }
+
+ if ($endorsement_value['no_of_days'] != $excel_data[$key][9]) {
+ $errors[$key][] = [
+ 'row' => $key,
+ 'column' => 9,
+ 'db_data' => $endorsement_value['no_of_days'],
+ 'excel_data' => $excel_data[$key][9]
+ ];
+ }
+
+
+
+ if ($endorsement_value['premium'] != $excel_data[$key][10]) {
+ $errors[$key][] = [
+ 'row' => $key,
+ 'column' => 10,
+ 'db_data' => $endorsement_value['premium'],
+ 'excel_data' => $excel_data[$key][10]
+ ];
+ }
+
+ if ($endorsement_value['pro_rata_premium'] != $excel_data[$key][11]) {
+ $errors[$key][] = [
+ 'row' => $key,
+ 'column' => 11,
+ 'db_data' => $endorsement_value['pro_rata_premium'],
+ 'excel_data' => $excel_data[$key][11]
+ ];
+ }
+
+ if ($endorsement_value['gst'] != $excel_data[$key][12]) {
+ $errors[$key][] = [
+ 'row' => $key,
+ 'column' => 12,
+ 'db_data' => $endorsement_value['gst'],
+ 'excel_data' => $excel_data[$key][12]
+ ];
+ }
+
+ $batch_list_id[] = array('emp_policy_id' =>$endorsement_value['primaryKey'], 'batch_code' => $batch_code, 'created_by' => $user_id);
+ }
+
+
+ $error_count = count($errors);
+ $json_errors = json_encode($errors);
+
+
+ $missing_id_count = count($missing_id);
+ $json_missing_id = json_encode($missing_id);
+
+ // dd($error_count, $missing_id_count, $json_errors, $json_missing_id, $batch_list_id);
+
+ if ($missing_id_count > 0) {
+
+ $data = [
+
+ 'count' => $endorsement_data_count,
+ 'error_data' => $json_missing_id,
+ 'status' => 'failed',
+ ];
+
+ $this->batchFileModel->where('id', $file_id)->set($data)->update();
+
+ $file_data = $this->getDataByFileId($file_id, 'failure');
+ $this->setPullNotification($file_data);
+
+ return 'The ENDORSEMENT ID column is either partially or entirely empty.';
+ }
+
+
+ if ($error_count > 0) {
+
+ $data = [
+ 'count' => $endorsement_data_count,
+ 'error_data' => $json_errors,
+ 'status' => 'failed',
+ ];
+
+ $this->batchFileModel->where('id', $file_id)->set($data)->update();
+
+ $file_data = $this->getDataByFileId($file_id, 'failure');
+ $this->setPullNotification($file_data);
+
+ return 'Deletion File Validation Failed';
+
+ } else {
+
+ $data = [
+ 'count' => $endorsement_data_count,
+ 'status' => $status,
+ 'error_data' => $partially_updated_data ?? null,
+ ];
+
+ $this->batchFileModel->where('id', $file_id)->set($data)->update();
+ $insert = $this->batchListModel->insertBatch($batch_list_id);
+
+
+ $job_details = new Jobs();
+ $r = Jobs::addJob(['job_name' => 'importDeletionUpdateEndorsementID', 'payload' => ['file_id' => $file_id]]);
+
+ // $this->importDeletionUpdateEndorsementID(['file_id' => $file_id]);
+
+ return 'Deletion File Validation ENDORSEMENT ID validated the file Successfully';
+ }
- $this->cashDepositCalculationForDeletion($depositeData);
- return 1;
}
+ public function importDeletionUpdateEndorsementID($params)
+ {
+
+ $this->myLogger->logme('error', 'Deletion Update Endorsement ID -- Function called');
+
+ $file_id = $params['file_id'];
+ $file = $this->batchFileModel->find($file_id);
+ if (!$file) {
+
+ $data = [
+ 'status' => 'failed-4',
+ ];
+
+ $this->batchFileModel->where('id', $file_id)->set($data)->update();
+ $this->myLogger->logme('error', 'Deletion Update Endorsement ID -- The Physical file not found -- File id : {data}', ['data' => $file_id]);
+
+ $file_data = $this->getDataByFileId($file_id, 'failure');
+ $this->setPullNotification($file_data);
+
+ return 'Deletion Update Endorsement ID -- The Physical file not found'; // Return error code if file not found
+ }
+
+ $client_id = $file['client_id'];
+ $client_policy_id = $file['client_policy_id'];
+ $client_branch_id = $file['client_branch_id'];
+ $status = $file['status'];
+ $batch_code = $file['batch_code'];
+ $user_id = $file['created_by'];
+
+
+ $status_val = 'success';
+ if ($status == 'in-progress-partially') {
+
+ $status_val = 'partially success';
+ }
+
+ $this->myLogger->logme('error', 'Deletion Update Endorsement ID -- file name : {data}', ['data' => $file['file_name']]);
+
+ $file_name_with_path = WRITEPATH . "/uploads/import_excel/" . $file['file_name'];
+ $excel_data = $this->readExcelFileToArray($file_name_with_path);
+ unset($excel_data[0]);
+ array_pop($excel_data);
+
+ $emp_count = count($excel_data); //excel file count
+
+ $employees_table_data = [];
+ $emp_endorsement_table_data = [];
+ $employee_policy_table_data = [];
+ $employee_policy_table_primaryKey = [];
+
+ $totals = 0;
+
+
+ foreach ($excel_data as $key => $value) {
+
+ $emp_name = $value[2]; //employee name
+ $emp_code = $value[1]; //employee code
+ $totals = $totals + $value[13];
+
+
+ $fetch_data = [
+ 'client_policy_id' => $client_policy_id,
+ 'client_branch_id' => $client_branch_id,
+ 'emp_name' => $emp_name,
+ 'emp_code' => $emp_code
+ ];
+ $result = $this->employeePolicyModel->fetchEmpEndorsementData($fetch_data);
+
+ // dd($result['emp_endorsement_primarykey']);
+
+ if (isset($result['emp_endorsement_primarykey']) && $result['emp_endorsement_primarykey'] !== null) {
+
+ $employee_policy_table_primaryKey[] = $result['emp_policy_primarykey']; //for cash deposite
+ $employee_policy_table_data[] = array('id' => $result['emp_policy_primarykey'], 'date_of_exit' => $result['date_of_exit'], 'reason_for_exit' => $result['reason_for_exit'], 'status' => $result['status'], 'is_active' => 0);
+ $employees_table_data[] = array('id' => $result['employees_primarykey'], 'emp_status' => $result['status'], 'is_active' => 0);
+ $emp_endorsement_table_data[] = array('id' => $result['emp_endorsement_primarykey'], 'group_key' => $result['group_key'], 'endorsement_id' => $value[15], 'status' => 'complete');
+ }
+
+ }
+
+ $rounded_totals = round($totals, 2);
+
+ // dd($employees_table_data, $emp_endorsement_table_data, $employee_policy_table_data, $employee_policy_table_primaryKey, $totals, $emp_count);
+
+
+ // Check if $employees_table_data is null or empty
+ if (empty($employees_table_data)) {
+ return ['status' => 'error', 'message' => 'Employees table data is empty or null.'];
+ }
+
+ // Check if $employee_policy_table_data is null or empty
+ if (empty($employee_policy_table_data)) {
+ return ['status' => 'error', 'message' => 'Employee policy table data is empty or null.'];
+ }
+
+ // Check if $emp_endorsement_table_data is null or empty
+ if (empty($emp_endorsement_table_data)) {
+ return ['status' => 'error', 'message' => 'Employee endorsement table data is empty or null.'];
+ }
+
+ $this->employeeModel->updateBatch($employees_table_data, 'id');
+ $this->employeePolicyModel->updateBatch($employee_policy_table_data, 'id');
+ $this->employeePolicyModel->bulkUpdateForEndorsement($emp_endorsement_table_data);
+
+ // Update batch file status and amount
+ $this->batchFileModel->update($file_id, [
+ 'count' => $emp_count,
+ 'status' => $status_val,
+ 'amount' => $rounded_totals,
+ ]);
+
+
+ $this->myLogger->logme('error', 'Deletion Update Endorsement ID -- Employee count : {data}', ['data' => $emp_count]);
+ $this->myLogger->logme('error', 'Deletion Update Endorsement ID -- Batch File status : {data}', ['data' => $status_val]);
+
+
+ $file_data = $this->getDataByFileId($file_id, 'success');
+ $this->setPullNotification($file_data);
+
+ //call the cash deposite function
+
+ $policy_name = $this->getPolicyNameUsingClientPolicyId($client_policy_id);
+
+ $job_details = new Jobs();
+ $r = Jobs::addJob(['job_name' => 'cashDepositCalculationForDeletion', 'payload' => [
+ 'employeeIds' => $employee_policy_table_primaryKey,
+ 'client_id' => $client_id,
+ 'client_policy_id' => $client_policy_id,
+ 'client_branch_id' => $client_branch_id,
+ 'count' => $emp_count,
+ 'event' => $file['event_type'],
+ 'policy_name' => $policy_name['policy_name'],
+ 'user_id' => $user_id,
+ ]]);
+
+ return 'Deletion Update Endorsement ID -- ' . $status_val . '-- Updated Count : ' . $emp_count;
+ }
+
+
+
+
+
+ //Endorsement Addition and Dependent Addition
+
+
+ public function AdditionAndDependentAddition($params)
+ {
+
+ $this->myLogger->logme('error', 'Addition And Dependent Addition File Validation -- Function called');
+
+ $file_id = $params['file_id'];
+ $file = $this->batchFileModel->where('id', $file_id)->first();
+
+ $client_id = $file['client_id'];
+ $client_policy_id = $file['client_policy_id'];
+ $client_branch_id = $file['client_branch_id'];
+ $batch_code = $file['batch_code'];
+ $user_id = $file['created_by'];
+
+ $file_name_with_path = WRITEPATH . "/uploads/import_excel/" . $file['file_name'];
+
+ if (!file_exists($file_name_with_path)) {
+
+ $this->myLogger->logme('error', 'Addition And Dependent Addition File Validation -- The Physical file not found');
+ $this->myLogger->logme('error', 'Addition And Dependent Addition File Validation -- File Name : {data}', ['data' => $file['file_name']]);
+ $this->myLogger->logme('error', 'Addition And Dependent Addition File Validation -- File Path : {data}', ['data' => $file_name_with_path]);
+
+ return 'The Physical file not found';
+ }
+
+ $excel_data = $this->readExcelFileToArray($file_name_with_path);
+ unset($excel_data[0]);
+
+
+ $endorsement_data = $this->empEndorsementModel
+ ->select("
+ emp_endorsement.id,
+ emp_endorsement.pk,
+ emp_endorsement.emp_code,
+ emp_endorsement.endorsement_id,
+ emp_endorsement.old_value,
+ emp_endorsement.new_value,
+ emp_endorsement.field_name,
+ emp_endorsement.remarks,
+ emp_endorsement.actions,
+ employees.id AS primaryKey,
+ employees.name AS emp_name,
+ employees.dob AS emp_dob,
+ employees.gender AS emp_gender,
+ employees.client_id AS emp_client_id,
+ 'Has Define' AS emp_type,
+ employee_polices.uhid,
+ employees.relationship_code
+ ")
+ ->join("employees", "employees.id = emp_endorsement.pk", "left")
+ ->join("employee_polices", "employees.id = employee_polices.employee_id", "left")
+ ->where("employees.client_id", $client_id)
+ ->where("employee_polices.client_policy_id", $client_policy_id)
+ ->where("employees.client_branch_id", $client_branch_id)
+ ->where("employees.is_active", 1)
+ ->where("employees.emp_status", "active")
+ ->where("emp_endorsement.actions", "c")
+ ->where("(emp_endorsement.endorsement_id IS NULL OR emp_endorsement.endorsement_id = '')")
+ ->findAll();
+
+
+
+ // dd($endorsement_data, $excel_data);
+
+
+ if ($endorsement_data == null || empty($endorsement_data)) {
+
+ $data = [
+ 'status' => 'failed-1',
+ ];
+
+ $this->batchFileModel->where('id', $file_id)->set($data)->update();
+ $this->myLogger->logme('error', 'correctionFileValidation ENDORSEMENT ID already updated');
+
+ $file_data = $this->getDataByFileId($file_id, 'failure');
+ $this->setPullNotification($file_data);
+
+ return 'The list of employees provided has already been updated with the ENDORSEMENT ID, or this is not the correct file';
+
+ $this->myLogger->logme('error', 'Addition And Dependent Addition File Validation ENDORSEMENT ID already updated or the uploadedfile is not correct');
+ }
+
+ $excel_data_count = count($excel_data);
+ $endorsement_data_count = count($endorsement_data);
+
+ $this->myLogger->logme('error', 'Addition And Dependent Addition File Validation excel file count : {data}', ['data' => $excel_data_count]);
+ $this->myLogger->logme('error', 'Addition And Dependent Addition File Validation database count : {data}', ['data' => $endorsement_data_count]);
+
+
+ $difference = $endorsement_data_count - $excel_data_count;
+
+ $status = 'in-progress';
+ if ($excel_data_count < $endorsement_data_count) {
+
+ $status = 'in-progress-partially';
+ $partially_updated_data = 'Expected : ' . $endorsement_data_count . ', ' . 'Updated : ' . $excel_data_count . ', ' . 'difference : ' . $difference;
+ $this->myLogger->logme('error', 'Addition And Dependent Addition File Validation excel file count partially : {data}', ['data' => $partially_updated_data]);
+ }
+
+
+
+ if ($endorsement_data_count < $excel_data_count) {
+
+ $data = [
+ 'status' => 'failed-3',
+ ];
+
+ $this->batchFileModel->where('id', $file_id)->set($data)->update();
+ $this->myLogger->logme('error', 'Addition And Dependent Addition File Validation excel file count ( {excel} ) exceeds db count ( {db} )', ['db' => $endorsement_data_count, 'excel' => $excel_data_count]);
+
+ $file_data = $this->getDataByFileId($file_id, 'failure');
+ $this->setPullNotification($file_data);
+
+ return 'The Excel record count exceeds the DB record count. excel file count : ' . $excel_data_count . 'db count : ' . $endorsement_data_count;
+ }
+
+
+ $errors = []; // Initialize an array to store errors
+ $missing_id = [];
+ $batch_list_id = [];
+
+ foreach ($endorsement_data as $key => $endorsement_value) {
+
+ $key = $key + 1;
+
+ if (!isset($excel_data[$key])) {
+ break;
+ }
+
+
+ if ($excel_data[$key][10] === null) {
+ $missing_id[$key][] = [
+ 'row' => $key,
+ 'column' => 10,
+ ];
+ }
+
+
+ if ($endorsement_value['emp_name'] != $excel_data[$key][2]) {
+ $errors[$key][] = [
+ 'row' => $key,
+ 'column' => 2,
+ 'db_data' => $endorsement_value['emp_name'],
+ 'excel_data' => $excel_data[$key][2]
+ ];
+ }
+
+ if ($endorsement_value['emp_code'] != $excel_data[$key][0]) {
+ $errors[$key][] = [
+ 'row' => $key,
+ 'column' => 0,
+ 'db_data' => $endorsement_value['emp_code'],
+ 'excel_data' => $excel_data[$key][0]
+ ];
+ }
+
+ if ($endorsement_value['emp_dob'] != $excel_data[$key][5]) {
+ $errors[$key][] = [
+ 'row' => $key,
+ 'column' => 5,
+ 'db_data' => $endorsement_value['emp_dob'],
+ 'excel_data' => $excel_data[$key][5]
+ ];
+ }
+
+ if ($endorsement_value['emp_gender'] != $excel_data[$key][6]) {
+ $errors[$key][] = [
+ 'row' => $key,
+ 'column' => 6,
+ 'db_data' => $endorsement_value['emp_gender'],
+ 'excel_data' => $excel_data[$key][6]
+ ];
+ }
+
+ if ($endorsement_value['old_value'] != $excel_data[$key][7]) {
+ $errors[$key][] = [
+ 'row' => $key,
+ 'column' => 7,
+ 'db_data' => $endorsement_value['old_value'],
+ 'excel_data' => $excel_data[$key][7]
+ ];
+ }
+
+ if ($endorsement_value['new_value'] != $excel_data[$key][8]) {
+ $errors[$key][] = [
+ 'row' => $key,
+ 'column' => 8,
+ 'db_data' => $endorsement_value['new_value'],
+ 'excel_data' => $excel_data[$key][8]
+ ];
+ }
+
+
+
+ if ($endorsement_value['uhid'] != $excel_data[$key][1]) {
+ $errors[$key][] = [
+ 'row' => $key,
+ 'column' => 1,
+ 'db_data' => $endorsement_value['uhid'],
+ 'excel_data' => $excel_data[$key][1]
+ ];
+ }
+
+ $batch_list_id[] = $endorsement_value['primaryKey'];
+ }
+
+
+ $error_count = count($errors);
+ $json_errors = json_encode($errors);
+
+
+ $missing_id_count = count($missing_id);
+ $json_missing_id = json_encode($missing_id);
+
+ // dd($error_count, $missing_id_count, $json_errors, $json_missing_id, $batch_list_id);
+
+
+ if ($missing_id_count > 0) {
+
+ $data = [
+
+ 'count' => $endorsement_data_count,
+ 'error_data' => $json_missing_id,
+ 'status' => 'failed',
+ ];
+
+ $this->batchFileModel->where('id', $file_id)->set($data)->update();
+
+ $file_data = $this->getDataByFileId($file_id, 'failure');
+ $this->setPullNotification($file_data);
+
+ return 'The ENDORSEMENT ID column is either partially or entirely empty.';
+
+ }
+
+
+ if ($error_count > 0) {
+
+ $data = [
+
+ 'count' => $endorsement_data_count,
+ 'error_data' => $json_errors,
+ 'status' => 'failed',
+ ];
+
+ $this->batchFileModel->where('id', $file_id)->set($data)->update();
+ return 'Correction Validation Failed';
+
+ } else {
+
+ $data = [
+ 'count' => $endorsement_data_count,
+ 'status' => $status,
+ 'error_data' => $partially_updated_data ?? null,
+ ];
+
+ $this->batchFileModel->where('id', $file_id)->set($data)->update();
+
+
+ foreach ($batch_list_id as $key => $value) {
+
+ $data = [
+ 'emp_policy_id' => $value,
+ 'batch_code' => $batch_code,
+ 'created_by' => $user_id,
+ ];
+
+ $insert = $this->batchListModel->insert($data);
+ }
+
+
+ $job_details = new Jobs();
+ $r = Jobs::addJob(['job_name' => 'importAdditionAndDependentAdditionUpdateEndorsementID','payload' => ['file_id' => $file_id]]);
+
+ // $this->importAdditionAndDependentAdditionUpdateEndorsementID(['file_id' => $file_id]);
+
+ return 'Correction Validation Success';
+ }
+ }
+
+
+ public function importAdditionAndDependentAdditionUpdateEndorsementID($params){
+
+ $this->myLogger->logme('error', 'importCorrectionUpdateEndorsementID called');
+
+ $file_id = $params['file_id'];
+ $file = $this->batchFileModel->find($file_id);
+ if (!$file) {
+
+ $data = [
+ 'status' => 'failed-4',
+ ];
+
+ $this->batchFileModel->where('id', $file_id)->set($data)->update();
+ $this->myLogger->logme('error', 'importCorrectionUpdateEndorsementID the Physical file not found - file id : {data}', ['data' => $file_id]);
+
+ $file_data = $this->getDataByFileId($file_id, 'failure');
+ $this->setPullNotification($file_data);
+
+ return 'importCorrectionUpdateEndorsementID the Physical file not found'; // Return error code if file not found
+ }
+
+ $client_id = $file['client_id'];
+ $client_policy_id = $file['client_policy_id'];
+ $client_branch_id = $file['client_branch_id'];
+ $insurer_or_tpa = $file['insurer_or_tpa'];
+ $status = $file['status'];
+ $batch_code = $file['batch_code'];
+ $user_id = $file['created_by'];
+
+
+ $status_val = 'success';
+ if ($status == 'in-progress-partially') {
+
+ $status_val = 'partially success';
+ }
+
+ $this->myLogger->logme('error', 'importCorrectionUpdateEndorsementID file name : {data}', ['data'=> $file['file_name']]);
+
+ $file_name_with_path = WRITEPATH . "/uploads/import_excel/" . $file['file_name'];
+ $excel_data = $this->readExcelFileToArray($file_name_with_path);
+ unset($excel_data[0]);
+
+ $emp_ids = [];
+ $emp_details = [];
+ $endorsement_id = [];
+ $endorsement_details = [];
+
+ $emp_count = count($excel_data);
+ $db = \Config\Database::connect();
+
+
+ foreach ($excel_data as $key => $value) {
+
+ $emp_code = $value[0];
+ $old_value = $value[7];
+ $endorsement_id[] = $value[10];
+ $uhid = $value[1];
+
+
+ $result = $this->empEndorsementModel
+ ->select('emp_endorsement.*, employees.id as emp_id')
+ ->join('employees', 'employees.id = emp_endorsement.pk')
+ ->join('employee_polices', 'employee_polices.employee_id = employees.id')
+ ->where('employees.emp_code', $emp_code)
+ ->where('employees.client_id', $client_id)
+ ->where('employees.client_branch_id', $client_branch_id)
+ ->where('employee_polices.client_policy_id', $client_policy_id)
+ ->where('employee_polices.uhid', $uhid)
+ ->where('emp_endorsement.old_value', $old_value)
+
+ ->where('employee_polices.is_active', 1)
+ ->where('employee_polices.status', 'active')
+ ->where('employees.is_active', 1)
+ ->where('employees.emp_status', 'active')
+ ->first();
+
+ if (isset($result['id']) && $result['id'] !== null) {
+
+ // return $result;
+ $emp_details[] = array('id' => $result['emp_id'], $result['field_name'] => $value[8]);
+ $endorsement_details[] = array('group_key' => $result['group_key'], 'id' => $result['id'], 'endorsement_id' => $value[10], 'status' => 'complete');
+ }
+
+ }
+
+ // return [$emp_details, $endorsement_details];
+
+ $this->empEndorsementModel->updateBatch($endorsement_details, 'group_key');
+ $this->employeePolicyModel->bulkUpdateForCorrection($emp_details);
+
+ // Update batch file status and amount
+ $this->batchFileModel->update($file_id, [
+ 'count' => $emp_count,
+ 'status' => $status_val,
+ ]);
+
+
+ $this->myLogger->logme('error', 'importCorrectionUpdateEndorsementID employee count : {data}', ['data'=> $emp_count]);
+ $this->myLogger->logme('error', 'importCorrectionUpdateEndorsementID batch file status : {data}', ['data'=> $status_val]);
+
+
+ $file_data = $this->getDataByFileId($file_id, 'success');
+ $this->setPullNotification($file_data);
+
+
+ return 'Import Correction Updated '. $status_val . '- Updated Count : ' . $emp_count;
+
+ }
+
/**
* The below functions are Calculates and records cash deposits for employee policies at inception.
@@ -1728,7 +3165,7 @@ class EmpDataServiceController extends BaseController
")->getRow();
$insurer_id = $this->clientPolicyModel->where('id', $arrayData['client_policy_id'])->first();
- $description = 'The following amount of Rs. ' . $amount->total_sum . '/- has been debited for the ' . $arrayData['count'] . ' employees at ' . remove_underscore_capitalize_first_letter($arrayData['event']) . ' to ' . remove_underscore_capitalize_first_letter($arrayData['policy_name']) . '.';
+ $description = 'The following amount of Rs. ' . round($amount->total_sum, 2) . '/- has been debited for the ' . $arrayData['count'] . ' employees at ' . remove_underscore_capitalize_first_letter($arrayData['event']) . ' to ' . remove_underscore_capitalize_first_letter($arrayData['policy_name']) . '.';
if(get_session_userid() == null){
@@ -1758,18 +3195,19 @@ class EmpDataServiceController extends BaseController
public function cashDepositCalculationForSIEnhancement($arrayData)
- {
+ {
+ // return $arrayData;
+
if (!empty($arrayData)) {
$amount = $this->employeePolicyModel->query("
- SELECT
- SUM(ROUND((employee_polices.premium * DATEDIFF(employee_polices.policy_end_date, employee_polices.si_enhancement_date)) / 365, 2) +
- ROUND(((employee_polices.premium * DATEDIFF(employee_polices.policy_end_date, employee_polices.si_enhancement_date)) / 365) * 0.18, 2)) AS total_sum
+ SELECT SUM(rata_premimum + gst) AS total_sum
FROM employee_polices
WHERE id IN (" . implode(',', $arrayData['employeeIds']) . ")
- ")->getRow();
+ ")->getRow();
+
$insurer_id = $this->clientPolicyModel->where('id', $arrayData['client_policy_id'])->first();
- $description = 'The following amount of ' . $amount->total_sum . ' has been credited for the ' . $arrayData['count'] . ' employees at ' . remove_underscore_capitalize_first_letter($arrayData['event']) . ' to ' . remove_underscore_capitalize_first_letter($arrayData['policy_name']) . '.';
+ $description = 'The following amount of ' . round($amount->total_sum, 2) . ' has been credited for the ' . $arrayData['count'] . ' employees at ' . remove_underscore_capitalize_first_letter($arrayData['event']) . ' to ' . remove_underscore_capitalize_first_letter($arrayData['policy_name']) . '.';
$data = [
@@ -1779,11 +3217,12 @@ class EmpDataServiceController extends BaseController
'insurer_id' => $insurer_id['insurer_id'],
'description' => $description,
'transaction_type' => 'Debit',
- 'updated_by' => get_session_userid(),
+ 'updated_by' => $arrayData['user_id'],
'is_active' => 1,
];
- $response = DepositHelper::saveDeposit($data, get_session_userid());
- return true;
+ $response = DepositHelper::saveDeposit($data, $arrayData['user_id']);
+ $msg = "SI Enhancement Cash Deposite Updated Successfully -- " . $description;
+ return [$msg, $response];
// print_r($response);
// $query = $this->employeePolicyModel->getLastQuery();
// echo $query . "
";
@@ -1802,15 +3241,13 @@ class EmpDataServiceController extends BaseController
// echo '';
// print_r($arrayData); die;
$amount = $this->employeePolicyModel->query("
- SELECT
- SUM(ROUND((employee_polices.premium * DATEDIFF(employee_polices.policy_end_date, employee_polices.date_of_exit)) / 365, 2) +
- ROUND(((employee_polices.premium * DATEDIFF(employee_polices.policy_end_date, employee_polices.date_of_exit)) / 365) * 0.18, 2)) AS total_sum
- FROM employee_polices
- WHERE id IN (" . implode(',', $arrayData['employeeIds']) . ")
+ SELECT SUM(rata_premimum + gst) AS total_sum
+ FROM employee_polices
+ WHERE id IN (" . implode(',', $arrayData['employeeIds']) . ")
")->getRow();
$insurer_id = $this->clientPolicyModel->where('id', $arrayData['client_policy_id'])->first();
- $description = 'The following amount of ' . $amount->total_sum . ' has been credited for the ' . $arrayData['count'] . ' employees at ' . remove_underscore_capitalize_first_letter($arrayData['event']) . ' to ' . remove_underscore_capitalize_first_letter($arrayData['policy_name']) . '.';
+ $description = 'The following amount of ' . round($amount->total_sum, 2) . ' has been credited for the ' . $arrayData['count'] . ' employees at ' . remove_underscore_capitalize_first_letter($arrayData['event']) . ' to ' . remove_underscore_capitalize_first_letter($arrayData['policy_name']) . '.';
$data = [
@@ -1820,10 +3257,13 @@ class EmpDataServiceController extends BaseController
'insurer_id' => $insurer_id['insurer_id'],
'description' => $description,
'transaction_type' => 'Credit',
- 'updated_by' => get_session_userid(),
+ 'updated_by' => $arrayData['user_id'],
'is_active' => 1,
];
- $response = DepositHelper::saveDeposit($data, get_session_userid());
+ $response = DepositHelper::saveDeposit($data, $arrayData['user_id']);
+ $msg = "Deletion Cash Deposite Updated Successfully -- " . $description;
+ return [$msg, $response];
+
return true;
// print_r($response);
// $query = $this->employeePolicyModel->getLastQuery();
@@ -2173,15 +3613,26 @@ class EmpDataServiceController extends BaseController
public function readExcelFileToArray($path)
{
-
$spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($path);
$sheet = $spreadsheet->getActiveSheet();
-
+
$highestRowAndColumn = $sheet->getHighestRowAndColumn();
$excel_data = $sheet->rangeToArray('A1:' . $highestRowAndColumn['column'] . $highestRowAndColumn['row']);
-
- return $excel_data;
+
+ // Filter out empty or null rows
+ $filtered_data = array_filter($excel_data, function($row) {
+ // Check if all cells in the row are empty or null
+ foreach ($row as $cell) {
+ if (!is_null($cell) && $cell !== '') {
+ return true;
+ }
+ }
+ return false;
+ });
+
+ return $filtered_data;
}
+
public function removeOldExportInfoFromBatchFile($params){
@@ -2205,7 +3656,6 @@ class EmpDataServiceController extends BaseController
$id = $batch_data['id'];
$batch_code = $batch_data['batch_code'];
-
$this->batchFileModel->where('id', $id)->delete();
$this->batchListModel->where('batch_code', $batch_code)->delete();
@@ -2218,9 +3668,10 @@ class EmpDataServiceController extends BaseController
public function getDataByFileId($file_id, $status = 'success'){
$data = $this->batchFileModel
- ->select('batch_files.*, clients.client_name, clients.short_name, policies.name as policy_name')
+ ->select('batch_files.*, clients.client_name, clients.short_name, policies.name as policy_name, client_branch.branch_name')
->join('clients', 'clients.id = batch_files.client_id')
->join('client_policy', 'client_policy.id = batch_files.client_policy_id')
+ ->join('client_branch', 'client_branch.id = batch_files.client_branch_id')
->join('policies', 'policies.id = client_policy.policy_id')
->where('batch_files.id', $file_id)
->first();
@@ -2228,12 +3679,12 @@ class EmpDataServiceController extends BaseController
if($status == 'success'){
- $msg_txt = $data['short_name'] . ' - ' . $data['policy_name'] . ' - ' . $data['event_type'] . ' - ' . $data['actions'] . ' - ' . $data['insurer_or_tpa'];
+ $msg_txt = $data['client_name'] . '( ' . $data['branch_name'] . ' )' . ' - ' . $data['policy_name'] . ' - ' . $data['event_type'] . ' - ' . $data['actions'] . ' - ' . $data['insurer_or_tpa'];
$msg_title = 'File Upload Success';
}else if ($status == 'failure'){
- $msg_txt = $data['short_name'] . ' - ' . $data['policy_name'] . ' - ' . $data['event_type'] . ' - ' . $data['actions'] . ' - ' . $data['insurer_or_tpa'];
+ $msg_txt = $data['client_name'] . '( ' . $data['branch_name'] . ' )' . ' - ' . $data['policy_name'] . ' - ' . $data['event_type'] . ' - ' . $data['actions'] . ' - ' . $data['insurer_or_tpa'];
$msg_title = 'File Upload Failure';
}
diff --git a/app/Controllers/EmployeeController.php b/app/Controllers/EmployeeController.php
index f64d48a3..61c66278 100644
--- a/app/Controllers/EmployeeController.php
+++ b/app/Controllers/EmployeeController.php
@@ -76,7 +76,13 @@ class EmployeeController extends AdminController
$data['status'] = ['draft' => 'Draft', 'active' => 'Active', 'inactive' => 'In-Active', 'expired' => 'Expired'];
if (count($this->request->getGet())) {
$filterData = $this->request->getGet();
- $data['employees'] = $this->employeePolicyModel->getEmployeePolicy(client_id: $filterData['client_id'], policy_id: $filterData['policy_id'], status: $filterData['status']);
+ $data['employees'] = $this->employeePolicyModel->getEmployeePolicy(
+ client_id: $filterData['client_id'],
+ policy_id: $filterData['policy_id'],
+ status: $filterData['status'],
+ branch_id: $filterData['branch_id']
+ );
+
$data['getData'] = $filterData;
}
@@ -89,6 +95,8 @@ class EmployeeController extends AdminController
//echo $this->request->isAJAX();die();
$result = $this->clientModel->clientsWithPolicies();
+ // dd($result);
+
// print_r($result);die();
if (!count($result)) {
return $this->respond(['dataStatus' => false, 'code' => 404, 'message' => 'no data found'], 200);
@@ -172,16 +180,31 @@ class EmployeeController extends AdminController
'emplist' => [
'uploaded[emplist]',
'mime_in[emplist,application/vnd.ms-excel,application/vnd,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.oasis.opendocument.spreadsheet]',
- 'max_size[emplist,8192]',
+ 'max_size[emplist,16384]',
],
]);
+
+ if ($validated)
+ {
+ $avatar = $this->request->getFile('emplist');
+ if (!$avatar) {
+ $this->myLogger->logme("error", 'File not found');
+ return $this->respond(['dataStatus' => false, 'code' => 400, 'message' => 'File not found'], 400);
+ }
- if ($validated) {
- $avatar = $this->request->getFile('emplist');
- $is_moved = $avatar->move(WRITEPATH . 'uploads/excel/');
- $filename = $avatar->getName();
+ $is_moved = $avatar->move(WRITEPATH . 'uploads/excel/');
+ if ($is_moved) {
+ $filename = $avatar->getName();
+ // Handle successful upload, e.g., log success or further processing
+ $this->myLogger->logme("error", 'File move successful');
+
+ } else {
+ $this->myLogger->logme("error", 'File move failed');
+ return $this->respond(['dataStatus' => false, 'code' => 500, 'message' => 'File move failed'], 500);
+ }
} else {
- return $this->respond(['dataStatus' => false, 'code' => 404, 'message' => 'invalid file'], 200);
+ $this->myLogger->logme("error", 'Upload failed Invalid file');
+ return $this->respond(['dataStatus' => false, 'code' => 404, 'message' => 'Invalid file'], 404);
}
//process post variable entry in file table
@@ -190,10 +213,11 @@ class EmployeeController extends AdminController
$client_id = $this->request->getPost('client_id');
$policy_id = $this->request->getPost('policy_id');
+ $branch_id = $this->request->getPost('branch_id');
$action = $this->request->getPost('upload-action-type');
$status = 'inprogress';
- $file_id = $this->fileModel->insert(['file_name' => $filename, 'client_id' => $client_id, 'policy_id' => $policy_id, 'created_by' => $loggedInUserID, 'status' => $status, 'action' => $action]); //here field policy_id have client_policy_id and not policy id from policy master
+ $file_id = $this->fileModel->insert(['file_name' => $filename, 'client_id' => $client_id, 'policy_id' => $policy_id, 'created_by' => $loggedInUserID, 'status' => $status, 'action' => $action, 'client_branch_id' => $branch_id]); //here field policy_id have client_policy_id and not policy id from policy master
$this->myLogger->logme("error", '{file_id} uploaded success', ['file_id' => $file_id]);
//start validation process
@@ -232,6 +256,7 @@ class EmployeeController extends AdminController
'up.first_name',
'pm.name as policy_name',
'c.short_name',
+ 'cb.branch_name',
'cp.id as client_policy_id',
'(SELECT COUNT(*)
FROM employees e
@@ -244,6 +269,7 @@ class EmployeeController extends AdminController
])
->join('user_profiles up', 'files.created_by = up.id')
->join('client_policy cp', 'files.policy_id = cp.id', 'left')
+ ->join('client_branch cb', 'files.client_branch_id = cb.id', 'left')
->join('policies pm', 'cp.policy_id = pm.id', 'left')
->join('clients c', 'files.client_id = c.id and files.client_id = cp.client_id', 'left')
->where('files.created_by', get_session_userid())
@@ -251,8 +277,9 @@ class EmployeeController extends AdminController
->findAll();
// dd($data['fileList']);
- $data['batch_list'] = $this->batchFileModel->select('batch_files.*, policies.name as policy_name, clients.short_name as client_short_name')
+ $data['batch_list'] = $this->batchFileModel->select('batch_files.*, policies.name as policy_name, clients.short_name as client_short_name, client_branch.branch_name')
->join('client_policy', 'client_policy.id = batch_files.client_policy_id')
+ ->join('client_branch', 'client_branch.id = batch_files.client_branch_id')
->join('policies', 'policies.id = client_policy.policy_id')
->join('clients', 'clients.id = client_policy.client_id')
->orderBy('batch_files.id', 'desc')
@@ -346,42 +373,47 @@ class EmployeeController extends AdminController
public function importExport()
{
- $this->myLogger->logme('error', 'importExport function called');
+ $this->myLogger->logme('error', 'Import Export -- Function called');
$empDataServiceController = new EmpDataServiceController();
$client_id = $this->request->getPost('client_id');
$client_policy_id = $this->request->getPost('client_policy_id');
+ $client_branch_id = $this->request->getPost('client_branch_id');
$insurer_or_tpa = $this->request->getPost('insurer_or_tpa');
$event_type = $this->request->getPost('event_type');
$actions = $this->request->getPost('action_type');
$client_data = $this->clientModel->where('id', $client_id)->first();
- $policy_name = $this->clientPolicyModel->select('policies.name')->join('policies', 'policies.id = client_policy.policy_id')->where('client_policy.id', $client_policy_id)->first();
- $file_name = generate_filename($client_data['short_name'], $event_type, $actions, $insurer_or_tpa, $policy_name['name']);
+ $policy_name_and_branch_name = $this->clientPolicyModel->select('policies.name, client_branch.branch_code')
+ ->join('client_branch', 'client_branch.id = client_policy.client_branch_id')
+ ->join('policies', 'policies.id = client_policy.policy_id')
+ ->where('client_policy.id', $client_policy_id)
+ ->first();
+ $file_name = generate_filename($client_data['short_name'], $event_type, $actions, $insurer_or_tpa, $policy_name_and_branch_name['name'], $policy_name_and_branch_name['branch_code']);
$batch_data = [
'client_id' => $client_id,
'client_policy_id' => $client_policy_id,
+ 'client_branch_id' => $client_branch_id,
'insurer_or_tpa' => $insurer_or_tpa,
'event_type' => $event_type,
'actions' => $actions,
'file_name' => $file_name,
];
- // $event_type = 'si_enhancement';
if ($actions == 'export') {
if ($event_type == 'inception' || $event_type == 'addition' || $event_type == 'dependent_addition') {
$return = $empDataServiceController->generateExcelForAdditionandInception($batch_data);
-
- if($return == 0){
+
+ if ($return == 0) {
session()->setFlashdata('error', "Insufficient deposit amount.");
return redirect()->to(base_url('employee/upload'));
- }
-
+ }
+
if (!$return) {
if ($insurer_or_tpa == 'tpa') {
@@ -391,7 +423,6 @@ class EmployeeController extends AdminController
session()->setFlashdata('error', "No data was found for this action. The UHID has already been updated.");
return redirect()->to(base_url('employee/upload'));
}
-
} else {
$this->myLogger->logme('error', 'Successfully exported Excel file in {data}.', ['data' => $event_type]);
}
@@ -407,6 +438,13 @@ class EmployeeController extends AdminController
} else if ($event_type == 'si_enhancement') {
$return = $empDataServiceController->generateExcelForSIEnhancement($batch_data);
+
+ if ($return == 0) {
+
+ session()->setFlashdata('error', "Insufficient deposit amount.");
+ return redirect()->to(base_url('employee/upload'));
+ }
+
if (!$return) {
session()->setFlashdata('error', 'No data found about this action');
return redirect()->to(base_url('employee/upload'));
@@ -426,101 +464,90 @@ class EmployeeController extends AdminController
} else if ($actions == 'import') {
$batch_data['file'] = $this->request->getFile('import_file_data');
-
+ $file = $this->request->getFile('import_file_data');
+
+ $is_moved = $file->move(WRITEPATH . 'uploads/import_excel');
+ $filename = $file->getName();
+ $this->myLogger->logme('error', 'Inception Import file name : {data}', ['data' => $filename]);
+
+ $random_number_count = 4;
+ $batch_data['batch_code'] = generate_random_string($random_number_count);
+ $batch_data['created_by'] = get_session_userid();
+ $batch_data['status'] = 'pending';
+ $batch_data['file_name'] = $filename;
if ($event_type == 'inception' || $event_type == 'addition' || $event_type == 'dependent_addition') {
-
- $file = $this->request->getFile('import_file_data');
-
- $is_moved = $file->move(WRITEPATH . 'uploads/import_excel');
- $filename = $file->getName();
- $this->myLogger->logme('error', 'Inception Import file name : {data}', ['data' => $filename]);
-
-
- $random_number_count = 4;
- $batch_data['batch_code'] = generate_random_string($random_number_count);
- $batch_data['created_by'] = get_session_userid();
- $batch_data['status'] = 'pending';
- $batch_data['file_name'] = $filename;
-
$file_id = $this->batchFileModel->insert($batch_data);
- $job_details = new Jobs();
- $r = Jobs::addJob(['job_name' => 'importInceptionFileValidation','payload' => ['file_id' => $file_id]]);
-
+ $job_details = new Jobs();
+ $r = Jobs::addJob(['job_name' => 'importInceptionFileValidation', 'payload' => ['file_id' => $file_id]]);
+
$return = 1;
// $return = $empDataServiceController->importInceptionFileValidation(['file_id' => $file_id]);
if ($return == 1) {
- session()->setFlashdata('success', 'Data updated successfully. File is being validated.');
+ session()->setFlashdata('success', 'File Uploaded Successfully File is being validated.');
return redirect()->to(base_url('employee/upload'));
- } else if ($return == 2) {
- session()->setFlashdata('error', 'The TPA ID column is either partially or entirely empty.');
- return redirect()->to(base_url('employee/upload'));
- } else if ($return == 0) {
- session()->setFlashdata('error', 'Please upload the correct file.');
- return redirect()->to(base_url('employee/upload'));
- } else if ($return == 3) {
- session()->setFlashdata('error', 'The list of employees provided has already been updated with the TPA ID, or this is not the correct file');
- return redirect()->to(base_url('employee/upload'));
- } else if ($return == 4) {
- session()->setFlashdata('error', 'The UHID column is either partially or entirely empty.');
- return redirect()->to(base_url('employee/upload'));
- } else if ($return == 5) {
- session()->setFlashdata('error', 'The list of employees provided has already been updated with the UHID, or this is not the correct file');
- return redirect()->to(base_url('employee/upload'));
- } else if ($return == 6) {
- session()->setFlashdata('error', 'The Excel record count exceeds the DB record count.');
+ } else {
+ session()->setFlashdata($return['status'], $return['message']);
return redirect()->to(base_url('employee/upload'));
}
} else if ($event_type == 'correction') {
- $return = $empDataServiceController->importExcelDataForCorrection($batch_data);
+ $file_id = $this->batchFileModel->insert($batch_data);
+
+ $job_details = new Jobs();
+ $r = Jobs::addJob(['job_name' => 'importCorrectionValidation', 'payload' => ['file_id' => $file_id]]);
+
+ $return = 1;
+
+ // $return = $empDataServiceController->importCorrectionValidation(['file_id' => $file_id]);
+
if ($return == 1) {
- session()->setFlashdata('success', 'Data updated successfully');
+ session()->setFlashdata('success', 'File Uploaded Successfully File is being validated.');
return redirect()->to(base_url('employee/upload'));
- } else if ($return == 2) {
- session()->setFlashdata('error', 'The Endorsement ID columns are empty.');
- return redirect()->to(base_url('employee/upload'));
- } else if ($return == 0) {
- session()->setFlashdata('error', 'Please upload the correct file');
- return redirect()->to(base_url('employee/upload'));
- } else if ($return == 3) {
- session()->setFlashdata('error', 'File already uploaded');
+ } else {
+ session()->setFlashdata('error', $return);
return redirect()->to(base_url('employee/upload'));
}
} else if ($event_type == 'si_enhancement') {
- $return = $empDataServiceController->importExcelDataForSIEnhancement($batch_data);
+
+ $file_id = $this->batchFileModel->insert($batch_data);
+
+ $job_details = new Jobs();
+ $r = Jobs::addJob(['job_name' => 'importSIEnhancementValidation', 'payload' => ['file_id' => $file_id]]);
+
+ $return = 1;
+
+ // $return = $empDataServiceController->importSIEnhancementValidation(['file_id' => $file_id]);
+
if ($return == 1) {
- session()->setFlashdata('success', 'Data updated successfully');
+ session()->setFlashdata('success', 'File Uploaded Successfully File is being validated.');
return redirect()->to(base_url('employee/upload'));
- } else if ($return == 2) {
- session()->setFlashdata('error', 'The Endorsement ID columns are empty.');
- return redirect()->to(base_url('employee/upload'));
- } else if ($return == 0) {
- session()->setFlashdata('error', 'Please upload the correct file');
- return redirect()->to(base_url('employee/upload'));
- } else if ($return == 3) {
- session()->setFlashdata('error', 'File already uploaded');
+ } else {
+ session()->setFlashdata('error', $return);
return redirect()->to(base_url('employee/upload'));
}
} else if ($event_type == 'deletion') {
- $return = $empDataServiceController->importExcelDataForDeletion($batch_data);
+ $file_id = $this->batchFileModel->insert($batch_data);
+
+ $job_details = new Jobs();
+ $r = Jobs::addJob(['job_name' => 'importDeletionValidation', 'payload' => ['file_id' => $file_id]]);
+
+ $return = 1;
+
+ // $return = $empDataServiceController->importDeletionValidation(['file_id' => $file_id]);
+
+
if ($return == 1) {
- session()->setFlashdata('success', 'Data updated successfully');
+ session()->setFlashdata('success', 'File Uploaded Successfully File is being validated.');
return redirect()->to(base_url('employee/upload'));
- } else if ($return == 2) {
- session()->setFlashdata('error', 'The Endorsement ID columns are empty.');
- return redirect()->to(base_url('employee/upload'));
- } else if ($return == 0) {
- session()->setFlashdata('error', 'Please upload the correct file');
- return redirect()->to(base_url('employee/upload'));
- } else if ($return == 3) {
- session()->setFlashdata('error', 'File already uploaded');
+ } else {
+ session()->setFlashdata('error', $return);
return redirect()->to(base_url('employee/upload'));
}
}
@@ -544,8 +571,13 @@ class EmployeeController extends AdminController
$data['status'] = ['pending' => 'Pending', 'inprogress' => 'In-Progress', 'complete' => 'Complete'];
if (count($this->request->getGet())) {
$filterData = $this->request->getGet();
- $data['employees'] = $this->employeePolicyModel->getEmployeeEndorsementList(client_id: $filterData['client_id'], policy_id: $filterData['policy_id'], status: $filterData['status']);
- $data['getData'] = $filterData;
+ $data['employees'] = $this->employeePolicyModel->getEmployeeEndorsementList(
+ client_id: $filterData['client_id'],
+ policy_id: $filterData['policy_id'],
+ status: $filterData['status'],
+ branch_id: $filterData['branch_id']
+ );
+ $data['getData'] = $filterData;
// echo "";
// print_r($data); die;
}
@@ -684,6 +716,9 @@ class EmployeeController extends AdminController
public function viewUploadedEmployeeList()
{
+
+ $empDataServiceController = new EmpDataServiceController();
+
$file_id = $this->request->getGet('file_id');
// $emp_data['employees'] = $this->employeePolicyModel->getViewEmpSuccessList($file_id);
// $html = view('view_file_upload_emp_list', $emp_data);
@@ -695,20 +730,21 @@ class EmployeeController extends AdminController
->join('clients c', 'files.client_id = c.id and files.client_id = cp.client_id', 'left')
->where('files.id', $file_id)->first();
+ // dd($file_name);
+
try {
$filePath = WRITEPATH . '/uploads/excel/' . $file_name['file_name'];
if (file_exists($filePath)) {
- $spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($filePath);
- $sheet = $spreadsheet->getActiveSheet();
-
- $highestRowAndColumn = $sheet->getHighestRowAndColumn();
- $excel_data = $sheet->rangeToArray('A1:' . $highestRowAndColumn['column'] . $highestRowAndColumn['row']);
- // dd($excel_data);
+
+ $excel_data = $empDataServiceController->readExcelFileToArray($filePath);
$emp_data['thead'] = $excel_data[0];
unset($excel_data[0]);
$emp_data['tbody'] = $excel_data;
+ $emp_data['count'] = count($excel_data);
+
+ // dd($emp_data);
$html = view('view_file_upload_emp_list', $emp_data);
} else {
@@ -854,8 +890,9 @@ class EmployeeController extends AdminController
}
- public function generateIDCardForEmployee($rand_string)
- {
+ public function generateIDCardForEmployee($rand_string, $people = 0)
+ {
+ // dd($rand_string, $people);
try {
@@ -883,9 +920,13 @@ class EmployeeController extends AdminController
$client_policy_id = $get_emp_code_and_client_policy_id['client_policy_id'];
$emp_code = $get_emp_code_and_client_policy_id['emp_code'];
- // $data['data'] = $this->employeePolicyModel->getECardDataUsingMd5($client_policy_id, $emp_code);
+
$data = $this->employeePolicyModel->getECardDataUsingMd5($client_policy_id, $emp_code);
+ if($people == 0){
+ $data = $this->employeePolicyModel->getECardSingleData($rand_string, $emp_code);
+ }
+
// dd($data);
$template_data_path = WRITEPATH . 'e_card_template/';
@@ -920,15 +961,27 @@ class EmployeeController extends AdminController
'{DOB}' => date('d-M-Y', strtotime($value['dob'])),
'{SELF_NAME}' => $value['self'] ?? $value['name'],
'{POLICY_DATE}' => date('d-M-Y', strtotime($value['policy_end_date'])),
- '{INSURER_NAME}' => $value['insurer_name'],
+ '{POLICY_START_DATE}' => date('d-M-Y', strtotime($value['policy_start_date'])),
+ '{POLICY_NO}' => date('d-M-Y', strtotime($value['policy_start_date'])),
+ '{INSURER_NAME}' => strtoupper($value['insurer_name']),
'{INSURER_LOGO}' => base_url() . 'public/uploads/logo/' . $value['insurer_logo'],
'{FRONT_CARD}' => base_url() . 'public/uploads/template_bg/' . $value['front_card'],
- '{BACK_CARD}' => base_url() . 'public/uploads/logo/' . $value['back_card'],
+ '{BACK_CARD}' => base_url() . 'public/uploads/template_bg/' . $value['back_card'],
'{EMP_ID}' =>$value['emp_code'],
'{CORPORATE_NAME}' =>$value['client_name'],
'{AGE}' =>$value['emp_age'],
- '{TPA_NAME}' =>$value['emp_age'],
+ '{TPA_NAME}' =>$value['tpa_name'],
+ '{INSURER_BRANCH}' =>$value['insurer_branch_city'],
+ '{RELATION}' =>$value['relationship'],
'{TPA_LOGO}' => base_url() . 'public/uploads/logo/' . $value['tpa_logo'],
+ '{MEDI_USER}' => base_url() . 'public/e_card_imgs/medi_uesr.jpg',
+ '{MEDI_INSURER}' => base_url() . 'public/e_card_imgs/Magma.png',
+ '{MEDI_BARCODE}' => base_url() . 'public/e_card_imgs/borcode.jpeg',
+ '{QR_ANDROID}' => base_url() . 'public/e_card_imgs/android.png',
+ '{QR_IOS}' => base_url() . 'public/e_card_imgs/ios.png',
+ '{QR_ANDROID_2}' => base_url() . 'public/e_card_imgs/play_store.png',
+ '{QR_IOS_2}' => base_url() . 'public/e_card_imgs/appstore.png',
+
];
// Replace placeholders with values in HTML content
@@ -1008,6 +1061,34 @@ class EmployeeController extends AdminController
{
$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";
+ }
+
}
@@ -1064,9 +1145,32 @@ class EmployeeController extends AdminController
}
- public function previewTemplate($id = null){
+ public function previewTemplate($id = null)
+ {
+
+
+ $value = [
+ 'tpa_id' => 'TPA12345',
+ 'name' => 'John Doe',
+ 'uhid' => 'UHID67890',
+ 'gender' => 'Male',
+ 'dob' => '1985-05-15',
+ 'self' => 'John Doe',
+ 'policy_end_date' => '2024-12-31',
+ 'policy_start_date' => '2023-01-01',
+ 'policy_no' => 'POL1234567890',
+ 'insurer_name' => 'Example Insurance Company',
+ 'emp_code' => 'EMP001122',
+ 'client_name' => 'Corporate Client Inc.',
+ 'emp_age' => 39,
+ 'tpa_name' => 'Example TPA',
+ 'insurer_branch_city' => 'New York',
+ 'relationship' => 'Self'
+ ];
+
+
$tpa_id = $this->TPAModel->where('id', $id)->first();
$template_data_path = WRITEPATH . 'e_card_template/';
@@ -1077,28 +1181,52 @@ class EmployeeController extends AdminController
$data['message'] = 'Record Not Found';
return view('errors/404', $data);
- }
+ }
$tmplt_data = file_get_contents($final_path);
$placeholders = [
+ '{TPA_ID}' => $value['tpa_id'],
+ '{NAME}' => $value['name'],
+ '{UHID}' => $value['uhid'],
+ '{GENDER}' => $value['gender'],
+ '{DOB}' => date('d-M-Y', strtotime($value['dob'])),
+ '{SELF_NAME}' => $value['self'] ?? $value['name'],
+ '{POLICY_DATE}' => date('d-M-Y', strtotime($value['policy_end_date'])),
+ '{POLICY_START_DATE}' => date('d-M-Y', strtotime($value['policy_start_date'])),
+ '{POLICY_NO}' => $value['policy_no'],
+ '{INSURER_NAME}' => strtoupper($value['insurer_name']),
+ '{EMP_ID}' => $value['emp_code'],
+ '{CORPORATE_NAME}' => $value['client_name'],
+ '{AGE}' => $value['emp_age'],
+ '{TPA_NAME}' => $value['tpa_name'],
+ '{INSURER_BRANCH}' => $value['insurer_branch_city'],
+ '{RELATION}' => $value['relationship'],
'{FRONT_CARD}' => base_url() . 'public/uploads/template_bg/' . $tpa_id['front_card'],
- '{BACK_CARD}' => base_url() . 'public/uploads/logo/' . $tpa_id['back_card'],
+ '{BACK_CARD}' => base_url() . 'public/uploads/template_bg/' . $tpa_id['back_card'],
+ '{TPA_LOGO}' => base_url() . 'public/uploads/logo/' . $tpa_id['tpa_logo'],
+ '{INSURER_LOGO}' => base_url() . 'public/assets/images/sample_logo_3.png',
+ '{MEDI_USER}' => base_url() . 'public/e_card_imgs/medi_uesr.jpg',
+ '{MEDI_INSURER}' => base_url() . 'public/e_card_imgs/Magma.png',
+ '{MEDI_BARCODE}' => base_url() . 'public/e_card_imgs/borcode.jpeg',
+ '{QR_ANDROID}' => base_url() . 'public/e_card_imgs/android.png',
+ '{QR_IOS}' => base_url() . 'public/e_card_imgs/ios.png',
+ '{QR_ANDROID_2}' => base_url() . 'public/e_card_imgs/play_store.png',
+ '{QR_IOS_2}' => base_url() . 'public/e_card_imgs/appstore.png',
+
];
-
+
// Get the values to replace the placeholders
$replaceValues = array_values($placeholders);
-
+
// Get the placeholders to search for
$searchPlaceholders = array_keys($placeholders);
-
+
// Replace placeholders with values in HTML content
$htmlContent = str_replace($searchPlaceholders, $replaceValues, $tmplt_data);
- echo $htmlContent;
-
-
+ echo $htmlContent;
}
@@ -1111,6 +1239,7 @@ class EmployeeController extends AdminController
$client_id = $file['client_id'];
$client_policy_id = $file['client_policy_id'];
$insurer_or_tpa = $file['insurer_or_tpa'];
+ $event_type = $file['event_type'];
$error_data = json_decode($file['error_data']);
@@ -1126,8 +1255,10 @@ class EmployeeController extends AdminController
$excel_data = $empDataServiceController->readExcelFileToArray($file_name_with_path);
$excelErrorData['excel_header'] = $excel_data[0];
unset($excel_data[0]);
- array_pop($excel_data);
+ if($event_type == 'inception' || $event_type == 'deletion'){
+ array_pop($excel_data);
+ }
$finalArray = [];
foreach ($error_data as $key => $values) {
@@ -1143,15 +1274,22 @@ class EmployeeController extends AdminController
}else{
- if ($insurer_or_tpa == 'tpa') {
+ if($event_type == 'inception'){
- $error = 'Expected value : TPA ID';
+ if ($insurer_or_tpa == 'tpa') {
- } else if ($insurer_or_tpa == 'insurer') {
-
- $error = 'Expected value : UHID';
+ $error = 'Expected value : TPA ID';
+
+ } else if ($insurer_or_tpa == 'insurer') {
+
+ $error = 'Expected value : UHID';
+ }
+
+ }else{
+ $error = 'Expected value : ENDORSEMENT ID';
}
+
}
$data = ['value' => $excel_data[$row][$column], 'error' => $error,];
$excel_data[$row][$column] = $data;
@@ -1182,9 +1320,18 @@ class EmployeeController extends AdminController
{
$client_policy_id = $this->request->uri->getSegment(3);
$policy_details = $this->clientPolicyModel->find($client_policy_id);
- // print_r($policy_details);die();
$policy_terms = isset($policy_details['policy_terms']) ? true : false;
+ $si_enhancement_true_or_false = 1;
+ if($policy_terms){
+ $policyTermsData = json_decode($policy_details['policy_terms']);
+
+ if (isset($policyTermsData->suminsuredenhancement) && $policyTermsData->suminsuredenhancement !== null) {
+ $si_enhancement_true_or_false = $policyTermsData->suminsuredenhancement;
+ }
+ }
+
+
$slab_details = $this->policiesModel->getPolicySlabRatesForEmpOnboard($client_policy_id,$policy_details['client_id']);
$message = null;
@@ -1199,7 +1346,7 @@ class EmployeeController extends AdminController
}
$message = isset($message) ? ($message . ' not defined for choosed policy') : null;
- return $this->respond(['dataStatus' => true, 'code' => 200, 'message' => $message], 200);
+ return $this->respond(['dataStatus' => true, 'code' => 200, 'message' => $message, 'si_enhancement' => $si_enhancement_true_or_false], 200);
}
diff --git a/app/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php
index 91c4b6b6..a14aac42 100644
--- a/app/Controllers/EmployeeRestController.php
+++ b/app/Controllers/EmployeeRestController.php
@@ -25,6 +25,9 @@ use App\Models\PolicyPremium2Model;
use App\Models\PolicyTypeModel;
use App\Models\NotificationModel;
use App\Models\UserModel;
+use App\Models\FEContentModel;
+use App\Models\AddImgModel;
+
use App\Controllers\Jobs ;
use App\Controllers\JobWorker ;
@@ -57,6 +60,8 @@ class EmployeeRestController extends AdminController
protected $policyTypeModel;
protected $notificationModel;
protected $userModel;
+ protected $feContentModel;
+ protected $addImgModel;
public function __construct()
{
@@ -76,6 +81,8 @@ class EmployeeRestController extends AdminController
$this->policyTypeModel = new PolicyTypeModel();
$this->notificationModel = new NotificationModel();
$this->userModel = new UserModel();
+ $this->feContentModel = new FEContentModel();
+ $this->addImgModel = new AddImgModel();
}
@@ -84,15 +91,22 @@ class EmployeeRestController extends AdminController
try {
$emp_code = $this->request->getGet('emp_code');
$client_id = $this->request->getGet('client_id');
+ $client_branch_id = $this->request->getGet('client_branch_id');
if ($emp_code) {
$relationship = 'self';
$employee = $this->employeeModel->where('emp_code', $emp_code)
->where('client_id', $client_id)
+ ->where('client_branch_id', $client_branch_id)
->where('is_active', 1 )
->where('relationship', $relationship)
->first();
$result = $employee;
- return $this->respond(['status' => 'success','code' => 200,'data' => $result],200);
+ $AccountManagerDetails = $this->clientRMModel->select('client_rm.* , user_profiles.*')
+ ->join('user_profiles', 'client_rm.user_id = user_profiles.id', 'left')
+ ->where('client_rm.client_id', $client_id )
+ ->where('client_rm.level', 3 )
+ ->findAll();
+ return $this->respond(['status' => 'success','code' => 200,'data' => $result, 'AccountManagerDetails'=> isset($AccountManagerDetails[0]) ? $AccountManagerDetails[0] : null ],200);
} else {
$result = "No Match's";
return $this->respond(['status' => 'failed','code' => 404,'data' => $result],404);
@@ -102,7 +116,7 @@ class EmployeeRestController extends AdminController
}
}
-
+ //not in use
public function editEmployeeProfile()
{
try {
@@ -125,7 +139,7 @@ class EmployeeRestController extends AdminController
}
-
+ //not in use
public function getEmployeeAndDependence()
{
try {
@@ -152,7 +166,7 @@ class EmployeeRestController extends AdminController
}
-
+ //not in use
public function editEmployeeAndDependence()
{
try {
@@ -348,7 +362,7 @@ class EmployeeRestController extends AdminController
$Gender = $this->employeeModel->where('emp_code',$empCode)->where('relationship','Self')->get()->getRow()->gender;
if($Gender == 'M'){ return 'F'; }else{ return 'M'; }
}
-}
+ }
private function convertDateFormatYMD($dateString)
{
@@ -372,6 +386,7 @@ class EmployeeRestController extends AdminController
return null;
}
}
+
public function deleteDependence()
{
try {
@@ -400,11 +415,78 @@ class EmployeeRestController extends AdminController
}
+ // Get the RelationShip list
+ public function createOrUpdateEmployeePolicySiAmount()
+ {
+
+ try {
+ $requestData = $this->request->getJSON();
+
+ foreach ($requestData as $key => $value) {
+
+
+ $checkIfExist = $this->employeePolicyModel->where('employee_id', $value->employee_id)
+ ->where('client_policy_id', $value->client_policy_id)
+ ->where('is_active', 1 )
+ ->findAll();
+
+
+ // dd($checkIfExist);
+ if ($checkIfExist) {
+
+ $empPolicy = $this->employeePolicyModel->updateSiAndPremium($value->client_policy_id, $value->employee_id, $value->basic_cover_si);
+
+ }else{
+
+ $data['employee_id']= $value->employee_id;
+ $data['client_policy_id']= $value->client_policy_id;
+ $data['basic_cover_si']= $value->basic_cover_si;
+ $data['status'] = 'draft';
+
+ $this->employeePolicyModel->insert($data);
+ }
+ }
+
+ $this->updatePremiumAmount($requestData[0]->client_policy_id , $requestData[0]->emp_code);
+
+ return $this->respond(['status' => 'success','code' => 200,'data' => []], 200);
+
+ } catch (\Exception $e) {
+ return $this->respond(['status' => 'failed','code' => 500,'data' => $e->getMessage()], 500);
+ }
+ }
+
+ public function findPremiumAmount($slabArray,$siAmount)
+ {
+ foreach ($slabArray as $key => $value) {
+ if($value['si'] == $siAmount){
+ return $value['premium'];
+ break;
+ }
+ }
+ }
+
+ public function relationshipList()
+ {
+ try {
+
+ $relation_ships= $this->relationshipModel->findAll();
+
+ if(count($relation_ships) > 0){
+ return $this->respond(['status' => 'success','code' => 200,'data' => $relation_ships], 200);
+ }else{
+ return $this->respond(['status' => 'success','code' => 200,'data' => "No Data..!"], 200);
+ }
+
+ } catch (\Exception $e) {
+ return $this->respond(['status' => 'failed','code' => 500,'data' => $e->getMessage()], 500);
+ }
+ }
public function getEmployeeAndDependenceByClientId()
{
try {
- $empData = $this->employeePolicyModel->getEmployeePolicy( client_id:$this->request->getGet('client_id'),policy_id: $this->request->getGet('client_policy_id'),status:0);
+ $empData = $this->employeePolicyModel->getEmployeePolicy( client_id:$this->request->getGet('client_id'),policy_id: $this->request->getGet('client_policy_id'),status:0,branch_id:$this->request->getGet('client_branch_id'));
if ($empData) {
return $this->respond(['status' => 'success', 'code' => 200, 'data' => $empData], 200);
@@ -419,11 +501,11 @@ class EmployeeRestController extends AdminController
}
-
public function exportDataByClientPolicyId()
{
try {
- $empData = $this->employeePolicyModel->getEmployeePolicy( client_id:$this->request->getGet('client_id'),policy_id: $this->request->getGet('client_policy_id'),status:0);
+
+ $empData = $this->employeePolicyModel->getEmployeePolicy( client_id:$this->request->getGet('client_id'),policy_id: $this->request->getGet('client_policy_id'),status:0,branch_id:$this->request->getGet('client_branch_id'));
if(count($empData))
{
@@ -496,6 +578,7 @@ class EmployeeRestController extends AdminController
}
+ //not in use
public function getClientPolicy()
{
try {
@@ -534,73 +617,7 @@ class EmployeeRestController extends AdminController
- // Get the RelationShip list
- public function createOrUpdateEmployeePolicySiAmount()
- {
-
- try {
- $requestData = $this->request->getJSON();
-
- foreach ($requestData as $key => $value) {
-
-
- $checkIfExist = $this->employeePolicyModel->where('employee_id', $value->employee_id)
- ->where('client_policy_id', $value->client_policy_id)
- ->where('is_active', 1 )
- ->findAll();
-
-
- // dd($checkIfExist);
- if ($checkIfExist) {
-
- $empPolicy = $this->employeePolicyModel->updateSiAndPremium($value->client_policy_id, $value->employee_id, $value->basic_cover_si);
-
- }else{
-
- $data['employee_id']= $value->employee_id;
- $data['client_policy_id']= $value->client_policy_id;
- $data['basic_cover_si']= $value->basic_cover_si;
- $data['status'] = 'draft';
-
- $this->employeePolicyModel->insert($data);
- }
- }
-
- $this->updatePremiumAmount($requestData[0]->client_policy_id , $requestData[0]->emp_code);
-
- return $this->respond(['status' => 'success','code' => 200,'data' => []], 200);
-
- } catch (\Exception $e) {
- return $this->respond(['status' => 'failed','code' => 500,'data' => $e->getMessage()], 500);
- }
- }
-
- public function findPremiumAmount($slabArray,$siAmount)
- {
- foreach ($slabArray as $key => $value) {
- if($value['si'] == $siAmount){
- return $value['premium'];
- break;
- }
- }
- }
- public function relationshipList()
- {
- try {
-
- $relation_ships= $this->relationshipModel->findAll();
-
- if(count($relation_ships) > 0){
- return $this->respond(['status' => 'success','code' => 200,'data' => $relation_ships], 200);
- }else{
- return $this->respond(['status' => 'success','code' => 200,'data' => "No Data..!"], 200);
- }
-
- } catch (\Exception $e) {
- return $this->respond(['status' => 'failed','code' => 500,'data' => $e->getMessage()], 500);
- }
- }
// Upload the Employee Detail in DB by Sheet Data
public function employeeUpload()
@@ -614,6 +631,7 @@ class EmployeeRestController extends AdminController
// die;
$file = $this->request->getFile('file');
$client_id = $this->request->getPost('client_id');
+ $client_branch_id = $this->request->getPost('client_branch_id');
$policy_id = $this->request->getPost('policy_id');
$client_data = $this->clientModel->where('id', $client_id)->first();
@@ -632,7 +650,7 @@ class EmployeeRestController extends AdminController
- $client_policy = $this->clientPolicyModel->where('id', $policy_id)->where('client_id', $client_id)->first();
+ $client_policy = $this->clientPolicyModel->where('id', $policy_id)->where('client_id', $client_id)->where('client_branch_id', $client_branch_id)->first();
if ($client_policy) {
$policy = $this->policesModel->where('id', $client_policy['policy_id'])->first();
$policy_permium_1 = $this->policyPremium1Model->where(['client_id' => $client_id , 'client_policy_id' => $policy_id,'is_active' =>1])-> first();
@@ -666,6 +684,7 @@ class EmployeeRestController extends AdminController
$extractData['file_name']= $filename;
$extractData['client_id']= $client_id;
+ $extractData['client_branch_id']= $client_branch_id;
$extractData['status']= 'success';
$extractData['policy_id']= $policy_id;
$extractData['action']= 'enrollment';
@@ -772,6 +791,7 @@ class EmployeeRestController extends AdminController
'client_id' => $client_id,
'emp_status'=>'draft',
'band'=> $extra['10'][$index],
+ 'client_branch_id' => $client_branch_id
];
$basic_cover_si_value = null;
@@ -928,13 +948,15 @@ public function getAgeRange($terms,$familyFloatesValue)
}
+
public function getEmployeePolicy()
{
try {
$id = $this->request->getGet('id');
$emp_code = $this->request->getGet('emp_code');
- $client_id = $this->request->getGet('client_id');
+ $client_id = $this->request->getGet('client_id');
+ $client_branch_id = $this->request->getGet('client_branch_id');
// This is an array containing keys to be removed from the terms and conditions array
$keysToRemove = ["removable_keys"];
@@ -942,8 +964,11 @@ public function getEmployeePolicy()
$empPolicy = $this->employeeModel->getEmployeePolicy($id);
// Retrieve employee and dependents data by passing the employee code
- $employeeData = $this->employeeModel->where('emp_code',$emp_code)->where('client_id',$client_id)
- ->where('is_active', 1 )->where('is_addon_value',0)->findAll();
+ $employeeData = $this->employeeModel->where('emp_code',$emp_code)
+ ->where('client_id',$client_id)
+ ->where('client_branch_id',$client_branch_id)
+ ->where('is_active', 1 )
+ ->where('is_addon_value',0)->findAll();
if ($empPolicy) {
@@ -1091,12 +1116,13 @@ public function getEmployeePolicy()
->where('client_policy.policy_type_id', 3 )
->where('client_policy.is_addon', 1 )
->where('client_policy.client_id', $this->request->getGet('client_id') )
+ ->where('client_policy.client_branch_id', $this->request->getGet('client_branch_id') )
->where('client_policy.is_active', 1 )
->get()
->getResult();
if($checkGmcParentsPolicyExist)
{
- $GmcParrentsData = $this->getGmcParrentsPolicy($checkGmcParentsPolicyExist,$emp_code,$client_id);
+ $GmcParrentsData = $this->getGmcParrentsPolicy($checkGmcParentsPolicyExist,$emp_code,$client_id,$client_branch_id);
return $this->respond(['status' => 'success','code' => 200,'data' => [$array,$GmcParrentsData]], 200);
}
@@ -1122,11 +1148,14 @@ public function getEmployeePolicy()
}
-public function getGmcParrentsPolicy($GmcParrentsPolicy,$emp_code,$client_id)
+public function getGmcParrentsPolicy($GmcParrentsPolicy,$emp_code,$client_id,$client_branch_id)
{
- $employeeData = $this->employeeModel->where('emp_code',$emp_code)->where('client_id',$client_id)
- ->where('is_active', 1 )->where('is_addon_value',0)->findAll();
+ $employeeData = $this->employeeModel->where('emp_code',$emp_code)
+ ->where('client_id',$client_id)
+ ->where('client_branch_id',$client_branch_id)
+ ->where('is_active', 1 )
+ ->where('is_addon_value',0)->findAll();
foreach ($GmcParrentsPolicy as $key => $array) {
@@ -1163,9 +1192,7 @@ public function getGmcParrentsPolicy($GmcParrentsPolicy,$emp_code,$client_id)
$array->eCardDownload = null;
}
- // if($array->tpa_id != null){
- // $array->eCardDownload = base_url('download-e-card/') . $array->rand_string;
- // }else{ $array->eCardDownload = null; }
+
$array->eCardDownload = null;
// Map family floaters that already exist in the employee table
@@ -1256,6 +1283,7 @@ public function getGmcParrentsPolicy($GmcParrentsPolicy,$emp_code,$client_id)
}
}
+
public function FloterConvertion($array){
$result = [];
@@ -1320,7 +1348,8 @@ public function getClientDetails()
$client = $this->clientModel->where('id',$this->request->getGet('client_id'))->first();
if($client) {
$client['client_logo'] = base_url().'public/uploads/logo/'.$client['client_logo'];
- $clientPolicy = $this->clientPolicyModel->where('client_id',$this->request->getGet('client_id'))->findAll();
+ $clientPolicy = $this->clientPolicyModel->where('client_id',$this->request->getGet('client_id'))
+ ->where('client_branch_id',$this->request->getGet('client_branch_id'))->findAll();
return $this->respond(['status' => 'success','code' => 200,'data' => ['client'=>$client,'client_policy'=>$clientPolicy]], 200);
}else{
@@ -1335,17 +1364,23 @@ public function getAddOnPolicy()
{
try {
- $addOnEmployeeData = $this->employeeModel->where('is_active', 1 )->where('emp_code',$this->request->getGet('emp_code'))->where('client_id',$this->request->getGet('client_id'))->where('is_addon_value',1)->findAll();
+ $addOnEmployeeData = $this->employeeModel->where('is_active', 1 )
+ ->where('emp_code',$this->request->getGet('emp_code'))
+ ->where('client_id',$this->request->getGet('client_id'))
+ ->where('client_branch_id',$this->request->getGet('client_branch_id'))
+ ->where('is_addon_value',1)->findAll();
-
+
$clientPolicy = $this->clientPolicyModel->where('client_id',$this->request->getGet('client_id'))
+ ->where('client_branch_id',$this->request->getGet('client_branch_id'))
->where('policy_status', 1)
->findAll();
-
+
if(count($clientPolicy))
{
- $band = $addOnEmployeeData = $this->employeeModel->where('is_active', 1 )->where('emp_code',$this->request->getGet('emp_code'))->where('client_id',$this->request->getGet('client_id'))->where('family_floater_key','self')->get()->getRow()->band;
+ $band = $this->employeeModel->where('is_active', 1 )->where('emp_code',$this->request->getGet('emp_code'))->where('client_id',$this->request->getGet('client_id'))->where('client_branch_id',$this->request->getGet('client_branch_id'))->where('family_floater_key','self')->get()->getRow()->band;
+
$PolicyData = [];
foreach ($clientPolicy as $key => $array) {
$responce = [];
@@ -1361,9 +1396,16 @@ public function getAddOnPolicy()
$uniqueData[] = $item;
}
}else{
- if (!in_array($item['si'], $siValues)) {
- $uniqueData[] = $item;
- $siValues[] = $item['si'];
+ if (!in_array($item['si'], $siValues) ) {
+
+ if ($item['policy_grid_id'] == 11 && ($item['max_si'] != 0 || $item['max_si'] != null)) {
+ $uniqueData[] = $item;
+ $siValues[] = $item['si'];
+ }else if($item['policy_grid_id'] != 11){
+ $uniqueData[] = $item;
+ $siValues[] = $item['si'];
+ }
+
}
}
@@ -1768,6 +1810,7 @@ public function getCashDepositData()
$ClientPolicyData = $this->clientPolicyModel->select('client_policy.client_id as clientId , client_policy.insurer_id as insurerId,insurers.name as insurer_name')
->join('insurers', 'client_policy.insurer_id = insurers.id', 'left')
->where('client_policy.client_id', $this->request->getGet('client_id') )
+ ->where('client_policy.client_branch_id', $this->request->getGet('client_branch_id') )
->where('client_policy.is_active', 1 )
->where('client_policy.policy_status', 1)
->groupBy('client_policy.insurer_id')
@@ -1789,6 +1832,7 @@ public function getCashDepositData()
->join('policies', 'client_policy.policy_id = policies.id', 'left')
->where('client_policy.insurer_id', $value['insurerId'] )
->where('client_policy.client_id', $this->request->getGet('client_id') )
+ ->where('client_policy.client_branch_id', $this->request->getGet('client_branch_id') )
->where('client_policy.is_active', 1 )
->where('client_policy.policy_status', 1)
->findAll();
@@ -1797,7 +1841,7 @@ public function getCashDepositData()
{
$value['type'] = $this->policyTypeModel->where('id',$value['policy_type_id'])->get()->getRow()->policy_type;
- $employeeDetails = $this->employeePolicyModel->getEmployeePolicy( client_id:$value['client_id'],policy_id: $value['client_policy_id'],status:0);
+ $employeeDetails = $this->employeePolicyModel->getEmployeePolicy( client_id:$value['client_id'],policy_id: $value['client_policy_id'],status:0,branch_id:$this->request->getGet('client_branch_id'));
$enrolledCount = 0;
$draftCount = 0;
if(count($employeeDetails))
@@ -1970,23 +2014,30 @@ public function removeEmpAndEmpPolicyData()
}
-
-
-function getEmployeeOldPolicy()
+function getEmployeeActiveOrInactivePolicy()
{
+
+ if($this->request->getGet('type') == 'Active'){ $policy_status = 1; }else{ $policy_status = 0; }
$ClientPolicyData = $this->clientPolicyModel->select('client_policy.* , policies.name as policy_name , policy_type.policy_type as policy_type')
->join('policies', 'client_policy.policy_id = policies.id', 'left')
->join('policy_type', 'client_policy.policy_type_id = policy_type.id', 'left')
->where('client_policy.client_id', $this->request->getGet('client_id') )
+ ->where('client_policy.client_branch_id', $this->request->getGet('client_branch_id') )
->where('client_policy.is_active', 1 )
- ->where('client_policy.policy_status', 0)
+ ->where('client_policy.policy_status', $policy_status)
->orderby('client_policy.id' , 'ASC')
->findAll();
// Retrieve employee and dependents data by passing the employee code
$employeeData = $this->employeeModel->where('emp_code',$this->request->getGet('emp_code'))
->where('client_id',$this->request->getGet('client_id'))
+ ->where('client_branch_id',$this->request->getGet('client_branch_id'))
->where('is_active', 1 )->findAll();
+ $employeeName = $this->employeeModel->where('emp_code',$this->request->getGet('emp_code'))
+ ->where('client_id',$this->request->getGet('client_id'))
+ ->where('client_branch_id',$this->request->getGet('client_branch_id'))
+ ->where('family_floater_key','self')->where('is_active', 1 )
+ ->get()->getRow()->name;
$whereArrayForId = [];
foreach ( $employeeData as $key => $value) { array_push($whereArrayForId, $value['id']); }
@@ -1995,15 +2046,22 @@ function getEmployeeOldPolicy()
$result = [];
foreach ($ClientPolicyData as $key => $ClientPolicyValue) {
+
+
$terms = json_decode($ClientPolicyValue['policy_terms']);
- // dd($terms);
+
+ if($ClientPolicyValue['policy_type_id'] == 1){ $data['policy_terms'] = $this->policyTermsFiter($terms,'gpa'); }
+ else{ $data['policy_terms'] = $this->policyTermsFiter($terms,'gmc'); }
+
$data['client_id'] = $ClientPolicyValue['client_id'];
$data['client_policy_id'] = $ClientPolicyValue['id'];
$data['policy_name'] = $ClientPolicyValue['policy_name'];
$data['policy_type'] = $ClientPolicyValue['policy_type'];
$data['policy_type'] = $ClientPolicyValue['policy_type'];
+ $data['policy_no'] = $ClientPolicyValue['policy_no'];
$data['policy_start_date'] = $this->convertDateFormatDisplay($ClientPolicyValue['policy_start_date']);
$data['policy_end_date'] = $this->convertDateFormatDisplay($ClientPolicyValue['policy_end_date']);
+ // $data['policy_terms'] = $terms;
if($ClientPolicyValue['policy_type_id'] == 1){ $data['heading'] = 'Group Personal Accident Coverage'; }else
if($ClientPolicyValue['policy_type_id'] == 2){ $data['heading'] = 'Group Medical Coverage'; }else
@@ -2017,29 +2075,42 @@ function getEmployeeOldPolicy()
if($terms->family_floater == 1){ $data['floter_text_heading'] = 'Floter Sum Insured'; }else{ $data['floter_text_heading'] = 'Sum Insured'; }
}
- $employee_policy = $this->employeePolicyModel->select('employees.*,employee_polices.employee_id , employee_polices.basic_cover_si , employee_polices.premium , employee_polices.gst , employee_polices.tpa_id , employee_polices.rand_string')
+ $employee_policy = $this->employeePolicyModel->select('employees.*,employee_polices.employee_id , employee_polices.basic_cover_si , employee_polices.premium , employee_polices.gst , employee_polices.tpa_id , employee_polices.rand_string , employee_polices.uhid as uhid')
->join('employees', 'employee_polices.employee_id = employees.id', 'left')
->whereIn('employee_polices.employee_id',$whereArrayForId)
->where('employee_polices.client_policy_id',$ClientPolicyValue['id'])
->where('employee_polices.is_active', 1 )->findAll();
- $si_value = 0;
- $si_premium_value = 0;
- $si_gst_value = 0;
- foreach ($employee_policy as $key => $value) {
- if(isset($value['basic_cover_si'])){ $si_value = $value['basic_cover_si']; }
- if(isset($value['premium'])){ $si_premium_value = $si_premium_value + $value['premium'];}
- if(isset($value['gst'])){ $si_gst_value = $si_gst_value + $value['gst'];}
- }
+ if(count($employee_policy) > 0)
+ {
+ $si_value = 0;
+ $si_premium_value = 0;
+ $si_gst_value = 0;
+
+ foreach ($employee_policy as $key => $value) {
+ if(isset($value['basic_cover_si'])){ $si_value = $value['basic_cover_si']; }
+ if(isset($value['premium'])){ $si_premium_value = $si_premium_value + $value['premium'];}
+ if(isset($value['gst'])){ $si_gst_value = $si_gst_value + $value['gst'];}
+ }
- $data['si_value'] = $si_value;
- $data['si_premium_value'] = ($ClientPolicyValue['policy_type_id'] == 1 || $ClientPolicyValue['policy_type_id'] == 2) ? 0 : $si_premium_value;
- $data['si_gst_value'] = ($ClientPolicyValue['policy_type_id'] == 1 || $ClientPolicyValue['policy_type_id'] == 2) ? 0 : $si_gst_value;
-
- $data['EmployeePolicy'] = $employee_policy;
- array_push($result, $data);
+
+ if($employee_policy[0]['tpa_id'] != null)
+ $data['eCardDownload'] = base_url('download-e-card/') . $employee_policy[0]['rand_string'];
+ else
+ $data['eCardDownload'] = null;
+
+
+
+ $data['si_value'] = $si_value;
+ $data['si_premium_value'] = ($ClientPolicyValue['policy_type_id'] == 1 || $ClientPolicyValue['policy_type_id'] == 2) ? 0 : $si_premium_value;
+ $data['si_gst_value'] = ($ClientPolicyValue['policy_type_id'] == 1 || $ClientPolicyValue['policy_type_id'] == 2) ? 0 : $si_gst_value;
+
+ $data['EmployeePolicy'] = $employee_policy;
+ array_push($result, $data);
+ }
+
}
- return $this->respond(['status' => 'success','code' => 200,'data' => $result ], 200);
+ return $this->respond(['status' => 'success','code' => 200,'data' => $result , 'emp_name' => $employeeName ], 200);
}else{
return $this->respond(['status' => 'failed','code' => 404,'data' => [] ], 200);
@@ -2047,81 +2118,70 @@ function getEmployeeOldPolicy()
}
-function getEmployeeActiveOrInactivePolicy()
+
+function policyTermsFiter($terms , $type)
{
+
+ $gpa = [
+ "sumInsured2" => "Sum Insured",
+ "totalSumInsured" => "Total Sum Assured",
+ "self" => "Self",
+ "self_min_age" => "Min Age",
+ "self_max_age" => "Max Age",
+ "accidentalDeathBenefit" => "Accidental Death Benefit",
+ "permanentTotalDisablement" => "Permanent Total Disablement",
+ "permanentPartialDisablement" => "Permanent Partial Disablement",
+ "temporaryTotalDisablementBenefit" => "Temporary Total Disablement benefit",
+ "accidentalHospitalizationExpenses" => "Accidental Hospitalization Expenses",
+ "childrenEducationWelfareFund" => "Children Education Welfare Fund",
+ "compassionateVisitExpenses" => "Compassionate Visit Expenses",
+ "compassionateVisitExpensesData" => "Compassionate Visit Expenses Data",
+ "brokenBoneExpenses" => "Broken Bone Expenses",
+ "brokenBoneExpensesData" => "Broken Bone Expenses Data",
+ "ambulanceCharges" => "Ambulance charges",
+ "ambulanceChargesData" => "Ambulance charges Data",
+ "burnExpenses" => "Burn Expenses",
+ "burnExpensesData" => "Burn Expenses Data",
+ "carriageOfDeadBody" => "Carriage of Dead Body",
+ "carriageOfDeadBodyData" => "Carriage of Dead Body Data",
+ "animalSnakeInsectBite" => "Animal/Snake/Insect bite",
+ "terrorism" => "Terrorism",
+ "worldwideCover" => "Worldwide Cover"
+ ];
+
+ $gmc = [
+ "sum_insured" => "Sum Insured",
+ "waiverofpreexistingdiseases" => "Waiver of Pre-existing Diseases",
+ "maternitycoverage" => "Maternity Coverage",
+ "babyday1cover" => "Baby Day 1 Cover",
+ "9monthwaitingperiodwaived" => "9-month waiting Period –waived",
+ "coverfromthedateofjoining" => "Cover from the date of Joining",
+ "waiverof1,2,3&4thyearexclusions" => "Waiver of 1, 2, 3 & 4th year Exclusions",
+ "waiverof30dayswaitingperiod" => "Waiver of 30 days waiting period",
+ "prehospitalizationcover" => "Pre Hospitalization Cover",
+ "copayzonewisecopay" => "Co-Pay/Zone wise Co Pay",
+ "roomrentlimit" => "Room Rent Limit",
+ "ailmentcapping" => "Ailment capping",
+ ];
- if($this->request->getGet('type') == 'Active'){ $value = 1; }else{ $value = 0; }
- $ClientPolicyData = $this->clientPolicyModel->select('client_policy.* , policies.name as policy_name , policy_type.policy_type as policy_type')
- ->join('policies', 'client_policy.policy_id = policies.id', 'left')
- ->join('policy_type', 'client_policy.policy_type_id = policy_type.id', 'left')
- ->where('client_policy.client_id', $this->request->getGet('client_id') )
- ->where('client_policy.is_active', 1 )
- ->where('client_policy.policy_status', $value)
- ->orderby('client_policy.id' , 'ASC')
- ->findAll();
- // Retrieve employee and dependents data by passing the employee code
- $employeeData = $this->employeeModel->where('emp_code',$this->request->getGet('emp_code'))
- ->where('client_id',$this->request->getGet('client_id'))
- ->where('is_active', 1 )->findAll();
- $whereArrayForId = [];
- foreach ( $employeeData as $key => $value) { array_push($whereArrayForId, $value['id']); }
- if(count($ClientPolicyData) > 0 && count($employeeData) > 0)
- {
- $result = [];
- foreach ($ClientPolicyData as $key => $ClientPolicyValue) {
-
- $terms = json_decode($ClientPolicyValue['policy_terms']);
- // dd($terms);
- $data['client_id'] = $ClientPolicyValue['client_id'];
- $data['client_policy_id'] = $ClientPolicyValue['id'];
- $data['policy_name'] = $ClientPolicyValue['policy_name'];
- $data['policy_type'] = $ClientPolicyValue['policy_type'];
- $data['policy_type'] = $ClientPolicyValue['policy_type'];
- $data['policy_start_date'] = $this->convertDateFormatDisplay($ClientPolicyValue['policy_start_date']);
- $data['policy_end_date'] = $this->convertDateFormatDisplay($ClientPolicyValue['policy_end_date']);
-
- if($ClientPolicyValue['policy_type_id'] == 1){ $data['heading'] = 'Group Personal Accident Coverage'; }else
- if($ClientPolicyValue['policy_type_id'] == 2){ $data['heading'] = 'Group Medical Coverage'; }else
- if($ClientPolicyValue['policy_type_id'] == 3){ $data['heading'] = 'Group Medical Coverage - Parents'; }else
- if($ClientPolicyValue['policy_type_id'] == 4){ $data['heading'] = 'Group Medical Coverage - Top Up'; }else
- if($ClientPolicyValue['policy_type_id'] == 5){ $data['heading'] = 'Group Medical Coverage - Parents (Top Up)'; }
-
- if($ClientPolicyValue['policy_type_id'] == 1){ $data['floter_text_heading'] = 'Sum Insured'; }
- else
- {
- if($terms->family_floater == 1){ $data['floter_text_heading'] = 'Floter Sum Insured'; }else{ $data['floter_text_heading'] = 'Sum Insured'; }
- }
-
- $employee_policy = $this->employeePolicyModel->select('employees.*,employee_polices.employee_id , employee_polices.basic_cover_si , employee_polices.premium , employee_polices.gst , employee_polices.tpa_id , employee_polices.rand_string')
- ->join('employees', 'employee_polices.employee_id = employees.id', 'left')
- ->whereIn('employee_polices.employee_id',$whereArrayForId)
- ->where('employee_polices.client_policy_id',$ClientPolicyValue['id'])
- ->where('employee_polices.is_active', 1 )->findAll();
- $si_value = 0;
- $si_premium_value = 0;
- $si_gst_value = 0;
- foreach ($employee_policy as $key => $value) {
- if(isset($value['basic_cover_si'])){ $si_value = $value['basic_cover_si']; }
- if(isset($value['premium'])){ $si_premium_value = $si_premium_value + $value['premium'];}
- if(isset($value['gst'])){ $si_gst_value = $si_gst_value + $value['gst'];}
- }
-
- $data['si_value'] = $si_value;
- $data['si_premium_value'] = ($ClientPolicyValue['policy_type_id'] == 1 || $ClientPolicyValue['policy_type_id'] == 2) ? 0 : $si_premium_value;
- $data['si_gst_value'] = ($ClientPolicyValue['policy_type_id'] == 1 || $ClientPolicyValue['policy_type_id'] == 2) ? 0 : $si_gst_value;
-
- $data['EmployeePolicy'] = $employee_policy;
- array_push($result, $data);
+ $finalarray = [];
+ if($type == 'gpa'){
+ foreach ($gpa as $key => $value) {
+ if(isset($terms->$key))
+ $finalarray[$value] = $terms->$key;
}
-
- return $this->respond(['status' => 'success','code' => 200,'data' => $result ], 200);
-
}else{
- return $this->respond(['status' => 'failed','code' => 404,'data' => [] ], 200);
+ foreach ($gmc as $key => $value) {
+ if(isset($terms->$key))
+ $finalarray[$value] = $terms->$key;
+ }
}
+
+ return $finalarray;
+
}
@@ -2137,4 +2197,46 @@ private function convertDateFormatDisplay($dateString)
}
}
+public function getFEContent()
+{
+ try {
+
+ $feContentData = $this->feContentModel->findAll();
+ if (count($feContentData) > 0) {
+
+ return $this->respond(['status' => 'success','code' => 200,'data' => $feContentData ],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);
+ }
+}
+
+public function getAdvertisementImage()
+{
+ try {
+
+ $img = $this->addImgModel->where('is_active',1)->findAll();
+
+ if (count($img) > 0) {
+ $data=[];
+ foreach ($img as $key => $value) {
+ $url = base_url('public/uploads/add_image_upload/').$value['name'];
+ array_push($data,$url);
+ }
+
+ return $this->respond(['status' => 'success','code' => 200,'data' => $data ],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);
+ }
+}
+
}
\ No newline at end of file
diff --git a/app/Controllers/EmployeeServiceController.php b/app/Controllers/EmployeeServiceController.php
index 6e6bb123..ed6bf76e 100644
--- a/app/Controllers/EmployeeServiceController.php
+++ b/app/Controllers/EmployeeServiceController.php
@@ -229,12 +229,13 @@ class EmployeeServiceController extends AdminController
$result['error_data'][$row_key][$keys[$col_key]]['error'][] = $format_error['error'];
}
}
-
+ // Kint::dump($is_mandatory);
//allowed values check
- if($is_mandatory === true && isset($allowed_values) && is_array($allowed_values))
+ if(($is_mandatory === true && isset($allowed_values) && is_array($allowed_values)) || (is_array($is_mandatory) && (isset($allowed_values) && is_array($allowed_values))))
{
-
- if(!in_array(strtolower(trim($col)),$allowed_values))
+ // print_r($allowed_values);
+ // dd($col);
+ if(!in_array((trim($col)),$allowed_values))
{
array_push($result['error_summary'],3);
$result['error_data'][$row_key][$keys[$col_key]]['col_name'] = $column_dispaly_name; //push column name
@@ -263,9 +264,9 @@ class EmployeeServiceController extends AdminController
}
- }
-
- }
+ }//col foreach
+ // break;
+ }//row foreach
if(isset($result['error_summary']) && count($result['error_summary']))
{
@@ -348,102 +349,114 @@ class EmployeeServiceController extends AdminController
unset($excel_data[0]);
$relationship = $this->general_relationships;
- $employee_data_group_by_family = data_group_by_family($excel_data);
- // dd($employee_data_group_by_family);
- foreach ($employee_data_group_by_family as $emp_id => $family)
- {
- //if action is DA then get all familiy members,transfrom them into excel array, addd data source as db or excel
- if($file['action'] == 'dependent_addition')
- {
- $existing_famility_details = $this->employeeModel->getEmpFamilybyEmpCode(emp_code: $emp_id,client_id: $file['client_id'],client_policy_id: $file ['policy_id'],emp_status: ['active'],policy_status:['active']);
- // dd(($existing_famility_details));
- //transsform familiy details from db columns to exxcel row with column indexs for checking remaining functionalitites
- $existing_famility_details = transform_db_data_to_excel($existing_famility_details,$file);
- // dd(array_keys($existing_famility_details[0]));
- $family = array_merge($family,$existing_famility_details);
- // kint::dump($family);
- $family = data_group_by_family($family)[ $emp_id ];// reason to call this again is bring self to first index of the array
- }
- // kint::dump($family);//die();
- //check name dup within a family
+ if(in_array($file['action'],['inception','addition','dependent_addition']))// the below funcitons are only for I,DA,A
+ {
+ $employee_data_group_by_family = data_group_by_family($excel_data);
- if($file['action'] == 'inception' || $file['action'] == 'addition' || $file['action'] == 'dependent_addition')
- {
- $res = name_dup_check_within_family($family,$file['action']);
- // dd($res);
- if(count($res))
+ $is_self_available_in_policy_terms = false;
+ if($policy_details['policy_type_id'] == 3) // GMC parents
{
- foreach($res as $k => $rowid)
+ $temp = $policy_terms['family_floaters'];
+ $temp = is_array($temp) ? $temp : (is_object($temp) ? (array)$temp : []);
+ $is_self_available_in_policy_terms = isset($temp['self']) ? true : false;
+ }
+ // dd($employee_data_group_by_family);
+ foreach ($employee_data_group_by_family as $emp_id => $family)
{
- array_push($result['error_summary'],7); // dup entry in excel file
- $result['error_data'][$rowid]['name_of_emp_dep']['error'][] = "Twofold Name found within family";
- }
- }
- }
- //check self availbale in uploaded file
- if(($file['action'] == 'inception' || $file['action'] == 'addition') && ($policy_details['policy_type_id'] == 3 && $policy_details['base_policy'] == null)) // 3 is GMC parents dep addon)
- {
- // dd('file check');
- $res = check_self_available_in_family($family,$file['action']);
- // dd($res);
- if(!$res['is_self_found'])
- {
- array_push($result['error_summary'],14); // Self not found
- $result['error_data'][ $res['row_id'] ]['sno']['error'][] = "Self not found in uploaded file";
- }
- }
+ //if action is DA then get all familiy members,transfrom them into excel array, addd data source as db or excel
+ if($file['action'] == 'dependent_addition')
+ {
+ $existing_famility_details = $this->employeeModel->getEmpFamilybyEmpCode(emp_code: $emp_id,client_id: $file['client_id'],client_policy_id: $file ['policy_id'],emp_status: ['active'],policy_status:['active'],client_branch_id:[ $file['client_branch_id'] ]);
+ // dd(($existing_famility_details));
+ //transsform familiy details from db columns to exxcel row with column indexs for checking remaining functionalitites
+ $existing_famility_details = transform_db_data_to_excel($existing_famility_details,$file);
+ // dd(array_keys($existing_famility_details[0]));
+ $family = array_merge($family,$existing_famility_details);
+ // kint::dump($family);
+ $family = data_group_by_family($family)[ $emp_id ];// reason to call this again is bring self to first index of the array
+ }
+ // kint::dump($family);//die();
+ //check name dup within a family
- //check self avaialbe where self data is not available either same policy (i.e.) gMC parents
- if($file['action'] == 'dependent_addition' || ($policy_details['policy_type_id'] == 3 && $policy_details['base_policy'] == null)) // 3 is GMC parents as base policy not as dep addon)
- {
- $self_details = $this->employeeModel->getEmpFamilybyEmpCode(emp_code: $emp_id,client_id: $file['client_id'],emp_status: ['active'],policy_status:['active']);
- // dd($self_details);
- if(!count($self_details))
- {
- array_push($result['error_summary'],14); // Self not found
- $result['error_data'][ $family[0][0] ]['sno']['error'][] = "Self not found in System";
- }
- }
-
+ if($file['action'] == 'inception' || $file['action'] == 'addition' || $file['action'] == 'dependent_addition')
+ {
+ $res = name_dup_check_within_family($family,$file['action']);//in both file data & DB data
+ // dd($res);
+ if(count($res))
+ {
+ foreach($res as $k => $rowid)
+ {
+ array_push($result['error_summary'],7); // dup entry in excel file
+ $result['error_data'][$rowid]['name_of_emp_dep']['error'][] = "Twofold Name found within family";
+ }
+ }
+ }
- if($file['action'] == 'dependent_addition' || $file['action'] == 'addition' || $file['action'] == 'inception')
- {
- $res = check_dependent_conflict($family,$policy_terms,$file['action']);
- // dd($res);
- if(!$res['status'])
- {
- foreach($res['error_data'] as $key => $value)
- {
- array_push($result['error_summary'],$value['code']);
- $result['error_data'][ $value['row_id'] ][($value['col_name'])]['error'][] = $value['msg'];
- }
- }
- }
+ //check self availbale in uploaded file
+ if(($file['action'] == 'inception' || $file['action'] == 'addition') && ($policy_details['policy_type_id'] == 3 && $is_self_available_in_policy_terms)) // 3 is GMC parents dep addon)
+ {
+ // dd('file check');
+ $res = check_self_available_in_family($family,$file['action']);
+ // dd($res);
+ if(!$res['is_self_found'])
+ {
+ array_push($result['error_summary'],14); // Self not found
+ $result['error_data'][ $res['row_id'] ]['sno']['error'][] = "Self not found in uploaded file";
+ }
+ }
- //check dup with empid and name with db
- $res = name_and_empid_check_in_db($family,$file);
- // dd($res);
- // echo '
';
- // print_r($res);
- if(count($res['del']))
- {
- foreach($res['del'] as $k => $rowid)
- {
- array_push($result['error_summary'],10); //record not avail for deletion
- $result['error_data'][$rowid]['name_of_emp_dep']['error'][] = "Record Not found ";
- }
- }
- if(count($res['i']))
- {
- foreach($res['i'] as $k => $rowid)
- {
- array_push($result['error_summary'],9); //dup entry
- $result['error_data'][$rowid]['name_of_emp_dep']['error'][] = "Record already exists";
- }
- }
- }
+ //check self avaialbe either same policy DB level(i.e.) gMC parents
+ if($file['action'] == 'dependent_addition' || ($policy_details['policy_type_id'] == 3 && !$is_self_available_in_policy_terms)) // 3 is GMC parents as base policy not as dep addon)
+ {
+ $self_details = $this->employeeModel->getEmpFamilybyEmpCode(emp_code: $emp_id,client_id: $file['client_id'],emp_status: ['active'],policy_status:['active'],client_branch_id:[ $file['client_branch_id'] ]);
+ // dd($self_details);
+ if(!count($self_details))
+ {
+ array_push($result['error_summary'],14); // Self not found
+ $result['error_data'][ $family[0][0] ]['sno']['error'][] = "Self not found in System";
+ }
+ }
+
+
+ if($file['action'] == 'dependent_addition' || $file['action'] == 'addition' || $file['action'] == 'inception')
+ {
+ $res = check_dependent_conflict($family,$policy_terms,$file['action']);
+ // dd($res);
+ if(!$res['status'])
+ {
+ foreach($res['error_data'] as $key => $value)
+ {
+ array_push($result['error_summary'],$value['code']);
+ $result['error_data'][ $value['row_id'] ][($value['col_name'])]['error'][] = $value['msg'];
+ }
+ }
+ }
+
+ //check dup with empid and name with db
+ $res = name_and_empid_check_in_db($family,$file);
+ // dd($res);
+ // echo '
';
+ // print_r($res);
+ if(count($res['del']))
+ {
+ foreach($res['del'] as $k => $rowid)
+ {
+ array_push($result['error_summary'],10); //record not avail for deletion
+ $result['error_data'][$rowid]['name_of_emp_dep']['error'][] = "Record Not found ";
+ }
+ }
+ if(count($res['i']))
+ {
+ foreach($res['i'] as $k => $rowid)
+ {
+ array_push($result['error_summary'],9); //dup entry
+ $result['error_data'][$rowid]['name_of_emp_dep']['error'][] = "Record already exists";
+ }
+ }
+ }// end of foreach
+ }// end of if current action I,DA,A
// s($result);
// die();
@@ -559,7 +572,7 @@ class EmployeeServiceController extends AdminController
//if action is DA then get all familiy members,transfrom them into excel array, addd data source as db or excel
if($file['action'] == 'dependent_addition')
{
- $existing_famility_details = $this->employeeModel->getEmpFamilybyEmpCode(emp_code: $emp_id,client_id: $file['client_id'],client_policy_id: $file ['policy_id'],emp_status: ['active'],policy_status:['active']);
+ $existing_famility_details = $this->employeeModel->getEmpFamilybyEmpCode(emp_code: $emp_id,client_id: $file['client_id'],client_policy_id: $file ['policy_id'],emp_status: ['active'],policy_status:['active'],client_branch_id: [ $file['client_branch_id'] ]);
// dd($existing_famility_details);
//transsform familiy details from db columns to exxcel row with column indexs for checking remaining functionalitites
$existing_famility_details = transform_db_data_to_excel($existing_famility_details,$file);
@@ -652,14 +665,14 @@ class EmployeeServiceController extends AdminController
$group_key = rand(100000, 999999);
//for emp table
- $this->empEndorsementModel->save(['pk' => (int)$data['emp_id'],'emp_code' => $data['emp_code'],'table_name' => 'employees','actions' => 'd','name' => $data['name'],'field_name' => 'emp_status','old_value' => $data['emp_status'],'new_value' => 'deactivate','created_by' => $file['created_by'],'remarks' => 'general deletion','group_key' => $group_key,'file_id' => $file['id']]);
+ $this->empEndorsementModel->save(['pk' => (int)$data['emp_id'],'emp_code' => $data['emp_code'],'table_name' => 'employees','actions' => 'd','name' => $data['name'],'field_name' => 'emp_status','old_value' => $data['emp_status'],'new_value' => 'deactivate','created_by' => $file['created_by'],'remarks' => 'general deletion','group_key' => $group_key,'file_id' => $file['id'],'status' => 'pending']);
// dd( $this->empEndorsementModel->getLastQuery());
// $this->empEndorsementModel->save(['pk' => (int)$data['emp_id'],'emp_code' => $data['emp_code'],'table_name' => 'employees','actions' => 'd','name' => $data['name'],'field_name' => 'change_event','old_value' => $data['change_event'],'new_value' => 'deletion','created_by' => $file['created_by'],'remarks' => 'general deletion']);
// for employee policy table
- $this->empEndorsementModel->save(['pk' => (int)$data['emp_policy_id'],'emp_code' => $data['emp_code'],'table_name' => 'employee_polices','actions' => 'd','name' => $data['name'],'field_name' => 'date_of_exit','old_value' => $data['date_of_exit'],'new_value' => change_date_format($row[4],'d-M-Y','Y-m-d'),'created_by' => $file['created_by'],'remarks' => 'general deletion','group_key' => $group_key,'file_id' => $file['id']]);
- $this->empEndorsementModel->save(['pk' => (int)$data['emp_policy_id'],'emp_code' => $data['emp_code'],'table_name' => 'employee_polices','actions' => 'd','name' => $data['name'],'field_name' => 'reason_for_exit','old_value' => $data['reason_for_exit'],'new_value' => $row[5],'created_by' => $file['created_by'],'remarks' => 'general deletion','group_key' => $group_key,'file_id' => $file['id']]);
- $this->empEndorsementModel->save(['pk' => (int)$data['emp_policy_id'],'emp_code' => $data['emp_code'],'table_name' => 'employee_polices','actions' => 'd','name' => $data['name'],'field_name' => 'status','old_value' => $data['status'],'new_value' => 'deactivate','created_by' => $file['created_by'],'remarks' => 'general deletion','group_key' => $group_key,'file_id' => $file['id']]);
+ $this->empEndorsementModel->save(['pk' => (int)$data['emp_policy_id'],'emp_code' => $data['emp_code'],'table_name' => 'employee_polices','actions' => 'd','name' => $data['name'],'field_name' => 'date_of_exit','old_value' => $data['date_of_exit'],'new_value' => change_date_format($row[4],'d-M-Y','Y-m-d'),'created_by' => $file['created_by'],'remarks' => 'general deletion','group_key' => $group_key,'file_id' => $file['id'],'status' => 'pending']);
+ $this->empEndorsementModel->save(['pk' => (int)$data['emp_policy_id'],'emp_code' => $data['emp_code'],'table_name' => 'employee_polices','actions' => 'd','name' => $data['name'],'field_name' => 'reason_for_exit','old_value' => $data['reason_for_exit'],'new_value' => $row[5],'created_by' => $file['created_by'],'remarks' => 'general deletion','group_key' => $group_key,'file_id' => $file['id'],'status' => 'pending']);
+ $this->empEndorsementModel->save(['pk' => (int)$data['emp_policy_id'],'emp_code' => $data['emp_code'],'table_name' => 'employee_polices','actions' => 'd','name' => $data['name'],'field_name' => 'status','old_value' => $data['status'],'new_value' => 'inactive','created_by' => $file['created_by'],'remarks' => 'general deletion','group_key' => $group_key,'file_id' => $file['id'],'status' => 'pending']);
};
//iterate each row
foreach ($excel_data as $col_key => $row)
@@ -669,48 +682,57 @@ class EmployeeServiceController extends AdminController
break;
}
// echo '
START- ' . $row[2];
- $employee = $this->employeeModel->where('emp_code', $row[1])->where('name',$row[2])->where('client_id',$file['client_id'])->first();
-
- $existing_endorsements = $this->empEndorsementModel->where('actions','d')
- ->where('table_name','employees')
- ->where('endorsement_id is null')
- ->where('emp_code',$employee['emp_code'])
- ->where('name',$employee['name'])
- ->where('field_name','emp_status')
- ->findAll();
-
-
- if(!count($existing_endorsements))
+ $employee = $this->employeeModel->where('emp_code', $row[1])->where('name',$row[2])->where('client_id',$file['client_id'])->where('client_branch_id',$file['client_branch_id'])->first();
+ // $employee = $this->employeeModel->where('emp_code', $row[1])->where('name',$row[2])->where('client_id',$file['client_id'])->first();
+ // dd($employee);
+ if(is_array($employee) && count($employee))
{
- if(strtolower($employee['relationship']) != 'self')
- {
-
- if(!in_array($employee['id'],$endorsement_data))//make entry in endorsement firsttime only with checking that PK of emp exisintg in variable $endorsement_data
- {
- $employee_policy = $this->employeePolicyModel->where('employee_id',$employee['id'])->where('client_policy_id',$file['policy_id'])->first();
- $data = ['emp_id' => $employee['id'],'name' => $employee['name'],'emp_status' => $employee['emp_status'],'emp_policy_id' => $employee_policy['id'],'emp_code' => $employee['emp_code'],'change_event' => $employee['change_event'],'date_of_exit' => $employee_policy['date_of_exit'],'reason_for_exit' => $employee_policy['reason_for_exit'],'status' => $employee_policy['status']];
- $endorsement($data,$file,$row);
- $endorsement_data[] = $employee['id'];
- }
- }
- else
- {
-
- $family = $this->employeeModel->getEmpFamilybyEmpCode(emp_code: $row[1],client_id: $file['client_id'],client_policy_id: $file ['policy_id'],emp_status: ['active'],policy_status: ['active']);
- // Kint::dump($family);
- foreach ($family as $key => $emp) {
-
- if(!in_array($emp['emp_id'],$endorsement_data))
- {
- $endorsement($emp,$file,$row);
-
- $endorsement_data[] = $emp['emp_id'];
-
- }
- }
+ $existing_endorsements = $this->empEndorsementModel->where('actions','d')
+ ->where('table_name','employees')
+ ->where('endorsement_id is null')
+ ->where('emp_code',$employee['emp_code'])
+ ->where('name',$employee['name'])
+ ->where('field_name','emp_status')
+ ->findAll();
+
+ if(!count($existing_endorsements))
+ {
+ if(strtolower($employee['relationship']) != 'self')
+ {
+
+ if(!in_array($employee['id'],$endorsement_data))//make entry in endorsement firsttime only with checking that PK of emp exisintg in variable $endorsement_data
+ {
+ $employee_policy = $this->employeePolicyModel->where('employee_id',$employee['id'])->where('client_policy_id',$file['policy_id'])->first();
+ $data = ['emp_id' => $employee['id'],'name' => $employee['name'],'emp_status' => $employee['emp_status'],'emp_policy_id' => $employee_policy['id'],'emp_code' => $employee['emp_code'],'change_event' => $employee['change_event'],'date_of_exit' => $employee_policy['date_of_exit'],'reason_for_exit' => $employee_policy['reason_for_exit'],'status' => $employee_policy['status']];
+ $endorsement($data,$file,$row);
+ $endorsement_data[] = $employee['id'];
+ }
+ }
+ else
+ {
+
+ $family = $this->employeeModel->getEmpFamilybyEmpCode(emp_code: $row[1],client_id: $file['client_id'],client_policy_id: $file ['policy_id'],emp_status: ['active'],policy_status: ['active']);
+ // Kint::dump($family);
+ foreach ($family as $key => $emp) {
+
+ if(!in_array($emp['emp_id'],$endorsement_data))
+ {
+ $endorsement($emp,$file,$row);
+
+ $endorsement_data[] = $emp['emp_id'];
+
+ }
+ }
+
+ }
}
}
+ else
+ {
+
+ $this->myLogger->logme("error",'{emp_code} - {name} not found',['emp_code' => $row[1],'name' => $row[2]]);
+ }
// print_r($endorsement_data);
@@ -759,7 +781,7 @@ class EmployeeServiceController extends AdminController
$field_value = ($field_name == 'dob' ? change_date_format($row[4],'d-M-Y','Y-m-d') : $row[4] );
- $employee = $this->employeeModel->where('emp_code', $row[1])->where('name',$row[2])->where('client_id',$file['client_id'])->first();
+ $employee = $this->employeeModel->where('emp_code', $row[1])->where('name',$row[2])->where('client_id',$file['client_id'])->where('client_branch_id',$file['client_branch_id'])->first();
$existing_endorsements = $this->empEndorsementModel->where('actions','c')
->where('table_name','employees')
->where('endorsement_id is null')
@@ -772,7 +794,7 @@ class EmployeeServiceController extends AdminController
if(!count($existing_endorsements))
{
$group_key = rand(100000, 999999);
- $this->empEndorsementModel->save(['pk' => (int)$employee['id'],'emp_code' => $employee['emp_code'],'table_name' => 'employees','actions' => 'c','name' => $employee['name'],'field_name' => $field_name,'old_value' => $employee[ $field_name ],'new_value' => $field_value,'created_by' => $file['created_by'],'remarks' => $row[7],'date_of_correction' => change_date_format($row[5],'d-M-Y','Y-m-d'),'group_key' => $group_key,'file_id' => $file['id']]);
+ $this->empEndorsementModel->save(['pk' => (int)$employee['id'],'emp_code' => $employee['emp_code'],'table_name' => 'employees','actions' => 'c','name' => $employee['name'],'field_name' => $field_name,'old_value' => $employee[ $field_name ],'new_value' => $field_value,'created_by' => $file['created_by'],'remarks' => $row[7],'date_of_correction' => change_date_format($row[5],'d-M-Y','Y-m-d'),'group_key' => $group_key,'file_id' => $file['id'],'status' => 'pending']);
}
@@ -819,7 +841,7 @@ class EmployeeServiceController extends AdminController
break;
}
// echo '
START- ' . $row[2];
- $employee = $this->employeeModel->where('emp_code', $row[1])->where('name',$row[2])->where('client_id',$file['client_id'])->first();
+ $employee = $this->employeeModel->where('emp_code', $row[1])->where('name',$row[2])->where('client_id',$file['client_id'])->where('client_branch_id',$file['client_branch_id'])->first();
$employee_policy = $this->employeePolicyModel->where('employee_id',$employee['id'])->where('client_policy_id',$file['policy_id'])->first();
$existing_endorsements = $this->empEndorsementModel->where('actions','si')
@@ -833,15 +855,15 @@ class EmployeeServiceController extends AdminController
//make entry in endorsement table
if(!count($existing_endorsements))
{
-
+ //transform data to send
foreach ($slab_details['slab_rates'] as $skey => $slab_value)
{
if($slab_value['si'] == $row[3])
{
$group_key = rand(100000, 999999);
- $this->empEndorsementModel->save(['pk' => (int)$employee['id'],'emp_code' => $employee['emp_code'],'table_name' => 'employee_polices','actions' => 'si','name' => $employee['name'],'field_name' => 'basic_cover_si','old_value' => $employee_policy['basic_cover_si'],'new_value' => $row[3],'created_by' => $file['created_by'],'remarks' => 'general si enhancement','group_key' => $group_key,'file_id' => $file['id']]);
- $this->empEndorsementModel->save(['pk' => (int)$employee['id'],'emp_code' => $employee['emp_code'],'table_name' => 'employee_polices','actions' => 'si','name' => $employee['name'],'field_name' => 'premium','old_value' => $employee_policy['premium'],'new_value' => $slab_value['premium'],'created_by' => $file['created_by'],'remarks' => 'general si enhancement','group_key' => $group_key,'file_id' => $file['id']]);
- $this->empEndorsementModel->save(['pk' => (int)$employee['id'],'emp_code' => $employee['emp_code'],'table_name' => 'employee_polices','actions' => 'si','name' => $employee['name'],'field_name' => 'si_enhancement_date','old_value' => null,'new_value' => change_date_format($row[4],'d-M-Y','Y-m-d'),'created_by' => $file['created_by'],'remarks' => 'general si enhancement','group_key' => $group_key,'file_id' => $file['id']]);
+ $this->empEndorsementModel->save(['pk' => (int)$employee_policy['id'],'emp_code' => $employee['emp_code'],'table_name' => 'employee_polices','actions' => 'si','name' => $employee['name'],'field_name' => 'basic_cover_si','old_value' => $employee_policy['basic_cover_si'],'new_value' => $row[3],'created_by' => $file['created_by'],'remarks' => 'general si enhancement','group_key' => $group_key,'file_id' => $file['id'],'status' => 'pending']);
+ $this->empEndorsementModel->save(['pk' => (int)$employee_policy['id'],'emp_code' => $employee['emp_code'],'table_name' => 'employee_polices','actions' => 'si','name' => $employee['name'],'field_name' => 'premium','old_value' => $employee_policy['premium'],'new_value' => $slab_value['premium'],'created_by' => $file['created_by'],'remarks' => 'general si enhancement','group_key' => $group_key,'file_id' => $file['id'],'status' => 'pending']);
+ $this->empEndorsementModel->save(['pk' => (int)$employee_policy['id'],'emp_code' => $employee['emp_code'],'table_name' => 'employee_polices','actions' => 'si','name' => $employee['name'],'field_name' => 'si_enhancement_date','old_value' => null,'new_value' => change_date_format($row[4],'d-M-Y','Y-m-d'),'created_by' => $file['created_by'],'remarks' => 'general si enhancement','group_key' => $group_key,'file_id' => $file['id'],'status' => 'pending']);
break;
}
}
@@ -867,27 +889,29 @@ class EmployeeServiceController extends AdminController
$slab_details = $this->policiesModel->getPolicySlabRatesForEmpOnboard($file['policy_id'],$file['client_id']);
foreach($familiy_data as $fkey => $value)
{
- if($file['id'] == null || $value['temp']['source'] == 'excel' || (($file['action'] == 'dependent_addition' && in_array($value['temp']['source'],[10,11]) && ($slab_details['slab_rates'][0]['premium_type'] == 1 && strtolower($value['relationship']) == 'self') || ($slab_details['slab_rates'][0]['premium_type'] == 1 || $slab_details['slab_rates'][0]['premium_type'] == null)))) //insert data come from excel and from db i.e. ( $file['id'] == null for enrollment data)
+ if($file['id'] == null || $value['temp']['source'] == 'excel' || (($file['action'] == 'dependent_addition' && ($slab_details['slab_rates'][0]['premium_type'] == 1 && strtolower($value['relationship']) == 'self') || ($slab_details['slab_rates'][0]['premium_type'] == 2 || $slab_details['slab_rates'][0]['premium_type'] == null)))) //insert data come from excel and from db i.e. ( $file['id'] == null for enrollment data)
{
- $employee = $this->employeeModel->checkExistingEmp($value);
+ $employee = $this->employeeModel->checkExistingEmp($value,$file['client_branch_id']);
$policy_data = $value['policy_details'];
$temp = $value['temp'];
unset($value['policy_details']);
unset($value['temp']);
// Kint::dump($value);
+ // Kint::dump($temp);
// Kint::dump($policy_data);
+ // echo '---------------------------------------';
+
//start implemet of si enhancement of grid type 10,11
- if(count($employee) && (($file['action'] == 'dependent_addition' && in_array($value['temp']['source'],[10,11]) && ($slab_details['slab_rates'][0]['premium_type'] == 1 && strtolower($value['relationship']) == 'self') || ($slab_details['slab_rates'][0]['premium_type'] == 2 || $slab_details['slab_rates'][0]['premium_type'] == null))))
+ if(count($employee) && $file['action'] == 'dependent_addition' && $temp['source'] == 'db' && in_array($value['temp']['grid_id'],[10,11]) && ( ($slab_details['slab_rates'][0]['premium_type'] == 1 && (strtolower($value['relationship']) == 'self' || $temp['additional_rack_rate_acting_self'])) || ($slab_details['slab_rates'][0]['premium_type'] == 2 || $slab_details['slab_rates'][0]['premium_type'] == null)))
{
+ $log_message = 'Employee record from DB,Checking SI for - '.$employee[0]['name'].'('.$employee[0]['emp_code'].')';
+ $this->myLogger->logme('error',$log_message);
$res = $this->employeesSIEnhanceProcessWhileOnbboard(employee:$employee[0],policy_data: $policy_data,file:$file);// where employee holds existing emp data and policy_data holds new si enhancement
- if(!$res)
- {
- //if endorsement not happend no need to update emp/policy details in DB.
- break;
- }
+
+ break;//skip db employee
}
- //end implemet of si enhancement of grid type 10,11
+ //end implemet of si enhancement of grid type
//save employee table
if(count($employee))
@@ -895,6 +919,7 @@ class EmployeeServiceController extends AdminController
$value['updated_by'] = $file['created_by'];
$value['id'] = $employee[0]['id'];
$value['emp_status'] = 'active';
+ $value['client_branch_id'] = $file['client_branch_id'];
$log_message = 'Update Employee - '.$employee[0]['name'].'('.$employee[0]['emp_code'].') with PK '.$employee[0]['id'];
// $this->myLogger->logme('error',('Update - ' . $employee[0]['id'].' - '. $employee[0]['emp_code'] .' - '.$employee[0]['name']));
}
@@ -902,6 +927,7 @@ class EmployeeServiceController extends AdminController
{
$value['emp_status'] = 'active';
$value['created_by'] = $file['created_by'];
+ $value['client_branch_id'] = $file['client_branch_id'];
$log_message = 'Insert Employee- '.$value['name'] .'('.$value['emp_code'] .') with PK ';
// $this->myLogger->logme('error',('Insert - ' . $value['emp_code'] .' - '. $value['name']));
}
@@ -934,7 +960,21 @@ class EmployeeServiceController extends AdminController
$this->employeePolicyModel->save($policy_data);
$emp_policy_id = $this->employeePolicyModel->getInsertID();
- if($emp_policy_id != 0){ $log_message .= ' with PK ' . $emp_policy_id; }
+ if($emp_policy_id != 0)//emp policy inserted
+ {
+ $log_message .= ' with PK ' . $emp_policy_id;
+
+ //make endorsement entry if action is addition OR Dependt addition
+ if(($file['action'] == 'dependent_addition' || $file['action'] == 'addition') && $temp['source'] == 'excel')
+ {
+ $log_message = $file['action'].' - endorsement'. $value['emp_code'].' - '.$value['name'].' - with policy id'.$emp_policy_id;
+ $this->myLogger->logme('error',$log_message);
+ $actions = ($file['action'] == 'dependent_addition' ? 'da' : ($file['action'] == 'addition' ? 'a' : NULL));
+ $addition_endorse_data = ['pk' => $emp_policy_id,'group_key' => rand(100000, 999999),'emp_code' => $value['emp_code'],'table_name' => 'employee_polices','actions' => $actions,'name' => $value['name'],'field_name' => 'basic_cover_si','old_value' => NULL,'new_value' => $policy_data['basic_cover_si'],'remarks' => 'addition endorsement','file_id' => $file['id'],'created_by' => $file['created_by']];
+ $this->employeeEndorsementforAddtionAndDependentAddition($addition_endorse_data);
+ }
+
+ }
else{ $emp_policy_id = $employee_policy[0]['id']; }
$this->myLogger->logme('error',$log_message);
@@ -943,17 +983,27 @@ class EmployeeServiceController extends AdminController
}// for end
}//function end
+
+ public function employeeEndorsementforAddtionAndDependentAddition($employee)
+ {
+ $this->empEndorsementModel->save($employee);
+ }
+
// $employee -> holds existing emp model obj and $policy_data holds new policy changes as array
public function employeesSIEnhanceProcessWhileOnbboard(array $employee,array $policy_data,array $file)
{
- $employee = $this->employeeModel->where('emp_code', $employee['emp_code'])->where('name',$employee['name'])->where('client_id',$employee['client_id'])->where('is_active',1)->first();
-
+
+ $employee = $this->employeeModel->where('emp_code', $employee['emp_code'])->where('name',$employee['name'])->where('client_id',$employee['client_id'])->where('client_branch_id',$file['client_branch_id'])->where('is_active',1)->first();
+ // Kint::dump($this->employeeModel->getLastQuery());
+ // dd($employee);
$employee_policy = $this->employeePolicyModel->where('employee_id',$employee['id'])->where('client_policy_id',$file['policy_id'])->first();
// dd($employee_policy);
- $slab_details = $this->policiesModel->getPolicySlabRatesForEmpOnboard($employee_policy['client_policy_id'],$employee['client_id']);
+ // $slab_details = $this->policiesModel->getPolicySlabRatesForEmpOnboard($employee_policy['client_policy_id'],$employee['client_id']);
+ // dd($slab_details);
+ // $temp_slab_details = ($temp['grid_type'] == 'primary' ? $slab_details['slab_rates'] : $slab_details['additional_slab_info']['slab_rates']);
//check si has changed in normal case OR check premium only changed, still treat as SI enhancement in grid type 10
- if($employee_policy['basic_cover_si'] != $policy_data['basic_cover_si'] || ($slab_details['grid_master']['ui_type'] == 10 && $policy_data['premimum'] != null && $policy_data['premimum'] != "" && $employee_policy['premimum'] != $policy_data['premimum']))
+ if($employee_policy['basic_cover_si'] != $policy_data['basic_cover_si'] || ($policy_data['premium'] != null && $policy_data['premium'] != "" && $employee_policy['premium'] != $policy_data['premium']))
{
$existing_endorsements = $this->empEndorsementModel->where('actions','si')
->where('table_name','employee_polices')
@@ -962,24 +1012,22 @@ class EmployeeServiceController extends AdminController
->where('name',$employee['name'])
->where('field_name','basic_cover_si')
->findAll();
- // dd($existing_endorsements);
//make entry in endorsement table
if(!count($existing_endorsements))
{
-
- foreach ($slab_details['slab_rates'] as $skey => $slab_value)
- {
- if($slab_value['si'] == $policy_data['basic_cover_si'])
- {
- $group_key = rand(100000, 999999);
- $this->empEndorsementModel->save(['pk' => (int)$employee['id'],'emp_code' => $employee['emp_code'],'table_name' => 'employee_polices','actions' => 'si','name' => $employee['name'],'field_name' => 'basic_cover_si','old_value' => $employee_policy['basic_cover_si'],'new_value' => $policy_data['basic_cover_si'],'created_by' => $file['created_by'],'remarks' => 'general si enhancement via DA','group_key' => $group_key,'file_id' => $file['id']]);
- $this->empEndorsementModel->save(['pk' => (int)$employee['id'],'emp_code' => $employee['emp_code'],'table_name' => 'employee_polices','actions' => 'si','name' => $employee['name'],'field_name' => 'premium','old_value' => $employee_policy['premium'],'new_value' => $slab_value['premium'],'created_by' => $file['created_by'],'remarks' => 'general si enhancement via DA','group_key' => $group_key,'file_id' => $file['id']]);
- $this->empEndorsementModel->save(['pk' => (int)$employee['id'],'emp_code' => $employee['emp_code'],'table_name' => 'employee_polices','actions' => 'si','name' => $employee['name'],'field_name' => 'si_enhancement_date','old_value' => null,'new_value' => date('Y-m-d'),'created_by' => $file['created_by'],'remarks' => 'general si enhancement via DA','group_key' => $group_key,'file_id' => $file['id']]);
- $this->myLogger->logme('error',($employee['emp_code'].' - '.$employee['name'].'- ( NEW/OLD SI - '.$employee_policy['basic_cover_si'].'/'.$policy_data['basic_cover_si'].')'. '( NEW/OLD PREMIUM - '.$employee_policy['premium'].'/'.$policy_data['premimum'].') '.' - si enhancement via DA'));
- return true; //retun true when endorsement inserted
+ $group_key = rand(100000, 999999);
+ $data = array(
+ ['pk' => (int)$employee_policy['id'],'emp_code' => $employee['emp_code'],'table_name' => 'employee_polices','actions' => 'si','name' => $employee['name'],'field_name' => 'basic_cover_si','old_value' => $employee_policy['basic_cover_si'],'new_value' => $policy_data['basic_cover_si'],'created_by' => $file['created_by'],'remarks' => 'general si enhancement via DA','group_key' => $group_key,'file_id' => $file['id']],
+ ['pk' => (int)$employee_policy['id'],'emp_code' => $employee['emp_code'],'table_name' => 'employee_polices','actions' => 'si','name' => $employee['name'],'field_name' => 'premium','old_value' => $employee_policy['premium'],'new_value' => $policy_data['premium'],'created_by' => $file['created_by'],'remarks' => 'general si enhancement via DA','group_key' => $group_key,'file_id' => $file['id']],
+ ['pk' => (int)$employee_policy['id'],'emp_code' => $employee['emp_code'],'table_name' => 'employee_polices','actions' => 'si','name' => $employee['name'],'field_name' => 'si_enhancement_date','old_value' => null,'new_value' => date('Y-m-d'),'created_by' => $file['created_by'],'remarks' => 'general si enhancement via DA','group_key' => $group_key,'file_id' => $file['id']]
+ );
- }
- }
+ $this->empEndorsementModel->insertBatch($data);
+ $this->myLogger->logme('error',($employee['emp_code'].' - '.$employee['name'].'- ( NEW/OLD SI - '.$employee_policy['basic_cover_si'].'/'.$policy_data['basic_cover_si'].')'. '( NEW/OLD PREMIUM - '.$employee_policy['premium'].'/'.$policy_data['premium'].') '.' - si enhancement via DA'));
+ $log_message = 'SI enhancement done during dependent_addition - '.$employee['name'].'('.$employee['emp_code'].')';
+ $this->myLogger->logme('error',$log_message);
+ return true; //retun true when endorsement inserted
+
}
return false; //retun false when endorsement not happend
}
@@ -1108,10 +1156,11 @@ class EmployeeServiceController extends AdminController
public function getFileMetaDataByFileId($file_id, $status = 'success'){
$data = $this->fileModel
- ->select('files.*, clients.client_name, clients.short_name, policies.name as policy_name')
+ ->select('files.*, clients.client_name, clients.short_name, policies.name as policy_name,client_branch.branch_code')
->join('clients', 'clients.id = files.client_id')
->join('client_policy', 'client_policy.id = files.policy_id')
->join('policies', 'policies.id = client_policy.policy_id')
+ ->join('client_branch', 'client_branch.id = files.client_branch_id','left')
->where('files.id', $file_id)
->first();
@@ -1124,7 +1173,7 @@ class EmployeeServiceController extends AdminController
$msg_title = 'File Upload Failure';
}
- $msg_txt = $data['client_name'] . ' - ' . $data['policy_name'] . ' - ' . ucfirst($data['action']);
+ $msg_txt = $data['client_name'] . ' ('.$data['branch_code'].') - ' . $data['policy_name'] . ' - ' . ucfirst($data['action']);
$user_id = $data['created_by'];
$url = 'employee/upload';
diff --git a/app/Controllers/JobWorker.php b/app/Controllers/JobWorker.php
index 7b26d8cb..38fd648a 100644
--- a/app/Controllers/JobWorker.php
+++ b/app/Controllers/JobWorker.php
@@ -16,10 +16,22 @@ class JobWorker extends AdminController
private static $event_class_mapping = [
'add' => ['type' => 'HC', 'handler' => 'App\\Helpers\\HttpRequestHelper'], 'sub' => ['type' => 'CC', 'handler' => 'App\\Controllers\\Jobs\SubJob'], 'fancy_date_time_format' => ['type' => 'HF', 'handler' => 'fancy_date_time_format'], 'addNumber' => ['type' => 'HC', 'handler' => 'App\\Model\\HttpRequestHelper'], 'excelFileFormatValidation' => ['type' => 'CC', 'handler' => 'App\\Controllers\\EmployeeServiceController'], 'excelFileDataValidation' => ['type' => 'CC', 'handler' => 'App\\Controllers\\EmployeeServiceController'], 'employeesOnboardPreprocess' => ['type' => 'CC', 'handler' => 'App\\Controllers\\EmployeeServiceController'], 'employeeDisembark' => ['type' => 'CC', 'handler' => 'App\\Controllers\\EmployeeServiceController'], 'employeesSIEnhanceProcess' => ['type' => 'CC', 'handler' => 'App\\Controllers\\EmployeeServiceController'], 'employeesCorrectionProcess' => ['type' => 'CC', 'handler' => 'App\\Controllers\\EmployeeServiceController'], 'send_email' => ['type' => 'HC', 'handler' => 'App\\Helpers\\MailHelper'], 'bulk_mail' => ['type' => 'HC', 'handler' => 'App\\Helpers\\MailHelper'], 'insertBatchList' => ['type' => 'CC', 'handler' => 'App\\Controllers\\EmpDataServiceController'],
+
'importInceptionFileValidation' => ['type' => 'CC', 'handler' => 'App\\Controllers\\EmpDataServiceController'],
'importInceptionUpdateTPAandUHID' => ['type' => 'CC', 'handler' => 'App\\Controllers\\EmpDataServiceController'],
'cashDepositCalculationForInception' => ['type' => 'CC', 'handler' => 'App\\Controllers\\EmpDataServiceController'],
'sendMailForDownloadingECard' => ['type' => 'CC', 'handler' => 'App\\Controllers\\EmpDataServiceController'],
+
+ 'importCorrectionValidation' => ['type' => 'CC', 'handler' => 'App\\Controllers\\EmpDataServiceController'],
+ 'importCorrectionUpdateEndorsementID' => ['type' => 'CC', 'handler' => 'App\\Controllers\\EmpDataServiceController'],
+
+ 'cashDepositCalculationForSIEnhancement' => ['type' => 'CC', 'handler' => 'App\\Controllers\\EmpDataServiceController'],
+ 'importSIEnhancementValidation' => ['type' => 'CC', 'handler' => 'App\\Controllers\\EmpDataServiceController'],
+ 'importSIEnhancementUpdateEndorsementID' => ['type' => 'CC', 'handler' => 'App\\Controllers\\EmpDataServiceController'],
+
+ 'cashDepositCalculationForDeletion' => ['type' => 'CC', 'handler' => 'App\\Controllers\\EmpDataServiceController'],
+ 'importDeletionValidation' => ['type' => 'CC', 'handler' => 'App\\Controllers\\EmpDataServiceController'],
+ 'importDeletionUpdateEndorsementID' => ['type' => 'CC', 'handler' => 'App\\Controllers\\EmpDataServiceController'],
];
public function __construct()
{
@@ -175,7 +187,16 @@ class JobWorker extends AdminController
}
$payload = is_array($payload) ? $payload : [];
- $response = $jobHandler($payload,$job->id);
+ try
+ {
+ $response = $jobHandler($payload,$job->id);
+ }
+ catch(\Exception $e)
+ {
+ $job_status = self::STATUS_FAILED;
+ $runtime = $runtime === null ? microtime(true) - $start : $runtime;
+ $response = ['file_name' => $e->getFile(),'error' => $e->getMessage(),'line_no' => $e->getLine(),'info' => $e->getTraceAsString()];
+ }
$runtime = microtime(true) - $start;
$job_status = self::STATUS_DONE;
diff --git a/app/Controllers/MasterController.php b/app/Controllers/MasterController.php
index b652d3eb..8afffb88 100644
--- a/app/Controllers/MasterController.php
+++ b/app/Controllers/MasterController.php
@@ -190,6 +190,11 @@ class MasterController extends AdminController
$uploadFilePath = ROOTPATH . 'public/uploads/logo/';
$file_name = file_Upload($this->request->getFile('insurer_logo'), $uploadFilePath);
$data = $this->request->getPost();
+
+ if($this->request->getPost('addition_add_day')){
+ $data['addition_add_day'] = 1;
+ }
+
$data['created_by'] = get_session_userid();
$data['insurer_logo'] = $file_name;
@@ -265,6 +270,12 @@ class MasterController extends AdminController
$data['insurer_logo'] = $file_name;
}
+ if($this->request->getPost('addition_add_day')){
+ $data['addition_add_day'] = 1;
+ }else{
+ $data['addition_add_day'] = 0;
+ }
+
$update = $this->insurerModel->update($id,$data);
if($update){
echo json_encode(array("status" => true , 'data' => $data));
diff --git a/app/Controllers/PendingActionsController.php b/app/Controllers/PendingActionsController.php
index 9670dbba..c7764902 100644
--- a/app/Controllers/PendingActionsController.php
+++ b/app/Controllers/PendingActionsController.php
@@ -7,20 +7,482 @@ use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;
use Psr\Log\LoggerInterface;
+use App\Helpers\DepositHelper;
+use App\Helpers\MailHelper;
+use App\Helpers\sendMailNotification;
+
+
+use App\Models\EmployeeModel;
+use App\Models\EmployeePolicyModel;
+use App\Models\ClientModel;
+use App\Models\ClientPolicyModel;
+use App\Models\BatchListModel;
+use App\Models\BatchFileModel;
+use App\Models\EmpEndorsementModel;
+
+use App\Controllers\Jobs;
+use App\Controllers\JobWorker;
+
+use CodeIgniter\API\ResponseTrait;
+
+
+
class PendingActionsController extends AdminController
{
-
+ use ResponseTrait;
+
+ protected $myLogger;
+ protected $employeeModel;
+ protected $employeePolicyModel;
+ protected $clientModel;
+ protected $clientPolicyModel;
+ protected $batchListModel;
+ protected $batchFileModel;
+ protected $empEndorsementModel;
+ protected $db;
+
public function __construct()
{
+ //section
+ set_session_context('PendingActionsController Called');
+ //services
+ $this->myLogger = \Config\Services::mylogger();
+ $this->db = \Config\Database::connect();
+
+ //models
+ $this->employeeModel = new EmployeeModel();
+ $this->employeePolicyModel = new EmployeePolicyModel();
+ $this->clientModel = new ClientModel();
+ $this->clientPolicyModel = new ClientPolicyModel();
+ $this->batchListModel = new BatchListModel();
+ $this->batchFileModel = new BatchFileModel();
+ $this->empEndorsementModel = new EmpEndorsementModel();
}
public function getPendingActions()
{
//get pending actions like inception, corrections,deletions,SI enhanccnement to users
+
+ $inception = $this->getPendingActionForInception();
+ $correction = $this->getPendingActionForCorrection();
+ $si_enhancement = $this->getPendingActionForSIEnhancement();
+ $deletion = $this->getPendingActionForDeletion();
+ $tpa = $this->getPendingActionForTPAIDEmpty();
+ $uhid = $this->getPendingActionForUHIDEmpty();
+
+ // dd($inception, $si_enhancement, $correction, $deletion, $tpa, $uhid);
+
+ $data = ['inception' => $inception, 'correction' => $correction, 'si_enhancement' => $si_enhancement, 'deletion' => $deletion, 'tpa' => $tpa, 'uhid' => $uhid];
+ return $this->respond($data);
}
+ public function getPendingActionForInception()
+ {
+ // Build the query
+ $builder = $this->db->table('client_policy cp');
+ $builder->select('
+ clients.client_name,
+ policies.name as policy_name,
+ cp.id as client_policy_id,
+ cp.client_id,
+ cp.policy_id,
+ cp.policy_type_id,
+ cp.is_addon,
+ cp.policy_status,
+ cp.open_for_enrollment,
+ cp.inception_type,
+ cb.id as branch_id,
+ cb.branch_name,
+ COUNT(ep.id) AS employee_policy_count
+ ');
+ $builder->join('employee_polices ep', 'cp.id = ep.client_policy_id AND ep.is_active = 1', 'left');
+ $builder->join('clients', 'cp.client_id = clients.id');
+ $builder->join('client_branch cb', 'cb.id = cp.client_branch_id');
+ $builder->join('policies', 'cp.policy_id = policies.id');
+ $builder->where('cp.is_active', 1);
+ $builder->where('cp.open_for_enrollment', 1);
+ $builder->where('cp.is_addon', 1);
+ $builder->where('cp.policy_status', 1);
+ $builder->where('cp.inception_type', 1);
+ $builder->whereIn('cp.policy_type_id', [1, 2, 3]);
+ $builder->groupBy('cp.id, cp.client_id, cp.policy_id, cp.policy_type_id, cp.is_addon, cp.policy_status, cp.open_for_enrollment');
+ $builder->having('employee_policy_count = 0 OR employee_policy_count IS NULL');
+
+ // Execute the query
+ $query = $builder->get();
+
+ // Fetch the results
+ $results = $query->getResultArray();
+
+ return $results;
+ }
+
+
+ public function getPendingActionForCorrection()
+ {
+
+ // Subquery for batch_export_count
+ $subQueryExport = $this->db->table('batch_files bl')
+ ->select('COUNT(*)')
+ ->where('bl.client_id = clients.id')
+ ->where('bl.actions', 'export')
+ ->where('bl.event_type', 'correction')
+ ->where('bl.insurer_or_tpa', 'tpa')
+ ->getCompiledSelect();
+
+ // Subquery for batch_import_count
+ $subQueryImport = $this->db->table('batch_files bl')
+ ->select('COUNT(*)')
+ ->where('bl.client_id = clients.id')
+ ->where('bl.actions', 'import')
+ ->where('bl.event_type', 'correction')
+ ->where('bl.insurer_or_tpa', 'tpa')
+ ->where('bl.status', 'success')
+ ->getCompiledSelect();
+
+ // Subquery builder
+ $subqueryBuilder = $this->db->table('emp_endorsement')
+ ->select('
+
+ clients.client_name as client_name,
+ clients.id as client_id,
+ client_branch.id as branch_id,
+ client_branch.branch_name,
+ emp_endorsement.id,
+ emp_endorsement.pk,
+ emp_endorsement.endorsement_id,
+ emp_endorsement.group_key,
+ emp_endorsement.emp_code,
+ emp_endorsement.table_name,
+ emp_endorsement.actions,
+ emp_endorsement.name,
+ emp_endorsement.status,
+ employees.name as ename
+ ')
+ ->join('employees', 'emp_endorsement.pk = employees.id AND employees.is_active = 1 AND employees.emp_status = \'active\'')
+ ->join('clients', 'employees.client_id = clients.id AND clients.is_active = 1', 'left')
+ ->join('client_branch', 'client_branch.id = employees.client_branch_id', 'left')
+ ->where([
+ 'emp_endorsement.actions' => 'c',
+ 'emp_endorsement.is_active' => 1,
+ 'emp_endorsement.status' => 'pending',
+ 'emp_endorsement.endorsement_id' => null
+ ])
+ ->groupBy('emp_endorsement.pk, emp_endorsement.emp_code, emp_endorsement.table_name, emp_endorsement.actions, emp_endorsement.name');
+
+ // Main query builder
+ $builder = $this->db->table('clients');
+ $builder->select("
+ subquery.client_name,
+ subquery.client_id,
+ subquery.branch_name,
+ subquery.branch_id,
+ COUNT(subquery.id) AS subquery_count,
+ ($subQueryExport) AS batch_export_count,
+ ($subQueryImport) AS batch_import_count
+ ");
+ $builder->join('(' . $subqueryBuilder->getCompiledSelect() . ') AS subquery', 'clients.id = subquery.client_id', 'left');
+ $builder->groupBy('clients.id');
+
+ // Execute the query
+ $query = $builder->get();
+
+ // Fetch the results
+ $results = $query->getResultArray();
+
+
+ $filteredResults = array_filter($results, function ($value) {
+ return $value['subquery_count'] != 0;
+ });
+
+ return $filteredResults;
+ }
+
+
+ public function getPendingActionForSIEnhancement()
+ {
+
+ // Subquery for batch_export_count
+ $subQueryExport = $this->db->table('batch_files bl')
+ ->select('COUNT(*)')
+ ->where('bl.client_id = clients.id')
+ ->where('bl.actions', 'export')
+ ->where('bl.event_type', 'si_enhancement')
+ ->where('bl.insurer_or_tpa', 'tpa')
+ ->getCompiledSelect();
+
+ // Subquery for batch_import_count
+ $subQueryImport = $this->db->table('batch_files bl')
+ ->select('COUNT(*)')
+ ->where('bl.client_id = clients.id')
+ ->where('bl.actions', 'import')
+ ->where('bl.event_type', 'si_enhancement')
+ ->where('bl.insurer_or_tpa', 'tpa')
+ ->where('bl.status', 'success')
+ ->getCompiledSelect();
+
+
+ // Build the subquery
+ $subqueryBuilder = $this->db->table('emp_endorsement')
+ ->select('
+ clients.client_name as client_name,
+ clients.id as client_id,
+ client_branch.id as branch_id,
+ client_branch.branch_name,
+ client_policy.id as client_policy_id,
+ policies.name as policy_name,
+ policies.id as pid,
+ emp_endorsement.id,
+ emp_endorsement.pk,
+ emp_endorsement.endorsement_id,
+ emp_endorsement.group_key,
+ emp_endorsement.emp_code,
+ emp_endorsement.table_name,
+ emp_endorsement.actions,
+ emp_endorsement.name,
+ emp_endorsement.status
+ ')
+ ->join('employee_polices', 'emp_endorsement.pk = employee_polices.id AND employee_polices.is_active = 1 AND employee_polices.status = \'active\'')
+ ->join('client_policy', 'employee_polices.client_policy_id = client_policy.id AND client_policy.is_active = 1 AND client_policy.policy_status = 1')
+ ->join('clients', 'client_policy.client_id = clients.id AND clients.is_active = 1')
+ ->join('client_branch', 'client_branch.id = client_policy.client_branch_id')
+ ->join('policies', 'client_policy.policy_id = policies.id AND policies.is_active = 1')
+ ->where([
+ 'emp_endorsement.actions' => 'si',
+ 'emp_endorsement.is_active' => 1,
+ 'emp_endorsement.status' => 'pending',
+ 'emp_endorsement.endorsement_id' => null
+ ])
+ ->groupBy('emp_endorsement.pk, emp_endorsement.emp_code, emp_endorsement.table_name, emp_endorsement.actions, emp_endorsement.name');
+
+ // Build the main query
+ $builder = $this->db->table('clients');
+ $builder->select("
+ clients.id,
+ subquery.client_name,
+ subquery.client_id,
+ subquery.client_policy_id,
+ subquery.policy_name,
+ subquery.branch_name,
+ subquery.branch_id,
+ COUNT(subquery.id) AS subquery_count,
+ ($subQueryExport) AS batch_export_count,
+ ($subQueryImport) AS batch_import_count
+ ");
+ $builder->join('(' . $subqueryBuilder->getCompiledSelect() . ') AS subquery', 'clients.id = subquery.client_id', 'left');
+ $builder->groupBy('clients.id');
+
+ // Execute the query
+ $query = $builder->get();
+
+ // Fetch the results
+ $results = $query->getResultArray();
+
+
+ $filteredResults = array_filter($results, function ($value) {
+ return $value['subquery_count'] != 0;
+ });
+
+ return $filteredResults;
+ }
+
+
+ public function getPendingActionForDeletion()
+ {
+
+
+ // Subquery for batch_export_count
+ $subQueryExport = $this->db->table('batch_files bl')
+ ->select('COUNT(*)')
+ ->where('bl.client_id = clients.id')
+ ->where('bl.actions', 'export')
+ ->where('bl.event_type', 'deletion')
+ ->where('bl.insurer_or_tpa', 'insurer')
+ ->getCompiledSelect();
+
+ // Subquery for batch_import_count
+ $subQueryImport = $this->db->table('batch_files bl')
+ ->select('COUNT(*)')
+ ->where('bl.client_id = clients.id')
+ ->where('bl.actions', 'import')
+ ->where('bl.event_type', 'deletion')
+ ->where('bl.insurer_or_tpa', 'insurer')
+ ->where('bl.status', 'success')
+ ->getCompiledSelect();
+
+ // Build the subquery
+ $subqueryBuilder = $this->db->table('emp_endorsement')
+ ->select('
+ clients.id as client_id,
+ clients.client_name as client_name,
+ client_branch.id as branch_id,
+ client_branch.branch_name,
+ client_policy.id as client_policy_id,
+ policies.name as policy_name,
+ policies.id as pid,
+ emp_endorsement.pk,
+ emp_endorsement.id,
+ emp_endorsement.group_key,
+ emp_endorsement.emp_code,
+ emp_endorsement.table_name,
+ emp_endorsement.actions,
+ emp_endorsement.name,
+ emp_endorsement.status
+
+ ')
+ ->join('employee_polices', 'emp_endorsement.pk = employee_polices.id AND employee_polices.is_active = 1 AND employee_polices.status = \'active\' AND emp_endorsement.table_name = \'employee_polices\'', 'left')
+ ->join('client_policy', 'employee_polices.client_policy_id = client_policy.id AND client_policy.is_active = 1 AND client_policy.policy_status = 1', 'left')
+ ->join('clients', 'client_policy.client_id = clients.id AND clients.is_active = 1', 'left')
+ ->join('client_branch', 'client_branch.id = client_policy.client_branch_id', 'left')
+ ->join('policies', 'client_policy.policy_id = policies.id AND policies.is_active = 1', 'left')
+ ->where([
+ 'emp_endorsement.actions' => 'd',
+ 'emp_endorsement.is_active' => 1,
+ 'emp_endorsement.status' => 'pending',
+ 'emp_endorsement.endorsement_id' => null,
+ 'emp_endorsement.table_name' => 'employee_polices'
+ ])
+ ->groupBy('emp_endorsement.pk, emp_endorsement.emp_code, emp_endorsement.actions, emp_endorsement.name');
+
+ // Build the main query
+ $builder = $this->db->table('clients');
+ $builder->select("
+ clients.id,
+ subquery.client_name,
+ subquery.client_id,
+ subquery.client_policy_id,
+ subquery.policy_name,
+ subquery.branch_name,
+ subquery.branch_id,
+ COUNT(subquery.id) AS subquery_count,
+ ($subQueryExport) AS batch_export_count,
+ ($subQueryImport) AS batch_import_count
+ ");
+ $builder->join('(' . $subqueryBuilder->getCompiledSelect() . ') AS subquery', 'clients.id = subquery.client_id', 'left');
+ $builder->groupBy('clients.id');
+
+ // Execute the query
+ $query = $builder->get();
+
+ // Fetch the results
+ $results = $query->getResultArray();
+
+ $filteredResults = array_filter($results, function ($value) {
+ return $value['subquery_count'] != 0;
+ });
+
+ return $filteredResults;
+ }
+
+
+ public function getPendingActionForUHIDEmpty()
+ {
+ // Subquery for batch_export_count
+ $subQueryExport = $this->db->table('batch_files bl')
+ ->select('COUNT(*)')
+ ->where('bl.client_policy_id = cp.id')
+ ->where('bl.actions', 'export')
+ ->where('bl.event_type', 'inception')
+ ->where('bl.insurer_or_tpa', 'insurer')
+ ->getCompiledSelect();
+
+ // Subquery for batch_import_count
+ $subQueryImport = $this->db->table('batch_files bl')
+ ->select('COUNT(*)')
+ ->where('bl.client_policy_id = cp.id')
+ ->where('bl.actions', 'import')
+ ->where('bl.event_type', 'inception')
+ ->where('bl.insurer_or_tpa', 'insurer')
+ ->where('bl.status', 'success')
+ ->getCompiledSelect();
+
+ // Main query
+ $query = $this->db->table('employee_polices ep')
+ ->select('c.id as client_id')
+ ->select('ep.client_policy_id')
+ ->select('c.client_name')
+ ->select('c.short_name')
+ ->select('p.name as policy_name')
+ ->select('ep.uhid')
+ ->select('cb.branch_name, cb.id as branch_id')
+ ->select("($subQueryExport) AS batch_export_count", false)
+ ->select("($subQueryImport) AS batch_import_count", false)
+ ->join('client_policy cp', 'ep.client_policy_id = cp.id AND cp.is_active = 1 AND cp.policy_status = 1')
+ ->join('clients c', 'c.id = cp.client_id')
+ ->join('client_branch cb', 'cb.id = cp.client_branch_id')
+ ->join('policies p', 'p.id = cp.policy_id')
+ ->where('ep.uhid IS NULL')
+ ->where('ep.status', 'active')
+ ->where('ep.is_active', 1)
+ ->groupBy('ep.client_policy_id, ep.uhid, c.short_name, p.name')
+ ->get();
+
+ // Fetch the results
+ $results = $query->getResultArray();
+
+ return $results;
+ }
+
+
+ public function getPendingActionForTPAIDEmpty()
+ {
+
+ // Subquery for batch_export_count
+ $subQueryExport = $this->db->table('batch_files bl')
+ ->select('COUNT(*)')
+ ->where('bl.client_policy_id = client_policy.id')
+ ->where('bl.actions', 'export')
+ ->where('bl.event_type', 'inception')
+ ->where('bl.insurer_or_tpa', 'tpa')
+ ->getCompiledSelect();
+
+ // Subquery for batch_import_count
+ $subQueryImport = $this->db->table('batch_files bl')
+ ->select('COUNT(*)')
+ ->where('bl.client_policy_id = client_policy.id')
+ ->where('bl.actions', 'import')
+ ->where('bl.event_type', 'inception')
+ ->where('bl.insurer_or_tpa', 'tpa')
+ ->where('bl.status', 'success')
+ ->getCompiledSelect();
+
+ // Build the query
+ $builder = $this->db->table('employee_polices');
+ $builder->select('
+
+ employee_polices.client_policy_id,
+ employee_polices.uhid,
+ employee_polices.tpa_id,
+ clients.short_name,
+ clients.client_name,
+ policies.name as policy_name,
+ clients.id as client_id,
+ client_branch.id as branch_id,
+ client_branch.branch_name
+ ');
+ $builder->select("($subQueryExport) AS batch_export_count", false);
+ $builder->select("($subQueryImport) AS batch_import_count", false);
+
+ $builder->join('client_policy', 'employee_polices.client_policy_id = client_policy.id AND client_policy.is_active = 1 AND client_policy.policy_status = 1');
+ $builder->join('clients', 'clients.id = client_policy.client_id');
+ $builder->join('client_branch', 'client_branch.id = client_policy.client_branch_id');
+ $builder->join('policies', 'policies.id = client_policy.policy_id');
+ $builder->where('employee_polices.tpa_id', null);
+ $builder->where('employee_polices.uhid IS NOT NULL');
+ $builder->where('employee_polices.status', 'active');
+ $builder->where('employee_polices.is_active', 1);
+ $builder->groupBy('employee_polices.client_policy_id');
+
+ // Execute the query
+ $query = $builder->get();
+
+ // Fetch the results
+ $results = $query->getResultArray();
+
+ return $results;
+ }
}
diff --git a/app/Controllers/RestAuthenticationController.php b/app/Controllers/RestAuthenticationController.php
index 3af70fc4..72e7b8c7 100644
--- a/app/Controllers/RestAuthenticationController.php
+++ b/app/Controllers/RestAuthenticationController.php
@@ -101,7 +101,7 @@ class RestAuthenticationController extends AdminController
$auth = HttpRequestHelper::getRequestInfo();
if ($auth) {
$data = [
- 'user_id' => $employeeData['id'],
+ 'user_id' => $employeeData['id'],
'user_type' => 'employee',
'ip' => $auth['ip'],
'platform' => $auth['platform'],
diff --git a/app/Controllers/UserController.php b/app/Controllers/UserController.php
index 5d1f2813..184cbefa 100644
--- a/app/Controllers/UserController.php
+++ b/app/Controllers/UserController.php
@@ -58,9 +58,33 @@ class UserController extends AdminController
$userData = $this->request->getPost();
$userData['created_by'] = get_session_userid();
+ $temp_team = $userData['team'];
unset($userData['team']);
$insert = $this->userModel->insert($userData);
if($insert){
+ $db = \Config\Database::connect();
+ $tableName = 'hdz_staff';
+
+ if($userData['role'] == 1){
+ $admin = 1;
+ }else{
+ $admin = 0;
+ }
+ foreach ($temp_team as $key => $value) {
+ if($value == 2){
+ $hdz_staff = [
+ 'emp_code' => $userData['emp_code'],
+ 'fullname' => $userData['first_name'],
+ 'username' => strtolower($userData['first_name']),
+ 'email' => $userData['email'],
+ 'admin' => $admin,
+ 'registration' => time(),
+ ];
+
+ $db->table($tableName)->insert($hdz_staff);
+ }
+ }
+
$teamData['user_id'] = $insert ;
foreach ($teams as $value) {
$teamData['team_id'] = $value;
@@ -99,6 +123,35 @@ class UserController extends AdminController
$update = $this->userModel->where('id', $id )->set($userData)->update();
if($update){
+
+ $db = \Config\Database::connect();
+ $tableName = 'hdz_staff';
+
+ if($userData['role'] == 1){
+ $admin = 1;
+ }else{
+ $admin = 0;
+ }
+
+ foreach ($userData['team'] as $key => $value) {
+ if($value == 2){
+ $hdz_staff = [
+ 'emp_code' => $userData['emp_code'],
+ 'fullname' => $userData['first_name'],
+ 'username' => strtolower($userData['first_name']),
+ 'email' => $userData['email'],
+ 'admin' => $admin,
+ ];
+
+
+ $db->table($tableName)->where('emp_code', $userData['emp_code'])
+ ->where('email', $userData['email'])
+ ->set($userData)
+ ->update();
+ }
+ }
+
+
$this->userTeamsModel->where('user_id', $id)->delete();
if($teams){
$teamData['user_id'] = $id ;
@@ -120,6 +173,12 @@ class UserController extends AdminController
$deactive = $model->where('id', $id)->set(['is_active' => 0])->update();
if($deactive)
{
+ // $db = \Config\Database::connect();
+ // $tableName = 'hdz_staff';
+
+ // $db->table($tableName)->insert($hdz_staff);
+
+
echo json_encode(array("status" => true));
}else{
echo json_encode(array("status" => false));
diff --git a/app/Filters/AuthJWT.php b/app/Filters/AuthJWT.php
index a9b6911f..193ad6ec 100644
--- a/app/Filters/AuthJWT.php
+++ b/app/Filters/AuthJWT.php
@@ -12,6 +12,7 @@ use ReflectionClass;
require_once('../vendor/autoload.php');
+use App\Models\EmployeeModel;
class AuthJWT implements FilterInterface
@@ -19,19 +20,27 @@ class AuthJWT implements FilterInterface
public function before(RequestInterface $request, $arguments = null)
{
$jwt = $request->getHeader('Authorization');
+ $model = new EmployeeModel();
if ($jwt) {
if (JWTToken::validateJWT($jwt)) {
$data = JWTToken::validateJWT($jwt);
$data = json_decode($data);
- if ($data->status) {
- // $auth = $request->getHeader("Authorization");
-
+
+ $id = $data->decoded->id;
+ $user_data = $model->where('id', $id)->first();
+
+ if($user_data['token_time_out'] > time()){
+ $data =["token_time_out" => time() + getenv('TOKENTIMEOUT') ];
+ $model->update($id, $data);
return true;
}else{
+ $data =["token_time_out" => ''];
+ $model->update($id, $data);
header('Content-Type: application/json');
http_response_code(401);
- $error = json_encode(["status" => 401, "message" => $data->message]);
+ // $error = json_encode(["status" => 401, "message" => $data->message]);
+ $error = json_encode(["status" => 401, "message" => "Token is Invalid"]);
echo $error;
exit;
}
diff --git a/app/Filters/CloseDbConnection.php b/app/Filters/CloseDbConnection.php
new file mode 100644
index 00000000..ad49eb86
--- /dev/null
+++ b/app/Filters/CloseDbConnection.php
@@ -0,0 +1,25 @@
+logme('error','CloseDbConnections....!');
+ $db->close();
+ }
+}
diff --git a/app/Helpers/JWTToken.php b/app/Helpers/JWTToken.php
index 6c6d29cf..592c38f8 100644
--- a/app/Helpers/JWTToken.php
+++ b/app/Helpers/JWTToken.php
@@ -12,27 +12,28 @@ use Firebase\JWT\SignatureInvalidException;
use CodeIgniter\HTTP\RequestInterface;
use ReflectionClass;
+use App\Models\EmployeeModel;
class JWTToken
{
public static function encode($data =null)
{
- $secret_Key="secret";
- $iat = time();
- $exp = $iat + 36000;
- $request_data = [
- "iat" => $iat,
- "exp" => $exp,
- ];
- if ($data !== null) {
- $request_data = array_merge($request_data, (array)$data);
- }
- try{
- $token = JWT::encode($request_data ,$secret_Key,'HS512');
+ $secret_Key ="secret";
- return $token;
- // return ['status' => true,'token' => $token];
+ $request_data = (array)$data;
+
+ try{
+ $token = JWT::encode($request_data ,$secret_Key,'HS512');
+
+ $model = new EmployeeModel();
+ $id = $request_data['id'];
+ $data =[
+ "token_time_out" => time() + getenv('TOKENTIMEOUT')
+ ];
+ $model->update($id, $data);
+
+ return $token;
}
catch (Exception $e) {
return ['status' => false,'message' => $e->getMessage()];
diff --git a/app/Helpers/excel_import_export_helper.php b/app/Helpers/excel_import_export_helper.php
index 5c29ce41..65e44eaa 100644
--- a/app/Helpers/excel_import_export_helper.php
+++ b/app/Helpers/excel_import_export_helper.php
@@ -212,10 +212,10 @@ if (! function_exists('transform_objects_to_array_for_si_enhancement')) {
$obj->no_of_days,
$obj->old_si_premium,
$obj->new_si_premium,
- $obj->difference_premium,
+ round($obj->difference_premium, 2),
$obj->pro_rata_premimum,
$obj->gst,
- $obj->total ,
+ round($obj->total, 2),
$endorsement_id,
];
@@ -359,7 +359,7 @@ if (!function_exists('read_excel_file_to_array')) {
if (! function_exists('generate_filename')) {
- function generate_filename($client_short_name, $event_type, $actions, $insurer_or_tpa, $policy_name) {
+ function generate_filename($client_short_name, $event_type, $actions, $insurer_or_tpa, $policy_name, $branch_code) {
$evenTypeLabel = '';
if($event_type == 'inception'){
@@ -387,9 +387,10 @@ if (! function_exists('generate_filename')) {
$currentDateTime = new DateTime('now', new DateTimeZone('Asia/Kolkata'));
$formattedDateTime = $currentDateTime->format('d-m-Y_H-i-s');
$policy_name = str_replace(' ', '_', $policy_name);
+ $branch_code = isset($branch_code) ? str_replace(' ', '_', $branch_code) : '_';
// Generate file name
- $file_name = $client_short_name. '_' . $policy_name . '_' . $insurer_or_tpa_lable . $actions . $evenTypeLabel . '_' . $formattedDateTime . '.xlsx';
+ $file_name = $client_short_name. '_' . $branch_code . '_' . $policy_name . '_' . $insurer_or_tpa_lable . $actions . $evenTypeLabel . '_' . $formattedDateTime . '.xlsx';
return $file_name;
}
}
diff --git a/app/Helpers/excel_util_helper.php b/app/Helpers/excel_util_helper.php
index e4561843..ca88b7f1 100644
--- a/app/Helpers/excel_util_helper.php
+++ b/app/Helpers/excel_util_helper.php
@@ -1,19 +1,27 @@
diff($passedDateTime);
+ $interval = $currentDateTime->diff($passedDateTime);
+ // $totalDays = $interval->days;
+ // if ($include_start_date) {
+ // $totalDays += 1;
+ // }
+ //$interval->totalDays = $totalDays;
+ return $interval;
+
}
}
@@ -193,35 +201,43 @@ if(!function_exists('check_si'))
if(!$is_si_found && $slab_value['si'] == $received_si) //match si amount
{
+ // echo 'found';
$is_si_found = true;
}
// check age slab
- if($row[3] != null && DateTime::createFromFormat('d-M-Y', $row[3]) !== false)// dob
+ if(in_array(strtoupper($row['current_action']), ['I','A','DA']))
{
- $dob = change_date_format($row[3],'d-M-Y','Y-m-d');
- // echo $row[3].' - '.$dob;echo '
';
- $currentDateTime = new DateTime();//die();
- $passedDateTime = new DateTime($dob);
- $interval = $currentDateTime->diff($passedDateTime);
- if(!$is_age_slab_found)
+ if($row[3] != null && DateTime::createFromFormat('d-M-Y', $row[3]) !== false)// dob
{
- if(isset($slab_value['age_from']) && isset($slab_value['age_to']))
+ $dob = change_date_format($row[3],'d-M-Y','Y-m-d');
+ // echo $row[3].' - '.$dob;echo '
';
+ $currentDateTime = new DateTime();//die();
+ $passedDateTime = new DateTime($dob);
+ $interval = $currentDateTime->diff($passedDateTime);
+ if(!$is_age_slab_found)
{
- if($slab_value['age_from'] !== null && $slab_value['age_to'] !== null && $slab_value['age_from'] <= $interval->y && $slab_value['age_to'] >= $interval->y && $slab_value['si'] == $received_si)
+ if(isset($slab_value['age_from']) && isset($slab_value['age_to']))
{
- $is_age_slab_found = true;// send true if age slab found
+ if($slab_value['age_from'] !== null && $slab_value['age_to'] !== null && $slab_value['age_from'] <= $interval->y && $slab_value['age_to'] >= $interval->y && $slab_value['si'] == $received_si)
+ {
+ $is_age_slab_found = true;// send true if age slab found
+ }
}
+ else
+ {
+ $is_age_slab_found = true;// send true if age conditin is not applicable
+ }
+
}
- else
- {
- $is_age_slab_found = true;// send true if age conditin is not applicable
- }
-
}
+ }
+ else
+ {
+ $is_age_slab_found = true;// send true if age conditin is not applicable
}//end of check age slab
- }
+ }// end of for loop
}
@@ -405,15 +421,17 @@ if (!function_exists('name_and_empid_check_in_db'))
foreach ($family_data as $rkey => $row)
{
- if(isset($row['temp']) && $row['temp']['source'] != 'db')
- {
+ if($current_action != 'dependent_addition' || (isset($row['temp']) && $row['temp']['source'] != 'db'))
+ {
$res = $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("cp.id",$policy_id)
+ ->where("cp.id",$policy_id)
->where("employees.client_id",$client_id)
->where("employees.is_active",1)
+ ->where("employees.emp_status",'active')
->where("ep.is_active",1)
+ ->where("ep.status",'active')
// ->where("ep.client_id",$client_id)
->where('name',$row[2])->where('emp_code',$row[1])
->findAll();
@@ -585,8 +603,9 @@ if (!function_exists('generate_relationship_code'))
$relationship = ['self' => 1,'spouse' => 2,'son' => 3,'daughter' => 4,'father' => 5,'mother' => 6,'father-in-law' => 7,'mother-in-law' => 8];
$slug = \Config\Services::slug();
$relationship_code = $slug->slugify($arr['relationship']);
+ $emp_type_code = ($relationship_code == 'self' ? 'EMP_TYP_01' : 'EMP_TYP_03');
$relationship_code = $gender[ $arr['gender'] ] . $relationship[ $relationship_code ] ;
- return $relationship_code;
+ return ['relationship_code' => $relationship_code,'emp_type_code' => $emp_type_code];
}
}
@@ -594,28 +613,90 @@ if (!function_exists('calculate_premimum'))
{
function calculate_premimum($family_data,$policy_terms,$slab_details,$fileArr,$default_si = null)
{
-//
- // dd($slab_details);
- // grid type
- // 1 = premium => si
+ // dd($family_data);
+ $slug = \Config\Services::slug();
$result = [];
- $grid_type = $slab_details['grid_master']['ui_type'];
- $fileArr['grid_type'] = $grid_type;
+ $primary_grid_type = $slab_details['grid_master']['ui_type'];
+
+ //gather detailes for additional rack info
+ $additional_grid_type = isset($slab_details['additional_slab_info']['grid_master']['ui_type']) ? $slab_details['additional_slab_info']['grid_master']['ui_type'] : null;
+ // dd(isset($slab_details['additional_slab_info']['grid_master']['ui_type']));
+ $policy_terms_json = ($policy_terms['policy_terms']);
+ $policy_terms_json = (array) json_decode($policy_terms_json);
+ // dd($policy_terms);
+ $primary_rack_rate_applicable_familiy_members = ['self'];
+ if(isset($policy_terms_json['family_floaters']))
+ {
+ $primary_rack_rate_applicable_familiy_members = generate_family_relationship_array((array)$policy_terms_json['family_floaters']);
+ }
+
+ $additional_grid_type_applicable_familiy_members = [];
+ if($additional_grid_type != null)
+ {
+ $additional_grid_type_applicable_familiy_members = (array)json_decode($slab_details['additional_slab_info']['slab_rates'][0]['additional_relationship']);
+ $additional_grid_type_applicable_familiy_members = generate_family_relationship_array($additional_grid_type_applicable_familiy_members);
+ }
+ // Kint::dump($primary_rack_rate_applicable_familiy_members);
+ // Kint::dump($additional_grid_type_applicable_familiy_members);
+ //remove common family members in primary array
+ $primary_rack_rate_applicable_familiy_members = array_diff($primary_rack_rate_applicable_familiy_members,$additional_grid_type_applicable_familiy_members);
+ // dd($primary_rack_rate_applicable_familiy_members);
+
+
+
//this variable for store emp id and their band for emp band level premium calculation for all famility members (especially for grid type 9) also store max age and max count of a familiy for grid type 10,11
$emp_details_with_empband_max_age_max_count = [];
- //max age amoung familiy
- $max_age = max(array_map(function($item) {return calculate_days_bw_dates(from_date: $item[3])->y; }, $family_data));
+ //find max age and max count of family members for both primary and additional grid type
+ $max_age_and_count = (array_reduce($family_data,function($max_age,$family_member) use ($primary_rack_rate_applicable_familiy_members,$slug) {
+
+ if( in_array($slug->slugify($family_member[5]), $primary_rack_rate_applicable_familiy_members))
+ {
+ $max_age['primary_rack_rate_max_age'][] = calculate_days_bw_dates(from_date: $family_member[3])->y;
+ $max_age['primary_rack_rate_max_count'] = $max_age['primary_rack_rate_max_count'] + 1;
+ }
+ else
+ {
+ $max_age['additional_rack_rate_max_age'][] = calculate_days_bw_dates(from_date: $family_member[3])->y;
+ $max_age['additional_rack_rate_max_count'] = $max_age['additional_rack_rate_max_count'] + 1;
+ }
+ return $max_age;
+ }, ['primary_rack_rate_max_age' => [], 'additional_rack_rate_max_age' => [],'primary_rack_rate_max_count' => 0,'additional_rack_rate_max_count' => 0]));
+
+ $get_max_age_or_count = function($relationship,$flag) use ($slug, $primary_rack_rate_applicable_familiy_members, $max_age_and_count)
+ {
+ if(in_array($slug->slugify($relationship),$primary_rack_rate_applicable_familiy_members))
+ {
+ return $flag == 'age' ? max($max_age_and_count['primary_rack_rate_max_age']) : $max_age_and_count['primary_rack_rate_max_count'];
+ }
+ return $flag == 'age' ? max($max_age_and_count['additional_rack_rate_max_age']) : $max_age_and_count['additional_rack_rate_max_count'];
+ };
+
+
+ $get_current_member_grid_type = function($relationship) use ($slug, $primary_rack_rate_applicable_familiy_members,$primary_grid_type,$additional_grid_type)
+ {
+ if(in_array($slug->slugify($relationship),$primary_rack_rate_applicable_familiy_members))
+ {
+ return ['type' => 'primary','grid_id' => $primary_grid_type];
+ }
+ return ['type' => 'additional','grid_id' => $additional_grid_type];
+ };
+ // Kint::dump($max_age_and_count);dd();
foreach($family_data as $fkey => $member)
{
+ //get grid type either primary or additional based on current member relationship available in primary_rack_rate_applicable_familiy_members or not. if yes then primaty grid type else additional grid type
+ $current_grid_info = $get_current_member_grid_type($member[5]);
+ $fileArr['grid_info'] = $current_grid_info;
//transform as db row column
$transformed_familiy_member_data = transform_excel_data_to_db($member,$fileArr);
// dd($transformed_familiy_member_data);
+
//store emp id and emp band and attach it to their familiy members where band is always empty
$emp_details_with_empband_max_age_max_count[ $transformed_familiy_member_data['emp_code'] ]['band'] = isset($emp_details_with_empband_max_age_max_count[ $transformed_familiy_member_data['emp_code'] ]['band']) ? $emp_details_with_empband_max_age_max_count[ $transformed_familiy_member_data['emp_code'] ]['band'] : NULL;
$emp_details_with_empband_max_age_max_count[ $transformed_familiy_member_data['emp_code'] ]['si'] = isset($emp_details_with_empband_max_age_max_count[ $transformed_familiy_member_data['emp_code'] ]['si']) ? $emp_details_with_empband_max_age_max_count[ $transformed_familiy_member_data['emp_code'] ]['si'] : NULL;
+ //get emp band and si from self and make it available for whole family
if(strtolower($transformed_familiy_member_data['relationship']) == 'self')
{
$emp_details_with_empband_max_age_max_count[ $transformed_familiy_member_data['emp_code'] ]['band'] = $transformed_familiy_member_data['band'];
@@ -623,14 +704,38 @@ if (!function_exists('calculate_premimum'))
}
//end of store emp id and emp band and attach it to their familiy members where band is always empty
- $emp_details_with_empband_max_age_max_count[ $transformed_familiy_member_data['emp_code'] ]['maxcount'] =count($family_data);
+ $emp_details_with_empband_max_age_max_count[ $transformed_familiy_member_data['emp_code'] ]['maxcount'] = $get_max_age_or_count($transformed_familiy_member_data['relationship'],'count');
- $emp_details_with_empband_max_age_max_count[ $transformed_familiy_member_data['emp_code'] ]['maxage'] = $max_age;
+ $emp_details_with_empband_max_age_max_count[ $transformed_familiy_member_data['emp_code'] ]['maxage'] = $get_max_age_or_count($transformed_familiy_member_data['relationship'],'age');
+
+ //set additional_rack_rate_acting_self in emp_details_with_empband_max_age_max_count array
+ $transformed_familiy_member_data['temp']['additional_rack_rate_acting_self'] = false;
+ if(!isset($emp_details_with_empband_max_age_max_count[ $transformed_familiy_member_data['emp_code'] ]['additional_rack_rate_acting_self']) && $current_grid_info['type'] == 'additional')
+ {
+
+ if($transformed_familiy_member_data['temp']['action'] != 'DA')
+ {
+ $transformed_familiy_member_data['temp']['additional_rack_rate_acting_self'] = true;
+ $emp_details_with_empband_max_age_max_count[ $transformed_familiy_member_data['emp_code'] ]['additional_rack_rate_acting_self'] = true;
+ }
+ else// if dependent addition then set employee from db is an acting self
+ {
+
+ if($transformed_familiy_member_data['temp']['source'] == 'db' && $transformed_familiy_member_data['temp']['rata_premimum'])
+ {
+ // echo 'SETTING';
+ $transformed_familiy_member_data['temp']['additional_rack_rate_acting_self'] = true;
+ $emp_details_with_empband_max_age_max_count[ $transformed_familiy_member_data['emp_code'] ]['additional_rack_rate_acting_self'] = true;
+ }
+ }
+ }
//generate relationship code
if($transformed_familiy_member_data['temp']['action'] != 'D' && $transformed_familiy_member_data['temp']['action'] != 'C' && $transformed_familiy_member_data['temp']['action'] != 'SI')
{
- $transformed_familiy_member_data['relationship_code'] = generate_relationship_code($transformed_familiy_member_data);
+ $temp_res = generate_relationship_code($transformed_familiy_member_data);
+ $transformed_familiy_member_data['relationship_code'] = $temp_res['relationship_code'];
+ $transformed_familiy_member_data['emp_type'] = $temp_res['emp_type_code'];
}
//calculate primimum based on grid type
@@ -642,17 +747,46 @@ if (!function_exists('calculate_premimum'))
$transformed_familiy_member_data['temp']['maxage'] = $emp_details_with_empband_max_age_max_count[ $transformed_familiy_member_data['emp_code'] ]['maxage'];
$transformed_familiy_member_data['temp']['maxcount'] = $emp_details_with_empband_max_age_max_count[ $transformed_familiy_member_data['emp_code'] ]['maxcount'];
- $transformed_familiy_member_data['policy_details']['basic_cover_si'] = isset($emp_details_with_empband_max_age_max_count[ $transformed_familiy_member_data['emp_code'] ]['si']) ? $emp_details_with_empband_max_age_max_count[ $transformed_familiy_member_data['emp_code'] ]['si'] : $transformed_familiy_member_data['policy_details']['basic_cover_si'];
+ //set self si to all familiy members, except they've come from DB
+ // if(isset($emp_details_with_empband_max_age_max_count[ $transformed_familiy_member_data['emp_code'] ]['si']))
+ // {
+ if($transformed_familiy_member_data['temp']['source'] != 'db')
+ {
+ $transformed_familiy_member_data['policy_details']['basic_cover_si'] = isset($emp_details_with_empband_max_age_max_count[ $transformed_familiy_member_data['emp_code'] ]['si']) ? $emp_details_with_empband_max_age_max_count[ $transformed_familiy_member_data['emp_code'] ]['si'] : $transformed_familiy_member_data['policy_details']['basic_cover_si'];
+ }
+ // }
+
- if( $fileArr['id'] == null || $transformed_familiy_member_data['temp']['source'] == 'excel' || ($fileArr['action'] == 'dependent_addition' && in_array($grid_type,[10,11]) && $slab_details['slab_rates'][0]['premium_type'] == 1 && strtolower($transformed_familiy_member_data['relationship']) == 'self'))//if file id is null then data coming from enrollment (from DB) otherwise data coming from xcel, so calculate only data from excel (new entry) note: even data coming from excel for event dependet additon we fetch other dependts from db and calculate premium for whole family
- {
+ // this array hold conditions to allow calculate premium amt
+ $conditions = [
+ 'isEmployeeSourceEnrollment' => $fileArr['id'] == null,
+ 'isEmployeeSourceExcelFile' => $transformed_familiy_member_data['temp']['source'] == 'excel',
+ 'isCurrentActionDependentAddition' => $fileArr['action'] == 'dependent_addition',
+ 'isPrimaryGridType' => $transformed_familiy_member_data['temp']['grid_type'] == 'primary',
+ 'isAdditionalGridType' => $transformed_familiy_member_data['temp']['grid_type'] == 'additional',
+ 'isPrimaryGridPremiumTypeSingle' => $slab_details['slab_rates'][0]['premium_type'] == 1,
+ 'isAdditionalPremiumTypeSingle' => isset($slab_details['additional_slab_info']['slab_rates'][0]['premium_type']) ? ( $slab_details['additional_slab_info']['slab_rates'][0]['premium_type'] == 1) : 0,
+ 'isCurrentRelationshipSelf' => strtolower($transformed_familiy_member_data['relationship']) == 'self',
+ 'isBasicCoverCalculatedToCurrentEmployee' => ($transformed_familiy_member_data['policy_details']['basic_cover_si'] != null && $transformed_familiy_member_data['policy_details']['basic_cover_si'] != 0)
+ ];
+ // Kint::dump($transformed_familiy_member_data['policy_details']);
+ // echo ($transformed_familiy_member_data['policy_details']['basic_cover_si'] != null && $transformed_familiy_member_data['policy_details']['basic_cover_si'] != 0);
+ // echo ($conditions['isBasicCoverCalculatedToCurrentEmployee']);
+ // echo "
";
+ // same logic for both primay and additional grid type
+ $primaryGridTypeCondition = $conditions['isCurrentActionDependentAddition'] && $conditions['isPrimaryGridType'] && $conditions['isPrimaryGridPremiumTypeSingle'] && $conditions['isCurrentRelationshipSelf'];
+ $additionalGridTypeCondition = $conditions['isCurrentActionDependentAddition'] && $conditions['isAdditionalGridType'] && $conditions['isAdditionalPremiumTypeSingle'] && $conditions['isBasicCoverCalculatedToCurrentEmployee'];
+
+ // Final combined condition
+ if ($conditions['isEmployeeSourceEnrollment'] || $conditions['isEmployeeSourceExcelFile'] || $primaryGridTypeCondition || $additionalGridTypeCondition) {
+
$transformed_familiy_member_data = premium_calculation_manager($transformed_familiy_member_data,$policy_terms,$slab_details,$default_si);
$result[] = $transformed_familiy_member_data;
}
}
}
-
+ // Kint::dump($emp_details_with_empband_max_age_max_count);
return $result;
}
}
@@ -702,13 +836,15 @@ if (!function_exists('transform_excel_data_to_db'))
$result['file_id'] = $actionArr['id'];
$result['client_id'] = $actionArr['client_id'];
$result['change_event'] = $memArr[15];
- $result['temp']['grid_type'] = $actionArr['grid_type'];
+ $result['temp']['grid_type'] = $actionArr['grid_info']['type'];
+ $result['temp']['grid_id'] = $actionArr['grid_info']['grid_id'];
$result['temp']['action'] = isset($memArr['current_action']) ? $memArr['current_action'] : $current_column_action;
$result['temp']['source'] = isset($memArr['temp']['source']) ? $memArr['temp']['source'] : 'excel';
$result['temp']['emp_id'] = isset($memArr['temp']['emp_id']) ? $memArr['temp']['emp_id'] : null;
$result['temp']['emp_policy_id'] = isset($memArr['temp']['emp_policy_id']) ? $memArr['temp']['emp_policy_id'] : null;
$result['temp']['policy_status'] = isset($memArr['temp']['policy_status']) ? $memArr['temp']['policy_status'] : null;
$result['temp']['emp_status'] = isset($memArr['temp']['emp_status']) ? $memArr['temp']['emp_status'] : null;
+ $result['temp']['rata_premimum'] = isset($memArr['temp']['rata_premimum']) ? $memArr['temp']['rata_premimum'] : 0;
$result['policy_details'] = $policy;
return $result;
@@ -722,11 +858,12 @@ if (!function_exists('premium_calculation_manager'))
{
function premium_calculation_manager($emp_data,$policy_terms,$slab_details,$default_si = null)
{
+ // Kint::dump($emp_data);
$myLogger = \Config\Services::mylogger();
// grid type
// 1 = premium => si
- // dd($emp_data);
+ // Kint::dump($emp_data);
//check if the data comes from enrollment (DB) and status is draft then fetch original data of employee from
//audit history table then initiate calculation with it. so this data again get updated in emp table
@@ -758,23 +895,36 @@ if (!function_exists('premium_calculation_manager'))
//gird and calculation start
$slug = \Config\Services::slug();
- $grid_type = $slab_details['grid_master']['ui_type'];
+ $grid_type = $emp_data['temp']['grid_id'];
+ $temp_slab_rates = $emp_data['temp']['grid_type'] == 'primary' ? $slab_details['slab_rates'] : $slab_details['additional_slab_info']['slab_rates'];
+
+ //if curent action is dependent addition OR addition then pull insurer master to set whether add one day from employee date of coverage
+ if($emp_data['temp']['action'] == 'DA' || $emp_data['temp']['action'] == 'A')
+ {
+ $insurer = new InsurerModel();
+ $insurer = ($insurer->find($policy_terms['insurer_id']));
+ if($insurer['addition_add_day'] == true)
+ {
+ $emp_data['policy_details']['date_coverage'] = (new DateTime($emp_data['policy_details']['date_coverage']))->modify('+1 day')->format('Y-m-d');
+ }
+ }
+ // dd($emp_data);
$is_match_found = false;
switch ($grid_type) {
case "1":
//GPA - Sum Insured (SI) * Multiplier
$employee_received_si = $default_si == null ? $emp_data['policy_details']['basic_cover_si'] : $default_si;
$employee_received_band = $emp_data['temp']['band'];
- foreach ($slab_details['slab_rates'] as $skey => $slab_value)
+ foreach ($temp_slab_rates as $skey => $slab_value)
{
if(($slab_value['si'] == $employee_received_si) || ($slab_value['grade'] != null && $slab_value['grade'] == $employee_received_band && $slab_value['si'] == $employee_received_si))
{
$emp_data['policy_details']['basic_cover_si'] = $slab_value['si'];
$emp_data['policy_details']['date_coverage'] = (isset($emp_data['policy_details']['date_coverage']) ? $emp_data['policy_details']['date_coverage'] : $policy_terms['policy_start_date']);
$emp_data['policy_details']['policy_end_date'] = $policy_terms['policy_end_date'];
- $emp_data['policy_details']['days'] = calculate_days_bw_dates($emp_data['policy_details']['date_coverage'],$policy_terms['policy_end_date'])->days;
+ $emp_data['policy_details']['days'] = (calculate_days_bw_dates($emp_data['policy_details']['date_coverage'],$policy_terms['policy_end_date'])->days + 1);
$emp_data['policy_details']['premium'] = $slab_value['premium'];
- $emp_data['policy_details']['rata_premimum'] = calculate_pro_rata_premimum($slab_value['premium'],$emp_data['policy_details']['days']);
+ $emp_data['policy_details']['rata_premimum'] = calculate_pro_rata_premimum($emp_data['policy_details']['premium'],$emp_data['policy_details']['days'],(calculate_days_bw_dates($policy_terms['policy_start_date'],$policy_terms['policy_end_date'])->days + 1));
$emp_data['policy_details']['gst'] = (float) number_format(($emp_data['policy_details']['rata_premimum'] * (18/100)),2,'.','');
$is_match_found = true;
break;
@@ -785,16 +935,16 @@ if (!function_exists('premium_calculation_manager'))
case "2":
//GPA - Flat Rate for all SI
$employee_received_si = $default_si == null ? $emp_data['policy_details']['basic_cover_si'] : $default_si;
- foreach ($slab_details['slab_rates'] as $skey => $slab_value)
+ foreach ($temp_slab_rates as $skey => $slab_value)
{
if($slab_value['si'] == $employee_received_si)
{
$emp_data['policy_details']['basic_cover_si'] = $slab_value['si'];
$emp_data['policy_details']['date_coverage'] = (isset($emp_data['policy_details']['date_coverage']) ? $emp_data['policy_details']['date_coverage'] : $policy_terms['policy_start_date']);
$emp_data['policy_details']['policy_end_date'] = $policy_terms['policy_end_date'];
- $emp_data['policy_details']['days'] = calculate_days_bw_dates($emp_data['policy_details']['date_coverage'],$policy_terms['policy_end_date'])->days;
+ $emp_data['policy_details']['days'] = (calculate_days_bw_dates($emp_data['policy_details']['date_coverage'],$policy_terms['policy_end_date'])->days + 1);
$emp_data['policy_details']['premium'] = $slab_value['premium'];
- $emp_data['policy_details']['rata_premimum'] = calculate_pro_rata_premimum($slab_value['premium'],$emp_data['policy_details']['days']);
+ $emp_data['policy_details']['rata_premimum'] = calculate_pro_rata_premimum($emp_data['policy_details']['premium'],$emp_data['policy_details']['days'],(calculate_days_bw_dates($policy_terms['policy_start_date'],$policy_terms['policy_end_date'])->days + 1));
$emp_data['policy_details']['gst'] = (float) number_format(($emp_data['policy_details']['rata_premimum'] * (18/100)),2,'.','');
$is_match_found = true;
break;
@@ -804,16 +954,16 @@ if (!function_exists('premium_calculation_manager'))
case "3":
//GMC - SI
$employee_received_si = $default_si == null ? $emp_data['policy_details']['basic_cover_si'] : $default_si;
- foreach ($slab_details['slab_rates'] as $skey => $slab_value)
+ foreach ($temp_slab_rates as $skey => $slab_value)
{
if($slab_value['si'] == $employee_received_si)
{
$emp_data['policy_details']['basic_cover_si'] = $slab_value['si'];
$emp_data['policy_details']['date_coverage'] = (isset($emp_data['policy_details']['date_coverage']) ? $emp_data['policy_details']['date_coverage'] : $policy_terms['policy_start_date']);
$emp_data['policy_details']['policy_end_date'] = $policy_terms['policy_end_date'];
- $emp_data['policy_details']['days'] = calculate_days_bw_dates($emp_data['policy_details']['date_coverage'],$policy_terms['policy_end_date'])->days;
+ $emp_data['policy_details']['days'] = (calculate_days_bw_dates($emp_data['policy_details']['date_coverage'],$policy_terms['policy_end_date'])->days + 1);
$emp_data['policy_details']['premium'] = $slab_value['premium'];
- $emp_data['policy_details']['rata_premimum'] = calculate_pro_rata_premimum($slab_value['premium'],$emp_data['policy_details']['days']);
+ $emp_data['policy_details']['rata_premimum'] = calculate_pro_rata_premimum($emp_data['policy_details']['premium'],$emp_data['policy_details']['days'],(calculate_days_bw_dates($policy_terms['policy_start_date'],$policy_terms['policy_end_date'])->days + 1));
$emp_data['policy_details']['gst'] = (float) number_format(($emp_data['policy_details']['rata_premimum'] * (18/100)),2,'.','');
$is_match_found = true;
break;
@@ -826,7 +976,7 @@ if (!function_exists('premium_calculation_manager'))
//GMC - Employees Age band
$employee_received_si = $default_si == null ? $emp_data['policy_details']['basic_cover_si'] : $default_si;
// dd($employee_received_si);
- foreach ($slab_details['slab_rates'] as $skey => $slab_value)
+ foreach ($temp_slab_rates as $skey => $slab_value)
{
$age = calculate_days_bw_dates(from_date: $emp_data['dob'])->y;
if($slab_value['si'] == $employee_received_si && ($slab_value['age_from'] <= $age && $slab_value['age_to'] >= $age))
@@ -835,9 +985,9 @@ if (!function_exists('premium_calculation_manager'))
$emp_data['policy_details']['basic_cover_si'] = $slab_value['si'];
$emp_data['policy_details']['date_coverage'] = (isset($emp_data['policy_details']['date_coverage']) ? $emp_data['policy_details']['date_coverage'] : $policy_terms['policy_start_date']);
$emp_data['policy_details']['policy_end_date'] = $policy_terms['policy_end_date'];
- $emp_data['policy_details']['days'] = calculate_days_bw_dates($emp_data['policy_details']['date_coverage'],$policy_terms['policy_end_date'])->days;
+ $emp_data['policy_details']['days'] = (calculate_days_bw_dates($emp_data['policy_details']['date_coverage'],$policy_terms['policy_end_date'])->days + 1);
$emp_data['policy_details']['premium'] = $slab_value['premium'];
- $emp_data['policy_details']['rata_premimum'] = calculate_pro_rata_premimum($slab_value['premium'],$emp_data['policy_details']['days']);
+ $emp_data['policy_details']['rata_premimum'] = calculate_pro_rata_premimum($emp_data['policy_details']['premium'],$emp_data['policy_details']['days'],(calculate_days_bw_dates($policy_terms['policy_start_date'],$policy_terms['policy_end_date'])->days + 1));
$emp_data['policy_details']['gst'] = (float) number_format(($emp_data['policy_details']['rata_premimum'] * (18/100)),2,'.','');
$is_match_found = true;
break;
@@ -847,7 +997,7 @@ if (!function_exists('premium_calculation_manager'))
case "5":
//GMC - Employees Age + SI
$employee_received_si = $default_si == null ? $emp_data['policy_details']['basic_cover_si'] : $default_si;
- foreach ($slab_details['slab_rates'] as $skey => $slab_value)
+ foreach ($temp_slab_rates as $skey => $slab_value)
{
$age = calculate_days_bw_dates(from_date: $emp_data['dob'])->y;
if($slab_value['si'] == $employee_received_si && ($slab_value['age_from'] <= $age && $slab_value['age_to'] >= $age))
@@ -855,9 +1005,9 @@ if (!function_exists('premium_calculation_manager'))
$emp_data['policy_details']['basic_cover_si'] = $slab_value['si'];
$emp_data['policy_details']['date_coverage'] = (isset($emp_data['policy_details']['date_coverage']) ? $emp_data['policy_details']['date_coverage'] : $policy_terms['policy_start_date']);
$emp_data['policy_details']['policy_end_date'] = $policy_terms['policy_end_date'];
- $emp_data['policy_details']['days'] = calculate_days_bw_dates($emp_data['policy_details']['date_coverage'],$policy_terms['policy_end_date'])->days;
+ $emp_data['policy_details']['days'] = (calculate_days_bw_dates($emp_data['policy_details']['date_coverage'],$policy_terms['policy_end_date'])->days + 1);
$emp_data['policy_details']['premium'] = $slab_value['premium'];
- $emp_data['policy_details']['rata_premimum'] = calculate_pro_rata_premimum($slab_value['premium'],$emp_data['policy_details']['days']);
+ $emp_data['policy_details']['rata_premimum'] = calculate_pro_rata_premimum($emp_data['policy_details']['premium'],$emp_data['policy_details']['days'],(calculate_days_bw_dates($policy_terms['policy_start_date'],$policy_terms['policy_end_date'])->days + 1));
$emp_data['policy_details']['gst'] = (float) number_format(($emp_data['policy_details']['rata_premimum'] * (18/100)),2,'.','');
$is_match_found = true;
break;
@@ -867,18 +1017,18 @@ if (!function_exists('premium_calculation_manager'))
case "6":
//GMC - Employees + Dependent Age band
$employee_received_si = $default_si == null ? $emp_data['policy_details']['basic_cover_si'] : $default_si;
- foreach ($slab_details['slab_rates'] as $skey => $slab_value)
+ foreach ($temp_slab_rates as $skey => $slab_value)
{
$age = calculate_days_bw_dates(from_date: $emp_data['dob'])->y;
- if($slab_value['si'] == $employee_received_si && ($slab_value['age_from'] <= $age && $slab_value['age_to'] >= $age) && (($slab_value['premium_type'] == 1 && strtolower($emp_data['relationship']) == 'self') || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null) ))
+ if($slab_value['si'] == $employee_received_si && ($slab_value['age_from'] <= $age && $slab_value['age_to'] >= $age) && (($slab_value['premium_type'] == 1 && ( strtolower($emp_data['relationship']) == 'self' || $emp_data['temp']['additional_rack_rate_acting_self']) ) || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null) ))
{
// echo $emp_data['name'];
$emp_data['policy_details']['basic_cover_si'] = $slab_value['si'];
$emp_data['policy_details']['date_coverage'] = (isset($emp_data['policy_details']['date_coverage']) ? $emp_data['policy_details']['date_coverage'] : $policy_terms['policy_start_date']);
$emp_data['policy_details']['policy_end_date'] = $policy_terms['policy_end_date'];
- $emp_data['policy_details']['days'] = calculate_days_bw_dates($emp_data['policy_details']['date_coverage'],$policy_terms['policy_end_date'])->days;
+ $emp_data['policy_details']['days'] = (calculate_days_bw_dates($emp_data['policy_details']['date_coverage'],$policy_terms['policy_end_date'])->days + 1);
$emp_data['policy_details']['premium'] = $slab_value['premium'];
- $emp_data['policy_details']['rata_premimum'] = calculate_pro_rata_premimum($slab_value['premium'],$emp_data['policy_details']['days']);
+ $emp_data['policy_details']['rata_premimum'] = calculate_pro_rata_premimum($emp_data['policy_details']['premium'],$emp_data['policy_details']['days'],(calculate_days_bw_dates($policy_terms['policy_start_date'],$policy_terms['policy_end_date'])->days + 1));
$emp_data['policy_details']['gst'] = (float) number_format(($emp_data['policy_details']['rata_premimum'] * (18/100)),2,'.','');
$is_match_found = true;
break;
@@ -889,17 +1039,17 @@ if (!function_exists('premium_calculation_manager'))
case "7":
//GMC - Employees + Dependent Age + SI
$employee_received_si = $default_si == null ? $emp_data['policy_details']['basic_cover_si'] : $default_si;
- foreach ($slab_details['slab_rates'] as $skey => $slab_value)
+ foreach ($temp_slab_rates as $skey => $slab_value)
{
$age = calculate_days_bw_dates(from_date: $emp_data['dob'])->y;
- if($slab_value['si'] == $employee_received_si && ($slab_value['age_from'] <= $age && $slab_value['age_to'] >= $age) && (($slab_value['premium_type'] == 1 && strtolower($emp_data['relationship']) == 'self') || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null) ))
+ if($slab_value['si'] == $employee_received_si && ($slab_value['age_from'] <= $age && $slab_value['age_to'] >= $age) && (($slab_value['premium_type'] == 1 && ( strtolower($emp_data['relationship']) == 'self' || $emp_data['temp']['additional_rack_rate_acting_self']) ) || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null) ))
{
$emp_data['policy_details']['basic_cover_si'] = $slab_value['si'];
$emp_data['policy_details']['date_coverage'] = (isset($emp_data['policy_details']['date_coverage']) ? $emp_data['policy_details']['date_coverage'] : $policy_terms['policy_start_date']);
$emp_data['policy_details']['policy_end_date'] = $policy_terms['policy_end_date'];
- $emp_data['policy_details']['days'] = calculate_days_bw_dates($emp_data['policy_details']['date_coverage'],$policy_terms['policy_end_date'])->days;
+ $emp_data['policy_details']['days'] = (calculate_days_bw_dates($emp_data['policy_details']['date_coverage'],$policy_terms['policy_end_date'])->days + 1);
$emp_data['policy_details']['premium'] = $slab_value['premium'];
- $emp_data['policy_details']['rata_premimum'] = calculate_pro_rata_premimum($slab_value['premium'],$emp_data['policy_details']['days']);
+ $emp_data['policy_details']['rata_premimum'] = calculate_pro_rata_premimum($emp_data['policy_details']['premium'],$emp_data['policy_details']['days'],(calculate_days_bw_dates($policy_terms['policy_start_date'],$policy_terms['policy_end_date'])->days + 1));
$emp_data['policy_details']['gst'] = (float) number_format(($emp_data['policy_details']['rata_premimum'] * (18/100)),2,'.','');
$is_match_found = true;
@@ -911,18 +1061,18 @@ if (!function_exists('premium_calculation_manager'))
//GMC - SI as per Grade or Band
$employee_received_band = $emp_data['temp']['band'];
$employee_received_si = $default_si == null ? $emp_data['policy_details']['basic_cover_si'] : $default_si;
- foreach ($slab_details['slab_rates'] as $skey => $slab_value)
+ foreach ($temp_slab_rates as $skey => $slab_value)
{
- if($slab_value['grade'] == $employee_received_band && $slab_value['si'] == $employee_received_si && (($slab_value['premium_type'] == 1 && strtolower($emp_data['relationship']) == 'self') || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null) ))
+ if($slab_value['grade'] == $employee_received_band && $slab_value['si'] == $employee_received_si && (($slab_value['premium_type'] == 1 && (strtolower($emp_data['relationship']) == 'self' || $emp_data['temp']['additional_rack_rate_acting_self']) ) || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null) ))
{
// $emp_data['policy_details']['basic_cover_si'] = $slab_value['si'];
$emp_data['policy_details']['basic_cover_si'] = $slab_value['si'];
$emp_data['policy_details']['date_coverage'] = (isset($emp_data['policy_details']['date_coverage']) ? $emp_data['policy_details']['date_coverage'] : $policy_terms['policy_start_date']);
$emp_data['policy_details']['policy_end_date'] = $policy_terms['policy_end_date'];
- $emp_data['policy_details']['days'] = calculate_days_bw_dates($emp_data['policy_details']['date_coverage'],$policy_terms['policy_end_date'])->days;
+ $emp_data['policy_details']['days'] = (calculate_days_bw_dates($emp_data['policy_details']['date_coverage'],$policy_terms['policy_end_date'])->days + 1);
$emp_data['policy_details']['premium'] = $slab_value['premium'];
- $emp_data['policy_details']['rata_premimum'] = calculate_pro_rata_premimum($slab_value['premium'],$emp_data['policy_details']['days']);
+ $emp_data['policy_details']['rata_premimum'] = calculate_pro_rata_premimum($emp_data['policy_details']['premium'],$emp_data['policy_details']['days'],(calculate_days_bw_dates($policy_terms['policy_start_date'],$policy_terms['policy_end_date'])->days + 1));
$emp_data['policy_details']['gst'] = (float) number_format(($emp_data['policy_details']['rata_premimum'] * (18/100)),2,'.','');
$is_match_found = true;
break;
@@ -933,17 +1083,17 @@ if (!function_exists('premium_calculation_manager'))
//GMC - Flat Rate for all
$employee_received_band = $emp_data['temp']['band'];
$employee_received_si = $default_si == null ? $emp_data['policy_details']['basic_cover_si'] : $default_si;
- foreach ($slab_details['slab_rates'] as $skey => $slab_value)
+ foreach ($temp_slab_rates as $skey => $slab_value)
{
- if($slab_value['si'] == $employee_received_si && (($slab_value['premium_type'] == 1 && strtolower($emp_data['relationship']) == 'self') || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null) ))
+ if($slab_value['si'] == $employee_received_si && (($slab_value['premium_type'] == 1 && (strtolower($emp_data['relationship']) == 'self' || $emp_data['temp']['additional_rack_rate_acting_self'])) || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null) ))
{
$emp_data['policy_details']['basic_cover_si'] = $slab_value['si'];
$emp_data['policy_details']['date_coverage'] = (isset($emp_data['policy_details']['date_coverage']) ? $emp_data['policy_details']['date_coverage'] : $policy_terms['policy_start_date']);
$emp_data['policy_details']['policy_end_date'] = $policy_terms['policy_end_date'];
- $emp_data['policy_details']['days'] = calculate_days_bw_dates($emp_data['policy_details']['date_coverage'],$policy_terms['policy_end_date'])->days;
+ $emp_data['policy_details']['days'] = (calculate_days_bw_dates($emp_data['policy_details']['date_coverage'],$policy_terms['policy_end_date'])->days + 1);
$emp_data['policy_details']['premium'] = $slab_value['premium'];
- $emp_data['policy_details']['rata_premimum'] = calculate_pro_rata_premimum($slab_value['premium'],$emp_data['policy_details']['days']);
+ $emp_data['policy_details']['rata_premimum'] = calculate_pro_rata_premimum($emp_data['policy_details']['premium'],$emp_data['policy_details']['days'],(calculate_days_bw_dates($policy_terms['policy_start_date'],$policy_terms['policy_end_date'])->days + 1));
$emp_data['policy_details']['gst'] = (float) number_format(($emp_data['policy_details']['rata_premimum'] * (18/100)),2,'.','');
$is_match_found = true;
break;
@@ -954,18 +1104,23 @@ if (!function_exists('premium_calculation_manager'))
//GMC - Maximum age of Dependents
$max_age = $emp_data['temp']['maxage'];
$employee_received_si = $default_si == null ? $emp_data['policy_details']['basic_cover_si'] : $default_si;
+ // echo $emp_data['name'].'-'.$employee_received_si.'
';
+ // echo $emp_data['temp']['grid_type'].'
';
$emp_data['policy_details']['basic_cover_si'] = null;
- foreach ($slab_details['slab_rates'] as $skey => $slab_value)
+ foreach ($temp_slab_rates as $skey => $slab_value)
{
-
- if($slab_value['si'] == $employee_received_si && ($slab_value['age_from'] <= $max_age && $slab_value['age_to'] >= $max_age) && (($slab_value['premium_type'] == 1 && strtolower($emp_data['relationship']) == 'self') || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null) ))
+ // echo $slab_value['si'].'-'.$slab_value['age_from'].'-'.$slab_value['age_to'].'-'.$max_age.'
';
+ if( $slab_value['si'] == $employee_received_si &&
+ ($slab_value['age_from'] <= $max_age && $slab_value['age_to'] >= $max_age) &&
+ (($slab_value['premium_type'] == 1 &&
+ ( (strtolower($emp_data['relationship']) == 'self') || ($emp_data['temp']['additional_rack_rate_acting_self']) )) || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null) ) )
{
$emp_data['policy_details']['basic_cover_si'] = $employee_received_si;
$emp_data['policy_details']['date_coverage'] = isset($emp_data['policy_details']['date_coverage']) ? $emp_data['policy_details']['date_coverage'] : $policy_terms['policy_start_date'];
$emp_data['policy_details']['policy_end_date'] = $policy_terms['policy_end_date'];
- $emp_data['policy_details']['days'] = calculate_days_bw_dates($emp_data['policy_details']['date_coverage'],$policy_terms['policy_end_date'])->days;
+ $emp_data['policy_details']['days'] = (calculate_days_bw_dates($emp_data['policy_details']['date_coverage'],$policy_terms['policy_end_date'])->days + 1);
$emp_data['policy_details']['premium'] = $slab_value['premium'];
- $emp_data['policy_details']['rata_premimum'] = calculate_pro_rata_premimum($slab_value['premium'],$emp_data['policy_details']['days']);
+ $emp_data['policy_details']['rata_premimum'] = calculate_pro_rata_premimum($emp_data['policy_details']['premium'],$emp_data['policy_details']['days'],(calculate_days_bw_dates($policy_terms['policy_start_date'],$policy_terms['policy_end_date'])->days + 1));
$emp_data['policy_details']['gst'] = ((float) number_format(($emp_data['policy_details']['rata_premimum'] * (18/100)),2,'.',''));
$is_match_found = true;
break;
@@ -979,10 +1134,11 @@ if (!function_exists('premium_calculation_manager'))
// echo $employee_received_band;
$employee_received_si = $default_si == null ? $emp_data['policy_details']['basic_cover_si'] : $default_si;
$emp_data['policy_details']['basic_cover_si'] = null;
- foreach ($slab_details['slab_rates'] as $skey => $slab_value)
+ foreach ($temp_slab_rates as $skey => $slab_value)
{
- if($slab_value['si'] == $employee_received_si && ($slab_value['grade'] == $employee_received_band) && (($slab_value['premium_type'] == 1 && strtolower($emp_data['relationship']) == 'self') || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null) ))
+ if($slab_value['si'] == $employee_received_si && $slab_value['grade'] == $employee_received_band && (($slab_value['premium_type'] == 1 &&
+ ( (strtolower($emp_data['relationship']) == 'self') || ($emp_data['temp']['additional_rack_rate_acting_self']) )) || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null) ))
{
//calculate premium based on count
// echo $emp_data['name'];
@@ -992,9 +1148,9 @@ if (!function_exists('premium_calculation_manager'))
$emp_data['policy_details']['basic_cover_si'] = $familiy_si_covered;
$emp_data['policy_details']['date_coverage'] = (isset($emp_data['policy_details']['date_coverage']) ? $emp_data['policy_details']['date_coverage'] : $policy_terms['policy_start_date']);
$emp_data['policy_details']['policy_end_date'] = $policy_terms['policy_end_date'];
- $emp_data['policy_details']['days'] = calculate_days_bw_dates($emp_data['policy_details']['date_coverage'],$policy_terms['policy_end_date'])->days;
+ $emp_data['policy_details']['days'] = (calculate_days_bw_dates($emp_data['policy_details']['date_coverage'],$policy_terms['policy_end_date'])->days + 1);
$emp_data['policy_details']['premium'] = get_premium_for_si(slab_details: $slab_details,si_amount: $familiy_si_covered,band: $employee_received_band);
- $emp_data['policy_details']['rata_premimum'] = calculate_pro_rata_premimum($emp_data['policy_details']['premium'],$emp_data['policy_details']['days']);
+ $emp_data['policy_details']['rata_premimum'] = calculate_pro_rata_premimum($emp_data['policy_details']['premium'],$emp_data['policy_details']['days'],(calculate_days_bw_dates($policy_terms['policy_start_date'],$policy_terms['policy_end_date'])->days + 1));
$emp_data['policy_details']['gst'] = ((float) number_format(($emp_data['policy_details']['rata_premimum'] * (18/100)),2,'.',''));
$is_match_found = true;
break;
@@ -1009,17 +1165,17 @@ if (!function_exists('premium_calculation_manager'))
$employee_relationship = $slug->slugify($emp_data['relationship']);
$employee_relationship = ($employee_relationship == 'daughter' || $employee_relationship == 'son' ? $employee_relationship = 'child' : $employee_relationship);
$emp_data['policy_details']['basic_cover_si'] = null;
- foreach ($slab_details['slab_rates'] as $skey => $slab_value)
+ foreach ($temp_slab_rates as $skey => $slab_value)
{
- if( $slab_value['si'] == $employee_received_si && ((($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null) && $slab_value['relationship'] == $employee_relationship) || ($slab_value['premium_type'] == 1 && strtolower($emp_data['relationship']) == 'self')) )
+ if( $slab_value['si'] == $employee_received_si && ((($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null) && $slab_value['relationship'] == $employee_relationship) || ($slab_value['premium_type'] == 1 && (strtolower($emp_data['relationship']) == 'self' || $emp_data['temp']['additional_rack_rate_acting_self'] ) )) )
{
$emp_data['policy_details']['basic_cover_si'] = $employee_received_si;
$emp_data['policy_details']['date_coverage'] = (isset($emp_data['policy_details']['date_coverage']) ? $emp_data['policy_details']['date_coverage'] : $policy_terms['policy_start_date']);
$emp_data['policy_details']['policy_end_date'] = $policy_terms['policy_end_date'];
- $emp_data['policy_details']['days'] = calculate_days_bw_dates($emp_data['policy_details']['date_coverage'],$policy_terms['policy_end_date'])->days;
+ $emp_data['policy_details']['days'] = (calculate_days_bw_dates($emp_data['policy_details']['date_coverage'],$policy_terms['policy_end_date'])->days + 1);
$emp_data['policy_details']['premium'] = $slab_value['premium'];
- $emp_data['policy_details']['rata_premimum'] = calculate_pro_rata_premimum($slab_value['premium'],$emp_data['policy_details']['days']);
+ $emp_data['policy_details']['rata_premimum'] = calculate_pro_rata_premimum($emp_data['policy_details']['premium'],$emp_data['policy_details']['days'],(calculate_days_bw_dates($policy_terms['policy_start_date'],$policy_terms['policy_end_date'])->days + 1));
$emp_data['policy_details']['gst'] = ((float) number_format(($emp_data['policy_details']['rata_premimum'] * (18/100)),2,'.',''));
$is_match_found = true;
break;
@@ -1034,17 +1190,17 @@ if (!function_exists('premium_calculation_manager'))
$employee_relationship = ($employee_relationship == 'daughter' || $employee_relationship == 'son' ? $employee_relationship = 'child' : $employee_relationship);
$emp_data['policy_details']['basic_cover_si'] = null;
$age = calculate_days_bw_dates(from_date: $emp_data['dob'])->y;
- foreach ($slab_details['slab_rates'] as $skey => $slab_value)
+ foreach ($temp_slab_rates as $skey => $slab_value)
{
- if( $slab_value['si'] == $employee_received_si && ($slab_value['age_from'] <= $age && $slab_value['age_to'] >= $age) && ((($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null) && $slab_value['relationship'] == $employee_relationship) || ($slab_value['premium_type'] == 1 && strtolower($emp_data['relationship']) == 'self')) )
+ if( $slab_value['si'] == $employee_received_si && ($slab_value['age_from'] <= $age && $slab_value['age_to'] >= $age) && ((($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null) && $slab_value['relationship'] == $employee_relationship) || ($slab_value['premium_type'] == 1 && (strtolower($emp_data['relationship']) == 'self' || $emp_data['temp']['additional_rack_rate_acting_self']) )) )
{
$emp_data['policy_details']['basic_cover_si'] = $employee_received_si;
$emp_data['policy_details']['date_coverage'] = (isset($emp_data['policy_details']['date_coverage']) ? $emp_data['policy_details']['date_coverage'] : $policy_terms['policy_start_date']);
$emp_data['policy_details']['policy_end_date'] = $policy_terms['policy_end_date'];
- $emp_data['policy_details']['days'] = calculate_days_bw_dates($emp_data['policy_details']['date_coverage'],$policy_terms['policy_end_date'])->days;
+ $emp_data['policy_details']['days'] = (calculate_days_bw_dates($emp_data['policy_details']['date_coverage'],$policy_terms['policy_end_date'])->days + 1);
$emp_data['policy_details']['premium'] = $slab_value['premium'];
- $emp_data['policy_details']['rata_premimum'] = calculate_pro_rata_premimum($slab_value['premium'],$emp_data['policy_details']['days']);
+ $emp_data['policy_details']['rata_premimum'] = calculate_pro_rata_premimum($emp_data['policy_details']['premium'],$emp_data['policy_details']['days'],calculate_days_bw_dates($policy_terms['policy_start_date'],$policy_terms['policy_end_date'])->days);
$emp_data['policy_details']['gst'] = ((float) number_format(($emp_data['policy_details']['rata_premimum'] * (18/100)),2,'.',''));
$is_match_found = true;
break;
@@ -1055,13 +1211,13 @@ if (!function_exists('premium_calculation_manager'))
default:
- $this->myLogger->logme('error',($emp_data['emp_code'].'-'.$emp_data['name'].' - grid type not found'));
+ $myLogger->logme('error',($emp_data['emp_code'].'-'.$emp_data['name'].' - grid type not found'));
}
if(!$is_match_found)
{
$age = calculate_days_bw_dates(from_date: $emp_data['dob'])->y;
$log_message = '[ client_policy_id : ' .$emp_data['policy_details']['client_policy_id'].' - '. $emp_data['emp_code'].' - '.$emp_data['name'] .' - '. $emp_data['policy_details']['basic_cover_si'] . ', Age : '. $age.' ]';
- if($slab_details['slab_rates'][0]['premium_type'] == 1)
+ if($temp_slab_rates[0]['premium_type'] == 1)
{
$log_message .= ' - skipping, calculating only self..!';
//reset emp si and others policy level data if premium only for self
@@ -1085,9 +1241,17 @@ if (!function_exists('premium_calculation_manager'))
if (!function_exists('calculate_pro_rata_premimum'))
{
- function calculate_pro_rata_premimum($premium,$days)
+ function calculate_pro_rata_premimum($premium,$employee_policy_coverage_days,$policy_coverage_days)
{
- return (float) number_format(($premium / 365) * $days,2,'.','');
+ return (float) number_format(($premium / ($policy_coverage_days) ) * $employee_policy_coverage_days,2,'.','');
+ }
+}
+
+if (!function_exists('no_of_days_in_current_fin_year'))
+{
+ function no_of_days_in_current_fin_year()
+ {
+ return true;
}
}
@@ -1134,6 +1298,7 @@ if (!function_exists('transform_db_data_to_excel'))
$row['temp']['emp_policy_id'] = $value['emp_policy_id'];
$row['temp']['emp_status'] = $value['emp_status'];
$row['temp']['policy_status'] = $value['status'];
+ $row['temp']['rata_premimum'] = $value['rata_premimum'];
array_push($return_data, ($row));
}
@@ -1226,7 +1391,7 @@ if(!function_exists('get_premium_for_si'))
{
foreach ($slab_details['slab_rates'] as $skey => $slab_value)
{
- if($slab_value['si'] == $si_amount && $slab_value['grade'] == $band)
+ if($slab_value['si'] == $si_amount && $slab_value['grade'] == $band && $slab_value['max_si'] == 0)
{
return $slab_value['premium'];
}
@@ -1297,4 +1462,47 @@ if(!function_exists('check_dup_mobileno'))
}
return array('status' => true);
}
+}
+
+if(!function_exists('generate_family_relationship_array'))
+{
+ function generate_family_relationship_array($family_structure_from_policy_terms) {
+ $family_relationships = [];
+
+ // Add self and spouse
+ if ($family_structure_from_policy_terms['self'] > 0) {
+ $family_relationships[] = 'self';
+ }
+ if ($family_structure_from_policy_terms['spouse'] > 0) {
+ $family_relationships[] = 'spouse';
+ }
+
+ // Add children
+ if ($family_structure_from_policy_terms['childrens'] > 0) {
+ $family_relationships[] = 'son';
+ $family_relationships[] = 'daughter';
+ }
+
+ // Add parents
+ if ($family_structure_from_policy_terms['parents'] > 0) {
+ $family_relationships[] = 'father';
+ $family_relationships[] = 'mother';
+ }
+
+ // Add parents-in-law
+ if ($family_structure_from_policy_terms['parents-in-law'] > 0) {
+ $family_relationships[] = 'father-in-law';
+ $family_relationships[] = 'mother-in-law';
+ }
+
+ // Add either parents or parents-in-law
+ if ($family_structure_from_policy_terms['either-parents-pil'] > 0) {
+ $family_relationships[] = 'father';
+ $family_relationships[] = 'mother';
+ $family_relationships[] = 'father-in-law';
+ $family_relationships[] = 'mother-in-law';
+ }
+
+ return $family_relationships;
+}
}
\ No newline at end of file
diff --git a/app/Helpers/sendMailNotification.php b/app/Helpers/sendMailNotification.php
index cfc96b17..0c8c7067 100644
--- a/app/Helpers/sendMailNotification.php
+++ b/app/Helpers/sendMailNotification.php
@@ -105,6 +105,7 @@ class sendMailNotification
$name = $get_emp_email_and_other_details['name'];
$mail_content = $notification['mail_content'];
$nhance_logo = $_ENV['NHANCE_LOGO'];
+ $post_enrollment_app_link = $_ENV['POST_ENROLLMENT_APP_LINK'];
$client_logo = base_url() . "public/uploads/logo/" . $client_data['client_logo'];
// $client_logo = $nhance_logo;
@@ -114,8 +115,9 @@ class sendMailNotification
$mail_content = str_replace("[[member_name]]", $name, $mail_content);
$mail_content = str_replace("[[app_link]]", "Review Details", $mail_content);
+ $mail_content = str_replace("[[post_enrollment_app_link]]", "Review Details", $mail_content);
// $mail_content = str_replace("[[tpa_id]]", $tpa_id, $mail_content);
- $mail_content = str_replace("[[ecard_download_link]]", "Download Insurance Card", $mail_content);
+ $mail_content = str_replace("[[ecard_download_link]]", "Download Insurance Card", $mail_content);
$mail_content = str_replace("[[client_name]]", $client_data['client_name'], $mail_content);
$wholeData = ['mail' => $mail, 'subject' => $subject,'message'=> $mail_content,'bcc'=> $client_data['common_mails']];
diff --git a/app/Helpers/session_helper.php b/app/Helpers/session_helper.php
index 6e879e4b..ce6a0f56 100644
--- a/app/Helpers/session_helper.php
+++ b/app/Helpers/session_helper.php
@@ -10,6 +10,37 @@ if (!function_exists('check_session')) {
}
}
+if (!function_exists('set_last_visited_time')) {
+ function set_last_visited_time()
+ {
+ $session = \Config\Services::session();
+ $session->set('last_visited', date("Y-m-d H:i:s"));
+ }
+}
+
+if (!function_exists('get_last_visited_time')) {
+ function get_last_visited_time()
+ {
+ // Get the session service
+ $session = \Config\Services::session();
+
+ // Get the last visited time from session
+ $lastVisitTime = $session->get('last_visited');
+
+ // Check if the last visited time is set
+ if ($lastVisitTime) {
+ // Calculate the time five minutes ago
+ $fiveMinutesBefore = date("YmdHi", strtotime('-5 minutes'));
+
+ // Compare the last visited time with the time five minutes ago
+ return date("YmdHi", strtotime($lastVisitTime)) > $fiveMinutesBefore ? 1 : 0;
+ }
+
+ // If last visited time is not set, return 0
+ return 0;
+ }
+}
+
if (!function_exists('get_session_userid')) {
function get_session_userid()
{
diff --git a/app/Helpers/utility_helper.php b/app/Helpers/utility_helper.php
index eaa72ce7..2dbcb1ce 100644
--- a/app/Helpers/utility_helper.php
+++ b/app/Helpers/utility_helper.php
@@ -188,6 +188,7 @@ if (!function_exists('get_base64_image')) {
if (!function_exists('format_indian_number')) {
function format_indian_number($number) {
// Round the number to two decimal places
+ $number = isset($number) ? $number : 0;
$number = round($number, 2);
// Split the number into integer and decimal parts
@@ -218,3 +219,23 @@ if (!function_exists('format_indian_number')) {
}
+if (!function_exists('get_username')) {
+ function get_username($user_id) {
+ // Connect to the database
+ $db = \Config\Database::connect();
+
+ // Query the database
+ $query = $db->table('user_profiles')
+ ->select('first_name')
+ ->where('id', $user_id)
+ ->get();
+
+ // Get the result
+ $result = $query->getRow();
+
+ // Return the username if found, otherwise return null
+ return $result ? $result->first_name : null;
+ }
+}
+
+
diff --git a/app/Models/AddImgModel.php b/app/Models/AddImgModel.php
new file mode 100644
index 00000000..130da9f6
--- /dev/null
+++ b/app/Models/AddImgModel.php
@@ -0,0 +1,21 @@
+
\ No newline at end of file
diff --git a/app/Models/BatchFileModel.php b/app/Models/BatchFileModel.php
index 1d2b4a0d..df644790 100644
--- a/app/Models/BatchFileModel.php
+++ b/app/Models/BatchFileModel.php
@@ -24,6 +24,7 @@ class BatchFileModel extends Model
"amount",
"status",
"error_data",
+ "client_branch_id",
];
// Callbacks
diff --git a/app/Models/ClientModel.php b/app/Models/ClientModel.php
index 193b9b71..fd1e8510 100644
--- a/app/Models/ClientModel.php
+++ b/app/Models/ClientModel.php
@@ -4,6 +4,7 @@ namespace App\Models;
use CodeIgniter\Model;
use App\Models\ClientPolicyModel;
+use App\Models\ClientBranchModel;
class ClientModel extends Model
{
@@ -41,7 +42,19 @@ class ClientModel extends Model
foreach ($clients as &$client) {
$clientPolicyModel = new ClientPolicyModel();
- $clientPolicies = $clientPolicyModel->select(['client_policy.id','p.name','pt.policy_type'])
+ $clientPolicies = $clientPolicyModel
+ ->select(['
+
+ client_branch.id as branch_id',
+ 'client_branch.branch_name',
+ 'client_branch.branch_code',
+ 'client_branch.client_id',
+ 'client_policy.id as client_policy_id',
+ 'client_policy.policy_terms',
+ 'p.name',
+ 'pt.policy_type',
+ ])
+ ->join('client_branch', 'client_branch.id = client_policy.client_branch_id')
->join('policies p', 'p.id = client_policy.policy_id')
->join('policy_type pt','client_policy.policy_type_id = pt.id')
->where('client_policy.client_id',$client['id'])
@@ -50,6 +63,13 @@ class ClientModel extends Model
->findAll();
$client['policies'] = $clientPolicies;
+
+ $clientBranchModel = new ClientBranchModel();
+ $clientBranchs = $clientBranchModel->select(['client_branch.id','client_branch.branch_name','client_branch.branch_code', 'client_branch.client_id'])
+ ->where('client_branch.client_id',$client['id'])
+ ->findAll();
+
+ $client['branchs'] = $clientBranchs;
}
//print_r(($clients));die();
return $clients;
diff --git a/app/Models/ClientPolicyModel.php b/app/Models/ClientPolicyModel.php
index 4cdd36b5..b9cd0ae1 100644
--- a/app/Models/ClientPolicyModel.php
+++ b/app/Models/ClientPolicyModel.php
@@ -41,7 +41,8 @@ class ClientPolicyModel extends Model
"Is_active",
"date_of_exit",
"reason_for_exit",
- "policy_no"
+ "policy_no",
+ "client_branch_id"
];
public function getClientPolicyById($id){
diff --git a/app/Models/EmployeeModel.php b/app/Models/EmployeeModel.php
index 7ec30755..adffe7ff 100644
--- a/app/Models/EmployeeModel.php
+++ b/app/Models/EmployeeModel.php
@@ -37,7 +37,10 @@ class EmployeeModel extends Model
"is_active",
"file_id",
"is_addon_value",
- "is_createdby_hr"
+ "is_createdby_hr",
+ "client_branch_id",
+ "token_time_out",
+ "emp_type"
];
// Callbacks
@@ -76,7 +79,7 @@ class EmployeeModel extends Model
// for emp onboard process do not change
- public function checkExistingEmp($arr)
+ public function checkExistingEmp($arr,$client_branch_id)
{
if($arr['temp']['emp_id'] == null)
@@ -84,9 +87,12 @@ class EmployeeModel extends Model
return $this->where('emp_code',$arr['emp_code'])
->where('name',$arr['name'])
->where('client_id',$arr['client_id'])
+ ->where('client_branch_id',$client_branch_id)
->where('is_active',1)
->where('gender',$arr['gender'])
->where('dob',$arr['dob'])
+ ->where('is_active',1)
+ ->where('emp_status','active')
->find();
}
else
@@ -96,9 +102,9 @@ class EmployeeModel extends Model
}
- public function getEmpFamilybyEmpCode(string $client_policy_id = null,string $emp_code = null,string $client_id = null,array $emp_status = [],array $policy_status = [],array $relationship = [])
+ public function getEmpFamilybyEmpCode(string $client_policy_id = null,string $emp_code = null,string $client_id = null,array $emp_status = [],array $policy_status = [],array $relationship = [],array $client_branch_id = [])
{
- $result = $this->select(['employees.id as emp_id', 'employees.client_id', 'employees.relationship', 'employees.relationship_code', 'employees.change_event', 'employees.emp_code', 'employees.name', 'employees.email_personal', 'employees.email_corporate', 'employees.mobile', 'employees.gender', 'employees.dob', 'employees.doj', 'employees.basic_pay', 'employees.band', 'employees.designation', 'employees.emp_status','employee_polices.id as emp_policy_id', 'employee_polices.employee_id', 'employee_polices.client_policy_id', 'employee_polices.tpa_id', 'employee_polices.uhid', 'employee_polices.batch_code', 'employee_polices.status', 'employee_polices.pre_existing_alignments', 'employee_polices.basic_cover_si', 'employee_polices.date_coverage', 'employee_polices.policy_end_date', 'employee_polices.days', 'employee_polices.premium', 'employee_polices.rata_premimum', 'employee_polices.gst', 'employee_polices.date_of_exit', 'employee_polices.reason_for_exit','policies.name as policy_name','client_policy.is_addon'])
+ $result = $this->select(['employees.id as emp_id', 'employees.client_id','employees.client_branch_id', 'employees.relationship', 'employees.relationship_code', 'employees.change_event', 'employees.emp_code', 'employees.name', 'employees.email_personal', 'employees.email_corporate', 'employees.mobile', 'employees.gender', 'employees.dob', 'employees.doj', 'employees.basic_pay', 'employees.band', 'employees.designation', 'employees.emp_status','employee_polices.id as emp_policy_id', 'employee_polices.employee_id', 'employee_polices.client_policy_id', 'employee_polices.tpa_id', 'employee_polices.uhid', 'employee_polices.batch_code', 'employee_polices.status', 'employee_polices.pre_existing_alignments', 'employee_polices.basic_cover_si', 'employee_polices.date_coverage', 'employee_polices.policy_end_date', 'employee_polices.days', 'employee_polices.premium', 'employee_polices.rata_premimum', 'employee_polices.gst', 'employee_polices.date_of_exit', 'employee_polices.reason_for_exit','policies.name as policy_name','client_policy.is_addon'])
->join('employee_polices', 'employee_polices.employee_id = employees.id')
->join('client_policy', 'client_policy.id = employee_polices.client_policy_id')
->join('policies', 'policies.id = client_policy.policy_id')
@@ -116,6 +122,9 @@ class EmployeeModel extends Model
})
->when(count($emp_status), function($query) use ($emp_status){
return $query->whereIn('employees.emp_status', $emp_status);
+ })
+ ->when(count($client_branch_id), function($query) use ($client_branch_id){
+ return $query->whereIn('employees.client_branch_id', $client_branch_id);
})
->when(count($relationship), function($query) use ($relationship){
return $query->whereIn('employees.relationship', $relationship);
diff --git a/app/Models/EmployeePolicyModel.php b/app/Models/EmployeePolicyModel.php
index 5b5caf18..4f9652d9 100644
--- a/app/Models/EmployeePolicyModel.php
+++ b/app/Models/EmployeePolicyModel.php
@@ -76,7 +76,7 @@ class EmployeePolicyModel extends Model
}
// -----------------------------------------------------------------------------------------------------
- public function getEmployeePolicy($client_id,$policy_id,$status)
+ public function getEmployeePolicy($client_id,$policy_id,$status, $branch_id)
{
$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')
@@ -88,6 +88,7 @@ class EmployeePolicyModel extends Model
->join('tpa_branch tpab', 'cp.tpa_branch_id = tpab.id') //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)
@@ -119,6 +120,7 @@ class EmployeePolicyModel extends Model
public function getInceptionEmployeeDataForExportExcel($ref_data)
{
$client_policy_id = $ref_data['client_policy_id'];
+ $client_branch_id = $ref_data['client_branch_id'];
$insurer_or_tpa = $ref_data['insurer_or_tpa'];
$event = $ref_data['event_type'];
@@ -141,7 +143,7 @@ class EmployeePolicyModel extends Model
employees.relationship AS emp_relationship,
employees.relationship_code AS emp_relationship_code,
TIMESTAMPDIFF(YEAR, employees.dob, CURDATE()) AS emp_age,
- 'Has Define' as emp_type,
+ employees.emp_type as emp_type,
employee_polices.id as primaryKey,
employee_polices.tpa_id,
@@ -173,7 +175,13 @@ class EmployeePolicyModel extends Model
) as batch_data ON employee_polices.id = batch_data.emp_policy_id
WHERE employee_polices.client_policy_id = '{$client_policy_id}'
AND (employee_polices.{$id} IS NULL OR employee_polices.{$id} = '')
- AND employee_polices.is_active = 1";
+ AND employees.client_branch_id = '{$client_branch_id}'
+ AND employee_polices.is_active = 1
+ AND employee_polices.status = 'active'
+ AND employees.is_active = 1
+ AND employees.emp_status = 'active'
+
+ ";
// Get the result set
$query = $this->db->query($sql);
@@ -187,6 +195,7 @@ class EmployeePolicyModel extends Model
$client_id = $ref_data['client_id'];
$client_policy_id = $ref_data['client_policy_id'];
+ $client_branch_id = $ref_data['client_branch_id'];
$insurer_or_tpa = $ref_data['insurer_or_tpa'];
$sql = "
@@ -205,7 +214,7 @@ class EmployeePolicyModel extends Model
employees.dob AS emp_dob,
employees.gender AS emp_gender,
employees.client_id AS emp_client_id,
- 'Has Define' AS emp_type,
+ employees.emp_type as emp_type,
employee_polices.uhid,
employees.relationship_code,
batch_data.emp_policy_id,
@@ -231,11 +240,16 @@ class EmployeePolicyModel extends Model
AND batch_files.insurer_or_tpa = '{$insurer_or_tpa}'
) AS batch_data ON emp_endorsement.pk = batch_data.emp_policy_id
- WHERE batch_data.bf IS NULL
- AND batch_data.bl IS NULL
- AND employees.client_id = '{$client_id}'
+ WHERE employees.client_id = '{$client_id}'
AND employee_polices.client_policy_id = '{$client_policy_id}'
+ AND employees.client_branch_id = '{$client_branch_id}'
AND emp_endorsement.actions = 'c'
+ AND employee_polices.is_active = 1
+ AND employee_polices.status = 'active'
+ AND employees.is_active = 1
+ AND employees.emp_status = 'active'
+ AND (employee_polices.tpa_id IS NOT NULL AND employee_polices.tpa_id != '')
+ AND (employee_polices.uhid IS NOT NULL AND employee_polices.uhid != '')
AND (emp_endorsement.endorsement_id IS NULL OR emp_endorsement.endorsement_id = '')";
// Execute the raw query
@@ -254,18 +268,20 @@ class EmployeePolicyModel extends Model
$client_id = $ref_data['client_id'];
$client_policy_id = $ref_data['client_policy_id'];
+ $client_branch_id = $ref_data['client_branch_id'];
$insurer_or_tpa = $ref_data['insurer_or_tpa'];
$query = $this->db->query("
SELECT
a.id as endorsement_primarykey,
+ a.group_key,
employee_polices.id AS primaryKey,
employees.name AS emp_name,
employees.emp_code AS emp_code,
employees.dob AS emp_dob,
employees.gender AS emp_gender,
employees.relationship_code AS emp_relationship_code,
- 'Has Define' AS emp_type,
+ employees.emp_type as emp_type,
employee_polices.uhid AS risk_id,
employee_polices.pre_existing_alignments,
employee_polices.policy_end_date,
@@ -277,10 +293,15 @@ class EmployeePolicyModel extends Model
sidata.new_basic_cover_si,
sidata.new_si_premium,
sidata.date_of_coverage,
+
DATEDIFF(employee_polices.policy_end_date, sidata.date_of_coverage) + 1 AS no_of_days,
+
sidata.new_si_premium - employee_polices.rata_premimum AS difference_premium,
+
ROUND((sidata.new_si_premium - employee_polices.rata_premimum) * (DATEDIFF(employee_polices.policy_end_date, sidata.date_of_coverage) + 1) / 365, 2) AS pro_rata_premimum,
+
ROUND(((sidata.new_si_premium - employee_polices.rata_premimum) * (DATEDIFF(employee_polices.policy_end_date, sidata.date_of_coverage) + 1) / 365) * 0.18, 2) AS gst,
+
((sidata.new_si_premium - employee_polices.rata_premimum) * (DATEDIFF(employee_polices.policy_end_date, sidata.date_of_coverage) + 1) / 365) + ROUND(((sidata.new_si_premium - employee_polices.rata_premimum) * (DATEDIFF(employee_polices.policy_end_date, sidata.date_of_coverage) + 1) / 365) * 0.18, 2) AS total
FROM
@@ -340,13 +361,16 @@ class EmployeePolicyModel extends Model
AND batch_files.actions = 'export'
AND batch_files.insurer_or_tpa = '{$insurer_or_tpa}'
) AS batch_data ON employee_polices.id = batch_data.emp_policy_id
- WHERE
- batch_data.bf IS NULL
- AND batch_data.bl IS NULL
- AND employee_polices.client_policy_id = '{$client_policy_id}'
- AND employee_polices.is_active = '1'
+
+ WHERE employee_polices.client_policy_id = '{$client_policy_id}'
+ AND employees.client_branch_id = '{$client_branch_id}'
AND (a.endorsement_id IS NULL OR a.endorsement_id = '')
- AND a.field_name = 'si_enhancement_date'
+ AND a.actions = 'si'
+ AND employee_polices.is_active = 1
+ AND employee_polices.status = 'active'
+ AND employees.is_active = 1
+ AND employees.emp_status = 'active'
+ group by group_key
");
// Get the result set
@@ -361,18 +385,20 @@ class EmployeePolicyModel extends Model
$client_id = $ref_data['client_id'];
$client_policy_id = $ref_data['client_policy_id'];
+ $client_branch_id = $ref_data['client_branch_id'];
$insurer_or_tpa = $ref_data['insurer_or_tpa'];
$query = $this->db->query("
- SELECT
+ SELECT DISTINCT
a.id as endorsement_primarykey,
+ a.group_key,
employee_polices.id as primaryKey,
employees.name AS emp_name,
employees.emp_code AS emp_code,
employees.dob AS emp_dob,
employees.gender AS emp_gender,
employees.relationship AS emp_relationship,
- 'Has Define' as emp_type,
+ employees.emp_type as emp_type,
employee_polices.basic_cover_si,
employee_polices.uhid as risk_id,
@@ -396,7 +422,7 @@ class EmployeePolicyModel extends Model
FROM
emp_endorsement a
LEFT JOIN
- employees ON a.emp_code = employees.emp_code
+ employees ON a.emp_code = employees.emp_code and a.pk = employees.id
LEFT JOIN
employee_polices ON employees.id = employee_polices.employee_id
@@ -431,15 +457,20 @@ class EmployeePolicyModel extends Model
AND batch_files.actions = 'export'
AND batch_files.insurer_or_tpa = '{$insurer_or_tpa}'
) AS batch_data ON employee_polices.id = batch_data.emp_policy_id
- WHERE
- batch_data.bf IS NULL
- AND batch_data.bl IS NULL
- AND employee_polices.client_policy_id = {$client_policy_id}
+
+ WHERE employee_polices.client_policy_id = {$client_policy_id}
+ AND employees.client_branch_id = {$client_branch_id}
+ AND (a.endorsement_id IS NULL OR a.endorsement_id = '')
+ AND a.actions = 'd'
AND employee_polices.is_active = 1
- AND (a.endorsement_id IS NULL OR a.endorsement_id = '') AND a.field_name = 'status'
+ AND employee_polices.status = 'active'
+ AND employees.is_active = 1
+ AND employees.emp_status = 'active'
+ group by group_key
");
$result = $query->getResult();
+
return $result;
}
@@ -538,34 +569,62 @@ class EmployeePolicyModel extends Model
public function fetchEmpEndorsementData($fetch_data)
{
+ // dd($fetch_data);
+
$client_policy_id = $fetch_data['client_policy_id'];
+ $client_branch_id = $fetch_data['client_branch_id'];
$emp_name = $fetch_data['emp_name'];
$emp_code = $fetch_data['emp_code'];
// Your raw SQL query
$sql = "
- SELECT
- ep.id,
- MAX(CASE WHEN ee.field_name = 'date_of_exit' THEN ee.new_value END) AS date_of_exit,
- MAX(CASE WHEN ee.field_name = 'reason_for_exit' THEN ee.new_value END) AS reason_for_exit,
- MAX(CASE WHEN ee.field_name = 'status' THEN ee.new_value END) AS status
- FROM
- emp_endorsement AS ee
- JOIN
- employee_polices AS ep ON ep.id = ee.pk
- WHERE
- ee.emp_code = '$emp_code'
- AND ep.client_policy_id = $client_policy_id
- AND ee.name = '$emp_name'
- AND ee.field_name IN ('date_of_exit', 'reason_for_exit', 'status')
- GROUP BY
- ee.emp_code, ee.name, ep.id";
+ SELECT
+ ee.id as emp_endorsement_primarykey,
+ ep.id as emp_policy_primarykey,
+ e.id as employees_primarykey,
+ ee.group_key,
+ MAX(
+ CASE
+ WHEN ee.field_name = 'date_of_exit' THEN ee.new_value
+ END
+ ) AS date_of_exit,
+ MAX(
+ CASE
+ WHEN ee.field_name = 'reason_for_exit' THEN ee.new_value
+ END
+ ) AS reason_for_exit,
+ MAX(
+ CASE
+ WHEN ee.field_name = 'status' THEN ee.new_value
+ END
+ ) AS status
+ FROM
+ emp_endorsement AS ee
+ JOIN employee_polices AS ep ON ep.id = ee.pk
+ JOIN employees AS e ON e.emp_code = ee.emp_code
+ WHERE
+ ee.emp_code = '$emp_code'
+ AND ep.client_policy_id = '$client_policy_id'
+ AND e.client_branch_id = '$client_branch_id'
+ AND ee.name = '$emp_name'
+ AND ee.field_name IN ('date_of_exit', 'reason_for_exit', 'status')
+ AND ep.is_active = 1
+ AND ep.status = 'active'
+ AND e.is_active = 1
+ AND e.emp_status = 'active'
+ GROUP BY
+ ee.group_key
+ ";
+
+ // dd($sql);
// Execute the raw SQL query
$query = $this->db->query($sql);
// Fetch and return results
- return $row = $query->getRowArray();
+ $row = $query->getRowArray();
+
+ return $row;
}
@@ -592,7 +651,7 @@ class EmployeePolicyModel extends Model
}
- public function getEmployeeEndorsementList($client_id, $policy_id, $status)
+ public function getEmployeeEndorsementList($client_id, $policy_id, $status, $branch_id)
{
$query1 = $this->db->table('emp_endorsement e');
$query1->select('
@@ -609,14 +668,16 @@ class EmployeePolicyModel extends Model
insurers.short_name as insurer_short_name
');
$query1->distinct();
- $query1->join('employee_polices ep', 'ep.id = e.pk', 'left');
- $query1->join('employees', 'employees.id = ep.employee_id', 'left');
- $query1->join('client_policy', 'client_policy.id = ep.client_policy_id', 'left');
- $query1->join('policies', 'policies.id = client_policy.policy_id', 'left');
- $query1->join('insurers', 'insurers.id = policies.insurer_id', 'left');
+ $query1->join('employee_polices ep', 'ep.id = e.pk');
+ $query1->join('employees', 'employees.id = ep.employee_id');
+ $query1->join('client_policy', 'client_policy.id = ep.client_policy_id');
+ $query1->join('client_branch', 'client_branch.id = employees.client_branch_id');
+ $query1->join('policies', 'policies.id = client_policy.policy_id');
+ $query1->join('insurers', 'insurers.id = policies.insurer_id');
$query1->whereIn('e.actions', ['c']);
- $query1->where('ep.client_policy_id', $client_id);
- $query1->where('employees.client_id', $policy_id);
+ $query1->where('ep.client_policy_id', $policy_id);
+ $query1->where('employees.client_id', $client_id);
+ $query1->where('employees.client_branch_id', $branch_id);
if($status != 0 && !empty($status)){
$query1->where('e.status', $status);
@@ -640,14 +701,16 @@ class EmployeePolicyModel extends Model
policies.name as policy_name,
insurers.short_name as insurer_short_name
');
- $query2->join('employee_polices ep', 'ep.id = e.pk', 'left');
- $query2->join('employees', 'employees.id = ep.employee_id', 'left');
- $query2->join('client_policy', 'client_policy.id = ep.client_policy_id', 'left');
- $query2->join('policies', 'policies.id = client_policy.policy_id', 'left');
- $query2->join('insurers', 'insurers.id = policies.insurer_id', 'left');
+ $query2->join('employee_polices ep', 'ep.id = e.pk');
+ $query2->join('employees', 'employees.id = ep.employee_id');
+ $query2->join('client_policy', 'client_policy.id = ep.client_policy_id');
+ $query2->join('client_branch', 'client_branch.id = employees.client_branch_id');
+ $query2->join('policies', 'policies.id = client_policy.policy_id');
+ $query2->join('insurers', 'insurers.id = policies.insurer_id');
$query2->whereIn('e.actions', ['si', 'd']);
- $query2->where('ep.client_policy_id', $client_id);
- $query2->where('employees.client_id', $policy_id);
+ $query2->where('ep.client_policy_id', $policy_id);
+ $query2->where('employees.client_id', $client_id);
+ $query1->where('employees.client_branch_id', $branch_id);
if($status != 0 && !empty($status)){
$query2->where('e.status', $status);
@@ -731,6 +794,7 @@ class EmployeePolicyModel extends Model
clients.short_name AS client_short_name,
cp.policy_start_date,
+ cp.policy_no,
policies.name AS policy_name,
@@ -768,6 +832,72 @@ class EmployeePolicyModel extends Model
return $result;
+ }
+
+
+ public function getECardSingleData($rand_string, $emp_code){
+
+ $result = $this->db->table('employees e')
+ ->select('e.id,
+ e.name, e.mobile,
+ e.relationship,
+ e.relationship_code,
+ e.emp_code,
+ e.email_personal,
+ e.email_corporate,
+ e.gender,
+ e.dob,
+ e.doj,
+ e.band,
+ TIMESTAMPDIFF(YEAR, e.dob, CURDATE()) AS emp_age,
+ (SELECT name FROM employees WHERE relationship = "Self" and emp_code = ' . $this->db->escape($emp_code) . ') AS self,
+
+
+ ep.tpa_id,
+ ep.uhid,
+ ep.policy_end_date,
+
+ clients.client_name,
+ clients.short_name AS client_short_name,
+
+ cp.policy_start_date,
+ cp.policy_no,
+
+ policies.name AS policy_name,
+
+ insurers.name AS insurer_name,
+ insurers.short_name AS insurer_short_name,
+ insurers.insurer_logo,
+
+ insurer_branch.branch_name,
+ insurer_branch.branch_code,
+ insurer_branch.city as insurer_branch_city,
+
+ tpa.name AS tpa_name,
+ tpa.tpa_logo AS tpa_logo,
+ tpa.front_card,
+ tpa.back_card,
+ tpa.short_name AS tpa_short_name'
+ )
+
+ ->join('employee_polices ep', 'ep.employee_id = e.id')
+ ->join('client_policy cp', 'cp.id = ep.client_policy_id')
+ ->join('clients', 'clients.id = cp.client_id')
+ ->join('policies', 'policies.id = cp.policy_id')
+ ->join('insurers', 'insurers.id = cp.insurer_id')
+ ->join('insurer_branch', 'insurer_branch.id = cp.insurer_branch_id')
+ ->join('tpa', 'tpa.id = cp.tpa_id')
+ ->where("ep.tpa_id IS NOT NULL AND ep.tpa_id <> ''")
+ ->where('e.emp_status', 'active')
+ ->where('e.is_active', '1')
+ ->where('ep.status', 'active')
+ ->where('ep.is_active', '1')
+ ->where('ep.rand_string', $rand_string)
+ ->get()
+ ->getResultArray();
+
+ return $result;
+
}
@@ -789,4 +919,194 @@ class EmployeePolicyModel extends Model
}
+ public function bulkUpdate($emp_details)
+ {
+ // Extract IDs, tpa_ids, and uhids
+ $ids = array_column($emp_details, 'id');
+ $tpa_ids = array_column($emp_details, 'tpa_id');
+ $uhids = array_column($emp_details, 'uhid');
+
+ // Escape values for SQL
+ $escapedIds = array_map([$this->db, 'escape'], $ids);
+ $escapedTpaIds = array_map([$this->db, 'escape'], $tpa_ids);
+ $escapedUhids = array_map([$this->db, 'escape'], $uhids);
+
+ // Construct the CASE statements
+ $caseTpaId = array_map(function($id, $tpa_id) {
+ return "WHEN id = $id THEN $tpa_id";
+ }, $escapedIds, $escapedTpaIds);
+
+ $caseUhid = array_map(function($id, $uhid) {
+ return "WHEN id = $id THEN $uhid";
+ }, $escapedIds, $escapedUhids);
+
+ // Convert cases to a string
+ $caseTpaIdString = implode(' ', $caseTpaId);
+ $caseUhidString = implode(' ', $caseUhid);
+
+ // Convert ids to a string
+ $idsString = implode(', ', $escapedIds);
+
+ // Construct the SQL query
+ $sql = "
+ UPDATE {$this->table}
+ SET
+ tpa_id = CASE {$caseTpaIdString} END,
+ uhid = CASE {$caseUhidString} END
+ WHERE id IN ({$idsString})
+ ";
+
+ // Begin a transaction
+ $this->db->transBegin();
+
+ try {
+ // Execute the query
+ $this->db->query($sql);
+
+ // Commit the transaction
+ if ($this->db->transStatus() === FALSE) {
+ // If something went wrong, rollback
+ $this->db->transRollback();
+ throw new \Exception('Bulk update failed.');
+ } else {
+ // Otherwise, commit
+ $this->db->transCommit();
+ }
+
+ return $this->db->getLastQuery();
+
+ } catch (\Exception $e) {
+ // Rollback the transaction on error
+ $this->db->transRollback();
+ throw $e;
+ }
+ }
+
+
+ public function bulkUpdateForEndorsement($endorsement_details)
+ {
+
+ // Extract IDs, endorsement_ids, and statuses
+ $ids = array_column($endorsement_details, 'group_key');
+ $endorsement_ids = array_column($endorsement_details, 'endorsement_id');
+ $statuses = array_column($endorsement_details, 'status');
+
+ // Escape values for SQL
+ $escapedIds = array_map([$this->db, 'escape'], $ids);
+ $escapedEndorsementIds = array_map([$this->db, 'escape'], $endorsement_ids);
+ $escapedStatuses = array_map([$this->db, 'escape'], $statuses);
+
+ // Construct the CASE statements
+ $caseEndorsementId = array_map(function ($id, $endorsement_id) {
+ return "WHEN group_key = $id THEN $endorsement_id";
+ }, $escapedIds, $escapedEndorsementIds);
+
+ $caseStatus = array_map(function ($id, $status) {
+ return "WHEN status = $id THEN $status";
+ }, $escapedIds, $escapedStatuses);
+
+ // Convert cases to a string
+ $caseEndorsementIdString = implode(' ', $caseEndorsementId);
+ $caseStatusString = implode(' ', $caseStatus);
+
+ // Convert ids to a string
+ $idsString = implode(', ', $escapedIds);
+
+ // Construct the SQL query
+ $sql = "
+ UPDATE emp_endorsement
+ SET
+ endorsement_id = CASE {$caseEndorsementIdString} END,
+ status = CASE {$caseStatusString} END
+ WHERE group_key IN ({$idsString})
+ ";
+
+ // Begin a transaction
+ $this->db->transBegin();
+
+ try {
+ // Execute the query
+ $this->db->query($sql);
+
+ // Commit the transaction
+ if ($this->db->transStatus() === FALSE) {
+ // If something went wrong, rollback
+ $this->db->transRollback();
+ throw new \Exception('Bulk update failed.');
+ } else {
+ // Otherwise, commit
+ $this->db->transCommit();
+ }
+
+ return $this->db->getLastQuery();
+ } catch (\Exception $e) {
+ // Rollback the transaction on error
+ $this->db->transRollback();
+ throw $e;
+ }
+ }
+
+
+ public function bulkUpdateForCorrection($emp_details){
+
+ foreach ($emp_details as $employee) {
+ $id = $this->db->escape($employee['id']);
+ $ids[] = $id;
+
+ foreach ($employee as $field => $value) {
+ if ($field === 'id') continue;
+ $escapedValue = $this->db->escape($value);
+
+ if (!isset($caseStatements[$field])) {
+ $caseStatements[$field] = [];
+ }
+
+ $caseStatements[$field][] = "WHEN id = $id THEN $escapedValue";
+ }
+ }
+
+ // Construct the CASE strings
+ $caseStrings = [];
+ foreach ($caseStatements as $field => $cases) {
+ $caseStrings[] = "$field = CASE " . implode(' ', $cases) . " END";
+ }
+
+ // Convert ids to a string
+ $idsString = implode(', ', $ids);
+
+ // Construct the SQL query
+ $sql = "
+ UPDATE employees
+ SET " . implode(', ', $caseStrings) . "
+ WHERE id IN ($idsString)
+ ";
+
+ // Begin a transaction
+ $this->db->transBegin();
+
+ try {
+ // Execute the query
+ $this->db->query($sql);
+
+ // Commit the transaction
+ if ($this->db->transStatus() === FALSE) {
+ // If something went wrong, rollback
+ $this->db->transRollback();
+ throw new \Exception('Bulk update failed.');
+ } else {
+ // Otherwise, commit
+ $this->db->transCommit();
+ }
+
+ return $this->db->getLastQuery();
+
+ } catch (\Exception $e) {
+ // Rollback the transaction on error
+ $this->db->transRollback();
+ throw $e;
+ }
+
+ }
+
+
}
\ No newline at end of file
diff --git a/app/Models/FEContentModel.php b/app/Models/FEContentModel.php
new file mode 100644
index 00000000..c1b572d3
--- /dev/null
+++ b/app/Models/FEContentModel.php
@@ -0,0 +1,25 @@
+
\ No newline at end of file
diff --git a/app/Models/FileModel.php b/app/Models/FileModel.php
index aefbb419..51f397ec 100644
--- a/app/Models/FileModel.php
+++ b/app/Models/FileModel.php
@@ -17,7 +17,8 @@ class FileModel extends Model
"reason",
"action",
"client_id",
- "policy_id"
+ "policy_id",
+ "client_branch_id",
];
diff --git a/app/Models/InsurerModel.php b/app/Models/InsurerModel.php
index acda3845..6c5d3617 100644
--- a/app/Models/InsurerModel.php
+++ b/app/Models/InsurerModel.php
@@ -18,6 +18,7 @@ class InsurerModel extends Model
"created_by",
"updated_by",
"is_active",
+ "addition_add_day"
];
diff --git a/app/Models/MessageModel.php b/app/Models/MessageModel.php
index eac21cbe..6f2256a3 100644
--- a/app/Models/MessageModel.php
+++ b/app/Models/MessageModel.php
@@ -69,6 +69,7 @@ class MessageModel extends Model
$builder->orWhere('messages.role_id', $roleId);
$builder->orWhere('messages.team_id', $teamId);
$builder->groupEnd();
+ $builder->orderBy('id', 'desc');
$query = $builder->get();
return $query->getResult();
diff --git a/app/Models/PolicesModel.php b/app/Models/PolicesModel.php
index a56af6bc..8fd138a1 100644
--- a/app/Models/PolicesModel.php
+++ b/app/Models/PolicesModel.php
@@ -39,7 +39,9 @@ class PolicesModel extends Model
{
$premium_slab_data = null;
+ $additional_premium_slab_data = null;
$grid_type = null;
+ $additional_grid_type = null;
$policyPremium1Model = new PolicyPremium1Model();
$premium_slab_data = $policyPremium1Model->where(['client_id' => $client_id, 'client_policy_id' => $policy_id, 'is_active' => 1])->findAll();
@@ -48,7 +50,12 @@ class PolicesModel extends Model
{
// echo '2';
$policyPremium2Model = new PolicyPremium2Model();
- $premium_slab_data = $policyPremium2Model->where(['client_id' => $client_id, 'client_policy_id' => $policy_id, 'is_active' => 1])->findAll();
+ $premium_slab_data = $policyPremium2Model->where(['client_id' => $client_id, 'client_policy_id' => $policy_id, 'is_active' => 1,'rack_rate_type' => 0])->findAll();
+
+ //check any additional rack rate configured
+ $additional_premium_slab_data = $policyPremium2Model->where(['client_id' => $client_id, 'client_policy_id' => $policy_id, 'is_active' => 1,'rack_rate_type' => 1])->findAll();
+
+
}
if(isset($premium_slab_data[0]['policy_grid_id']))
@@ -57,7 +64,14 @@ class PolicesModel extends Model
$policyGridModel = new PolicyGridModel();
$grid_type = $policyGridModel->find($grid_id);
}
-
- return ['slab_rates' => $premium_slab_data,'grid_master' => $grid_type];
+ if(isset($additional_premium_slab_data[0]['policy_grid_id']))
+ {
+ $additional_grid_id = $additional_premium_slab_data[0]['policy_grid_id'];
+ $policyGridModel = new PolicyGridModel();
+ $additional_grid_type = $policyGridModel->find($additional_grid_id);
+ }
+
+
+ return ['slab_rates' => $premium_slab_data,'grid_master' => $grid_type,'additional_slab_info' => ['slab_rates' => $additional_premium_slab_data,'grid_master' => $additional_grid_type]];
}
}
diff --git a/app/Models/PolicyPremium2Model.php b/app/Models/PolicyPremium2Model.php
index a03ca381..b302a53c 100644
--- a/app/Models/PolicyPremium2Model.php
+++ b/app/Models/PolicyPremium2Model.php
@@ -25,6 +25,8 @@ class PolicyPremium2Model extends Model
'is_active',
'premium_type',
'relationship',
+ 'additional_relationship',
+ 'rack_rate_type',
];
diff --git a/app/Views/UserList.php b/app/Views/UserList.php
index a4d5afdc..c1794990 100644
--- a/app/Views/UserList.php
+++ b/app/Views/UserList.php
@@ -42,9 +42,9 @@ table.dataTable tbody td {
-
+
User List
-
@@ -303,8 +303,9 @@ var form = document.getElementById("UserForm");
// Add submit event listener to the form
form.addEventListener("submit", function(event) {
// Disable the submit button to avoid multiple submissions
- document.getElementById("btnSubmit").disabled = true;
+ // document.getElementById("btnSubmit").disabled = true;
});
+
diff --git a/app/Views/batch_list.php b/app/Views/batch_list.php
index c08961b8..0b28f477 100644
--- a/app/Views/batch_list.php
+++ b/app/Views/batch_list.php
@@ -1,33 +1,39 @@
-
+
+
+
+
+
+
+
{INSURER_NAME}
+
+
+
+ | UHID No |
+ : |
+ {UHID} |
+
+
+ | {NAME} |
+
+
+ | Age |
+ : |
+ {AGE} years |
+
+
+ | Relationship |
+ : |
+ {RELATION} |
+
+
+ | Plan Period |
+ : |
+ {POLICY_START_DATE} To {POLICY_DATE} |
+
+
+ | Policy No |
+ : |
+ {POLICY_NO} |
+
+ Insurer |
+ : |
+ LCO : {TPA_ID} : {INSURER_BRANCH} |
+
+
+
+
+

+
+
+
+
Instructions
+
+ - Card has to be presented to our network hospitals at the time of the admission while availing cashless
+ - Free authorizationfrom FHPL it must should be taken before 48 hrs for all planed admissions & emergency admissions within 24 hrs of getting admitted to any network hospitals FHPL
+ - The issuance of this card doesnot guarantee cashless benefits /hospitalisation
+ - The card is for the identification purpose.in case of without photograph card.Alternative identification proof such as Voter ID/driving license etc...should be produced
+ - All insurance claim will be processed as per policy terms & conditions
+ - For more details kindly referbook kindly provided
+
+
+
+
+
+
TERMS AND CONDITIONS:
+
+
+ - This card is generated as per the details given by your employer/HR. Incase of any errors in the
+ details you may confirm the same through your employer for making required corrections.
+ - No physical card will be provided to you. For all requirements you may use this card printed in black
+ and white or colour.
+ - You can access our network hospitals list from our website https://www.fhpl.net for any information
+ regarding hospitals available within your location or as required.
+ - For the convenience of the members the guide book is made available on our website
+ https://www.fhpl.net for understanding protocols in the event of any hospitalization assistance required
+ for availing cashless service and also to forward any claim where the member has spent on his/her own.
+ - All our network hospitals will accept the printed card and seek the preauthorization from FHPL in the
+ event of any in-patient hospitalization.
+ - Incase there is no photograph on the ID card, the member has to identify himself/herself with any other
+ photo-card like: credit card, ration card, electoral card, Company ID card etc in conjunction with this card.
+ - This card is not transferable and cannot be forwarded further to any other person by email/fax.
+ - The card will be visible to any member as long the policy is valid after which this service will be
+ withdrawn or till such time the member is employed with the current employer.
+ - Usage of this card after the validity/policy expiry will not be entertained.
+ - A fresh card will be generated subjected to the renewal of the policy.
+ - For Any further queries, Please feel free to contact us on Toll—Free Helpline :1800 - 103 - 7519
+
+
+
+
+
-
-
-
-
-
THE NEW INDIA COMPANY PRIVATE LIMITED
-
-
-
-
- | Card No |
- : |
- CHE-NI-K0674-001-0000003-A |
-
-
- | Name |
- : |
- BHODANADHAN S |
-
-
- | Gender |
- : |
- M |
-
-
- | age |
- : |
- 53 years |
-
-
- | Employee code |
- : |
- 1015 |
-
-
- | Corporate name |
- : |
- KELD ELLENTOFT INDIA PVT LTD |
-
-
- | Valid form |
- : |
- 28-04-2024 |
-
-
-
-
-
-
-
-
-
-
Terms&conditions
-
- - Submit this card & photo ID for availing cashless insurrer empanelled hospitals
- - Cashless facility is subject to approved by vidal health as per policy terms and conditions
- - Validdity of this card is subject to valid policy renewal of policy
- - imidiate intimation to vidal health is must incase of any hospitalisation
- - Download the vidal health mobile app from android iOS to get an E-Card check your policy claim status, Hospital list and more, Give a missed call to 022-4892-6099 from your registered mobile number, or visit www.vidalhealthpa.com,or scan << Qr code on corner >>
-
-
-

-
-
-
24x7 help line no
-
-
- karnataka/andrapradesh/telangana:080-46267018/1860425051
-
-
- North and east region/gujarat:080-46267021/18604250261
-
-
- Maharastra:080-46267020/18604250254
-
-
- Tamil Nadu:080-46267020/18604250254
-
-
- Kerala:080-46267019/18604250253
-
-
- S.R citizen:080-4626-7070
-
-
- vidal health insurance TPA pvt limited,tower no 2,
-
- First Floor,SJR ipark,EPIP zone ,whitefield,bangalore,
-
-
-
- email:helpvidalhealthpa@gmail.com/website:WWW.vidalhealthp.com
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/writable/e_card_template/fhpl_tpa.html b/writable/e_card_template/fhpl_tpa.html
new file mode 100644
index 00000000..a074425b
--- /dev/null
+++ b/writable/e_card_template/fhpl_tpa.html
@@ -0,0 +1,89 @@
+
\ No newline at end of file
diff --git a/writable/e_card_template/hcl.html b/writable/e_card_template/hcl.html
deleted file mode 100644
index 60f04c20..00000000
--- a/writable/e_card_template/hcl.html
+++ /dev/null
@@ -1,118 +0,0 @@
-
-
-