FIX_AUTO_SAVE_TERMS : RV

This commit is contained in:
VENKATESHWARAN 2025-09-03 10:44:07 +05:30
parent 98bc8f1006
commit 329680c2fe
5 changed files with 154 additions and 48 deletions

View File

@ -2423,6 +2423,7 @@ class ClientController extends AdminController
// echo "<pre>";
// print_r($this->request->getPost());die;
$this->myLogger->logme('error', "post data : " . json_encode($this->request->getPost() ?? []));
$this->myLogger->logme('error', 'Terms CREATE function called');
/*** Client Policy Table Primary Key(ID) ***/
@ -2624,7 +2625,7 @@ class ClientController extends AdminController
}
$data['enrollment_display_key'] = $this->enrollmentGMCDisplayValueTransform();
$this->myLogger->logme('error', "contructed post data : " . json_encode($data ?? []));
// print_r($data);die;
$jsonData = json_encode($data);

View File

@ -4947,7 +4947,7 @@ class LeadsController extends BaseController
// Start table with clean styling
$html .= "<h3 style='color: #333; font-weight: 500; margin-bottom: 15px;'>{$category}</h3>";
$html .= "<table style='width: 100%; border-collapse: collapse; font-family: Arial, sans-serif; font-size: 14px;color:black;'>";
$html .= "<table data-custom-table-css='table' style='width: 100%; border-collapse: collapse; font-family: Arial, sans-serif; font-size: 14px;'>";
// Table header with light background
$html .= "<tr>";

View File

