FEAT_IMOPARTEXPORT_SIE_DEL_COMPLETE : RV

This commit is contained in:
VENKATESHWARAN 2024-03-21 08:27:52 +05:30
parent 65bb5a0c63
commit 00d4e9fbcc
8 changed files with 1018 additions and 130 deletions

View File

@ -49,18 +49,19 @@ class EmpDataServiceController extends BaseController
}
public function batchFilesAndBatchListEntry($data, $filename, $objects){
public function batchFilesAndBatchListEntry($data, $objects){
$random_number_count = 4;
$data['batch_code'] = generate_random_string($random_number_count);
$data['created_by'] = get_session_userid();
$data['file_name'] = $filename;
// $data['file_name'] = $filename;
$insert = $this->batchFileModel->insert($data);
$batch_file_batch_code = $this->batchFileModel->where('id', $insert)->first();
if($insert){
foreach($objects as $value){
$batch_list_data['batch_code'] = $batch_file_batch_code['batch_code'];
$batch_list_data['emp_policy_id'] = $value->employee_policy_id ?? $value->emp_id;
$batch_list_data['emp_policy_id'] = $value->primaryKey ?? $value->employee_policy_id ?? '';
$batch_list_data['created_by'] = get_session_userid();
$this->batchListModel->insert($batch_list_data);
}
@ -70,60 +71,108 @@ class EmpDataServiceController extends BaseController
}
public function generateExcelForAdditionandInception($batch_files_data, $export_data, $file_name)
{
/**
* Generates an Excel file for Inception_Addititon_DependentAddititon, Correction, SI_Enhancement and Deletion events based on given export data.
*
* @param array $export_data An array containing export data such as
* client_policy_id,
* insurer_or_tpa,
* event_type,
* actions,
* file_name.
* @return bool True if the Excel file is successfully generated and exported, otherwise false.
*/
$data = transform_objects_to_array_for_inception($export_data);
public function generateExcelForAdditionandInception($export_data)
{
// Fetch employee data for export from the database
$objects = $this->employeePolicyModel->getInceptionEmployeeDataForExportExcel($export_data['client_policy_id'], $export_data['insurer_or_tpa'], $export_data['event_type'], $export_data['actions']);
// Log the count of exported data
$count = count($objects);
$export_data['count'] = $count;
$this->myLogger->logme('error', 'Inception export data count : {data}', ['data'=> $count ]);
// If no data is found for export, return false
if($count == 0){
return false;
}
// Log the export file name
$this->myLogger->logme('error', 'Inception export file name : {data}', ['data'=> $export_data['file_name'] ]);
// Transform retrieved objects to an array suitable for export
$data = transform_objects_to_array_for_inception($objects);
// Define headers for the Excel file
$headers = [
'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'
];
// Create a temporary file in memory
// Generate Excel file
$tempFile = tmpfile();
$success = generate_excel($headers, $data, $tempFile, 1);
// Generate Excel file with the temporary file
$value = generate_excel($headers, $data, $tempFile, 1);
// If Excel generation is successful
if ($success) {
// Batch files and list entry
$return = $this->batchFilesAndBatchListEntry($export_data, $objects);
// Generate a random filename
$randomFilename = $file_name;
if($value){
$return = $this->batchFilesAndBatchListEntry($batch_files_data, $randomFilename, $export_data);
if($return){
// Set the appropriate headers for Excel file download
// If batch operation is successful
if ($return) {
// Set headers for Excel file download
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="' . $randomFilename . '"');
header('Content-Disposition: attachment;filename="' . $export_data['file_name'] . '"');
header('Cache-Control: max-age=0');
// Rewind the temporary file pointer
// Output file contents
rewind($tempFile);
// Output the contents of the temporary file to the browser
fpassthru($tempFile);
// Close and remove the temporary file
// Close and remove temporary file
fclose($tempFile);
}else{
return false;
}
return true; // Excel file successfully generated and exported
} else {
return false; // Batch operation failed
}
}
return false; // Excel generation failed
}
public function generateExcelForCorrection($file_name, $objects, $batch_files_data)
public function generateExcelForCorrection($export_data)
{
$objects = $this->employeePolicyModel->getCorrectionEmployeesDataForExportExcel($export_data['client_id'], $export_data['client_policy_id'], $export_data['insurer_or_tpa']);
// dd($objects);
$count = count($objects);
$export_data['count'] = $count;
$this->myLogger->logme('error','Correction export data count : {data}', ['data'=> $count ]);
if($count == 0){
return false;
}
$this->myLogger->logme('error','Correction 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'
'Emp Code',
'RISK ID',
'NAME OF EMP/DEP',
'EMP/DEP TYPE',
'RELATION',
'DOB',
'GENDER',
'Wrong Data',
'Correct Data',
'Remarks',
'Endorsement_Id'
];
@ -132,17 +181,93 @@ class EmpDataServiceController extends BaseController
// Generate Excel file with the temporary file
$value = generate_excel($headers, $correction_data, $tempFile);
// Generate a random filename
$randomFilename = $file_name;
if($value){
$return = $this->batchFilesAndBatchListEntry($batch_files_data, $randomFilename, $objects);
$return = $this->batchFilesAndBatchListEntry($export_data, $objects);
if($return){
// Set the appropriate headers for Excel file download
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="' . $randomFilename . '"');
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;
}
}
}
public function generateExcelForSIEnhancement($export_data)
{
$objects = $this->employeePolicyModel->getSIEnhancementEmployeesDataForExportExcel($export_data['client_id'], $export_data['client_policy_id'], $export_data['insurer_or_tpa']);
// dd($objects);
$count = count($objects);
$export_data['count'] = $count;
$this->myLogger->logme('error','SI_Enhancement export data count : {data}', ['data'=> $count ]);
if($count == 0){
return false;
}
$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);
$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'
];
// Create a temporary file in memory
$tempFile = tmpfile();
// Generate Excel file with the temporary file
$value = generate_excel($headers, $si_data, $tempFile);
if($value){
$return = $this->batchFilesAndBatchListEntry($export_data, $objects);
if($return){
// 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
@ -161,6 +286,120 @@ class EmpDataServiceController extends BaseController
}
}
}
public function generateExcelForDeletion($export_data)
{
$objects = $this->employeePolicyModel->getDeletionEmployeeDataForExportExcel($export_data['client_id'], $$export_data['client_policy_id'], $$export_data['insurer_or_tpa']);
$count = count($objects);
$export_data['count'] = $count;
$this->myLogger->logme('error','Deletion export data count : {data}', ['data'=> $count ]);
if($count == 0){
return false;
}
$this->myLogger->logme('error','Deletion export file name : {data}', ['data'=> $export_data['file_name'] ]);
$si_data = transform_objects_to_array_for_deletion($objects);
// dd($si_data);
$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'
];
// Create a temporary file in memory
$tempFile = tmpfile();
// Generate Excel file with the temporary file
$value = generate_excel($headers, $si_data, $tempFile, 2);
if($value){
$return = $this->batchFilesAndBatchListEntry($export_data, $objects);
if( $return){
// 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;
}
}
}
public function cashDepositCalculationForInception($arrayData = [])
{
$arrayData = array(
array(
0 => 6,
1 => 10,
2 => 17,
3 => 101,
4 => 102
),
);
// Flatten the array to get all IDs in a single array
$idArray = call_user_func_array('array_merge', $arrayData);
// Select from the employee_policy table where the id is in the $idArray
$results = $this->employeePolicyModel
->select('employee_polices.pro_rata_premium')
->whereIn('id', $idArray)
->get()
->getResultArray();
// Output the results
print_r($results); die;
}
public function cashDepositCalculationForSIEnhancement($arrayData)
{
}
public function cashDepositCalculationForDeletion($arrayData)
{
}
// -----------------------------------------------------------------------------------
}

