nhance/app/Views/policyRegisterModel.php
2025-03-19 14:17:39 +05:30

1173 lines
55 KiB
PHP

<div class="modal fade" id="policyRegisterModel" tabindex="-1" aria-labelledby="fullWidthModalLabel" aria-hidden="true">
<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" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<!-- Tabs Navigation -->
<ul class="nav nav-pills navtab-bg nav-justified" id="policyTabs">
<li class="nav-item">
<a id="product-selection-tab" data-toggle="tab" aria-expanded="false" class="nav-link active" href="#product-selection" aria-current="page">Product Selection</a>
</li>
<li class="nav-item">
<a id="policy-details-tab" data-toggle="tab" aria-expanded="false" class="nav-link" href="#policy-details">Policy Details</a>
</li>
<li class="nav-item">
<a id="risk-info-tab" data-toggle="tab" aria-expanded="false" class="nav-link" href="#risk-information">Risk Information</a>
</li>
<li id="risksplitupTab" class="nav-item">
<a id="risk-splitup-tab" data-toggle="tab" aria-expanded="false" class="nav-link" href="#risk-splitup">Risk Split UP Information</a>
</li>
</ul>
<!-- Tab Content -->
<div class="tab-content mt-3">
<!-- Product selection Tab -->
<div class="tab-pane fade show active" id="product-selection">
<form id="productSelectionForm" class="parsley-examples" enctype="multipart/form-data">
<div class="row">
<div class="form-group col-md-3">
<button type="button" class="btn btn-primary" id="getDataFromLead" onclick="assignLeadData()">Get Data From Lead</button>
</div>
</div>
<div class="row">
<div class="form-group col-md-3">
<label>Select Buisness Type<span class="text-danger">*</span></label>
</div>
<div class="form-group col-md-3">
<label for="singleProduct">Single Location</label>
<input type="checkbox" id="singleProduct" name="singleProduct" class="business-type-checkbox" checked />
</div>
<div class="form-group col-md-3">
<label for="multipleProduct">Multiple Location</label>
<input type="checkbox" id="multipleProduct" name="multipleProduct" class="business-type-checkbox" />
</div>
</div>
<div class="row">
<div class="form-group col-md-3" id="multilocation_type_div">
<label for="multilocation_type" class="form-label">Multilocation Type <span class="text-danger">*</span></label>
<select id="multilocation_type" name="multilocation_type" class="form-control">
<option value="">Select</option>
<option value="multiLocation">Multilocation Without Floater</option>
<option value="multiFloater">Multilocation With Floater</option>
</select>
</div>
</div>
<div class="row">
<div class="form-group col-md-3">
<label for="client_type">Client Type<span class="text-danger">*</span></label>
<select class="form-control" id="client_type" name="client_type" >
<option value="">Select Client type</option>
<?php
if (isset($client_type) && count($client_type)) {
foreach ($client_type as $key => $value) {
echo "<option value='" . $key . "' >" . $value . "</option>";
}
}
?>
</select>
</div>
<div class="form-group col-md-3">
<label for="buisnessNature">Nature of Buisness</label>
<input type="text" class="form-control" id="buisnessNature"/>
</div>
</div>
<hr>
<div class="text-right">
<button type="submit" class="btn btn-primary" id="submitProductSelection">Proceed</button>
</div>
</form>
</div>
<!-- Policy Details Tab -->
<div class="tab-pane fade" id="policy-details">
<h5>Product Information</h5>
<form id="policyDetailsForm" class="parsley-examples" enctype="multipart/form-data">
<div class="row">
<div class="form-group col-md-3">
<label for="valueOfRisk">Value of the Risk<span class="text-danger">*</span></label>
<input type="number" id="valueOfRisk" name="valueOfRisk" class="form-control" />
</div>
</div>
<div class="row">
<div class="form-group col-md-3">
<label for="insured_name">Insured Name<span class="text-danger">*</span></label>
<input type="text" id="insured_name" name="insured_name" class="form-control" />
</div>
<div class="form-group col-md-3">
<label for="email">Email Id<span class="text-danger">*</span></label>
<input type="text" id="email" name="email" class="form-control" />
</div>
<div class="form-group col-md-3">
<label for="mobile">Mobile Number<span class="text-danger">*</span></label>
<input type="text" id="mobile" name="mobile" class="form-control" />
</div>
<div class="form-group col-md-3 single_location">
<label for="customer_id">Customer ID</label>
<input type="text" id="customer_id" name="customer_id" class="form-control" />
</div>
<div class="form-group col-md-3 single_location">
<label for="policy_number">Policy Number</label>
<input type="text" id="policy_number" name="policy_number" class="form-control" />
</div>
<div class="form-group col-md-3 single_location">
<label for="pan_number">PAN Number</label>
<input type="text" id="pan_number" name="pan_number" class="form-control" />
</div>
<div class="form-group col-md-3">
<input type="checkbox" id="dataFromLead" name="dataFromLead" class="form-check-input" />
<label for="dataFromLead">Get Data From Leads</label>
</div>
</div>
<hr>
<h5>Communication Address</h5>
<div class="row">
<div class="form-group col-md-3">
<label for="pin_code">Pin Code<span class="text-danger">*</span></label>
<input type="text" id="pin_code" name="pin_code" class="form-control" />
</div>
<div class="form-group col-md-3">
<label for="address1">Address 1<span class="text-danger">*</span></label>
<input type="text" id="address1" name="address1" class="form-control" />
</div>
<div class="form-group col-md-3">
<label for="address2">Address 2</label>
<input type="text" id="address2" name="address2" class="form-control" />
</div>
<div class="form-group col-md-3">
<label for="address3">Address 3</label>
<input type="text" id="address3" name="address3" class="form-control" />
</div>
</div>
<div class="row">
<div class="col-md-3">
<div class="form-check">
<input type="checkbox" class="form-check-input" id="terrorismSwitch">
<label class="form-check-label" for="terrorismSwitch">Is Terrorism ?</label>
</div>
</div>
<div class="form-group col-md-3">
<label for="policy_term">Policy Term<span class="text-danger">*</span></label>
<select id="policy_term" name="policy_term" class="form-control" >
<option value="">Select</option>
<option value="1_month">1 Months</option>
<option value="2_month">2 Months</option>
<option value="3_month">3 Months</option>
<option value="4_month">4 Months</option>
<option value="5_month">5 Months</option>
<option value="6_month">6 Months</option>
<option value="7_month">7 Months</option>
<option value="8_month">8 Months</option>
<option value="9_month">9 Months</option>
<option value="10_month">10 Months</option>
<option value="11_month">11 Months</option>
<option value="12_month">12 Months</option>
<option value="0.5_month">0.5 Months</option>
</select>
</div>
<div id="locationNoDIV" class="form-group col-md-3">
<label for="location_no">No of location<span class="text-danger">*</span></label>
<select id="location_no" name="location_no" class="form-control" >
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
</select>
</div>
<!-- <div class="row single_location">
<div class="form-group col-md-3">
<input type="checkbox" name="floater" id="floater" /><label for="floater"> Floater</label>
</div>
<div class="form-group col-md-3">
<input type="checkbox" id="declaration" name="declaration" /><label for="declaration"> Declaration</label>
</div>
<hr>
<div class="form-group col-md-3">
<input type="checkbox" name="msme" id="msme" /><label for="msme"> MSME Customer</label>
</div>
<div class="form-group col-md-3">
<label for="msme_num">MSME Number</label>
<input type="text" id="msme_num" name="msme_num" class="form-control" disabled />
</div>
</div> -->
<div class="row">
<div class="form-group col-md-12">
<label for="hypothecations">Hypothecations</label>
<textarea id="hypothecations" name="hypothecations" class="form-control" rows="3"></textarea>
</div>
</div>
<hr>
</div>
<div class="row">
<div class="col-md-12 text-right">
<button type="submit" id="addRiskBtn" class="btn btn-primary">Add Risk Locations</button>
</div>
</div>
</form>
</div>
<!-- Insured Information Tab -->
<div class="tab-pane fade" id="risk-information">
<form id="policyRiskAddressForm" class="parsley-examples" enctype="multipart/form-data">
<div id="addRiskInfo"></div>
<div class="row">
<div class="col-md-12 text-right">
<button type="submit" id="riskSplitup" class="btn btn-primary">Validate and Add Risk Split up</button>
</div>
</div>
<div class="row">
<div class="col-md-12 text-right">
<button type="submit" id="submitPolicyRisk" class="btn btn-primary">Submit For Validation</button>
</div>
</div>
</form>
</div>
<div class="tab-pane fade" id="risk-splitup">
<form id="policyRiskSplitUpForm" class="parsley-examples" enctype="multipart/form-data">
<div id="addRiskSplitUp"></div>
<div class="row">
<div class="col-md-12 text-right">
<button type="submit" id="riskSplitUPButton" class="btn btn-primary">Register</button>
</div>
</div>
</form>
</div>
</div>
<!-- Contact Information Tab -->
</div>
</div>
<!-- <div class="modal-footer">
<button type="button" class="btn btn-primary">Submit</button>
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
</div> -->
</div>
</div>
</div>
<script>
var storedData = JSON.parse(localStorage.getItem('policyData'));
$(document).ready(function() {
// console.log("Stored date Found : ",storedData.length);
if (!$.isEmptyObject(storedData)) {
prepareDataForEdit(storedData);
} else {
console.log("inside else trying to open product sleection tab");
// const productSelectionTab = new bootstrap.Tab(document.getElementById);
const productSelectionTab = new bootstrap.Tab(document.getElementById('product-selection-tab'));
productSelectionTab.show();
}
})
var increment = 1;
var increment2 = 1;
var productSelectionData = {};
// var productSelectionData = {
// "multipleProduct": "on",
// "multilocation_type": "stockFloater",
// "singleProduct": "off"
// }
var policyDetailsData = {};
// var policyDetailsData = {
// "valueOfRisk": "1000000",
// "insured_name": "Madhumitha",
// "email": "srinivassaravanan2002@gmail.com",
// "mobile": "06382156701",
// "pin_code": "635109",
// "address1": "5/316,plot no.26",
// "address2": "Sridharan illam, om Shanti nagar",
// "address3": "",
// "policy_term": "1month",
// "location_no": "2",
// "hypothecations": "",
// "customer_id": "",
// "policy_number": "",
// "pan_number": ""
// }
var policyRiskAddress = {};
// var policyRiskAddress = [{
// "pin_code": "635109",
// "address1": "5/316,plot no.26",
// "address2": "Sridharan illam, om Shanti nagar",
// "address3": "",
// "constructionType": "kutcha",
// "basementSI": "",
// "occupancy": "museum",
// "isBasement": "yes",
// "pumSI": "",
// "iibCode": "12",
// "eqZone": "",
// "floodRisk": "low",
// "stormRisk": "low",
// "working_or_silent": "silent",
// "select_location": "Location 1",
// "buisness_desc": "121",
// "age_of_building": "upto20",
// "isHigherGrouds": "no"
// },
// {
// "pin_code": "635109",
// "address1": "5/316,plot no.26",
// "address2": "Sridharan illam, om Shanti nagar",
// "address3": "",
// "constructionType": "kutcha",
// "basementSI": "",
// "occupancy": "schools/college",
// "isBasement": "yes",
// "pumSI": "",
// "iibCode": "12",
// "eqZone": "",
// "floodRisk": "low",
// "stormRisk": "low",
// "working_or_silent": "silent",
// "select_location": "Location 2",
// "buisness_desc": "121",
// "age_of_building": "upto20",
// "isHigherGrouds": "no"
// }
// ]
var policyRiskSplitUpData = {};
$(document).ready(function() {
if ($.isEmptyObject(storedData)) {
$('#multilocation_type_div').hide();
}
// When a business-type checkbox changes, handle exclusive selection
$('.business-type-checkbox').on('change', function() {
const $current = $(this);
const id = $current.attr('id');
// If the current checkbox is checked:
if ($current.is(':checked')) {
// Uncheck the other business-type checkboxes without triggering their change event
$('.business-type-checkbox').not($current).prop('checked', false);
if (id === 'multipleProduct') {
// For multiple product, show the multilocation container and mark it
$('#multilocation_type').closest('.form-group').show();
$('#multilocation_type').prop('required', true);
} else if (id === 'singleProduct') {
// For single product, hide the multilocation container and remove attribute
$('#multilocation_type').closest('.form-group').hide();
$('#multilocation_type').prop('required', false);
}
} else {
// If uncheckked and it's the multiple product, hide the container
if (id === 'multipleProduct') {
$('#multilocation_type').closest('.form-group').hide();
$('#multilocation_type').prop('required', false);
}
}
});
});
$("#msme").change(function() {
if ($("#msme").is(":checked")) {
$("#msme_num").removeAttr('disabled', false);
$("label[for='msme_num']").append('<span class="text-danger">*</span>');
} else {
$("#msme_num").prop('disabled', 'disabled');
$("label[for='msme_num']").find("span.text-danger").remove();
$("#msme_num").val("");
}
})
$('#productSelectionForm').submit(function(event) {
productSelectionData = {};
// console.log("submit function is clicked");
event.preventDefault();
var formDataProductSelection = $("#productSelectionForm").serializeArray();
$.each(formDataProductSelection, function(i, field) {
productSelectionData[field.name] = field.value;
});
productSelectionData['singleProduct'] = $('#singleProduct').is(':checked') ? 'on' : 'off';
productSelectionData['multipleProduct'] = $('#multipleProduct').is(':checked') ? 'on' : 'off';
productSelectionData['multilocation_type'] = $('#singleProduct').is(':checked') ? "" : productSelectionData['multilocation_type'];
if (!$('#singleProduct').is(':checked') && !$('#multipleProduct').is(':checked')) {
// productSelectionData = {};
toastr.warning("Please choose a Product", "Warning");
} else {
policydetailsOpen();
}
console.log("form data product selection : ", productSelectionData);
})
function policydetailsOpen() {
// PolicyTabOpened();
console.log("function is called");
// Use the ID for the Policy Details tab button.
// const policyDetailsTab = new bootstrap.Tab(document.getElementById('policy-details-tab'));
const policyDetailsTab = new bootstrap.Tab(document.getElementById('policy-details-tab'));
policyDetailsTab.show();
}
$("#policyRiskSplitUpForm").submit(function(event) {
event.preventDefault();
const formDataSplitUp = $("#policyRiskSplitUpForm").serializeArray();
console.log("Form is trying to submit : ", formDataSplitUp);
const groupData = [];
// Determine the number of dynamic rows
const totalRows = formDataSplitUp.filter(field => field.name === "building[]").length;
// Initialize empty objects for each row
for (let i = 0; i < totalRows; i++) {
groupData.push({});
}
// Track the position of each field type in the grouped data
const fieldCounts = {};
formDataSplitUp.forEach(field => {
const fieldName = field.name.replace('[]', '');
// Initialize count for this field type if not exists
if (!fieldCounts[fieldName]) {
fieldCounts[fieldName] = 0;
}
const index = fieldCounts[fieldName]; // Correctly track field index
groupData[index][fieldName] = field.value;
// Increment the count for the next occurrence of this field type
fieldCounts[fieldName]++;
});
policyRiskSplitUpData = groupData;
console.log("Grouped Data as Objects: ", policyRiskSplitUpData);
savePolicyDataLocal();
})
$("#policyRiskAddressForm").submit(function(event) {
event.preventDefault();
const formData = $("#policyRiskAddressForm").serializeArray();
const groupedData = [];
// Determine the number of dynamic rows
const totalRows = formData.filter(field => field.name === "pin_code[]").length;
// Initialize empty objects for each row
for (let i = 0; i < totalRows; i++) {
groupedData.push({});
}
// Track the position of each field type in the grouped data
const fieldCounts = {};
formData.forEach(field => {
const fieldName = field.name.replace('[]', '');
// Initialize count for this field type if not exists
if (!fieldCounts[fieldName]) {
fieldCounts[fieldName] = 0;
}
const index = fieldCounts[fieldName]; // Correctly track field index
groupedData[index][fieldName] = field.value;
// Increment the count for the next occurrence of this field type
fieldCounts[fieldName]++;
});
policyRiskAddress = groupedData;
console.log("Grouped Data as Objects: ", policyRiskAddress);
if (productSelectionData.singleProduct == 'on') {
savePolicyDataLocal();
} else {
riskSplitup();
}
});
$("#policyDetailsForm").submit(function(event) {
event.preventDefault();
var formData = $("#policyDetailsForm").serializeArray();
$.each(formData, function(i, field) {
policyDetailsData[field.name] = field.value;
});
// console.log("form data", policyDetailsData.location_no);
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();
}
});
function riskSplitup() {
// riskSplitupTabOpened()
const riskSplitTab = new bootstrap.Tab(document.getElementById('risk-splitup-tab'));
riskSplitTab.show();
}
$(document).ready(function() {
$('a[data-toggle="tab"]').on('shown.bs.tab', function(e) {
if (e.target.id === 'policy-details-tab') {
if (Object.keys(productSelectionData).length > 0) {
$("#policy-details").show();
// validatePolicyBasedOnProductSelection();
} else {
$("#policy-details").hide();
toastr.warning("Please Choose a Product First", "Warning");
}
} else if (e.target.id === 'risk-splitup-tab') {
contianertoCheck = document.getElementById("addRiskSplitUp");
console.log("policy det", policyRiskAddress.length)
if (!$.isEmptyObject(policyRiskAddress)) {
if (increment2 == 1) {
policyRiskAddress.forEach(function() {
console.log("increment count is ", increment2)
addHTMLInputForRiskSplitUP();
// validatePolicyBasedOnProductSelection();
})
}
} else {
if (contianertoCheck.innerHTML == "") {
addHTMLInputForRiskSplitUpWarninig();
}
}
} else if (e.target.id === 'risk-info-tab') {
console.log("function called ");
contianertoCheck = document.getElementById("addRiskInfo");
// console.log("policy details data ", policyDetailsData);
if (!$.isEmptyObject(policyDetailsData)) {
if (increment == 1) {
console.log("inside if ");
addHTMLInputForRiskAddress();
// validatePolicyBasedOnProductSelection();
}
} else {
console.log("inside else ");
if (contianertoCheck.innerHTML == "") {
addHTMLInputForRiskAddressWarninig();
}
}
const riskTab = new bootstrap.Tab(document.getElementById('risk-info-tab'));
riskTab.show();
}
});
});
// function riskInfoTabOpened() {
// }
// $('.nav-tabs a[href="#product-selection"]').click(function() {
// const productSelectionTab = new bootstrap.Tab(document.getElementById('product-selection-tab'));
// productSelectionTab.show();
// })
// // document.getElementById('policy-details-tab').addEventListener('shown.bs.tab', function() {
// $('.nav-tabs a[href="#policy-details"]').click(function() {
// console.log("policy tab opened");
// PolicyTabOpened();
// const policyDetailsTab = new bootstrap.Tab(document.getElementById('policy-details-tab'));
// policyDetailsTab.show();
// });
// $('.nav-tabs a[href="#risk-splitup"]').click(function() {
// console.log("risk splitup tab opened");
// riskSplitupTabOpened();
// const riskSplitTab = new bootstrap.Tab(document.getElementById('risk-splitup-tab'));
// riskSplitTab.show();
// });
// $('.nav-tabs a[href="#risk-information"]').click(function() {
// console.log("risk address tab opened");
// // riskInfoTabOpened();
// // const riskTab = new bootstrap.Tab(document.getElementById('risk-info-tab'));
// // riskTab.show();
// });
function addHTMLInputForRiskSplitUpWarninig() {
const containerWarninig = document.getElementById('addRiskSplitUp');
const newRow = document.createElement('div');
newRow.innerHTML += `
<h3>Please Enter Risk Address Before Adding the splitup</h3>
`;
containerWarninig.appendChild(newRow);
}
function addHTMLInputForRiskSplitUP() {
// console.log("Function called ", increment2, " times");
const container = document.getElementById("addRiskSplitUp");
// container.innerHTML = '';
const newRowRisk = document.createElement("div");
// console.log("Risk Split Up for address : ", policyRiskAddress.length)
// policyRiskAddress
newRowRisk.innerHTML += `
<h5>Fire (Sookshma/Laghu) 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">
<div class="form-group col-md-3 multi_location_company">
<label for="building_${increment2}">Building</label>
<input type="text" id="building_${increment2}" name="building[]" class="form-control multi_location_company" />
</div>
<div class="form-group col-md-3 multi_location_company">
<label for="content_${increment2}">Content</label>
<input type="text" id="content_${increment2}" name="content[]" class="form-control multi_location_company" />
</div>
<div class="form-group col-md-3 multi_location_company">
<label for="furniture_${increment2}">Furniture/Office Equipment</label>
<input type="text" id="furniture_${increment2}" name="furniture[]" class="form-control multi_location_company" />
</div>
<div class="form-group col-md-3 multi_location_company">
<label for="plantAndMachinery_${increment2}">Plant and Machinery</label>
<input type="text" id="plantAndMachinery_${increment2}" name="plantAndMachinery[]" class="form-control multi_location_company" />
</div>
<div class="form-group col-md-3 multi_location_company">
<label for="electricalFittings_${increment2}">Electrical Fittings</label>
<input type="text" id="electricalFittings_${increment2}" name="electricalFittings[]" class="form-control multi_location_company"/>
</div>
</div>
<br>
<div class = "stockSI">
<h5>Stock Sum Insured</h5>
<div class = "row">
<div class="form-group col-md-3 multi_location_company">
<label for="stockInProcess_${increment2}">Stock In Process</label>
<input type="text" id="stockInProcess_${increment2}" name="stockInProcess[]" class="form-control multi_location_company" />
</div>
<div class="form-group col-md-3 multi_location_company">
<label for="rawMaterial_${increment2}">Raw Material</label>
<input type="text" id="rawMaterial_${increment2}" name="rawMaterial[]" class="form-control multi_location_company" />
</div>
<div class="form-group col-md-3 multi_location_company">
<label for="finishedStock_${increment2}">Finished Stock</label>
<input type="text" id="finishedStock_${increment2}" name="finishedStock[]" class="form-control multi_location_company"/>
</div>
</div>
<hr></div>
`;
container.appendChild(newRowRisk);
increment2++;
}
function addHTMLInputForRiskAddressWarninig() {
const containerWarninig = document.getElementById('addRiskInfo');
const newRow = document.createElement('div');
newRow.innerHTML += `
<h3>Please Enter Policy Details before adding the Risk Address</h3>
`;
containerWarninig.appendChild(newRow);
}
function addHTMLInputForRiskAddress() {
const container = document.getElementById('addRiskInfo');
// container.innerHTML = "";
const newRow = document.createElement('div');
// console.log("policy details ", policyDetailsData);
newRow.className = 'form-row dynamic-form-row mb-3';
newRow2 = document.createElement("div");
// newRow2.className = 'form-row btn mb-3';
newRow.innerHTML = `
<div class = "row">
<div id = "sameAsCommunicationAddress_div" class = "form-group col-md-4">
<input type = "checkbox" id = "sameAsCommunicationAddress" onchange="addOrRemoveAdd()">
<label for = "sameAsCommunicationAddress" >Same as Communication Address</label>
</div>
<div>
<div class="row">
<div class="form-group col-md-3">
<label for="pin_code_${increment}">Pin Code<span class = "text-danger">*</span></label>
<input type="text" id="pin_code_${increment}" name="pin_code[]" class="form-control" />
</div>
<div class="form-group col-md-3">
<label for="address1_${increment}">Address 1<span class = "text-danger">*</span></label>
<input type="text" id="address1_${increment}" name="address1[]" class="form-control" />
</div>
<div class="form-group col-md-3">
<label for="address2_${increment}">Address 2</label>
<input type="text" id="address2_${increment}" name="address2[]" class="form-control" />
</div>
<div class="form-group col-md-3">
<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-3">
<label for="constructionType_${increment}">Construction Type<span class = "text-danger">*</span></label>
<select id="constructionType_${increment}" name="constructionType[]" class="form-control" >
<option value = "kutcha" selected>Kutcha</option>
<option value = "pucca">Pucca</option>
</select>
</div>
<div class="form-group col-md-3">
<label for="basementSI_${increment}">Basement Sum Insured</label>
<input type="text" id="basementSI_${increment}" name="basementSI[]" class="form-control"/>
</div>
<div class="form-group col-md-3">
<label for="occupancy_${increment}">Occupancy<span class = "text-danger">*</span></label>
<select id="occupancy_${increment}" name="occupancy[]" class="form-control" onchange = "showRequiredFieldsBasedOnLocation()">
<option value = "">Select</option>
<option value = "museum">Museum</option>
<option value = "schools/college">Schools/College</option>
<option value = "hospital">Hospitals</option>
<option value = "hospital">Auditorium</option>
</select>
</div>
<div class="form-group col-md-3 common_location_occupancy">
<label for="isBasement_${increment}">Basement<span class = "text-danger">*</span></label>
<select id="isBasement_${increment}" name="isBasement[]" class="form-control common_location_occupancy" >
<option value = "yes" selected>Yes</option>
<option value = "no">No</option>
</select>
</div>
<div class = "form-group col-md-3 single_location_occupancy>
<label for = "pumSI_${increment}">PUM Sum Insured Limit<span class = "text-danger">*</span></label>
<input type = "num" id = "pumSI_${increment}" name = "pumSI" class = "form-control single_location_occupancy"/>
</div>
<div class="form-group col-md-3 common_location_occupancy">
<label for="iibCode_${increment}">IIB Code<span class = "text-danger">*</span></label>
<input type = "text" id="iibCode_${increment}" name="iibCode[]" class="form-control common_location_occupancy" >
</div>
<div class="form-group col-md-3 single_location_occupancy">
<label for="eqZone_${increment}">EQ Zone<span class = "text-danger">*</span></label>
<input type = "text" id="eqZone_${increment}" name="eqZone[]" class="form-control single_location_occupancy" >
</div>
<div class="form-group col-md-3 single_location_occupancy">
<label for="floodRisk_${increment}">Flood Risk Category<span class = "text-danger">*</span></label>
<select id="floodRisk_${increment}" name="floodRisk[]" class="form-control single_location_occupancy" >
<option value = "low" selected>Low</option>
<option value = "mid">Mid</option>
<option value = "high">High</option>
</select>
</div>
<div class="form-group col-md-3 single_location_occupancy">
<label for="stormRisk_${increment}">Storm Risk Category<span class = "text-danger">*</span></label>
<select id="stormRisk_${increment}" name="stormRisk[]" class="form-control single_location_occupancy" >
<option value = "low" selected>Low</option>
<option value = "mid">Mid</option>
<option value = "high">High</option>
</select>
</div>
<div class="form-group col-md-3 single_location_occupancy">
<label for="working_or_silent_${increment}">If used as an Industrial Manufacturing unit, please state whether the factory is working or silent <span class = "text-danger">*</span></label>
<select id="working_or_silent_${increment}" name="working_or_silent[]" class="form-control single_location_occupancy" >
<option value = "working" selected >Working</option>
<option value = "silent" selected >Silent</option>
</select>
</div>
<div class = "form-group col-md-3">
<label for = "select_location_${increment}">Location <span class = "text-danger">*</span></label>
<select id = "select_location_${increment}" name = "select_location[]" value = "1" ></select>
</div>
<div class="row">
<div class="form-group col-md-12 multiLocationOccupancy">
<label for="buisness_desc_${increment}">Buisness Description <span class = "text-danger">*</span></label>
<textarea id="buisness_desc_${increment}" name="buisness_desc[]" class="form-control multiLocationOccupancy" rows="3"></textarea>
</div>
<div class = "form-group col-md-3 multiLocationOccupancyWithoutFloater>
<label for = "age_of_building_${increment}">Age of Building <span class = "text-danger">*</span></label>
<select id = "age_of_building_${increment}" name = "age_of_building[]" class="form-control multiLocationOccupancyWithoutFloater">
<option value = "upto20" selected>Upto 20</option>
<option value = "20to30">20 to 30</option>
<option value = "above30">Above 30</option>
</select>
</div>
<div class = "form-group col-md-5 multiLocationOccupancyWithoutFloater>
<label for = "isHigherGrouds_${increment}">Is Risk Located on Higher Grounds <span class = "text-danger">*</span></label>
<select id = "isHigherGrouds_${increment}" name = "isHigherGrouds[]" class="form-control multiLocationOccupancyWithoutFloater">
<option value = "no" selected>No</option>
<option value = "yes">Yes</option>
</select>
</div>
</div>
<div class="row mt-2">
<div class="form-group col-md-3">
<button type = "button" class="btn btn-secondary duplicate-btn">Add/Duplicate Locations</button>
</div>
</div>
</div>
<hr>
`;
// newRow2.innerHTML += `
// <div class = "row">
// <div class="col-md-12 text-right">
// <button type ="submit" id="riskSplitup" class="btn btn-primary">Validate and Add Risk Split up</button>
// </div>
// </div>
// <div class = "row">
// <div class="col-md-12 text-right">
// <button type ="submit" id="submitPolicyRisk" class="btn btn-primary">Submit For Validation</button>
// </div>
// </div>
// `;
container.appendChild(newRow);
// container.appendChild(newRow2);
const selectElement = document.getElementById(`select_location_${increment}`);
for (let i = 1; i <= policyDetailsData.location_no; i++) {
const option = document.createElement('option');
option.value = `Location ${i}`;
option.textContent = `Location ${i}`;
selectElement.appendChild(option);
}
increment++;
}
$(document).on('change', '[id^="occupancy_"]', function() {
// var selectedProduct = productSelectionData;
// if (selectedProduct.singleProduct == 'on') {
// }
});
$(document).on('click', '.duplicate-btn', function() {
console.log("button is clicked");
console.log("increment cout ", increment);
if (policyDetailsData.location_no >= increment) {
const $rowToClone = $(this).closest('.form-row');
// Clone the row
const $clone = $rowToClone.clone();
// Increment the counter
// Update all IDs and reset values in the clone
$clone.find('[id]').each(function() {
const oldId = $(this).attr('id');
const newId = oldId.replace(/_(\d+)$/, `_${increment}`);
$(this).attr('id', newId);
});
// Update labels to match new IDs
$clone.find('label').each(function() {
const oldFor = $(this).attr('for');
if (oldFor) {
const newFor = oldFor.replace(/_(\d+)$/, `_${increment}`);
$(this).attr('for', newFor);
}
});
// Insert the cloned row after the original
$clone.insertAfter($rowToClone);
let selectedLocation = $(`#select_location_${increment - 1}`).val();
$(`#select_location_${increment} option[value="${selectedLocation}"]`).remove();
increment++;
} else {
toastr.error("Maximum no of allowed locations reached", "Error")
}
})
function addOrRemoveAdd() {
console.log("chceck box clicked");
if ($("#sameAsCommunicationAddress").is(":checked")) {
$("#pin_code_1").val(policyDetailsData.pin_code);
$("#address1_1").val(policyDetailsData.address1);
$("#address2_1").val(policyDetailsData.address2);
$("#address3_1").val(policyDetailsData.address3);
} else {
$("#pin_code_1").val("");
$("#address1_1").val("");
$("#address2_1").val("");
$("#address3_1").val("");
}
}
function validatePolicyBasedOnProductSelection() {
var selectedProduct = productSelectionData;
if (selectedProduct.singleProduct == 'on') {
console.log("inside if ");
$('[class*="single_location"]').show();
$("#locationNoDIV").hide();
$("#location_no").removeAttr("required", false);
$('[class*="duplicate-btn"]').hide();
$("[id^='select_location']").hide();
$('[id^="select_location"]').hide().prev('label').hide();
$("[id^='select_location']").removeAttr('required', false);
// $('[class*="single_location_occupancy"]').hide().removeAttr("required", false);
$('[class*="multi_location_company"]').hide().removeAttr('required');
$("#riskSplitup").hide();
$("#submitPolicyRisk").show();
$("#risksplitupTab").hide();
// $('[class*="multiLocationOccupancy"]').hide().removeAttr('required', false);
// $('[class*="multiLocationOccupancyWithoutFloater"]').hide().removeAttr('required', false);
} else if (selectedProduct.multipleProduct == 'on') {
console.log("inside elseif");
$('[class*="single_location"]').hide().removeAttr('required');
// $('[class*="single_location_occupancy"]').hide().removeAttr('required');
$('[class*="multi_location_company"]').show();
$("#sameAsCommunicationAddress_div").hide();
$("#locationNoDIV").show();
$("#location_no").prop("required", "required");
$("#riskSplitup").show();
$("#submitPolicyRisk").hide();
// $('[class*="multiLocationOccupancyWithoutFloater"]').hide().removeAttr('required', false);
$("#risksplitupTab").show();
if (selectedProduct.multilocation_type == "stockFloater") {
$('[class*="stockSI"]').hide().removeAttr('required', false);
}
}
// $('[class*="common_location_occupancy"]').hide().removeAttr('required');
// $('[class*="multiLocationOccupancyWithoutFloater"]').hide().removeAttr('required', false);
// $('[class*="multiLocationOccupancy"]').hide().removeAttr('required', false);
}
function showRequiredFieldsBasedOnLocation() {
$('[class*="common_location_occupancy"]').show().prop("required", "required");
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.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);
}
}
}
function registerPolicyData() {
// Build the initial JSON object with productSelection and policyDetails
var outputData = {
productSelection: productSelectionData,
policyDetails: policyDetailsData,
locations: []
};
// Loop over each policy risk address
$.each(policyRiskAddress, function(index, riskAddress) {
// Find the corresponding policyRiskSplitUp entry by matching the location identifier
var matchingRiskSplitUp = $.grep(policyRiskSplitUpData, function(item) {
return item.location_selected === riskAddress.select_location;
});
// If a match is found, use the first match; otherwise, use an empty object.
var riskSplitUpData = matchingRiskSplitUp.length > 0 ? matchingRiskSplitUp[0] : {};
// Create a location object that groups the risk and split-up data together
var locationObj = {
select_location: riskAddress.select_location,
policyRisk: riskAddress,
policyRiskSplitUp: riskSplitUpData
};
// Add this location to the locations array
outputData.locations.push(locationObj);
});
console.log(outputData);
return outputData;
}
function savePolicyDataLocal() {
// Generate the JSON structure using the registerPolicyData function
var policyData = registerPolicyData();
// Save the JSON as a string in localStorage under the key 'policyData'
$('.loader').fadeIn();
$('.loader-mask').fadeIn();
localStorage.setItem('policyData', JSON.stringify(policyData));
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
toastr.success("Policy Registered Successfully");
console.log("Policy data saved to local storage. : ", policyData);
}
function loadPolicyDataBack(storedData) {
if (storedData) {
var parsedData = storedData;
// Assign back to original variables
productSelectionData = parsedData.productSelection;
policyDetailsData = parsedData.policyDetails;
// Since your JSON groups locations together,
// extract policyRiskAddress and policyRiskSplitUpData from each location
policyRiskAddress = [];
policyRiskSplitUpData = [];
$.each(parsedData.locations, function(index, loc) {
policyRiskAddress.push(loc.policyRisk);
policyRiskSplitUpData.push(loc.policyRiskSplitUp);
});
console.log("Data restored to original variables.");
} else {
console.log("No policy data found in local storage.");
}
}
function prepareDataForEdit(data) {
loadPolicyDataBack(data);
// Populate Product Selection
$('#singleProduct').prop('checked', data.productSelection.singleProduct === 'on');
$('#multipleProduct').prop('checked', data.productSelection.multipleProduct === 'on');
console.log($('#multipleProduct').is(":checked") ? "yes" : "no");
$('#multipleProduct').is(":checked") ? $('#multilocation_type').show() : $('#multilocation_type').hide();
$('#multilocation_type').val(data.productSelection.multilocation_type);
// Trigger product selection change
$('.business-type-checkbox').trigger('change');
// Populate Policy Details
const policyDetails = data.policyDetails;
Object.keys(policyDetails).forEach(key => {
$(`#${key}`).val(policyDetails[key]);
// console.log("Key ",key," set value : ",policyDetails[key]);
});
// Populate Risk Addresses
data.locations.forEach((location, index) => {
addHTMLInputForRiskAddress();
//showRequiredFieldsBasedOnLocation();
// if (index > 0) $('.duplicate-btn').first().trigger('click');
const prefix = `_${index + 1}`;
const risk = location.policyRisk;
// Populate address fields
$(`#pin_code${prefix}`).val(risk.pin_code);
$(`#address1${prefix}`).val(risk.address1);
$(`#address2${prefix}`).val(risk.address2);
$(`#address3${prefix}`).val(risk.address3);
// Populate risk details
$(`#constructionType${prefix}`).val(risk.constructionType);
$(`#occupancy${prefix}`).val(risk.occupancy).trigger("change");
$(`#isBasement${prefix}`).val(risk.isBasement);
$(`#iibCode${prefix}`).val(risk.iibCode);
$(`#buisness_desc${prefix}`).val(risk.buisness_desc);
$(`#select_location${prefix}`).val(risk.select_location);
$(`#pumSI${prefix}`).val(risk.pumSI);
$(`#eqZone${prefix}`).val(risk.eqZone);
$(`#basementSI${prefix}`).val(risk.basementSI);
});
// Populate Risk Split-Up Data
data.locations.forEach((location, index) => {
addHTMLInputForRiskSplitUP();
//showRequiredFieldsBasedOnLocation();
const prefix = `_${index + 1}`;
const splitUp = location.policyRiskSplitUp;
$(`#building${prefix}`).val(splitUp.building);
$(`#content${prefix}`).val(splitUp.content);
$(`#furniture${prefix}`).val(splitUp.furniture);
$(`#plantAndMachinery${prefix}`).val(splitUp.plantAndMachinery);
$(`#electricalFittings${prefix}`).val(splitUp.electricalFittings);
$(`#stockInProcess${prefix}`).val(splitUp.stockInProcess);
$(`#rawMaterial${prefix}`).val(splitUp.rawMaterial);
$(`#finishedStock${prefix}`).val(splitUp.finishedStock);
});
// Show first tab
$('#product-selection-tab a').tab('show');
// Update all increment counters
increment = data.locations.length + 1;
increment2 = data.locations.length + 1;
//showRequiredFieldsBasedOnLocation();
}
function assignLeadData(){
const lead_data = '<?= json_encode($lead_data['custom_fields']) ?>';
if (lead_data){
console.log("Lead Data : ",lead_data);
}
}
</script>