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

This commit is contained in:
Gowtham M 2025-06-26 09:50:58 +05:30
commit c127b088f6
13 changed files with 333 additions and 101 deletions

View File

@ -4223,24 +4223,46 @@ class ClientController extends AdminController
}
public function get_client_policy_data_using_policy_no()
{
{
$received_data = $this->request->getGet();
$policy_no = $this->request->getGet('policy_no');
$client_id = $this->request->getGet('client_id');
$client_branch_id = $this->request->getGet('client_branch_id');
$policy_type_id = $this->request->getGet('policy_type_id');
$data = $this->clientPolicyModel
->select("
client_policy.*,
policy_type.policy_type,
clients.client_type,
clients.client_name,
DATE_FORMAT(client_policy.policy_start_date, '%d/%m/%Y') as policy_start_date,
DATE_FORMAT(client_policy.policy_end_date, '%d/%m/%Y') as policy_end_date
")
->join('clients', 'client_policy.client_id = clients.id')
->join('policy_type', 'client_policy.policy_type_id = policy_type.id')
->where('client_policy.policy_no', $policy_no)
->where('client_policy.is_active', 1)
->where('client_policy.policy_status', 1)
->first();
if ($data) {
return $this->respond(['status' => true, 'data' => $data, 'code' => 200], 200);
if ($data['client_id'] == $client_id && $data['client_branch_id'] == $client_branch_id) {
if ($data['policy_type_id'] == $policy_type_id) {
return $this->respond(['status' => true, 'data' => $data, 'code' => 200, 'received_data' => $received_data], 200);
} else {
$policy_type = $this->policyTypeModel->where('id', $policy_type_id)->first();
$message = 'This policy number is mapped to the selected client with policy type: ' . (!empty($data['policy_type']) ? $data['policy_type'] : 'N/A') . '. You selected: ' . (!empty($policy_type['policy_type']) ? $policy_type['policy_type'] : 'N/A') . '. Please check.';
return $this->respond(['status' => true, 'data' => $data, 'code' => 409, "message" => $message, 'received_data' => $received_data], 200);
}
} else {
$message = 'This policy number is already linked to another client' . (!empty($data['client_name']) ? '. Client name : ' . $data['client_name'] : '') . '. Please check';
return $this->respond(['status' => true, 'code' => 409, "message" => $message, 'received_data' => $received_data, 'db_data' => $data], 200);
}
} else {
return $this->respond(['status' => false, 'message' => 'No Data Found', 'code' => 404], 200);
return $this->respond(['status' => false, 'message' => 'No Data Found', 'code' => 404, 'received_data' => $received_data], 200);
}
}

View File

@ -1918,7 +1918,7 @@ class EmpDataServiceController extends BaseController
$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
->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)

View File

@ -344,9 +344,11 @@ class EmployeeController extends AdminController
$query->where('cr.user_id', $user_id);
}
// ->where('files.created_by', get_session_userid())
$data['fileList'] = $query->groupBy("c.id")->orderBy('files.created_at', 'desc')
->limit(1500)
$data['fileList'] = $query->groupBy("files.id")->orderBy('files.created_at', 'desc')
// $data['fileList'] = $query
->limit(2000)
->find();
// dd($this->fileModel->getLastQuery());
// dd($data['fileList']);
$query2 = $this->batchFileModel->select("
@ -395,7 +397,7 @@ class EmployeeController extends AdminController
$query2->where('cr.user_id', $user_id);
}
// ->where('files.created_by', get_session_userid())
$data['batch_list'] = $query2->groupBy("clients.id")->orderBy('batch_files.id', 'desc')
$data['batch_list'] = $query2->groupBy("batch_files.id")->orderBy('batch_files.id', 'desc')
->limit(1500)
->find();

View File

