Merge branch 'dev' of bitbucket.org:jubilian/nhance into dev

This commit is contained in:
Srinivas-Saravanan 2025-05-16 17:51:10 +05:30
commit df9795bc48
6 changed files with 260 additions and 39 deletions

View File

@ -1243,40 +1243,8 @@ class ClientController extends AdminController
$data['created_by'] = get_session_userid();
$policy_tranction_data = [
'issuer' => 2,
'client_id' => $this->request->getPost('client_id'),
'client_branch_id' => $this->request->getPost('client_branch_id'),
'insurer_id' => $insurerId,
'insurer_branch_id' => $insurerBranchId,
'issue_type' => 1,
'policy_no' => $this->request->getPost('policy_no'),
'cd_ac_pk' => $this->request->getPost('cd_ac_no'),
'policy_issue_date' => date('Y-m-d'),
'policy_start_date' => change_date_format($this->request->getPost('policy_start_date'), 'd-m-Y', 'Y-m-d'),
'policy_end_date' => change_date_format($this->request->getPost('policy_end_date'), 'd-m-Y', 'Y-m-d'),
'action_type' => 'inception',
'status' => 'pending',
'created_by' => get_session_userid(),
];
$insert = $this->clientPolicyModel->insert($data);
if ($insert) {
$policy_tranction_data['client_policy_id'] = $insert;
$policy_tranction_data_insert = $this->policyTransactionModel->insert($data);
if ($policy_tranction_data_insert) {
$statusData = [
'policy_tran_id' => $policy_tranction_data_insert,
'status' => 'pending',
'created_by' => get_session_userid(),
];
$this->policyTransactionStatusModel->insert($statusData);
}
$clientPoliceData = $this->clientPolicyModel->getClientPolicyByClientId($this->request->getPost('client_id'));
$clientPoliceData['role'] = get_role_id();
return $this->respond(['status' => true, 'code' => 200, 'data' => $clientPoliceData, 'method' => 'CERATE', 'post_data' => $data], 200);
@ -4667,6 +4635,13 @@ class ClientController extends AdminController
// $EmpDataServiceController->importDeletionValidation(['file_id' => 171]);
// $EmpDataServiceController->importDeletionUpdateEndorsementID(['file_id' => 171]);
// $EmpDataServiceController->importCorrectionUpdateEndorsementID(['file_id' => 188]);
$params = [
'client_policy_id' => 6090,
'action_type' => "inception",
];
$res = $EmpDataServiceController->makeEntryForBDSPolicyTransaction($params);
dd($res);
// $array = [
// "employeeIds" => ["12800", "12798", "12797", "12799"],

View File

@ -28,6 +28,11 @@ 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\Controllers\Jobs;
use App\Controllers\JobWorker;
@ -60,6 +65,11 @@ class EmpDataServiceController extends BaseController
protected $excelExportTemplateModel;
protected $clientBranchModel;
protected $endorsementModel;
protected $BdsPlacementModel;
protected $leadsModel;
protected $leadInstallmentPaymentDetailesModel;
protected $policyTransactionModel;
protected $PTCOShareDetailsModel;
public function __construct()
@ -83,6 +93,11 @@ class EmpDataServiceController extends BaseController
$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();
}
@ -1976,6 +1991,13 @@ class EmpDataServiceController extends BaseController
'user_id' => $user_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,
]]);
// $this->cashDepositCalculationForInception($depositeData);
// $this->sendMailForDownloadingECard($emp_policy_ids);
@ -2400,6 +2422,13 @@ class EmpDataServiceController extends BaseController
$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,
]]);
//import file to upload Google Drive
// if(excelFileGDriveUpload($file_id, 'batch_file')){
@ -3024,6 +3053,13 @@ class EmpDataServiceController extends BaseController
'user_id' => $user_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,
]]);
}
$file_data = $this->getDataByFileId($file_id, 'success');
@ -3498,6 +3534,13 @@ class EmpDataServiceController extends BaseController
'policy_name' => $policy_name['policy_name'],
'user_id' => $user_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,
]]);
}
$file_data = $this->getDataByFileId($file_id, 'success');
@ -4675,7 +4718,171 @@ class EmpDataServiceController extends BaseController
$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]];
}
$policy_data = $this->clientPolicyModel
->where('id', $params['client_policy_id'])
->where('is_active', 1)
->first();
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]];
}
$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]));
$policyTransactionData = $this->constructBDSData($policy_data, $lead_data, $params);
$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);
// $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]));
$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", "Installment data inserted: " . 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) {
$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' => ['error' => $e]];
}
}
private function constructBDSData($policy_data, $lead_data, $params)
{
$policyTransactionData = [
'issuer' => 2,
'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' => $policy_data['id'] ?? null,
'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' => $policy_data['policy_start_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' => $policy_data['emp_count'] ?? null,
'dependent_count' => $policy_data['dependent_count'] ?? null,
'revenue_type' => ($lead_data['lead_type'] == 1 ? "NA" : ($lead_data['lead_type'] == 2 ? "EA" : "EANR") ) ?? null,
'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($policy_data['policy_start_date'])) ?? null,
'ct_type' => 1,
'is_cd_reduce_from_bds' => 0,
'client_type_id' => 0,
'status' => "completed",
'action_type' => $params['action_type'] ?? null,
'endorsement_no' => $params['endorsement_no'] ?? null,
'issue_type' => $lead_data['lead_type'] ?? null,
'source_client_policy_id' => $lead_data['source_policy_id'] ?? null,
'tsi' => generate_tsi_code($lead_data['lead_type']) ?? null,
'installment' => $lead_data['no_of_installment'] ?? null,
];
$this->myLogger->logme("error", "Constructed policy transaction data: " . json_encode($policyTransactionData));
return $policyTransactionData;
}
private function ConstructPTShareData($policy_data, $pt_id)
{
$coShareData = [
'pt_id' => $pt_id,
'insurer_id' => $policy_data['insurer_id'],
'insurer_branch_id' => $policy_data['insurer_branch_id'],
'co_share_type' => 1,
];
$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;
}
}
public function retriveBDSPolicyTransactionEntry()
{
}
}