View File

@ -259,58 +259,70 @@ class EmployeeController extends AdminController
$this->myLogger->logme('error','importExport function called');
$empDataServiceController = new EmpDataServiceController();
$client_id = $this->request->getPost('client_id');
$client_policy_id = $this->request->getPost('client_policy_id');
$insurer_or_tpa = $this->request->getPost('insurer_or_tpa');
$event_type = $this->request->getPost('event_type');
$actions = $this->request->getPost('action_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']);
$batch_data = [
'client_id' => $client_id,
'client_policy_id' => $client_policy_id,
'insurer_or_tpa' => $insurer_or_tpa,
'event_type' => $event_type,
'actions' => $actions,
'file_name' => $file_name,
];
$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']);
if($actions == 'export'){
if($event_type == 'inception'){
$objects = $this->employeePolicyModel->getInceptionEmployeeDataForExportExcel($client_policy_id, $insurer_or_tpa, $event_type, $actions);
$count = count($objects);
$this->myLogger->logme('error','Inception export data count : {data}', ['data'=> $count ]);
$batch_data['count'] = $count;
if($count == 0){
$return = $empDataServiceController->generateExcelForAdditionandInception($batch_data);
if(!$return){
session()->setFlashdata('error', 'No data found about this action');
return redirect()->to(base_url('employee/upload'));
} else{
$this->myLogger->logme('error','Successfully exported Excel file in Inception/Addition/DependentAddition.');
}
session()->setFlashdata('error', 'No data found');
return redirect()->to(base_url('employee/upload'));
}
} else if($event_type == 'correction'){
$this->myLogger->logme('error','Inception export file name : {data}', ['data'=> $file_name ]);
$empDataServiceController->generateExcelForAdditionandInception($batch_data, $objects, $file_name);
$return = $empDataServiceController->generateExcelForCorrection($batch_data);
if(!$return){
session()->setFlashdata('error', 'No data found about this action');
return redirect()->to(base_url('employee/upload'));
} else{
$this->myLogger->logme('error','Successfully exported Excel file in Correction.');
}
} else if($event_type == 'correction'){
} else if($event_type == 'si_enhancement'){
$objects = $this->employeePolicyModel->getCorrectionEmployeesDataForExportExcel($client_id, $client_policy_id, $insurer_or_tpa);
$count = count($objects);
$this->myLogger->logme('error','Correction export data count : {data}', ['data'=> $count ]);
$batch_data['count'] = $count;
if($count == 0){
session()->setFlashdata('error', 'No data found');
return redirect()->to(base_url('employee/upload'));
}
$this->myLogger->logme('error','Correction export file name : {data}', ['data'=> $file_name ]);
$empDataServiceController->generateExcelForCorrection($file_name, $objects, $batch_data);
$return = $empDataServiceController->generateExcelForSIEnhancement($batch_data);
if(!$return){
session()->setFlashdata('error', 'No data found about this action');
return redirect()->to(base_url('employee/upload'));
} else{
$this->myLogger->logme('error','Successfully exported Excel file in SI_Enhancement.');
}
}else if($event_type == 'deletion'){
$return = $empDataServiceController->generateExcelForDeletion($batch_data);
if(!$return){
session()->setFlashdata('error', 'No data found about this action');
return redirect()->to(base_url('employee/upload'));
} else{
$this->myLogger->logme('error','Successfully exported Excel file in Deletion.');
}
}
}else if($actions == 'import'){
if($event_type == 'inception'){
@ -328,22 +340,28 @@ class EmployeeController extends AdminController
$batch_data['batch_code'] = $batch_code;
$batch_data['created_by'] = get_session_userid();
$batch_data['file_name'] = $filename;
$insert = $this->batchFileModel->insert($batch_data);
$batch_file_batch_code = $this->batchFileModel->where('id', $insert)->first();
// $insert = $this->batchFileModel->insert($batch_data);
$batch_file_batch_code = $this->batchFileModel->where('id', 2)->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'];
//check the file exist or not
if(!file_exists($file_name_with_path))
{
session()->setFlashdata('error', 'File not found');
return redirect()->to(base_url('employee/upload'));
// session()->setFlashdata('error', 'File not found');
// return redirect()->to(base_url('employee/upload'));
}
$data = read_excel_file_to_array($file_name_with_path);
unset($data[0]);
array_pop($data);
$count = count($data);
// $this->batchFileModel->where('id', $insert)->set('count', $count)->update();
// dd($data );
$employeeIds = [];
foreach ($data as $key => $value) {
// Check if the array is not empty and has the necessary data
if (!empty($value) && (isset($value[15]) || isset($value[16]))) {
@ -354,21 +372,43 @@ class EmployeeController extends AdminController
$emp_code = $value[2];
$name = $value[1];
// echo $tpa_id, $uhid, $emp_code, $name; die;
$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', $name)
->where('employees.emp_code', $emp_code)
->where('employee_polices.is_active', 1)
->first();
$batch_code_for_batch_list['emp_policy_id'] = $val['id'];
$this->batchListModel->insert($batch_code_for_batch_list);
array_push($employeeIds, $val['id']);
$this->employeePolicyModel->updateTPAIDorUHID( $client_policy_id, $client_id, $name, $emp_code, $uhid, $tpa_id);
$query = $this->employeePolicyModel->getLastQuery();
echo $query . "<br>";
// $query = $this->employeePolicyModel->getLastQuery();
// echo $query . "<br>";
}else{
session()->setFlashdata('error', 'Something went wrong');
return redirect()->to(base_url('employee/upload'));
// session()->setFlashdata('error', 'Something went wrong');
// return redirect()->to(base_url('employee/upload'));
}
}
$action = ['action' => 'inception'];
$depositeData = [
$employeeIds,
$action
];
$empDataServiceController->cashDepositCalculationForInception();
// echo '<pre>';
// print_r($depositeData); die;
session()->setFlashdata('success', 'Data updated successfully');
return redirect()->to(base_url('employee/upload'));
// session()->setFlashdata('success', 'Data updated successfully');
// return redirect()->to(base_url('employee/upload'));
}else if($event_type == 'correction'){
@ -388,6 +428,9 @@ class EmployeeController extends AdminController
$insert = $this->batchFileModel->insert($batch_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))
@ -398,6 +441,8 @@ class EmployeeController extends AdminController
$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();
// dd($data);
foreach ($data as $key => $value) {
@ -406,10 +451,23 @@ class EmployeeController extends AdminController
$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.*')
->join('employees', 'employees.id = emp_endorsement.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)
@ -430,8 +488,206 @@ class EmployeeController extends AdminController
$this->employeeModel->where('id', $emp_id)->set($field_name, $new_value)->update();
}
$query = $this->employeePolicyModel->getLastQuery();
echo $query . "<br>";
// $query = $this->employeePolicyModel->getLastQuery();
// echo $query . "<br>";
}else{
session()->setFlashdata('error', 'Something went wrong');
return redirect()->to(base_url('employee/upload'));
}
}
session()->setFlashdata('success', 'Data updated successfully');
return redirect()->to(base_url('employee/upload'));
}else if($event_type == 'si_enhancement'){
$file = $this->request->getFile('import_file_data');
$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 ]);
$batch_data['batch_code'] = $batch_code;
$batch_data['created_by'] = get_session_userid();
$batch_data['file_name'] = $filename;
$insert = $this->batchFileModel->insert($batch_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))
{
session()->setFlashdata('error', 'File not found');
return redirect()->to(base_url('employee/upload'));
}
$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();
// dd($data);
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] : '';
$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();
$batch_code_for_batch_list['emp_policy_id'] = $val['id'];
$this->batchListModel->insert($batch_code_for_batch_list);
$this->employeePolicyModel->updateEndoresmentIdForSIEnhancement($emp_code, $client_id, $client_policy_id, $emp_name, $endorsement_id);
$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();
$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);
// $query = $this->employeePolicyModel->getLastQuery();
// echo $query . "<br>";
}else{
session()->setFlashdata('error', 'Something went wrong');
return redirect()->to(base_url('employee/upload'));
}
}
session()->setFlashdata('success', 'Data updated successfully');
return redirect()->to(base_url('employee/upload'));
}else if($event_type == 'deletion'){
$file = $this->request->getFile('import_file_data');
$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 ]);
$batch_data['batch_code'] = $batch_code;
$batch_data['created_by'] = get_session_userid();
$batch_data['file_name'] = $filename;
$insert = $this->batchFileModel->insert($batch_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))
{
session()->setFlashdata('error', 'File not found');
return redirect()->to(base_url('employee/upload'));
}
$data = read_excel_file_to_array($file_name_with_path);
unset($data[0]);
array_pop($data);
$count = count($data);
$this->batchFileModel->where('id', $insert)->set('count', $count)->update();
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();
$batch_code_for_batch_list['emp_policy_id'] = $val['id'];
$this->batchListModel->insert($batch_code_for_batch_list);
$this->employeePolicyModel->updateEndoresmentIdForDeletion($emp_code, $client_id, $client_policy_id, $emp_name, $endorsement_id);
$deletionDataForEmployee = $this->empEndorsementModel
->select('emp_endorsement.new_value, 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);
$deletionDataForEmployeePolicy = $this->employeePolicyModel->fetchEmpEndorsementData($emp_code, $client_policy_id, $emp_name);
$deletionDataForEmployeePolicy['updated_by'] = get_session_userid();
$this->employeePolicyModel->save($deletionDataForEmployeePolicy);
// echo '<pre>';
// print_r($deletionDataForEmployeePolicy); die;
$this->employeePolicyModel->save($deletionDataForEmployeePolicy);
// $query = $this->employeePolicyModel->getLastQuery();
// echo $query . "<br>";
}else{
session()->setFlashdata('error', 'Something went wrong');
return redirect()->to(base_url('employee/upload'));
@ -449,5 +705,5 @@ class EmployeeController extends AdminController
}
// -------------------------------------------------------------------------------------------
}

