MERGE_BRANCH_WITH COOKIE SAVE SRINIVAS

This commit is contained in:
Srinivas-Saravanan 2025-01-07 17:00:24 +05:30
commit 11c93c21ed
7 changed files with 387 additions and 43 deletions

View File

@ -428,7 +428,7 @@ $routes->group("/api", ["filter" => "authJWT"], function ($routes) {
$routes->post("logined", "RestAuthenticationController::logined");
$routes->post("getId", "RestAuthenticationController::getUserIdFromToken");
});
// $routes->get("getEmployeePolicy", "EmployeeRestController::getEmployeePolicy");
$routes->group("employeeRest", ["filter" => "authJWT"], function ($routes) {
$routes->post("getVerifiedUserData", "RestAuthenticationController::getVerifiedUserData");

View File

@ -2549,12 +2549,14 @@ class ClientController extends AdminController
}
}
//for this function policy binding dropdown list use ( client policy )
public function getClientBranch($client_id)
{
$branchs = $this->clientBranchModel
->select('*')
->where('client_id', $client_id)
->where('is_active', 1)
->findAll();
return $this->respond(['status' => true, 'code' => 200, 'data' => $branchs], 200);

View File

@ -3854,7 +3854,7 @@ class EmpDataServiceController extends BaseController
//end not in use
/**
* The below functions are Calculates and records cash deposits for employee policies at inception.
* The below functions are Calculates and records cash deposits for employee policies at Deletion.
*
* @param array $arrayData An array containing necessary data including :
* - employee IDs,
@ -4059,7 +4059,7 @@ class EmpDataServiceController extends BaseController
AND emp_endorsement.field_name = 'date_of_exit'
")->getRow();
dd(db_connect()->getLastQuery(), $amount);
// dd(db_connect()->getLastQuery(), $amount);
if($amount){

View File

@ -1086,6 +1086,7 @@ class EmployeeController extends AdminController
return $response;
}
//E-CARD DOWNLOAD FUNCTION
public function generateIDCardForEmployee($rand_string, $people = 0)
{
// dd($rand_string, $people);
@ -1186,6 +1187,8 @@ class EmployeeController extends AdminController
'{QR_ANDROID_2}' => base_url() . 'public/e_card_imgs/play_store.png',
'{QR_IOS_2}' => base_url() . 'public/e_card_imgs/appstore.png',
];
$placeholders['{LEVELS}'] = $this->generateAcmAndMForEcard($client_id);
foreach ($placeholders as $placeholder => $replaceValue) {
$htmlContent = str_replace($placeholder, $replaceValue, $htmlContent);
@ -1225,8 +1228,278 @@ class EmployeeController extends AdminController
}
//truncateFileDataIn DB (de activate rows)
//truncateFileDataIn DB (de activate rows) NEW FUNCTION
public function truncateFileData($file_id, $role_id = null)
{
$this->myLogger->logme('error', '---- truncateFileData Function called ----');
$file_id = $this->request->uri->getSegment(3);
// $file_id = 747;
$this->myLogger->logme('error', 'File id for truncate : -- FILE ID : {data} --', ['data' => $file_id]);
//get the files data
$file = $this->fileModel->find($file_id);
$client_id = $file['client_id'];
$client_policy_id = $file['policy_id'];
$loggedInUserID = get_session_userid();
//get the client policy data
$policy_data = $this->clientPolicyModel->where('id', $client_policy_id)->first();
//get the cd transaction data based on the insurer and client
$cd_tranction = $this->cashDepositModel
->where('client_id', $client_id) //client
->where('insurer_id', $policy_data['insurer_id']) //insurer
->where('event_name',$file['action']) //event
->where('client_policy_id', $client_policy_id)//policy
->orderBy('id', 'desc')
->first();
// print_r($file); die;
if ($file['action'] == 'inception' || $file['action'] == 'dependent_addition' || $file['action'] == 'addition' || $file['action'] == 'enrollment' || $file['action'] == 'missed_inception') {
if($file['action'] == 'enrollment'){
$result = $this->employeeModel->getEmpListByFileId(file_id: $file_id, emp_status: ['draft','enrolled'], policy_status: ['draft','enrolled']);
}else{
$result = $this->employeeModel->getEmpListByFileId(file_id: $file_id, emp_status: ['active'], policy_status: ['active']);
}
// print_r($result); die;
if (count($result) && $role_id == null) {
if(get_role_id() == 1 || get_role_id() == 5){
return $this->respond(['role' => get_role_id(), 'dataStatus' => false, 'code' => 404, 'message' => 'File data already processed. Do you want to truncate data from uploaded file?'], 200);
}else{
return $this->respond(['role' => get_role_id(), 'dataStatus' => false, 'code' => 404, 'message' => 'File data already processed'], 200);
}
} else {
$this->myLogger->logme('error', '---- TRUNCATED STARTED WITH ADMIN OR HEAD PERMISSION ----');
$this->myLogger->logme('error', '---- Event Type : -- {data} ----', ['data' => $file['action']]);
if($file['action'] != 'enrollment')
{
$employee_policy_data_with_file_id = $this->employeePolicyModel->where('file_id', $file_id)->findAll();
if(!empty($employee_policy_data_with_file_id) && count($employee_policy_data_with_file_id) > 0){
// GET THE CD TRANSACTION AMOUNT
$cd_amount_total = $this->employeePolicyModel->calculateCdTranctionAmount($file_id);
$cd_amount = $cd_amount_total['total'] ?? 0;
$this->myLogger->logme('error', '---- CD Amount : {data} ----', ['data' => $cd_amount]);
//STEP: 1 - Update employee policy table
$db = db_connect();
$query = "
UPDATE employee_polices
SET employee_polices.status = 'truncated', employee_polices.is_active = 0
WHERE employee_polices.file_id = $file_id
";
$db->query($query);
$affectedRows = $db->affectedRows();
$this->myLogger->logme('error', '---- employee_polices table update query : {data} ----', ['data' => $query]);
$this->myLogger->logme('error', '---- employee_polices table updated - Affected Rows : {data} ----', ['data' => $affectedRows]);
// print_r($db->getLastQuery()); die;
//STEP:2 - Update emp_endorsement Table
if(in_array($file['action'], ['addition', 'dependent_addition'])){
$this->empEndorsementModel->where('file_id', $file_id)->set(['status' => 'truncated','is_active' => 0])->update();
$this->myLogger->logme('error', '---- emp_endorsement table updated ----');
}
//STEP:3 - Update files table status
$this->fileModel->where('id', $file_id)->set(['status' => 'truncated'])->update();
$this->myLogger->logme('error', '---- files table updated ----');
//FINAL STEP - Update reverse entry in cash_deposite table
if(!empty($cd_amount)){
$cd_data = [
'amount' => $cd_amount,
'sub_type_id' => 8,
'endorsement_no' => null,
'insurer_id' =>$policy_data['insurer_id'],
'description' => 'The policy Truncated by Admin or Head',
'transaction_type' => 'Credit',
'updated_by' => 1,
'client_id' => $client_id,
'client_policy_id' => $client_policy_id,
'cd_ac_no' => $policy_data['cd_ac_no'] ?? null,
'cd_ac_pk' => $policy_data['cd_ac_pk'] ?? null,
'event_name' => $file['action'],
];
$response = DepositHelper::saveDeposit($cd_data, $loggedInUserID);
$this->myLogger->logme('error', 'cash_deposite table updated -- cd transaction');
}
}else{
$this->myLogger->logme('error', '---- There is no data to truncate ----');
return $this->respond(['role' => get_role_id(), 'dataStatus' => false, 'code' => 404, 'message' => 'There is no data to truncate'], 200);
}
}
else
{
// echo 'came here...1';
//check all dependents added by self and other dependent policies
$emp_codes = $this->employeeModel->select('emp_code')
->where('file_id', $file_id)
->findAll();
$emp_codes = array_column($emp_codes,'emp_code');
// Kint::dump($emp_codes);//die;
$dependent_policies = $this->clientPolicyModel->select('id')
->where('base_policy', $client_policy_id)
->findAll();
// $dependent_policies = [ [10],[25],[35] ];
// Kint::dump($dependent_policies);
// Kint::dump(array_column($dependent_policies,'id'));
if(count($dependent_policies))
{
$dependent_policies = array_column($dependent_policies,'id');
// Kint::dump($dependent_policies);
$second_level_dependent_policies = $this->clientPolicyModel->select('id')
->whereIn('base_policy', $dependent_policies)
->findAll();
// dd($second_level_dependent_policies);
if(count($second_level_dependent_policies))
{
$second_level_dependent_policies = array_column($second_level_dependent_policies,'id');
}
$dependent_policies = array_merge($dependent_policies,$second_level_dependent_policies);
}
$dependent_policies = array_merge($dependent_policies,[$client_policy_id]);
// Kint::dump($dependent_policies);
//update emp and emp plocies
$db = db_connect();
$emp_codes = '(' . implode(',', array_map(fn($code) => "'$code'", $emp_codes)) . ')';
$dependent_policies = '(' . implode(',', $dependent_policies) . ')';
$query = "
UPDATE employee_polices
JOIN employees ON employees.id = employee_polices.employee_id and employees.emp_code in $emp_codes
SET employee_polices.status = 'truncated', employee_polices.is_active = 0
WHERE employee_polices.client_policy_id in $dependent_policies
";
// print_r($query); die;
$db->query($query);
$affectedRows = $db->affectedRows();
// dd($affectedRows);
$affectedRows = $affectedRows * 2;
$this->fileModel->where('id', $file_id)->set(['status' => 'truncated'])->update();
}
$this->myLogger->logme('error', 'SUCCESSFULLY TRUNCATED');
return $this->respond(['dataStatus' => true, 'code' => 200, 'data' => round($affectedRows / 2)], 200);
}
} else if ($file['action'] == 'si_enhancement' || $file['action'] == 'correction' || $file['action'] == 'deletion') {
$res = $this->empEndorsementModel->select(['count(id) as count'])
->where('emp_endorsement.file_id', $file_id)
->groupStart()
->where('emp_endorsement.endorsement_id is not null')
->orwhereIn('emp_endorsement.status', ['complete'])
->groupEnd()
->get()
->getResult();
// print_r($this->empEndorsementModel->getLastQuery());
// echo $res[0]->count;die();
if ($res[0]->count == 0 || $role_id == 5 || $role_id == 1) {
$this->myLogger->logme('error', 'TRUNCATED STARTED WITH ADMIN OR HEAD PERMISSION');
$this->myLogger->logme('error', 'Event Type : -- {data} --', ['data' => $file['action']]);
$transaction_type = 'Credit';
$cd_amount = $cd_tranction['amount'];
if($file['action'] == 'deletion'){
$transaction_type = 'Debit';
//get cd amount for the particular file id to reverse entry to the cash deposite for only deletion
$cd_amount_total = $this->employeePolicyModel->getDeletionDataForTruncated($file['id']);
$totalSum = array_sum(array_column($cd_amount_total, 'total'));
$cd_amount = $totalSum;
$this->myLogger->logme('error', 'Deletion CD Amount : {data}', ['data' => $cd_amount]);
}
$this->myLogger->logme('error', 'Endorsemnt CD Amount : {data}', ['data' => $cd_amount]);
//STEP 1:
//update truncated status to the Emp_endorsement table
$this->empEndorsementModel->where('file_id', $file_id)
->set(['status' => 'truncated','is_active' => 0])
->update();
$this->myLogger->logme('error', 'emp_endorsement table updated');
//STEP 2:
if($file['action'] == 'deletion') {
//update the employee policy table reverse the data
$this->employeePolicyModel->updateEmployeePolicyTruncateReverse($file_id);
$this->myLogger->logme('error', 'employee_polices table updated for deletion');
}
if($file['action'] == 'correction'){
}
// STEP 3:
//update files table status to "truncated"
$this->fileModel->where('id', $file_id)->set(['status' => 'truncated'])->update();
$this->myLogger->logme('error', 'files table updated');
if($cd_tranction && $file['action'] != 'correction'){
$cd_data = [
'amount' => $cd_amount,
'sub_type_id' => 8,
'endorsement_no' => null,
'insurer_id' =>$policy_data['insurer_id'],
'description' => 'The policy Truncated by Admin or Head',
'transaction_type' => $transaction_type,
'updated_by' => 1,
'client_id' => $client_id,
'client_policy_id' => $client_policy_id,
'cd_ac_no' => $policy_data['cd_ac_no'] ?? null,
'cd_ac_pk' => $policy_data['cd_ac_pk'] ?? null,
'event_name' => $file['action'],
];
$response = DepositHelper::saveDeposit($cd_data, $loggedInUserID);
$this->myLogger->logme('error', 'cash_deposite table updated -- cd transaction');
}
$this->myLogger->logme('error', 'SUCCESSFULLY TRUNCATED');
return $this->respond(['dataStatus' => true, 'code' => 200, 'data' => 'success'], 200);
} else {
if(get_role_id() == 1 || get_role_id() == 5){
return $this->respond(['role' => get_role_id(), 'dataStatus' => false, 'code' => 404, 'message' => 'File data already processed. Do you want to truncate data from uploaded file?'], 200);
}else{
return $this->respond(['dataStatus' => false, 'code' => 404, 'message' => 'File data already processed'], 200);
}
}
}
}
//truncateFileData OLD FUNCTION
public function truncateFileDataOld($file_id, $role_id = null)
{
$file_id = $this->request->uri->getSegment(3);
// $file_id = 747;
@ -1288,7 +1561,7 @@ class EmployeeController extends AdminController
if($file['action'] != 'enrollment')
{
//STEP: 1 - Update employee policy table
//STEP: 1 - Update employee policy table
//update emp and emp plocies
$db = db_connect();
$query = "
@ -1331,13 +1604,13 @@ class EmployeeController extends AdminController
// Kint::dump($emp_codes);//die;
$dependent_policies = $this->clientPolicyModel->select('id')
->where('base_policy', $client_policy_id)
->findAll();
->where('base_policy', $client_policy_id)
->findAll();
// $dependent_policies = [ [10],[25],[35] ];
// Kint::dump($dependent_policies);
// Kint::dump(array_column($dependent_policies,'id'));
if(count($dependent_policies))
{
// Kint::dump($dependent_policies);
// Kint::dump(array_column($dependent_policies,'id'));
if(count($dependent_policies))
{
$dependent_policies = array_column($dependent_policies,'id');
// Kint::dump($dependent_policies);
$second_level_dependent_policies = $this->clientPolicyModel->select('id')
@ -1350,11 +1623,11 @@ class EmployeeController extends AdminController
}
$dependent_policies = array_merge($dependent_policies,$second_level_dependent_policies);
}
$dependent_policies = array_merge($dependent_policies,[$client_policy_id]);
// Kint::dump($dependent_policies);
}
$dependent_policies = array_merge($dependent_policies,[$client_policy_id]);
// Kint::dump($dependent_policies);
//update emp and emp plocies
//update emp and emp plocies
$db = db_connect();
$emp_codes = '(' . implode(',', array_map(fn($code) => "'$code'", $emp_codes)) . ')';
$dependent_policies = '(' . implode(',', $dependent_policies) . ')';
@ -1402,7 +1675,7 @@ class EmployeeController extends AdminController
}
} else if ($file['action'] == 'si_enhancement' || $file['action'] == 'correction' || $file['action'] == 'deletion') {
$res = $this->empEndorsementModel->select(['count(id) as count'])
->where('emp_endorsement.file_id', $file_id)
->groupStart()
@ -1425,7 +1698,7 @@ class EmployeeController extends AdminController
if($file['action'] == 'deletion'){
$transaction_type = 'Debit';
//get cd amount for the particular file id to reverse entry to the cash deposite for only deletion
//get cd amount for the particular file id to reverse entry to the cash deposite for only deletion
$cd_amount_total = $this->employeePolicyModel->getDeletionDataForTruncated($file['id']);
$totalSum = array_sum(array_column($cd_amount_total, 'total'));
$cd_amount = $totalSum;
@ -2173,27 +2446,30 @@ class EmployeeController extends AdminController
exit;
}
//------------------------------------------------------------------------------------------------------
public function test_members_list(){
// $model = new EmployeeModel();
// $list = [
// ['relationship' => 'spouse','emp_code' => 'TEST002', 'name' => 'Lakshmi','email_personal' => 'lakshmi@gmail.com','mobile'=>'6382156701','gender'=>'female','dob'=>'1996-05-19','doj'=>'2022-02-01','basic_pay'=>'100000','emp_status'=>'enrolled'],
// ['relationship' => 'Daughter','emp_code' => 'TEST002', 'name' => 'Jayalakshmi','email_personal' => 'jayalakshmi@gmail.com','mobile'=>'6382156701','gender'=>'female','dob'=>'2018-05-19','doj'=>'2022-02-01','basic_pay'=>'100000','emp_status'=>'enrolled'],
// ['relationship' => 'Son','emp_code' => 'TEST002', 'name' => 'Jayam Ravi','email_personal' => 'jayamravi@gmail.com','mobile'=>'6382156701','gender'=>'male','dob'=>'1994-05-19','doj'=>'2019-02-01','basic_pay'=>'100000','emp_status'=>'enrolled'],
// // ['relationship' => 'self','emp_code' => 'TEST003', 'name' => 'Ravi Shankar','email_personal' => 'srinivassaravanan2002@gmail.com','email_corporate'=>'srinivas.saravanan@venbainfotech.com','mobile'=>'6382156701','gender'=>'male','dob'=>'1994-05-19','doj'=>'2022-02-01','basic_pay'=>'100000','emp_status'=>'enrolled']
// ['relationship' => 'spouse','emp_code' => 'TEST001', 'name' => 'Lakshmi','email_personal' => 'lakshmi@gmail.com','mobile'=>'6382156701','gender'=>'female','dob'=>'1996-05-19','doj'=>'2022-02-01','basic_pay'=>'100000','emp_status'=>'enrolled'],
// $model = new EmployeeModel();
// $list = [
// ['relationship' => 'spouse','emp_code' => 'TEST002', 'name' => 'Lakshmi','email_personal' => 'lakshmi@gmail.com','mobile'=>'6382156701','gender'=>'female','dob'=>'1996-05-19','doj'=>'2022-02-01','basic_pay'=>'100000','emp_status'=>'enrolled'],
// ['relationship' => 'Daughter','emp_code' => 'TEST002', 'name' => 'Jayalakshmi','email_personal' => 'jayalakshmi@gmail.com','mobile'=>'6382156701','gender'=>'female','dob'=>'2018-05-19','doj'=>'2022-02-01','basic_pay'=>'100000','emp_status'=>'enrolled'],
// ['relationship' => 'Son','emp_code' => 'TEST002', 'name' => 'Jayam Ravi','email_personal' => 'jayamravi@gmail.com','mobile'=>'6382156701','gender'=>'male','dob'=>'1994-05-19','doj'=>'2019-02-01','basic_pay'=>'100000','emp_status'=>'enrolled'],
// // ['relationship' => 'self','emp_code' => 'TEST003', 'name' => 'Ravi Shankar','email_personal' => 'srinivassaravanan2002@gmail.com','email_corporate'=>'srinivas.saravanan@venbainfotech.com','mobile'=>'6382156701','gender'=>'male','dob'=>'1994-05-19','doj'=>'2022-02-01','basic_pay'=>'100000','emp_status'=>'enrolled']
// ['relationship' => 'spouse','emp_code' => 'TEST001', 'name' => 'Lakshmi','email_personal' => 'lakshmi@gmail.com','mobile'=>'6382156701','gender'=>'female','dob'=>'1996-05-19','doj'=>'2022-02-01','basic_pay'=>'100000','emp_status'=>'enrolled'],
// ];
// foreach($list as $listitem){
// ];
// foreach($list as $listitem){
// $model->insert($listitem);
// }
// die();
$employee_data = $this->employeeModel->getTestEmployeeData();
$data['employees'] = $employee_data;
$data['clients'] = $this->clientModel->findAll();
// dd($data);
return $this->loadLayout('test_members_list',$data);
// $model->insert($listitem);
// }
// die();
$employee_data = $this->employeeModel->getTestEmployeeData();
$data['employees'] = $employee_data;
$data['clients'] = $this->clientModel->findAll();
// dd($data);
return $this->loadLayout('test_members_list',$data);
}
public function mapEmployees(){
@ -2276,8 +2552,6 @@ class EmployeeController extends AdminController
}
public function cloneWorksheet()
{
// Define file paths
@ -2332,4 +2606,45 @@ class EmployeeController extends AdminController
}
}
//------------------------------------------------------------------------------------------------------
public function generateAcmAndMForEcard($client_id)
{
$db = db_connect();
$builder = $db->table('client_rm');
$builder->select('user_profiles.first_name, user_profiles.mobile, user_profiles.email, client_rm.level');
$builder->join('user_profiles', 'client_rm.user_id = user_profiles.id');
$builder->where('client_rm.client_id', $client_id);
$builder->whereIn('client_rm.level', [2, 3]);
$builder->where('client_rm.is_active', 1);
$builder->orderBy('client_rm.level', 'desc');
$query = $builder->get();
$result = $query->getResultArray();
$levels = [
3 => [],
2 => []
];
foreach ($result as $value) {
$levels[$value['level']][] = $value;
}
// Generate the HTML content
$html = '';
foreach ($levels as $level => $contacts) {
$displayLevel = $level == 3 ? 1 : 2; // Switch levels for display
$html .= '<br>Level ' . $displayLevel . '<br>';
foreach ($contacts as $index => $contact) {
$html .= ($index + 1) . '. ' . $contact['first_name'] . ' / ' . $contact['mobile'] . ' / ' . $contact['email'] . '<br>';
}
}
$html .= '<br><br><br>';
return $html;
}
}

View File

@ -153,6 +153,8 @@ class EmployeeModel extends Model
->join('client_policy', 'client_policy.id = employee_polices.client_policy_id')
->join('policy_type', 'policy_type.id = client_policy.policy_type_id')
->where('client_policy.policy_status', 1)
->where('employee_polices.status !=', 'truncated')
->where('employee_polices.is_active', 1)
->where('employee_polices.employee_id', $id)
->get()
->getResult();

View File

@ -1683,4 +1683,29 @@ class EmployeePolicyModel extends Model
$query = "UPDATE emp_endorsement SET status = $caseStatus, endorsement_id = $caseEndorsementId WHERE id IN ($ids);"; // Execute the query
$this->db->query($query);
}
//calculate the CD Transaction sum of the amount for the inception, addition, dependent addition, missed inception
public function calculateCdTranctionAmount($file_id)
{
$query = $this->db->query("
SELECT
ROUND(SUM(ep.rata_premimum + ep.gst), 2) AS total
FROM
employee_polices ep
WHERE
ep.file_id = $file_id
AND ep.uhid IS NOT NULL'
AND ep.status != 'truncated'
AND ep.status != 'truncated'
AND ep.is_active = 1;
");
$result = $query->getResultArray();
// dd($this->db->getLastQuery(), $result);
// dd($result);
return $result[0];
}
}

View File

@ -265,11 +265,13 @@ $(document).ready(function() {
$(document).ready(function() {
$('#tickets-table').DataTable({
dom: "<'row'<'col-sm-0'f><'col-sm-9 text-right'B>>",
dom: "<'row'<'col-sm-0'f><'col-sm-7 text-right'B>>" +
"<'row'<'col-sm-12'tr>>" +
"<'row'<'col-sm-5'i><'col-sm-7'p>>",
buttons: [{
extend: 'csv',
text: 'CSV',
title: 'TransactionDetails',
title: 'CD TransactionDetails',
exportOptions: {
columns: ''
}
@ -283,17 +285,15 @@ $(document).ready(function() {
}
}
],
language: {
search: "_INPUT_",
searchPlaceholder: "Search..."
},
ordering: false,
paging: true ,
});
});
</script>
<!-- Include jQuery library (if not already included) -->
<script>