876 lines
35 KiB
PHP
876 lines
35 KiB
PHP
<!-- Leads Non EB -->
|
|
|
|
<style>
|
|
.readonly-color {
|
|
background-color: #e0e0e0;
|
|
/* Darker background */
|
|
color: #666;
|
|
/* Darker text color */
|
|
}
|
|
|
|
.readonly-select {
|
|
pointer-events: none;
|
|
background-color: #f0f0f0;
|
|
color: #666;
|
|
}
|
|
|
|
hr.solid {
|
|
border-top: 3px solid #bbb;
|
|
}
|
|
|
|
.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_non_eb_form">
|
|
<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-6" style="text-align: right; position: relative;">
|
|
<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_non_eb_form_id"
|
|
enctype="multipart/form-data">
|
|
|
|
<input type="hidden" name="id" id="leads_primarykey">
|
|
<input type="hidden" name="lead_form_type" id="lead_form_type_id" value="2">
|
|
|
|
<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">
|
|
|
|
<div class="form-group col-md-3 freshFields">
|
|
<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 freshFields">
|
|
<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 freshFields">
|
|
<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 freshFields">
|
|
<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 class="form-group col-md-3 renewalFields" style="display: none;">
|
|
<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 renewalFields" style="display: none;">
|
|
<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 renewalFields" style="display: none;">
|
|
<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" onchange="getPolicyData(this)">
|
|
<option value="" selected>Select Source Policy</option>
|
|
</select>
|
|
</div>
|
|
|
|
<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>
|
|
|
|
<hr>
|
|
|
|
<!-- policy row -->
|
|
<div class="form-row" id="dynamic-form-container">
|
|
|
|
<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" name="policy_type_id"
|
|
onchange="getPolicyTypeFields(this)" required>
|
|
<option value="">Select Policy Type</option>
|
|
<?php
|
|
if (isset($policy_type) && count($policy_type)) {
|
|
foreach ($policy_type as $value) {
|
|
if(in_array($value['allocg'], ["Non-EB", "Marine"])){
|
|
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" name="insurer">
|
|
<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" name="tpa">
|
|
<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="">Date of Commencement <span class="text-danger">*</span></label>
|
|
<input type="text" class="form-control policy_start_date" id="policy_start_date" name="policy_start_date"
|
|
placeholder="Enter DOC" required>
|
|
</div>
|
|
|
|
<div class="form-group col-md-3">
|
|
<label for="">Date of Expiry <span class="text-danger">*</span></label>
|
|
<input type="text" class="form-control policy_end_date" id="policy_end_date" name="policy_end_date"
|
|
placeholder="Enter DOE" required>
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div id="appendArea"></div>
|
|
|
|
<div id="appendAreaForClaim"></div>
|
|
|
|
<hr>
|
|
|
|
<div id="multiFileAppendArea_1"></div>
|
|
|
|
<hr>
|
|
|
|
<!-- other row -->
|
|
<div class="form-row">
|
|
|
|
<!-- <div class="form-group col-md-3">
|
|
<label for="file_upload">File Upload<span class="text-danger"></span></label>
|
|
<input type="file" class="form-control" id="file_name" name="file_name" accept=".xls,.xlsx">
|
|
<span class="text-danger" id="file_name_display"></span>
|
|
</div> -->
|
|
|
|
<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">
|
|
<button type="submit" class="btn btn-primary waves-effect waves-light mr-1">Submit</button>
|
|
</div>
|
|
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
|
|
$(document).ready(function(){
|
|
|
|
var today = new Date();
|
|
|
|
var policy_start_datePicker = flatpickr("#policy_start_date", {
|
|
dateFormat: "d/m/Y",
|
|
allowInput: false,
|
|
onChange: function(selectedDates, dateStr, instance) {
|
|
var endDate = new Date(selectedDates[0]);
|
|
endDate.setFullYear(endDate.getFullYear() + 1);
|
|
endDate.setDate(endDate.getDate() - 1); // Set end date to last day of selected year
|
|
policy_end_datePicker.setDate(endDate);
|
|
}
|
|
});
|
|
var policy_end_datePicker = flatpickr("#policy_end_date", {
|
|
dateFormat: "d/m/Y",
|
|
allowInput: false
|
|
});
|
|
|
|
addFileField(1);
|
|
})
|
|
|
|
function getPolicyTypeFields(input) {
|
|
|
|
console.log('getPolicyTypeFields', input);
|
|
let policy_type_id = $(input).val();
|
|
|
|
console.log(policy_type_id)
|
|
let url = '<?= base_url('util/getPolicyTypeFields/') ?>';
|
|
|
|
let requestData = {
|
|
policy_type_id: policy_type_id,
|
|
};
|
|
|
|
// Show loader
|
|
$('.loader').fadeIn();
|
|
$('.loader-mask').fadeIn();
|
|
|
|
// Send AJAX request
|
|
sendAjaxRequestForGlobal(url, 'GET', requestData, function(response) {
|
|
|
|
console.log('Data fetched successfully:', response);
|
|
|
|
$('#appendArea').empty();
|
|
$('#appendAreaForClaim').empty();
|
|
|
|
if (response.status == true) {
|
|
|
|
console.log(response.message, 'SUCCESS');
|
|
$('#appendArea').append(response.data);
|
|
let lead_type = $('#lead_type').val();
|
|
|
|
if(lead_type != 1){
|
|
|
|
let html = `<hr><div class="form-row"> <div class="form-group col-md-3"><h4> Claim Details </h4></div></div>`
|
|
let referenceDiv = document.getElementById('appendAreaForClaim');
|
|
referenceDiv.insertAdjacentHTML('beforeend', html);
|
|
|
|
appendThreeYearsClaims();
|
|
}
|
|
|
|
var retro_active_datePicker = flatpickr("#retro_active_date", {
|
|
dateFormat: "d/m/Y",
|
|
allowInput: false
|
|
});
|
|
|
|
var project_start_datePicker = flatpickr("#project_start_date", {
|
|
dateFormat: "d/m/Y",
|
|
allowInput: false
|
|
});
|
|
|
|
} else {
|
|
console.log(response.message, 'WARNING');
|
|
}
|
|
|
|
// Hide loader
|
|
$('.loader').fadeOut();
|
|
$('.loader-mask').delay(350).fadeOut('slow');
|
|
|
|
}, function(xhr, status, error) {
|
|
console.error('Error fetching data:', error);
|
|
console.error(xhr.responseText);
|
|
toastr.error('An error occurred while fetch data.', 'ERROR');
|
|
|
|
// Hide loader
|
|
$('.loader').fadeOut();
|
|
$('.loader-mask').delay(350).fadeOut('slow');
|
|
});
|
|
}
|
|
|
|
$("#leads_non_eb_form_id").submit(function(event) {
|
|
|
|
event.preventDefault();
|
|
|
|
var isValid = $('#leads_non_eb_form_id').parsley().validate();
|
|
console.log('isValid', isValid)
|
|
|
|
if (!isValid) {
|
|
$('#leads_non_eb_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);
|
|
|
|
$('.loader').fadeIn();
|
|
$('.loader-mask').fadeIn();
|
|
|
|
var formData = new FormData($('#leads_non_eb_form_id')[0]);
|
|
var policy_type_ids = formData.getAll('policy_type_id[]');
|
|
console.log('form policy ', policy_type_ids);
|
|
|
|
const jsonString = JSON.stringify(salse_person_id);
|
|
console.log('jsonString', jsonString);
|
|
|
|
let customFieldData = {};
|
|
|
|
$('.custom_fields').find('input, select, textarea').each(function () {
|
|
let key = $(this).attr('name');
|
|
let value;
|
|
|
|
if ($(this).is(':radio')) {
|
|
if ($(this).is(':checked')) {
|
|
value = $(this).val();
|
|
} else {
|
|
return; // Skip unchecked radio buttons
|
|
}
|
|
} else if ($(this).is(':checkbox')) {
|
|
value = $(this).is(':checked') ? $(this).val() : ''; // Store value if checked, otherwise empty
|
|
} else {
|
|
value = $(this).val();
|
|
}
|
|
|
|
customFieldData[key] = value;
|
|
});
|
|
|
|
const finyearJsonString = gatherClaimExperienceData();
|
|
console.log('finyearJsonString', finyearJsonString);
|
|
formData.append('fin_years_claims', finyearJsonString);
|
|
|
|
|
|
// Append the JSON string to the FormData object
|
|
formData.append('salse_person_id', jsonString);
|
|
formData.append('custom_fields', JSON.stringify(customFieldData));
|
|
|
|
form_action = '<?= base_url('leads/create') ?>';
|
|
|
|
$.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()
|
|
leadTypeBsedHideAndShow(value, true)
|
|
})
|
|
|
|
function leadTypeBsedHideAndShow(value, resetValues = false) {
|
|
|
|
if (value == 1) {
|
|
|
|
$('.btnDiv').show();
|
|
$('.claim-row').hide();
|
|
|
|
|
|
$('.emp_title').text('No of Employees')
|
|
$('.depnd_title').text('No of Dependents')
|
|
$('.total_title').text('Total Lives')
|
|
|
|
$('.renewalFields').find('select, input').removeAttr('required');
|
|
$('.renewalFields').hide();
|
|
|
|
$('.freshFields').find('select, input').attr('required', 'required');
|
|
$('.freshFields').show();
|
|
|
|
$('#policy_end_date').attr('required', 'required');
|
|
$('#policy_start_date').attr('required', 'required');
|
|
|
|
if(resetValues){
|
|
|
|
$('#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('');
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$('.btnDiv').hide();
|
|
$('.claim-row').show();
|
|
|
|
$('.emp_title').text('No of Employees at Inception')
|
|
$('.depnd_title').text(' No of Dependents at Inception')
|
|
$('.total_title').text('Total Lives at Inception')
|
|
|
|
$('.freshFields').find('select, input').removeAttr('required');
|
|
$('.freshFields').hide();
|
|
|
|
$('.renewalFields').show();
|
|
$('.renewalFields').find('select, input').attr('required', 'required');
|
|
|
|
$('.proposed_div').show().find('select, input').attr('required', 'required');
|
|
|
|
$('#policy_end_date').removeAttr('required');
|
|
$('#policy_start_date').removeAttr('required');
|
|
$('#claims').removeAttr('required');
|
|
|
|
if(resetValues){
|
|
|
|
$('#gst').val('');
|
|
$('#pan').val('');
|
|
$('#branch_name').val('');
|
|
$('#branch_code').val('');
|
|
$('#contact_person_name').val('');
|
|
$('#contact_person_mobile').val('');
|
|
$('#contact_person_email').val('');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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 || '');
|
|
|
|
|
|
$('#pan').prop('readOnly', true);
|
|
$('#gst').prop('readOnly', true);
|
|
$('#branch_name').prop('readOnly', true);
|
|
$('#branch_code').prop('readOnly', true);
|
|
$('#contact_person_name').prop('readOnly', true);
|
|
$('#contact_person_mobile').prop('readOnly', true);
|
|
$('#contact_person_email').prop('readOnly', true);
|
|
// $('#policy_type_id_1').prop('readOnly', true);
|
|
|
|
$('.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();
|
|
console.log('client_policy_id', client_policy_id);
|
|
|
|
if (client_policy_id) {
|
|
|
|
// Show loader
|
|
$('.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 && res.data) {
|
|
|
|
$(`#policy_type_id`).removeClass('readonly-select ').select2();
|
|
$(`#insurer`).removeClass('readonly-select ').select2();
|
|
$(`#tpa`).removeClass('readonly-select ').select2();
|
|
|
|
const insurer = `${res.data.insurer_branch_id}-${res.data.insurer_id}`;
|
|
const tpa = `${res.data.tpa_branch_id}-${res.data.tpa_id}`;
|
|
|
|
// Update fields with response data
|
|
$(`#policy_type_id`).val(res.data.policy_type_id).trigger('change');
|
|
$(`#insurer`).val(insurer).trigger('change');
|
|
$(`#tpa`).val(tpa).trigger('change');
|
|
|
|
if ($('#policy_start_date').hasClass('flatpickr-input')) {
|
|
const fpInstance = $('#policy_start_date')[0]._flatpickr;
|
|
if (fpInstance) {
|
|
fpInstance.destroy(); // Remove Flatpickr instance
|
|
}
|
|
}
|
|
|
|
if ($('#policy_end_date').hasClass('flatpickr-input')) {
|
|
const fpInstance = $('#policy_end_date')[0]._flatpickr;
|
|
if (fpInstance) {
|
|
fpInstance.destroy(); // Remove Flatpickr instance
|
|
}
|
|
}
|
|
|
|
$('#policy_start_date').val(res.new_start_date); // Set new value
|
|
$('#policy_end_date').val(res.end_date);
|
|
|
|
|
|
$("#policy_end_date").prop('readOnly', true);
|
|
$("#policy_start_date").prop("readOnly", true);
|
|
$(`#policy_type_id`).addClass('readonly-select ').select2('destroy');
|
|
$(`#insurer`).addClass('readonly-select ').select2('destroy');
|
|
$(`#tpa`).addClass('readonly-select ').select2('destroy');
|
|
|
|
} else {
|
|
console.warn('Invalid response:', res.message || 'Unknown error');
|
|
// Reset fields if response is invalid
|
|
$(`#policy_type_id`).val('').trigger('change');
|
|
$(`#insurer`).val('').trigger('change');
|
|
$(`#tpa`).val('').trigger('change');
|
|
}
|
|
|
|
// Hide loader
|
|
$('.loader').fadeOut();
|
|
$('.loader-mask').delay(350).fadeOut('slow');
|
|
},
|
|
error: function(xhr, status, error) {
|
|
console.error('AJAX Error:', xhr.responseText || error);
|
|
|
|
// Reset fields on error
|
|
$(`#policy_type_id`).val('').trigger('change');
|
|
$(`#insurer`).val('').trigger('change');
|
|
$(`#tpa`).val('').trigger('change');
|
|
|
|
$('.loader').fadeOut();
|
|
$('.loader-mask').delay(350).fadeOut('slow');
|
|
}
|
|
});
|
|
} else {
|
|
console.warn('Client policy ID is required.');
|
|
|
|
// Reset fields if no client policy ID is provided
|
|
$(`#policy_type_id`).val('').trigger('change');
|
|
$(`#insurer`).val('').trigger('change');
|
|
$(`#tpa`).val('').trigger('change');
|
|
}
|
|
}
|
|
|
|
var increment = 1;
|
|
|
|
function appendThreeYearsClaims() {
|
|
|
|
let claimsFields = `
|
|
|
|
<div class="row claim-row">
|
|
|
|
<div class="form-group col-md-2">
|
|
<label for="first_year_${increment}">Year<span class="text-danger">*</span></label>
|
|
<select class="form-control first_year_" id="first_year_${increment}" name="first_year[]">
|
|
<option value="">Select Year</option>
|
|
<?php foreach ($lastFiveYears as $year) {
|
|
echo "<option value='$year'>$year</option>";
|
|
} ?>
|
|
</select>
|
|
</div>
|
|
<div class="form-group col-md-2">
|
|
<label for="first_claim_amount_${increment}">Claim Amount<span class="text-danger">*</span></label>
|
|
<input type="text" class="form-control" id="first_claim_amount_${increment}" name="first_claim_amount[]">
|
|
</div>
|
|
<div class="form-group col-md-2">
|
|
<label for="first_claim_amount_${increment}">Settled Amount<span class="text-danger">*</span></label>
|
|
<input type="text" class="form-control" id="first_settled_amount_${increment}" name="first_settled_amount[]">
|
|
</div>
|
|
<div class="form-group col-md-2">
|
|
<label for="first_cause_of_death_${increment}">Cause Of Loss <span class="text-danger">*</span></label>
|
|
<input type="text" class="form-control" id="first_cause_of_loss_${increment}" name="first_cause_of_loss[]">
|
|
</div>
|
|
<div class="form-group col-md-2">
|
|
<label for="first_claim_status_${increment}">Claim Status<span class="text-danger">*</span></label>
|
|
<input type="text" class="form-control" id="first_claim_status_${increment}" name="first_claim_status[]">
|
|
</div>
|
|
<div class="form-group col-md-2">
|
|
<div class="" style="position: relative; top: 28px; float: right; text-align: end;">
|
|
<a class="btn btn-danger waves-effect waves-light" onclick="removeClaim(this)">x</a>
|
|
<a class="btn btn-primary waves-effect waves-light mr-1" onclick="appendThreeYearsClaims()">+</a>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
`;
|
|
|
|
// Append new claim fields
|
|
let referenceDiv = document.getElementById('appendAreaForClaim');
|
|
|
|
referenceDiv.insertAdjacentHTML('beforeend', claimsFields);
|
|
|
|
// Increment claim index
|
|
increment = increment + 1;
|
|
|
|
}
|
|
|
|
function removeClaim(btn) {
|
|
const container = document.getElementById('appendAreaForClaim');
|
|
const rows = container.querySelectorAll('.claim-row');
|
|
|
|
if (rows.length > 1) {
|
|
const row = btn.closest('.claim-row');
|
|
row.remove();
|
|
}
|
|
}
|
|
|
|
function gatherClaimExperienceData() {
|
|
|
|
let claimData = [];
|
|
|
|
$(".claim-row").each(function() {
|
|
|
|
let year = $(this).find("[name='first_year[]']").val();
|
|
let claimAmount = $(this).find("[name='first_claim_amount[]']").val();
|
|
let settledAmount = $(this).find("[name='first_settled_amount[]']").val();
|
|
let causeOfLoss = $(this).find("[name='first_cause_of_loss[]']").val();
|
|
let claimStatus = $(this).find("[name='first_claim_status[]']").val();
|
|
|
|
claimData.push({
|
|
"year": year,
|
|
"claim_amount": claimAmount,
|
|
"settled_amount": settledAmount,
|
|
"cause_of_loss": causeOfLoss,
|
|
"status": claimStatus,
|
|
});
|
|
});
|
|
|
|
let finalJson = {
|
|
"finyear": claimData
|
|
};
|
|
|
|
console.log(finalJson);
|
|
|
|
let jsonString = JSON.stringify(finalJson);
|
|
console.log(jsonString);
|
|
|
|
return jsonString;
|
|
}
|
|
|
|
</script>
|