View File

@ -45,20 +45,20 @@ class LoginController extends BaseController
$session_data = ['isLoggedIn' => True ,'userid' => $user->id];
set_session_data($session_data);
log_message('error', 'Set The UserId : `'. $user->id .'` in Session');
log_message('error', 'Is User Login Sucessfully');
log_message('error', 'User Login Sucessfully');
// $this->getUserDeviceInfo($user->id);
$this->getUserDeviceInfo($user->id, 'NhanceUser');
return redirect()->to(base_url('/dashboard/view'));
}else{
log_message('error', 'Is User Not Activate');
session()->setFlashdata('error', 'Is User Not Activate');
log_message('error', 'User Not Activate');
session()->setFlashdata('error', 'User Not Activate');
return redirect()->to(base_url('login'));
}
}else{
log_message('error', 'Is User Not Register');
session()->setFlashdata('error', 'Is User Not Register');
log_message('error', 'User Not Register');
session()->setFlashdata('error', 'User Not Register');
return redirect()->to(base_url('login'));
}
}

View File

@ -48,6 +48,19 @@ if (!function_exists('generate_random_string')) {
if (!function_exists('generate_excel')) {
/*
This function generates an Excel file using the given headers and data and saves it with the specified filename.
It utilizes the PhpSpreadsheet library to create and manipulate Excel files.
Parameters:
- $headers: An array containing the column headers for the Excel sheet.
- $data: An array containing the data to be inserted into the Excel sheet.
- $filename: The name of the file to be saved.
- $totals (optional): A flag indicating whether to include total calculations in the Excel sheet.
*/
function generate_excel($headers, $data, $filename, $totals = null)
{
// Create new Spreadsheet object
@ -62,9 +75,11 @@ if (!function_exists('generate_excel')) {
// Set data into the spreadsheet
$spreadsheet->getActiveSheet()->fromArray($data, null, 'A2');
if($totals){
if($totals == 1){
// Call the helper function for Calculate GST, Pro Rata Premium, and Total sums for inception
add_totals_row($spreadsheet, $data);
}else if($totals == 2){
add_totals_for_deletion($spreadsheet, $data);
}
// Create Excel writer
@ -162,6 +177,94 @@ if (! function_exists('transform_objects_to_array_for_correction')) {
}
if (! function_exists('transform_objects_to_array_for_si_enhancement')) {
function transform_objects_to_array_for_si_enhancement($objects) {
// Define an array to store the transformed data
$data = [];
$endorsement_id = "";
// Initialize serial number
$serialNumber = 1;
// Iterate through each object
foreach ($objects as $obj) {
// Extract all values for the object
$rowData = [
$serialNumber++,
$obj->emp_name,
$obj->emp_code,
$obj->emp_type,
$obj->emp_relationship_code,
$obj->emp_dob,
$obj->emp_gender,
$obj->pre_existing_alignments,
$obj->new_basic_cover_si,
$obj->old_basic_cover_si,
$obj->date_of_coverage,
$obj->policy_end_date,
$obj->no_of_days,
$obj->old_si_premium,
$obj->new_si_premium,
$obj->difference_premium,
$obj->pro_rata_premimum,
$obj->gst,
$obj->total ,
$endorsement_id,
];
// Append the row data to the main data array
$data[] = $rowData;
}
return $data;
}
}
if (! function_exists('transform_objects_to_array_for_deletion')) {
function transform_objects_to_array_for_deletion($objects) {
// Define an array to store the transformed data
$data = [];
$claim_status = "";
$endorsement_id = "";
// Initialize serial number
$serialNumber = 1;
// Iterate through each object
foreach ($objects as $obj) {
// Extract all values for the object
$rowData = [
$serialNumber++,
$obj->emp_code,
$obj->emp_name,
$obj->emp_dob,
$obj->emp_gender,
$obj->emp_relationship,
$obj->basic_cover_si,
$obj->dateofexit,
$obj->policy_end_date,
$obj->no_of_days,
$obj->premium,
$obj->pro_rata_premium,
$obj->gst,
$obj->total,
$claim_status,
$endorsement_id
];
// Append the row data to the main data array
$data[] = $rowData;
}
return $data;
}
}
if (!function_exists('add_totals_row')) {
function add_totals_row(Spreadsheet $spreadsheet, array $data)
{
@ -186,6 +289,30 @@ if (!function_exists('add_totals_row')) {
}
if (!function_exists('add_totals_for_deletion')) {
function add_totals_for_deletion(Spreadsheet $spreadsheet, array $data)
{
// Calculate GST, Pro Rata Premium, and Total sums
$gstSum = 0;
$proRataPremiumSum = 0;
$totalSum = 0;
foreach ($data as $row) {
$proRataPremiumSum += $row[11];
$gstSum += $row[12];
$totalSum += $row[13];
}
// Add a new row with sums
$lastRow = count($data) + 1; // To get the last row number
$spreadsheet->getActiveSheet()->setCellValue('K' . ($lastRow + 1), 'TOTALS');
$spreadsheet->getActiveSheet()->setCellValue('L' . ($lastRow + 1), $proRataPremiumSum);
$spreadsheet->getActiveSheet()->setCellValue('M' . ($lastRow + 1), $gstSum);
$spreadsheet->getActiveSheet()->setCellValue('N' . ($lastRow + 1), $totalSum);
}
}
if (!function_exists('read_excel_file_to_array')) {
function read_excel_file_to_array($file)
{

View File

@ -17,12 +17,15 @@ class EmployeePolicyModel extends Model
"batch_id",
"status",
"pre_existing_alignments",
"date_of_exit",
"reason_for_exit",
"basic_cover_si",
"date_coverage",
"policy_end_date",
"days",
"premium",
"rata_premimum",
"si_enhancement_date",
"gst",
"created_by",
"updated_by",
@ -62,7 +65,7 @@ class EmployeePolicyModel extends Model
TIMESTAMPDIFF(YEAR, employees.dob, CURDATE()) AS emp_age,
"Has Define" as emp_type,
employee_polices.id as employee_policy_id,
employee_polices.id as primaryKey,
employee_polices.pre_existing_alignments,
employee_polices.basic_cover_si,
employee_polices.date_coverage,
@ -75,7 +78,6 @@ class EmployeePolicyModel extends Model
batch_data.emp_policy_id,
batch_data.bl AS batch_list_batch_code,
batch_data.bf AS batch_files_batch_code')
->join('employees', 'employees.id = employee_polices.employee_id', 'left')
->join("(
SELECT
@ -90,6 +92,7 @@ class EmployeePolicyModel extends Model
->where('batch_data.bf', null)
->where('batch_data.bl', null)
->where('employee_polices.client_policy_id', $client_policy_id)
->where('employee_polices.is_active', 1)
->get()
->getResult();
}
@ -98,43 +101,247 @@ class EmployeePolicyModel extends Model
public function getCorrectionEmployeesDataForExportExcel($client_id, $client_policy_id, $insurer_or_tpa)
{
return $this->db->table('emp_endorsement')
->select('emp_endorsement.id,
emp_endorsement.emp_id,
emp_endorsement.emp_code,
emp_endorsement.endorsement_id,
emp_endorsement.old_value,
emp_endorsement.new_value,
emp_endorsement.field_name,
emp_endorsement.remarks,
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,
batch_data.emp_policy_id,
batch_data.bl AS batch_list_batch_code,
batch_data.bf AS batch_files_batch_code')
->join('employees', 'employees.id = emp_endorsement.emp_id', 'left')
->join('employee_polices', 'employees.id = employee_polices.employee_id', 'left')
->join("(SELECT batch_list.emp_policy_id,
batch_list.batch_code as bl,
batch_files.batch_code as bf
FROM batch_files
LEFT JOIN batch_list ON batch_files.batch_code = batch_list.batch_code
$sql = "
SELECT DISTINCT
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,
batch_data.emp_policy_id,
batch_data.bl AS batch_list_batch_code,
batch_data.bf AS batch_files_batch_code
FROM
emp_endorsement
LEFT JOIN
employees ON employees.id = emp_endorsement.pk
LEFT JOIN
employee_polices ON employees.id = employee_polices.employee_id
LEFT JOIN (
SELECT batch_list.emp_policy_id,
batch_list.batch_code AS bl,
batch_files.batch_code AS bf
FROM
batch_files
LEFT JOIN
batch_list ON batch_files.batch_code = batch_list.batch_code
WHERE batch_files.event_type = 'correction'
AND batch_files.actions = 'export'
AND batch_files.insurer_or_tpa = '{$insurer_or_tpa}') as batch_data", 'emp_endorsement.emp_id = batch_data.emp_policy_id', 'left', false)
->where('batch_data.bf IS NULL')
->where('batch_data.bl IS NULL')
->where('emp_endorsement.endorsement_id', '')
->where('employees.client_id', $client_id)
->where('employee_polices.client_policy_id', $client_policy_id)
->get()
->getResult();
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}'
AND employee_polices.client_policy_id = '{$client_policy_id}'
AND emp_endorsement.actions = 'c'
AND (emp_endorsement.endorsement_id IS NULL OR emp_endorsement.endorsement_id = '')";
// Execute the raw query
$query = $this->db->query($sql);
// Get the result set
$result = $query->getResult();
return $result;
}
public function getSIEnhancementEmployeesDataForExportExcel($client_id, $client_policy_id, $insurer_or_tpa){
$query = $this->db->query("
SELECT
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,
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.premium as old_si_premium,
batch_data.emp_policy_id,
batch_data.bl AS batch_list_batch_code,
batch_data.bf AS batch_files_batch_code,
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.premium AS difference_premium,
ROUND((sidata.new_si_premium - employee_polices.premium) * (DATEDIFF(employee_polices.policy_end_date, sidata.date_of_coverage) + 1) / 365, 2) AS pro_rata_premimum,
ROUND(((sidata.new_si_premium - employee_polices.premium) * (DATEDIFF(employee_polices.policy_end_date, sidata.date_of_coverage) + 1) / 365) * 0.18, 2) AS gst,
((sidata.new_si_premium - employee_polices.premium) * (DATEDIFF(employee_polices.policy_end_date, sidata.date_of_coverage) + 1) / 365) + ROUND(((sidata.new_si_premium - employee_polices.premium) * (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
LEFT JOIN (
SELECT DISTINCT
batch_list.emp_policy_id,
batch_list.batch_code AS bl,
batch_files.batch_code AS bf
FROM
batch_files
LEFT JOIN
batch_list ON batch_files.batch_code = batch_list.batch_code
WHERE
batch_files.event_type = 'si_enhancement'
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'
AND (a.endorsement_id IS NULL OR a.endorsement_id = '')
AND a.field_name = 'si_enhancement_date'
");
// Get the result set
$results = $query->getResult();
return $results;
}
public function getDeletionEmployeeDataForExportExcel($client_id, $client_policy_id, $insurer_or_tpa){
$query = $this->db->query("
SELECT
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.premium,
batch_data.emp_policy_id AS emp_policy_id,
batch_data.bl AS batch_list_batch_code,
batch_data.bf AS batch_files_batch_code,
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.premium * DATEDIFF(employee_polices.policy_end_date, deletiondata.dateofexit)) / 365, 2) AS pro_rata_premium,
ROUND(((employee_polices.premium * DATEDIFF(employee_polices.policy_end_date, deletiondata.dateofexit)) / 365) * 0.18, 2) AS gst,
ROUND(((employee_polices.premium * DATEDIFF(employee_polices.policy_end_date, deletiondata.dateofexit)) / 365) + (((employee_polices.premium * 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
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
LEFT JOIN
(
SELECT
batch_list.emp_policy_id,
batch_list.batch_code AS bl,
batch_files.batch_code AS bf
FROM
batch_files
LEFT JOIN
batch_list ON batch_files.batch_code = batch_list.batch_code
WHERE
batch_files.event_type = 'deletion'
AND batch_files.actions = 'export'
AND batch_files.insurer_or_tpa = 'insurer'
) 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 = 12
AND employee_polices.is_active = 1
AND (a.endorsement_id IS NULL OR a.endorsement_id = '') AND a.field_name = 'status'
");
$result = $query->getResult();
return $result;
}
@ -170,7 +377,7 @@ class EmployeePolicyModel extends Model
$sql = "
UPDATE emp_endorsement
JOIN employees ON employees.id = emp_endorsement.emp_id
JOIN employees ON employees.id = emp_endorsement.pk
JOIN employee_polices ON employees.id = employee_polices.employee_id
SET emp_endorsement.endorsement_id = '$endorsement_id'
WHERE employees.emp_code = '$emp_code'
@ -179,6 +386,66 @@ class EmployeePolicyModel extends Model
$query = $this->query($sql);
}
public function updateEndoresmentIdForSIEnhancement($emp_code, $client_id, $client_policy_id, $emp_name, $endorsement_id){
$sql = "
UPDATE emp_endorsement
JOIN employee_polices ON employee_polices.id = emp_endorsement.pk
JOIN employees ON employee_polices.employee_id = employees.id
SET emp_endorsement.endorsement_id = '$endorsement_id'
WHERE employees.emp_code = '$emp_code'
AND employees.client_id = '$client_id'
AND employee_polices.client_policy_id = '$client_policy_id'
AND employees.name = '$emp_name'
";
$query = $this->query($sql);
}
public function updateEndoresmentIdForDeletion($emp_code, $client_id, $client_policy_id, $emp_name, $endorsement_id){
$sql = "
UPDATE emp_endorsement
JOIN employee_polices ON employee_polices.id = emp_endorsement.pk
JOIN employees ON employee_polices.employee_id = employees.id
SET emp_endorsement.endorsement_id = '$endorsement_id'
WHERE employees.emp_code = '$emp_code'
AND employees.client_id = '$client_id'
AND employee_polices.client_policy_id = '$client_policy_id'
AND employees.name = '$emp_name'
";
$query = $this->query($sql);
}
public function fetchEmpEndorsementData($emp_code, $client_policy_id, $emp_name)
{
// 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";
// Execute the raw SQL query
$query = $this->db->query($sql);
// Fetch and return results
return $row = $query->getRowArray();
}
//------------------------------------------------------------------
}

View File

@ -110,7 +110,6 @@
$('#file_upload').hide();
// Declare a global variable to store API response data
var clientPolicies = [];

View File

@ -1,4 +1,4 @@
<div class="tab-pane fade active show" id="KYC-DOC-tab">
<div class="tab-pane fade" id="KYC-DOC-tab">
<div class="row">
<div class="col-12">

View File

@ -82,7 +82,7 @@
}
grid_html = `
<div class="form-row" id="grid_1" style="width:84%">
<div class="form-row" id="grid_1">
<input value="1" type="hidden" name="policy_type">
<div class="form-group col-md-3">
<label for="mobile">Select <span class="text-danger">*</span></label>
@ -773,7 +773,6 @@
Count++;
var container = document.getElementById('grid_content_input');
if(ui_type == '1_1' || ui_type == '1_1_1' || ui_type == '1_1_1_1')
{
if (ui_type == '1_1_1' || ui_type == '1_1_1_1') {
@ -791,7 +790,8 @@
<div class="form-group">
<button style="margin-top: 44px;" type="button" class="btn btn-danger" id="gmc_remove" onclick="removebutton(${Count})">x</button>
<button style="margin-top: 44px;" type="button" class="btn btn-primary" id="gmc_add_more_${Count}" onclick="appendGridtHtml('1_1_1_1')">+</button>
</div></div>`;
</div>
</div>`;
// return html;
}else{
html =` <div class="form-row col-md-4">