5961 lines
247 KiB
PHP
Executable File
5961 lines
247 KiB
PHP
Executable File
<?php
|
|
|
|
namespace App\Controllers;
|
|
|
|
use CodeIgniter\HTTP\IncomingRequest;
|
|
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\FileModel;
|
|
use App\Models\BatchListModel;
|
|
use App\Models\BatchFileModel;
|
|
use App\Models\EmpEndorsementModel;
|
|
use App\Models\ClientDepositModel;
|
|
use App\Models\NotificationModel;
|
|
use App\Models\MessageModel;
|
|
use App\Models\UserMessageModel;
|
|
use App\Models\CDMasterModel;
|
|
use App\Models\InsurerExcelExportTemplateModel;
|
|
use App\Models\ClientBranchModel;
|
|
use App\Models\EndorsementModel;
|
|
use App\Models\BdsPlacementModel;
|
|
use App\Models\LeadsModel;
|
|
use App\Models\LeadInstallmentPaymentDetails;
|
|
use App\Models\PolicyTransactionModel;
|
|
use App\Models\PTCOShareDetailsModel;
|
|
use App\Models\LevelContactModel;
|
|
|
|
|
|
use App\Controllers\Jobs;
|
|
use App\Controllers\JobWorker;
|
|
use App\Models\PolicyTypeModel;
|
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
|
use PhpOffice\PhpSpreadsheet\Reader\Xlsx;
|
|
use PhpOffice\PhpSpreadsheet\IOFactory;
|
|
use PhpOffice\PhpSpreadsheet\Reader\Exception as SpreadsheetReaderException;
|
|
use PhpParser\Node\Expr\Cast\Double;
|
|
use Kint\Kint;
|
|
use PhpParser\Node\Stmt\TraitUseAdaptation;
|
|
|
|
use function PHPUnit\Framework\returnSelf;
|
|
|
|
class EmpDataServiceController extends BaseController
|
|
{
|
|
protected $myLogger;
|
|
protected $employeeModel;
|
|
protected $employeePolicyModel;
|
|
protected $clientModel;
|
|
protected $fileModel;
|
|
protected $clientPolicyModel;
|
|
protected $batchListModel;
|
|
protected $batchFileModel;
|
|
protected $empEndorsementModel;
|
|
protected $clientDepositModel;
|
|
protected $notificationModel;
|
|
protected $messageModel;
|
|
protected $userMessageModel;
|
|
protected $CDMasterModel;
|
|
protected $excelExportTemplateModel;
|
|
protected $clientBranchModel;
|
|
protected $endorsementModel;
|
|
protected $BdsPlacementModel;
|
|
protected $leadsModel;
|
|
protected $leadInstallmentPaymentDetailesModel;
|
|
protected $policyTransactionModel;
|
|
protected $PTCOShareDetailsModel;
|
|
protected $LevelContactModel;
|
|
|
|
|
|
|
|
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();
|
|
$this->clientDepositModel = new ClientDepositModel();
|
|
$this->notificationModel = new NotificationModel();
|
|
$this->messageModel = new MessageModel();
|
|
$this->userMessageModel = new UserMessageModel();
|
|
$this->CDMasterModel = new CDMasterModel();
|
|
$this->excelExportTemplateModel = new InsurerExcelExportTemplateModel();
|
|
$this->clientBranchModel = new ClientBranchModel();
|
|
$this->endorsementModel = new EndorsementModel();
|
|
$this->BdsPlacementModel = new BdsPlacementModel();
|
|
$this->leadsModel = new LeadsModel();
|
|
$this->leadInstallmentPaymentDetailesModel = new LeadInstallmentPaymentDetails();
|
|
$this->policyTransactionModel = new PolicyTransactionModel();
|
|
$this->PTCOShareDetailsModel = new PTCOShareDetailsModel();
|
|
$this->LevelContactModel = new LevelContactModel();
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
* The below function are Inserts batch files and corresponding batch list entries into the database.
|
|
*
|
|
* @param array $data An array containing data for batch file insertion.
|
|
* @param array $objects An array of objects containing information for batch list entries.
|
|
* @return bool Returns true on successful insertion.
|
|
*/
|
|
|
|
|
|
public function batchFilesAndBatchListEntry($data, $objects)
|
|
{
|
|
|
|
$random_number_count = 4;
|
|
$data['batch_code'] = generate_random_string($random_number_count);
|
|
$data['created_by'] = get_session_userid();
|
|
|
|
$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->primaryKey ?? $value->employee_policy_id ?? '';
|
|
// $batch_list_data['created_by'] = get_session_userid();
|
|
// $this->batchListModel->insert($batch_list_data);
|
|
// }
|
|
// }
|
|
|
|
return $insert;
|
|
// return true;
|
|
}
|
|
|
|
|
|
public function insertBatchList($params)
|
|
{
|
|
|
|
foreach ($params['batch_list_data'] as $value) {
|
|
|
|
$batch_list_data['batch_code'] = $params['batch_code'];
|
|
$batch_list_data['emp_policy_id'] = $value['primaryKey'];
|
|
$batch_list_data['created_by'] = $params['user_id'];
|
|
$this->batchListModel->insert($batch_list_data);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
* 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.
|
|
*/
|
|
|
|
public function generateExcelForAdditionandInception($export_data)
|
|
{
|
|
|
|
// Fetch employee data for export from the database
|
|
$objects = $this->employeePolicyModel->getInceptionEmployeeDataForExportExcel($export_data);
|
|
$policy_details = $this->clientPolicyModel->where('id', $export_data['client_policy_id'])->first();
|
|
|
|
if ($policy_details['cd_ac_pk'] == null) {
|
|
$this->myLogger->logme('error', 'The policy does not have a CD account number.');
|
|
return 5;
|
|
}
|
|
|
|
$cash_balance = $this->clientDepositModel
|
|
->where('cd_ac_pk', $policy_details['cd_ac_pk'])
|
|
// ->where('cd_ac_no', $policy_details['cd_ac_no'])
|
|
->where('is_active', 1)
|
|
->orderBy('id', 'DESC')
|
|
->first();
|
|
|
|
// dd(db_connect()->getLastQuery(), $cash_balance);
|
|
|
|
if ($cash_balance == null) {
|
|
$balance = $this->CDMasterModel
|
|
->where('client_id', $export_data['client_id'])
|
|
->where('insurer_id', $policy_details['insurer_id'])
|
|
->where('id', $policy_details['cd_ac_pk'])
|
|
->first();
|
|
|
|
$cash_balance['balance'] = $balance['opening_bal'];
|
|
}
|
|
|
|
// Calculate the total amount from the objects
|
|
$totals = 0;
|
|
foreach ($objects as $item) {
|
|
$totals = $totals + $item->total;
|
|
}
|
|
|
|
$totals = round($totals);
|
|
|
|
//check CD amt insufficient only insurer, not tpa // DO NOT REMOVE THIS
|
|
if($export_data['insurer_or_tpa'] == 'insurer')
|
|
{
|
|
if ((int) $cash_balance['balance'] < (int) $totals) {
|
|
clear_cd_balance_session(); // Clear old junk first
|
|
|
|
$cd_session_data = json_encode([
|
|
'cd_balance' => false,
|
|
'cd_amount' => $cash_balance['balance'],
|
|
'excel_file_amt' => $totals
|
|
]);
|
|
|
|
session()->set('cd_balance_info', $cd_session_data);
|
|
session()->set('cd_balance', 'insufficient'); // Use a string status for clarity
|
|
|
|
$hr_data = $this->getHrdataForInsufficientMailSend($export_data['client_branch_id']);
|
|
session()->set('hr_data', json_encode(['client_id' => $export_data['client_id'], 'hr_data' => $hr_data]));
|
|
}else{
|
|
session()->set('cd_balance', 'sufficient'); // Use a string status for clarity
|
|
session()->set('cd_balance_info', null);
|
|
}
|
|
}
|
|
|
|
// Log the count of exported data
|
|
$count = count($objects);
|
|
$export_data['count'] = $count;
|
|
$export_data['amount'] = $totals;
|
|
$export_data['status'] = 'success';
|
|
|
|
$this->myLogger->logme('error', 'Inception export data count : {data}', ['data' => $count]);
|
|
|
|
// 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;
|
|
}
|
|
|
|
// Log the export file name
|
|
$this->myLogger->logme('error', 'Inception export file name : {data}', ['data' => $export_data['file_name']]);
|
|
|
|
// default excel header information
|
|
$excel_header_columns = [
|
|
[
|
|
'column_index' => 0,
|
|
'column_name' => 'S.No',
|
|
'db_column_name' => 'index'
|
|
],
|
|
[
|
|
'column_index' => 1,
|
|
'column_name' => 'NAME OF EMP/DEP',
|
|
'db_column_name' => 'emp_name'
|
|
],
|
|
[
|
|
'column_index' => 2,
|
|
'column_name' => 'EMP ID',
|
|
'db_column_name' => 'emp_code'
|
|
],
|
|
// [
|
|
// 'column_index' => 3,
|
|
// 'column_name' => 'EMP/DEP TYPE',
|
|
// 'db_column_name' => 'emp_type'
|
|
// ],
|
|
// [
|
|
// 'column_index' => 4,
|
|
// 'column_name' => 'RELATIONSHIP CODE',
|
|
// 'db_column_name' => 'emp_relationship_code'
|
|
// ],
|
|
[
|
|
'column_index' => 3,
|
|
'column_name' => 'DOB',
|
|
'db_column_name' => 'emp_dob'
|
|
],
|
|
[
|
|
'column_index' => 4,
|
|
'column_name' => 'GENDER',
|
|
'db_column_name' => 'emp_gender'
|
|
],
|
|
[
|
|
'column_index' => 5,
|
|
'column_name' => 'PRE EXISTING AILMENTS',
|
|
'db_column_name' => 'pre_existing_alignments'
|
|
],
|
|
[
|
|
'column_index' => 6,
|
|
'column_name' => 'BASIC COVER SI',
|
|
'db_column_name' => 'basic_cover_si'
|
|
],
|
|
[
|
|
'column_index' => 7,
|
|
'column_name' => 'DATE OF COVERAGE',
|
|
'db_column_name' => 'date_of_coverage'
|
|
],
|
|
[
|
|
'column_index' => 8,
|
|
'column_name' => 'AGE',
|
|
'db_column_name' => 'emp_age'
|
|
],
|
|
[
|
|
'column_index' => 9,
|
|
'column_name' => 'RELATIONSHIP',
|
|
'db_column_name' => 'emp_relationship'
|
|
],
|
|
[
|
|
'column_index' => 10,
|
|
'column_name' => 'REMARKS',
|
|
'db_column_name' => 'remarks'
|
|
],
|
|
[
|
|
'column_index' => 11,
|
|
'column_name' => 'POLICY END DATE',
|
|
'db_column_name' => 'policy_end_date'
|
|
],
|
|
[
|
|
'column_index' => 12,
|
|
'column_name' => 'NO OF DAYS',
|
|
'db_column_name' => 'days'
|
|
],
|
|
[
|
|
'column_index' => 13,
|
|
'column_name' => 'TPA ID',
|
|
'db_column_name' => 'tpa_id'
|
|
],
|
|
[
|
|
'column_index' => 14,
|
|
'column_name' => 'RISK ID',
|
|
'db_column_name' => 'uhid'
|
|
],
|
|
// [
|
|
// 'column_index' => 15,
|
|
// 'column_name' => 'PREMIUM',
|
|
// 'db_column_name' => 'premium'
|
|
// ],
|
|
[
|
|
'column_index' => 15,
|
|
'column_name' => 'PRO RATA PREMIUM',
|
|
'db_column_name' => 'rata_premimum'
|
|
],
|
|
[
|
|
'column_index' => 16,
|
|
'column_name' => 'GST',
|
|
'db_column_name' => 'gst'
|
|
],
|
|
[
|
|
'column_index' => 17,
|
|
'column_name' => 'TOTAL AMOUNT',
|
|
'db_column_name' => 'total'
|
|
]
|
|
];
|
|
|
|
if( $export_data['insurer_or_tpa'] == 'tpa'){
|
|
|
|
$excel_header_columns = [
|
|
[
|
|
'column_index' => 0,
|
|
'column_name' => 'S.No',
|
|
'db_column_name' => 'index'
|
|
],
|
|
[
|
|
'column_index' => 1,
|
|
'column_name' => 'NAME OF EMP/DEP',
|
|
'db_column_name' => 'emp_name'
|
|
],
|
|
[
|
|
'column_index' => 2,
|
|
'column_name' => 'EMP ID',
|
|
'db_column_name' => 'emp_code'
|
|
],
|
|
// [
|
|
// 'column_index' => 3,
|
|
// 'column_name' => 'EMP/DEP TYPE',
|
|
// 'db_column_name' => 'emp_type'
|
|
// ],
|
|
// [
|
|
// 'column_index' => 4,
|
|
// 'column_name' => 'RELATIONSHIP CODE',
|
|
// 'db_column_name' => 'emp_relationship_code'
|
|
// ],
|
|
[
|
|
'column_index' => 3,
|
|
'column_name' => 'DOB',
|
|
'db_column_name' => 'emp_dob'
|
|
],
|
|
[
|
|
'column_index' => 4,
|
|
'column_name' => 'GENDER',
|
|
'db_column_name' => 'emp_gender'
|
|
],
|
|
[
|
|
'column_index' => 5,
|
|
'column_name' => 'PRE EXISTING AILMENTS',
|
|
'db_column_name' => 'pre_existing_alignments'
|
|
],
|
|
[
|
|
'column_index' => 6,
|
|
'column_name' => 'BASIC COVER SI',
|
|
'db_column_name' => 'basic_cover_si'
|
|
],
|
|
[
|
|
'column_index' => 7,
|
|
'column_name' => 'DATE OF COVERAGE',
|
|
'db_column_name' => 'date_of_coverage'
|
|
],
|
|
[
|
|
'column_index' => 8,
|
|
'column_name' => 'AGE',
|
|
'db_column_name' => 'emp_age'
|
|
],
|
|
[
|
|
'column_index' => 9,
|
|
'column_name' => 'RELATIONSHIP',
|
|
'db_column_name' => 'emp_relationship'
|
|
],
|
|
[
|
|
'column_index' => 10,
|
|
'column_name' => 'REMARKS',
|
|
'db_column_name' => 'remarks'
|
|
],
|
|
[
|
|
'column_index' => 11,
|
|
'column_name' => 'POLICY END DATE',
|
|
'db_column_name' => 'policy_end_date'
|
|
],
|
|
[
|
|
'column_index' => 12,
|
|
'column_name' => 'NO OF DAYS',
|
|
'db_column_name' => 'no_of_days'
|
|
],
|
|
[
|
|
'column_index' => 13,
|
|
'column_name' => 'TPA ID',
|
|
'db_column_name' => 'tpa_id'
|
|
],
|
|
[
|
|
'column_index' => 14,
|
|
'column_name' => 'RISK ID',
|
|
'db_column_name' => 'uhid'
|
|
],
|
|
// [
|
|
// 'column_index' => 17,
|
|
// 'column_name' => 'PREMIUM',
|
|
// 'db_column_name' => 'premium'
|
|
// ],
|
|
[
|
|
'column_index' => 15,
|
|
'column_name' => 'PRO RATA PREMIUM',
|
|
'db_column_name' => 'pro_rata_premium'
|
|
],
|
|
[
|
|
'column_index' => 16,
|
|
'column_name' => 'GST',
|
|
'db_column_name' => 'gst'
|
|
],
|
|
[
|
|
'column_index' => 17,
|
|
'column_name' => 'TOTAL AMOUNT',
|
|
'db_column_name' => 'total'
|
|
]
|
|
];
|
|
|
|
//for addition and dependent addition adding a ENDORSEMENT NO column
|
|
if(in_array($export_data['event_type'], ['addition', 'dependent_addition', 'missed_inception'])){
|
|
$excel_header_columns[] = [
|
|
'column_index' => 18,
|
|
'column_name' => 'ENDORSEMENT NO',
|
|
'db_column_name' => ''
|
|
];
|
|
}
|
|
|
|
}else{
|
|
|
|
// get excel export format structure array
|
|
// $template_json = $this->clientPolicyModel
|
|
// ->select('insurer_excel_export_template.jsoncolumns')
|
|
// ->join('insurer_excel_export_template', 'insurer_excel_export_template.insurer_id = client_policy.insurer_id and insurer_excel_export_template.policy_type_id = client_policy.policy_type_id')
|
|
// ->where('client_policy.id', $export_data['client_policy_id'])
|
|
// ->where('insurer_excel_export_template.event_name', $export_data['event_type'])
|
|
// ->where('insurer_excel_export_template.is_active', 1) //Live issue changes 17-10-2024
|
|
// ->where('insurer_excel_export_template.type_name', $export_data['actions'])
|
|
// ->first();
|
|
|
|
$sql = "
|
|
SELECT `insurer_excel_export_template`.`jsoncolumns`
|
|
FROM `client_policy`
|
|
JOIN `insurer_excel_export_template`
|
|
ON `insurer_excel_export_template`.`insurer_id` = `client_policy`.`insurer_id`
|
|
AND `insurer_excel_export_template`.`policy_type_id` =
|
|
CASE
|
|
WHEN `client_policy`.`policy_type_id` IN (2, 3, 4, 5) THEN 2
|
|
ELSE `client_policy`.`policy_type_id`
|
|
END
|
|
WHERE `client_policy`.`id` = :client_policy_id:
|
|
AND `insurer_excel_export_template`.`event_name` = :event_name:
|
|
AND `insurer_excel_export_template`.`is_active` = 1
|
|
AND `insurer_excel_export_template`.`type_name` = :type_name:
|
|
LIMIT 1";
|
|
|
|
$binds = [
|
|
'client_policy_id' => (int)$export_data['client_policy_id'],
|
|
'event_name' => $export_data['event_type'],
|
|
'type_name' => $export_data['actions'],
|
|
];
|
|
$query = db_connect()->query($sql,$binds);
|
|
$template_json = $query->getRowArray();
|
|
|
|
// dd(db_connect()->getLastQuery());
|
|
|
|
if(!empty($template_json) && $template_json != null){
|
|
$excel_header_columns = json_decode($template_json['jsoncolumns'], true);
|
|
}else{
|
|
return 6;
|
|
}
|
|
}
|
|
|
|
// remove existing batch file anf batch list data every time export
|
|
$this->removeOldExportInfoFromBatchFile($export_data);
|
|
|
|
//convert the excel data based on the insurer
|
|
$excel_data_info = generate_insurer_based_excel($excel_header_columns, $objects);
|
|
|
|
// Generate Excel file
|
|
$tempFile = tmpfile();
|
|
$success = generate_excel($excel_data_info['header'], $excel_data_info['data'], $tempFile);
|
|
|
|
// If Excel generation is successful
|
|
if ($success) {
|
|
|
|
$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, '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('Content-Transfer-Encoding: binary');
|
|
header('Cache-Control: must-revalidate');
|
|
header('Pragma: public');
|
|
header('Expires: 0');
|
|
|
|
// Output file contents
|
|
rewind($tempFile);
|
|
fpassthru($tempFile);
|
|
|
|
// Close and remove temporary file
|
|
fclose($tempFile);
|
|
exit();
|
|
|
|
return true; // Excel file successfully generated and exported
|
|
|
|
} else {
|
|
|
|
return false; // Batch operation failed
|
|
}
|
|
}
|
|
|
|
return false; // Excel generation failed
|
|
}
|
|
|
|
|
|
public function generateExcelForCorrection($export_data)
|
|
{
|
|
$ids = [];
|
|
|
|
$objects = $this->employeePolicyModel->getCorrectionEmployeesDataForExportExcel($export_data);
|
|
// dd(db_connect()->getLastQuery(),$objects);
|
|
|
|
foreach ($objects as $obj) {
|
|
$ids[] = $obj->id;
|
|
}
|
|
|
|
$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) {
|
|
$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']]);
|
|
|
|
if( $export_data['insurer_or_tpa'] == 'tpa'){
|
|
|
|
$excel_header_columns = [
|
|
['column_index' => 0, 'column_name' => 'Emp Code', 'db_column_name' => 'emp_code'],
|
|
['column_index' => 1, 'column_name' => 'RISK ID', 'db_column_name' => 'uhid'],
|
|
['column_index' => 1, 'column_name' => 'NAME OF EMP/DEP', 'db_column_name' => 'emp_name'],
|
|
['column_index' => 3, 'column_name' => 'EMP/DEP TYPE', 'db_column_name' => 'emp_type'],
|
|
['column_index' => 4, 'column_name' => 'RELATION', 'db_column_name' => 'emp_relationship'],
|
|
['column_index' => 5, 'column_name' => 'DOB', 'db_column_name' => 'emp_dob'],
|
|
['column_index' => 6, 'column_name' => 'GENDER', 'db_column_name' => 'emp_gender'],
|
|
['column_index' => 7, 'column_name' => 'Wrong Data', 'db_column_name' => 'old_value'],
|
|
['column_index' => 8, 'column_name' => 'Correct Data', 'db_column_name' => 'new_value'],
|
|
['column_index' => 9, 'column_name' => 'Remarks', 'db_column_name' => 'remarks'],
|
|
['column_index' => 10, 'column_name' => 'Endorsement_Id', 'db_column_name' => null]
|
|
];
|
|
}else{
|
|
|
|
// get excel export format structure array
|
|
$template_json = $this->clientPolicyModel
|
|
->select('insurer_excel_export_template.jsoncolumns')
|
|
->join('insurer_excel_export_template', 'insurer_excel_export_template.insurer_id = client_policy.insurer_id and insurer_excel_export_template.policy_type_id = client_policy.policy_type_id')
|
|
->where('client_policy.id', $export_data['client_policy_id'])
|
|
->where('insurer_excel_export_template.event_name', $export_data['event_type'])
|
|
->where('insurer_excel_export_template.is_active', 1) //Live issue changes 17-10-2024
|
|
->where('insurer_excel_export_template.type_name', $export_data['actions'])
|
|
->first();
|
|
|
|
if(!empty($template_json) && $template_json != null){
|
|
$excel_header_columns = json_decode($template_json['jsoncolumns'], true);
|
|
}else{
|
|
return 6;
|
|
}
|
|
}
|
|
|
|
|
|
$excel_data_info = generate_insurer_based_excel($excel_header_columns, $objects);
|
|
|
|
// Generate Excel file
|
|
$tempFile = tmpfile();
|
|
$success = generate_excel($excel_data_info['header'], $excel_data_info['data'], $tempFile);
|
|
|
|
if ($success) {
|
|
|
|
$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) {
|
|
|
|
$endorsement_update_data['status'] = 'inprogress';
|
|
if( $export_data['insurer_or_tpa'] == 'tpa'){
|
|
$endorsement_update_data['is_tpa_export'] = $return ?? generate_random_string(4);
|
|
}
|
|
|
|
$this->empEndorsementModel->where('group_key', $group_key)->set($endorsement_update_data)->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);
|
|
exit();
|
|
|
|
return true;
|
|
} else {
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
public function generateExcelForSIEnhancement($export_data)
|
|
{
|
|
$ids = [];
|
|
$objects = $this->employeePolicyModel->getSIEnhancementEmployeesDataForExportExcel($export_data);
|
|
|
|
$policy_details = $this->clientPolicyModel->where('id', $export_data['client_policy_id'])->first();
|
|
|
|
if ($policy_details['cd_ac_pk'] == null) {
|
|
$this->myLogger->logme('error', 'The policy does not have a CD account number.');
|
|
return 1;
|
|
}
|
|
|
|
$cash_balance = $this->clientDepositModel
|
|
->where('cd_ac_pk', $policy_details['cd_ac_pk'])
|
|
// ->where('cd_ac_no', $policy_details['cd_ac_no'])
|
|
->where('is_active', 1)
|
|
->orderBy('id', 'DESC')
|
|
->first();
|
|
|
|
if ($cash_balance == null) {
|
|
|
|
$balance = $this->CDMasterModel
|
|
->where('client_id', $export_data['client_id'])
|
|
->where('insurer_id', $policy_details['insurer_id'])
|
|
->where('id', $policy_details['cd_ac_pk'])
|
|
->first();
|
|
|
|
$cash_balance['balance'] = $balance['opening_bal'];
|
|
}
|
|
|
|
|
|
$totals = 0;
|
|
foreach ($objects as $obj) {
|
|
$ids[] = $obj->endorsement_primarykey;
|
|
$totals += $obj->total;
|
|
}
|
|
|
|
$rounded_totals = round($totals, 2);
|
|
// echo '<pre>';
|
|
// print_r($ids); die;
|
|
|
|
//check CD amt insufficiend for only insurer, not tpa // DO NOT REMOVE THIS
|
|
if($export_data['insurer_or_tpa'] == 'insurer')
|
|
{
|
|
if (!empty($cash_balance)) {
|
|
if ((int) $cash_balance['balance'] < (int) $totals) {
|
|
clear_cd_balance_session(); // Clear old junk first
|
|
|
|
$cd_session_data = json_encode([
|
|
'cd_balance' => false,
|
|
'cd_amount' => $cash_balance['balance'],
|
|
'excel_file_amt' => $totals
|
|
]);
|
|
|
|
session()->set('cd_balance_info', $cd_session_data);
|
|
session()->set('cd_balance', 'insufficient'); // Use a string status for clarity
|
|
|
|
$hr_data = $this->getHrdataForInsufficientMailSend($export_data['client_branch_id']);
|
|
session()->set('hr_data', json_encode(['client_id' => $export_data['client_id'], 'hr_data' => $hr_data]));
|
|
}else{
|
|
session()->set('cd_balance', 'sufficient'); // Use a string status for clarity
|
|
session()->set('cd_balance_info', null);
|
|
}
|
|
}
|
|
}
|
|
|
|
$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']]);
|
|
|
|
|
|
// get excel export format structure array
|
|
$template_json = $this->clientPolicyModel
|
|
->select('insurer_excel_export_template.jsoncolumns')
|
|
->join('insurer_excel_export_template', 'insurer_excel_export_template.insurer_id = client_policy.insurer_id and insurer_excel_export_template.policy_type_id = client_policy.policy_type_id')
|
|
->where('client_policy.id', $export_data['client_policy_id'])
|
|
->where('insurer_excel_export_template.event_name', $export_data['event_type'])
|
|
->where('insurer_excel_export_template.is_active', 1) //Live issue changes 17-10-2024
|
|
->where('insurer_excel_export_template.type_name', $export_data['actions'])
|
|
->first();
|
|
|
|
if(!empty($template_json) && $template_json != null){
|
|
$excel_header_columns = json_decode($template_json['jsoncolumns'], true);
|
|
}else{
|
|
return 6;
|
|
}
|
|
|
|
if( $export_data['insurer_or_tpa'] == 'tpa'){
|
|
|
|
$excel_header_columns = [
|
|
['column_index' => 0, 'column_name' => 'S.No', 'db_column_name' => 'index'],
|
|
['column_index' => 1, 'column_name' => 'NAME OF EMP/DEP', 'db_column_name' => 'emp_name'],
|
|
['column_index' => 2, 'column_name' => 'EMP ID', 'db_column_name' => 'emp_code'],
|
|
['column_index' => 3, 'column_name' => 'EMP/DEP TYPE', 'db_column_name' => 'emp_type'],
|
|
['column_index' => 4, 'column_name' => 'RELATION', 'db_column_name' => 'emp_relationship_code'],
|
|
['column_index' => 5, 'column_name' => 'DOB', 'db_column_name' => 'emp_dob'],
|
|
['column_index' => 6, 'column_name' => 'GENDER', 'db_column_name' => 'emp_gender'],
|
|
['column_index' => 7, 'column_name' => 'PRE EXISTING AILMENTS', 'db_column_name' => 'pre_existing_alignments'],
|
|
['column_index' => 8, 'column_name' => 'BASIC COVER SI', 'db_column_name' => 'new_basic_cover_si'],
|
|
['column_index' => 9, 'column_name' => 'Old Sum Insured', 'db_column_name' => 'old_basic_cover_si'],
|
|
['column_index' => 10, 'column_name' => 'Date of Coverage', 'db_column_name' => 'date_of_coverage'],
|
|
['column_index' => 11, 'column_name' => 'Policy End Date', 'db_column_name' => 'policy_end_date'],
|
|
['column_index' => 12, 'column_name' => 'No Of Days', 'db_column_name' => 'no_of_days'],
|
|
['column_index' => 13, 'column_name' => 'Old SI Premium', 'db_column_name' => 'old_si_premium'],
|
|
['column_index' => 14, 'column_name' => 'New SI premium', 'db_column_name' => 'new_si_premium'],
|
|
['column_index' => 15, 'column_name' => 'Difference premium', 'db_column_name' => 'difference_premium'],
|
|
['column_index' => 16, 'column_name' => 'Pro Rata Premium', 'db_column_name' => 'pro_rata_premium'],
|
|
['column_index' => 17, 'column_name' => 'GST', 'db_column_name' => 'gst'],
|
|
['column_index' => 18, 'column_name' => 'Total', 'db_column_name' => 'total'],
|
|
['column_index' => 19, 'column_name' => 'ENDORSEMENT_ID', 'db_column_name' => null]
|
|
];
|
|
|
|
}
|
|
|
|
$excel_data_info = generate_insurer_based_excel($excel_header_columns, $objects);
|
|
|
|
// Generate Excel file
|
|
$tempFile = tmpfile();
|
|
$success = generate_excel($excel_data_info['header'], $excel_data_info['data'], $tempFile);
|
|
|
|
if ($success) {
|
|
|
|
$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) {
|
|
|
|
$endorsement_update_data['status'] = 'inprogress';
|
|
|
|
if( $export_data['insurer_or_tpa'] == 'tpa'){
|
|
$endorsement_update_data['is_tpa_export'] = $return ?? generate_random_string(4);
|
|
}
|
|
|
|
$this->empEndorsementModel->where('group_key', $group_key)->set($endorsement_update_data)->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);
|
|
exit();
|
|
|
|
return true;
|
|
} else {
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
public function generateExcelForDeletion($export_data)
|
|
{
|
|
// dd($export_data);
|
|
|
|
$ids = [];
|
|
|
|
$objects = $this->employeePolicyModel->getDeletionEmployeeDataForExportExcel($export_data);
|
|
// dd(db_connect()->getLastQuery());
|
|
// dd($objects);
|
|
|
|
$totals = 0;
|
|
foreach ($objects as $obj) {
|
|
$ids[] = $obj->endorsement_primarykey;
|
|
$totals += $obj->total;
|
|
}
|
|
$rounded_totals = round($totals, 2);
|
|
|
|
$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']]);
|
|
|
|
if( $export_data['insurer_or_tpa'] == 'tpa'){
|
|
|
|
$excel_header_columns = [
|
|
['column_index' => 0, 'column_name' => 'S.No', 'db_column_name' => 'index'],
|
|
['column_index' => 1, 'column_name' => 'EMP ID', 'db_column_name' => 'emp_code'],
|
|
['column_index' => 2, 'column_name' => 'EMP NAME', 'db_column_name' => 'emp_name'],
|
|
['column_index' => 3, 'column_name' => 'DOB', 'db_column_name' => 'emp_dob'],
|
|
['column_index' => 4, 'column_name' => 'GENDER', 'db_column_name' => 'emp_gender'],
|
|
['column_index' => 5, 'column_name' => 'RELATIONSHIP', 'db_column_name' => 'emp_relationship'],
|
|
['column_index' => 6, 'column_name' => 'SUM INSURED', 'db_column_name' => 'basic_cover_si'],
|
|
['column_index' => 7, 'column_name' => 'Date of Leaving', 'db_column_name' => 'dateofexit'],
|
|
['column_index' => 8, 'column_name' => 'Policy End Date', 'db_column_name' => 'policy_end_date'],
|
|
['column_index' => 9, 'column_name' => 'No Of Days', 'db_column_name' => 'no_of_days'],
|
|
['column_index' => 10, 'column_name' => 'Premium', 'db_column_name' => 'premium'],
|
|
['column_index' => 11, 'column_name' => 'Pro Rata Premium', 'db_column_name' => 'pro_rata_premium'],
|
|
['column_index' => 12, 'column_name' => 'GST', 'db_column_name' => 'gst'],
|
|
['column_index' => 13, 'column_name' => 'Total', 'db_column_name' => 'total'],
|
|
['column_index' => 14, 'column_name' => 'Claim Status', 'db_column_name' => 'claim_status'],
|
|
['column_index' => 15, 'column_name' => 'ENDORSEMENT_ID', 'db_column_name' => null]
|
|
];
|
|
|
|
}else{
|
|
|
|
// get excel export format structure array
|
|
$template_json = $this->clientPolicyModel
|
|
->select('insurer_excel_export_template.jsoncolumns')
|
|
->join('insurer_excel_export_template', 'insurer_excel_export_template.insurer_id = client_policy.insurer_id and insurer_excel_export_template.policy_type_id = client_policy.policy_type_id')
|
|
->where('client_policy.id', $export_data['client_policy_id'])
|
|
->where('insurer_excel_export_template.event_name', $export_data['event_type'])
|
|
->where('insurer_excel_export_template.is_active', 1) //Live issue changes 17-10-2024
|
|
->where('insurer_excel_export_template.type_name', $export_data['actions'])
|
|
->first();
|
|
|
|
if(!empty($template_json) && $template_json != null){
|
|
$excel_header_columns = json_decode($template_json['jsoncolumns'], true);
|
|
}else{
|
|
return 6;
|
|
}
|
|
|
|
}
|
|
|
|
$excel_data_info = generate_insurer_based_excel($excel_header_columns, $objects);
|
|
|
|
// Generate Excel file
|
|
$tempFile = tmpfile();
|
|
$success = generate_excel($excel_data_info['header'], $excel_data_info['data'], $tempFile);
|
|
|
|
if ($success) {
|
|
$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) {
|
|
$endorsement_update_data['status'] = 'inprogress';
|
|
if( $export_data['insurer_or_tpa'] == 'tpa'){
|
|
$endorsement_update_data['is_tpa_export'] = $return ?? generate_random_string(4);
|
|
}
|
|
$this->empEndorsementModel->where('group_key', $group_key)->set($endorsement_update_data)->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);
|
|
exit();
|
|
|
|
return true;
|
|
} else {
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
public function generateExcelForAllEventType($export_data)
|
|
{
|
|
|
|
$additionData = [];
|
|
$deletionData = [];
|
|
$inceptionData = [];
|
|
$correctionData = [];
|
|
$enhancementData = [];
|
|
$dependentAdditionData = [];
|
|
|
|
$event_type_array = $export_data['event_type'];
|
|
|
|
foreach ($export_data['event_type'] as $value)
|
|
{
|
|
|
|
if($value == 'addition'){
|
|
$export_data['event_type'] = 'addition';
|
|
$additionData = $this->employeePolicyModel->getInceptionEmployeeDataForExportExcel($export_data);
|
|
|
|
}else if($value == 'inception'){
|
|
$export_data['event_type'] = 'inception';
|
|
$inceptionData = $this->employeePolicyModel->getInceptionEmployeeDataForExportExcel($export_data); //Live issue changes 17-10-2024
|
|
|
|
}else if($value == 'dependent_addition'){
|
|
$export_data['event_type'] = 'dependent_addition';
|
|
$dependentAdditionData = $this->employeePolicyModel->getInceptionEmployeeDataForExportExcel($export_data);
|
|
|
|
}else if($value == 'deletion'){
|
|
$export_data['event_type'] = 'deletion';
|
|
$deletionData = $this->employeePolicyModel->getDeletionEmployeeDataForExportExcel($export_data);
|
|
|
|
}else if($value == 'si_enhancement'){
|
|
$export_data['event_type'] = 'si_enhancement';
|
|
$enhancementData = $this->employeePolicyModel->getSIEnhancementEmployeesDataForExportExcel($export_data);
|
|
|
|
}else if($value == 'correction'){
|
|
$export_data['event_type'] = 'correction';
|
|
$correctionData = $this->employeePolicyModel->getCorrectionEmployeesDataForExportExcel($export_data);
|
|
|
|
}else if($value == "missed_inception"){
|
|
$export_data['event_type'] = 'missed_inception';
|
|
$additionData = $this->employeePolicyModel->getInceptionEmployeeDataForExportExcel($export_data);
|
|
}
|
|
|
|
}
|
|
|
|
if(empty($additionData) && empty($deletionData) && empty($inceptionData) && empty($correctionData) && empty($enhancementData) && empty($dependentAdditionData)){
|
|
|
|
return false;
|
|
}
|
|
|
|
|
|
//for cd tranction and cd master data is empty check
|
|
if(!empty($inceptionData) && $inceptionData != null || !empty($additionData) && $additionData != null || !empty($dependentAdditionData) && $dependentAdditionData != null){
|
|
|
|
$policy_details = $this->clientPolicyModel->where('id', $export_data['client_policy_id'])->first();
|
|
|
|
if ($policy_details['cd_ac_pk'] == null) {
|
|
$this->myLogger->logme('error', 'The policy does not have a CD account number.');
|
|
return 5;
|
|
}
|
|
|
|
$cash_balance = $this->clientDepositModel
|
|
->where('cd_ac_pk', $policy_details['cd_ac_pk'])
|
|
// ->where('cd_ac_no', $policy_details['cd_ac_no'])
|
|
->where('is_active', 1)
|
|
->orderBy('id', 'DESC')
|
|
->first();
|
|
|
|
if ($cash_balance == null) {
|
|
$balance = $this->CDMasterModel
|
|
->where('client_id', $export_data['client_id'])
|
|
->where('insurer_id', $policy_details['insurer_id'])
|
|
->where('id', $policy_details['cd_ac_pk'])
|
|
->first();
|
|
|
|
$cash_balance['balance'] = $balance['opening_bal'];
|
|
}
|
|
|
|
// Calculate the total amount from the objects
|
|
$totals = 0;
|
|
foreach ($inceptionData as $item) {
|
|
$totals = $totals + $item->total;
|
|
}
|
|
|
|
foreach ($additionData as $item) {
|
|
$totals = $totals + $item->total;
|
|
}
|
|
|
|
foreach ($dependentAdditionData as $item) {
|
|
$totals = $totals + $item->total;
|
|
}
|
|
|
|
$totals = round($totals, 2);
|
|
|
|
|
|
if($export_data['insurer_or_tpa'] != 'tpa')// check overal emp premium amt with cd balance only for insurer export, not tpa export
|
|
{
|
|
if (!empty($cash_balance)) {
|
|
if ((int) $cash_balance['balance'] < (int) $totals) {
|
|
clear_cd_balance_session(); // Clear old junk first
|
|
|
|
$cd_session_data = json_encode([
|
|
'cd_balance' => false,
|
|
'cd_amount' => $cash_balance['balance'],
|
|
'excel_file_amt' => $totals
|
|
]);
|
|
|
|
session()->set('cd_balance_info', $cd_session_data);
|
|
session()->set('cd_balance', 'insufficient'); // Use a string status for clarity
|
|
|
|
$hr_data = $this->getHrdataForInsufficientMailSend($export_data['client_branch_id']);
|
|
session()->set('hr_data', json_encode(['client_id' => $export_data['client_id'], 'hr_data' => $hr_data]));
|
|
}else{
|
|
session()->set('cd_balance', 'sufficient'); // Use a string status for clarity
|
|
session()->set('cd_balance_info', null);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
$this->removeOldExportInfoFromBatchFile($export_data);
|
|
|
|
|
|
// Merging all data into a single array
|
|
$mergedData = array_merge($inceptionData, $additionData, $dependentAdditionData, $correctionData, $enhancementData, $deletionData);
|
|
|
|
// dd($inceptionData, $additionData, $dependentAdditionData, $correctionData, $enhancementData, $deletionData, $mergedData);
|
|
|
|
|
|
// $template_json = $this->clientPolicyModel
|
|
// ->select('insurer_excel_export_template.jsoncolumns')
|
|
// ->join('insurer_excel_export_template', 'insurer_excel_export_template.insurer_id = client_policy.insurer_id and insurer_excel_export_template.policy_type_id = client_policy.policy_type_id')
|
|
// ->where('client_policy.id', $export_data['client_policy_id'])
|
|
// ->where('insurer_excel_export_template.event_name', 'all')
|
|
// ->where('insurer_excel_export_template.is_active', 1) //Live issue changes 17-10-2024
|
|
// ->where('insurer_excel_export_template.type_name', $export_data['actions'])
|
|
// ->first();
|
|
|
|
$sql = "
|
|
SELECT `insurer_excel_export_template`.`jsoncolumns`
|
|
FROM `client_policy`
|
|
JOIN `insurer_excel_export_template`
|
|
ON `insurer_excel_export_template`.`insurer_id` = `client_policy`.`insurer_id`
|
|
AND `insurer_excel_export_template`.`policy_type_id` =
|
|
CASE
|
|
WHEN `client_policy`.`policy_type_id` IN (2, 3, 4, 5) THEN 2
|
|
ELSE `client_policy`.`policy_type_id`
|
|
END
|
|
WHERE `client_policy`.`id` = :client_policy_id:
|
|
AND `insurer_excel_export_template`.`event_name` = 'all'
|
|
AND `insurer_excel_export_template`.`is_active` = 1
|
|
AND `insurer_excel_export_template`.`type_name` = :type_name:
|
|
LIMIT 1";
|
|
|
|
$binds = ['client_policy_id' => (int)$export_data['client_policy_id'],'type_name' => $export_data['actions']];
|
|
$query = db_connect()->query($sql,$binds);
|
|
$template_json = $query->getRowArray();
|
|
|
|
|
|
if(!empty($template_json) && $template_json != null){
|
|
$excel_header_columns = json_decode($template_json['jsoncolumns'], true);
|
|
}else{
|
|
return 6;
|
|
}
|
|
|
|
|
|
// Generating Excel data
|
|
$excel_data_info = generate_insurer_based_excel($excel_header_columns, $mergedData);
|
|
|
|
// Generate Excel file
|
|
$tempFile = tmpfile();
|
|
$success = generate_excel($excel_data_info['header'], $excel_data_info['data'], $tempFile);
|
|
|
|
// If Excel generation is successful
|
|
if ($success) {
|
|
|
|
$random_number_count = 4;
|
|
$batch_code = generate_random_string($random_number_count);
|
|
session()->set('batch_code', $batch_code);
|
|
|
|
foreach ($event_type_array as $value)
|
|
{
|
|
$random_number_count = 4;
|
|
$export_data['batch_code'] = session()->get('batch_code');
|
|
$export_data['created_by'] = get_session_userid();
|
|
|
|
$insert = null;
|
|
if($value == 'addition'){
|
|
|
|
if(!empty($additionData) && $additionData != null){
|
|
|
|
$count = count($additionData);
|
|
$export_data['count'] = $count;
|
|
$export_data['status'] = 'success';
|
|
$export_data['event_type'] = 'addition';
|
|
|
|
$insert = $this->batchFileModel->insert($export_data);
|
|
$batch_file_batch_code = $this->batchFileModel->where('id', $insert)->first();
|
|
// $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, 'user_id' => get_session_userid(), 'batch_list_data' => $additionData]]);
|
|
|
|
}
|
|
|
|
}else if($value == 'inception'){
|
|
|
|
if(!empty($inceptionData) && $inceptionData != null){
|
|
|
|
$count = count($inceptionData);
|
|
$export_data['count'] = $count;
|
|
$export_data['status'] = 'success';
|
|
$export_data['event_type'] = 'inception';
|
|
|
|
$insert = $this->batchFileModel->insert($export_data);
|
|
$batch_file_batch_code = $this->batchFileModel->where('id', $insert)->first();
|
|
// $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, 'user_id' => get_session_userid(), 'batch_list_data' => $inceptionData]]);
|
|
}
|
|
|
|
}else if($value == 'dependent_addition'){
|
|
|
|
if(!empty($dependentAdditionData) && $dependentAdditionData != null){
|
|
|
|
$count = count($dependentAdditionData);
|
|
$export_data['count'] = $count;
|
|
$export_data['status'] = 'success';
|
|
$export_data['event_type'] = 'dependent_addition';
|
|
|
|
$insert = $this->batchFileModel->insert($export_data);
|
|
$batch_file_batch_code = $this->batchFileModel->where('id', $insert)->first();
|
|
// $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, 'user_id' => get_session_userid(), 'batch_list_data' => $dependentAdditionData]]);
|
|
}
|
|
}else if($value == 'deletion'){
|
|
|
|
if(!empty($deletionData) && $deletionData != null){
|
|
|
|
$count = count($deletionData);
|
|
$export_data['count'] = $count;
|
|
$export_data['status'] = 'success';
|
|
$export_data['event_type'] = 'deletion';
|
|
|
|
$insert = $this->batchFileModel->insert($export_data);
|
|
$batch_file_batch_code = $this->batchFileModel->where('id', $insert)->first();
|
|
// $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, 'user_id' => get_session_userid(), 'batch_list_data' => $deletionData]]);
|
|
}
|
|
|
|
}else if($value == 'si_enhancement'){
|
|
|
|
if(!empty($enhancementData) && $enhancementData != null){
|
|
|
|
$count = count($enhancementData);
|
|
$export_data['count'] = $count;
|
|
$export_data['status'] = 'success';
|
|
$export_data['event_type'] = 'si_enhancement';
|
|
|
|
$insert = $this->batchFileModel->insert($export_data);
|
|
$batch_file_batch_code = $this->batchFileModel->where('id', $insert)->first();
|
|
// $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, 'user_id' => get_session_userid(), 'batch_list_data' => $enhancementData]]);
|
|
}
|
|
|
|
}else if($value == 'correction'){
|
|
|
|
if(!empty($correctionData) && $correctionData != null){
|
|
|
|
$count = count($correctionData);
|
|
$export_data['count'] = $count;
|
|
$export_data['status'] = 'success';
|
|
$export_data['event_type'] = 'correction';
|
|
|
|
$insert = $this->batchFileModel->insert($export_data);
|
|
$batch_file_batch_code = $this->batchFileModel->where('id', $insert)->first();
|
|
// $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, 'user_id' => get_session_userid(), 'batch_list_data' => $correctionData]]);
|
|
}
|
|
}
|
|
|
|
if(in_array($value, ['deletion', 'si_enhancement', 'correction']) && $insert){
|
|
|
|
$endorsement_data_for_update = [];
|
|
|
|
if($value == 'deletion'){
|
|
$endorsement_data_for_update = $deletionData;
|
|
}else if($value == 'si_enhancement') {
|
|
$endorsement_data_for_update = $enhancementData;
|
|
}else if($value == 'correction') {
|
|
$endorsement_data_for_update = $correctionData;
|
|
}
|
|
|
|
foreach ($endorsement_data_for_update as $key => $edata) {
|
|
|
|
$id = $edata->id ?? $edata->endorsement_primarykey ?? null;
|
|
|
|
if($id){
|
|
$group_key = $this->empEndorsementModel->select('group_key')->where('id', $id)->first();
|
|
if ($group_key) {
|
|
|
|
$endorsement_update_data['status'] = 'inprogress';
|
|
if( $export_data['insurer_or_tpa'] == 'tpa'){
|
|
$endorsement_update_data['is_tpa_export'] = $return ?? generate_random_string(4);
|
|
}
|
|
|
|
$this->empEndorsementModel->where('group_key', $group_key)->set($endorsement_update_data)->update();
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
session()->remove('batch_code');
|
|
|
|
// 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('Content-Transfer-Encoding: binary');
|
|
header('Cache-Control: must-revalidate');
|
|
header('Pragma: public');
|
|
header('Expires: 0');
|
|
|
|
// Output file contents
|
|
rewind($tempFile);
|
|
fpassthru($tempFile);
|
|
|
|
// Close and remove temporary file
|
|
fclose($tempFile);
|
|
exit();
|
|
|
|
return true; // Excel file successfully generated and exported
|
|
|
|
} else {
|
|
|
|
return false; // Batch operation failed
|
|
}
|
|
}
|
|
|
|
return false; // Excel generation failed
|
|
|
|
|
|
|
|
}
|
|
|
|
//not in use
|
|
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;
|
|
}
|
|
}
|
|
}
|
|
//end not in use
|
|
|
|
/**
|
|
* The below functions are Imports data from an Excel file for :
|
|
* - Inception
|
|
* - Deletion
|
|
* - Correction
|
|
* - SI_Enhancement
|
|
*
|
|
* This functions are processes the uploaded Excel file, extracts relevant information,
|
|
* and updates employee policies and employees table accordingly.
|
|
*
|
|
* @param array $import_data An associative array containing :
|
|
* - client_id,
|
|
* - client_policy_id,
|
|
* - the uploaded file.
|
|
* @return int Returns:
|
|
* - 1 if data import is successful.
|
|
* - 2 if the file does not exist.
|
|
* - 0 if the provided data is incomplete or incorrect.
|
|
*/
|
|
|
|
|
|
//Endorsement Inception
|
|
|
|
public function importInceptionFileValidation($params)
|
|
{
|
|
|
|
$this->myLogger->logme('info', 'Inception File Validation -- Function called');
|
|
|
|
$file_id = $params['file_id'];
|
|
// dd($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'];
|
|
|
|
$client_policy_data = $this->clientPolicyModel->where('id', $client_policy_id)->first();
|
|
|
|
$insurer_or_tpa = $file['insurer_or_tpa'];
|
|
if ($insurer_or_tpa == 'tpa') {
|
|
$id = 'tpa_id';
|
|
} else if ($insurer_or_tpa == 'insurer') {
|
|
$id = 'uhid';
|
|
}
|
|
|
|
$ref_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' => $file['event_type'],
|
|
];
|
|
|
|
$file_name_with_path = storage_ensure_local_file(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',
|
|
// 'RELATIONSHIP CODE',
|
|
'DOB',
|
|
'GENDER',
|
|
'PRE EXISTING AILMENTS',
|
|
'BASIC COVER SI',
|
|
'DATE OF COVERAGE',
|
|
'AGE',
|
|
'RELATIONSHIP',
|
|
'REMARKS',
|
|
'POLICY END DATE',
|
|
'NO OF DAYS',
|
|
'TPA ID',
|
|
'RISK ID',
|
|
// 'PREMIUM',
|
|
'PRO RATA PREMIUM',
|
|
'GST',
|
|
'TOTAL AMOUNT',
|
|
];
|
|
|
|
if(in_array($file['event_type'], ['addition', 'dependent_addition', 'missed_inception'])){
|
|
$inceptionHeader[] = 'ENDORSEMENT NO';
|
|
}
|
|
|
|
// dd($inceptionHeader);
|
|
foreach ($inceptionHeader as $key => $value) {
|
|
|
|
if (!isset($excel_header[$key]) || $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', 'excel_header' => $excel_header, 'inception_header' => $inceptionHeader];
|
|
}
|
|
}
|
|
|
|
$emp_count = count($excel_data);
|
|
|
|
//get the employee data for excel file validation
|
|
$employee_data = $this->employeePolicyModel->getInceptionEmployeeDataForExportExcel($ref_data, 1);
|
|
|
|
// ----------------- CD BALANCE CHECK ---------------------------------------------------------------------------
|
|
|
|
$cash_balance = $this->clientDepositModel
|
|
->where('cd_ac_pk', $client_policy_data['cd_ac_pk'])
|
|
->where('is_active', 1)
|
|
->orderBy('id', 'DESC')
|
|
->first();
|
|
|
|
if ($cash_balance == null) {
|
|
$balance = $this->CDMasterModel
|
|
->where('client_id', $file['client_id'])
|
|
->where('insurer_id', $client_policy_data['insurer_id'])
|
|
->where('id', $client_policy_data['cd_ac_pk'])
|
|
->first();
|
|
|
|
$cash_balance['balance'] = $balance['opening_bal'];
|
|
}
|
|
|
|
// Calculate the total amount from the objects
|
|
$totals = 0;
|
|
foreach ($employee_data as $item) {
|
|
$totals = $totals + $item['total'];
|
|
}
|
|
|
|
$totals = round($totals, 2);
|
|
|
|
//check CD amt insufficient only insurer, not tpa
|
|
if($file['insurer_or_tpa'] == 'insurer')
|
|
{
|
|
if (!empty($cash_balance)) {
|
|
if ((int) $cash_balance['balance'] < (int) $totals) {
|
|
$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]);
|
|
$this->batchFileModel->where('id', $file_id)->set(['status' => 'failed-7', 'error_data' => 'Insufficient deposit balance. Available CD Balance: ' . $cash_balance['balance'] . ', Excel Total Amount: ' . $totals])->update();
|
|
return ['status' => 'error', 'message' => 'Insufficient deposit balance. Available CD Balance: ' . $cash_balance['balance'] . ', Required Amount: ' . $totals];
|
|
}
|
|
}
|
|
}
|
|
|
|
// ---------------- END CD BALANCE CHECK ----------------------------------------------------------------------------
|
|
|
|
|
|
if ($employee_data == null || empty($employee_data)) {
|
|
|
|
if ($insurer_or_tpa == 'tpa') {
|
|
|
|
$data = [
|
|
'status' => 'failed-1',
|
|
];
|
|
|
|
$this->batchFileModel->where('id', $file_id)->set($data)->update();
|
|
$this->myLogger->logme('error', 'Inception File Validation -- TPAID already updated');
|
|
|
|
$file_data = $this->getDataByFileId($file_id, 'failure');
|
|
$this->setPullNotification($file_data);
|
|
|
|
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') {
|
|
|
|
$data = [
|
|
'status' => 'failed-2',
|
|
];
|
|
|
|
$this->batchFileModel->where('id', $file_id)->set($data)->update();
|
|
$this->myLogger->logme('error', 'Inception File Validation -- UHID already updated');
|
|
|
|
$file_data = $this->getDataByFileId($file_id, 'failure');
|
|
$this->setPullNotification($file_data);
|
|
|
|
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', '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', '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);
|
|
$difference = $emp_data_count - $excel_data_count;
|
|
|
|
$status = 'in-progress';
|
|
|
|
if ($excel_data_count < $emp_data_count) {
|
|
$status = 'in-progress-partially';
|
|
$partially_updated_data = 'Expected : ' . $emp_data_count . ', ' . 'Updated : ' . $excel_data_count . ', ' . 'difference : ' . $difference;
|
|
$this->myLogger->logme('error', 'Inception File Validation -- excel file count partially : {data}', ['data' => $partially_updated_data]);
|
|
}
|
|
|
|
if ($emp_data_count < $excel_data_count) {
|
|
|
|
$data = [
|
|
'status' => 'failed-3',
|
|
];
|
|
|
|
$this->batchFileModel->where('id', $file_id)->set($data)->update();
|
|
$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 ['status' => 'error', 'message' =>'The Excel record count exceeds the DB record count. excel file count : ' . $excel_data_count . 'db count : ' . $emp_data_count];
|
|
}
|
|
|
|
|
|
$errors = []; // Initialize an array to store errors
|
|
$missing_id = [];
|
|
$batch_list_id = [];
|
|
$tpa_id_all = []; //this array to store all TPA ID
|
|
$tpa_id_duplicate = []; //store duplicate TPA ID
|
|
|
|
foreach ($employee_data as $key => $emp_value) {
|
|
|
|
$key = $key + 1;
|
|
|
|
if(!isset($excel_data[$key])){
|
|
break;
|
|
}
|
|
|
|
//--- TPA ID Duplicate check start ---
|
|
|
|
// Duplicate checking for only GMC's and GPA
|
|
if(in_array($client_policy_data['policy_type_id'], [1,2,3,4,5])){
|
|
$current_tpa_id = $excel_data[$key][13];
|
|
|
|
if (isset($tpa_id_all[$current_tpa_id])) {
|
|
|
|
// Add the current row to errors
|
|
$errors[$key][] = [
|
|
'row' => $key,
|
|
'column' => 13,
|
|
'db_data' => "Duplicate TPA ID Found",
|
|
'excel_data' => $current_tpa_id
|
|
];
|
|
|
|
// Add all existing rows with the same TPA ID to errors
|
|
foreach ($tpa_id_all[$current_tpa_id] as $existing_row) {
|
|
$errors[$existing_row][] = [
|
|
'row' => $existing_row,
|
|
'column' => 13,
|
|
'db_data' => "Duplicate TPA ID Found",
|
|
'excel_data' => $current_tpa_id
|
|
];
|
|
}
|
|
|
|
} else {
|
|
if($current_tpa_id != "" && $current_tpa_id != null){
|
|
$tpa_id_all[$current_tpa_id][] = $key;
|
|
}
|
|
}
|
|
}
|
|
|
|
//--- TPA ID Duplicate check end ---
|
|
|
|
if ($insurer_or_tpa == 'tpa' && in_array($client_policy_data['policy_type_id'], [1,2,3,4,5])) {
|
|
|
|
//verify the TPA ID is not null
|
|
if ($excel_data[$key][13] === null) {
|
|
$missing_id[$key][] = [
|
|
'row' => $key,
|
|
'column' => 13,
|
|
'db_data' => "TPA ID is Must",
|
|
'excel_data' => $excel_data[$key][13]
|
|
];
|
|
}
|
|
} else if ($insurer_or_tpa == 'insurer') {
|
|
|
|
//verify the UHID or Risk ID is not null
|
|
if ($excel_data[$key][14] === null) {
|
|
$missing_id[$key][] = [
|
|
'row' => $key,
|
|
'column' => 14,
|
|
'db_data' => "UHID or Risk ID is Must",
|
|
'excel_data' => $excel_data[$key][14]
|
|
];
|
|
}
|
|
}
|
|
|
|
if (in_array($file['event_type'], ['addition', 'dependent_addition', 'missed_inception'])) {
|
|
if ($excel_data[$key][18] === null) {
|
|
$missing_id[$key][] = [
|
|
'row' => $key,
|
|
'column' => 18,
|
|
'db_data' => "Endorsement ID is Must",
|
|
'excel_data' => $excel_data[$key][18]
|
|
];
|
|
}
|
|
}
|
|
|
|
|
|
if ($emp_value['emp_name'] != $excel_data[$key][1]) {
|
|
$errors[$key][] = [
|
|
'row' => $key,
|
|
'column' => 1,
|
|
'db_data' => $emp_value['emp_name'],
|
|
'excel_data' => $excel_data[$key][1]
|
|
];
|
|
}
|
|
|
|
if ($emp_value['emp_code'] != $excel_data[$key][2]) {
|
|
$errors[$key][] = [
|
|
'row' => $key,
|
|
'column' => 2,
|
|
'db_data' => $emp_value['emp_code'],
|
|
'excel_data' => $excel_data[$key][2]
|
|
];
|
|
}
|
|
|
|
if ($emp_value['emp_dob'] != $excel_data[$key][3]) {
|
|
$errors[$key][] = [
|
|
'row' => $key,
|
|
'column' => 3,
|
|
'db_data' => $emp_value['emp_dob'],
|
|
'excel_data' => $excel_data[$key][3]
|
|
];
|
|
}
|
|
|
|
if ($emp_value['emp_gender'] != $excel_data[$key][4]) {
|
|
$errors[$key][] = [
|
|
'row' => $key,
|
|
'column' => 4,
|
|
'db_data' => $emp_value['emp_gender'],
|
|
'excel_data' => $excel_data[$key][4]
|
|
];
|
|
}
|
|
|
|
if ($emp_value['pre_existing_alignments'] != $excel_data[$key][5]) {
|
|
$errors[$key][] = [
|
|
'row' => $key,
|
|
'column' => 5,
|
|
'db_data' => $emp_value['pre_existing_alignments'],
|
|
'excel_data' => $excel_data[$key][5]
|
|
];
|
|
}
|
|
|
|
if ($emp_value['basic_cover_si'] != $excel_data[$key][6]) {
|
|
$errors[$key][] = [
|
|
'row' => $key,
|
|
'column' => 6,
|
|
'db_data' => $emp_value['basic_cover_si'],
|
|
'excel_data' => $excel_data[$key][6]
|
|
];
|
|
}
|
|
|
|
if ($emp_value['emp_relationship'] != $excel_data[$key][9]) {
|
|
$errors[$key][] = [
|
|
'row' => $key,
|
|
'column' => 9,
|
|
'db_data' => $emp_value['emp_relationship'],
|
|
'excel_data' => $excel_data[$key][9]
|
|
];
|
|
}
|
|
|
|
if ($emp_value['policy_end_date'] != $excel_data[$key][11]) {
|
|
$errors[$key][] = [
|
|
'row' => $key,
|
|
'column' => 11,
|
|
'db_data' => $emp_value['policy_end_date'],
|
|
'excel_data' => $excel_data[$key][11]
|
|
];
|
|
}
|
|
|
|
if ($emp_value['no_of_days'] != $excel_data[$key][12]) {
|
|
$errors[$key][] = [
|
|
'row' => $key,
|
|
'column' => 12,
|
|
'db_data' => $emp_value['no_of_days'],
|
|
'excel_data' => $excel_data[$key][12]
|
|
];
|
|
}
|
|
|
|
// if ($emp_value['premium'] != $excel_data[$key][17]) {
|
|
// $errors[$key][] = [
|
|
// 'row' => $key,
|
|
// 'column' => 17,
|
|
// 'db_data' => $emp_value['premium'],
|
|
// 'excel_data' => $excel_data[$key][17]
|
|
// ];
|
|
// }
|
|
|
|
if ($emp_value['pro_rata_premium'] != $excel_data[$key][15]) {
|
|
$errors[$key][] = [
|
|
'row' => $key,
|
|
'column' => 15,
|
|
'db_data' => $emp_value['pro_rata_premium'],
|
|
'excel_data' => $excel_data[$key][15]
|
|
];
|
|
}
|
|
|
|
if ($emp_value['gst'] != $excel_data[$key][16]) {
|
|
|
|
$errors[$key][] = [
|
|
'row' => $key,
|
|
'column' => 16,
|
|
'db_data' => $emp_value['gst'],
|
|
'excel_data' => $excel_data[$key][16]
|
|
];
|
|
}
|
|
|
|
if ($insurer_or_tpa == 'tpa') {
|
|
|
|
if ($emp_value['uhid'] != $excel_data[$key][14]) {
|
|
$errors[$key][] = [
|
|
'row' => $key,
|
|
'column' => 14,
|
|
'db_data' => $emp_value['uhid'],
|
|
'excel_data' => $excel_data[$key][14]
|
|
];
|
|
}
|
|
|
|
} else if ($insurer_or_tpa == 'insurer' && in_array($client_policy_data['policy_type_id'], [1,2,3,4,5])) {
|
|
|
|
if ($emp_value['tpa_id'] != $excel_data[$key][13]) {
|
|
$errors[$key][] = [
|
|
'row' => $key,
|
|
'column' => 13,
|
|
'db_data' => $emp_value['tpa_id'],
|
|
'excel_data' => $excel_data[$key][13]
|
|
];
|
|
}
|
|
}
|
|
|
|
$batch_list_id[] = $emp_value['primaryKey'];
|
|
}
|
|
|
|
// dd($errors);
|
|
|
|
$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, $employee_data, $excel_data);
|
|
|
|
if ($missing_id_count > 0) {
|
|
|
|
$data = [
|
|
'error_data' => $json_missing_id,
|
|
'status' => 'failed',
|
|
];
|
|
|
|
$this->batchFileModel->where('id', $file_id)->set($data)->update();
|
|
|
|
if ($insurer_or_tpa == 'tpa') {
|
|
|
|
$file_data = $this->getDataByFileId($file_id, 'failure');
|
|
$this->setPullNotification($file_data);
|
|
|
|
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 ['status' => 'error', 'message' =>'The UHID column is either partially or entirely empty.'];
|
|
}
|
|
}
|
|
|
|
|
|
if ($error_count > 0) {
|
|
|
|
$data = [
|
|
'error_data' => $json_errors,
|
|
'status' => 'failed',
|
|
];
|
|
|
|
$file_data = $this->getDataByFileId($file_id, 'failure');
|
|
$this->setPullNotification($file_data);
|
|
|
|
$this->batchFileModel->where('id', $file_id)->set($data)->update();
|
|
return ['status' => 'error', 'message' => 'Inception File Validation Failed Excel and Database Data are Mismatching'];
|
|
|
|
} else {
|
|
|
|
$data = [
|
|
'count' => $emp_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);
|
|
}
|
|
|
|
|
|
$parameters['file_id'] = $file_id;
|
|
|
|
$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'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
public function importInceptionUpdateTPAandUHID($params)
|
|
{
|
|
|
|
$this->myLogger->logme('error', 'Inception Update TPA and UHID -- Function called');
|
|
|
|
$file_id = $params['file_id'];
|
|
$file = $this->batchFileModel->find((int)$file_id);
|
|
// dd($file);
|
|
|
|
if (!$file) {
|
|
|
|
$data = [
|
|
'status' => 'failed-4',
|
|
];
|
|
|
|
$this->batchFileModel->where('id', (int)$file_id)->set($data)->update();
|
|
$this->myLogger->logme('error', 'Inception Update TPA and UHID -- The Physical file not found -- File id : {data}', ['data' => $file_id]);
|
|
|
|
$file_data = $this->getDataByFileId((int)$file_id, 'failure');
|
|
$this->setPullNotification($file_data);
|
|
|
|
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'];
|
|
$policy_issue_date = $file['policy_issue_date'];
|
|
|
|
$insurer_id = $this->clientPolicyModel->where('id', (int)$client_policy_id)->first();
|
|
|
|
$CD_Account_Number = $this->CDMasterModel
|
|
->where('client_id', (int)$client_id)
|
|
->where('insurer_id', (int)$insurer_id['insurer_id'])
|
|
->first();
|
|
|
|
$get_policy_type = $this->clientPolicyModel
|
|
->select('client_policy.*, policy_type.policy_type')
|
|
->join('policy_type', 'policy_type.id = client_policy.policy_type_id', 'left')
|
|
->where('client_policy.id', (int)$client_policy_id)
|
|
->first();
|
|
|
|
// dd($get_policy_type);
|
|
|
|
$status_val = 'success';
|
|
if ($status == 'in-progress-partially') {
|
|
$status_val = 'partially success';
|
|
}
|
|
|
|
$this->myLogger->logme('error', 'Inception Update TPA and UHID -- file name : {data}', ['data' => $file['file_name']]);
|
|
|
|
$file_name_with_path = storage_ensure_local_file(WRITEPATH . 'uploads/import_excel', $file['file_name']);
|
|
$excel_data = $this->readExcelFileToArray($file_name_with_path);
|
|
unset($excel_data[0]); // Remove header row
|
|
// array_pop($excel_data);
|
|
|
|
$totals = 0;
|
|
$emp_policy_ids = [];
|
|
$emp_details = [];
|
|
$tpa_id = [];
|
|
$uhid = [];
|
|
$emp_endorsement_table_data = [];
|
|
$enrollment_file_id = null;
|
|
$endorsement_id = null;
|
|
$no_of_insured = [];
|
|
$no_of_dependent = [];
|
|
|
|
|
|
$emp_count = count($excel_data);
|
|
$db = \Config\Database::connect();
|
|
|
|
// print_rr($excel_data); die;
|
|
|
|
foreach ($excel_data as $key => $value) {
|
|
|
|
$name = $value[1];
|
|
$emp_code = $value[2];
|
|
$tpa_id[] = $value[13];
|
|
$uhid[] = $value[14];
|
|
$amount = $value[17];
|
|
|
|
if(!empty($name) && !empty($emp_code)){
|
|
|
|
$totals = $totals + floatval($amount);
|
|
|
|
$query = $db->table('employee_polices');
|
|
$query->select('employee_polices.id, employees.id as emp_id, employees.emp_code, employees.name as emp_name, employees.relationship');
|
|
$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') {
|
|
|
|
$query->where('(employee_polices.tpa_id IS NULL OR employee_polices.tpa_id = "")');
|
|
} else if ($file['insurer_or_tpa'] == 'insurer') {
|
|
|
|
$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);
|
|
|
|
$result = $query->get()->getRowArray();
|
|
// Kint::dump($result);
|
|
|
|
if (isset($result['id']) && $result['id'] !== null) {
|
|
$emp_policy_ids[] = $result['id']; //for cash deposite
|
|
$emp_details[] = array('id' => $result['id'], 'tpa_id' => $value[13], 'uhid' => $value[14]);
|
|
if (strtolower($result['relationship']) == 'self') {
|
|
$no_of_insured[] = ['emp_id' => $result['emp_id'], 'emp_code' => $result['emp_code'], 'emp_name' => $result['emp_name'] ];
|
|
}else{
|
|
$no_of_dependent[] = ['emp_id' => $result['emp_id'], 'emp_code' => $result['emp_code'], 'emp_name' => $result['emp_name'] ];
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if(in_array($file['event_type'], ['missed_inception']) && isset($value[18])){
|
|
$endorsement_id = $value[18];
|
|
|
|
$result_for_employees_policy = $this->employeePolicyModel
|
|
->select('employee_polices.*')
|
|
->join('employees', 'employees.id = employee_polices.employee_id')
|
|
->join('emp_endorsement', 'emp_endorsement.pk = employees.id') // assuming this is the correct join
|
|
->where('employees.emp_code', $emp_code)
|
|
->where('employees.name', $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();
|
|
|
|
$enrollment_file_id = $result_for_employees_policy['file_id'] ?? null;
|
|
}
|
|
|
|
//for addition and dependent_addition endorsement , endorsement_id update functionality
|
|
if(in_array($file['event_type'], ['addition', 'dependent_addition']) && isset($value[18])){
|
|
|
|
$action = 'a';
|
|
if($file['event_type'] == "dependent_addition"){
|
|
$action = 'da';
|
|
}
|
|
|
|
$endorsement_id = $value[18];
|
|
|
|
$result_for_endorsement = $this->empEndorsementModel
|
|
->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', $name)
|
|
->where('employees.client_id', $client_id)
|
|
->where('employees.client_branch_id', $client_branch_id)
|
|
->where('emp_endorsement.actions', $action)
|
|
->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();
|
|
|
|
if (!empty($result_for_endorsement) && count($result_for_endorsement)) {
|
|
if(empty($enrollment_file_id)){
|
|
$enrollment_file_id = $result_for_endorsement['file_id']; //files table primary key
|
|
}
|
|
$emp_endorsement_table_data[] = array('id' => $result_for_endorsement['id'], 'group_key' => $result_for_endorsement['group_key'], 'endorsement_id' => $value[18], 'status' => 'complete');
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// dd($emp_endorsement_table_data, $enrollment_file_id, $no_of_insured, $no_of_dependent);
|
|
|
|
//update the employee policy data (TPAID or UHID)
|
|
if(!empty($emp_details)){
|
|
$return = $this->employeePolicyModel->bulkUpdate($emp_details);
|
|
}else{
|
|
$this->batchFileModel->update($file_id, [
|
|
'count' => 0,
|
|
'status' => "failed-6",
|
|
'amount' => 0,
|
|
]);
|
|
return ['status' => 'error', 'message' => 'There is no data to update']; // Return error code
|
|
}
|
|
|
|
if(in_array($file['event_type'], ['addition', 'dependent_addition']) && !empty($emp_endorsement_table_data)){
|
|
$this->employeePolicyModel->updateEmpEndorsementAddition($emp_endorsement_table_data);
|
|
}
|
|
|
|
// Update batch file status and amount
|
|
$this->batchFileModel->update($file_id, [
|
|
'count' => $emp_count,
|
|
'status' => $status_val,
|
|
'amount' => $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]);
|
|
|
|
//get the BASE PREMIUM and GST for BDS Entry
|
|
$base_bremium_and_gst = $this->getInceptionBasePremium($emp_policy_ids);
|
|
$this->myLogger->logme('error', 'Inception Base Premium and GST :'. json_encode($base_bremium_and_gst ?? []));
|
|
|
|
//update CD transaction entry if only insurer
|
|
if ($file['insurer_or_tpa'] == 'insurer') {
|
|
|
|
if(in_array($file['event_type'], ['addition', 'dependent_addition', 'missed_inception'])){
|
|
$this->storeEndorsementNumber($file_id, $endorsement_id, $enrollment_file_id);
|
|
}
|
|
|
|
$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' => $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' => 'cashDepositCalculationForInception', 'payload' => [
|
|
'employeeIds' => $emp_policy_ids,
|
|
'client_id' => $client_id,
|
|
'client_policy_id' => $client_policy_id,
|
|
'cd_ac_no' => $CD_Account_Number['cd_ac_no'] ?? null,
|
|
'endorsement_no' => $endorsement_id,
|
|
'client_branch_id' => $client_branch_id,
|
|
'count' => $emp_count,
|
|
'event_name' => $file['event_type'],
|
|
'policy_name' => $policy_name['policy_name'],
|
|
'user_id' => $user_id,
|
|
'file_id' => $file_id,
|
|
]]);
|
|
|
|
// $r = Jobs::addJob(['job_name' => 'makeEntryForBDSPolicyTransaction', 'payload' => [
|
|
// 'client_policy_id' => $client_policy_id ?? null,
|
|
// 'endorsement_no' => $endorsement_id ?? null,
|
|
// 'emp_count' => $emp_count ?? null,
|
|
// 'action_type' => $file['event_type'] ?? null,
|
|
// 'no_of_insured' => count($no_of_insured ?? []) ?? null,
|
|
// 'no_of_dependent' => count($no_of_dependent ?? []) ?? null,
|
|
// 'base_premium' => $base_bremium_and_gst['base_premium'] ?? null,
|
|
// 'gst' => $base_bremium_and_gst['gst'] ?? null,
|
|
// 'policy_issue_date' => $policy_issue_date ?? null,
|
|
// 'created_by' => $file['created_by'] ?? null,
|
|
// ]]);
|
|
|
|
// $this->cashDepositCalculationForInception($depositeData);
|
|
// $this->sendMailForDownloadingECard($emp_policy_ids);
|
|
|
|
}
|
|
|
|
//send ecard mail if the event is tpa only
|
|
if ($file['insurer_or_tpa'] == 'tpa') {
|
|
|
|
if (in_array($get_policy_type['policy_type_id'], [2, 3])) {
|
|
|
|
// generate e-card and store S3
|
|
$r = Jobs::addJob(['job_name' => 'bulkGenerateEcardAndStoreinS3', 'payload' => ['client_policy_id' => $client_policy_id]]);
|
|
|
|
$job_details = new Jobs();
|
|
$r = Jobs::addJob(['job_name' => 'sendMailForDownloadingECard', 'payload' => ['ids' => $emp_policy_ids, 'client_policy_id' => $client_policy_id]]);
|
|
}
|
|
|
|
}
|
|
|
|
$file_data = $this->getDataByFileId($file_id, 'success');
|
|
$this->setPullNotification($file_data);
|
|
|
|
//import file to upload Google Drive
|
|
// if(excelFileGDriveUpload($file_id, 'batch_file')){
|
|
// $this->myLogger->logme('error', 'Inception Update Google Drive File Upload -- File Uploaded Successfully');
|
|
// }else{
|
|
// $this->myLogger->logme('error', 'Inception Update Google Drive File Upload -- File Uploaded Field');
|
|
// }
|
|
|
|
return 'Import Inception Updated ' . $status_val . '- Updated Count : ' . $emp_count;
|
|
}
|
|
|
|
|
|
|
|
//Endorsement Correction
|
|
public function importCorrectionValidation($params)
|
|
{
|
|
$this->myLogger->logme('error', 'Correction 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'];
|
|
|
|
$ref_data = [
|
|
'client_id' => $client_id,
|
|
'client_policy_id' => $client_policy_id,
|
|
'client_branch_id' => $client_branch_id,
|
|
'insurer_or_tpa' => $file['insurer_or_tpa'],
|
|
'event_type' => $file['event_type'],
|
|
];
|
|
|
|
$file_name_with_path = storage_ensure_local_file(WRITEPATH . 'uploads/import_excel', $file['file_name']);
|
|
|
|
if (empty($file_name_with_path) || !file_exists($file_name_with_path)) {
|
|
|
|
$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';
|
|
}
|
|
|
|
$excel_data = $this->readExcelFileToArray($file_name_with_path);
|
|
$excel_header = $excel_data[0];
|
|
unset($excel_data[0]);
|
|
|
|
$headers = ['Emp Code','RISK ID','NAME OF EMP/DEP','EMP/DEP TYPE','RELATION','DOB','GENDER','Wrong Data','Correct Data','Remarks','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', 'Correction File Validation -- Upload the worng excel file');
|
|
return ['status' => 'error', 'message' => 'Upload the worng excel file'];
|
|
}
|
|
}
|
|
|
|
$endorsement_data = $this->employeePolicyModel->getCorrectionEmployeesDataForExportExcel($ref_data, 1);
|
|
|
|
// 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 importCorrectionUpdateEndorsementID($params)
|
|
{
|
|
|
|
$this->myLogger->logme('error', 'importCorrectionUpdateEndorsementID called');
|
|
|
|
$file_id = (int)$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'];
|
|
$event_type = $file['event_type'];
|
|
$policy_issue_date = $file['policy_issue_date'];
|
|
|
|
$client_policy_data = $this->clientPolicyModel->where('id', $client_policy_id)->first();
|
|
|
|
$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 = storage_ensure_local_file(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 = [];
|
|
$enrollment_file_id = null;
|
|
|
|
$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];
|
|
|
|
$isDate = \DateTime::createFromFormat('d-M-Y', $old_value) && \DateTime::createFromFormat('d-M-Y', $old_value)->format('d-M-Y') === $old_value;
|
|
|
|
if($isDate){
|
|
$old_value = change_date_format($old_value);
|
|
}
|
|
|
|
// dd($old_value, $isDate);
|
|
|
|
$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')
|
|
->where("emp_endorsement.is_active", 1)
|
|
->where("emp_endorsement.status !=", "truncated")
|
|
->first();
|
|
|
|
// print_r($result); die;
|
|
|
|
if (isset($result['id']) && $result['id'] !== null) {
|
|
// return $result;
|
|
if(empty($enrollment_file_id)){
|
|
$enrollment_file_id = $result['file_id'];
|
|
}
|
|
|
|
if($result['field_name'] == 'dob'){
|
|
$value[8] = change_date_format($value[8]);
|
|
}
|
|
// dd($value[8]);
|
|
|
|
$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');
|
|
$endorsement_details[] = array('group_key' => $result['group_key'], 'endorsement_id' => $value[10], 'status' => 'complete');
|
|
}
|
|
|
|
}
|
|
|
|
// return [$emp_details, $endorsement_details];
|
|
|
|
$this->empEndorsementModel->updateBatch($endorsement_details, 'group_key');
|
|
$this->employeePolicyModel->bulkUpdateForCorrection($emp_details);
|
|
$this->storeEndorsementNumber($file_id, $endorsement_id[0], $enrollment_file_id);
|
|
|
|
|
|
// Update batch file status and amount
|
|
$this->batchFileModel->update($file_id, [
|
|
'count' => $emp_count,
|
|
'status' => $status_val,
|
|
]);
|
|
|
|
if(in_array($client_policy_data['policy_type_id'], [2, 3])){
|
|
// re-generate e-card and store S3
|
|
$r = Jobs::addJob(['job_name' => 'bulkGenerateEcardAndStoreinS3', 'payload' => ['client_policy_id' => $client_policy_id]]);
|
|
}
|
|
|
|
$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);
|
|
|
|
// $r = Jobs::addJob(['job_name' => 'makeEntryForBDSPolicyTransaction', 'payload' => [
|
|
// 'client_policy_id' => $client_policy_id ?? null,
|
|
// 'endorsement_no' => $endorsement_id[0] ?? null,
|
|
// 'emp_count' => $emp_count ?? null,
|
|
// 'action_type' => $file['event_type'] ?? null,
|
|
// 'policy_issue_date' => $policy_issue_date ?? null,
|
|
// 'created_by' => $file['created_by'] ?? null,
|
|
// ]]);
|
|
|
|
|
|
//import file to upload Google Drive
|
|
// if(excelFileGDriveUpload($file_id, 'batch_file')){
|
|
// $this->myLogger->logme('error', 'Correction File Update Google Drive File Upload -- File Uploaded Successfully');
|
|
// }else{
|
|
// $this->myLogger->logme('error', 'Correction File Update Google Drive File Upload -- File Uploaded Field');
|
|
// }
|
|
|
|
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'];
|
|
$insurer_or_tpa = $file['insurer_or_tpa'];
|
|
$user_id = $file['created_by'];
|
|
|
|
$ref_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' => $file['event_type'],
|
|
];
|
|
|
|
$client_policy_data = $this->clientPolicyModel->where('id', $client_policy_id)->first();
|
|
|
|
$file_name_with_path = storage_ensure_local_file(WRITEPATH . 'uploads/import_excel', $file['file_name']);
|
|
|
|
if (empty($file_name_with_path) || !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'];
|
|
}
|
|
}
|
|
|
|
$endorsement_data = $this->employeePolicyModel->getSIEnhancementEmployeesDataForExportExcel($ref_data, 1);
|
|
// $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);
|
|
|
|
// ----------------- CD BALANCE CHECK ---------------------------------------------------------------------------
|
|
|
|
$cash_balance = $this->clientDepositModel
|
|
->where('cd_ac_pk', $client_policy_data['cd_ac_pk'])
|
|
->where('is_active', 1)
|
|
->orderBy('id', 'DESC')
|
|
->first();
|
|
|
|
if ($cash_balance == null) {
|
|
$balance = $this->CDMasterModel
|
|
->where('client_id', $file['client_id'])
|
|
->where('insurer_id', $client_policy_data['insurer_id'])
|
|
->where('id', $client_policy_data['cd_ac_pk'])
|
|
->first();
|
|
|
|
$cash_balance['balance'] = $balance['opening_bal'];
|
|
}
|
|
|
|
// Calculate the total amount from the objects
|
|
$totals = 0;
|
|
foreach ($endorsement_data as $item) {
|
|
$totals = $totals + $item['total'];
|
|
}
|
|
|
|
$totals = round($totals, 2);
|
|
|
|
//check CD amt insufficient only insurer, not tpa
|
|
if($file['insurer_or_tpa'] == 'insurer')
|
|
{
|
|
if (!empty($cash_balance)) {
|
|
if ((int) $cash_balance['balance'] < (int) $totals) {
|
|
$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]);
|
|
$this->batchFileModel->where('id', $file_id)->set(['status' => 'failed-7', 'error_data' => 'Insufficient deposit balance. Available CD Balance: ' . $cash_balance['balance'] . ', Excel Total Amount: ' . $totals])->update();
|
|
return ['status' => 'error', 'message' => 'Insufficient deposit balance. Available CD Balance: ' . $cash_balance['balance'] . ', Required Amount: ' . $totals];
|
|
}
|
|
}
|
|
}
|
|
|
|
// ---------------- END CD BALANCE CHECK ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
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_premium'] != $excel_data[$key][16]) {
|
|
$errors[$key][] = [
|
|
'row' => $key,
|
|
'column' => 16,
|
|
'db_data' => $endorsement_value['pro_rata_premium'],
|
|
'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)
|
|
{
|
|
|
|
$this->myLogger->logme('error', 'SI Enhancement Update Endorsement ID -- Function called');
|
|
|
|
$file_id = (int)$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'];
|
|
$policy_issue_date = $file['policy_issue_date'];
|
|
|
|
$insurer_id = $this->clientPolicyModel->where('id', $client_policy_id)->first();
|
|
|
|
$CD_Account_Number = $this->CDMasterModel
|
|
->where('client_id', $client_id)
|
|
->where('insurer_id', $insurer_id['insurer_id'])
|
|
->first();
|
|
|
|
|
|
$status_val = 'success';
|
|
if ($status == 'in-progress-partially') {
|
|
|
|
$status_val = 'partially success';
|
|
}
|
|
|
|
$this->myLogger->logme('error', 'SI Enhancement Update Endorsement ID -- file name : {data}', ['data' => $file['file_name']]);
|
|
|
|
$file_name_with_path = storage_ensure_local_file(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 = '';
|
|
$enrollment_file_id = '';
|
|
$endorsement_details = [];
|
|
$no_of_insured = [];
|
|
$no_of_dependent = [];
|
|
$totals = 0;
|
|
|
|
foreach ($excel_data as $key => $value) {
|
|
|
|
$emp_name = $value[1];
|
|
$emp_code = $value[2];
|
|
$endorsement_id = $value[19];
|
|
$totals += $value[18];
|
|
|
|
|
|
$result = $this->empEndorsementModel
|
|
|
|
->select('
|
|
emp_endorsement.*,
|
|
employees.id as emp_id,
|
|
employees.name as emp_name,
|
|
employees.emp_code,
|
|
employees.relationship,
|
|
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();
|
|
|
|
if (isset($result['id']) && $result['id'] !== null) {
|
|
|
|
if(empty($enrollment_file_id)){
|
|
$enrollment_file_id = $result['file_id'];
|
|
}
|
|
|
|
$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');
|
|
$endorsement_details[] = array('group_key' => $result['group_key'], 'endorsement_id' => $value[19], 'status' => 'complete');
|
|
if (strtolower($result['relationship']) == 'self') {
|
|
$no_of_insured[] = ['emp_id' => $result['emp_id'], 'emp_code' => $result['emp_code'], 'emp_name' => $result['emp_name'] ];
|
|
}else{
|
|
$no_of_dependent[] = ['emp_id' => $result['emp_id'], 'emp_code' => $result['emp_code'], 'emp_name' => $result['emp_name'] ];
|
|
}
|
|
}
|
|
|
|
$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'] = date('Y-m-d', strtotime($value[10])) ?? null;
|
|
$empData['rata_premimum'] = $value[16];
|
|
$empData['gst'] = $value[17];
|
|
$empData['created_by'] = $user_id;
|
|
$empData['old_basic_cover_si'] = $value[9];
|
|
|
|
$emp_details[] = $empData;
|
|
}
|
|
|
|
$rounded_totals = round($totals, 2);
|
|
|
|
// dd($emp_policy_ids, $emp_details, $endorsement_details);
|
|
|
|
if ($file['insurer_or_tpa'] == 'insurer') {
|
|
|
|
$this->employeePolicyModel->updateBatch($emp_policy_ids, 'id');
|
|
|
|
// $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;
|
|
// }
|
|
|
|
// $insertedIds = [];
|
|
// foreach ($emp_details as $emp) {
|
|
|
|
// $old_si_value = $emp['old_basic_cover_si'];
|
|
// $new_si_value = $emp['basic_cover_si'];
|
|
|
|
// if($old_si_value < $new_si_value){
|
|
// $insertedIds['si_adjustment'] = 2;
|
|
// }else{
|
|
// $insertedIds['si_adjustment'] = 1;
|
|
// }
|
|
|
|
// unset($emp['old_basic_cover_si']);
|
|
// $insertedIds['pk'] = $this->employeePolicyModel->insert($emp);
|
|
// }
|
|
|
|
$insertedIds = [];
|
|
foreach ($emp_details as $emp) {
|
|
|
|
$old_si_value = $emp['old_basic_cover_si'];
|
|
$new_si_value = $emp['basic_cover_si'];
|
|
|
|
// Determine SI adjustment type
|
|
$si_adjustment = ($old_si_value < $new_si_value) ? 1 : 2;
|
|
|
|
unset($emp['old_basic_cover_si']);
|
|
|
|
// Insert and store PK with adjustment info
|
|
$pk = $this->employeePolicyModel->insert($emp);
|
|
|
|
$insertedIds[] = [
|
|
'pk' => $pk,
|
|
'si_adjustment' => $si_adjustment
|
|
];
|
|
} // dd($insertedIds);
|
|
|
|
// update si enhancement endorsement complete
|
|
$this->empEndorsementModel->updateBatch($endorsement_details, 'group_key');
|
|
|
|
// $this->employeePolicyModel->bulkUpdateForEndorsement($endorsement_details); // do not remove this
|
|
$this->storeEndorsementNumber($file_id, $endorsement_id, $enrollment_file_id);
|
|
}
|
|
|
|
|
|
// Update batch file status and amount
|
|
$this->batchFileModel->update($file_id, [
|
|
'count' => $emp_count,
|
|
'status' => $status_val,
|
|
'amount' => $rounded_totals,
|
|
]);
|
|
|
|
$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]);
|
|
|
|
//get the BASE PREMIUM and GST for BDS Entry
|
|
$base_bremium_and_gst = $this->getInceptionBasePremium($employeeIds);
|
|
$this->myLogger->logme('error', 'SI Enhancement Base Premium and GST :'. json_encode($base_bremium_and_gst ?? []));
|
|
|
|
|
|
//call the cash deposite function
|
|
if ($file['insurer_or_tpa'] == 'insurer') {
|
|
|
|
$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,
|
|
'cd_ac_no' => $CD_Account_Number['cd_ac_no'] ?? null,
|
|
'endorsement_no' => $endorsement_id ?? null,
|
|
'count' => $emp_count,
|
|
'event_name' => $file['event_type'],
|
|
'policy_name' => $policy_name['policy_name'],
|
|
'user_id' => $user_id,
|
|
'file_id' => $file_id,
|
|
]]);
|
|
|
|
// $r = Jobs::addJob(['job_name' => 'makeEntryForBDSPolicyTransaction', 'payload' => [
|
|
// 'client_policy_id' => $client_policy_id ?? null,
|
|
// 'endorsement_no' => $endorsement_id ?? null,
|
|
// 'emp_count' => $emp_count ?? null,
|
|
// 'action_type' => $file['event_type'] ?? null,
|
|
// 'no_of_insured' => count($no_of_insured ?? []) ?? null,
|
|
// 'no_of_dependent' => count($no_of_dependent ?? []) ?? null,
|
|
// 'base_premium' => $base_bremium_and_gst['base_premium'] ?? null,
|
|
// 'gst' => $base_bremium_and_gst['gst'] ?? null,
|
|
// 'policy_issue_date' => $policy_issue_date ?? null,
|
|
// 'created_by' => $file['created_by'] ?? null,
|
|
// ]]);
|
|
|
|
}
|
|
|
|
$file_data = $this->getDataByFileId($file_id, 'success');
|
|
$this->setPullNotification($file_data);
|
|
|
|
//import file to upload Google Drive
|
|
// if(excelFileGDriveUpload($file_id, 'batch_file')){
|
|
// $this->myLogger->logme('error', 'SI Enhancement File Update Google Drive File Upload -- File Uploaded Successfully');
|
|
// }else{
|
|
// $this->myLogger->logme('error', 'SI Enhancement File Update Google Drive File Upload -- File Uploaded Field');
|
|
// }
|
|
|
|
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();
|
|
|
|
// dd($file);
|
|
|
|
$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'];
|
|
|
|
$ref_data = [
|
|
'client_id' => $client_id,
|
|
'client_policy_id' => $client_policy_id,
|
|
'client_branch_id' => $client_branch_id,
|
|
'insurer_or_tpa' => $file['insurer_or_tpa'],
|
|
'event_type' => $file['event_type'],
|
|
];
|
|
|
|
|
|
$file_name_with_path = storage_ensure_local_file(WRITEPATH . 'uploads/import_excel', $file['file_name']);
|
|
|
|
if (empty($file_name_with_path) || !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]);
|
|
// array_pop($excel_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'];
|
|
// dd($headers, $excel_header);
|
|
|
|
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', 'Deletion File Validation -- Upload the worng excel file');
|
|
return ['status' => 'error', 'message' => 'Upload the worng excel file'];
|
|
}
|
|
}
|
|
|
|
$objects = $this->employeePolicyModel->getDeletionEmployeeDataForExportExcel($ref_data, 1);
|
|
$endorsement_data = $objects;
|
|
|
|
// dd($endorsement_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', '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';
|
|
}
|
|
|
|
}
|
|
|
|
|
|
public function importDeletionUpdateEndorsementID($params)
|
|
{
|
|
|
|
$this->myLogger->logme('error', 'Deletion Update Endorsement ID -- Function called');
|
|
|
|
$file_id = (int)$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'];
|
|
$policy_issue_date = $file['policy_issue_date'];
|
|
|
|
$insurer_id = $this->clientPolicyModel->where('id', $client_policy_id)->first();
|
|
|
|
$CD_Account_Number = $this->CDMasterModel
|
|
->where('client_id', $client_id)
|
|
->where('insurer_id', $insurer_id['insurer_id'])
|
|
->first();
|
|
|
|
|
|
$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 = storage_ensure_local_file(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 = [];
|
|
$endorsement_id = '';
|
|
$enrollment_file_id = null; //files table primary key
|
|
$no_of_insured = [];
|
|
$no_of_dependent = [];
|
|
|
|
$totals = 0;
|
|
|
|
|
|
foreach ($excel_data as $key => $value) {
|
|
|
|
$emp_name = $value[2]; //employee name
|
|
$emp_code = $value[1]; //employee code
|
|
$totals = $totals + $value[13];
|
|
$endorsement_id = $value[15];
|
|
|
|
if(!empty($emp_code) && !empty($emp_name)){
|
|
|
|
$fetch_data = [
|
|
'client_policy_id' => $client_policy_id,
|
|
'client_branch_id' => $client_branch_id,
|
|
'client_id' => $client_id,
|
|
'emp_name' => $emp_name,
|
|
'emp_code' => $emp_code
|
|
];
|
|
|
|
$result = $this->employeePolicyModel->fetchEmpEndorsementData($fetch_data);
|
|
// dd($result, db_connect()->getLastQuery());
|
|
|
|
if (isset($result['emp_endorsement_primarykey']) && $result['emp_endorsement_primarykey'] !== null) {
|
|
|
|
if(empty($enrollment_file_id)){
|
|
$enrollment_file_id = $result['file_id']; //files table primary key
|
|
}
|
|
$employee_policy_table_primaryKey[] = $result['emp_policy_primarykey']; //for cash deposite
|
|
$employee_policy_table_data[] = array('id' => $result['emp_policy_primarykey'], 'date_of_exit' => change_date_format($result['date_of_exit']), 'reason_for_exit' => $result['reason_for_exit'], 'claim_status' => $result['claim_status'], 'status' => $result['status']);
|
|
// $employees_table_data[] = array('id' => $result['employees_id'], 'emp_status' => $result['status']);
|
|
$emp_endorsement_table_data[] = array('id' => $result['emp_endorsement_primarykey'], 'group_key' => $result['group_key'], 'endorsement_id' => $value[15], 'status' => 'complete');
|
|
|
|
if (strtolower($result['relationship']) == 'self') {
|
|
$no_of_insured[] = ['emp_id' => $result['employees_primarykey'], 'emp_code' => $result['emp_code'], 'emp_name' => $result['emp_name'] ];
|
|
}else{
|
|
$no_of_dependent[] = ['emp_id' => $result['employees_primarykey'], 'emp_code' => $result['emp_code'], 'emp_name' => $result['emp_name'] ];
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$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.'];
|
|
// }
|
|
|
|
if ($file['insurer_or_tpa'] == 'insurer') {
|
|
|
|
// Check if $employee_policy_table_data is null or empty
|
|
if (empty($employee_policy_table_data)) {
|
|
$this->batchFileModel->update($file_id, [
|
|
'status' => "failed",
|
|
]);
|
|
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)) {
|
|
$this->batchFileModel->update($file_id, [
|
|
'status' => "failed",
|
|
]);
|
|
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);
|
|
$this->storeEndorsementNumber($file_id, $endorsement_id, $enrollment_file_id);
|
|
}
|
|
|
|
// 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]);
|
|
|
|
$base_bremium_and_gst = $this->getDeletionBasePremium($employee_policy_table_primaryKey, ['client_policy_id' => $client_policy_id]);
|
|
$this->myLogger->logme('error', 'Deletion Base Premium and GST :'. json_encode($base_bremium_and_gst ?? []));
|
|
|
|
//call the cash deposite function
|
|
if ($file['insurer_or_tpa'] == 'insurer') {
|
|
|
|
$policy_name = $this->getPolicyNameUsingClientPolicyId($client_policy_id);
|
|
$job_details = new Jobs();
|
|
|
|
$r = Jobs::addJob(['job_name' => 'visitOffBoard', 'payload' => [
|
|
'memberIds' => $employee_policy_table_primaryKey ?? [],
|
|
'policyNumber' => $policy_name['policy_no'] ?? null ,
|
|
'source' => 'NHANCE'
|
|
]]);
|
|
|
|
$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,
|
|
'cd_ac_no' => $CD_Account_Number['cd_ac_no'] ?? null,
|
|
'endorsement_no' => $endorsement_id ?? null,
|
|
'count' => $emp_count,
|
|
'event_name' => $file['event_type'],
|
|
'policy_name' => $policy_name['policy_name'],
|
|
'user_id' => $user_id,
|
|
'file_id' => $file_id,
|
|
]]);
|
|
|
|
// $r = Jobs::addJob(['job_name' => 'makeEntryForBDSPolicyTransaction', 'payload' => [
|
|
// 'client_policy_id' => $client_policy_id ?? null,
|
|
// 'endorsement_no' => $endorsement_id ?? null,
|
|
// 'emp_count' => $emp_count ?? null,
|
|
// 'action_type' => $file['event_type'] ?? null,
|
|
// 'no_of_insured' => count($no_of_insured ?? []) ?? null,
|
|
// 'no_of_dependent' => count($no_of_dependent ?? []) ?? null,
|
|
// 'base_premium' => $base_bremium_and_gst['base_premium'] ?? null,
|
|
// 'gst' => $base_bremium_and_gst['gst'] ?? null,
|
|
// 'policy_issue_date' => $policy_issue_date ?? null,
|
|
// 'created_by' => $file['created_by'] ?? null,
|
|
// ]]);
|
|
}
|
|
|
|
$file_data = $this->getDataByFileId($file_id, 'success');
|
|
$this->setPullNotification($file_data);
|
|
|
|
//import file to upload Google Drive
|
|
// if(excelFileGDriveUpload($file_id, 'batch_file')){
|
|
// $this->myLogger->logme('error', 'Deletion File Update Google Drive File Upload -- File Uploaded Successfully');
|
|
// }else{
|
|
// $this->myLogger->logme('error', 'Deletion File Update Google Drive File Upload -- File Uploaded Field');
|
|
// }
|
|
|
|
return 'Deletion Update Endorsement ID -- ' . $status_val . '-- Updated Count : ' . $emp_count;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//Endorsement Addition and Dependent Addition
|
|
|
|
//not in use
|
|
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 = storage_ensure_local_file(WRITEPATH . 'uploads/import_excel', $file['file_name']);
|
|
|
|
if (empty($file_name_with_path) || !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 = (int)$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 = storage_ensure_local_file(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;
|
|
|
|
}
|
|
|
|
//end not in use
|
|
|
|
/**
|
|
* 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,
|
|
* - client policy ID,
|
|
* - client ID,
|
|
* - count of employees,
|
|
* - policy_name, and
|
|
* - event type.
|
|
*
|
|
* @return bool Returns true if the operation is successful, otherwise returns 0.
|
|
*/
|
|
|
|
public function cashDepositCalculationForInception($arrayData)
|
|
{
|
|
if (!empty($arrayData)) {
|
|
|
|
|
|
$client_branch_data = $this->clientBranchModel->where('id', $arrayData['client_branch_id'])->first();
|
|
$units = json_decode($client_branch_data['units']);
|
|
|
|
// dd(json_decode($client_branch_data['units']));
|
|
|
|
|
|
foreach($units as $unit)
|
|
{
|
|
$client_policy_id = $arrayData['client_policy_id'];
|
|
$cd_ac_pk = $this->clientPolicyModel->select('cd_ac_pk')->where('id',$client_policy_id)->first();
|
|
$sanitizedIds = array_map('intval', $arrayData['employeeIds']);
|
|
$placeholders = implode(',', array_fill(0, count($sanitizedIds), '?'));
|
|
$amount = $this->employeePolicyModel->query("
|
|
SELECT SUM(rata_premimum + gst) AS total_sum
|
|
FROM employee_polices
|
|
JOIN employees ON employees.id = employee_polices.employee_id
|
|
WHERE employees.unit = ?
|
|
AND employee_polices.id IN ($placeholders)
|
|
", array_merge([$unit], $sanitizedIds))->getRow();
|
|
|
|
if($amount){
|
|
|
|
$insurer_id = $this->clientPolicyModel->where('id', $arrayData['client_policy_id'])->first();
|
|
$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_name']) . ' to ' . remove_underscore_capitalize_first_letter($arrayData['policy_name']) . '.';
|
|
|
|
$data = [
|
|
'amount' => $amount->total_sum ?? 0,
|
|
'sub_type_id' => 4,
|
|
'client_id' => $arrayData['client_id'],
|
|
'client_policy_id' => $arrayData['client_policy_id'],
|
|
'endorsement_no' => $arrayData['endorsement_no'] ?? null,
|
|
'cd_ac_no' => $arrayData['cd_ac_no'] ?? null,
|
|
'insurer_id' => $insurer_id['insurer_id'],
|
|
'unit' => $unit,
|
|
'description' => $description,
|
|
'transaction_type' => 'Debit',
|
|
'updated_by' => $arrayData['user_id'],
|
|
'event_name' => $arrayData['event_name'],
|
|
'is_active' => 1,
|
|
'cd_ac_pk' => $cd_ac_pk['cd_ac_pk'],
|
|
'file_id' => $arrayData['file_id'],
|
|
];
|
|
|
|
$response = DepositHelper::saveDeposit($data, $arrayData['user_id']);
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
|
|
} else {
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
|
|
// public function cashDepositCalculationForSIEnhancement($arrayData)
|
|
// {
|
|
// // return $arrayData;
|
|
|
|
// if (!empty($arrayData)) {
|
|
|
|
// $client_branch_data = $this->clientBranchModel->where('id', $arrayData['client_branch_id'])->first();
|
|
// $units = json_decode($client_branch_data['units']);
|
|
|
|
// foreach($units as $unit)
|
|
// {
|
|
|
|
// $amount = $this->employeePolicyModel->query("
|
|
// SELECT SUM(rata_premimum + gst) AS total_sum
|
|
// FROM employee_polices
|
|
// JOIN employees ON employees.id = employee_polices.employee_id
|
|
// WHERE employees.unit = '$unit'
|
|
// AND employee_polices.id IN (" . implode(',', $arrayData['employeeIds']) . ")
|
|
// ")->getRow();
|
|
|
|
// if($amount){
|
|
|
|
// $insurer_id = $this->clientPolicyModel->where('id', $arrayData['client_policy_id'])->first();
|
|
// $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_name']) . ' to ' . remove_underscore_capitalize_first_letter($arrayData['policy_name']) . '.';
|
|
|
|
// $data = [
|
|
|
|
// 'amount' => $amount->total_sum,
|
|
// 'sub_type_id' => 4,
|
|
// 'client_id' => $arrayData['client_id'],
|
|
// 'client_policy_id' => $arrayData['client_policy_id'],
|
|
// 'endorsement_no' => $arrayData['endorsement_no'] ?? null,
|
|
// 'cd_ac_no' => $arrayData['cd_ac_no'] ?? null,
|
|
// 'insurer_id' => $insurer_id['insurer_id'],
|
|
// 'unit' => $unit,
|
|
// 'description' => $description,
|
|
// 'transaction_type' => 'Debit',
|
|
// 'updated_by' => $arrayData['user_id'],
|
|
// 'event_name' => $arrayData['event_name'],
|
|
// 'is_active' => 1,
|
|
// 'cd_ac_pk' => $insurer_id['cd_ac_pk']
|
|
// ];
|
|
|
|
// $response = DepositHelper::saveDeposit($data, $arrayData['user_id']);
|
|
// }
|
|
// }
|
|
|
|
// $msg = "SI Enhancement Cash Deposite Updated Successfully ";
|
|
// return [$msg];
|
|
|
|
// // print_r($response);
|
|
// // $query = $this->employeePolicyModel->getLastQuery();
|
|
// // echo $query . "<br>";
|
|
|
|
// } else {
|
|
// return 0;
|
|
// }
|
|
// }
|
|
|
|
public function cashDepositCalculationForSIEnhancement($arrayData)
|
|
{
|
|
if (!empty($arrayData)) {
|
|
|
|
$client_branch_data = $this->clientBranchModel->where('id', $arrayData['client_branch_id'])->first();
|
|
$units = json_decode($client_branch_data['units']);
|
|
|
|
foreach ($units as $unit) {
|
|
|
|
$si_enhance_amt = 0;
|
|
$si_decrease_amt = 0;
|
|
|
|
foreach ($arrayData['employeeIds'] as $value) {
|
|
|
|
// If $value is an array, get its elements; otherwise, assign defaults
|
|
$pk = is_array($value) ? ($value['pk'] ?? null) : $value;
|
|
$si_adjustment = is_array($value) ? ($value['si_adjustment'] ?? null) : $value;
|
|
|
|
$query = "
|
|
SELECT SUM(rata_premimum + gst) AS total_sum
|
|
FROM employee_polices
|
|
JOIN employees ON employees.id = employee_polices.employee_id
|
|
WHERE employees.unit = :unit:
|
|
AND employee_polices.id = :pk:
|
|
";
|
|
|
|
$binds = ['unit' => $unit,'pk' => $pk];
|
|
$amount = $this->employeePolicyModel->query($query,$binds)->getRow();
|
|
|
|
if ($amount && $amount->total_sum > 0) {
|
|
if ($si_adjustment == 2) {
|
|
$si_decrease_amt += $amount->total_sum;
|
|
} else {
|
|
$si_enhance_amt += $amount->total_sum;
|
|
}
|
|
}
|
|
}
|
|
|
|
// Save Enhancement amount
|
|
if ($si_enhance_amt > 0) {
|
|
$policy_data = $this->clientPolicyModel->where('id', $arrayData['client_policy_id'])->first();
|
|
|
|
$description = 'An amount of ' . round($si_enhance_amt, 2) .
|
|
' has been debited for ' . $arrayData['count'] . ' employees under ' .
|
|
remove_underscore_capitalize_first_letter($arrayData['event_name']) .
|
|
' in ' . remove_underscore_capitalize_first_letter($arrayData['policy_name']) . '.';
|
|
|
|
$data = [
|
|
'amount' => round($si_enhance_amt, 2),
|
|
'sub_type_id' => 4,
|
|
'client_id' => $arrayData['client_id'],
|
|
'client_policy_id' => $arrayData['client_policy_id'],
|
|
'endorsement_no' => $arrayData['endorsement_no'] ?? null,
|
|
'cd_ac_no' => $arrayData['cd_ac_no'] ?? null,
|
|
'insurer_id' => $policy_data['insurer_id'],
|
|
'unit' => $unit,
|
|
'description' => $description,
|
|
'transaction_type' => 'Debit',
|
|
'updated_by' => $arrayData['user_id'],
|
|
'event_name' => $arrayData['event_name'],
|
|
'is_active' => 1,
|
|
'cd_ac_pk' => $policy_data['cd_ac_pk'],
|
|
'file_id' => $arrayData['file_id'],
|
|
];
|
|
|
|
DepositHelper::saveDeposit($data, $arrayData['user_id']);
|
|
}
|
|
|
|
// Save Decrease amount
|
|
if ($si_decrease_amt > 0) {
|
|
|
|
$policy_data = $this->clientPolicyModel->where('id', $arrayData['client_policy_id'])->first();
|
|
|
|
$description = 'An amount of ' . round($si_decrease_amt, 2) .
|
|
' has been credited for ' . $arrayData['count'] . ' employees due to a decrease in Sum Insured (SI) under ' .
|
|
remove_underscore_capitalize_first_letter($arrayData['event_name']) .
|
|
' in ' . remove_underscore_capitalize_first_letter($arrayData['policy_name']) . '.';
|
|
|
|
$data = [
|
|
'amount' => round($si_decrease_amt, 2),
|
|
'sub_type_id' => 4,
|
|
'client_id' => $arrayData['client_id'],
|
|
'client_policy_id' => $arrayData['client_policy_id'],
|
|
'endorsement_no' => $arrayData['endorsement_no'] ?? null,
|
|
'cd_ac_no' => $arrayData['cd_ac_no'] ?? null,
|
|
'insurer_id' => $policy_data['insurer_id'],
|
|
'unit' => $unit,
|
|
'description' => $description,
|
|
'transaction_type' => 'Credit',
|
|
'updated_by' => $arrayData['user_id'],
|
|
'event_name' => $arrayData['event_name'],
|
|
'is_active' => 1,
|
|
'cd_ac_pk' => $policy_data['cd_ac_pk'],
|
|
'file_id' => $arrayData['file_id'],
|
|
];
|
|
|
|
DepositHelper::saveDeposit($data, $arrayData['user_id']);
|
|
}
|
|
}
|
|
|
|
$msg = "SI Adjustment Cash Deposit Updated Successfully.";
|
|
return [$msg];
|
|
} else {
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
|
|
public function cashDepositCalculationForDeletion($arrayData)
|
|
{
|
|
// print_r($arrayData);
|
|
if (!empty($arrayData)) {
|
|
|
|
// dd($arrayData);
|
|
|
|
// echo '<pre>';
|
|
// print_r($arrayData); die;
|
|
|
|
$client_branch_data = $this->clientBranchModel->where('id', $arrayData['client_branch_id'])->first();
|
|
$units = json_decode($client_branch_data['units']);
|
|
|
|
// dd($client_branch_data, $units);
|
|
|
|
$get_insurer_id_from_client_policy = db_connect()->table('client_policy')
|
|
->select('insurer_id,cd_ac_pk')
|
|
->where('id', $arrayData['client_policy_id'])
|
|
->get()
|
|
->getRowArray();
|
|
|
|
// dd($get_insurer_id_from_client_policy);
|
|
|
|
$add_one_day = 0;
|
|
|
|
if (!empty($get_insurer_id_from_client_policy)) {
|
|
|
|
$get_the_insurer_add_one_for_delete = db_connect()
|
|
->table('insurers')
|
|
->select('deletion_add_day')
|
|
->where('id', $get_insurer_id_from_client_policy['insurer_id'])
|
|
->get()
|
|
->getRowArray();
|
|
|
|
// dd($get_the_insurer_add_one_for_delete, $get_the_insurer_add_one_for_delete['deletion_add_day']);
|
|
|
|
if (!empty($get_the_insurer_add_one_for_delete) && $get_the_insurer_add_one_for_delete['deletion_add_day'] == 1) {
|
|
$add_one_day = 1;
|
|
}
|
|
}
|
|
|
|
// dd($add_one_day);
|
|
|
|
foreach($units as $unit) {
|
|
|
|
// $amount = $this->employeePolicyModel->query("
|
|
// SELECT SUM(rata_premimum + gst) AS total_sum
|
|
// FROM employee_polices
|
|
// JOIN employees ON employees.id = employee_polices.employee_id
|
|
// WHERE employees.unit = '$unit'
|
|
// AND employee_polices.id IN (" . implode(',', $arrayData['employeeIds']) . ")
|
|
// ")->getRow();
|
|
|
|
$sanitizedIds = array_map('intval', $arrayData['employeeIds']);
|
|
$placeholders = implode(',', array_fill(0, count($sanitizedIds), '?'));
|
|
$safeAddOneDay = (int)$add_one_day;
|
|
$amount = $this->employeePolicyModel->query("
|
|
SELECT
|
|
SUM(ROUND(
|
|
((employee_polices.rata_premimum * (DATEDIFF(employee_polices.policy_end_date, emp_endorsement.new_value) + ?)) / 365) +
|
|
(((employee_polices.rata_premimum * (DATEDIFF(employee_polices.policy_end_date, emp_endorsement.new_value) + ?)) / 365) * 0.18),
|
|
2
|
|
)) AS total_sum
|
|
FROM
|
|
employee_polices
|
|
JOIN
|
|
employees ON employees.id = employee_polices.employee_id
|
|
JOIN
|
|
emp_endorsement ON emp_endorsement.pk = employee_polices.id
|
|
WHERE
|
|
employee_polices.id IN ($placeholders)
|
|
AND emp_endorsement.pk IN ($placeholders)
|
|
AND employee_polices.claim_status = 0
|
|
AND emp_endorsement.field_name = 'date_of_exit'
|
|
AND emp_endorsement.is_active = 1
|
|
AND emp_endorsement.actions = 'd'
|
|
AND emp_endorsement.status != 'truncated'
|
|
", array_merge([$safeAddOneDay, $safeAddOneDay], $sanitizedIds, $sanitizedIds))->getRow();
|
|
|
|
// dd(db_connect()->getLastQuery(), $amount);
|
|
|
|
if($amount){
|
|
|
|
$insurer_id = $this->clientPolicyModel->where('id', $arrayData['client_policy_id'])->first();
|
|
$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_name']) . ' to ' . remove_underscore_capitalize_first_letter($arrayData['policy_name']) . '.';
|
|
|
|
$data = [
|
|
|
|
'amount' => $amount->total_sum,
|
|
'sub_type_id' => 3,
|
|
'client_id' => $arrayData['client_id'],
|
|
'client_policy_id' => $arrayData['client_policy_id'],
|
|
'endorsement_no' => $arrayData['endorsement_no'] ?? null,
|
|
'cd_ac_no' => $arrayData['cd_ac_no'] ?? null,
|
|
'insurer_id' => $insurer_id['insurer_id'],
|
|
'description' => $description,
|
|
'transaction_type' => 'Credit',
|
|
'updated_by' => $arrayData['user_id'],
|
|
'event_name' => $arrayData['event_name'],
|
|
'is_active' => 1,
|
|
'cd_ac_pk' => $insurer_id['cd_ac_pk'],
|
|
'file_id' => $arrayData['file_id'],
|
|
];
|
|
|
|
$response = DepositHelper::saveDeposit($data, $arrayData['user_id']);
|
|
}
|
|
}
|
|
|
|
$msg = "Deletion Cash Deposite Updated Successfully -- ";
|
|
return [$msg];
|
|
// print_r($response);
|
|
// $query = $this->employeePolicyModel->getLastQuery();
|
|
// echo $query . "<br>";
|
|
|
|
} else {
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
* Below function retrieves the policy name associated with a given client policy ID.
|
|
*
|
|
* @param int $client_policy_id The ID of the client policy.
|
|
* @return mixed Returns the policy name if found, otherwise null.
|
|
*/
|
|
|
|
public function getPolicyNameUsingClientPolicyId($client_policy_id)
|
|
{
|
|
return $this->clientPolicyModel->select('policy_type.policy_type as policy_name, client_policy.policy_no')
|
|
->join('policy_type', 'policy_type.id = client_policy.policy_type_id')
|
|
->where('client_policy.id', $client_policy_id)
|
|
->first();
|
|
}
|
|
|
|
|
|
/**
|
|
* Below function converts row data into column data format for SI enhancement.
|
|
*
|
|
* This function takes an array of data containing information about SI enhancement
|
|
* and calculates additional fields such as pro rata premium, GST, and total.
|
|
*
|
|
* @param array $data The array of data containing SI enhancement information.
|
|
* @return array Returns the converted data in column format.
|
|
*/
|
|
public function convertRowTColumnForSIEnhancement($data)
|
|
{
|
|
|
|
$result = array();
|
|
|
|
foreach ($data as $obj) {
|
|
|
|
$pro_rata_premium = round(($obj->difference_premium * $obj->no_of_days / 365), 2);
|
|
$gst = round(($pro_rata_premium * 18 / 100), 2);
|
|
$total = round(($pro_rata_premium + $gst), 2);
|
|
|
|
$old_total = round(($obj->old_rata + $obj->old_gst), 2);
|
|
|
|
|
|
$result[] = array(
|
|
"field_name" => 'Basic Cover SI',
|
|
"old_value" => $obj->old_basic_cover_si,
|
|
"new_value" => $obj->new_basic_cover_si
|
|
);
|
|
|
|
$result[] = array(
|
|
"field_name" => 'Premium',
|
|
"old_value" => $obj->old_si_premium,
|
|
"new_value" => $obj->new_si_premium
|
|
);
|
|
|
|
$result[] = array(
|
|
"field_name" => 'SI Enhancement Date',
|
|
"old_value" => change_date_format($obj->old_date, 'Y-m-d', 'd-M-Y'),
|
|
"new_value" => change_date_format($obj->date_of_coverage, 'Y-m-d', 'd-M-Y')
|
|
);
|
|
|
|
$result[] = array(
|
|
"field_name" => 'Difference Premium',
|
|
"old_value" => ' --- ',
|
|
"new_value" => $obj->difference_premium
|
|
);
|
|
|
|
$result[] = array(
|
|
"field_name" => 'No of Days',
|
|
"old_value" => $obj->old_days,
|
|
"new_value" => $obj->no_of_days
|
|
);
|
|
|
|
$result[] = array(
|
|
"field_name" => 'Pro Rata Premium',
|
|
"old_value" => $obj->old_rata,
|
|
"new_value" => $pro_rata_premium
|
|
);
|
|
|
|
$result[] = array(
|
|
"field_name" => 'GST(18%)',
|
|
"old_value" => $obj->old_gst,
|
|
"new_value" => $gst
|
|
);
|
|
|
|
$result[] = array(
|
|
"field_name" => 'Total',
|
|
"old_value" => $old_total,
|
|
"new_value" => $total
|
|
);
|
|
}
|
|
|
|
return $result;
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
* Below function converts row data into column data format for deletion records.
|
|
*
|
|
* This function takes an array of data containing information about deletion records
|
|
* and converts it into a column format. It also calculates additional fields such as
|
|
* period of non-coverage, premium for non-coverage period, GST, total amount, and
|
|
* claim status based on the exist_reason field.
|
|
*
|
|
* @param array $data The array of data containing deletion records information.
|
|
* @return array Returns the converted data in column format.
|
|
*/
|
|
public function convertRowTColumnForDeletion($data)
|
|
{
|
|
|
|
$result = array();
|
|
|
|
foreach ($data as $obj) {
|
|
|
|
$old_total = round(($obj->old_rata + $obj->old_gst), 2);
|
|
|
|
$result[] = array(
|
|
"field_name" => 'Policy Period',
|
|
"data" => change_date_format($obj->start_date, 'Y-m-d', 'd-M-Y') . ' - <br> ' . change_date_format($obj->end_date, 'Y-m-d', 'd-M-Y'),
|
|
);
|
|
|
|
$result[] = array(
|
|
"field_name" => 'Exit on',
|
|
"data" => change_date_format($obj->dateofexit, 'Y-m-d', 'd-M-Y'),
|
|
);
|
|
|
|
$result[] = array(
|
|
"field_name" => 'Reason',
|
|
"data" => $obj->exist_reason,
|
|
);
|
|
|
|
|
|
|
|
if ($obj->exist_reason != 'death') {
|
|
|
|
$result[] = array(
|
|
"field_name" => 'Period of non coverage',
|
|
"data" => $obj->no_of_days
|
|
);
|
|
|
|
$result[] = array(
|
|
"field_name" => 'Premium for non coverage period',
|
|
"data" => $obj->pro_rata_premium
|
|
);
|
|
|
|
$result[] = array(
|
|
"field_name" => 'GST(18%)',
|
|
"data" => $obj->gst
|
|
);
|
|
|
|
$result[] = array(
|
|
"field_name" => 'Total Amount',
|
|
"data" => $obj->total
|
|
);
|
|
|
|
$result[] = array(
|
|
"field_name" => 'Claim',
|
|
"data" => '---',
|
|
);
|
|
}
|
|
}
|
|
|
|
return $result;
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------------
|
|
|
|
|
|
public function readExcelToArray($file)
|
|
{
|
|
if ($file->isValid() && !$file->hasMoved()) {
|
|
$file = $file;
|
|
|
|
try {
|
|
|
|
$reader = IOFactory::createReaderForFile($file->getPathname());
|
|
$spreadsheet = $reader->load($file->getPathname());
|
|
|
|
// Get the active sheet
|
|
$sheet = $spreadsheet->getActiveSheet();
|
|
|
|
// Iterate through rows to read data
|
|
$data = [];
|
|
foreach ($sheet->getRowIterator() as $row) {
|
|
$rowData = [];
|
|
foreach ($row->getCellIterator() as $cell) {
|
|
$rowData[] = $cell->getValue();
|
|
}
|
|
$data[] = $rowData;
|
|
}
|
|
|
|
return $data;
|
|
} catch (SpreadsheetReaderException $e) {
|
|
|
|
error_log('PhpSpreadsheet reader exception: ' . $e->getMessage());
|
|
return false;
|
|
}
|
|
} else {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public function insertBatchFileAndBatchListForImportExcel($data, $ids)
|
|
{
|
|
|
|
$random_number_count = 4;
|
|
$data['batch_code'] = generate_random_string($random_number_count);
|
|
$data['created_by'] = get_session_userid();
|
|
|
|
$insert = $this->batchFileModel->insert($data);
|
|
$batch_file_batch_code = $this->batchFileModel->where('id', $insert)->first();
|
|
|
|
if ($insert) {
|
|
foreach ($ids as $id) {
|
|
$batch_list_data['batch_code'] = $batch_file_batch_code['batch_code'];
|
|
$batch_list_data['emp_policy_id'] = $id;
|
|
$batch_list_data['created_by'] = get_session_userid();
|
|
$this->batchListModel->insert($batch_list_data);
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
public function sendMailForDownloadingECard($params, $single_mail = null)
|
|
{
|
|
// dd($params);
|
|
$this->myLogger->logme('info', 'sendMailForDownloadingECard - Function called');
|
|
|
|
$ids = $params['ids'] ?? null;
|
|
$client_policy_id = $params['client_policy_id'] ?? null;
|
|
|
|
if (empty($ids)) {
|
|
$this->myLogger->logme('error', 'sendMailForDownloadingECard - employee_policy_ids are empty');
|
|
return ['status' => false , 'message' => 'employee_policy_ids are empty'];
|
|
}
|
|
|
|
if (empty($client_policy_id)) {
|
|
$this->myLogger->logme('error', 'sendMailForDownloadingECard - client_policy_id are empty');
|
|
return ['status' => false , 'message' => 'client_policy_id are empty'];
|
|
}
|
|
|
|
$temp_id = $ids[0];
|
|
|
|
$get_client_info = $this->employeePolicyModel
|
|
->select('
|
|
employee_polices.client_policy_id,
|
|
employees.emp_code,
|
|
employees.email_corporate,
|
|
employees.client_id,
|
|
employees.name,
|
|
employee_polices.rand_string,
|
|
employee_polices.tpa_id'
|
|
)
|
|
->join('employees', 'employees.id = employee_polices.employee_id')
|
|
->where('employees.emp_status', 'active')
|
|
->where('employees.is_active', '1')
|
|
->where('employee_polices.status', 'active')
|
|
->where('employee_polices.is_active', '1')
|
|
->where('employee_polices.id', $temp_id)
|
|
->first();
|
|
|
|
if (!$get_client_info) {
|
|
$this->myLogger->logme('error', 'sendMailForDownloadingECard - No client information found for the first ID');
|
|
return ['status' => false , 'message' => 'No client information found for the first ID'];
|
|
}
|
|
|
|
$client_data = $this->clientModel->where('id', $get_client_info['client_id'])->first();
|
|
|
|
$notification = $this->notificationModel
|
|
->where('client_id', $get_client_info['client_id'])
|
|
->where('template_name', 'member_ecard_mail')
|
|
->first();
|
|
|
|
if (empty($notification) || $notification['enabled'] != 1) {
|
|
$this->myLogger->logme('error', 'sendMailForDownloadingECard - Notification setup not enabled or missing for E-Card Notification');
|
|
return ['status' => false , 'message' => 'Notification setup not enabled or missing for E-Card Notification'];
|
|
}
|
|
|
|
$client_policy_data = $this->clientPolicyModel->where('id', $client_policy_id)->first();
|
|
// print_rr($client_policy_data); die;
|
|
|
|
// this for handle the GMC - Parants to send the E-Card mail
|
|
if($client_policy_data['policy_type_id'] == 3 && $client_policy_data['is_addon'] == 3){
|
|
|
|
$this->myLogger->logme('error', 'sendMailForDownloadingECard - Processing the GMC - Patents E-Card Mail send');
|
|
|
|
try {
|
|
|
|
$emp_details = $this->employeePolicyModel
|
|
->select("
|
|
employees.id as emp_id,
|
|
employees.client_id,
|
|
employees.client_branch_id,
|
|
employees.relationship,
|
|
employees.emp_code,
|
|
employees.email_corporate,
|
|
employees.name,
|
|
employees.mobile,
|
|
employee_polices.basic_cover_si,
|
|
|
|
(
|
|
SELECT self_data.email_corporate
|
|
FROM employees AS self_data
|
|
WHERE self_data.is_active = 1
|
|
AND self_data.emp_status = 'active'
|
|
AND self_data.family_floater_key = 'self'
|
|
AND self_data.emp_code = employees.emp_code
|
|
LIMIT 1
|
|
) AS self_mail,
|
|
|
|
cp.policy_type_id,
|
|
cp.is_addon,
|
|
cp.policy_no,
|
|
|
|
employee_polices.id as emp_policy_id,
|
|
employee_polices.client_policy_id,
|
|
employee_polices.rand_string,
|
|
employee_polices.tpa_id
|
|
")
|
|
->join('employees', 'employees.id = employee_polices.employee_id')
|
|
->join('client_policy cp', 'employee_polices.client_policy_id = cp.id')
|
|
->where('employees.emp_status', 'active')
|
|
->where('employees.is_active', 1)
|
|
->where('employee_polices.status', 'active')
|
|
->where('employee_polices.is_active', 1)
|
|
->whereIn('employee_polices.id', $ids)
|
|
->groupBy('employees.emp_code')
|
|
->findAll();
|
|
|
|
// dd($emp_details);
|
|
|
|
if (!empty($emp_details)) {
|
|
|
|
$count = 0;
|
|
$processedCount = 0;
|
|
$wholeData = [];
|
|
|
|
foreach ($emp_details as $emp_value) {
|
|
|
|
$this->myLogger->logme('error', 'sendMailForDownloadingECard - Processing send mail for the employee_policy_id: {id}', ['id' => $emp_value['emp_policy_id']]);
|
|
|
|
if (!empty($emp_value['self_mail'])) {
|
|
|
|
$params = [
|
|
'rand_string' => $emp_value['rand_string'],
|
|
'tpa_id' => $emp_value['tpa_id'],
|
|
'notification' => $notification,
|
|
'client_data' => $client_data,
|
|
'get_emp_email_and_other_details' => $emp_value,
|
|
|
|
'id' => $emp_value['emp_id'],
|
|
'emp_code' => $emp_value['emp_code'],
|
|
'policy_no' => $emp_value['policy_no'],
|
|
'client_policy_id' => $emp_value['client_policy_id'],
|
|
];
|
|
|
|
if(empty($single_mail)){
|
|
$params['all_member'] = 1;
|
|
}
|
|
|
|
$params['common'] = [
|
|
'client_id' => $emp_value['client_id'],
|
|
'client_branch_id' => $emp_value['client_branch_id'],
|
|
'client_policy_id' => $emp_value['client_policy_id'],
|
|
'employee_policy_id' => $emp_value['emp_policy_id'],
|
|
'employee_id' => $emp_value['emp_id'],
|
|
'mail_type' => 'member_ecard_mail',
|
|
];
|
|
|
|
$wholeData[] = sendMailNotification::sendMailNotification('member_ecard_mail', $params);
|
|
$count++;
|
|
|
|
}else{
|
|
$this->myLogger->logme('error', 'sendMailForDownloadingECard - process skiped - self mail not found for the dependent employee_policy_id: {id}', ['id' => $emp_value['emp_policy_id']]);
|
|
}
|
|
|
|
$processedCount++;
|
|
|
|
// Send batch emails or handle single email
|
|
if ($count == 20 || $processedCount == count($emp_details)) {
|
|
if (!empty($wholeData)) {
|
|
if ($single_mail == 1) {
|
|
$this->myLogger->logme('error', 'sendMailForDownloadingECard - Sending single mail');
|
|
$mail_result = MailHelper::send_email($wholeData[0]);
|
|
$this->myLogger->logme('info', 'sendMailForDownloadingECard - Single mail result: {result}', ['result' => $mail_result]);
|
|
return ['status' => true , 'data' =>$mail_result, 'message' => 'Email processing completed'];
|
|
} else {
|
|
$this->myLogger->logme('error', 'sendMailForDownloadingECard - Creating a job for bulk mail');
|
|
Jobs::addJob(['job_name' => 'bulk_mail', 'payload' => $wholeData]);
|
|
$wholeData = [];
|
|
$count = 0;
|
|
}
|
|
}else{
|
|
$this->myLogger->logme('error', 'sendMailForDownloadingECard - Whole mail data is empty');
|
|
}
|
|
}else{
|
|
$idscount = count($ids);
|
|
$this->myLogger->logme('error', "sendMailForDownloadingECard - processedCount not equal to ids count, processedCount : {$processedCount} and ids count : {$idscount}");
|
|
}
|
|
|
|
}
|
|
|
|
$this->myLogger->logme('error', 'sendMailForDownloadingECard - Email processing completed');
|
|
return ['status' => true , 'message' => 'Email processing completed'];
|
|
|
|
}else{
|
|
$this->myLogger->logme('error', 'sendMailForDownloadingECard - Employee Data not found');
|
|
return ['status' => false , 'message' => 'Employee Data not found'];
|
|
}
|
|
|
|
} catch (\Exception $th) {
|
|
$errorData = [
|
|
'message' => $th->getMessage(),
|
|
'file' => $th->getFile(),
|
|
'line' => $th->getLine(),
|
|
'code' => $th->getCode(),
|
|
'trace' => $th->getTraceAsString(),
|
|
'trace_array' => $th->getTrace(), // full array version (optional)
|
|
'function' => $th->getTrace()[0]['function'] ?? null,
|
|
'class' => $th->getTrace()[0]['class'] ?? null,
|
|
];
|
|
$this->myLogger->logme('error', 'sendMailForDownloadingECard - Exception occurred: {message}', ['message' => $th->getMessage()]);
|
|
return ['status' => false , 'message' => 'Exception occurred' . $th->getMessage(), 'error_data' => $errorData];
|
|
}
|
|
|
|
}
|
|
|
|
try {
|
|
$this->myLogger->logme('error', 'sendMailForDownloadingECard - Inside try block');
|
|
|
|
$count = 0;
|
|
$processedCount = 0;
|
|
$wholeData = [];
|
|
// $wholeMailData = [];
|
|
|
|
foreach ($ids as $id) {
|
|
|
|
$emp_details = $this->employeePolicyModel
|
|
->select('
|
|
employees.id as emp_id,
|
|
employees.client_id,
|
|
employees.client_branch_id,
|
|
employees.relationship,
|
|
employees.emp_code,
|
|
employees.email_corporate,
|
|
employees.name,
|
|
employees.mobile,
|
|
employee_polices.basic_cover_si,
|
|
|
|
cp.policy_type_id,
|
|
cp.is_addon,
|
|
cp.policy_no,
|
|
|
|
employee_polices.id as emp_policy_id,
|
|
employee_polices.client_policy_id,
|
|
employee_polices.rand_string,
|
|
employee_polices.tpa_id
|
|
')
|
|
->join('employees', 'employees.id = employee_polices.employee_id')
|
|
->join('client_policy cp', 'employee_polices.client_policy_id = cp.id')
|
|
->where('employees.emp_status', 'active')
|
|
->where('employees.is_active', '1')
|
|
->where('employee_polices.status', 'active')
|
|
->where('employee_polices.is_active', '1')
|
|
->where('employee_polices.id', $id)
|
|
->first();
|
|
|
|
if ($emp_details) {
|
|
$this->myLogger->logme('error', 'sendMailForDownloadingECard - Processing employee_policy_id: {id}', ['id' => $id]);
|
|
|
|
if (!empty($emp_details['email_corporate']) && $emp_details['relationship'] === 'Self') {
|
|
|
|
$params = [
|
|
'rand_string' => $emp_details['rand_string'],
|
|
'tpa_id' => $emp_details['tpa_id'],
|
|
'notification' => $notification,
|
|
'client_data' => $client_data,
|
|
'get_emp_email_and_other_details' => $emp_details,
|
|
|
|
'id' => $emp_details['emp_id'],
|
|
'emp_code' => $emp_details['emp_code'],
|
|
'policy_no' => $emp_details['policy_no'],
|
|
'client_policy_id' => $emp_details['client_policy_id'],
|
|
];
|
|
|
|
if(empty($single_mail)){
|
|
$params['all_member'] = 1;
|
|
}
|
|
|
|
$params['common'] = [
|
|
'client_id' => $emp_details['client_id'],
|
|
'client_branch_id' => $emp_details['client_branch_id'],
|
|
'client_policy_id' => $emp_details['client_policy_id'],
|
|
'employee_policy_id' => $emp_details['emp_policy_id'],
|
|
'employee_id' => $emp_details['emp_id'],
|
|
'mail_type' => 'member_ecard_mail',
|
|
];
|
|
|
|
$wholeData[] = sendMailNotification::sendMailNotification('member_ecard_mail', $params);
|
|
// $wholeMailData[] = sendMailNotification::sendMailNotification('member_ecard_mail', $params);
|
|
$count++;
|
|
}else{
|
|
$this->myLogger->logme('error', 'sendMailForDownloadingECard - process skiped - Self not found : {id}', ['id' => $id]);
|
|
}
|
|
|
|
$processedCount++;
|
|
|
|
// Send batch emails or handle single email
|
|
if ($count == 20 || $processedCount == count($ids)) {
|
|
if (!empty($wholeData)) {
|
|
if ($single_mail == 1) {
|
|
$this->myLogger->logme('error', 'sendMailForDownloadingECard - Sending single mail');
|
|
$mail_result = MailHelper::send_email($wholeData[0]);
|
|
$this->myLogger->logme('info', 'sendMailForDownloadingECard - Single mail result: {result}', ['result' => $mail_result]);
|
|
return ['status' => true , 'data' =>$mail_result, 'message' => 'Email processing completed'];
|
|
} else {
|
|
$this->myLogger->logme('error', 'sendMailForDownloadingECard - Creating a job for bulk mail');
|
|
Jobs::addJob(['job_name' => 'bulk_mail', 'payload' => $wholeData]);
|
|
$wholeData = [];
|
|
$count = 0;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// dd($wholeMailData);
|
|
|
|
$this->myLogger->logme('error', 'sendMailForDownloadingECard - Email processing completed');
|
|
return ['status' => true , 'message' => 'Email processing completed'];
|
|
|
|
} catch (\Exception $e) {
|
|
$this->myLogger->logme('error', 'sendMailForDownloadingECard - Exception occurred: {message}', ['message' => $e->getMessage()]);
|
|
return ['status' => false , 'message' => 'Exception occurred' . $e->getMessage()];
|
|
}
|
|
}
|
|
|
|
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']);
|
|
|
|
// 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)
|
|
{
|
|
|
|
$client_id = $params['client_id'];
|
|
$client_policy_id = $params['client_policy_id'];
|
|
$insurer_or_tpa = $params['insurer_or_tpa'];
|
|
$event_type = $params['event_type'];
|
|
$actions = $params['actions'];
|
|
|
|
|
|
$batch_data = $this->batchFileModel
|
|
->where('client_id', $client_id)
|
|
->where('client_policy_id', $client_policy_id)
|
|
->where('insurer_or_tpa', $insurer_or_tpa)
|
|
->where('event_type', $event_type)
|
|
->where('actions', $actions)
|
|
->first();
|
|
|
|
if(!empty($batch_data)){
|
|
|
|
$id = $batch_data['id'];
|
|
$batch_code = $batch_data['batch_code'];
|
|
$this->batchFileModel->where('id', $id)->delete();
|
|
$this->batchListModel->where('batch_code', $batch_code)->delete();
|
|
}
|
|
}
|
|
|
|
public function getDataByFileId($file_id, $status = 'success')
|
|
{
|
|
$data = $this->batchFileModel
|
|
->select('batch_files.*, clients.client_name, clients.short_name, policy_type.policy_type 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('policy_type', 'policy_type.id = client_policy.policy_type_id')
|
|
->where('batch_files.id', $file_id)
|
|
->first();
|
|
|
|
if($status == 'success'){
|
|
|
|
$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['client_name'] . '( ' . $data['branch_name'] . ' )' . ' - ' . $data['policy_name'] . ' - ' . $data['event_type'] . ' - ' . $data['actions'] . ' - ' . $data['insurer_or_tpa'];
|
|
$msg_title = 'File Upload Failure';
|
|
}
|
|
|
|
$user_id = $data['created_by'];
|
|
$url = 'employee/upload#KYC-DOC-tab';
|
|
|
|
return ['msg_txt' => $msg_txt, 'user_id' => $user_id, 'url' => $url, 'status' => $status, 'title' => $msg_title];
|
|
}
|
|
|
|
public function setPullNotification($data)
|
|
{
|
|
$array = ['message_text' => $data['msg_txt'], 'action_url' => $data['url'], 'msg_status' => $data['status'], 'msg_title' => $data['title']];
|
|
$jsonEncodeData = json_encode($array);
|
|
|
|
$msg_data = [
|
|
|
|
'message_text' => $jsonEncodeData,
|
|
'user_id' => $data['user_id'],
|
|
'role_id' => NULL,
|
|
'team_id' => NULL,
|
|
'message_type' => '1to1',
|
|
];
|
|
|
|
$this->messageModel->insert($msg_data);
|
|
}
|
|
|
|
public function storeEndorsementNumber($file_id, $endorsement_no, $enrollment_file_id)
|
|
{
|
|
// Log the function entry with input parameters
|
|
$this->myLogger->logme('error', "storeEndorsementNumber --- Starting function with file_id: $file_id and endorsement_no: $endorsement_no");
|
|
|
|
// Log before querying the database
|
|
$this->myLogger->logme('error', "storeEndorsementNumber --- Fetching file data for file_id: $file_id");
|
|
|
|
$filedata = $this->batchFileModel
|
|
->select('
|
|
batch_files.client_id,
|
|
batch_files.client_policy_id,
|
|
batch_files.event_type, .
|
|
batch_files.created_by,
|
|
client_policy.insurer_id,
|
|
client_policy.tpa_id
|
|
')
|
|
->join('client_policy', 'batch_files.client_policy_id = client_policy.id')
|
|
->where('batch_files.id', $file_id)
|
|
->first();
|
|
|
|
// dd($filedata);
|
|
|
|
// Log after fetching data
|
|
if ($filedata) {
|
|
$this->myLogger->logme('error', 'File data fetched successfully: ' . json_encode($filedata));
|
|
|
|
// Log before inserting data
|
|
$this->myLogger->logme('error', 'storeEndorsementNumber --- Inserting endorsement data into endorsementModel');
|
|
|
|
$this->endorsementModel->insert([
|
|
'client_id' => $filedata['client_id'],
|
|
'client_policy_id' => $filedata['client_policy_id'],
|
|
'insurer_id' => $filedata['insurer_id'],
|
|
'tpa_id' => $filedata['tpa_id'],
|
|
'endorsement_no' => $endorsement_no,
|
|
'file_id' => $enrollment_file_id,
|
|
'batch_file_id' => $file_id,
|
|
'endorsement_type' => $filedata['event_type'],
|
|
'created_by' => $filedata['created_by'],
|
|
]);
|
|
|
|
// Log after data insertion
|
|
$this->myLogger->logme('error', 'storeEndorsementNumber --- Endorsement data inserted successfully for file_id: ' . $file_id);
|
|
} else {
|
|
// Log if no file data is found
|
|
$this->myLogger->logme('error', "storeEndorsementNumber --- No file data found for file_id: $file_id");
|
|
}
|
|
|
|
// Log function exit
|
|
$this->myLogger->logme('error',"storeEndorsementNumber --- Function execution completed for file_id: $file_id");
|
|
}
|
|
|
|
// --------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
public function makeEntryForBDSPolicyTransaction($params)
|
|
{
|
|
try {
|
|
|
|
$this->myLogger->logme("error", "makeEntryForBDSPolicyTransaction() started: " . json_encode(['params' => $params]));
|
|
|
|
if (empty($params) || !isset($params['client_policy_id']) || empty($params['client_policy_id'])) {
|
|
$this->myLogger->logme("error", "Invalid parameters provided: " . json_encode(['params' => $params]));
|
|
return ['status' => "Failed", 'message' => "Client Policy ID is missing or empty", 'data' => ['params' => $params]];
|
|
}
|
|
|
|
if (!isset($params['action_type']) || empty($params['action_type'])) {
|
|
$this->myLogger->logme("error", "Invalid action type: " . json_encode(['params' => $params]));
|
|
return ['status' => "Failed", 'message' => "Action type is missing or empty", 'data' => ['params' => $params]];
|
|
}
|
|
|
|
//get the policy data
|
|
$policy_data = $this->clientPolicyModel->where('id', $params['client_policy_id'])->where('is_active', 1)->first();
|
|
$params['policy_no'] = $policy_data['policy_no'] ?? null;
|
|
|
|
//check if the entries available in the policy transaction table
|
|
$check_policy_exist = $this->checkPolicyTransactionExist($params);
|
|
|
|
if($check_policy_exist['status'] == true) {
|
|
return $check_policy_exist;
|
|
}
|
|
|
|
//Function call for if the old policy transaction entries exisit than active the Policy transaction entries
|
|
// $existing_policy_transaction_entry = $this->retrivePolicyTransactionEntries($params);
|
|
|
|
// if($existing_policy_transaction_entry != false) {
|
|
// return $existing_policy_transaction_entry;
|
|
// }
|
|
|
|
if (empty($policy_data)) {
|
|
$this->myLogger->logme("error", "No policy data found: " . json_encode(['client_policy_id' => $params['client_policy_id']]));
|
|
return ['status' => "Failed", 'message' => "No policy data found for the given client policy ID", 'data' => ['params' => $params]];
|
|
}
|
|
|
|
//get the leads data
|
|
$lead_data = $this->leadsModel->where('is_policy_created', $params['client_policy_id'])->where('is_active', 1)->first();
|
|
|
|
if (empty($lead_data)) {
|
|
$this->myLogger->logme("error", "No lead data found: " . json_encode(['client_policy_id' => $params['client_policy_id']]));
|
|
// return ['status' => "Failed", 'message' => "No lead data found for the given client policy ID", 'data' => ['params' => $params]];
|
|
}
|
|
|
|
$this->myLogger->logme("error", "Constructing policy transaction data: " . json_encode(['policy_data' => $policy_data, 'lead_data' => $lead_data]));
|
|
|
|
//Function to construct the policy transaction data to insert
|
|
$policyTransactionData = $this->constructBDSData($policy_data, $lead_data, $params);
|
|
|
|
//insert the policy transaction data to othe table
|
|
$insert_id = $this->policyTransactionModel->insert($policyTransactionData);
|
|
|
|
if (!$insert_id) {
|
|
$this->myLogger->logme("error", "Failed to insert into policy_transaction: " . json_encode($policyTransactionData));
|
|
return ['status' => "Failed", 'message' => "Failed to insert policy transaction record", 'data' => ['params' => $params]];
|
|
}
|
|
|
|
$this->myLogger->logme("error", "Policy transaction inserted successfully: " . json_encode(['insert_id' => $insert_id]));
|
|
|
|
//do not remove this commented item
|
|
$coShareDetails = $this->ConstructPTShareData($policy_data, $insert_id, $params, $lead_data, $params['action_type']);
|
|
$pt_co_share_id = $this->PTCOShareDetailsModel->insert($coShareDetails);
|
|
$this->myLogger->logme("error", "PT Co share data inserted successfully: " . json_encode(['pt_co_share_id' => $pt_co_share_id]));
|
|
|
|
// get the lead installment data
|
|
if(!empty($lead_data)){
|
|
|
|
$lead_installment_data = $this->leadInstallmentPaymentDetailesModel
|
|
->select('lead_id, installment_amount, payment_date, utr_no')
|
|
->where('lead_id', $lead_data['id'])
|
|
->where('is_active', 1)
|
|
->findAll();
|
|
|
|
if (!empty($lead_installment_data) && (isset($params['action_type']) && $params['action_type'] == "inception")) {
|
|
|
|
$this->myLogger->logme("error", "Found lead installment data: " . json_encode($lead_installment_data));
|
|
$installment_ids = $this->constructInstallmentData($lead_installment_data, $insert_id);
|
|
$this->myLogger->logme("error", "BDS Installment data inserted ids: " . json_encode(['installment_ids' => $installment_ids]));
|
|
}else{
|
|
$this->myLogger->logme("error", "Failed to insert Installment data : " . json_encode($params));
|
|
}
|
|
}
|
|
|
|
return ['status' => "Success", 'message' => "Policy transaction entry created successfully", 'data' => ['params' => $params, 'insert_id' => $insert_id]];
|
|
} catch (\Throwable $e) {
|
|
|
|
$errorDetails = [
|
|
'error_message' => $e->getMessage(),
|
|
'file' => $e->getFile(),
|
|
'line' => $e->getLine(),
|
|
'stack_trace' => $e->getTraceAsString(),
|
|
];
|
|
|
|
$this->myLogger->logme("error", "Exception occurred in makeEntryForBDSPolicyTransaction(): " . json_encode([
|
|
'error' => $e->getMessage(),
|
|
'trace' => $e->getTraceAsString()
|
|
]));
|
|
|
|
return ['status' => "Error", 'message' => "An unexpected error occurred", 'data' => $errorDetails];
|
|
}
|
|
}
|
|
|
|
private function constructBDSData($policy_data, $lead_data, $params)
|
|
{
|
|
|
|
$this->myLogger->logme("error", "constructBDSData Params: " . json_encode(['policy_data' => $policy_data, 'lead_data' => $lead_data, 'params' => $params]));
|
|
$action_type_string = $params['action_type'];
|
|
if(in_array($params['action_type'], ['dependent_addition', 'missed_inception'])){
|
|
$action_type_string = "addition";
|
|
}
|
|
|
|
// get the acm data for service person id
|
|
$acm_data = db_connect()->table('client_rm')->where('is_active', 1)->where('client_id', $policy_data['client_id'] ?? null)->where('level', 3) ->get() ->getRowArray();
|
|
$service_person_id = null;
|
|
if(!empty($acm_data)){
|
|
$service_person_id = $acm_data['user_id'] ?? null;
|
|
}else{
|
|
$service_person_id = $params['created_by'] ?? null;
|
|
}
|
|
|
|
// get the user data for salse person id
|
|
$user_data = db_connect()->table('user_profiles')->where('is_active', 1)->where('id', $lead_data['created_by'] ?? null)->get()->getRowArray();
|
|
$salse_person_id = null;
|
|
if(isset($lead_data['salse_person_id']) && !empty($lead_data['salse_person_id'])){
|
|
$salse_person_array = json_decode($lead_data['salse_person_id'] ?? '{}', true) ?? [];
|
|
$salse_person_id = $salse_person_array[0] ?? null;
|
|
}else{
|
|
$salse_person_id = $lead_data['created_by'] ?? null;
|
|
}
|
|
|
|
// get the policy transaction id for client policy id
|
|
$policy_transaction_data = $this->policyTransactionModel->where('is_active', 1)->where('TRIM(policy_no)', $policy_data['policy_no'])->where('action_type', 'inception')->first();
|
|
$client_policy_id = null;
|
|
if(!empty($policy_transaction_data) && $params['action_type'] != "inception"){
|
|
$client_policy_id = $policy_transaction_data['id'] ?? null;
|
|
}else{
|
|
$client_policy_id = $policy_data['id'] ?? null;
|
|
}
|
|
|
|
$policyTransactionData = [
|
|
|
|
'issuer' => 2,
|
|
'issuer_branch' => $user_data['nhance_branch_id'] ?? 1,
|
|
'client_id' => $policy_data['client_id'] ?? null,
|
|
'client_branch_id' => $policy_data['client_branch_id'] ?? null,
|
|
'insurer_id' => $policy_data['insurer_id'] ?? null,
|
|
'insurer_branch_id' => $policy_data['insurer_branch_id'] ?? null,
|
|
'tpa_id' => $policy_data['tpa_id'] ?? null,
|
|
'tpa_branch_id' => $policy_data['tpa_branch_id'] ?? null,
|
|
'policy_type_id' => $policy_data['policy_type_id'] ?? null,
|
|
'client_policy_id' => $client_policy_id,
|
|
'policy_no' => $policy_data['policy_no'] ?? null,
|
|
'cd_ac_no' => $policy_data['cd_ac_no'] ?? null,
|
|
'cd_ac_pk' => $policy_data['cd_ac_pk'] ?? null,
|
|
'policy_issue_date' => $params['policy_issue_date'] ?? null,
|
|
'policy_start_date' => $policy_data['policy_start_date'] ?? null,
|
|
'policy_end_date' => $policy_data['policy_end_date'] ?? null,
|
|
'data_received_date' => $policy_data['data_received_date'] ?? null,
|
|
'closure_date' => $policy_data['closure_date'] ?? null,
|
|
'emp_count' => $params['no_of_insured'] ?? null,
|
|
'dependent_count' => $params['no_of_dependent'] ?? null,
|
|
'revenue_type' => isset($lead_data['lead_type']) ?($lead_data['lead_type'] == 1 ? "NA" : ($lead_data['lead_type'] == 2 ? "EA" : "EANR") ) : "NA",
|
|
'co_share' => $policy_data['co_share'] ?? 0,
|
|
'pre_payable_by' => $policy_data['pre_payable_by'] ?? 1,
|
|
'renewal_date' => $policy_data['policy_end_date'] ?? null,
|
|
'month' => date('Y-m-01', strtotime($params['policy_issue_date'] ?? "")) ?? null,
|
|
'ct_type' => 1,
|
|
'is_cd_reduce_from_bds' => 0,
|
|
'client_type_id' => 0,
|
|
'bro_payable_by' => 1,
|
|
|
|
// 'status' => "co_insurer_pending",
|
|
'status' => "completed",
|
|
'action_type' => $action_type_string ?? null,
|
|
'endorsement_no' => $params['endorsement_no'] ?? null,
|
|
|
|
'issue_type' => $lead_data['lead_type'] ?? 1,
|
|
'source_client_policy_id' => $lead_data['source_policy_id'] ?? null,
|
|
'tsi' => generate_tsi_code($lead_data['lead_type'] ?? 1) ?? null,
|
|
'installment' => $lead_data['no_of_installment'] ?? null,
|
|
'created_by' => $params['created_by'] ?? null,
|
|
'entry_from' => 2,
|
|
|
|
'sales_generated_by' => $salse_person_id,
|
|
'serviced_by' => $service_person_id,
|
|
];
|
|
|
|
$this->myLogger->logme("error", "Constructed policy transaction data: " . json_encode($policyTransactionData));
|
|
|
|
return $policyTransactionData;
|
|
}
|
|
|
|
private function ConstructPTShareData($policy_data, $pt_id, $params, $lead_data, $action_type)
|
|
{
|
|
$policyTypeModel = new PolicyTypeModel();
|
|
$policy_type_data = $policyTypeModel->where('is_active', 1)->where('id', $policy_data['policy_type_id'])->first();
|
|
|
|
// Determine if we should negate the values
|
|
$multiplier = (strtolower($action_type) === 'deletion') ? -1 : 1;
|
|
|
|
$coShareData = [
|
|
'pt_id' => $pt_id,
|
|
'insurer_id' => $policy_data['insurer_id'],
|
|
'insurer_branch_id' => $policy_data['insurer_branch_id'],
|
|
'bp_amt' => ($params['base_premium'] ?? 0) * $multiplier,
|
|
'cop_amt' => ($params['base_premium'] ?? 0) * $multiplier,
|
|
'bp_gst_amt' => ($params['gst'] ?? 0) * $multiplier,
|
|
'bp_sgst' => 9, // Usually tax percentages remain positive, but multiply if this is an amount
|
|
'bp_cgst' => 9,
|
|
'co_share_type' => 1,
|
|
'co_share_per' => 100,
|
|
'standerd_bp_per' => $policy_type_data['ebp'],
|
|
'pt_policy_issue_date' => $params['policy_issue_date'] ?? null,
|
|
'amount' => (($params['base_premium'] ?? 0) + ($params['gst'] ?? 0)) * $multiplier,
|
|
];
|
|
|
|
if(isset($policy_data['gst']) && $policy_data['gst'] != null){
|
|
$coShareData['bp_igst'] = $policy_data['gst'] ?? 0;
|
|
$coShareData['bp_sgst'] = 0;
|
|
$coShareData['bp_cgst'] = 0;
|
|
}
|
|
|
|
// Calculate exp_amt logic
|
|
$agreed_per = $lead_data['agreed_percentage'] ?? $policy_type_data['ebp'] ?? 0;
|
|
$coShareData['exp_amt'] = ((($params['base_premium'] ?? 0) * $agreed_per) / 100) * $multiplier;
|
|
|
|
$this->myLogger->logme("error", "Constructed PT co-share data: " . json_encode($coShareData));
|
|
|
|
return $coShareData;
|
|
}
|
|
|
|
private function ConstructPTShareDataOld($policy_data, $pt_id, $params, $lead_data, $action_type = null)
|
|
{
|
|
$policyTypeModel = new PolicyTypeModel();
|
|
$policy_type_data = $policyTypeModel->where('is_active', 1)->where('id', $policy_data['policy_type_id'])->first();
|
|
|
|
$coShareData = [
|
|
'pt_id' => $pt_id,
|
|
'insurer_id' => $policy_data['insurer_id'],
|
|
'insurer_branch_id' => $policy_data['insurer_branch_id'],
|
|
'bp_amt' => $params['base_premium'],
|
|
'cop_amt' => $params['base_premium'],
|
|
'bp_gst_amt' => $params['gst'],
|
|
'bp_sgst' => 9,
|
|
'bp_cgst' => 9,
|
|
'co_share_type' => 1,
|
|
'co_share_per' => 100,
|
|
'standerd_bp_per' => $policy_type_data['ebp'],
|
|
'pt_policy_issue_date' => $params['policy_issue_date'] ?? null,
|
|
'amount' => ($params['base_premium'] ?? 0) + ($params['gst'] ?? 0),
|
|
];
|
|
|
|
if(isset($policy_data['gst']) && $policy_data['gst'] != null){
|
|
$coShareData['bp_igst'] = $policy_data['gst'];
|
|
$coShareData['bp_sgst'] = 0;
|
|
$coShareData['bp_cgst'] = 0;
|
|
}
|
|
|
|
if(isset($lead_data['agreed_percentage']) && !empty($lead_data['agreed_percentage'])){
|
|
$coShareData['exp_amt'] = (($params['base_premium'] ?? 0) * ($lead_data['agreed_percentage'] ?? 0)) / 100;
|
|
}else{
|
|
$coShareData['exp_amt'] = (($params['base_premium'] ?? 0) * ($policy_type_data['ebp'] ?? 0)) / 100;
|
|
}
|
|
|
|
$this->myLogger->logme("error", "Constructed PT co-share data: " . json_encode($coShareData));
|
|
|
|
return $coShareData;
|
|
}
|
|
|
|
private function constructInstallmentData($data, $pt_id)
|
|
{
|
|
if (!empty($data)) {
|
|
$installment_ids = [];
|
|
foreach ($data as $key => &$value) {
|
|
$value['pt_id'] = $pt_id;
|
|
$installment_ids[] = $this->BdsPlacementModel->insert($value);
|
|
}
|
|
unset($value);
|
|
|
|
return $installment_ids;
|
|
}
|
|
}
|
|
|
|
private function retrivePolicyTransactionEntries($params)
|
|
{
|
|
$policy_transaction_data = $this->policyTransactionModel
|
|
->where('is_active', 0)
|
|
->where('client_policy_id', $params['client_policy_id']);
|
|
|
|
if ($params['action_type'] != "inception") {
|
|
$policy_transaction_data = $policy_transaction_data->where('endorsement_no', $params['endorsement_no']);
|
|
}
|
|
|
|
$policy_transaction_data = $policy_transaction_data
|
|
->where('action_type', $params['action_type'])
|
|
->first();
|
|
|
|
if(empty($policy_transaction_data)){
|
|
$this->myLogger->logme("error", "retrive Policy Transaction Entries data not found : " . json_encode(['params' => $params]));
|
|
return false;
|
|
}
|
|
|
|
$pt_co_share_data = $this->PTCOShareDetailsModel->where('is_active', 0)->where('pt_id', $policy_transaction_data['id'])->findAll();
|
|
|
|
if(empty($pt_co_share_data)){
|
|
$this->myLogger->logme("error", "PT Co Share Table data not found");
|
|
}
|
|
|
|
$activated_pt_co_share_ids = [];
|
|
foreach ($pt_co_share_data as $key => $value) {
|
|
$this->PTCOShareDetailsModel->where('id', $value['id'])->set(['is_active' => 1])->update();
|
|
$activated_pt_co_share_ids[] = $value['id'];
|
|
}
|
|
|
|
$this->myLogger->logme("error", "Activated pt_co_share_ids : ". json_encode($activated_pt_co_share_ids));
|
|
|
|
$update_return = $this->policyTransactionModel->where('id', $policy_transaction_data['id'])->set(['is_active' => 1])->update();
|
|
|
|
if($update_return){
|
|
$this->myLogger->logme("error", "Invalid action type: " . json_encode(['params' => $params]));
|
|
return ['status' => "Success", 'message' => "Policy transaction entry Retrived successfully", 'data' => ['params' => $params, 'updated_id' => $policy_transaction_data['id']]];
|
|
}else{
|
|
$this->myLogger->logme("error", "Invalid action type: " . json_encode(['params' => $params]));
|
|
return ['status' => "Success", 'message' => "Failed to retrive the policy transaction entry", 'data' => ['params' => $params, 'updated_id' => $policy_transaction_data['id']]];
|
|
}
|
|
|
|
}
|
|
|
|
public function checkPolicyTransactionExist($params)
|
|
{
|
|
// Trim the input
|
|
$policy_no = trim($params['policy_no']);
|
|
|
|
// Base query
|
|
$policy_transaction_data = $this->policyTransactionModel->where('is_active', 1)->where('TRIM(policy_no)', $policy_no);
|
|
|
|
// Add endorsement condition only if not inception
|
|
if ($params['action_type'] !== "inception") {
|
|
$policy_transaction_data = $policy_transaction_data ->where('TRIM(endorsement_no)', trim($params['endorsement_no']));
|
|
}
|
|
|
|
$policy_transaction_data = $policy_transaction_data->first();
|
|
|
|
// If record exists → log and return true
|
|
if (!empty($policy_transaction_data)) {
|
|
$this->myLogger->logme("error", "Policy Transaction already exists. Input Parameters: " . json_encode($params) );
|
|
return ['status' => true, 'message' => "This entry already available in the Policy Transaction table", 'data' => $policy_transaction_data['id']];
|
|
}
|
|
|
|
return ['status' => false, 'message' => "This entry not available in the Policy Transaction table", 'data' => ''];
|
|
}
|
|
|
|
public function removeBDSPolicyTransactionEntryFromTruncate($params)
|
|
{
|
|
if (empty($params) || !isset($params['client_policy_id']) || empty($params['client_policy_id'])) {
|
|
$this->myLogger->logme("error", "Invalid parameters provided: " . json_encode(['params' => $params]));
|
|
return ['status' => "Failed", 'message' => "Client Policy ID is missing or empty", 'data' => ['params' => $params]];
|
|
}
|
|
|
|
if (!isset($params['file_id']) || empty($params['file_id'])) {
|
|
$this->myLogger->logme("error", "File ID is missing or empty : " . json_encode(['params' => $params]));
|
|
return ['status' => "Failed", 'message' => "File ID is missing or empty : ", 'data' => ['params' => $params]];
|
|
}
|
|
|
|
if (!isset($params['action_type']) || empty($params['action_type'])) {
|
|
$this->myLogger->logme("error", "Invalid action type: " . json_encode(['params' => $params]));
|
|
return ['status' => "Failed", 'message' => "Action type is missing or empty", 'data' => ['params' => $params]];
|
|
}
|
|
|
|
|
|
if($params['action_type'] != "inception"){
|
|
|
|
$endorsement_data = $this->endorsementModel
|
|
->where('is_active', 1)
|
|
->where('client_policy_id', $params['client_policy_id'])
|
|
->where('endorsement_type', $params['action_type'])
|
|
->where('file_id', $params['file_id'])
|
|
->first();
|
|
|
|
if(empty($endorsement_data)){
|
|
$this->myLogger->logme("error", "Endorsement data not found");
|
|
return ['status' => "Failed", 'message' => "Endorsement data not found", 'data' => ['params' => $params]];
|
|
}
|
|
}
|
|
|
|
$action_type_string = $params['action_type'];
|
|
if(in_array($params['action_type'], ['dependent_addition', 'missed_inception'])){
|
|
$action_type_string = "addition";
|
|
}
|
|
|
|
|
|
$policy_transaction_data = $this->policyTransactionModel
|
|
->where('is_active', 1)
|
|
->where('client_policy_id', $params['client_policy_id']);
|
|
|
|
if ($params['action_type'] != "inception") {
|
|
$policy_transaction_data = $policy_transaction_data->where('endorsement_no', $endorsement_data['endorsement_no']);
|
|
}
|
|
|
|
$policy_transaction_data = $policy_transaction_data
|
|
->where('action_type', $action_type_string)
|
|
->first();
|
|
|
|
|
|
if(empty($policy_transaction_data)){
|
|
$this->myLogger->logme("error", "Policy transaction data not found");
|
|
return ['status' => "Failed", 'message' => "Policy transaction data not found", 'data' => ['params' => $params]];
|
|
}
|
|
|
|
|
|
$pt_co_share_data = $this->PTCOShareDetailsModel->where('is_active', 1)->where('pt_id', $policy_transaction_data['id'])->findAll();
|
|
|
|
if(empty($pt_co_share_data)){
|
|
$this->myLogger->logme("error", "PT Co Share Table data not found");
|
|
}
|
|
|
|
$de_activated_pt_co_share_ids = [];
|
|
foreach ($pt_co_share_data as $key => $value) {
|
|
$this->PTCOShareDetailsModel->where('id', $value['id'])->set(['is_active' => 0])->update();
|
|
$de_activated_pt_co_share_ids[] = $value['id'];
|
|
}
|
|
|
|
$this->myLogger->logme("error", "De-activated pt_co_share_ids : ". json_encode($de_activated_pt_co_share_ids));
|
|
|
|
$update_return = $this->policyTransactionModel->where('id', $policy_transaction_data['id'])->set(['is_active' => 0])->update();
|
|
|
|
if($update_return){
|
|
$this->myLogger->logme("error", "Policy transaction data de-active successfully");
|
|
return ['status' => "Success", 'message' => "Policy transaction data Truncated successfully", 'data' => ['params' => $params]];
|
|
}else{
|
|
$this->myLogger->logme("error", "Failed to de-active policy transaction data");
|
|
return ['status' => "Success", 'message' => "Failed to truncated the policy transaction data", 'data' => ['params' => $params]];
|
|
}
|
|
|
|
}
|
|
|
|
// --------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
public function getInceptionBasePremium($ids)
|
|
{
|
|
$this->myLogger->logme('error', 'getInceptionBasePremium called with the params : ' . json_encode($ids ?? ""));
|
|
|
|
// Validate input
|
|
if (empty($ids) || !is_array($ids)) {
|
|
return ['base_premium' => 0, 'gst' => 0];
|
|
}
|
|
|
|
// Sanitize IDs to ensure they are integers
|
|
$sanitizedIds = array_filter(array_map('intval', $ids), function ($id) {
|
|
return $id > 0;
|
|
});
|
|
|
|
if (empty($sanitizedIds)) {
|
|
return ['base_premium' => 0, 'gst' => 0];
|
|
}
|
|
|
|
// Use parameter binding for security
|
|
$placeholders = str_repeat('?,', count($sanitizedIds) - 1) . '?';
|
|
|
|
$amount = $this->employeePolicyModel->query("
|
|
SELECT SUM(employee_polices.rata_premimum) AS base_premium,
|
|
SUM(employee_polices.gst) AS gst
|
|
FROM employee_polices
|
|
JOIN employees ON employees.id = employee_polices.employee_id
|
|
WHERE employee_polices.id IN ($placeholders)
|
|
", $sanitizedIds)->getRowArray();
|
|
|
|
$this->myLogger->logme('error', 'Get Last Executed Query : '.db_connect()->getLastQuery());
|
|
|
|
// Ensure we return proper numeric values
|
|
return [
|
|
'base_premium' => round($amount['base_premium'] ?? 0, 2),
|
|
'gst' => round($amount['gst'] ?? 0, 2)
|
|
];
|
|
}
|
|
|
|
public function getDeletionBasePremium($ids, $params)
|
|
{
|
|
$this->myLogger->logme('error', 'getDeletionBasePremium called with the params : ' . json_encode(['emp_policy_id' => $ids ?? [], 'params' => $params ?? []] ?? ""));
|
|
|
|
// Validate input
|
|
if (empty($ids) || !is_array($ids)) {
|
|
return ['base_premium' => 0, 'gst' => 0];
|
|
}
|
|
|
|
// Sanitize IDs to ensure they are integers
|
|
$sanitizedIds = array_filter(array_map('intval', $ids), function ($id) {
|
|
return $id > 0;
|
|
});
|
|
|
|
if (empty($sanitizedIds)) {
|
|
return ['base_premium' => 0, 'gst' => 0];
|
|
}
|
|
|
|
// Validate client_policy_id parameter
|
|
if (empty($params['client_policy_id'])) {
|
|
return ['base_premium' => 0, 'gst' => 0];
|
|
}
|
|
|
|
$get_insurer_id_from_client_policy = $this->clientPolicyModel
|
|
->select('insurers.deletion_add_day')
|
|
->join('insurers', 'client_policy.insurer_id = insurers.id')
|
|
->where('client_policy.id', intval($params['client_policy_id']))
|
|
->first();
|
|
|
|
$add_one_day = 0;
|
|
if (isset($get_insurer_id_from_client_policy['deletion_add_day']) && $get_insurer_id_from_client_policy['deletion_add_day'] == 1) {
|
|
$add_one_day = 1;
|
|
}
|
|
|
|
// Use parameter binding for security
|
|
$placeholders = str_repeat('?,', count($sanitizedIds) - 1) . '?';
|
|
|
|
// Prepare parameters array (ids repeated twice for both IN clauses)
|
|
$queryParams = array_merge($sanitizedIds, $sanitizedIds);
|
|
|
|
$amount = $this->employeePolicyModel->query("
|
|
SELECT
|
|
SUM(ROUND(
|
|
((employee_polices.rata_premimum * (DATEDIFF(employee_polices.policy_end_date, emp_endorsement.new_value) + ?)) / 365),
|
|
2
|
|
)) AS base_premium,
|
|
SUM(ROUND(
|
|
(((employee_polices.rata_premimum * (DATEDIFF(employee_polices.policy_end_date, emp_endorsement.new_value) + ?)) / 365) * 0.18),
|
|
2
|
|
)) AS gst
|
|
FROM
|
|
employee_polices
|
|
JOIN
|
|
employees ON employees.id = employee_polices.employee_id
|
|
JOIN
|
|
emp_endorsement ON emp_endorsement.pk = employee_polices.id
|
|
WHERE
|
|
employee_polices.id IN ($placeholders)
|
|
AND emp_endorsement.pk IN ($placeholders)
|
|
AND employee_polices.claim_status = 0
|
|
AND emp_endorsement.field_name = 'date_of_exit'
|
|
AND emp_endorsement.is_active = 1
|
|
AND emp_endorsement.actions = 'd'
|
|
AND emp_endorsement.status != 'truncated'
|
|
", array_merge([$add_one_day, $add_one_day], $queryParams))->getRowArray();
|
|
|
|
$this->myLogger->logme('error', 'Get Last Executed Query : '.db_connect()->getLastQuery());
|
|
// Ensure we return proper numeric values with rounding
|
|
return [
|
|
'base_premium' => round($amount['base_premium'] ?? 0, 2),
|
|
'gst' => round($amount['gst'] ?? 0, 2)
|
|
];
|
|
}
|
|
|
|
public function getHrdataForInsufficientMailSend($ref_id)
|
|
{
|
|
$data = $this->LevelContactModel
|
|
->select('id, name, email')
|
|
->where('ref_id', $ref_id)
|
|
->where('is_active', 1)
|
|
->where('contact_type', 'client')
|
|
->findAll();
|
|
|
|
return $data;
|
|
}
|
|
}
|