FEAT_NON_EB_NEW_CHANGE

This commit is contained in:
Srinivas-Saravanan 2025-05-05 15:07:16 +05:30
parent d76e999c93
commit b542913153
3 changed files with 245 additions and 94 deletions

View File

@ -727,6 +727,7 @@ class LeadsController extends BaseController
$data["child_table_data"] = json_decode($data['question_json'], true)['child_table_data'];
}
$data['product'] = $this->leadsModel->select("policy_type.policy_type")->join('policy_type', 'leads.policy_type_id = policy_type.id')->where('leads.id', $id)->first()['policy_type'];
// $data['lead_register_data'] = json_decode($data['lead_data']['custom_fields']);
// dd($data['lead_register_data']);
// dd($data);
@ -3044,7 +3045,6 @@ class LeadsController extends BaseController
$data['lead_edit_data']['claims_details_html'] = "";
}
}
// dd($data);
return $this->loadLayout('leads_form_handler', $data);

View File

@ -242,19 +242,19 @@ hr.solid {
</select>
</div>
<!-- <div class="form-group col-md-3">
<div class="form-group col-md-3">
<label for="insurer">Insurer <span class="text-danger"></span></label>
<select class="form-control" id="insurer" name="insurer">
<option value="">Select Insurer</option>
<?php //if (isset($insurer)) { ?>
<?php //foreach ($insurer as $value) { ?>
<option value="<?php //echo $value['id'] . '-' . $value['insurer_id'] ?>">
<?php //echo $value['insurer_name'] . '-' . $value['branch_code'] ?>
<?php if (isset($insurer)) { ?>
<?php foreach ($insurer as $value) { ?>
<option value="<?= $value['id'] . '-' . $value['insurer_id'] ?>">
<?= $value['insurer_name'] . '-' . $value['branch_code'] ?>
</option>
<?php //} ?>
<?php //} ?>
</select> -->
<!-- </div> -->
<?php } ?>
<?php } ?>
</select>
</div>
<!-- <div class="form-group col-md-3">
<label for="tpa">TPA <span class="text-danger"></span></label>

View File

@ -1,9 +1,9 @@
<div class="modal fade" id="policyRegisterModel" tabindex="-1" aria-labelledby="fullWidthModalLabel" aria-hidden="true">
<div class="modal fade" id="policyRegisterModel" tabindex="-1" aria-labelledby="fullWidthModalLabel" aria-hidden="true" data-backdrop="static" data-keyboard="false">
<div class="modal-dialog modal-xl modal-dialog-centered">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title" id="fullWidthModalLabel">REGISTER POLICY INFORMATION</h4>
<button type="button" onclick="resetAllform()" class="close" data-dismiss="modal" aria-label="Close">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
@ -150,10 +150,10 @@
</div>
<div class="row">
<div class="col-md-4">
<div class="form-check">
<input type="checkbox" class="form-check-input" id="terrorismSwitch">
<label class="form-check-label" for="terrorismSwitch">Is Terrorism Required?</label>
<div class="col-md-4 dt-switch-wrapper">
<div class="custom-control custom-switch">
<input type="checkbox" class="custom-control-input" id="terrorismSwitch">
<label class="custom-control-label" for="terrorismSwitch">Is Terrorism Required?</label>
</div>
</div>
<div class="form-group col-md-4">
@ -258,6 +258,20 @@
// console.log("Occupancy : ", occupancyMaster);
var storedPolicyData = {};
storedPolicyData = JSON.parse(localStorage.getItem('policyData'));
var isFormDirty = false;
$(document).ready(function() {
// Listen for changes in all inputs, selects, and textareas within your modal
$('#policyRegisterModel').on('change input', 'input, select, textarea', function() {
// alert("function called");
isFormDirty = true;
// console.log("Form is dirty",isFormDirty);
});
});
$(document).ready(function() {
// resetAllform();
// console.log("Stored date Found : ", typeof(storedPolicyData));
@ -320,6 +334,7 @@
});
$('#productSelectionForm').submit(function(event) {
// console.log("Submit function called");
event.preventDefault();
var isValid = $('#productSelectionForm').parsley().validate();
@ -372,6 +387,7 @@
$("#policyRiskSplitUpForm").submit(function(event) {
event.preventDefault();
isFormDirty = false;
var isValid = $('#policyRiskSplitUpForm').parsley().validate();
@ -416,15 +432,27 @@
let InProcess = [...document.querySelectorAll('[id^="stockInProcess_"]')].map(el => Number(el.value) || 0);
let rawMaterial = [...document.querySelectorAll('[id^="rawMaterial_"]')].map(el => Number(el.value) || 0);
let findMaterial = [...document.querySelectorAll('[id^="finishedStock_"]')].map(el => Number(el.value) || 0);
let building = [...document.querySelectorAll('[id^="building_"]')].map(el => Number(el.value) || 0);
let content = [...document.querySelectorAll('[id^="content_"]')].map(el => Number(el.value) || 0);
let furniture = [...document.querySelectorAll('[id^="furniture_"]')].map(el => Number(el.value) || 0);
let plantAndMachinery = [...document.querySelectorAll('[id^="plantAndMachinery_"]')].map(el => Number(el.value) || 0);
let electricalFittings = [...document.querySelectorAll('[id^="electricalFittings_"]')].map(el => Number(el.value) || 0);
totalSI = InProcess.reduce((acc, val) => acc + val, 0) +
rawMaterial.reduce((acc, val) => acc + val, 0) +
findMaterial.reduce((acc, val) => acc + val, 0);
findMaterial.reduce((acc, val) => acc + val, 0) +
building.reduce((acc, val) => acc + val, 0) +
content.reduce((acc, val) => acc + val, 0) +
furniture.reduce((acc, val) => acc + val, 0) +
plantAndMachinery.reduce((acc, val) => acc + val, 0) +
electricalFittings.reduce((acc, val) => acc + val, 0);
let allowedSI = Number($("#policySI").val()) || 0;
// alert(allowedSI);
if (totalSI != allowedSI) {
toastr.error("Sum Insured Exceeds Allowed Limit", "ERROR");
console.log("allowedSI : ", allowedSI, " totalSI : ", totalSI);
toastr.error("Sum Insured Does not Match Allowed Limit", "ERROR");
return false;
}
// console.log("Total SI: ", totalSI);
@ -446,6 +474,10 @@
// Determine the number of dynamic rows based on a field that appears per row
const totalRows = formDataSplitUp.filter(field => field.name === "building[]").length;
if (totalRows != policyDetailsData.location_no) {
toastr.error("Please Enter All Risk Address", "ERROR");
return;
}
// Initialize empty objects for each row
for (let i = 0; i < totalRows; i++) {
groupData.push({});
@ -499,11 +531,28 @@
return;
}
const formData = $("#policyRiskAddressForm").serializeArray();
console.log("formdata 1 : ", formData);
$("[id^='isBasement_']").each(function() {
let checkbox = $(this);
let isChecked = checkbox.is(":checked");
let increment = checkbox.attr("id").split("_")[1];
formData.push({
name: `is_basement[]`,
value: isChecked ? "yes" : "no"
});
});
console.log("formdata 2 : ", formData);
const groupedData = [];
// Determine the number of dynamic rows
const totalRows = formData.filter(field => field.name === "pin_code[]").length;
if (totalRows != policyDetailsData.location_no) {
toastr.error("Please Enter All Risk Address", "ERROR");
return;
}
// Initialize empty objects for each row
for (let i = 0; i < totalRows; i++) {
groupedData.push({});
@ -528,7 +577,7 @@
});
policyRiskAddress = groupedData;
// console.log("Grouped Data as Objects: ", policyRiskAddress);
console.log("Grouped Data as Objects: ", policyRiskAddress);
if (productSelectionData.singleProduct == 'on') {
savePolicyDataLocal();
@ -553,14 +602,17 @@
return;
}
var formData = $("#policyDetailsForm").serializeArray();
formData.push({
name: "terrorism",
value: $('#terrorismSwitch').is(':checked') ? 'yes' : 'no'
})
$.each(formData, function(i, field) {
policyDetailsData[field.name] = field.value;
});
// // console.log("form data", policyDetailsData.location_no);
console.log("form data", formData);
if (formData !== null && formData !== '') {
// console.log("form submitted trying to open the ris info tab");
// riskInfoTabOpened();
const riskTab = new bootstrap.Tab(document.getElementById('risk-info-tab'));
riskTab.show();
@ -655,7 +707,7 @@
// policyRiskAddress
newRowRisk.innerHTML += `
<h5 class = "fire">Fire (Sookshma/Laghu) Details</h5>
<h5 class = "fire">Fire <?= isset($product) ? $product : "" ?> Details</h5>
<h5>Risk Split Up for Address : ${policyRiskAddress[increment2-1].address1} ${policyRiskAddress[increment2-1].address2}</h5>
<input type = "hidden" name = "location_selected[]" value = "${policyRiskAddress[increment2-1].select_location}" id = "location_selected_${increment2}" />
<div class = "row">
@ -797,20 +849,9 @@
<label for="address3_${increment}">Address 3</label>
<input type="text" id="address3_${increment}" name="address3[]" class="form-control" />
</div>
<div class="form-group col-md-4">
<label for="constructionType_${increment}">Construction Type<span class="text-danger">*</span></label>
<select id="constructionType_${increment}" name="construction_type[]" class="form-control">
<option value="kutcha" selected>Kutcha</option>
<option value="pucca">Pucca</option>
</select>
</div>
<div class="form-group col-md-4">
<label for="basementSI_${increment}">Basement Utilisation</label>
<input type="text" id="basementSI_${increment}" name="basement_si[]" class="form-control"/>
</div>
<div class="form-group col-md-4">
<div class="form-group col-md-4">
<label for="occupancy_${increment}">Occupancy Risk<span class="text-danger">*</span></label>
<select id="occupancy_${increment}" name="occupancy[]" class="form-control" onchange="showRequiredFieldsBasedOnLocation('occupancy_${increment}')" required>
<select id="occupancy_${increment}" name="occupancy[]" class="form-control" onchange="showRequiredFieldsBasedOnLocation(this)" required>
<option value="">Select</option>
${occupancyMaster.map(occupancy =>
`<option value="${occupancy.id}">${occupancy.description}</option>`
@ -818,16 +859,30 @@
</select>
</div>
<div class="form-group col-md-4 common_location_occupancy">
<label for="isBasement_${increment}">Basement<span class="text-danger">*</span></label>
<select id="isBasement_${increment}" name="is_basement[]" class="form-control common_location_occupancy" required>
<option value="yes" selected>Yes</option>
<option value="no">No</option>
<label for="iibCode_${increment}">IIB Code<span class="text-danger">*</span></label>
<input type="text" onchange = "updateOccupancyRisk(this)" id="iibCode_${increment}" name="iib_code[]" class="form-control common_location_occupancy" required>
</div>
<div class="form-group col-md-4">
<label for="constructionType_${increment}">Construction Type<span class="text-danger">*</span></label>
<select id="constructionType_${increment}" name="construction_type[]" class="form-control">
<option value="kutcha" selected>Kutcha</option>
<option value="pucca">Pucca</option>
</select>
</div>
<div class="form-group col-md-4 common_location_occupancy">
<label for="iibCode_${increment}">IIB Code<span class="text-danger">*</span></label>
<input type="text" id="iibCode_${increment}" name="iib_code[]" class="form-control common_location_occupancy" required>
<div class="dt-switch-wrapper col-md-4 common_location_occupancy d-flex align-items-center">
<div class="custom-control custom-switch d-flex justify-content-center">
<input type="checkbox" class="custom-control-input" id="isBasement_${increment}" onchange="hideShowBasement(${increment})">
<label class="custom-control-label" for="isBasement_${increment}">Basement</label>
</div>
</div>
<div class="form-group col-md-4" style="display:none" >
<label for="basementSI_${increment}">Basement Utilisation</label>
<input type="text" id="basementSI_${increment}" name="basement_si[]" class="form-control"/>
</div>
<div class="form-group col-md-4 multiLocationOccupancy">
<label for="select_location_${increment}">Location <span class="text-danger">*</span></label>
<select required id="select_location_${increment}" name="select_location[]" class="form-control multiLocationOccupancy">
@ -1020,64 +1075,41 @@
}
function showRequiredFieldsBasedOnLocation(element) {
if (element) {
// alert(element);
var selectedOccupancy = $(`#${element}`).val();
var selectedOccupancy = $(element).val(); // FIXED
var selectedOccupancyMasterRow = occupancyMaster.find(iib => iib.id == selectedOccupancy);
// console.log("selected occupancy masater ", selectedOccupancyMasterRow)
// console.log("selected occupancy masater ", occupancyMaster)
if (!selectedOccupancyMasterRow) return;
var iibCODE = selectedOccupancyMasterRow.iib_code;
// console.log("selected occupancy masater ", iibCODE)
var elementID = element;
var elementID = element.id; // FIXED
let increment = elementID.split("_").pop();
// console.log("selected occupancy masater increment ", increment)
// console.log("selected occupancy masater element ", $(`#iibCode_${increment}`))
setTimeout(function() {
$(`#iibCode_${increment}`).val(iibCODE); // Set the value
// console.log("Selected --------------------", $(`#iibCode_${increment}`).val()); // Log the value
}, 1000);
$(`#iibCode_${increment}`).val(iibCODE);
}, 500);
}
// console.log("onchange occupancy function called ");
// // console.log("onchange occupancy function called ", selectedOccupancy);
// // console.log("onchange occupancy function called ", selectedOccupancyMasterRow);
// // console.log("onchange occupancy function called ", iibCODE);
// // console.log("onchange occupancy function called ", increment);
$('[class*="common_location_occupancy"]').show().prop("required", "required");
$('[class*="common_location_occupancy"]').show().prop("required", true);
var selectedProduct = productSelectionData;
if (selectedProduct.singleProduct == 'on') {
$('[class*="single_location_occupancy"]').show().prop("required", "required");
} else if (selectedProduct.multipleProduct == 'on') {
// // console.log("Muliple location");f
$('[class*="multiLocationOccupancy"]').show().prop('required', 'required');
if (selectedProduct.singleProduct === 'on') {
$('[class*="single_location_occupancy"]').show().prop("required", true);
} else if (selectedProduct.multipleProduct === 'on') {
$('[class*="multiLocationOccupancy"]').show().prop('required', true);
if (selectedProduct.multilocation_type == "multiLocation") {
// // console.log("multiple location without Floater");
$('[class*="multiLocationOccupancyWithoutFloater"]').show().prop('required', 'required');
} else if (selectedProduct.multilocation_type == "multiFloater") {
// // console.log("Muliple location With Floater");
$('[class*="multiLocationOccupancyWithoutFloater"]').hide().removeAttr('required', false);
} else if (selectedProduct.multilocation_type == "stockFloater") {
// // console.log("multiple location with stock floater");
$('[class*="multiLocationOccupancyWithoutFloater"]').show().prop('required', 'required');
$('[class*="stockSI"]').hide().removeAttr('required', false);
if (selectedProduct.multilocation_type === "multiLocation") {
$('[class*="multiLocationOccupancyWithoutFloater"]').show().prop('required', true);
} else if (selectedProduct.multilocation_type === "multiFloater") {
$('[class*="multiLocationOccupancyWithoutFloater"]').hide().removeAttr('required');
} else if (selectedProduct.multilocation_type === "stockFloater") {
$('[class*="multiLocationOccupancyWithoutFloater"]').show().prop('required', true);
$('[class*="stockSI"]').hide().removeAttr('required');
}
}
}
function registerPolicyData() {
var policyType;
@ -1271,9 +1303,9 @@
const policyDetails = data.policyDetails;
Object.keys(policyDetails).forEach(key => {
$(`#${key}`).val(policyDetails[key]);
// // console.log("Key ",key," set value : ",policyDetails[key]);
// console.log("Key ", key, " set value : ", policyDetails[key]);
});
$('#terrorismSwitch').prop('checked', policyDetails.terrorism === "yes")
// Populate Risk Addresses
data.locations.forEach((location, index) => {
addHTMLInputForRiskAddress();
@ -1293,12 +1325,13 @@
$(`#constructionType${prefix}`).val(risk.construction_type);
$(`#occupancy${prefix}`).select2();
$(`#occupancy${prefix}`).val(risk.occupancy).trigger("change");
$(`#isBasement${prefix}`).val(risk.is_basement);
// $(`#isBasement${prefix}`).val(risk.is_basement);
$(`#iibCode${prefix}`).val(risk.iib_code);
$(`#buisness_desc${prefix}`).val(risk.buisness_desc);
$(`#select_location${prefix}`).val(risk.select_location);
$(`#basementSI${prefix}`).val(risk.basement_si);
$(`#isBasement${prefix}`).prop('checked', risk.is_basement === "yes").trigger("change");
@ -1334,7 +1367,7 @@
});
isFormDirty = false; // Reset the form dirty flag
}
function checkandassignLeadData() {
@ -1379,6 +1412,7 @@
$("#address1").val(lead_data.address);
$("#mobile").val(mobile);
$("#email").val(contact_email);
// var policy_type = lead_data.policy_type_id;
}
}
@ -1396,6 +1430,8 @@
}
function resetAllform() {
// isFormDirty = false;
// console.log("FORM RESETED SUCCESSFULLY");
$("#productSelectionForm")[0].reset();
$("#policyDetailsForm")[0].reset();
@ -1421,12 +1457,39 @@
hideAndShowBurglary()
}
$('.close').on('click', function() {
$('.tab-pane').removeClass('active show');
$('.close').on('click', function(e) {
console.log("is form dirty : ", isFormDirty);
if (isFormDirty) {
e.preventDefault();
e.stopPropagation();
Swal.fire({
title: 'You have unsaved changes!',
text: 'Do you want to close without saving your data?',
icon: 'warning',
showCancelButton: true,
confirmButtonText: 'Yes, close it',
cancelButtonText: 'No, stay here',
}).then((result) => {
if (result.isConfirmed) {
isFormDirty = false; // Reset flag
closeModal();
resetAllform();
// $('#policyRegisterModel').modal('hide');
$('.tab-pane').removeClass('active show');
$("#addRiskInfo, #addRiskSplitUp").empty();
}
});
return false;
} else {
resetAllform();
$('.tab-pane').removeClass('active show');
$("#addRiskInfo, #addRiskSplitUp").empty();
}
});
$("#addRiskInfo, #addRiskSplitUp").empty();
})
function copyFirePolicy() {
// console.log("Copying Fire Policy Data...");
@ -1460,4 +1523,92 @@
document.querySelector('#policyRegisterModel [data-dismiss="modal"]').click();
}
function updateOccupancyRisk(element) {
let iibCode = $(element).val();
// Find matching occupancy row
let matchedOccupancy = occupancyMaster.find(iib => iib.iib_code == iibCode);
let matchedId = matchedOccupancy ? matchedOccupancy.id : null;
// Get increment from the element ID, like "iibCode_3"
let elementID = element.id;
let increment = elementID.split("_").pop(); // Extract "3" from "iibCode_3"
if (matchedId) {
$(`#occupancy_${increment}`).val(matchedId).trigger("change");
$(`#occupancy_${increment}`).select2();
} else {
toastr.error("Invalid IIB Code", "Error");
}
}
function hideShowBasement(incrementFromBasement) {
let isBasement = $(`#isBasement_${incrementFromBasement}`).is(":checked");
// Get the label associated with the input
let label = $(`label[for='basementSI_${incrementFromBasement}']`);
if (isBasement) {
$(`#basementSI_${incrementFromBasement}`).parent().show();
$(`#basementSI_${incrementFromBasement}`).prop("required", "required");
// Add * if not already there
if (label.find(".text-danger").length === 0) {
label.append('<span class="text-danger">*</span>');
}
} else {
$(`#basementSI_${incrementFromBasement}`).parent().hide();
$(`#basementSI_${incrementFromBasement}`).removeAttr("required");
// Remove * if exists
label.find(".text-danger").remove();
}
}
// function saveDataAsDraft() {
// return new Promise((resolve) => {
// const forms = [
// document.getElementById('productSelectionForm'),
// document.getElementById('policyDetailsForm'),
// document.getElementById('policyRiskAddressForm'),
// document.getElementById('policyRiskSplitUpForm')
// ];
// let isDirty = false;
// forms.forEach(form => {
// if (form) {
// const formInputs = form.querySelectorAll('input, select, textarea');
// formInputs.forEach(input => {
// if (input.defaultValue !== input.value && input.value !== '') {
// isDirty = true;
// }
// if (input.type === 'checkbox' || input.type === 'radio') {
// if (input.checked !== input.defaultChecked) {
// isDirty = true;
// }
// }
// });
// }
// });
// if (isDirty) {
// Swal.fire({
// title: 'You have unsaved changes!',
// text: 'Do you want to close without saving your data?',
// icon: 'warning',
// showCancelButton: true,
// confirmButtonText: 'Yes, close it',
// cancelButtonText: 'No, stay here',
// }).then((result) => {
// resolve(result.isConfirmed);
// });
// } else {
// resolve(true); // No unsaved changes, allow closing
// }
// });
// }
</script>