@ -493,7 +493,7 @@ class LeadsController extends BaseController
{
if ($this->leadsModel->where('id', $id)->set($data[0])->update()) {
$this->insertMultiFilesData($data[0]['multi_file_data'], $id);
$this->insertMultiFilesData($data[0]['multi_file_data'], $id, $data[0]['lead_form_type']);
$this->insertLeadStatus($id, $data[0]['status'], 3);
return $this->respond(['status' => true, 'lead_id' => $id, 'message' => "Lead updated successfully", 'data' => $data], 200);
}
@ -591,14 +591,18 @@ class LeadsController extends BaseController
return $multi_file_data;
}
public function insertMultiFilesData($data, $lead_id)
public function insertMultiFilesData($data, $lead_id, $lead_form_type = null)
{
// print_r($data); die;
log_message('info', 'insertMultiFilesData() called with lead_id: ' . $lead_id);
if (!empty($data)) {
log_message('info', 'Data is not empty. Total items: ' . count($data));
foreach ($data as $key => $value) {
log_message('info', "Processing item at index {$key}: " . json_encode($value));
if (!empty($value['id'])) {
log_message('info', "Record with ID {$value['id']} exists. Preparing to update.");
$lead_file_data = [
'lead_id' => $lead_id,
@ -607,10 +611,22 @@ class LeadsController extends BaseController
if (!empty($value['file_name'])) {
$lead_file_data['file_name'] = $value['file_name'];
log_message('info', "file_name found: {$value['file_name']}");
if (!empty($lead_form_type) && $lead_form_type == 1 && $key == 0) {
//for this push the job to the calculateMembersDemography() function
$job_details = new Jobs();
$r = Jobs::addJob(['job_name' => 'calculateMembersDemography', 'payload' => [
'lead_id' => $lead_id,
]]);
log_message('info', "calculateMembersDemography JOB PUSHED");
}
}
log_message('info', "Updating leadFilesModel where id = {$value['id']} with data: " . json_encode($lead_file_data));
$this->leadFilesModel->where('id', $value['id'])->set($lead_file_data)->update();
} else {
log_message('info', "No ID found. Preparing to insert new record.");
if (!empty($value['file_name'])) {
$lead_file_data = [
@ -618,16 +634,24 @@ class LeadsController extends BaseController
'docs_name' => $value['docs_name'],
'file_name' => $value['file_name'],
];
log_message('info', "Inserting into leadFilesModel: " . json_encode($lead_file_data));
$this->leadFilesModel->insert($lead_file_data);
} else {
log_message('warning', "Skipped insert: file_name missing in data at index {$key}");
}
}
if ($key == 0 && !empty($value['file_name'])) {
log_message('info', "Setting first file_name '{$value['file_name']}' to leadsModel for lead_id: {$lead_id}");
$this->leadsModel->where('id', $lead_id)->set('file_name', $value['file_name'])->update();
}
}
} else {
log_message('warning', 'insertMultiFilesData() received empty data array.');
}
log_message('info', 'insertMultiFilesData() completed successfully.');
return true;
}
@ -1286,9 +1310,9 @@ class LeadsController extends BaseController
'Policy Run Days' => $rfq_data['policy_run_days'],
'Inception Premium' => formatIndianCurrency($rfq_data['premium_at_inception']),
'Premium as on (' . date('d-m-Y', strtotime($rfq_data['incurred_claims_date'])) . ')' => formatIndianCurrency($rfq_data['premium_date']),
'Earned Premium' => $rfq_data['earned_premium'],
'Earned Premium' => formatIndianCurrency(intval($rfq_data['earned_premium'])),
'Incurred Claims as on (' . date('d-m-Y', strtotime($rfq_data['incurred_claims_date'])) . ')' => formatIndianCurrency($rfq_data['incurred_claims']),
'Annualised Claims' => formatIndianCurrency($rfq_data['annualised_claims']),
'Annualised Claims' => formatIndianCurrency(intval($rfq_data['annualised_claims'])),
'Incurred Claims Ratio' => $rfq_data['incurred_claims_ratio'] . " %",
'Earned Claims Ratio' => $rfq_data['earned_claims_ratio'] . " %",
];

View File

