diff --git a/app/Controllers/ClientController.php b/app/Controllers/ClientController.php
index 4a73bb1b..d3120770 100755
--- a/app/Controllers/ClientController.php
+++ b/app/Controllers/ClientController.php
@@ -2423,6 +2423,7 @@ class ClientController extends AdminController
// echo "
";
// 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);
diff --git a/app/Controllers/LeadsController.php b/app/Controllers/LeadsController.php
index db13f832..d5f8ea12 100644
--- a/app/Controllers/LeadsController.php
+++ b/app/Controllers/LeadsController.php
@@ -4947,7 +4947,7 @@ class LeadsController extends BaseController
// Start table with clean styling
$html .= "{$category}
";
- $html .= "";
+ $html .= "";
// Table header with light background
$html .= "";
diff --git a/app/Views/other_policy_terms.php b/app/Views/other_policy_terms.php
index 03850e4b..e674fa52 100755
--- a/app/Views/other_policy_terms.php
+++ b/app/Views/other_policy_terms.php
@@ -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,
diff --git a/app/Views/policy_gmc_terms.php b/app/Views/policy_gmc_terms.php
index 80d8555e..7074e83a 100755
--- a/app/Views/policy_gmc_terms.php
+++ b/app/Views/policy_gmc_terms.php
@@ -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,
diff --git a/app/Views/policy_gpa_terms.php b/app/Views/policy_gpa_terms.php
index 77168662..6337148a 100755
--- a/app/Views/policy_gpa_terms.php
+++ b/app/Views/policy_gpa_terms.php
@@ -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);