View File

@ -123,6 +123,10 @@ class JobWorker extends AdminController
'type' => 'CC', // Handler Category
'handler' => 'App\Controllers\EmpDataServiceController',
],
'makeEntryForBDSPolicyTransaction' => [
'type' => 'CC', // Handler Category
'handler' => 'App\Controllers\EmpDataServiceController',
],
'employeesEnrollmentInsert' => [
'type' => 'CC', // Handler Category
'handler' => 'App\Controllers\EmployeeServiceController',

View File

@ -2712,7 +2712,7 @@ class LeadsController extends BaseController
$this->myLogger->logme('featchLeadDataAndInsertClient', "Client creation failed after processing", ['lead_id' => $lead_id]);
return $this->respond(['status' => false, 'message' => 'Failed to create client', 'data' => $data], 200);
} catch (\Throwable $e) {
$this->myLogger->logme('featchLeadDataAndInsertClient', $e->getMessage(), ['lead_id' => $lead_id, 'trace' => $e->getTraceAsString()]);
$this->myLogger->logme('error', 'featchLeadDataAndInsertClient failed');
return $this->respond(['status' => false, 'message' => 'Internal server error', 'error' => $e->getMessage()], 500);
}
}
@ -2730,7 +2730,7 @@ class LeadsController extends BaseController
return $client_id;
} catch (\Throwable $e) {
$this->myLogger->logme('createClientWithLeadData', $e->getMessage(), ['lead_id' => $data['id'], 'trace' => $e->getTraceAsString()]);
$this->myLogger->logme('error','createClientWithLeadData failed');
return false;
}
}
@ -2750,7 +2750,7 @@ class LeadsController extends BaseController
return $branch_id;
} catch (\Throwable $e) {
$this->myLogger->logme('createClientBranchAndContactWithLeadData', $e->getMessage(), ['lead_id' => $data['id'], 'trace' => $e->getTraceAsString()]);
$this->myLogger->logme('error','createClientBranchAndContactWithLeadData failed');
return false;
}
}
@ -2763,12 +2763,12 @@ class LeadsController extends BaseController
if ($client_policy_id) {
$this->leadsModel->where('id', $data['id'])->set('is_client_created', $client_id)->update();
$this->leadsModel->where('id', $data['id'])->set('is_policy_created', $client_id)->update();
$this->leadsModel->where('id', $data['id'])->set('is_policy_created', $client_policy_id)->update();
}
return $client_policy_id;
} catch (\Throwable $e) {
$this->myLogger->logme('createClientPolicyWithLeadData', $e->getMessage(), ['lead_id' => $data['id'], 'trace' => $e->getTraceAsString()]);
$this->myLogger->logme('error','createClientPolicyWithLeadData failed');
return false;
}
}
@ -2871,7 +2871,7 @@ class LeadsController extends BaseController
return $this->convertQCRJsonToPolicyTerms($converted_json, $data['policy_type_id'], $proposel_data['proposel_name'], $proposel_data['insurer_name']);
} catch (\Throwable $e) {
$this->myLogger->logme('preparePolicyTermsFromRFQ', $e->getMessage(), ['lead_id' => $data['id'], 'trace' => $e->getTraceAsString()]);
$this->myLogger->logme('error','preparePolicyTermsFromRFQ');
return null;
}
}

View File

@ -22,6 +22,39 @@ class BdsPlacementModel extends Model
'is_active'
];
// Callbacks
protected $allowCallbacks = true;
protected $beforeInsert = ["checkAndADDCreatedByValue"];
protected $afterInsert = [];
protected $beforeUpdate = ["checkAndUpdateUpdatedByValue"];
protected $afterUpdate = [];
protected $beforeFind = [];
protected $afterFind = [];
protected $beforeDelete = [];
protected $afterDelete = [];
protected function checkAndADDCreatedByValue(array $data)
{
// Check if 'updated_by' value is null or empty
if (empty($data['data']['created_by'])) {
// Set 'updated_by' value to the current session user ID
$data['data']['created_by'] = get_session_userid();
}
return $data;
}
protected function checkAndUpdateUpdatedByValue(array $data)
{
// Check if 'updated_by' value is null or empty
if (empty($data['data']['updated_by'])) {
// Set 'updated_by' value to the current session user ID
$data['data']['updated_by'] = get_session_userid();
}
return $data;
}
public function getClientInstallmentDetails()
{

View File

@ -96,6 +96,7 @@ class LeadsModel extends Model
'is_installment',
'no_of_installment',
'is_policy_created',
];
@ -176,7 +177,8 @@ class LeadsModel extends Model
->where('leads.is_active', 1)
->where('leads.status', 'won')
->where("leads.proposel_data IS NOT NULL AND leads.proposel_data <> ''")
->where("(leads.is_client_created = '' OR leads.is_client_created IS NULL)");
->where("(leads.is_client_created = '' OR leads.is_client_created IS NULL)")
->where("(leads.is_policy_created = '' OR leads.is_policy_created IS NULL)");