@ -2037,8 +2037,8 @@ class PolicyTransactionController extends BaseController
//insurer statement list page
public function statementList()
{
// dd($this->validateInsurerStatement(['file_id' => 30]));
// $data['insurers'] = $this->insurerModel->where('is_active',1)->findAll();
// dd($this->validateInsurerStatement(['file_id' => 49]));
$data['insurers'] = $this->insurerModel->where('is_active',1)->findAll();
$today = date('Y-m-d');
$fromday = $from_date = date('Y-m-d', strtotime('-180 days', strtotime($today)));
// echo $fromday;die();
@ -2261,13 +2261,13 @@ class PolicyTransactionController extends BaseController
// dd($highestRowAndColumn);
$excel_data = $sheet->rangeToArray('A1:' . $highestRowAndColumn['column'] . $highestRowAndColumn['row']);
unset($excel_data[0]);
// Kint::dump($excel_data);
// Kint::dump($excel_data);die();
//get no of line items and update in DB
$line_items = 0;
// get uploaded month transactions data
$source_data = $this->PTCOShareDetailsModel->getNonReconcileredPolicyTransactions(insurer_id: $file['insurer_id'], insurer_branch_id: $file['branch_id']);
// var_dump($source_data);die();
// Kint::dump($source_data);//die();
// Kint::dump($source_data);die();
// check policy no,insurer and etc in DB for this month
@ -2277,17 +2277,24 @@ class PolicyTransactionController extends BaseController
if (!$is_row_empty) {
// $excel_row = ExcelSanitizeHelper::sanitizeArrayData($excel_row);
$is_source_found = 0;
// Kint::dump($excel_key,$excel_row[1],$excel_row[2]);
$policy_start_date = preg_replace('/^\p{Z}+|\p{Z}+$/u', '', $excel_row[4]); //policy_start_date from excel
$policy_end_date = preg_replace('/^\p{Z}+|\p{Z}+$/u', '', $excel_row[5]); //policy_end_date from excel
$policy_no = preg_replace('/^\p{Z}+|\p{Z}+$/u', '', $excel_row[1]); //policy_end_date from excel
$policy_no = preg_replace('/[\x{200C}\x{200B}]/u', '', $excel_row[1]); //policy_end_date from excel
$policy_no = preg_replace( '/[\x{200B}\x{200C}\x{200D}\x{FEFF}\x{00A0}\x{200E}\x{200F}\x{202A}-\x{202E}]/u', '', $excel_row[1]); //policy_end_date from excel
$client_name = preg_replace('/^\p{Z}+|\p{Z}+$/u', '', $excel_row[3]); //clientname from excel
$endorsement_no = preg_replace('/^\p{Z}+|\p{Z}+$/u', '', $excel_row[2]); //policy_end_date from excel
// Kint::dump($policy_no);
$endorsement_no = preg_replace( '/[\x{200B}\x{200C}\x{200D}\x{FEFF}\x{00A0}\x{200E}\x{200F}\x{202A}-\x{202E}]/u', '', $excel_row[2]); //policy_end_date from excel
// Kint::dump($excel_key,$policy_no,$endorsement_no,$policy_start_date,$policy_end_date);//die();
foreach ($source_data as $source_key => $source_row) {
$source_endorsement_no = $source_row['endorsement_no'] !== null ? $source_row['endorsement_no'] : null;
// Kint::dump($source_endorsement_no);
if (($policy_no == $source_row['policy_no']) && $endorsement_no == $source_endorsement_no && change_date_format($policy_start_date, 'd-m-Y', 'Y-m-d') == $source_row['policy_start_date'] && change_date_format($policy_end_date, 'd-m-Y', 'Y-m-d') == $source_row['policy_end_date'] && $client_name == $source_row['client_name']) {
if (($policy_no == $source_row['policy_no']) && $endorsement_no == $source_endorsement_no && change_date_format($policy_start_date, 'd-m-Y', 'Y-m-d') == $source_row['policy_start_date'] && change_date_format($policy_end_date, 'd-m-Y', 'Y-m-d') == $source_row['policy_end_date'] && $client_name == $source_row['client_name'])
{
$is_source_found = 1;
$line_items = $line_items + 1;
unset($source_data[$source_key]);

View File

@ -0,0 +1,59 @@
<?php
namespace App\Models;
use CodeIgniter\Model;
class HRAccessControlModel extends Model
{
protected $table = 'hr_access_control';
protected $primaryKey = 'id';
protected $allowedFields = [
'id',
'pre_hr_id',
'post_hr_id',
'allowed_modules',
'allowed_pre_policies',
'allowed_active_policies',
'allowed_cd',
'created_at',
'created_by',
'updated_at',
'updated_by',
'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;
}
}

View File

@ -112,6 +112,7 @@ class UserModel extends Model
->join('user_teams', 'user_profiles.id = user_teams.user_id')
->where('user_profiles.id', $user_id)
->where('user_teams.is_active', 1)
->where("user_profiles.is_active", 1)
->get()
->getResultArray();

View File

@ -1423,7 +1423,9 @@
console.log('Policy Run Days (Final):', policy_run_days);
let annualised_claims = policy_run_days > 0 ? (incurred_claims / policy_run_days) * 365 : 0;
let annualised_claims_roundoff = Math.round(annualised_claims);
// let annualised_claims_roundoff = annualised_claims.toFixed(2);
let annualised_claims_roundoff = Math.trunc(annualised_claims);
console.log('Annualised Claims:', annualised_claims);
console.log('Annualised Claims (Rounded):', annualised_claims_roundoff);
$('#annualised_claims').val(annualised_claims_roundoff);
@ -1431,22 +1433,24 @@
let premium_as_on_date = Number($('#premium_date').val()) || 0;
console.log('Premium as on Date:', premium_as_on_date);
let incurred_claim_ratio = (annualised_claims > 0 && premium_as_on_date > 0)
? (annualised_claims / premium_as_on_date)
let incurred_claim_ratio = (incurred_claims > 0 && premium_as_on_date > 0)
? (incurred_claims / premium_as_on_date) * 100
: 0;
let incurred_claim_ratio_roundoff = isFinite(incurred_claim_ratio) ? Math.round(incurred_claim_ratio) : 0;
let incurred_claim_ratio_roundoff = isFinite(incurred_claim_ratio) ? incurred_claim_ratio.toFixed(2) : 0;
console.log('Incurred Claim Ratio:', incurred_claim_ratio);
console.log('Incurred Claim Ratio (Rounded):', incurred_claim_ratio_roundoff);
$('#incurred_claims_ratio').val(incurred_claim_ratio_roundoff);
let earned_premium = premium_as_on_date > 0 ? (premium_as_on_date / 365) * 364 : 0;
let earned_premium_roundoff = Math.round(earned_premium);
let earned_premium = premium_as_on_date > 0 ? (premium_as_on_date / 365) * policy_run_days : 0;
// let earned_premium_roundoff = earned_premium.toFixed(2);
let earned_premium_roundoff = Math.trunc(earned_premium);
console.log('Earned Premium:', earned_premium);
console.log('Earned Premium (Rounded):', earned_premium_roundoff);
$('#earned_premium').val(earned_premium_roundoff);
let earnedClaimsRatio = earned_premium > 0 ? annualised_claims / earned_premium : 0;
let earnedClaimsRatioRounded = Math.round(earnedClaimsRatio);
let earnedClaimsRatio = premium_as_on_date > 0 ? (annualised_claims / premium_as_on_date) * 100 : 0;
let earnedClaimsRatioRounded = earnedClaimsRatio.toFixed(2);
console.log('Earned Claims Ratio:', earnedClaimsRatio);
console.log('Earned Claims Ratio (Rounded):', earnedClaimsRatioRounded);
$('#earned_claims_ratio').val(earnedClaimsRatioRounded);

View File

@ -1391,6 +1391,8 @@ function appendGridtHtml(ui_type = false, secondary = false, data = false)
console.log('appendGridtHtml function ui_type', ui_type);
console.log('appendGridtHtml function secondary', secondary);
console.log('appendGridtHtml function typeof secondary', typeof secondary);
var default_unit = $('#hidden_unit').val();
// alert(default_unit);
// console.log('appendGridtHtml function data.unit', data.unit);
// console.log('appendGridtHtml function data.unit type',typeof data.unit);

View File

@ -3838,6 +3838,15 @@ $('#policy_no').change(function(){
var policy_no = $(this).val();
policy_no = policy_no.trim();
let client_id = $('#client_id').val()?.trim();
let client_branch_id = $('#client_branch_id').val()?.trim();
let policy_type_id = $('#policy_type_id').val()?.trim();
if (!client_id || !client_branch_id || !policy_type_id) {
toastr.warning('Please select the policy type, client and branch', "WARNING");
$('#policy_no').val('');
return;
}
$pt_id = $('#policy_tranction_policy_number').val();
console.log('$pt_id', $pt_id);
@ -3846,13 +3855,19 @@ $('#policy_no').change(function(){
$.ajax({
url: '<?php echo base_url('util/get_client_policy_data_using_policy_no/');?>',
type: "GET",
data : { policy_no : policy_no },
data : { policy_no : policy_no, client_id : client_id, client_branch_id : client_branch_id, policy_type_id : policy_type_id},
dataType: 'json',
success: function (res) {
console.log('get_client_policy_data_using_policy_no response', res)
if(res.status == true){
if(res.status == true && res.code == 409){
toastr.warning(res.message,'WARNING');
$('#policy_no').val("");
return;
}
if(res.status == true){
$('#ct_type').val(1);
$('#client_policy_id').val(res.data.id);
$('#policy_start_date').val(res.data.policy_start_date);

View File

@ -212,8 +212,8 @@ $(document).ready(function() {
customizeData: function (data) {
for (var i = 0; i < data.body.length; i++) {
for (var j = 0; j < data.body[i].length; j++) {
// Check if the column is the 9th index (10th column)
if (j === 9) {
// Check if the column is the 9th index (10th column) and 10th index (11th column)
if (j === 9 || j === 10) {
data.body[i][j] = '\u200C' + data.body[i][j];
}
}

View File

@ -78,12 +78,12 @@
<i class="fa fa-info-circle text-primary"></i>
<div class="info-tooltip">
<strong>Formulas:</strong><br>
1. Incurred Claims = Paid Claims + Outstanding Claims<br>
2. Policy Run Days = Incurred Claim Date - Policy Start Date + 1<br>
3. Earned Premium = (Premium as on Date / 365) × 364<br>
4. Annualised Claims = (Incurred Claims / Policy Run Days) × 365<br>
5. Incurred Claim Ratio = Annualised Claims / Premium as on Date<br>
6. Earned Claims Ratio = Annualised Claims / Earned Premium
1. Incurred Claims = Paid Claims + Outstanding Claims<br>
2. Policy Run Days = Incurred Claim Date - Policy Start Date + 1<br>
3. Earned Premium = (Premium as on Date / 365) × Policy Run Days<br>
4. Annualised Claims = (Incurred Claims / Policy Run Days) × 365<br>
5. Incurred Claim Ratio = Incurred Claims / Premium as on Date<br>
6. Earned Claims Ratio = Annualised Claims / Premium as on Date
</div>
</span>
</div>

View File

@ -230,7 +230,7 @@
<?php } ?>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<a id="submitExcel" onclick="checkTheTableDataChanged(2)" class="btn btn-primary" id>Export Excel</a>
<button id="submitInternalMail" class="btn btn-primary" onclick="checkTheTableDataChanged(4)">Send Internal Mail</button>
<?php if (get_role_id() == 1 || in_array($user_team,[6,7])) { ?>
<?php if (in_array(get_role_id(), [1,5]) || in_array(BUSINESS_SUPPORT_TEAM_ID, user_team()) || in_array(MANAGEMENT_TEAM_ID, user_team())) { ?>
<button id="submitMail" class="btn btn-primary"
onclick="checkTheTableDataChanged(3)">Send Insurer Mail</button>
<?php } ?>
@ -2560,6 +2560,15 @@ function popInsurerInArray(proposal_name, insurerName) {
function changeInsurer(event) {
console.log('change insure event', event);
let proposal_name = getParentHeaderTh(event);
console.log('proposel Name', proposal_name)
if(proposal_name == null || proposal_name == ""){
toastr.warning("Could not change the insurer", "WARNING")
return;
}
// let newInsurerName = prompt("Enter New insurer name:");
const insurers = <?= json_encode($insurer); ?>;
@ -2577,77 +2586,164 @@ function changeInsurer(event) {
console.log('newInsurerName', newInsurerName)
console.log('newversion', newversion)
if (newInsurerName) {
const closestTh = event.target.closest('th');
let oldInsurerName = closestTh.innerText.split('⋮')[0].trim();
console.log(oldInsurerName + ' - ' + newInsurerName);
const closestTh = event.target.closest('th');
let oldInsurerName = closestTh.innerText.split('⋮')[0].trim();
let subThIndex = closestTh.cellIndex;
console.log(oldInsurerName + ' - ' + newInsurerName);
// Iterate over child nodes to find the text node containing "Myname"
closestTh.childNodes.forEach(node => {
if (node.nodeType === Node.TEXT_NODE && node.textContent.includes(oldInsurerName)) {
// Replace the old name with the new name
node.textContent = node.textContent.replace(oldInsurerName, newInsurerName);
if (!checkExistingInsurer(proposal_name, newInsurerName) && oldInsurerName != newInsurerName) {
Swal.fire({
title: "Insurer Dublicate Found?",
text: "Do you want version control!",
icon: "warning",
showCancelButton: true,
confirmButtonColor: "#3085d6",
cancelButtonColor: "#d33",
confirmButtonText: "Yes, Procced!"
}).then((result) => {
if (result.isConfirmed) {
let modifiedInsurerName = constructInsurerNameWithVersion(proposal_name, newInsurerName);
console.log('modifiedInsurerName', modifiedInsurerName);
changeInsurerData(event, modifiedInsurerName, dataId)
}else{
return false;
}
});
//find parent th index then it's text content
// Get the sub TH from the second header row
const table = document.getElementById('rfqTable');
const headerRows = table.querySelectorAll('thead tr');
const subTh = headerRows[1].children[subThIndex];
let accumulatedColspan = 0;
let parentTh = null;
const firstHeaderRow = headerRows[0];
// Find the parent TH for the specified sub TH index
for (let i = 0; i < firstHeaderRow.children.length; i++) {
const currentParentTh = firstHeaderRow.children[i];
const currentColspan = parseInt(currentParentTh.getAttribute('colspan')) || 1;
accumulatedColspan += currentColspan;
if (subThIndex < accumulatedColspan) {
parentTh = currentParentTh;
break;
}
}
changeInsurerForPremiumTable(event, newInsurerName, subThIndex)
let proposal_name = parentTh.innerText.split('⋮')[0].trim();
if (over_all_column_data[proposal_name]) {
// let tempInsurerList = over_all_column_data[proposal_name].insurers;
// console.log(tempInsurerList);
// if(!tempInsurerList.length) { return true; }
//replace the old insurer with the new insuren in global array
over_all_column_data[proposal_name].insurers.forEach(item => {
if (item.display_name === oldInsurerName) {
item.display_name = newInsurerName; // Replace with new name
item.ins_name = newInsurerName.split('-')[0].trim(); // Replace with new name
item.id = dataId
}
});
// console.log(tempInsurerList);
// over_all_column_data[proposal_name].insurers = tempInsurerList;
console.log('insurer name replaced in golbal variable');
console.log(over_all_column_data[proposal_name].insurers);
// over_all_column_data[proposal_name].insurers = tempInsurerList
isFormDataModified = true; // if any value changeing in the table to set true
return;
}
console.log('insurer name not replaced in golbal variable');
}else{
changeInsurerData(event, newInsurerName)
}
});
}
function changeInsurerData(event, newInsurerName, dataId){
if (newInsurerName) {
const closestTh = event.target.closest('th');
let oldInsurerName = closestTh.innerText.split('⋮')[0].trim();
let subThIndex = closestTh.cellIndex;
console.log(oldInsurerName + ' - ' + newInsurerName);
// Iterate over child nodes to find the text node containing "Myname"
closestTh.childNodes.forEach(node => {
if (node.nodeType === Node.TEXT_NODE && node.textContent.includes(oldInsurerName)) {
// Replace the old name with the new name
node.textContent = node.textContent.replace(oldInsurerName, newInsurerName);
}
});
//find parent th index then it's text content
// Get the sub TH from the second header row
const table = document.getElementById('rfqTable');
const headerRows = table.querySelectorAll('thead tr');
const subTh = headerRows[1].children[subThIndex];
let accumulatedColspan = 0;
let parentTh = null;
const firstHeaderRow = headerRows[0];
// Find the parent TH for the specified sub TH index
for (let i = 0; i < firstHeaderRow.children.length; i++) {
const currentParentTh = firstHeaderRow.children[i];
const currentColspan = parseInt(currentParentTh.getAttribute('colspan')) || 1;
accumulatedColspan += currentColspan;
if (subThIndex < accumulatedColspan) {
parentTh = currentParentTh;
break;
}
}
changeInsurerForPremiumTable(event, newInsurerName, subThIndex)
let proposal_name = parentTh.innerText.split('⋮')[0].trim();
if (over_all_column_data[proposal_name]) {
// let tempInsurerList = over_all_column_data[proposal_name].insurers;
// console.log(tempInsurerList);
// if(!tempInsurerList.length) { return true; }
//replace the old insurer with the new insuren in global array
over_all_column_data[proposal_name].insurers.forEach(item => {
if (item.display_name === oldInsurerName) {
item.display_name = newInsurerName; // Replace with new name
item.ins_name = newInsurerName.split('-')[0].trim(); // Replace with new name
item.id = dataId
}
});
// console.log(tempInsurerList);
// over_all_column_data[proposal_name].insurers = tempInsurerList;
console.log('insurer name replaced in golbal variable');
console.log(over_all_column_data[proposal_name].insurers);
// over_all_column_data[proposal_name].insurers = tempInsurerList
isFormDataModified = true; // if any value changeing in the table to set true
return;
}
console.log('insurer name not replaced in golbal variable');
}else{
toastr.warning("Could not change the insurer", "WARNING")
return;
}
}
function getParentHeaderTh(event) {
const currentTh = event.target.closest('th');
if (!currentTh) return;
const colIndex = currentTh.cellIndex;
// Get all header rows
const thead = currentTh.closest('thead');
const headerRows = thead.querySelectorAll('tr');
if (headerRows.length < 2) return; // need at least 2 header rows
const secondRowThs = headerRows[1].querySelectorAll('th');
const firstRowThs = headerRows[0].querySelectorAll('th');
// Step 1: Find actual column span index of clicked th in 2nd row
let actualColIndex = 0;
for (let i = 0; i < secondRowThs.length; i++) {
const th = secondRowThs[i];
const colspan = parseInt(th.getAttribute('colspan')) || 1;
if (th === currentTh) break;
actualColIndex += colspan;
}
// Step 2: Match it with first row <th>s
let colSpanCounter = 0;
for (let i = 0; i < firstRowThs.length; i++) {
const th = firstRowThs[i];
const colspan = parseInt(th.getAttribute('colspan')) || 1;
if (actualColIndex >= colSpanCounter && actualColIndex < colSpanCounter + colspan) {
let proposelName = th.innerText.split('⋮')[0].trim();
console.log("Parent TH Proposel innerText:", proposelName);
console.log("Parent TH Proposel textContent:", th.textContent.trim());
return proposelName;
}
colSpanCounter += colspan;
}
console.log("Parent header not found");
return null;
}
function changeState(event) {
console.log('changeState Function called')