@ -775,8 +775,34 @@
console.log('autoSaveOtherTerms function called');
var formData = new FormData($('#otherPolicyTerms')[0]);
console.log("formData", formData);
// var formData = new FormData($('#otherPolicyTerms')[0]);
// console.log("formData", formData);
var form = $('#otherPolicyTerms')[0];
if (!form) {
console.error("Form #otherPolicyTerms not found");
return;
}
// Check if form has any data before proceeding
var formData = new FormData(form);
var hasData = false;
for (let [key, value] of formData.entries()) {
console.log("Key:", key, "Value:", value);
if(key == "sum_insureds"){
if (value && value.toString().trim() !== '') {
hasData = true;
break;
}
}
}
if (!hasData) {
console.warn("Form data is empty, skipping auto-save");
return;
}
var policy_form_action = '<?= base_url("client/terms/other_terms") ?>';
console.log("policy_form_action", policy_form_action);
@ -809,9 +835,9 @@
// Append the JSON string to the FormData object
formData.append('policy_terms', jsonString);
formData.forEach((value, key) => {
console.log(key + ': ' + value);
});
// formData.forEach((value, key) => {
// console.log(key + ': ' + value);
// });
$.ajax({
data: formData,

View File

@ -1943,6 +1943,34 @@
console.log("autoSaveGmcTerms function called");
// Add form validation before proceeding
var form = $('#policyJsonForm')[0];
if (!form) {
console.error("Form #policyJsonForm not found");
return;
}
// Check if form has any data before proceeding
var formData = new FormData(form);
var hasData = false;
console.log("form entries : ", formData.entries());
for (let [key, value] of formData.entries()) {
console.log("Key:", key, "Value:", value);
if(key == "sum_insured"){
if (value && value.toString().trim() !== '') {
hasData = true;
break;
}
}
}
if (!hasData) {
console.warn("Form data is empty, skipping auto-save");
return;
}
var specialConditions = [];
$(".removeDom").each(function() {
@ -1957,19 +1985,15 @@
});
}
});
console.log("specialConditions", specialConditions);
var formData = new FormData($('#policyJsonForm')[0]);
console.log("formData", formData);
// var formData = new FormData($('#policyJsonForm')[0]);
var policy_form_action = '<?= base_url("client/policy/policyGMCTerms") ?>';
console.log("policy_form_action", policy_form_action);
formData.append("special_condition_display_value", JSON.stringify(specialConditions));
// console.log('formData', formData);
formData.forEach((value, key) => {
// console.log(key + ':', value);
});
$.ajax({
data: formData,

View File

@ -617,45 +617,77 @@
let gpaJsonObjectForSpecialCondition = JSON.parse(res.data);
Object.keys(gpaJsonObjectForSpecialCondition).forEach(function(key) {
if (key.includes("gpa_special_condition_label") || key.includes(
"gpa_special_condition_input")) {
// if (key.includes("gpa_special_condition_label") || key.includes("gpa_special_condition_input")) {
// if (key.includes("gpa_special_condition_label")) {
// for (let index = 0; index <
// gpaJsonObjectForSpecialCondition[key].length; index++) {
// specialConditionForGPA();
// }
// }
// let elements = document.getElementsByName(`${key}[]`);
// if (elements) {
// elements.forEach((element, index) => {
// if (gpaJsonObjectForSpecialCondition[key][
// index
// ] == undefined) {
// element.value = " ";
// } else {
// element.value =
// gpaJsonObjectForSpecialCondition[key][
// index
// ];
// if (key.includes("gpa_special_condition_label")) {
// let checkbox = $(element).closest('.form-group').find('input[name="gpa_special_condition_display[]"]');
// console.log("First element:", element);
// if (checkbox.length) {
// console.log("Checkbox found:", checkbox);
// // Correct way to set the 'id' attribute
// let formattedValue = gpaJsonObjectForSpecialCondition[key][index].replace(/[\s\-\/,&]+/g, '').toLowerCase();
// console.log('formattedValue', formattedValue);
// checkbox.attr('id', formattedValue + '_display');
// console.log("Updated Checkbox:", checkbox);
// } else {
// console.log("Checkbox not found for:", element);
// }
// }
// }
// });
// }
// }
if (key.includes("gpa_special_condition_label") || key.includes("gpa_special_condition_input")) {
if (key.includes("gpa_special_condition_label")) {
for (let index = 0; index <
gpaJsonObjectForSpecialCondition[key].length; index++) {
specialConditionForGPA();
let count = gpaJsonObjectForSpecialCondition[key]?.length || 0;
for (let i = 0; i < count; i++) {
specialConditionForGPA(); // Called once per label entry
}
}
let elements = document.getElementsByName(`${key}[]`);
if (elements) {
elements.forEach((element, index) => {
if (elements && elements.length) {
Array.from(elements).forEach((element, index) => {
let value = gpaJsonObjectForSpecialCondition[key]?.[index] || "";
if (gpaJsonObjectForSpecialCondition[key][
index
] == undefined) {
element.value = " ";
} else {
element.value =
gpaJsonObjectForSpecialCondition[key][
index
];
element.value = value;
if (key.includes("gpa_special_condition_label")) {
let checkbox = $(element).closest('.form-group').find('input[name="gpa_special_condition_display[]"]');
console.log("First element:", element);
if (key.includes("gpa_special_condition_label")) {
let checkbox = $(element).closest('.form-group')
.find('input[name="gpa_special_condition_display[]"]');
if (checkbox.length) {
console.log("Checkbox found:", checkbox);
// Correct way to set the 'id' attribute
let formattedValue = gpaJsonObjectForSpecialCondition[key][index].replace(/[\s\-\/,&]+/g, '').toLowerCase();
console.log('formattedValue', formattedValue);
checkbox.attr('id', formattedValue + '_display');
console.log("Updated Checkbox:", checkbox);
} else {
console.log("Checkbox not found for:", element);
}
if (checkbox.length) {
let formattedValue = value.replace(/[\s\-\/,&]+/g, '').toLowerCase();
checkbox.attr('id', formattedValue + '_display');
}
}
});
@ -1051,6 +1083,32 @@
console.log('autoSaveGpaTerms function called');
var form = $('#policyGPATerms')[0];
if (!form) {
console.error("Form #policyGPATerms not found");
return;
}
// Check if form has any data before proceeding
var formData = new FormData(form);
var hasData = false;
for (let [key, value] of formData.entries()) {
console.log("Key:", key, "Value:", value);
if(key == "sumInsured2"){
if (value && value.toString().trim() !== '') {
hasData = true;
break;
}
}
}
if (!hasData) {
console.warn("Form data is empty, skipping auto-save");
return;
}
var specialConditions = [];
$(".removeDom").each(function () {
@ -1063,12 +1121,9 @@
specialConditions.push({ [label]: input });
}
});
console.log("gpa_specialConditions", specialConditions);
var formData = new FormData($('#policyGPATerms')[0]);
console.log("formData", formData);
// var formData = new FormData($('#policyGPATerms')[0]);
var policy_form_action = '<?= base_url("client/terms/gpa_create") ?>';
console.log("policy_form_action", policy_form_action);