902 lines
36 KiB
PHP
902 lines
36 KiB
PHP
<style>
|
|
.readonly-color {
|
|
background-color: #e0e0e0;
|
|
/* Darker background */
|
|
color: #666;
|
|
/* Darker text color */
|
|
}
|
|
|
|
.readonly-select {
|
|
pointer-events: none;
|
|
background-color: #f0f0f0;
|
|
color: #666;
|
|
}
|
|
</style>
|
|
|
|
<style>
|
|
.select2-hidden-accessible+.select2-container .select2-dropdown {
|
|
display: none !important;
|
|
}
|
|
|
|
.select2-container .select2-selection--multiple .select2-selection__choice {
|
|
color: #000000;
|
|
}
|
|
|
|
.select2-selection__choice {
|
|
background-color: #0a8794 !important;
|
|
color: white !important;
|
|
font-weight: bold;
|
|
}
|
|
|
|
.select2-selection__choice__remove {
|
|
color: white !important;
|
|
margin-right: 5px;
|
|
}
|
|
</style>
|
|
|
|
<div class="row" id="leads_form" style="display:none;">
|
|
<div class="col-12">
|
|
<div class="card">
|
|
<div class="card-body">
|
|
<div class="row" style="margin-bottom:1rem;">
|
|
|
|
<div class="col-6" style="align-self: center;">
|
|
<h4 id="page_title" style="position: relative;">Add Lead</h4>
|
|
</div>
|
|
<div class="col-3" style="text-align: right; position: relative; left: 211px;">
|
|
<!-- <button class="btn btn-primary waves-effect waves-light" onclick="fileupload(this)">file upload</button> -->
|
|
</div>
|
|
<div class="col-1" style="text-align: right; position: relative; left: 193px;">
|
|
<a href="<?= base_url('leads/list') ?>" type="button" id="btnAdd"
|
|
class="btn btn-primary waves-effect waves-light">Back</a>
|
|
</div>
|
|
</div>
|
|
<form role="form" class="parsley-examples" method="post" id="leads_form_id"
|
|
enctype="multipart/form-data">
|
|
|
|
<input type="hidden" name="id" id="leads_primarykey">
|
|
|
|
<div class="form-row">
|
|
|
|
<div class="form-group col-md-3">
|
|
<label for="lead_type">Lead Type<span class="text-danger">*</span></label>
|
|
<select class="form-control" id="lead_type" name="lead_type" required>
|
|
<option value="">Select Lead Type</option>
|
|
<?php
|
|
if (isset($lead_type) && count($lead_type)) {
|
|
foreach ($lead_type as $key => $value) {
|
|
if($key == 1){
|
|
echo "<option value=" . $key . " selected>" . $value . "</option>";
|
|
}else{
|
|
echo "<option value=" . $key . ">" . $value . "</option>";
|
|
}
|
|
}
|
|
}
|
|
?>
|
|
</select>
|
|
</div>
|
|
|
|
<div class="form-group col-md-3">
|
|
<label for="issuer">Issuer<span class="text-danger">*</span></label>
|
|
<select class="form-control" id="issuer" name="issuer" required>
|
|
<option value="">Select Issuer</option>
|
|
<?php
|
|
if (isset($issuer) && count($issuer)) {
|
|
foreach ($issuer as $key => $value) {
|
|
echo "<option value=" . $key . ">" . $value . "</option>";
|
|
}
|
|
}
|
|
?>
|
|
</select>
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<hr>
|
|
|
|
<!-- client row -->
|
|
<div class="form-row" id="freshDiv">
|
|
|
|
<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" required>
|
|
<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="entity_type_id">Entity Type<span class="text-danger">*</span></label>
|
|
<select class="form-control" id="entity_type_id" name="entity_type_id" required>
|
|
<option value="" selected>Select Entity</option>
|
|
<?php
|
|
if (isset($entity) && count($entity)) {
|
|
foreach ($entity as $key => $value) {
|
|
echo "<option value=" . $value['id'] . ">" . $value['name'] . "</option>";
|
|
}
|
|
}
|
|
?>
|
|
</select>
|
|
</div>
|
|
|
|
<div class="form-group col-md-3">
|
|
<label for="client_name">Client Name<span class="text-danger">*</span></label>
|
|
<input type="text" class="form-control" id="client_name" name="client_name"
|
|
placeholder="Enter Client Name" required>
|
|
</div>
|
|
|
|
<div class="form-group col-md-3">
|
|
<label for="client_short_name">Client Short Name<span class="text-danger">*</span></label>
|
|
<input type="text" class="form-control" id="client_short_name" name="client_short_name"
|
|
placeholder="Enter Client Short Name" required>
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="form-row" id="renewalDiv" style="display: none;">
|
|
|
|
<div class="form-group col-md-3">
|
|
<label for="client_id">Client<span class="text-danger">*</span></label>
|
|
<select class="form-control" id="client_id" name="client_id">
|
|
<option value="">Select Client</option>
|
|
</select>
|
|
</div>
|
|
|
|
<div class="form-group col-md-3">
|
|
<label for="client_branch_id">Branch<span class="text-danger">*</span></label>
|
|
<select class="form-control" id="client_branch_id" name="client_branch_id"
|
|
onchange="getBranchData(this)">
|
|
<option value="">Select Branch</option>
|
|
</select>
|
|
</div>
|
|
|
|
<div class="form-group col-md-3">
|
|
<label for="source_policy_id"> Source Policy <span id="base_danger"
|
|
class="text-danger">*</span></label>
|
|
<select class="form-control" id="source_policy_id" name="source_policy_id">
|
|
<option value="" selected>Select Source Policy</option>
|
|
</select>
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="form-row">
|
|
<div class="form-group col-md-3">
|
|
<label for="pan">PAN<span class="text-danger"></span></label>
|
|
<input type="text" class="form-control" id="pan" placeholder="Enter PAN Number" data-parsley-error-message="Invalid PAN Number. Example: ABCDE1234F" name="pan" data-parsley-trigger="change" data-parsley-pattern="^[A-Z]{5}[0-9]{4}[A-Z]$">
|
|
</div>
|
|
</div>
|
|
<!-- end client row -->
|
|
|
|
<hr>
|
|
|
|
<!-- branch row-->
|
|
<div class="form-row">
|
|
|
|
<div class="form-group col-md-3">
|
|
<label for="gst">GST<span class="text-danger">*</span></label>
|
|
<input type="text" class="form-control" id="gst" placeholder="Enter GST Number"
|
|
data-parsley-error-message="Invalid GST Number. Example: 12ABCDE1234F5Z6" name="gst"
|
|
data-parsley-trigger="change"
|
|
data-parsley-pattern="^\d{2}[A-Z]{5}\d{4}[A-Z]{1}[A-Z\d]{1}[Z]{1}[A-Z\d]{1}$" required>
|
|
</div>
|
|
|
|
<div class="form-group col-md-3">
|
|
<label for="client_branch">Branch Name<span class="text-danger">*</span></label>
|
|
<input type="text" class="form-control" id="branch_name" name="branch_name"
|
|
placeholder="Enter Branch Name" required>
|
|
</div>
|
|
|
|
<div class="form-group col-md-3">
|
|
<label for="client_branch">Branch Code<span class="text-danger">*</span></label>
|
|
<input type="text" class="form-control" id="branch_code" name="branch_code"
|
|
placeholder="Enter Branch Code" required>
|
|
</div>
|
|
|
|
<div class="form-group col-md-3">
|
|
<label for="client_branch">Contact Person Name<span class="text-danger">*</span></label>
|
|
<input type="text" class="form-control" id="contact_person_name" name="contact_person_name"
|
|
placeholder="Enter Contact Name" required>
|
|
</div>
|
|
|
|
<div class="form-group col-md-3">
|
|
<label for="contact_person_mobile">Contact Person Mobile<span class="text-danger">*</span></label>
|
|
<input type="text" class="form-control" id="contact_person_mobile" name="contact_person_mobile"
|
|
placeholder="Enter Contact Mobile" required>
|
|
</div>
|
|
|
|
<div class="form-group col-md-3">
|
|
<label for="contact_person_email">Contact Person Email<span class="text-danger">*</span></label>
|
|
<input type="text" class="form-control" id="contact_person_email" name="contact_person_email"
|
|
placeholder="Enter Contact Email" required>
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<!-- policy row -->
|
|
<div id="dynamic-form-container"></div>
|
|
|
|
<hr>
|
|
|
|
<!-- other row -->
|
|
<div class="form-row">
|
|
|
|
<div class="form-group col-md-3">
|
|
<label for="salse_person_id">Sales Person<span class="text-danger">*</span></label>
|
|
<select class="form-control" id="salse_person_id" name="salse_person_id" multiple required>
|
|
<option value="">Select Sales Person</option>
|
|
<?php if (isset($salse_team)) { ?>
|
|
<?php foreach ($salse_team as $value) { ?>
|
|
<option value="<?= $value['id'];?>">
|
|
<?= $value['first_name'];?>
|
|
</option>
|
|
<?php } ?>
|
|
<?php } ?>
|
|
</select>
|
|
</div>
|
|
|
|
<div class="form-group col-md-3">
|
|
<label for="status"> Status <span id="base_danger" class="text-danger">*</span></label>
|
|
<select class="form-control" id="lead_status" name="status" required>
|
|
<option value="" selected>Select Status</option>
|
|
<?php
|
|
if (isset($lead_status) && count($lead_status)) {
|
|
foreach ($lead_status as $key => $value) {
|
|
if($key == 'queued'){
|
|
echo "<option value=" . $key . " selected>" . $value . "</option>";
|
|
}else{
|
|
echo "<option value=" . $key . ">" . $value . "</option>";
|
|
}
|
|
}
|
|
}
|
|
?>
|
|
</select>
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="form-row">
|
|
<div class="form-group col-md-12">
|
|
<label for="notes">Note</label>
|
|
<textarea class="form-control" id="notes" name="notes" rows="4"></textarea>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="form-group text-right m-b-0" id="submitButton">
|
|
<button type="submit" class="btn btn-primary waves-effect waves-light mr-1"
|
|
id="btnSubmit">Submit</button>
|
|
</div>
|
|
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div><!-- end form row -->
|
|
|
|
|
|
<script>
|
|
|
|
//SELECT2 document ready function
|
|
$(document).ready(function() {
|
|
|
|
getURLParamsForReport()
|
|
addHTMLInput()
|
|
setTimeout(function() {
|
|
$("textarea.select2-search__field").attr('rows', '1');
|
|
$("textarea.select2-search__field").css('resize', 'none');
|
|
}, 1000)
|
|
|
|
$('#insurer').select2();
|
|
$('#tpa').select2();
|
|
$('#proposed_insurer').select2();
|
|
$('#proposed_tpa').select2();
|
|
|
|
})
|
|
|
|
//DATE document ready function
|
|
// $(document).ready(function(){
|
|
|
|
// var today = new Date();
|
|
|
|
// var policy_start_date = flatpickr(".policy_start_date", {
|
|
// dateFormat: "d/m/Y",
|
|
// // defaultDate: today,
|
|
// allowInput: false,
|
|
// onChange: function(selectedDates, dateStr, instance) {
|
|
// var policy_end_date = new Date(selectedDates[0]);
|
|
// policy_end_date.setFullYear(policy_end_date.getFullYear() + 1);
|
|
// policy_end_date.setDate(policy_end_date.getDate() - 1); // Set end date to last day of selected year
|
|
// policy_end_datePicker.setDate(policy_end_date);
|
|
// }
|
|
// });
|
|
|
|
// // Calculate the end date (today + 1 year)
|
|
// // var closeDate = new Date(today);
|
|
// // closeDate.setFullYear(closeDate.getFullYear() + 1);
|
|
// // closeDate.setDate(closeDate.getDate() - 1); // Set end date to last day of next year
|
|
|
|
// var policy_end_datePicker = flatpickr(".policy_end_date", {
|
|
// dateFormat: "d/m/Y",
|
|
// // defaultDate: closeDate,
|
|
// allowInput: false
|
|
// });
|
|
// })
|
|
|
|
//---------------------------------------------------------------------------------------------------------
|
|
|
|
//view and edit Lead data function
|
|
function getLeadsDataForEdit(input) {
|
|
|
|
$('.loader').fadeIn();
|
|
$('.loader-mask').fadeIn();
|
|
|
|
$('#leads_form_id')[0].reset();
|
|
|
|
var id = input;
|
|
console.log('Selected Leads:', id);
|
|
|
|
$.ajax({
|
|
url: '<?= base_url("leads/list/") ?>' + id,
|
|
type: "GET",
|
|
dataType: 'json',
|
|
success: function(res) {
|
|
|
|
$('.btnDiv').hide();
|
|
console.log('getLeadsDataForEdit', res);
|
|
|
|
if (res.status == true) {
|
|
|
|
hide_list_show_add();
|
|
|
|
var page_title = 'Edit Lead';
|
|
|
|
$('#page_title').text(page_title);
|
|
$('#leads_primarykey').val(res.data.id);
|
|
|
|
$('#lead_type').val(res.data.lead_type);
|
|
$('#issuer').val(res.data.issuer);
|
|
$('#client_type').val(res.data.client_type);
|
|
$('#client_name').val(res.data.client_name);
|
|
$('#client_short_name').val(res.data.client_short_name);
|
|
$('#entity_type_id').val(res.data.entity_type_id);
|
|
$('#lead_status').val(res.data.status);
|
|
$('#notes').val(res.data.notes);
|
|
|
|
|
|
setTimeout(function() {
|
|
$('#client_id').val(res.data.client_id).change();
|
|
setTimeout(function() {
|
|
$('#client_branch_id').val(res.data.client_branch_id).change();
|
|
setTimeout(function() {
|
|
$('#source_policy_id').val(res.data.source_policy_id)
|
|
.change();
|
|
$('#pan').val(res.data.pan);
|
|
$('#gst').val(res.data.gst);
|
|
$('#branch_name').val(res.data.branch_name);
|
|
$('#branch_code').val(res.data.branch_code);
|
|
$('#contact_person_name').val(res.data.contact_person_name);
|
|
$('#contact_person_mobile').val(res.data.contact_person_mobile);
|
|
$('#contact_person_email').val(res.data.contact_person_email);
|
|
|
|
$('.loader').fadeOut();
|
|
$('.loader-mask').delay(350).fadeOut('slow');
|
|
}, 1000)
|
|
}, 1000);
|
|
}, 1000);
|
|
|
|
var insurer = res.data.insurer_branch_id + '-' + res.data.insurer_id;
|
|
var tpa = res.data.tpa_branch_id + '-' + res.data.tpa_id;
|
|
|
|
var proposed_insurer = res.data.proposed_insurer_branch_id + '-' + res.data.proposed_insurer_id;
|
|
var proposed_tpa = res.data.proposed_tpa_branch_id + '-' + res.data.proposed_tpa_id;
|
|
|
|
$('#policy_type_id_1').val(res.data.policy_type_id).change();
|
|
$('#insurer_1').val(insurer).select2();
|
|
$('#tpa_1').val(tpa).select2();
|
|
$('#proposed_insurer_1').val(proposed_insurer).select2();
|
|
$('#proposed_tpa_1').val(proposed_tpa).select2();
|
|
$('#policy_start_date_1').val(res.data.policy_start_date);
|
|
$('#policy_end_date_1').val(res.data.policy_end_date);
|
|
$('#no_of_lives').val(res.data.no_of_lives);
|
|
$('#claims').val(res.data.claims);
|
|
$('#location').val(res.data.location);
|
|
|
|
|
|
if (res.data.salse_person_id) {
|
|
selecSalsePerson(res.data.salse_person_id);
|
|
}
|
|
|
|
if (res.data.lead_type == 2) {
|
|
$('#renewalDiv').find('select, input').attr('required', 'required');
|
|
$('#freshDiv').find('select, input').removeAttr('required');
|
|
$('#renewalDiv').show();
|
|
$('#freshDiv').hide();
|
|
$('.proposed_div').show().find('select, input').attr('required', 'required');
|
|
} else {
|
|
$('#renewalDiv').find('select, input').removeAttr('required');
|
|
$('#freshDiv').find('select, input').attr('required', 'required');
|
|
$('#renewalDiv').hide();
|
|
$('#freshDiv').show();
|
|
$('.proposed_div').hide().find('select, input').removeAttr('required');
|
|
}
|
|
|
|
|
|
} else {
|
|
console.log('No data found');
|
|
}
|
|
},
|
|
error: function(xhr, status, error) {
|
|
$('.loader').fadeOut();
|
|
$('.loader-mask').delay(350).fadeOut('slow');
|
|
console.error(xhr.responseText);
|
|
console.error(status, error);
|
|
}
|
|
});
|
|
}
|
|
|
|
//client branch data
|
|
function getBranchData(input) {
|
|
|
|
var client_branch_id = $(input).val();
|
|
|
|
if (client_branch_id) {
|
|
|
|
$('.loader').fadeIn();
|
|
$('.loader-mask').fadeIn();
|
|
|
|
$.ajax({
|
|
url: '<?php echo base_url('util/get_client_branch_data/');?>' + client_branch_id,
|
|
type: "GET",
|
|
dataType: 'json',
|
|
success: function(res) {
|
|
|
|
console.log('getBranchData response', res);
|
|
|
|
if (res.status == true) {
|
|
|
|
$('#gst').val(res.data.gst);
|
|
$('#pan').val(res.data.pan);
|
|
$('#branch_name').val(res.data.branch_name);
|
|
$('#branch_code').val(res.data.branch_code);
|
|
$('#contact_person_name').val(res.contact.name);
|
|
$('#contact_person_mobile').val(res.contact.mobile);
|
|
$('#contact_person_email').val(res.contact.email);
|
|
|
|
$('.loader').fadeOut();
|
|
$('.loader-mask').delay(350).fadeOut('slow');
|
|
|
|
} else {
|
|
|
|
$('#gst').val('');
|
|
$('#pan').val('');
|
|
$('#branch_name').val('');
|
|
$('#branch_code').val('');
|
|
$('#contact_person_name').val('');
|
|
$('#contact_person_mobile').val('');
|
|
$('#contact_person_email').val('');
|
|
|
|
console.log(res.message, 'warning');
|
|
}
|
|
|
|
$('.loader').fadeOut();
|
|
$('.loader-mask').delay(350).fadeOut('slow');
|
|
},
|
|
error: function(xhr, status, error) {
|
|
console.error(xhr.responseText);
|
|
console.error(status, error);
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
//Client Policy Data
|
|
function getPolicyData(input) {
|
|
var client_policy_id = $(input).val();
|
|
if (client_policy_id) {
|
|
|
|
$('.loader').fadeIn();
|
|
$('.loader-mask').fadeIn();
|
|
|
|
$.ajax({
|
|
url: '<?php echo base_url('client/policy/list/');?>' + client_policy_id,
|
|
type: "GET",
|
|
dataType: 'json',
|
|
success: function(res) {
|
|
|
|
console.log('getPolicyData response', res);
|
|
|
|
if (res.status == true) {
|
|
|
|
$('#gst').val(res.data.gst);
|
|
$('#pan').val(res.data.pan);
|
|
$('#branch_name').val(res.data.branch_name);
|
|
$('#branch_code').val(res.data.branch_code);
|
|
$('#contact_person_name').val(res.contact.name);
|
|
$('#contact_person_mobile').val(res.contact.mobile);
|
|
$('#contact_person_email').val(res.contact.email);
|
|
|
|
$('.loader').fadeOut();
|
|
$('.loader-mask').delay(350).fadeOut('slow');
|
|
|
|
} else {
|
|
|
|
$('#gst').val('');
|
|
$('#pan').val('');
|
|
$('#branch_name').val('');
|
|
$('#branch_code').val('');
|
|
$('#contact_person_name').val('');
|
|
$('#contact_person_mobile').val('');
|
|
$('#contact_person_email').val('');
|
|
|
|
console.log(res.message, 'warning');
|
|
}
|
|
|
|
$('.loader').fadeOut();
|
|
$('.loader-mask').delay(350).fadeOut('slow');
|
|
},
|
|
error: function(xhr, status, error) {
|
|
console.error(xhr.responseText);
|
|
console.error(status, error);
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
// Salse team user list data
|
|
function selecSalsePerson(salse_person_ids) {
|
|
|
|
salse_person_ids = JSON.parse(salse_person_ids);
|
|
// Loop through each insurer-branch combination
|
|
$.each(salse_person_ids, function(index, value) {
|
|
// Use value in the format 'branch_id-insurer_id'
|
|
$('#salse_person_id option').each(function() {
|
|
if ($(this).val() === value) {
|
|
$(this).prop('selected', true); // Select the matching option
|
|
}
|
|
});
|
|
});
|
|
// Trigger change for plugins (like Select2)
|
|
$('#salse_person_id').trigger('change');
|
|
}
|
|
|
|
//---------------------------------------------------------------------------------------------------------
|
|
|
|
var increment = 1;
|
|
|
|
function addHTMLInput() {
|
|
|
|
const container = document.getElementById('dynamic-form-container');
|
|
const newRow = document.createElement('div');
|
|
newRow.className = 'form-row dynamic-form-row';
|
|
|
|
// Add an <hr> element
|
|
const hrElement = document.createElement('hr');
|
|
container.appendChild(hrElement);
|
|
|
|
// Set inner HTML with necessary input fields
|
|
newRow.innerHTML += `
|
|
|
|
<div class="form-group col-md-3">
|
|
<label for="policy_type_id">Policy Type <span class="text-danger">*</span></label>
|
|
<select class="form-control" id="policy_type_id_${increment}" name="policy_type_id[]" required>
|
|
<option value="">Select Policy Type</option>
|
|
<?php
|
|
if (isset($policy_type) && count($policy_type)) {
|
|
foreach ($policy_type as $value) {
|
|
echo "<option value='" . $value['id'] . "'>" .
|
|
$value['policy_type'] .
|
|
"</option>";
|
|
}
|
|
}
|
|
?>
|
|
</select>
|
|
</div>
|
|
|
|
<div class="form-group col-md-3">
|
|
<label for="insurer">Insurer <span class="text-danger">*</span></label>
|
|
<select class="form-control" id="insurer_${increment}" name="insurer[]" onchange="insurerChange(this, ${increment})" required>
|
|
<option value="">Select Insurer</option>
|
|
<?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>
|
|
|
|
<div class="form-group col-md-3">
|
|
<label for="tpa">TPA <span class="text-danger">*</span></label>
|
|
<select class="form-control" id="tpa_${increment}" name="tpa[]" onchange="tpaChange(this, ${increment})" required>
|
|
<option value="">Select TPA</option>
|
|
<?php if (isset($tpa)) { ?>
|
|
<?php foreach ($tpa as $value) { ?>
|
|
<option value="<?= $value['id'] . '-' . $value['tpa_id'] ?>">
|
|
<?= $value['tpa_short_name'] . '-' . $value['branch_code'] ?>
|
|
</option>
|
|
<?php } ?>
|
|
<?php } ?>
|
|
</select>
|
|
</div>
|
|
|
|
<div class="form-group col-md-3">
|
|
<label for="no_of_lives">No of Lives <span class="text-danger">*</span></label>
|
|
<input type="text" class="form-control" id="no_of_lives" name="no_of_lives[]" placeholder="Enter Lives" required>
|
|
</div>
|
|
|
|
<div class="form-group col-md-3">
|
|
<label for="policy_start_date_${increment}">Date of Commencement <span class="text-danger">*</span></label>
|
|
<input type="text" class="form-control policy_start_date" id="policy_start_date_${increment}" name="policy_start_date[]" placeholder="Enter DOC" required>
|
|
</div>
|
|
|
|
<div class="form-group col-md-3">
|
|
<label for="policy_end_date_${increment}">Date of Expiry <span class="text-danger">*</span></label>
|
|
<input type="text" class="form-control policy_end_date" id="policy_end_date_${increment}" name="policy_end_date[]" placeholder="Enter DOE" required>
|
|
</div>
|
|
|
|
<div class="form-group col-md-3">
|
|
<label for="claims">Claims <span class="text-danger">*</span></label>
|
|
<input type="text" class="form-control" id="claims" name="claims[]" placeholder="Enter Claims" required>
|
|
</div>
|
|
|
|
<div class="form-group col-md-3">
|
|
<label for="location">Location <span class="text-danger">*</span></label>
|
|
<input type="text" class="form-control" id="location" name="location[]" placeholder="Enter Location" required>
|
|
</div>
|
|
|
|
<div class="form-group col-md-3 proposed_div" style="display: none;">
|
|
<label for="proposed_insurer">Proposed Insurer <span class="text-danger">*</span></label>
|
|
<select class="form-control" id="proposed_insurer_${increment}" name="proposed_insurer[]" required>
|
|
<option value="">Select Insurer</option>
|
|
<?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>
|
|
|
|
<div class="form-group col-md-3 proposed_div" style="display: none;">
|
|
<label for="proposed_tpa">Proposed TPA <span class="text-danger">*</span></label>
|
|
<select class="form-control" id="proposed_tpa_${increment}" name="proposed_tpa[]" required>
|
|
<option value="">Select TPA</option>
|
|
<?php if (isset($tpa)) { ?>
|
|
<?php foreach ($tpa as $value) { ?>
|
|
<option value="<?= $value['id'] . '-' . $value['tpa_id'] ?>">
|
|
<?= $value['tpa_short_name'] . '-' . $value['branch_code'] ?>
|
|
</option>
|
|
<?php } ?>
|
|
<?php } ?>
|
|
</select>
|
|
</div>
|
|
|
|
<div class="form-group col-md-12 btnDiv" style="position: relative;top: 28px;float: right;text-align: end;">
|
|
<a class="btn btn-danger waves-effect waves-light" onclick="removeHTMLInput(this)">x</a>
|
|
<a class="btn btn-primary waves-effect waves-light mr-1" onclick="addHTMLInput()">+</a>
|
|
</div>
|
|
`;
|
|
|
|
container.appendChild(newRow);
|
|
|
|
|
|
var lead_type = $('#lead_type').val();
|
|
|
|
if (lead_type == 2) {
|
|
$('.proposed_div').show().find('select, input').attr('required', 'required');
|
|
} else {
|
|
$('.proposed_div').hide().find('select, input').removeAttr('required');
|
|
}
|
|
|
|
// Scroll the newly added select into view and focus on it
|
|
const newPolicyTypeSelect = document.getElementById(`policy_type_id_${increment}`);
|
|
newPolicyTypeSelect.scrollIntoView({ behavior: 'smooth', block: 'end' });
|
|
newPolicyTypeSelect.focus();
|
|
|
|
$('#insurer_'+ increment).select2();
|
|
$('#tpa_'+ increment).select2();
|
|
$('#proposed_insurer_'+ increment).select2();
|
|
$('#proposed_tpa_'+ increment).select2();
|
|
$('#policy_type_id_'+ increment).select2();
|
|
|
|
// Initialize date pickers
|
|
var policy_start_datePicker = flatpickr("#policy_start_date_" + increment, {
|
|
dateFormat: "d/m/Y",
|
|
allowInput: false,
|
|
onChange: function(selectedDates) {
|
|
var policy_end_date = new Date(selectedDates[0]);
|
|
policy_end_date.setFullYear(policy_end_date.getFullYear() + 1);
|
|
policy_end_date.setDate(policy_end_date.getDate() - 1); // Set end date to last day of selected year
|
|
policy_end_datePicker.setDate(policy_end_date);
|
|
}
|
|
});
|
|
|
|
var policy_end_datePicker = flatpickr("#policy_end_date_" + increment, {
|
|
dateFormat: "d/m/Y",
|
|
allowInput: false
|
|
});
|
|
|
|
increment++; // Increment after adding the input
|
|
}
|
|
|
|
function removeHTMLInput(element)
|
|
{
|
|
const container = document.getElementById('dynamic-form-container');
|
|
const rows = container.querySelectorAll('.dynamic-form-row');
|
|
|
|
if (rows.length > 1) {
|
|
const row = element.closest('.dynamic-form-row');
|
|
|
|
const hrElement = row.previousElementSibling; // Get the <hr> before the row
|
|
console.log(hrElement);
|
|
console.log(hrElement.tagName);
|
|
if (hrElement && hrElement.tagName === 'HR') { // Check if it's an <hr> element
|
|
hrElement.remove(); // Remove the <hr>
|
|
}
|
|
|
|
row.remove();
|
|
}
|
|
}
|
|
|
|
//---------------------------------------------------------------------------------------------------------
|
|
|
|
$("#leads_form_id").submit(function(event) {
|
|
|
|
event.preventDefault();
|
|
|
|
var isValid = $('#leads_form_id').parsley().validate();
|
|
|
|
if (!isValid) {
|
|
$('#leads_form_id').find('input, select, textarea').each(function() {
|
|
if ($(this).parsley().isValid() === false && !$(this).val()) {
|
|
console.log('Empty field ID:', this.id);
|
|
}
|
|
});
|
|
console.log('Form is Empty', 'Warning');
|
|
return;
|
|
}
|
|
|
|
var salse_person_id = $("#salse_person_id").val();
|
|
console.log('salse_person_id : ', salse_person_id);
|
|
|
|
|
|
form_action = '<?= base_url('leads/create') ?>';
|
|
|
|
$('.loader').fadeIn();
|
|
$('.loader-mask').fadeIn();
|
|
|
|
var formData = new FormData($('#leads_form_id')[0]);
|
|
console.log(formData);
|
|
|
|
const jsonString = JSON.stringify(salse_person_id);
|
|
console.log('jsonString', jsonString);
|
|
|
|
// Append the JSON string to the FormData object
|
|
formData.append('salse_person_id', jsonString);
|
|
|
|
$.ajax({
|
|
data: formData,
|
|
url: form_action,
|
|
type: "POST",
|
|
dataType: 'json',
|
|
processData: false,
|
|
contentType: false,
|
|
success: function(res) {
|
|
|
|
$('.loader').fadeOut();
|
|
$('.loader-mask').delay(350).fadeOut('slow');
|
|
|
|
console.log('inception_form_response', res)
|
|
|
|
if (res.status == true) {
|
|
|
|
toastr.success(res.message, 'Success');
|
|
|
|
window.location.href = '<?= base_url('leads/list') ?>';
|
|
|
|
} else {
|
|
toastr.error(res.message, 'Error');
|
|
}
|
|
|
|
},
|
|
error: function(xhr, status, error) {
|
|
console.error(xhr.responseText);
|
|
console.error(status, error);
|
|
$('.loader').fadeOut();
|
|
$('.loader-mask').delay(350).fadeOut('slow');
|
|
}
|
|
});
|
|
});
|
|
|
|
//-----------------------------------------------------------------------------------------------------------
|
|
|
|
$('#lead_type').change(function() {
|
|
|
|
let value = $(this).val()
|
|
|
|
if (value == 2) {
|
|
|
|
$('#renewalDiv').find('select, input').attr('required', 'required');
|
|
$('#freshDiv').find('select, input').removeAttr('required');
|
|
$('#renewalDiv').show();
|
|
$('.proposed_div').show().find('select, input').attr('required', 'required');
|
|
$('#freshDiv').hide();
|
|
|
|
$('#gst').val('');
|
|
$('#pan').val('');
|
|
$('#branch_name').val('');
|
|
$('#branch_code').val('');
|
|
$('#contact_person_name').val('');
|
|
$('#contact_person_mobile').val('');
|
|
$('#contact_person_email').val('');
|
|
|
|
} else {
|
|
|
|
$('#renewalDiv').find('select, input').removeAttr('required');
|
|
$('#freshDiv').find('select, input').attr('required', 'required');
|
|
$('#renewalDiv').hide();
|
|
$('.proposed_div').hide().find('select, input').removeAttr('required');
|
|
$('#freshDiv').show();
|
|
|
|
$('#gst').val('');
|
|
$('#pan').val('');
|
|
$('#branch_name').val('');
|
|
$('#branch_code').val('');
|
|
$('#contact_person_name').val('');
|
|
$('#contact_person_mobile').val('');
|
|
$('#contact_person_email').val('');
|
|
|
|
$('#client_type').val('');
|
|
$('#client_name').val('');
|
|
$('#client_short_name').val('');
|
|
$('#entity_type_id').val('');
|
|
}
|
|
|
|
})
|
|
|
|
function insurerChange(input, unique_id) {
|
|
var lead_type = $('#lead_type').val()
|
|
|
|
if(lead_type == 2){
|
|
var val = $(input).val();
|
|
$('#proposed_insurer_'+unique_id).val(val).select2();
|
|
}
|
|
}
|
|
|
|
function tpaChange(input, unique_id) {
|
|
var lead_type = $('#lead_type').val()
|
|
|
|
if(lead_type == 2){
|
|
var val = $(input).val();
|
|
$('#proposed_tpa_'+unique_id).val(val).select2();
|
|
}
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------------------------------------
|
|
|
|
function getURLParamsForReport() {
|
|
|
|
const params = new URLSearchParams(window.location.search);
|
|
const lead_id = params.get('lead_id') ?? 0;
|
|
|
|
if (lead_id != 0) {
|
|
hide_list_show_add();
|
|
setTimeout(() =>
|
|
getLeadsDataForEdit(lead_id),
|
|
1500); // Reduced timeout
|
|
} else {
|
|
show_list_hide_add();
|
|
}
|
|
|
|
console.log('lead_id', lead_id); // Retain the log if necessary
|
|
}
|
|
|
|
</script>
|