167 lines
5.5 KiB
PHP
167 lines
5.5 KiB
PHP
<?php
|
|
|
|
namespace App\Controllers;
|
|
|
|
use CodeIgniter\HTTP\IncomingRequest;
|
|
use CodeIgniter\HTTP\RequestInterface;
|
|
use CodeIgniter\HTTP\ResponseInterface;
|
|
use Psr\Log\LoggerInterface;
|
|
|
|
|
|
use App\Models\EmployeeModel;
|
|
use App\Models\EmployeePolicyModel;
|
|
use App\Models\ClientModel;
|
|
use App\Models\ClientPolicyModel;
|
|
use App\Models\FileModel;
|
|
use App\Models\BatchListModel;
|
|
use App\Models\BatchFileModel;
|
|
use App\Models\EmpEndorsementModel;
|
|
|
|
use App\Controllers\Jobs ;
|
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
|
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
|
|
|
|
class EmpDataServiceController extends BaseController
|
|
{
|
|
protected $myLogger;
|
|
protected $employeeModel;
|
|
protected $employeePolicyModel;
|
|
protected $clientModel;
|
|
protected $fileModel;
|
|
protected $clientPolicyModel;
|
|
protected $batchListModel;
|
|
protected $batchFileModel;
|
|
protected $empEndorsementModel;
|
|
|
|
public function __construct()
|
|
{
|
|
// helper('utility');
|
|
set_session_context('EmployeeDataService Second Service');
|
|
$this->myLogger = \Config\Services::mylogger();
|
|
$this->employeeModel = new EmployeeModel();
|
|
$this->employeePolicyModel = new EmployeePolicyModel();
|
|
$this->clientModel = new ClientModel();
|
|
$this->fileModel = new FileModel();
|
|
$this->clientPolicyModel = new ClientPolicyModel();
|
|
$this->batchListModel = new BatchListModel();
|
|
$this->batchFileModel = new BatchFileModel();
|
|
$this->empEndorsementModel = new EmpEndorsementModel();
|
|
}
|
|
|
|
|
|
public function batchFilesAndBatchListEntry($data, $filename, $objects){
|
|
$random_number_count = 4;
|
|
$data['batch_code'] = generate_random_string($random_number_count);
|
|
$data['created_by'] = get_session_userid();
|
|
$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['created_by'] = get_session_userid();
|
|
$this->batchListModel->insert($batch_list_data);
|
|
}
|
|
}
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
public function generateExcelForAdditionandInception($batch_files_data, $export_data, $file_name)
|
|
{
|
|
|
|
$data = transform_objects_to_array_for_inception($export_data);
|
|
$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
|
|
$tempFile = tmpfile();
|
|
|
|
// Generate Excel file with the temporary file
|
|
$value = generate_excel($headers, $data, $tempFile, 1);
|
|
|
|
// 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
|
|
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
|
|
header('Content-Disposition: attachment;filename="' . $randomFilename . '"');
|
|
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);
|
|
|
|
}else{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
public function generateExcelForCorrection($file_name, $objects, $batch_files_data)
|
|
{
|
|
|
|
$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);
|
|
|
|
// Generate a random filename
|
|
$randomFilename = $file_name;
|
|
|
|
if($value){
|
|
$return = $this->batchFilesAndBatchListEntry($batch_files_data, $randomFilename, $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('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;
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
}
|