1364 lines
59 KiB
PHP
1364 lines
59 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;
|
|
}
|
|
|
|
/* 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>
|
|
<script>
|
|
var pageSubTitle = 'Add Opportunity';
|
|
var pageBackButton = '<a href="<?= base_url('leads/list') ?>" data-toggle="tooltip" data-placement="top" title="Back"><i class="mdi mdi-arrow-left" style="font-size: 17px;"></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">
|
|
<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="form-row">
|
|
|
|
<div class="form-group offset-md-10 col-md-2 freshFields" style="float:right;">
|
|
<label class="switch">
|
|
<input id="exixting_client" type="checkbox" name="exixting_client">
|
|
<span class="slider round" style="height: 27px;"></span>
|
|
</label>
|
|
|
|
<label for="exixting_client" style="position: relative;top: 2px;">Existing Client</label>
|
|
</div>
|
|
|
|
</div>
|
|
<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">
|
|
<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">
|
|
<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">
|
|
<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"></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>
|
|
|
|
$(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 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');
|
|
}
|
|
|
|
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();
|
|
}
|
|
|
|
// 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 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);
|
|
|
|
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 == 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 != 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();
|
|
|
|
})
|
|
|
|
function leadTypeBsedHideAndShow(value, resetValues = false) {
|
|
|
|
if (value == 1) {
|
|
|
|
$('.btnDiv').show();
|
|
$('.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();
|
|
$('.claim-row').show();
|
|
|
|
$('.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('');
|
|
|
|
}
|
|
|
|
}
|
|
}
|
|
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 appendThreeYearsClaims() {
|
|
|
|
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">Claims History</label>
|
|
</div><br>`: ``}`
|
|
|
|
claimsFields += `
|
|
|
|
|
|
<div id = "claimHistoryRow" 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 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 for="first_policy_type_${increment}">Policy Type<span class="text-danger">*</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">
|
|
<label for="first_date_of_loss_${increment}">Date of Loss<span class="text-danger">*</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">
|
|
<label for="first_cause_of_death_${increment}">Cause Of Loss <span class="text-danger">*</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">
|
|
<label for="first_claim_amount_${increment}">Claim Amount<span class="text-danger">*</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">
|
|
<label for="first_claim_amount_${increment}">Settled Amount<span class="text-danger">*</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">
|
|
<label for="first_claim_status_${increment}">Claim Status<span class="text-danger">*</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(".claim-input").attr("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 = [];
|
|
|
|
$(".claim-row").each(function() {
|
|
|
|
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,
|
|
});
|
|
});
|
|
|
|
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;
|
|
// alert(cliam_history_status);
|
|
if (cliam_history_status == 1) {
|
|
if ($(".claim-row").length > 0) {
|
|
// Rows already exist, just show them
|
|
$(".claim-row").show();
|
|
} else {
|
|
// No rows yet, so create them
|
|
appendThreeYearsClaims();
|
|
}
|
|
$(".claim-input").attr("required", true);
|
|
} else {
|
|
|
|
$(".claim-row").hide();
|
|
$(".claim-input").removeAttr("required"); // Required Attributes Remove
|
|
$(".claim-input").val(""); // Value Reset
|
|
$(".claim-input").each(function() {
|
|
$(this).parsley().reset(); // Validation 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);
|
|
}
|
|
});
|
|
|
|
$(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) {
|
|
|
|
$('#client_name').val(actual_lead_client_details.company_name || '');
|
|
|
|
$('#gst').val(actual_lead_client_details.gst_number || '');
|
|
|
|
// 🔥 Important:
|
|
// Only auto-generate short name IF empty (avoid overwrite in edit)
|
|
if (!$('#client_short_name').val()) {
|
|
$('#client_name').trigger('input');
|
|
} else {
|
|
// Run duplicate validation once
|
|
validateInput($('#client_short_name')[0], "clients", "short_name");
|
|
}
|
|
}
|
|
|
|
// -------------------------------
|
|
// CONTACT PERSON AUTO FILL
|
|
// -------------------------------
|
|
if (actual_lead_contact_person_details) {
|
|
|
|
$('#contact_person_name').val(actual_lead_contact_person_details.name || '');
|
|
|
|
$('#contact_person_mobile').val(actual_lead_contact_person_details.mobile || '');
|
|
|
|
$('#contact_person_email').val(actual_lead_contact_person_details.email || '');
|
|
}
|
|
|
|
|
|
$('#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');
|
|
}
|
|
});
|
|
</script>
|