diff --git a/app/Controllers/ClientController.php b/app/Controllers/ClientController.php index 968fc9f9..98528212 100755 --- a/app/Controllers/ClientController.php +++ b/app/Controllers/ClientController.php @@ -87,6 +87,7 @@ class ClientController extends AdminController protected $vehicleModel; protected $leadsModel; protected $clientApi; + protected $PTCOShareDetailsModel; public function __construct() @@ -123,6 +124,7 @@ class ClientController extends AdminController $this->vehicleModel = new VehicleModel(); $this->leadsModel = new LeadsModel(); $this->clientApi = new ClientApiModel(); + $this->PTCOShareDetailsModel = new PTCOShareDetailsModel(); } //-------------------------------------------------------------------------------------------------------- @@ -270,7 +272,7 @@ class ClientController extends AdminController if($mail_active == 1){ $mail_send_return = MailHelper::send_email($wholeData[0]); - $this->myLogger->logme("info", $mail_send_return); + $this->myLogger->logme("error", $mail_send_return); } // if (isset($wholeData)) { @@ -1255,15 +1257,12 @@ class ClientController extends AdminController public function editClientPolicy() { - - // print_r('test'); die; $this->myLogger->logme('error', 'Client policy function called'); - - $id = $this->request->getPost('PrimaryKey'); - $client_id = $this->request->getPost('client_id'); + $id = $this->request->getPost('PrimaryKey'); + $client_id = $this->request->getPost('client_id'); $policy_type_id = $this->request->getPost('policy_type_id'); - $base_policy = $this->request->getPost('base_policy'); + $base_policy = $this->request->getPost('base_policy'); $insurerValue = (string) $this->request->getPost('insurer'); @@ -1279,9 +1278,7 @@ class ClientController extends AdminController $data['client_id'] = $client_id; $data['tpa_id'] = $tpaId; $data['policy_type_id'] = $this->request->getPost('policy_type_id'); - $data['policy_no'] = $this->request->getPost('policy_no'); - // $data['policy_start_date'] = change_date_format($this->request->getPost('policy_start_date'), 'd-m-Y', 'Y-m-d'); - // $data['policy_end_date'] = change_date_format($this->request->getPost('policy_end_date'), 'd-m-Y', 'Y-m-d'); + $data['policy_no'] = $this->request->getPost('policy_no'); $data['insured'] = $this->request->getPost('insured'); $data['no_of_lives'] = $this->request->getPost('no_of_lives'); @@ -1318,19 +1315,6 @@ class ClientController extends AdminController $data['reminder_date'] = null; } - // if($policy_type_id == 1 || $policy_type_id == 2 || $policy_type_id == 3 || $policy_type_id == 6 || $policy_type_id == 7){ - - // $data['is_addon'] = 1; - - // }else if($policy_type_id == 4){ - - // $data['is_addon'] = 2; - - // }else if($policy_type_id == 5){ - - // $data['is_addon'] = 3; - // } - if ($policy_type_id == 1 || $policy_type_id == 2 || $policy_type_id == 6 || $policy_type_id == 7) { $data['is_addon'] = 1; // Base Policy @@ -1348,47 +1332,26 @@ class ClientController extends AdminController } } - - $policy_terms = $this->clientPolicyModel->where('id', $this->request->getPost('base_policy'))->first(); - // if ( $this->request->getPost('is_addon') == 2 || $this->request->getPost('is_addon') == 3) { - // if ($this->request->getPost('is_addon') == 3) { - // $policyTerm = $policy_terms['policy_terms']; - // $decoded_policyTerm = json_decode($policyTerm, true); - // $decoded_policyTerm['family_floater'] =0; - // $decoded_policyTerm['family_floaters']['self'] =0; - // $decoded_policyTerm['family_floaters']['spouse'] =0; - // $decoded_policyTerm['family_floaters']['childrens'] =0; - // $decoded_policyTerm['family_floaters']['parents'] =0; - // $decoded_policyTerm['family_floaters']['parents-in-law'] =0; - // $decoded_policyTerm['family_floaters']['either-parents-pil'] =0; - - // $data['policy_terms'] = json_encode($decoded_policyTerm); - // } else { - // $data['policy_terms'] = $policy_terms['policy_terms']; - // } - - - // } - - // dd($data); + $old_client_policy_data = $this->clientPolicyModel->where('is_active', 1)->where('id', $id)->first(); $data['updated_by'] = get_session_userid(); - // print_r(json_encode($data));die; $insert = $this->clientPolicyModel->update($id, $data); - $lastQuery = $this->clientPolicyModel->getLastQuery(); - - // echo '
';
- // print_r($data); die;
if ($insert) {
+
+ $new_client_policy_data = $this->clientPolicyModel->where('is_active', 1)->where('id', $id)->first();
+ $policy_transaction_data = $this->policyTransactionModel->where('is_active', 1)->where('client_policy_id', $id)->countAllResults();
$clientPoliceData = $this->clientPolicyModel->getClientPolicyByClientId($client_id);
$clientPoliceData['role'] = get_role_id();
- // foreach ($clientPoliceData as $key => $value) {
- // $clientPoliceData[$key]->policy_start_date = date('d-M-Y', strtotime($value->policy_start_date));
- // $clientPoliceData[$key]->policy_end_date = date('d-M-Y', strtotime($value->policy_end_date));
- // }
+ if($policy_transaction_data > 0){
+ $r = Jobs::addJob(['job_name' => 'updatePolicyTransactionDataWhileClinetPolicyUpdate', 'payload' => [
+ 'old_client_policy_data' => $old_client_policy_data ?? null,
+ 'new_client_policy_data' => $new_client_policy_data ?? null,
+ ]]);
+ }
+
return $this->respond(['status' => true, 'code' => 200, 'data' => $clientPoliceData, 'method' => 'EDIT'], 200);
} else {
return $this->respond(['status' => false, 'code' => 404, 'message' => 'no data found'], 200);
@@ -1857,6 +1820,146 @@ class ClientController extends AdminController
}
}
+ public function updatePolicyTransactionDataWhileClinetPolicyUpdate($params)
+ {
+ try {
+ // Basic validation
+ if (empty($params) || !isset($params['old_client_policy_data']) || empty($params['old_client_policy_data'])) {
+ $this->myLogger->logme("error", "Old client policy data is missing or empty: " . json_encode(['params' => $params]));
+ return ['status' => "Failed", 'message' => "Old client policy data is missing or empty", 'data' => $params];
+ }
+
+ if (!isset($params['new_client_policy_data']) || empty($params['new_client_policy_data'])) {
+ $this->myLogger->logme("error", "New client policy data is missing or empty: " . json_encode(['params' => $params]));
+ return ['status' => "Failed", 'message' => "New client policy data is missing or empty", 'data' => $params];
+ }
+
+ $old = $params['old_client_policy_data'];
+ $new = $params['new_client_policy_data'];
+
+ $data = [];
+
+ // Check differences and prepare update data
+ $fields_to_check = [
+ 'client_branch_id', 'policy_type', 'insurer_id', 'insurer_branch_id',
+ 'cd_ac_pk', 'policy_end_date', 'policy_start_date', 'tpa_id', 'tpa_branch_id'
+ ];
+
+ foreach ($fields_to_check as $field) {
+ if (isset($new[$field]) && isset($old[$field]) && $new[$field] != $old[$field]) {
+ $data[$field] = $new[$field];
+ }
+ }
+
+ if (empty($data)) {
+ $this->myLogger->logme("error", "No changes detected in client policy update.");
+ return ['status' => "Failed", 'message' => "No changes detected in policy data."];
+ }
+
+ // Fetch related policy transactions
+ $policy_transactions = $this->policyTransactionModel
+ ->where('is_active', 1)
+ ->where('client_policy_id', $new['id'])
+ ->findAll();
+
+ $updated_pt_ids = [];
+
+ if (!empty($policy_transactions)) {
+
+ // Update each policy transaction and track affected IDs
+ foreach ($policy_transactions as $pt) {
+ $result = $this->policyTransactionModel
+ ->where('id', $pt['id'])
+ ->set($data)
+ ->update();
+
+ if ($this->policyTransactionModel->affectedRows() > 0) {
+ $updated_pt_ids[] = $pt['id'];
+ }
+ }
+
+ if (empty($updated_pt_ids)) {
+ $this->myLogger->logme("error", "No policy_transaction records were updated.");
+ return ['status' => "Failed", 'message' => "No records updated."];
+ }
+
+ // If insurer-related fields are updated, update co-share table as well
+ if (isset($data['insurer_id']) && !empty($data['insurer_id'])) {
+ $co_share_result = $this->updatePTCoShareTableEntry($policy_transactions, $old, $data);
+ $this->myLogger->logme("error", "PT co-share update result: " . json_encode($co_share_result));
+ }
+
+ $this->myLogger->logme("error", "Policy transaction(s) updated successfully. Updated IDs: " . json_encode($updated_pt_ids));
+
+ return [
+ 'status' => "Success",
+ 'message' => "Policy transaction(s) updated.",
+ 'updated_ids' => $updated_pt_ids
+ ];
+
+ } else {
+ $this->myLogger->logme("error", "No active policy_transaction records found for update.");
+ return ['status' => "Failed", 'message' => "No active policy_transaction records found."];
+ }
+
+ } catch (\Throwable $e) {
+ $this->myLogger->logme("error", "Exception during policy_transaction update: " . $e->getMessage());
+ return [
+ 'status' => "Failed",
+ 'message' => "An error occurred during update.",
+ 'error' => $e->getMessage()
+ ];
+ }
+ }
+
+
+ private function updatePTCoShareTableEntry($policy_transaction_data, $old_client_policy_data, $data)
+ {
+ $updated_ids = [];
+ $errors = [];
+
+ foreach ($policy_transaction_data as $value) {
+ $pt_id = $value['id'];
+
+ try {
+ // Find matching rows
+ $rows = $this->PTCOShareDetailsModel
+ ->where('pt_id', $pt_id)
+ ->where('insurer_id', $old_client_policy_data['insurer_id'])
+ ->where('insurer_branch_id', $old_client_policy_data['insurer_branch_id'])
+ ->where('is_active', 1)
+ ->findAll();
+
+ foreach ($rows as $row) {
+ // Update each row individually
+ $result = $this->PTCOShareDetailsModel
+ ->where('id', $row['id'])
+ ->set([
+ 'insurer_id' => $data['insurer_id'],
+ 'insurer_branch_id' => $data['insurer_branch_id'],
+ ])
+ ->update();
+
+ // Check if the update was successful
+ if ($this->PTCOShareDetailsModel->affectedRows() > 0) {
+ $updated_ids[] = $row['id'];
+ } else {
+ $errors[] = "No change or failed update for ID {$row['id']}";
+ }
+ }
+
+ } catch (\Exception $e) {
+ $errors[] = "Error updating pt_id {$pt_id}: " . $e->getMessage();
+ }
+ }
+
+ return [
+ 'updated_ids' => $updated_ids,
+ 'errors' => $errors,
+ ];
+ }
+
+
public function uploadVehicleFile()
@@ -4563,6 +4666,11 @@ class ClientController extends AdminController
public function sendextraparam()
{
+ // $data = db_connect()->table('jobs')->where('id', 1677)->get()->getRowArray();
+ // // dd($data);
+ // $return = $this->updatePolicyTransactionDataWhileClinetPolicyUpdate(json_decode($data['payload'], true));
+ // dd($return);
+ // die;
// $employeeController = new EmployeeController();
// $employeeController->truncateFileData('633');
@@ -4578,7 +4686,7 @@ class ClientController extends AdminController
$empServiceController = new EmployeeServiceController();
// $res = $empServiceController->excelFileFormatValidation(['file_id' => '865']);
// $res = $empServiceController->excelFileDataValidation(['file_id' => '865']);
- // $res = $empServiceController->employeesSIEnhanceProcess(['file_id' => '829']);
+ // $res = $empServiceController->employeesSIEnhanceProcess(['file_id' => '978']);
// $res = $empServiceController->employeeDisembark(['file_id' => '858']);
$policyTransactionController = new PolicyTransactionController();
@@ -4612,6 +4720,7 @@ class ClientController extends AdminController
// $EmpDataServiceController->importDeletionValidation(['file_id' => 304]); //for live
// $EmpDataServiceController->importSIEnhancementUpdateEndorsementID(['file_id' => 1199]); //for live
// $EmpDataServiceController->importSIEnhancementValidation(['file_id' => 1205]); //for live
+ $EmpDataServiceController->importInceptionUpdateTPAandUHID(['file_id' => 214]); //for live
// $result = $this->employeePolicyModel->getDeletionEmployeeDataForExportExcel($batch_data);
// print_rr($result); die;
@@ -4636,12 +4745,12 @@ class ClientController extends AdminController
// $EmpDataServiceController->importDeletionUpdateEndorsementID(['file_id' => 171]);
// $EmpDataServiceController->importCorrectionUpdateEndorsementID(['file_id' => 188]);
- $params = [
- 'client_policy_id' => 6090,
- 'action_type' => "inception",
- ];
- $res = $EmpDataServiceController->makeEntryForBDSPolicyTransaction($params);
- dd($res);
+ // $params = [
+ // 'client_policy_id' => 6090,
+ // 'action_type' => "inception",
+ // ];
+ // $res = $EmpDataServiceController->makeEntryForBDSPolicyTransaction($params);
+ // dd($res);
// $array = [
// "employeeIds" => ["12800", "12798", "12797", "12799"],
@@ -4677,7 +4786,7 @@ class ClientController extends AdminController
// $returndata = $LeadsController->convertQCRJsonToPolicyTerms($jsonArray, $policy_type, $proposel_name, $insurer_name);
// dd($returndata);
- $LeadsController->handleMemberDataGPATotalSumInsurerFromExcel(['lead_id' => 169]);
+ // $LeadsController->handleMemberDataGPATotalSumInsurerFromExcel(['lead_id' => 169]);
// -----------BDS REPORT CONTROLLER---------------------------------------------------------------------------------
diff --git a/app/Controllers/EmpDataServiceController.php b/app/Controllers/EmpDataServiceController.php
index 5709b0ae..cb93e213 100755
--- a/app/Controllers/EmpDataServiceController.php
+++ b/app/Controllers/EmpDataServiceController.php
@@ -447,7 +447,7 @@ class EmpDataServiceController extends BaseController
];
//for addition and dependent addition adding a ENDORSEMENT NO column
- if(in_array($export_data['event_type'], ['addition', 'dependent_addition'])){
+ if(in_array($export_data['event_type'], ['addition', 'dependent_addition', 'missed_inception'])){
$excel_header_columns[] = [
'column_index' => 18,
'column_name' => 'ENDORSEMENT NO',
@@ -1404,7 +1404,7 @@ class EmpDataServiceController extends BaseController
'TOTAL AMOUNT',
];
- if(in_array($file['event_type'], ['addition', 'dependent_addition'])){
+ if(in_array($file['event_type'], ['addition', 'dependent_addition', 'missed_inception'])){
$inceptionHeader[] = 'ENDORSEMENT NO';
}
@@ -1566,6 +1566,17 @@ class EmpDataServiceController extends BaseController
}
}
+ 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][] = [
@@ -1900,6 +1911,27 @@ class EmpDataServiceController extends BaseController
$emp_details[] = array('id' => $result['id'], 'tpa_id' => $value[13], 'uhid' => $value[14]);
}
+ 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.employee_id = 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])){
@@ -1929,7 +1961,9 @@ class EmpDataServiceController extends BaseController
->first();
if (!empty($result_for_endorsement) && count($result_for_endorsement)) {
- $enrollment_file_id = $result_for_endorsement['file_id']; //files table primary key
+ 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');
}
}
@@ -1945,7 +1979,6 @@ class EmpDataServiceController extends BaseController
if(in_array($file['event_type'], ['addition', 'dependent_addition']) && !empty($emp_endorsement_table_data)){
$this->employeePolicyModel->updateEmpEndorsementAddition($emp_endorsement_table_data);
- $this->storeEndorsementNumber($file_id, $endorsement_id, $enrollment_file_id);
}
// Update batch file status and amount
@@ -1962,6 +1995,11 @@ class EmpDataServiceController extends BaseController
//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);
@@ -2388,7 +2426,9 @@ class EmpDataServiceController extends BaseController
if (isset($result['id']) && $result['id'] !== null) {
// return $result;
- $enrollment_file_id = $result['file_id'];
+ if(empty($enrollment_file_id)){
+ $enrollment_file_id = $result['file_id'];
+ }
if($result['field_name'] == 'dob'){
$value[8] = change_date_format($value[8]);
@@ -2967,7 +3007,10 @@ class EmpDataServiceController extends BaseController
if (isset($result['id']) && $result['id'] !== null) {
- $enrollment_file_id = $result['file_id'];
+ 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');
@@ -3472,7 +3515,9 @@ class EmpDataServiceController extends BaseController
if (isset($result['emp_endorsement_primarykey']) && $result['emp_endorsement_primarykey'] !== null) {
- $enrollment_file_id = $result['file_id']; //files table primary key
+ 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']);
@@ -4735,6 +4780,14 @@ class EmpDataServiceController extends BaseController
return ['status' => "Failed", 'message' => "Action type is missing or empty", 'data' => ['params' => $params]];
}
+ //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;
+ }
+
+ //get the policy data
$policy_data = $this->clientPolicyModel
->where('id', $params['client_policy_id'])
->where('is_active', 1)
@@ -4745,6 +4798,7 @@ class EmpDataServiceController extends BaseController
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)
@@ -4752,13 +4806,15 @@ class EmpDataServiceController extends BaseController
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]];
+ // 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) {
@@ -4774,20 +4830,23 @@ class EmpDataServiceController extends BaseController
// $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();
+ // get the lead installment data
- 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));
+ 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();
- $installment_ids = $this->constructInstallmentData($lead_installment_data, $insert_id);
+ if (!empty($lead_installment_data) && (isset($params['action_type']) && $params['action_type'] == "inception")) {
- $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));
+ $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]];
@@ -4804,6 +4863,11 @@ class EmpDataServiceController extends BaseController
private function constructBDSData($policy_data, $lead_data, $params)
{
+ $action_type_string = $params['action_type'];
+ if(in_array($params['action_type'], ['dependent_addition', 'missed_inception'])){
+ $action_type_string = "addition";
+ }
+
$policyTransactionData = [
'issuer' => 2,
@@ -4834,12 +4898,13 @@ class EmpDataServiceController extends BaseController
'is_cd_reduce_from_bds' => 0,
'client_type_id' => 0,
- 'status' => "completed",
- 'action_type' => $params['action_type'] ?? null,
+ 'status' => "co_insurer_pending",
+ 'action_type' => $action_type_string ?? null,
'endorsement_no' => $params['endorsement_no'] ?? null,
- 'issue_type' => $lead_data['lead_type'] ?? 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']) ?? null,
+ 'tsi' => generate_tsi_code($lead_data['lead_type'] ?? 1) ?? null,
'installment' => $lead_data['no_of_installment'] ?? null,
];
@@ -4877,12 +4942,138 @@ class EmpDataServiceController extends BaseController
}
}
-
-
- public function retriveBDSPolicyTransactionEntry()
+ 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 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]];
+ }
}
+
+
+
}
diff --git a/app/Controllers/EmployeeController.php b/app/Controllers/EmployeeController.php
index 0bcc03c5..e5281998 100755
--- a/app/Controllers/EmployeeController.php
+++ b/app/Controllers/EmployeeController.php
@@ -1384,6 +1384,13 @@ class EmployeeController extends AdminController
$this->myLogger->logme('error', 'cash_deposite table updated -- cd transaction');
}
+ //this job for deactive policy transaction and pt co share table entry for BDS Sync
+ $r = Jobs::addJob(['job_name' => 'removeBDSPolicyTransactionEntryFromTruncate', 'payload' => [
+ 'client_policy_id' => $client_policy_id ?? null,
+ 'file_id' => $file_id ?? null,
+ 'action_type' => $file['action'] ?? null,
+ ]]);
+
}else{
$this->myLogger->logme('error', '---- There is no data to truncate ----');
@@ -1534,6 +1541,13 @@ class EmployeeController extends AdminController
}
+ //this job for deactive policy transaction and pt co share table entry for BDS Sync
+ $r = Jobs::addJob(['job_name' => 'removeBDSPolicyTransactionEntryFromTruncate', 'payload' => [
+ 'client_policy_id' => $client_policy_id ?? null,
+ 'file_id' => $file_id ?? null,
+ 'action_type' => $file['action'] ?? null,
+ ]]);
+
$this->myLogger->logme('error', 'SUCCESSFULLY TRUNCATED');
return $this->respond(['dataStatus' => true, 'code' => 200, 'data' => 'success'], 200);
diff --git a/app/Controllers/EmployeeServiceController.php b/app/Controllers/EmployeeServiceController.php
index 5d65c4a4..5584d67c 100755
--- a/app/Controllers/EmployeeServiceController.php
+++ b/app/Controllers/EmployeeServiceController.php
@@ -153,7 +153,7 @@ class EmployeeServiceController extends AdminController
'is_mandatory' => ['I', 'A', 'DA'],
'data_type' => 'str',
'format' => null,
- 'allowed_values' => null,
+ 'allowed_values' => ['Self', 'Spouse', 'Son', 'Daughter', 'Father', 'Mother', 'Father in Law', 'Mother in Law'],
'custom' => 'check_relationship',
'params' => ['row', 'relationship', 'policy_terms']
],
@@ -1587,9 +1587,17 @@ class EmployeeServiceController extends AdminController
{
$pre_rack_rate_name = $slab_value['rack_rate_name'];
$rack_rate_json = json_decode($slab_value['additional_relationship'], true);
- $relationship_array_key = strtolower($employee['relationship']);
+ $relationship_array_key = strtolower(trim($employee['relationship']));
- if(array_key_exists($relationship_array_key, $rack_rate_json) && $rack_rate_json[ strtolower($employee['relationship']) ] != 0 && $rack_rate_json[ strtolower($employee['relationship']) ] != 'NA')
+ if (in_array($relationship_array_key, ['son', 'daughter'])) {
+ $relationship_array_key = 'childrens';
+ } elseif (in_array($relationship_array_key, ['father', 'mother'])) {
+ $relationship_array_key = 'parents';
+ } elseif (in_array($relationship_array_key, ['father in law', 'mother in law', 'father-in-law', 'mother-in-law'])) {
+ $relationship_array_key = 'parents-in-law';
+ }
+
+ if(array_key_exists($relationship_array_key, $rack_rate_json) && $rack_rate_json[$relationship_array_key] != 0 && $rack_rate_json[$relationship_array_key] != 'NA')
{
$applicable_rack_rate_name = $slab_value['rack_rate_name'];
$applicable_rack_rate_master = $slab_value['grid_master'];
@@ -1623,6 +1631,7 @@ class EmployeeServiceController extends AdminController
}
+
$this->fileModel->where('id', $file_id)->set(['status' => 'success','reason' => ''])->update();
$this->myLogger->logme("error",'{file_id} uploaded success',['file_id' => $file_id]);
//set success msg to pull notifications
diff --git a/app/Controllers/JobWorker.php b/app/Controllers/JobWorker.php
index c471a9e6..4cbf5350 100755
--- a/app/Controllers/JobWorker.php
+++ b/app/Controllers/JobWorker.php
@@ -124,8 +124,12 @@ class JobWorker extends AdminController
'handler' => 'App\Controllers\EmpDataServiceController',
],
'makeEntryForBDSPolicyTransaction' => [
- 'type' => 'CC', // Handler Category
- 'handler' => 'App\Controllers\EmpDataServiceController',
+ 'type' => 'CC', // Handler Category
+ 'handler' => 'App\Controllers\EmpDataServiceController',
+ ],
+ 'removeBDSPolicyTransactionEntryFromTruncate' => [
+ 'type' => 'CC', // Handler Category
+ 'handler' => 'App\Controllers\EmpDataServiceController',
],
'employeesEnrollmentInsert' => [
'type' => 'CC', // Handler Category
@@ -134,7 +138,11 @@ class JobWorker extends AdminController
'calculateMembersDemography' => [
'type' => 'CC', // Handler Category
'handler' => 'App\Controllers\LeadsController',
- ]
+ ],
+ 'updatePolicyTransactionDataWhileClinetPolicyUpdate' => [
+ 'type' => 'CC', // Handler Category
+ 'handler' => 'App\Controllers\ClientController',
+ ],
];
diff --git a/app/Helpers/excel_util_helper.php b/app/Helpers/excel_util_helper.php
index 67ffc9b1..99c08108 100755
--- a/app/Helpers/excel_util_helper.php
+++ b/app/Helpers/excel_util_helper.php
@@ -1769,7 +1769,7 @@ if(!function_exists('check_dup_mobileno'))
{
foreach($existing_mobilenos as $k => $value)
{
- if ($row['12'] == $value['mobile']) {
+ if (strtolower($row['5']) == 'self' && $row['12'] == $value['mobile']) {
return array('status' => false,'error' => "Duplicate Mobile No");
// break;
}
@@ -1784,7 +1784,7 @@ if(!function_exists('check_dup_email'))
{
foreach($existing_mobilenos as $k => $value)
{
- if ($row['13'] == $value['email_corporate']) {
+ if (strtolower($row['5']) == 'self' && $row['13'] == $value['email_corporate']) {
return array('status' => false,'error' => "Duplicate Email");
// break;
}
diff --git a/app/Models/EndorsementModel.php b/app/Models/EndorsementModel.php
index 22bcec72..60b675cb 100644
--- a/app/Models/EndorsementModel.php
+++ b/app/Models/EndorsementModel.php
@@ -24,6 +24,7 @@ class EndorsementModel extends Model
'created_at',
'updated_by',
'updated_at',
+ 'file_id',
'is_active'
];
diff --git a/app/Views/newClientModal.php b/app/Views/newClientModal.php
index c4285aac..9a56eaa5 100644
--- a/app/Views/newClientModal.php
+++ b/app/Views/newClientModal.php
@@ -149,8 +149,13 @@
// If GST is currently validating, wait for it to complete
if (isGSTValidating) {
- toastr.info('Please wait while we validate your GST number...', 'Validating');
- return;
+ if($('#Owner_type').val() == 1){
+ toastr.info('Please wait while we validate your GST number...', 'Validating');
+ return;
+ }else if ($('#client_type').val() == 1){
+ toastr.info('Please wait while we validate your GST number...', 'Validating');
+ return;
+ }
}
// If GST validation failed, prevent submission
@@ -171,14 +176,30 @@
$('#aadhar').attr('data-parsley-required', 'false');
$('#aadhar').removeAttr('required');
+ if($('#Owner_type').val() == 2){
+ $('#gst').removeAttr('required');
+ }
+
isClientFormSubmitting = true;
var isValid = $('#client_form').parsley().validate();
- if (!isValid) {
- console.log('Form is Empty', 'Warning');
- return ;
+
+ if (!isValid) {
+ var emptyFieldIds = [];
+
+ $('#client_form').parsley().fields.forEach(function(field) {
+ if (!field.isValid()) {
+ var elem = field.$element;
+ var id = elem.attr('id') || elem.attr('name');
+ emptyFieldIds.push(id);
+ }
+ });
+
+ console.log('Empty/Invalid Fields:', emptyFieldIds);
+ return;
}
+
form_action = '= base_url("util/createClientWithMinimalData"); ?>';
$('.loader').fadeIn();
@@ -212,24 +233,22 @@
if(form_type != 1){
setTimeout(function(){
+
$('#client_id').val(res.client_id).change();
$('#client_id').prepend($('