FIX_INCEPTION_EXPORT : RV

This commit is contained in:
VENKATESHWARAN 2025-08-07 11:44:04 +05:30
parent dd2131ff55
commit 7d934d781d
2 changed files with 101 additions and 93 deletions

View File

@ -2477,7 +2477,8 @@ class EmployeeController extends AdminController
//------------------------------------------------------------------------------------------------------
public function test_members_list(){
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'],
@ -2500,7 +2501,8 @@ class EmployeeController extends AdminController
return $this->loadLayout('test_members_list',$data);
}
public function mapEmployees(){
public function mapEmployees()
{
$client_id = $this->request->getPost('client_id');
$branch_id = $this->request->getPost('branch_id');
$policy_id = $this->request->getPost('client_policy_id');
@ -2534,7 +2536,8 @@ class EmployeeController extends AdminController
}
}
public function getDataForMapping(){
public function getDataForMapping()
{
$policy_id = $this->request->getPost('policy_id');log_message('error',$policy_id);
$data['policy_start_date'] = $this->clientPolicyModel->select('policy_start_date')->where('id',$policy_id)->first()['policy_start_date'];
$data['si_amt'] = $this->PolicyPremium2Model->select('si')->where('client_policy_id', $policy_id)->groupBy('si')->findAll();
@ -2542,7 +2545,8 @@ class EmployeeController extends AdminController
return $this->respond(['status' => true, 'code' => 200, 'data' => $data], 200);
}
public function unmapEmployees($actionType){
public function unmapEmployees($actionType)
{
$selected_employees = (array)$this->request->getPost('selected');
if($actionType == 0){
for($i = 0;$i<count($selected_employees);$i++){log_message('error',$selected_employees[$i]);
@ -2636,7 +2640,6 @@ class EmployeeController extends AdminController
//------------------------------------------------------------------------------------------------------
public function generateAcmAndMForEcard($client_id)
{
$db = db_connect();
@ -2675,9 +2678,8 @@ class EmployeeController extends AdminController
return $html;
}
public function getEmpHistory(){
public function getEmpHistory()
{
$emp_id = $this->request->getPost('emp_id');
@ -2712,7 +2714,8 @@ class EmployeeController extends AdminController
}
public function formatFieldName($unformattedString){
public function formatFieldName($unformattedString)
{
if (str_contains($unformattedString, '_')) {
$data = str_replace('_', ' ', $unformattedString);
@ -2726,88 +2729,88 @@ class EmployeeController extends AdminController
}
//------------------------------------------------------------------------------------------------------
public function download_inception()
{
$client = $this->request->getPost('client');
$branch = $this->request->getPost('branch');
$policies = $this->request->getPost('policies');
$status = $this->request->getPost('status');
$empCode = $this->request->getPost('empCode');
$empName = $this->request->getPost('empName');
public function download_inception()
{
$client = $this->request->getPost('client');
$branch = $this->request->getPost('branch');
$policies = $this->request->getPost('policies');
$status = $this->request->getPost('status');
$empCode = $this->request->getPost('empCode');
$empName = $this->request->getPost('empName');
$result = $this->employeePolicyModel->download_inception(
$client, $branch, $policies, $status, $empCode, $empName
);
$result = $this->employeePolicyModel->download_inception(
$client, $branch, $policies, $status, $empCode, $empName
);
if (empty($result)) {
return $this->response->setStatusCode(204)->setBody('No data found');
}
if (empty($result)) {
return $this->response->setStatusCode(204)->setBody('No data found');
}
$formatted = [];
foreach ($result as $index => $row) {
$rowWithSerial = ['S.NO' => $index + 1] + $row;
$formatted[] = $rowWithSerial;
}
$result = $formatted;
$formatted = [];
foreach ($result as $index => $row) {
$rowWithSerial = ['S.NO' => $index + 1] + $row;
$formatted[] = $rowWithSerial;
}
$result = $formatted;
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$headers = array_keys($result[0]);
$columnWidth = 20; // standard column width
$headers = array_keys($result[0]);
$columnWidth = 20; // standard column width
$colIndex = 1;
foreach ($headers as $header) {
$columnLetter = Coordinate::stringFromColumnIndex($colIndex);
$cellCoordinate = $columnLetter . '1';
$sheet->setCellValue($cellCoordinate, ucfirst(str_replace('_', ' ', $header)));
$sheet->getColumnDimension($columnLetter)->setWidth($columnWidth);
$style = $sheet->getStyle($cellCoordinate);
$style->getFont()->setBold(true);
$style->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER);
$style->getBorders()->getAllBorders()->setBorderStyle(Border::BORDER_THIN);
$colIndex++;
}
$rowNum = 2;
foreach ($result as $row) {
$colIndex = 1;
foreach ($row as $cell) {
foreach ($headers as $header) {
$columnLetter = Coordinate::stringFromColumnIndex($colIndex);
$cellCoordinate = $columnLetter . $rowNum;
$sheet->setCellValue($cellCoordinate, $cell);
$cellCoordinate = $columnLetter . '1';
$sheet->setCellValue($cellCoordinate, ucfirst(str_replace('_', ' ', $header)));
$sheet->getColumnDimension($columnLetter)->setWidth($columnWidth);
$style = $sheet->getStyle($cellCoordinate);
$style->getFont()->setBold(true);
$style->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER);
$style->getBorders()->getAllBorders()->setBorderStyle(Border::BORDER_THIN);
$colIndex++;
}
$rowNum++;
$rowNum = 2;
foreach ($result as $row) {
$colIndex = 1;
foreach ($row as $cell) {
$columnLetter = Coordinate::stringFromColumnIndex($colIndex);
$cellCoordinate = $columnLetter . $rowNum;
$sheet->setCellValue($cellCoordinate, $cell);
$colIndex++;
}
$rowNum++;
}
$exportDir = WRITEPATH . 'exports';
if (!is_dir($exportDir)) {
mkdir($exportDir, 0777, true);
} else {
chmod($exportDir, 0777);
}
$filename = 'inception_export_' . date('Ymd_His') . '.xlsx';
$filepath = $exportDir . '/' . $filename;
$writer = new Xlsx($spreadsheet);
$writer->save($filepath);
return $this->response->setJSON([
'status' => 'success',
'downloadUrl' => base_url('employee/download_file?file=' . urlencode($filename))
]);
}
$exportDir = WRITEPATH . 'exports';
if (!is_dir($exportDir)) {
mkdir($exportDir, 0777, true);
} else {
chmod($exportDir, 0777);
}
$filename = 'inception_export_' . date('Ymd_His') . '.xlsx';
$filepath = $exportDir . '/' . $filename;
$writer = new Xlsx($spreadsheet);
$writer->save($filepath);
return $this->response->setJSON([
'status' => 'success',
'downloadUrl' => base_url('employee/download_file?file=' . urlencode($filename))
]);
}
public function download_file()
{
$filename = $this->request->getGet('file');

View File

@ -1862,15 +1862,18 @@ class EmployeePolicyModel extends Model
'employee_polices.basic_cover_si As `Basic cover SI`',
"DATE_FORMAT(employee_polices.date_coverage, '%d-%b-%Y') AS `Date of Coverage`",
"DATE_FORMAT(emp.doj, '%d-%b-%Y') AS `DOJ`",
'emp.basic_pay As `Basic Pay`',
'emp.band As `Band/Grade`',
'emp.designation As `Designation`',
'emp.mobile as Phone',
'emp.email_corporate As Email',
'emp.change_event',
'employee_polices.pre_existing_alignments as `PRE EXISTING AILMENTS`',
'COALESCE(employee_polices.pre_existing_alignments, 0) as `PRE EXISTING AILMENTS`',
'emp.change_event',
'employee_polices.date_of_exit',
'employee_polices.reason_for_exit',
@ -1902,25 +1905,27 @@ class EmployeePolicyModel extends Model
$result->where('employee_polices.client_policy_id', $policy_id);
}
if (is_array($status) && count($status) > 0) {
// if (is_array($status) && count($status) > 0) {
$result->where('employee_polices.status !=', 'expired');
// $result->where('employee_polices.status !=', 'expired');
if (in_array("active", $status)) {
// if (in_array("active", $status)) {
$result->where('employee_polices.tpa_id IS NOT NULL');
$result->where('employee_polices.uhid IS NOT NULL');
$result->whereIn('employee_polices.status', $status);
} elseif (in_array("pending", $status)) {
// $result->where('employee_polices.tpa_id IS NOT NULL');
// $result->where('employee_polices.uhid IS NOT NULL');
// $result->whereIn('employee_polices.status', $status);
// } elseif (in_array("pending", $status)) {
$result->where('employee_polices.tpa_id IS NULL');
$result->where('employee_polices.uhid IS NULL');
$result->whereIn('employee_polices.status', array_merge($status, ['active']));
} else {
// $result->where('employee_polices.tpa_id IS NULL');
// $result->where('employee_polices.uhid IS NULL');
// $result->whereIn('employee_polices.status', array_merge($status, ['active']));
// } else {
$result->whereIn('employee_polices.status', $status);
}
}
// $result->whereIn('employee_polices.status', $status);
// }
// }
$result->where('employee_polices.status =', 'enrolled');
if (!empty(trim($emp_code))) {
$result->where('emp.emp_code', $emp_code);