1747 lines
74 KiB
PHP
1747 lines
74 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;
|
|
}
|
|
|
|
.input-icon {
|
|
position: relative;
|
|
}
|
|
|
|
.input-icon .additional-icon {
|
|
position: absolute;
|
|
top: 50%;
|
|
right: 12px;
|
|
transform: translateY(-50%);
|
|
pointer-events: none;
|
|
color: #495057;
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
/* dont forgot it keep it safe card and card body space remover */ /* bcoz in design */
|
|
.card-body{ margin-top: 0px !important; }
|
|
|
|
/* this css as per design so not declare in golbal */ /* bcoz in design */
|
|
#collapseOne{
|
|
border: 1px solid #BFF3F5 !important;
|
|
border-radius: 10px !important;
|
|
border-width: 1px !important;
|
|
}
|
|
</style>
|
|
<?php
|
|
$isLeadEditNonEb = isset($lead_edit_data) && ! empty($lead_edit_data);
|
|
$nonEbPageTitle = $isLeadEditNonEb ? 'Edit Opportunities - (Non EB)' : 'Add Opportunities - (Non EB)';
|
|
?>
|
|
<script>
|
|
var pageHideMainNavTitle = true;
|
|
var pageTitle = '<?= $nonEbPageTitle ?>';
|
|
var pageBackButton = '<a href="<?= base_url('leads/list') ?>" class="topbar-icon-btn" data-toggle="tooltip" data-placement="top" title="Back" aria-label="Back"><i class="ri-arrow-left-s-line"></i></a>';
|
|
</script>
|
|
|
|
<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> -->
|
|
<!-- <h4 class="d-flex align-items-center" style="gap: 8px;">
|
|
<a href="<?= base_url('leads/list') ?>" style="cursor: pointer;" type="button" id="btnAdd">
|
|
<i class="mdi mdi-chevron-left" style="font-size: 43px;"></i>
|
|
</a>
|
|
<span class="title-text" id="page_title" style="position: relative;">Add Opportunity</span>
|
|
</h4> -->
|
|
</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">
|
|
<input type="hidden" name="actual_lead_id" id="actual_lead_id" value="<?= isset($actual_lead_id) ? $actual_lead_id : 0 ?>">
|
|
|
|
<div class="card" id="collapseOne">
|
|
<div class="card-body">
|
|
<h4 class="card-title mb-3">Opportunity Details</h4>
|
|
<hr>
|
|
<div class="form-row">
|
|
|
|
<div class="form-group col-md-4">
|
|
<label for="lead_type">Opportunity Type<span class="text-danger">*</span></label>
|
|
<select class="form-control" id="lead_type" name="lead_type" required>
|
|
<option value="">Select Opportunity 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-4">
|
|
<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>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- <hr> --> <!-- bcoz removed in design -->
|
|
|
|
<!-- client row -->
|
|
<div class="card" id="collapseOne">
|
|
<div class="card-body">
|
|
<div class="d-flex justify-content-between align-items-center mb-3">
|
|
<h4 class="card-title mb-0">Client Information</h4>
|
|
<div class="form-group freshFields mb-0 d-flex align-items-center">
|
|
<label for="exixting_client" class="mb-0 mr-2">Existing Client</label>
|
|
<label class="switch mb-0">
|
|
<input id="exixting_client" type="checkbox" name="exixting_client">
|
|
<span class="slider round" style="height: 27px;"></span>
|
|
</label>
|
|
</div>
|
|
</div>
|
|
<hr>
|
|
<div class="form-row">
|
|
|
|
<div class="form-group col-md-4 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-4 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,1)">
|
|
<option value="">Select Branch</option>
|
|
</select>
|
|
</div>
|
|
|
|
<div class="form-group col-md-4 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-4 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-4 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-4 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" onkeyup="validateInput(this, 'clients', 'short_name')" required>
|
|
</div>
|
|
|
|
<div class="form-group col-md-4 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-4">
|
|
<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>
|
|
</div>
|
|
</div>
|
|
<!-- end client row -->
|
|
<!-- <hr> --> <!-- bcoz removed in design -->
|
|
|
|
<!-- branch row-->
|
|
<div class="card" id="collapseOne">
|
|
<div class="card-body">
|
|
<h4 class="card-title mb-3">Branch Information</h4>
|
|
<hr>
|
|
<div class="form-row">
|
|
|
|
<div class="form-group col-md-4">
|
|
<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-4">
|
|
<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-4">
|
|
<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-4">
|
|
<label for="contact_person_summary">Contact Person's</label>
|
|
<select class="form-control" name="contact_person_summary" id="contact_person_summary">
|
|
<option value="">Select a Person</option>
|
|
</select>
|
|
|
|
</div>
|
|
|
|
<div class="form-group col-md-4">
|
|
<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-4">
|
|
<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-4">
|
|
<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>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- <hr> --> <!-- bcoz removed in design -->
|
|
|
|
<!-- policy row -->
|
|
<div class="card" id="collapseOne">
|
|
<div class="card-body">
|
|
<h4 class="card-title mb-3">Policy Details</h4>
|
|
<hr>
|
|
<div class="form-row" id="dynamic-form-container">
|
|
|
|
<div class="form-group col-md-4">
|
|
<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-4">
|
|
<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="<?php // echo $value['id'] . '-' . $value['tpa_id']
|
|
?>">
|
|
<?php // echo $value['tpa_short_name'] . '-' . $value['branch_code']
|
|
?>
|
|
</option>
|
|
<?php //}
|
|
?>
|
|
<?php //}
|
|
?>
|
|
</select>
|
|
</div> -->
|
|
|
|
<div class="form-group col-md-4">
|
|
<label for="">Date of Commencement <span class="text-danger">*</span></label>
|
|
<div class="input-icon">
|
|
<input type="text" class="form-control policy_start_date" id="policy_start_date" name="policy_start_date"
|
|
placeholder="Enter DOC" required>
|
|
<i class="mdi mdi-calendar-blank-outline additional-icon"></i>
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="form-group col-md-4">
|
|
<label for="">Date of Expiry <span class="text-danger">*</span></label>
|
|
<div class="input-icon">
|
|
<input type="text" class="form-control policy_end_date" id="policy_end_date" name="policy_end_date"
|
|
placeholder="Enter DOE" required>
|
|
<i class="mdi mdi-calendar-blank-outline additional-icon"></i>
|
|
</div>
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
<div id="appendArea"></div>
|
|
|
|
<div id="appendAreaForClaim">
|
|
</div>
|
|
|
|
<!-- <hr> --> <!-- bcoz removed in design -->
|
|
|
|
<div class="card" style="width:100%; background-color: transparent;">
|
|
<div class="card-body" style="background-color: #fff !important; border: 0px !important;">
|
|
<div id="multiFileAppendArea_1"></div>
|
|
</div>
|
|
</div>
|
|
|
|
</div>
|
|
</div>
|
|
<!-- <hr> --> <!-- bcoz removed in design -->
|
|
|
|
<!-- other row -->
|
|
<div class="card" id="collapseOne">
|
|
<div class="card-body">
|
|
<h4 class="card-title mb-3">Sales & Assignment</h4>
|
|
<hr>
|
|
<div class="form-row">
|
|
<?php
|
|
$savedViewers = [];
|
|
if (!empty($lead_edit_data['rfq_qcr_viewers'] ?? null)) {
|
|
$decoded = json_decode($lead_edit_data['rfq_qcr_viewers'] ?? "", true);
|
|
if (is_array($decoded)) $savedViewers = $decoded;
|
|
}
|
|
?>
|
|
<div class="form-group col-md-12">
|
|
<label for="rfq_qcr_viewers">RFQ/QCR File Viewers <span class="text-danger">*</span></label>
|
|
<select class="form-control" id="rfq_qcr_viewers" name="rfq_qcr_viewers" multiple required>
|
|
<?php if (isset($salse_team)) { ?>
|
|
<?php foreach ($salse_team as $member) { ?>
|
|
<?php $email = $member['email'] ?? ''; if (empty($email)) continue; ?>
|
|
<option value="<?= htmlspecialchars($email) ?>" <?= in_array($email, $savedViewers) ? 'selected' : '' ?>>
|
|
<?= htmlspecialchars($member['first_name']) ?>
|
|
</option>
|
|
<?php } ?>
|
|
<?php } ?>
|
|
</select>
|
|
</div>
|
|
</div>
|
|
|
|
<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-4">
|
|
<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-4">
|
|
<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" id="lost_reason_div" style="display: none;">
|
|
<div class="form-group col-md-12">
|
|
<label for="lost_reason">Lost Reason <span class="text-danger">*</span></label>
|
|
<textarea class="form-control" id="lost_reason" name="lost_reason" rows="4" placeholder="Please specify why this opportunity was lost"></textarea>
|
|
</div>
|
|
</div>
|
|
<div class="form-row">
|
|
<div class="form-group col-md-12">
|
|
<label for="notes">Remarks</label>
|
|
<textarea class="form-control" id="notes" name="notes" rows="4" maxlength="100"
|
|
oninput="this.value = this.value.slice(0, 100);">
|
|
</textarea>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="form-group text-right m-b-0">
|
|
<button type="submit" id="lead_form_submit_btn" class="btn btn-primary waves-effect waves-light mr-1">Submit</button>
|
|
</div>
|
|
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<?php include("newClientModal.php") ?>
|
|
|
|
|
|
<script>
|
|
var actualLeadClientName = '';
|
|
var actualLeadShortName = '';
|
|
var actualLeadGstNumber = '';
|
|
var actualLeadContactDetails = null;
|
|
|
|
function restoreActualLeadGstNumber() {
|
|
if ($('#actual_lead_id').val() && $('#actual_lead_id').val() != 0 && actualLeadGstNumber) {
|
|
$('#gst').val(actualLeadGstNumber);
|
|
}
|
|
}
|
|
|
|
function restoreActualLeadContactDetails() {
|
|
if ($('#actual_lead_id').val() && $('#actual_lead_id').val() != 0 && actualLeadContactDetails) {
|
|
$('#contact_person_name').val(actualLeadContactDetails.name || '');
|
|
$('#contact_person_mobile').val(actualLeadContactDetails.mobile || '');
|
|
$('#contact_person_email').val(actualLeadContactDetails.email || '');
|
|
}
|
|
}
|
|
|
|
$(document).ready(function() {
|
|
$('#rfq_qcr_viewers').parsley({
|
|
errorsContainer: function(ParsleyField) {
|
|
if (ParsleyField.$element.hasClass('select2-hidden-accessible')) {
|
|
return ParsleyField.$element.siblings('.select2-container');
|
|
}
|
|
return ParsleyField.$element;
|
|
}
|
|
});
|
|
$('#salse_person_id').parsley({
|
|
errorsContainer: function(ParsleyField) {
|
|
if (ParsleyField.$element.hasClass('select2-hidden-accessible')) {
|
|
return ParsleyField.$element.siblings('.select2-container');
|
|
}
|
|
return ParsleyField.$element;
|
|
}
|
|
});
|
|
$('#client_id').parsley({
|
|
errorsContainer: function(ParsleyField) {
|
|
if (ParsleyField.$element.hasClass('select2-hidden-accessible')) {
|
|
return ParsleyField.$element.siblings('.select2-container');
|
|
}
|
|
return ParsleyField.$element;
|
|
}
|
|
});
|
|
$('#client_branch_id').parsley({
|
|
errorsContainer: function(ParsleyField) {
|
|
if (ParsleyField.$element.hasClass('select2-hidden-accessible')) {
|
|
return ParsleyField.$element.siblings('.select2-container');
|
|
}
|
|
return ParsleyField.$element;
|
|
}
|
|
});
|
|
$('#policy_type_id').parsley({
|
|
errorsContainer: function(ParsleyField) {
|
|
if (ParsleyField.$element.hasClass('select2-hidden-accessible')) {
|
|
return ParsleyField.$element.siblings('.select2-container');
|
|
}
|
|
return ParsleyField.$element;
|
|
}
|
|
});
|
|
});
|
|
|
|
$(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 togglePolicyDateFields(value, fallbackPolicyTypeId = null) {
|
|
const policyTypesToHide = ['1', '2', '3', '4', '5', '6', '7'];
|
|
const selectedPolicyTypeId = $('#policy_type_id').val();
|
|
const policyTypeId = String(selectedPolicyTypeId || fallbackPolicyTypeId || '');
|
|
const shouldHide = value == 1 && policyTypesToHide.includes(policyTypeId);
|
|
const $policyDateFields = $('#policy_start_date, #policy_end_date').closest('.form-group');
|
|
|
|
$policyDateFields.toggle(!shouldHide);
|
|
|
|
if (shouldHide) {
|
|
$policyDateFields.find('input').prop('required', false).val('');
|
|
} else if (value == 1 || value == 3) {
|
|
$policyDateFields.find('input').prop('required', true);
|
|
}
|
|
}
|
|
|
|
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) {
|
|
|
|
// alert('hello')
|
|
// 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');
|
|
}
|
|
|
|
setupNonEbClaimDetailsSection();
|
|
|
|
// 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();
|
|
|
|
$('.claim-row').each(function() {
|
|
const isNil = $(this).find('.nil-claims-checkbox').prop('checked');
|
|
$(this).find('.nil-claims-value').val(isNil ? '1' : '0');
|
|
});
|
|
|
|
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 rfq_qcr_viewers = $("#rfq_qcr_viewers").val();
|
|
console.log('rfq_qcr_viewers : ', rfq_qcr_viewers);
|
|
|
|
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);
|
|
syncClaimHistoryFieldsToFormData(formData);
|
|
|
|
cliam_history_status = $("#claim_history").prop("checked") ? 1 : 0;
|
|
|
|
formData.append('claim_history',cliam_history_status);
|
|
|
|
// Append the JSON string to the FormData object
|
|
formData.append('rfq_qcr_viewers', JSON.stringify(rfq_qcr_viewers));
|
|
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');
|
|
if (xhr.status === 400) {
|
|
let response = JSON.parse(xhr.responseText);
|
|
let errorMessages = "";
|
|
let seenMessages = []; // Array to store unique messages
|
|
if (response.errors) {
|
|
$.each(response.errors, function (field, message) {
|
|
if (!seenMessages.includes(message)) {
|
|
errorMessages += `• ${message}<br>`;
|
|
seenMessages.push(message); // Mark this message as "seen"
|
|
}
|
|
});
|
|
toastr.error(errorMessages, 'Validation Error', { "allowHtml": true });
|
|
} else {
|
|
toastr.warning(response.message || 'Validation failed', 'Warning');
|
|
}
|
|
|
|
} else if (xhr.status === 403) {
|
|
let response = JSON.parse(xhr.responseText);
|
|
toastr.error(response.message, 'Security Policy');
|
|
} else if (xhr.status === 500) {
|
|
toastr.error('Something went wrong . Please try again later.', 'Server Error');
|
|
} else {
|
|
toastr.error('An unexpected error occurred. Please try again later.', 'Error');
|
|
}
|
|
}
|
|
});
|
|
});
|
|
|
|
$('#lead_type').change(function() {
|
|
let value = $(this).val();
|
|
// alert(value);
|
|
if (value == 1 || value == 3) {
|
|
// alert("Function Called");
|
|
|
|
if ($('#client_id option[value="add_client"]').length === 0) {
|
|
$('#client_id').prepend($('<option>', {
|
|
value: 'add_client',
|
|
text: '+ Add Client'
|
|
}));
|
|
}
|
|
|
|
$("#source_policy_id").prop("required",false);
|
|
$("#source_policy_id").closest("div") .find("label .text-danger").remove();
|
|
$('#source_policy_id').closest('.form-group').hide();
|
|
|
|
|
|
} else if (value != 1 && value != 3) {
|
|
$("#source_policy_id").prop("required",true);
|
|
$("#source_policy_id").prop("required", true);
|
|
if(value == 2){
|
|
$("#source_policy_id").closest('.form-group').show();
|
|
}
|
|
|
|
// Check if the asterisk doesn't already exist, then add it
|
|
let $label = $("#source_policy_id")
|
|
.closest("div")
|
|
.find("label");
|
|
|
|
if ($label.find(".text-danger").length === 0) {
|
|
$label.append(' <span class="text-danger">*</span>');
|
|
}
|
|
|
|
var addOption = $('#client_id option[value="add_client"]');
|
|
if (addOption.length > 0) {
|
|
addOption.remove();
|
|
}
|
|
|
|
|
|
}
|
|
|
|
leadTypeBsedHideAndShow(value, true);
|
|
|
|
$('#contact_person_summary').empty();
|
|
$('#contact_person_summary').append($('<option>', {
|
|
value: "",
|
|
text: "Select a Contact"
|
|
}));
|
|
|
|
$("#gst").val("");
|
|
$("#branch_name").val("");
|
|
$("#branch_code").val("");
|
|
$("#contact_person_name").val("");
|
|
$("#contact_person_mobile").val("");
|
|
$("#contact_person_email").val("");
|
|
|
|
|
|
// Fresh fields
|
|
$('#exixting_client').prop('checked', false);
|
|
$("#client_type").prop("selectedIndex", 0);
|
|
$("#entity_type_id").prop("selectedIndex", 0);
|
|
$("#client_name").val("");
|
|
$("#client_short_name").val("");
|
|
$('#client_type').removeClass('readonly-select');
|
|
$('#entity_type_id').removeClass('readonly-select');
|
|
$("#client_name").prop('readonly', false);
|
|
$("#client_short_name").prop('readonly', false);
|
|
|
|
// Renewal fields
|
|
$("#client_id").prop("selectedIndex", 0);
|
|
$("#client_branch_id").prop("selectedIndex", 0);
|
|
$("#source_policy_id").empty();
|
|
$('#source_policy_id').append($('<option>', {
|
|
value: "",
|
|
text: "Select a Policy"
|
|
}));
|
|
$("#pan").val("");
|
|
|
|
$('#policy_type_id_1').prop("selectedIndex", 0)
|
|
$('#insurer_1').prop("selectedIndex", 0)
|
|
$('#tpa_1').prop("selectedIndex", 0);
|
|
$('#policy_start_date').val("");
|
|
$('#policy_end_date').val("");
|
|
$("#appendArea_1").empty();
|
|
|
|
// --- Re-populate Actual Lead data if it was cleared ---
|
|
if ($('#actual_lead_id').val() && $('#actual_lead_id').val() != 0) {
|
|
$('#client_name').val(actualLeadClientName);
|
|
restoreActualLeadGstNumber();
|
|
restoreActualLeadContactDetails();
|
|
if (actualLeadShortName.trim() !== '') {
|
|
$('#client_short_name').val(actualLeadShortName);
|
|
} else if (actualLeadClientName.trim() !== '') {
|
|
// Fallback only when no persisted short name is available.
|
|
let baseName = actualLeadClientName
|
|
.trim()
|
|
.substring(0, 10)
|
|
.replace(/\s+/g, '')
|
|
.toUpperCase();
|
|
makeUniqueShortName(baseName);
|
|
} else {
|
|
$('#client_short_name').val('').parsley().reset();
|
|
}
|
|
}
|
|
|
|
})
|
|
|
|
function getClaimHistoryLabel(leadType) {
|
|
return String(leadType) === '1' ? 'Mortality Experience' : 'Claims Experience';
|
|
}
|
|
|
|
function getClaimDetailsSectionTitle(leadType) {
|
|
return String(leadType) === '1' ? 'Mortality Experience' : 'Claims Experience';
|
|
}
|
|
|
|
function shouldShowNonEbClaimHistory(leadType) {
|
|
return ['1', '2', '3'].includes(String(leadType));
|
|
}
|
|
|
|
function updateNonEbClaimRowVisibility(leadTypeOverride) {
|
|
const leadType = leadTypeOverride ?? $('#lead_type').val();
|
|
|
|
if (!shouldShowNonEbClaimHistory(leadType)) {
|
|
$('.claim-row').hide();
|
|
return;
|
|
}
|
|
|
|
if ($('#claim_history').length) {
|
|
if ($('#claim_history').prop('checked')) {
|
|
$('.claim-row').show();
|
|
} else {
|
|
$('.claim-row').hide();
|
|
}
|
|
} else {
|
|
$('.claim-row').show();
|
|
}
|
|
}
|
|
|
|
function setupNonEbClaimDetailsSection(leadTypeOverride) {
|
|
const leadType = leadTypeOverride ?? $('#lead_type').val();
|
|
const referenceDiv = document.getElementById('appendAreaForClaim');
|
|
|
|
if (!referenceDiv) {
|
|
return;
|
|
}
|
|
|
|
referenceDiv.innerHTML = '';
|
|
|
|
if (!shouldShowNonEbClaimHistory(leadType)) {
|
|
return;
|
|
}
|
|
|
|
const sectionTitle = getClaimDetailsSectionTitle(leadType);
|
|
const html = `<hr><div class="form-row claim-details-section-header"><div class="form-group col-md-3"><h4>${sectionTitle}</h4></div></div>`;
|
|
|
|
referenceDiv.insertAdjacentHTML('beforeend', html);
|
|
appendThreeYearsClaims();
|
|
updateNonEbClaimRowVisibility(leadType);
|
|
}
|
|
|
|
function leadTypeBsedHideAndShow(value, resetValues = false, skipClaimSetup = false) {
|
|
|
|
var actual_lead_id = $('#actual_lead_id').val();
|
|
|
|
if (value == 1 || value == 3) {
|
|
$('.btnDiv').show();
|
|
|
|
if (!skipClaimSetup && shouldShowNonEbClaimHistory(value)) {
|
|
setupNonEbClaimDetailsSection(value);
|
|
} else if (!shouldShowNonEbClaimHistory(value)) {
|
|
$('#appendAreaForClaim').empty();
|
|
$('.claim-row').hide();
|
|
}
|
|
|
|
|
|
$('.emp_title_text').text('No of Employees')
|
|
$('.depnd_title_text').text('No of Dependents')
|
|
$('.total_title_text').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('');
|
|
|
|
}
|
|
|
|
$('#exixting_client').removeAttr('required');
|
|
|
|
} else {
|
|
|
|
$('.btnDiv').hide();
|
|
|
|
if (!skipClaimSetup && shouldShowNonEbClaimHistory(value)) {
|
|
setupNonEbClaimDetailsSection(value);
|
|
}
|
|
|
|
$('.emp_title_text').text('No of Employees at Inception')
|
|
$('.depnd_title_text').text(' No of Dependents at Inception')
|
|
$('.total_title_text').text('Total Lives at Inception')
|
|
|
|
$('.freshFields').find('select, input').removeAttr('required');
|
|
$('.freshFields').hide();
|
|
|
|
$('.renewalFields').show();
|
|
$('.renewalFields').find('select, input').attr('required', 'required');
|
|
|
|
if (value == 3) {
|
|
$("#source_policy_id").removeAttr("required");
|
|
$('#source_policy_id').closest('.form-group').hide();
|
|
|
|
}else if(value == 2){
|
|
$('#source_policy_id').closest('.form-group').show();
|
|
}
|
|
|
|
$('.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('');
|
|
|
|
}
|
|
|
|
}
|
|
restoreActualLeadGstNumber();
|
|
restoreActualLeadContactDetails();
|
|
}
|
|
var allContacts = "";
|
|
function getBranchData(input,inputType) {
|
|
|
|
// alert("get branch Function called");
|
|
|
|
if (inputType == 1 ) {
|
|
var client_branch_id = $(input).val();
|
|
} else {
|
|
client_branch_id = input;
|
|
}
|
|
|
|
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);
|
|
|
|
allContacts = res.contact;
|
|
$('#contact_person_summary').empty();
|
|
$('#contact_person_summary').append($('<option>', {
|
|
value: "",
|
|
text: "Select a Contact"
|
|
}));
|
|
|
|
res.contact.forEach((value, key) => {
|
|
|
|
if (value.name && value.email) {
|
|
|
|
let display_value = `${value.name} - ${value.email} - ${value.mobile}`;
|
|
|
|
$('#contact_person_summary').append($('<option>', {
|
|
value: key, // index or key in array/object
|
|
text: display_value
|
|
}));
|
|
}
|
|
|
|
});
|
|
// $('#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 isClaimRowNilClaims($row) {
|
|
return $row.find('.nil-claims-checkbox').prop('checked');
|
|
}
|
|
|
|
function setClaimSelectValue($select, value) {
|
|
if (!$select.length) {
|
|
return;
|
|
}
|
|
|
|
if ($select.find('option[value="' + value + '"]').length === 0) {
|
|
$select.append($('<option>', { value: value, text: value }));
|
|
}
|
|
|
|
$select.val(value);
|
|
|
|
if ($select.hasClass('select2-hidden-accessible')) {
|
|
$select.trigger('change');
|
|
}
|
|
}
|
|
|
|
function resetClaimYearField($yearField) {
|
|
if (!$yearField.length) {
|
|
return;
|
|
}
|
|
|
|
$yearField.find('option[value="Nil"]').remove();
|
|
|
|
if ($yearField.val() === 'Nil') {
|
|
$yearField.val('').trigger('change');
|
|
}
|
|
}
|
|
|
|
function nilClaimsToggle(checkbox) {
|
|
const $row = $(checkbox).closest('.claim-row');
|
|
const isNil = $(checkbox).prop('checked');
|
|
const $yearField = $row.find('[name="first_year[]"]');
|
|
|
|
resetClaimYearField($yearField);
|
|
|
|
$row.find('.nil-claims-value').val(isNil ? '1' : '0');
|
|
$row.toggleClass('claim-row-nil', isNil);
|
|
$row.find('.claim-field-group .claim-required-star').toggle(!isNil);
|
|
|
|
$row.find('.claim-input').not('[name="first_year[]"]').each(function() {
|
|
const $field = $(this);
|
|
|
|
if (isNil) {
|
|
if ($field.is('select')) {
|
|
setClaimSelectValue($field, 'Nil');
|
|
} else {
|
|
$field.val('Nil');
|
|
}
|
|
|
|
$field.prop('disabled', true).removeAttr('required');
|
|
|
|
if ($field.hasClass('select2-hidden-accessible')) {
|
|
$field.next('.select2-container').addClass('select2-container--disabled');
|
|
}
|
|
|
|
if ($field.parsley) {
|
|
$field.parsley().reset();
|
|
}
|
|
} else {
|
|
$field.prop('disabled', false);
|
|
|
|
if ($field.hasClass('select2-hidden-accessible')) {
|
|
$field.next('.select2-container').removeClass('select2-container--disabled');
|
|
}
|
|
|
|
if ($field.is('select')) {
|
|
$field.find('option[value="Nil"]').remove();
|
|
$field.val('').trigger('change');
|
|
} else {
|
|
$field.val('');
|
|
}
|
|
}
|
|
});
|
|
|
|
const claimHistoryOn = !$('#claim_history').length || $('#claim_history').prop('checked');
|
|
|
|
if (claimHistoryOn) {
|
|
$yearField.prop('required', true).prop('disabled', false);
|
|
|
|
if ($yearField.hasClass('select2-hidden-accessible')) {
|
|
$yearField.next('.select2-container').removeClass('select2-container--disabled');
|
|
}
|
|
|
|
if (!isNil) {
|
|
$row.find('.claim-input').not('[name="first_year[]"]').prop('required', true);
|
|
}
|
|
}
|
|
|
|
if (typeof window.refreshLeadsFormValidation === 'function') {
|
|
window.refreshLeadsFormValidation();
|
|
}
|
|
}
|
|
|
|
function initNilClaimsRows() {
|
|
$('.claim-row .nil-claims-checkbox:checked').each(function() {
|
|
nilClaimsToggle(this);
|
|
});
|
|
}
|
|
|
|
function syncClaimHistoryFieldsToFormData(formData) {
|
|
const $rows = $('.claim-row');
|
|
|
|
if (!$rows.length) {
|
|
return;
|
|
}
|
|
|
|
const fieldNames = ['first_year[]', 'nil_claims[]', 'first_policy_type_[]', 'first_date_of_loss_[]', 'first_cause_of_loss[]', 'first_claim_amount[]', 'first_settled_amount[]', 'first_claim_status[]'];
|
|
|
|
fieldNames.forEach(function(name) {
|
|
if (typeof formData.delete === 'function') {
|
|
formData.delete(name);
|
|
}
|
|
});
|
|
|
|
$rows.each(function() {
|
|
const $row = $(this);
|
|
const isNil = $row.find('.nil-claims-checkbox').prop('checked');
|
|
|
|
$row.find('.nil-claims-value').val(isNil ? '1' : '0');
|
|
formData.append('first_year[]', $row.find('[name="first_year[]"]').val() || '');
|
|
formData.append('nil_claims[]', isNil ? '1' : '0');
|
|
|
|
if (isNil) {
|
|
formData.append('first_policy_type_[]', 'Nil');
|
|
formData.append('first_date_of_loss_[]', 'Nil');
|
|
formData.append('first_cause_of_loss[]', 'Nil');
|
|
formData.append('first_claim_amount[]', 'Nil');
|
|
formData.append('first_settled_amount[]', 'Nil');
|
|
formData.append('first_claim_status[]', 'Nil');
|
|
} else {
|
|
formData.append('first_policy_type_[]', $row.find('[name="first_policy_type_[]"]').val() || '');
|
|
formData.append('first_date_of_loss_[]', $row.find('[name="first_date_of_loss_[]"]').val() || '');
|
|
formData.append('first_cause_of_loss[]', $row.find('[name="first_cause_of_loss[]"]').val() || '');
|
|
formData.append('first_claim_amount[]', $row.find('[name="first_claim_amount[]"]').val() || '');
|
|
formData.append('first_settled_amount[]', $row.find('[name="first_settled_amount[]"]').val() || '');
|
|
formData.append('first_claim_status[]', $row.find('[name="first_claim_status[]"]').val() || '');
|
|
}
|
|
});
|
|
}
|
|
|
|
function appendThreeYearsClaims() {
|
|
|
|
const leadType = $('#lead_type').val();
|
|
const claimHistoryLabel = getClaimHistoryLabel(leadType);
|
|
|
|
let claimsFields = `${!document.querySelector('#claim_history') ? `<div class="custom-control custom-switch">
|
|
<input type="checkbox" onchange="claimHistoryToggle()" class="custom-control-input" id="claim_history" name="claim_history" checked />
|
|
<label class="custom-control-label" for="claim_history">${claimHistoryLabel}</label>
|
|
</div><br>`: ``}`
|
|
|
|
claimsFields += `
|
|
|
|
|
|
<div id = "claimHistoryRow" class="row claim-row">
|
|
|
|
<div class="form-group col-md-2 claim-year-group">
|
|
<label for="first_year_${increment}">Year<span class="text-danger claim-required-star">*</span></label>
|
|
<select class="form-control claim-input 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>Nil Claims</label>
|
|
<input type="hidden" class="nil-claims-value" name="nil_claims[]" value="0">
|
|
<div class="custom-control custom-checkbox" style="padding-top: 8px;">
|
|
<input type="checkbox" class="custom-control-input nil-claims-checkbox" id="nil_claims_${increment}" onchange="nilClaimsToggle(this)">
|
|
<label class="custom-control-label" for="nil_claims_${increment}">Nil Claims</label>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="form-group col-md-2 claim-field-group">
|
|
<label for="first_policy_type_${increment}">Policy Type<span class="text-danger claim-required-star">*</span></label>
|
|
<input type="text" class="form-control claim-input" id="first_policy_type_${increment}" name="first_policy_type_[]">
|
|
</div>
|
|
<div class="form-group col-md-2 claim-field-group">
|
|
<label for="first_date_of_loss_${increment}">Date of Loss<span class="text-danger claim-required-star">*</span></label>
|
|
<input type="text" class="form-control loss_date claim-input" id="first_date_of_loss_${increment}" name="first_date_of_loss_[]">
|
|
</div>
|
|
<div class="form-group col-md-2 claim-field-group">
|
|
<label for="first_cause_of_loss_${increment}">Cause Of Loss <span class="text-danger claim-required-star">*</span></label>
|
|
<input type="text" class="form-control claim-input" id="first_cause_of_loss_${increment}" name="first_cause_of_loss[]">
|
|
</div>
|
|
<div class="form-group col-md-2 claim-field-group">
|
|
<label for="first_claim_amount_${increment}">Claim Amount<span class="text-danger claim-required-star">*</span></label>
|
|
<input type="text" class="form-control claim-input" id="first_claim_amount_${increment}" name="first_claim_amount[]">
|
|
</div>
|
|
<div class="form-group col-md-2 claim-field-group">
|
|
<label for="first_settled_amount_${increment}">Settled Amount<span class="text-danger claim-required-star">*</span></label>
|
|
<input type="text" class="form-control claim-input" id="first_settled_amount_${increment}" name="first_settled_amount[]">
|
|
</div>
|
|
<div class="form-group col-md-2 claim-field-group">
|
|
<label for="first_claim_status_${increment}">Claim Status<span class="text-danger claim-required-star">*</span></label>
|
|
<input type="text" class="form-control claim-input" 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);
|
|
|
|
let isChecked = $("#claim_history").length > 0 ? $("#claim_history").prop("checked") : true;
|
|
let lastRow = $(".claim-row").last();
|
|
if (isChecked) {
|
|
lastRow.show();
|
|
lastRow.find('[name="first_year[]"]').prop("required", true);
|
|
if (!isClaimRowNilClaims(lastRow)) {
|
|
lastRow.find(".claim-input").not('[name="first_year[]"]').prop("required", true);
|
|
}
|
|
} else {
|
|
lastRow.hide();
|
|
lastRow.find(".claim-input").removeAttr("required");
|
|
}
|
|
|
|
// Increment claim index
|
|
increment = increment + 1;
|
|
|
|
$(".loss_date").each(function () {
|
|
flatpickr(this, {
|
|
dateFormat: "d-m-Y",
|
|
});
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
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 = [];
|
|
|
|
if ($("#claim_history").length > 0 && !$("#claim_history").prop("checked")) {
|
|
return JSON.stringify({
|
|
"finyear": claimData
|
|
});
|
|
}
|
|
|
|
$(".claim-row").each(function() {
|
|
|
|
let isNilClaims = $(this).find(".nil-claims-checkbox").prop("checked");
|
|
|
|
if (isNilClaims) {
|
|
let year = $(this).find("[name='first_year[]']").val();
|
|
claimData.push({
|
|
"year": year,
|
|
"policy_type": "Nil",
|
|
"date_of_loss": "Nil",
|
|
"claim_amount": "Nil",
|
|
"settled_amount": "Nil",
|
|
"cause_of_loss": "Nil",
|
|
"status": "Nil",
|
|
"nil_claims": 1,
|
|
});
|
|
return;
|
|
}
|
|
|
|
let year = $(this).find("[name='first_year[]']").val();
|
|
let policyType = $(this).find("[name='first_policy_type_[]']").val();
|
|
let dateOfLoss = $(this).find("[name='first_date_of_loss_[]']").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,
|
|
"policy_type" : policyType,
|
|
'date_of_loss' : dateOfLoss,
|
|
"claim_amount": claimAmount,
|
|
"settled_amount": settledAmount,
|
|
"cause_of_loss": causeOfLoss,
|
|
"status": claimStatus,
|
|
"nil_claims": 0,
|
|
});
|
|
});
|
|
|
|
let finalJson = {
|
|
"finyear": claimData
|
|
};
|
|
|
|
console.log(finalJson);
|
|
|
|
let jsonString = JSON.stringify(finalJson);
|
|
console.log(jsonString);
|
|
|
|
return jsonString;
|
|
}
|
|
|
|
function claimHistoryToggle() {
|
|
cliam_history_status = $("#claim_history").prop("checked") ? 1 : 0;
|
|
|
|
if (cliam_history_status == 1) {
|
|
if ($(".claim-row").length > 0) {
|
|
$(".claim-row").show();
|
|
} else {
|
|
appendThreeYearsClaims();
|
|
}
|
|
|
|
$(".claim-row").each(function() {
|
|
const $row = $(this);
|
|
$row.find('[name="first_year[]"]').prop("required", true);
|
|
|
|
if (!isClaimRowNilClaims($row)) {
|
|
$row.find(".claim-input").not('[name="first_year[]"]').prop("required", true);
|
|
}
|
|
});
|
|
} else {
|
|
$(".claim-row").hide();
|
|
$(".claim-row").each(function() {
|
|
const $row = $(this);
|
|
$row.find('.nil-claims-checkbox').prop('checked', false);
|
|
$row.find('.nil-claims-value').val('0');
|
|
$row.removeClass('claim-row-nil');
|
|
$row.find('.claim-required-star').show();
|
|
});
|
|
$(".claim-input").removeAttr("required").prop('disabled', false).val("");
|
|
$(".claim-input").each(function() {
|
|
if ($(this).hasClass('select2-hidden-accessible')) {
|
|
$(this).val(null).trigger('change');
|
|
}
|
|
if ($(this).parsley) {
|
|
$(this).parsley().reset();
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
$('#exixting_client').change(function () {
|
|
|
|
$('#contact_person_summary').empty();
|
|
$('#contact_person_summary').append($('<option>', {
|
|
value: "",
|
|
text: "Select a Contact"
|
|
}));
|
|
|
|
$("#gst").val("");
|
|
$("#pan").val("");
|
|
$("#branch_name").val("");
|
|
$("#branch_code").val("");
|
|
$("#contact_person_name").val("");
|
|
$("#contact_person_mobile").val("");
|
|
$("#contact_person_email").val("");
|
|
|
|
|
|
// Fresh fields
|
|
$("#client_type").prop("selectedIndex", 0);
|
|
$("#entity_type_id").prop("selectedIndex", 0);
|
|
$("#client_name").val("");
|
|
$("#client_short_name").val("");
|
|
|
|
// Renewal fields
|
|
$("#client_id").prop("selectedIndex", 0);
|
|
$("#client_branch_id").prop("selectedIndex", 0);
|
|
|
|
if ($(this).is(':checked')) {
|
|
$('#client_id').closest('.form-group').show();
|
|
$('#client_branch_id').closest('.form-group').show();
|
|
|
|
$('#client_type').addClass('readonly-select');
|
|
$('#entity_type_id').addClass('readonly-select');
|
|
|
|
$("#client_name").prop('readonly', true);
|
|
$("#client_short_name").prop('readonly', true);
|
|
|
|
$("#client_id").prop("required", true);
|
|
$("#client_branch_id").prop("required", true);
|
|
|
|
} else {
|
|
$('#client_id').closest('.form-group').hide();
|
|
$('#client_branch_id').closest('.form-group').hide();
|
|
|
|
$('#client_type').removeClass('readonly-select');
|
|
$('#entity_type_id').removeClass('readonly-select');
|
|
|
|
$("#client_name").prop('readonly', false);
|
|
$("#client_short_name").prop('readonly', false);
|
|
|
|
$("#client_id").prop("required", false);
|
|
$("#client_branch_id").prop("required", false);
|
|
}
|
|
restoreActualLeadGstNumber();
|
|
restoreActualLeadContactDetails();
|
|
});
|
|
|
|
$(document).ready(function() {
|
|
|
|
var actual_lead_client_details = <?= json_encode($actual_lead_client_details ?? null) ?>;
|
|
var actual_lead_contact_person_details = <?= json_encode($actual_lead_contact_person_details ?? null) ?>;
|
|
|
|
// -------------------------------
|
|
// CLIENT DETAILS AUTO FILL
|
|
// -------------------------------
|
|
if (actual_lead_client_details) {
|
|
actualLeadClientName = actual_lead_client_details.company_name || '';
|
|
$('#client_name').val(actualLeadClientName);
|
|
|
|
actualLeadGstNumber = actual_lead_client_details.gst_number || actual_lead_client_details.gst || '';
|
|
$('#gst').val(actualLeadGstNumber);
|
|
if (actual_lead_client_details.client_type !== undefined && actual_lead_client_details.client_type !== null && actual_lead_client_details.client_type !== '') {
|
|
$('#client_type').val(String(actual_lead_client_details.client_type));
|
|
}
|
|
let existingShortName = actual_lead_client_details.short_name || '';
|
|
if (existingShortName) {
|
|
// Prefer persisted short name while editing.
|
|
actualLeadShortName = existingShortName;
|
|
$('#client_short_name').val(existingShortName);
|
|
} else {
|
|
// Fallback: generate only when short name is unavailable.
|
|
setTimeout(function () {
|
|
let baseName = actual_lead_client_details.company_name
|
|
.trim()
|
|
.substring(0, 10)
|
|
.replace(/\s+/g, '')
|
|
.toUpperCase();
|
|
|
|
makeUniqueShortName(baseName);
|
|
}, 300);
|
|
}
|
|
}
|
|
|
|
// Auto-generate short name from client name on user input.
|
|
$('#client_name').on('input', function() {
|
|
let clientName = $(this).val();
|
|
if (clientName.trim() !== '') {
|
|
let baseName = clientName
|
|
.trim()
|
|
.substring(0, 10)
|
|
.replace(/\s+/g, '')
|
|
.toUpperCase();
|
|
makeUniqueShortName(baseName);
|
|
} else {
|
|
$('#client_short_name').val('').parsley().reset();
|
|
}
|
|
});
|
|
|
|
// Keep short name variable in sync if it's generated or changed
|
|
$('#client_short_name').on('input change', function() {
|
|
if ($('#actual_lead_id').val() && $('#actual_lead_id').val() != 0) {
|
|
actualLeadShortName = $(this).val();
|
|
}
|
|
});
|
|
|
|
// -------------------------------
|
|
// CONTACT PERSON AUTO FILL
|
|
// -------------------------------
|
|
if (actual_lead_contact_person_details) {
|
|
actualLeadContactDetails = actual_lead_contact_person_details;
|
|
restoreActualLeadContactDetails();
|
|
}
|
|
|
|
|
|
$('#lead_status').change(function() {
|
|
if ($(this).val() === 'lost') {
|
|
$('#lost_reason_div').show();
|
|
$('#lost_reason').attr('required', 'required');
|
|
} else {
|
|
$('#lost_reason_div').hide();
|
|
$('#lost_reason').val("");
|
|
$('#lost_reason').removeAttr('required');
|
|
}
|
|
});
|
|
|
|
// Check on page load
|
|
if ($('#lead_status').val() === 'lost') {
|
|
$('#lost_reason_div').show();
|
|
$('#lost_reason').attr('required', 'required');
|
|
} else {
|
|
// Ensure it's hidden and not required if the initial value is not 'lost'
|
|
$('#lost_reason_div').hide();
|
|
$('#lost_reason').val("");
|
|
$('#lost_reason').removeAttr('required');
|
|
}
|
|
|
|
const initialLeadType = $('#lead_type').val();
|
|
const isEditLead = String($('#actual_lead_id').val() || '0') !== '0';
|
|
|
|
if (initialLeadType && !isEditLead) {
|
|
leadTypeBsedHideAndShow(initialLeadType, false);
|
|
}
|
|
});
|
|
</script>
|