7006 lines
325 KiB
PHP
7006 lines
325 KiB
PHP
<style>
|
||
.co_share_table {
|
||
width: 39% !important;
|
||
/* margin-bottom: 1rem;
|
||
color: #212529; */
|
||
}
|
||
|
||
#insurerTableContainer {
|
||
/* max-height: 400px; */
|
||
overflow-y: auto;
|
||
margin-top: 20px;
|
||
/* overflow-x: auto; */
|
||
position: relative;
|
||
}
|
||
|
||
#insurerTable thead th:first-child,
|
||
#insurerTable tbody td:first-child {
|
||
position: sticky;
|
||
left: 0;
|
||
background-color: #fff;
|
||
z-index: 1;
|
||
width: 200px;
|
||
min-width: 200px;
|
||
max-width: 200px;
|
||
white-space: nowrap;
|
||
overflow: hidden;
|
||
text-overflow: ellipsis;
|
||
}
|
||
|
||
#insurerTable input[type="text"] {
|
||
border: none;
|
||
box-shadow: none;
|
||
outline: none;
|
||
width: 100%;
|
||
padding: 5px 30px !important;
|
||
}
|
||
|
||
#insurerTable th,
|
||
#insurerTable td {
|
||
padding: 2px 4px !important;
|
||
/* height: 30px; */
|
||
vertical-align: middle;
|
||
}
|
||
|
||
#insurerTable select {
|
||
height: 30px;
|
||
padding: 2px 5px;
|
||
}
|
||
|
||
#insurerTable input[type="checkbox"] {
|
||
margin: 0;
|
||
height: 20px;
|
||
width: 20px;
|
||
}
|
||
|
||
#insurerTable th,
|
||
#insurerTable th {
|
||
min-width: 230px;
|
||
}
|
||
|
||
.readonly-color {
|
||
background-color: #e0e0e0; /* Darker background */
|
||
color: #666; /* Darker text color */
|
||
}
|
||
|
||
.readonly-select {
|
||
pointer-events: none;
|
||
/* background-color: #f0f0f0; */
|
||
background-color: #e0e0e0;
|
||
color: #666;
|
||
}
|
||
|
||
.select2-hidden-accessible + .select2-container .select2-dropdown {
|
||
display: none !important;
|
||
}
|
||
|
||
.select2-container .select2-selection--multiple .select2-selection__choice {
|
||
color: #000000;
|
||
}
|
||
|
||
.highlighted {
|
||
background-color: #f0ad4e;
|
||
color: #fff;
|
||
}
|
||
|
||
.right-align-input {
|
||
text-align: right;
|
||
}
|
||
|
||
.input-with-percentage {
|
||
position: relative;
|
||
}
|
||
|
||
.input-with-percentage input {
|
||
padding-right: 20px;
|
||
text-align: right;
|
||
}
|
||
|
||
.input-with-percentage::after {
|
||
content: '%';
|
||
position: absolute;
|
||
right: 10px;
|
||
top: 50%;
|
||
transform: translateY(-50%);
|
||
font-weight: bold;
|
||
color: #495057;
|
||
}
|
||
|
||
/* .select2-container .select2-selection__rendered {
|
||
min-height: 38px;
|
||
display: flex;
|
||
align-items: center;
|
||
}
|
||
|
||
.select2-search__field{
|
||
height: 0px !important;
|
||
} */
|
||
|
||
.select2-selection__choice {
|
||
background-color: #0a8794 !important;
|
||
color: white !important;
|
||
font-weight: bold;
|
||
}
|
||
|
||
.select2-selection__choice__remove {
|
||
color: white !important;
|
||
margin-right: 5px;
|
||
}
|
||
|
||
:disabled {
|
||
background-color: #e0e0e0;
|
||
color: #666;
|
||
}
|
||
|
||
.info-icon {
|
||
color: #007bff;
|
||
font-size: 15px;
|
||
transition: 0.3s ease;
|
||
cursor: pointer;
|
||
}
|
||
|
||
.info-icon:hover {
|
||
color: #0056b3;
|
||
font-size: 24px;
|
||
}
|
||
|
||
/** newly implemented */
|
||
|
||
#insurerTable thead th:first-child {
|
||
border-top: 0px solid #fff !important;
|
||
border-bottom: 0px solid #fff !important;
|
||
background-color: transparent !important;
|
||
}
|
||
|
||
#insurerTable tbody td {
|
||
border-top: 0px solid #fff !important;
|
||
border-bottom: 0px solid #fff !important;
|
||
background-color: transparent !important;
|
||
}
|
||
|
||
#insurerTable th{
|
||
color: black !important;
|
||
background-color: transparent !important;
|
||
}
|
||
|
||
#insurerTable input[type="text"],
|
||
#insurerTable select {
|
||
width: 100%;
|
||
font-size: 14px;
|
||
line-height: 1.5;
|
||
color: #000;
|
||
background-color: #fff;
|
||
background-clip: padding-box;
|
||
border: 1px solid #ced4da;
|
||
border-radius: 4px;
|
||
transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
|
||
box-sizing: border-box;
|
||
}
|
||
|
||
/* Focus effect like form-control */
|
||
#insurerTable input[type="text"]:focus,
|
||
#insurerTable select:focus {
|
||
border-color: #80bdff;
|
||
outline: 0;
|
||
box-shadow: 0 0 0 0.2rem rgba(0, 123, 255, 0.25);
|
||
}
|
||
|
||
/* Disabled & readonly styling */
|
||
#insurerTable input[readonly],
|
||
#insurerTable input:disabled,
|
||
#insurerTable select:disabled {
|
||
background-color: #e0e0e0; /* Darker background */
|
||
color: #666; /* Darker text color */
|
||
cursor: not-allowed;
|
||
}
|
||
|
||
</style>
|
||
|
||
<style>
|
||
.vehicle-input-wrapper {
|
||
position: relative;
|
||
}
|
||
|
||
.vehicle-otp-container {
|
||
display: flex;
|
||
gap: 3px;
|
||
flex-wrap: wrap;
|
||
}
|
||
|
||
.vehicle-otp-box {
|
||
width: 34px;
|
||
height: 38px;
|
||
text-align: center;
|
||
font-size: 16px;
|
||
font-weight: 100;
|
||
font-family: 'Courier New', monospace;
|
||
border: 2px solid #ced4da;
|
||
border-radius: 6px;
|
||
text-transform: uppercase;
|
||
transition: all 0.2s ease;
|
||
}
|
||
|
||
.vehicle-otp-box:focus {
|
||
outline: none;
|
||
border-color: #007bff;
|
||
box-shadow: 0 0 0 0.2rem rgba(0, 123, 255, 0.25);
|
||
}
|
||
|
||
.vehicle-otp-box.filled {
|
||
background-color: #e7f3ff;
|
||
border-color: #007bff;
|
||
}
|
||
|
||
.vehicle-otp-box.parsley-error {
|
||
border-color: #dc3545;
|
||
background-color: #f8d7da;
|
||
}
|
||
|
||
.vehicle-format-info {
|
||
font-size: 11px;
|
||
color: #6c757d;
|
||
margin-top: 5px;
|
||
}
|
||
|
||
.vehicle-result {
|
||
margin-top: 8px;
|
||
/* padding: 6px 10px; */
|
||
background: #f8f9fa;
|
||
border-radius: 4px;
|
||
font-family: 'Courier New', monospace;
|
||
font-size: 13px;
|
||
font-weight: 600;
|
||
text-align: center;
|
||
letter-spacing: 1px;
|
||
display: none;
|
||
/* max-width: fit-content; */
|
||
margin-left: auto;
|
||
margin-right: auto;
|
||
}
|
||
|
||
.vehicle-result.show {
|
||
display: block;
|
||
}
|
||
|
||
.vehicle-badge {
|
||
display: inline-block;
|
||
padding: 2px 6px;
|
||
border-radius: 3px;
|
||
font-size: 10px;
|
||
font-weight: 700;
|
||
margin-left: 5px;
|
||
}
|
||
|
||
.vehicle-badge.success {
|
||
background: #d4edda;
|
||
color: #155724;
|
||
}
|
||
|
||
.vehicle-badge.error {
|
||
background: #f8d7da;
|
||
color: #721c24;
|
||
}
|
||
|
||
/* Parsley error styling */
|
||
.parsley-errors-list {
|
||
list-style: none;
|
||
padding: 0;
|
||
margin: 5px 0 0 0;
|
||
}
|
||
|
||
.parsley-errors-list li {
|
||
color: #dc3545;
|
||
font-size: 12px;
|
||
}
|
||
</style>
|
||
|
||
<div class="tab-pane fade active show" id="form">
|
||
<input type="hidden" id="entity_type_id">
|
||
<div class="row" id="inception_form">
|
||
<div class="col-xl-12" style="max-width: 100% !important;">
|
||
<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 Policy</h4>
|
||
</div>
|
||
<div class="col-3" style="text-align: right; position: relative; left: 211px;">
|
||
<!-- <button class="btn btn-primary waves-effect waves-light" onclick="fileupload(this)">file upload</button> -->
|
||
</div>
|
||
<div class="col-1" style="text-align: right; position: relative; left: 193px;">
|
||
<a href="<?= base_url('policy_tranction/inception/list') ?>" type="button" id="btnAdd" class="btn btn-primary waves-effect waves-light"
|
||
>Back</a>
|
||
</div>
|
||
</div>
|
||
<form role="form" class="parsley-examples" method="post" id="inception_form_id" enctype="multipart/form-data">
|
||
|
||
<input type="hidden" name="id" id="policy_tranction_primarykey">
|
||
<input type="hidden" name="client_policy_id" id="client_policy_id">
|
||
<input type="hidden" name="client_id" id="client_id_for_edit">
|
||
<input type="hidden" name="insurer_id" id="insurer_id">
|
||
<input type="hidden" name="cd_ac_no" id="cd_ac_pk_for_leader">
|
||
<input type="hidden" name="ct_type" id="ct_type">
|
||
<input type="hidden" name="remove_pt_co_id" id="remove_pt_co_id" >
|
||
<input type="hidden" name="issuer" id="issuer" value="2">
|
||
<input type="hidden" name="base_cd_amount" id="base_cd_amount">
|
||
<input type="hidden" name="cd_amt_changed" id="cd_amt_changed" disabled>
|
||
<input type="hidden" name="salse_person_manager_id" id="salse_person_manager_id">
|
||
<input type="hidden" name="service_person_manager_id" id="service_person_manager_id">
|
||
<input type="hidden" name="service_person_branch_id" id="service_person_branch_id">
|
||
<input type="hidden" name="issuer_branch" id="issuer_branch">
|
||
|
||
<!-- <input type="hidden" id="cd_ac_no_for_edit"> -->
|
||
<input type="hidden" id="premium_details_unique_id">
|
||
<input type="hidden" id="policy_tranction_policy_number">
|
||
<input type="hidden" id="pt_form_sumbit_handler" value="1">
|
||
|
||
<!-- Client Row -->
|
||
<div class="row">
|
||
<!-- Section 1 -->
|
||
<div class="col-md-12">
|
||
<div id="accordion_0" class="mb-0">
|
||
<label id="policyAccordion" class="m-1 d-flex justify-content-between align-items-center">
|
||
<span class="font-color-black">Client Details</span>
|
||
<a id="toggleIcon" class="text-dark float-right" data-toggle="collapse" href="#collapseOne"
|
||
aria-expanded="true">
|
||
<i id="icon" class="mdi mdi-chevron-up mr-1 text-primary" style="font-size: 28px;"></i>
|
||
</a>
|
||
</label>
|
||
<div class="card mb-1">
|
||
<div id="collapseOne" class="collapse show" aria-labelledby="headingOne" data-parent="#accordion_0">
|
||
<div class="card-body" style="background-color: #F5FFFF !important; border-radius: 10px; box-shadow: 4px 4px 4px 4px #00000040;">
|
||
<div class="row">
|
||
<div class="form-group col-md-3">
|
||
<label for="email"> Policy Type <span class="text-danger">*</span></label>
|
||
<select class="form-control" id="policy_type_id" name="policy_type_id"
|
||
required>
|
||
<option value="">Select Policy Type</option>
|
||
<?php
|
||
if (isset($policy_types) && count($policy_types)) {
|
||
foreach ($policy_types as $key => $value) {
|
||
echo "<option value='" . $value['id'] . "'
|
||
data-ebp='" . $value['ebp'] . "'
|
||
data-etp='" . $value['etp'] . "'
|
||
data-etep='" . $value['etep'] . "'
|
||
data-iep='" . $value['iep'] . "'
|
||
data-itep='" . $value['itep'] . "'
|
||
data-itp='" . $value['itp'] . "'
|
||
data-bap='" . $value['bap'] . "'
|
||
data-allocg='" . $value['allocg'] . "'
|
||
>" .
|
||
$value['policy_type'] .
|
||
"</option>";
|
||
}
|
||
}
|
||
?>
|
||
</select>
|
||
</div>
|
||
<div class="form-group col-md-3" id="vhnodiv" style="display: none;">
|
||
<label for="bp_sgst">Vehicle No</label>
|
||
<select id="vehicle_no" type="text" class="form-control" name="vehicle_id">
|
||
<option value="">Select Vehicle</option>
|
||
<option value="add_vehicle"> + Add Vehicle</option>
|
||
</select>
|
||
</div>
|
||
</div>
|
||
<div class="row" id="actcual_clients">
|
||
|
||
<div class="form-group col-md-3 client_type_div">
|
||
<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>
|
||
<option value="1">Group</option>
|
||
<option value="2">Individual</option>
|
||
</select>
|
||
</div>
|
||
|
||
<div class="form-group col-md-3">
|
||
<label for="client_branch">Client<span class="text-danger">*</span></label>
|
||
<select class="form-control" id="client_id" name="client_id" required>
|
||
<option value="">Select Client</option>
|
||
<option value="add_client"> + Add Client</option>
|
||
</select>
|
||
</div>
|
||
|
||
<div class="form-group col-md-3 branchdiv">
|
||
<label for="client_branch">Client Branch<span class="text-danger">*</span></label>
|
||
<select class="form-control" id="client_branch_id" name="client_branch_id">
|
||
<option value="">Select Branch</option>
|
||
</select>
|
||
</div>
|
||
|
||
<!-- <div class="form-group col-md-3">
|
||
<label for="client_branch">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 class="form-group col-md-3">
|
||
<label for="client_branch">Nhance Branch<span class="text-danger">*</span></label>
|
||
<select class="form-control" id="issuer_branch" name="issuer_branch" required>
|
||
<option value="">Select Nhance Branch</option>
|
||
<?php
|
||
if (isset($issuer_branch) && count($issuer_branch)) {
|
||
foreach ($issuer_branch as $key => $value) {
|
||
echo "<option value=" . $value['id'] . ">" . $value['branch_name'] . "</option>";
|
||
}
|
||
}
|
||
?>
|
||
</select>
|
||
</div> -->
|
||
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="row" id="vehicle_row_div">
|
||
</div>
|
||
<!-- Client Section -->
|
||
<div class="row" id="client_row_div">
|
||
</div>
|
||
|
||
<!-- Pre sales Row -->
|
||
<div class="row" id="pre_sales_row">
|
||
<div class="col-md-12">
|
||
<div id="accordion_1" class="mb-0">
|
||
<label id="policyAccordion" class="m-1 d-flex justify-content-between align-items-center">
|
||
<span class="font-color-black">Pre Sales</span>
|
||
<a id="toggleIcon" class="text-dark float-right" data-toggle="collapse" href="#collapseTwo"
|
||
aria-expanded="true">
|
||
<i id="icon" class="mdi mdi-chevron-up mr-1 text-primary" style="font-size: 28px;"></i>
|
||
</a>
|
||
</label>
|
||
<div class="card mb-1">
|
||
<div id="collapseTwo" class="collapse show" aria-labelledby="headingOne" data-parent="#accordion_1">
|
||
<div class="card-body" style="background-color: #F5FFFF !important; border-radius: 10px; box-shadow: 4px 4px 4px 4px #00000040;">
|
||
<div class="row" id="policyholdernamediv" style="display: none;">
|
||
<div class="form-group col-md-3">
|
||
<label for="bp_igst">Policyholder Name</label>
|
||
<input id="policy_holder_name" value="" type="text" class="form-control" name="policy_holder_name">
|
||
</div>
|
||
|
||
<div class="form-group col-md-3">
|
||
<label class="switch" style="position: relative;top: 30px;left: 4px;">
|
||
<input id="same_as_proposer" type="checkbox" name="same_as_proposer" checked>
|
||
<span class="slider round" style="height: 27px;"></span>
|
||
</label>
|
||
|
||
<label for="same_as_proposer"
|
||
style="position: relative;top: 31px;left: 17px;">Insured (Same as Proposer)</label>
|
||
</div>
|
||
</div>
|
||
<div class="row" id="family_details" style="display: none;">
|
||
<div class="col-md-12">
|
||
<div class="form-section">
|
||
<h4>Family details</h4>
|
||
<div id="dynamic-form-container-for-insured"></div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div class="row">
|
||
|
||
<div class="form-group col-md-3">
|
||
<label for="addon_policy"> Business Type <span id="base_danger"
|
||
class="text-danger">*</span></label>
|
||
<select class="form-control" id="issue_type" name="issue_type" required>
|
||
<option value="" selected>Select Issue Type</option>
|
||
<?php
|
||
if (isset($issuing_type) && count($issuing_type)) {
|
||
foreach ($issuing_type as $key => $value) {
|
||
echo "<option value=" . $key . ">" . $value . "</option>";
|
||
}
|
||
}
|
||
?>
|
||
</select>
|
||
</div>
|
||
|
||
<div class="form-group col-md-3">
|
||
<label for="bp_gst_amt">Revenue Type</label>
|
||
<select id="revenue_type" class="form-control" name="revenue_type">
|
||
<option value="">Select</option>
|
||
<option value="NA">NA</option>
|
||
<option value="EA">EA</option>
|
||
<option value="EANR">EANR</option>
|
||
</select>
|
||
</div>
|
||
|
||
<div class="form-group col-md-3" id="renewal" style="display: none;">
|
||
<label for="addon_policy"> Renewal Source Policy <span id="base_danger"class="text-danger"></span></label>
|
||
<select class="form-control" id="source_client_policy_id"name="source_client_policy_id" onchange="setRenewalPolicyData(this)">
|
||
<option value="" selected>Select Renewal Source Policy</option>
|
||
</select>
|
||
</div>
|
||
|
||
<div class="form-group col-md-3 sded_dates" style="display: none;">
|
||
<label for="addon_policy">Policy Start Date<span id="base_danger"
|
||
class="text-danger">*</span></label>
|
||
<input type="text" class="form-control" id="renewal_policy_start_date"
|
||
name="renewal_policy_start_date" placeholder="DD/MM/YYYY" >
|
||
</div>
|
||
|
||
<div class="form-group col-md-3 sded_dates" style="display: none;">
|
||
<label for="addon_policy">Policy End Date<span id="base_danger"
|
||
class="text-danger">*</span></label>
|
||
<input type="text" class="form-control" id="renewal_policy_end_date"
|
||
name="renewal_policy_end_date" placeholder="DD/MM/YYYY" >
|
||
</div>
|
||
|
||
<div class="form-group col-md-3 roll_div" style="display: none;">
|
||
<label for="rollover_date">Date of Expiring Policy for Rollover</label>
|
||
<input id="rollover_date" value="" type="text" class="form-control" name="rollover_date" placeholder="DD/MM/YYYY">
|
||
</div>
|
||
|
||
<div class="form-group col-md-3">
|
||
<label for="ref">Reference</label>
|
||
<input id="ref" value="" type="text" class="form-control" name="ref">
|
||
</div>
|
||
|
||
<!-- <div class="form-group col-md-3">
|
||
<label for="addon_policy"> Status <span id="base_danger"class="text-danger">*</span></label>
|
||
<select class="form-control" id="policy_status" name="status" required>
|
||
<option value="" selected>Select Status</option>
|
||
<?php
|
||
if (isset($policy_status) && count($policy_status)) {
|
||
foreach ($policy_status as $key => $value) {
|
||
if($key == 'pending'){
|
||
echo "<option value=" . $key . " selected>" . $value . "</option>";
|
||
}else{
|
||
echo "<option value=" . $key . ">" . $value . "</option>";
|
||
}
|
||
}
|
||
}
|
||
?>
|
||
</select>
|
||
</div> -->
|
||
|
||
<!-- <div class="form-group col-md-3">
|
||
<label for="ppteam">PP Team</label>
|
||
<select class="form-control" id="ppteam" name="ppteam">
|
||
<option value="">Select PP Team</option>
|
||
<?php if (isset($ppTeamsData)) { ?>
|
||
<?php foreach ($ppTeamsData as $value) { ?>
|
||
<option value="<?= $value['id'];?>">
|
||
<?= $value['first_name'];?>
|
||
</option>
|
||
<?php } ?>
|
||
<?php } ?>
|
||
</select>
|
||
</div> -->
|
||
|
||
<!-- <div class="form-group col-md-3">
|
||
<label for="remark">Remarks</label>
|
||
<textarea id="remark" class="form-control" name="remarks" rows="1"></textarea>
|
||
</div> -->
|
||
|
||
<!-- <div class="form-group col-md-6">
|
||
<label for="listed_insurers">Shortlisted Insurers</label>
|
||
<select class="form-control" id="listed_insurers" name="listed_insurers" multiple>
|
||
<option value=""></option>
|
||
<?php foreach ($insurer_branch as $value) { ?>
|
||
<option value="<?= $value['id'] . '-' . $value['insurer_id'] ?>" data-id="<?= $value['insurer_id'] ?>">
|
||
<?= $value['insurer_name'] . '-' . $value['branch_code'] ?>
|
||
</option>
|
||
<?php } ?>
|
||
</select>
|
||
</div> -->
|
||
|
||
</div>
|
||
<!-- <hr> -->
|
||
<div class="row">
|
||
<!-- <div class="form-group col-md-3">
|
||
<label for="addon_policy"> Status <span id="base_danger"class="text-danger">*</span></label>
|
||
<select class="form-control" id="policy_status" name="status" required>
|
||
<option value="" selected>Select Status</option>
|
||
<?php
|
||
if (isset($policy_status) && count($policy_status)) {
|
||
foreach ($policy_status as $key => $value) {
|
||
if($key == 'pending'){
|
||
echo "<option value=" . $key . " selected>" . $value . "</option>";
|
||
}else{
|
||
echo "<option value=" . $key . ">" . $value . "</option>";
|
||
}
|
||
}
|
||
}
|
||
?>
|
||
</select>
|
||
</div> -->
|
||
|
||
<!-- <div class="form-group col-md-3">
|
||
<label for="bp_cgst">Latest Action Date</label>
|
||
<input id="last_action_date" type="text" class="form-control" name="last_action_date" placeholder="DD/MM/YYYY">
|
||
</div> -->
|
||
|
||
<!-- <div class="form-group col-md-3">
|
||
<label for="fund_received">Fund Recd / Sent to Insurer</label>
|
||
<input id="fund_received" value="" type="text" class="form-control" name="fund_received">
|
||
</div> -->
|
||
|
||
<!-- <div class="form-group col-md-3">
|
||
<label class="switch" style="position: relative;top: 32px;left: 20px;">
|
||
<input id="policy_with_corr" type="checkbox" name="policy_with_corr">
|
||
<span class="slider round" style="height: 27px;"></span>
|
||
</label>
|
||
|
||
<label for="policy_with_corr" style="position: relative;top: 33px;left: 25px;"> Policy with Correction</label>
|
||
</div> -->
|
||
|
||
<!-- <div class="form-group col-md-3">
|
||
<label class="switch" style="position: relative;top: 32px;left: 20px;">
|
||
<input id="is_cd_reduce_from_bds" type="checkbox" name="is_cd_reduce_from_bds">
|
||
<span class="slider round" style="height: 27px;"></span>
|
||
</label>
|
||
|
||
<label for="is_cd_reduce_from_bds" style="position: relative;top: 33px;left: 25px;"> Make Entry in CD <i class="mdi mdi-information-outline info-icon" data-toggle="tooltip" title="Enabling this will affect ( Credit/Debit ) the CD transaction. ( GMC, GPA, EDLI and GTLI, CD transaction from CRM )"></i>
|
||
</label>
|
||
</div> -->
|
||
|
||
<!-- <div class="form-group col-md-3 current_date" style="display: none;">
|
||
<label for="bp_igst">Process Start Date</label>
|
||
<input id="process_start_date" type="text" class="form-control" name="process_start_date" placeholder="DD/MM/YYYY">
|
||
</div> -->
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- Policy Docs Row -->
|
||
<div class="row" id="policy_docs" style="display: none;">
|
||
<div class="col-md-12">
|
||
<div id="accordion_23" class="mb-0">
|
||
<label id="policyAccordion" class="m-1 d-flex justify-content-between align-items-center">
|
||
<span class="font-color-black">Policy Docs</span>
|
||
<a id="toggleIcon" class="text-dark float-right" data-toggle="collapse" href="#collapseTwentyTwo"
|
||
aria-expanded="true">
|
||
<i id="icon" class="mdi mdi-chevron-up mr-1 text-primary" style="font-size: 28px;"></i>
|
||
</a>
|
||
</label>
|
||
<div class="card mb-1">
|
||
<div id="collapseTwentyTwo" class="collapse show" aria-labelledby="headingOne" data-parent="#accordion_23">
|
||
<div class="card-body" id="policy_docs_div" style="background-color: #F5FFFF !important; border-radius: 10px; box-shadow: 4px 4px 4px 4px #00000040;">
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- Vehicle Docs Row -->
|
||
<div class="row" id="vehicle_docs" style="display: none;">
|
||
<div class="col-md-12">
|
||
<div id="accordion_22" class="mb-0">
|
||
<label id="policyAccordion" class="m-1 d-flex justify-content-between align-items-center">
|
||
<span class="font-color-black">Vehicle Docs</span>
|
||
<a id="toggleIcon" class="text-dark float-right" data-toggle="collapse" href="#collapseTwentyThree"
|
||
aria-expanded="true">
|
||
<i id="icon" class="mdi mdi-chevron-up mr-1 text-primary" style="font-size: 28px;"></i>
|
||
</a>
|
||
</label>
|
||
<div class="card mb-1">
|
||
<div id="collapseTwentyThree" class="collapse show" aria-labelledby="headingOne" data-parent="#accordion_22">
|
||
<div class="card-body" id="vehicle_docs_div" style="background-color: #F5FFFF !important; border-radius: 10px; box-shadow: 4px 4px 4px 4px #00000040;">
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- sales Row -->
|
||
<div class="row" id="sales_row" style="display: none;">
|
||
<div class="col-md-12">
|
||
<div id="accordion_2" class="mb-0">
|
||
<label id="policyAccordion" class="m-1 d-flex justify-content-between align-items-center">
|
||
<span class="font-color-black">Sales</span>
|
||
<a id="toggleIcon" class="text-dark float-right" data-toggle="collapse" href="#collapseThree"
|
||
aria-expanded="true">
|
||
<i id="icon" class="mdi mdi-chevron-up mr-1 text-primary" style="font-size: 28px;"></i>
|
||
</a>
|
||
</label>
|
||
<div class="card mb-1">
|
||
<div id="collapseThree" class="collapse show" aria-labelledby="headingOne" data-parent="#accordion_2">
|
||
<div class="card-body" style="background-color: #F5FFFF !important; border-radius: 10px; box-shadow: 4px 4px 4px 4px #00000040;">
|
||
<div class="row">
|
||
|
||
<div class="form-group col-md-3" id="base_policy_id" style="display: none;">
|
||
<label for="addon_policy">Base Policy<span id="base_danger"
|
||
class="text-danger">*</span></label>
|
||
<select class="form-control" id="base_policy" name="base_policy">
|
||
<option value="" selected>Select Base Policy</option>
|
||
</select>
|
||
</div>
|
||
|
||
<div class="form-group col-md-3">
|
||
<label for="addon_policy">Policy No<span id="base_danger"class="text-danger">*</span></label>
|
||
<input type="text" class="form-control" id="policy_no" name="policy_no"placeholder="Enter Policy No" >
|
||
</div>
|
||
|
||
<div class="form-group col-md-3">
|
||
<label for="addon_policy">Policy Issue Date<span id="base_danger" class="text-danger">*</span></label>
|
||
<input type="text" class="form-control" id="policy_issue_date" name="policy_issue_date" placeholder="DD/MM/YYYY" >
|
||
</div>
|
||
|
||
<div class="form-group col-md-3">
|
||
<label for="addon_policy">Policy Issue Month<span id="base_danger" class="text-danger">*</span></label>
|
||
<input type="text" class="form-control readonly-select" id="month" name="month" placeholder="MM/YYYY" >
|
||
</div>
|
||
|
||
<div class="form-group col-md-3">
|
||
<label for="bp_cgst">D.O.C</label>
|
||
<input id="policy_start_date" type="text" class="form-control" name="policy_start_date" placeholder="DD/MM/YYYY" >
|
||
</div>
|
||
|
||
<div class="form-group col-md-3">
|
||
<label for="bp_igst">D.O.E</label>
|
||
<input id="policy_end_date" type="text" class="form-control" name="policy_end_date" placeholder="DD/MM/YYYY" >
|
||
</div>
|
||
<!--
|
||
<div class="form-group col-md-3" id="tpa_div">
|
||
<label for="tpa"> TPA <span id="tpa_danger"class="text-danger"></span></label>
|
||
<select class="form-control" id="tpa" name="tpa" >
|
||
<option value="" selected>Select TPA</option>
|
||
<?php foreach ($tpa as $value) { ?>
|
||
<option value="<?= $value['id'] . '-' . $value['tpa_id'] ?>">
|
||
<?= $value['tpa_short_name'] . '-' . $value['branch_code'] ?>
|
||
</option>
|
||
<?php } ?>
|
||
</select>
|
||
</div> -->
|
||
|
||
<div class="form-group col-md-3" id="no_of_insured_div">
|
||
<label for="addon_policy">No of Insured<span id="base_danger"class="text-danger"></span></label>
|
||
<input type="text" class="form-control" id="emp_count" name="emp_count" placeholder="Enter Employeee" onkeypress="return onlyNumbers(event)">
|
||
</div>
|
||
|
||
<div class="form-group col-md-3" id="no_of_dependents_div">
|
||
<label for="addon_policy">No of Dependents<span id="base_danger" class="text-danger"></span></label>
|
||
<input type="text" class="form-control" id="dependent_count" name="dependent_count" placeholder="Enter Dependent" onkeypress="return onlyNumbers(event)">
|
||
</div>
|
||
|
||
<div class="form-group col-md-3">
|
||
<label for="installment">Installment <i id="infoIcon" class="mdi mdi-information-outline info-icon" data-toggle="tooltip" title="Click for Installment details" style="margin-left: 5px;"></i></label>
|
||
<input id="installment" value="" type="text" class="form-control" name="installment">
|
||
</div>
|
||
|
||
<div class="form-group col-md-3">
|
||
<label for="installment_data">
|
||
Installment Data
|
||
</label>
|
||
<input id="installment_data" class="form-control" name="installment_data">
|
||
</div>
|
||
|
||
<!-- <div class="form-group col-md-3">
|
||
<label for="spl">SPL</label>
|
||
<input id="spl" value="" type="text" class="form-control" name="spl">
|
||
</div> -->
|
||
|
||
|
||
<div class="form-group col-md-3">
|
||
<label class="switch" style="position: relative;top: 30px;left: 4px;">
|
||
<input id="cop_yes" type="checkbox" name="co_share">
|
||
<span class="slider round" style="height: 27px;"></span>
|
||
</label>
|
||
|
||
<label for="inception_type"
|
||
style="position: relative;top: 31px;left: 17px;">CoP Yes</label>
|
||
</div>
|
||
|
||
<!-- <div class="form-group col-md-4 payby d-none">
|
||
<label class="switch" style="position: relative;top: 30px;left: 4px;">
|
||
<input id="bro_payable_by" type="checkbox" name="bro_payable_by" checked>
|
||
<span class="slider round" style="height: 27px;"></span>
|
||
</label>
|
||
|
||
<label for="inception_type" style="position: relative;top: 31px;left: 17px;">Remuneration Pay By Leader</label>
|
||
</div> -->
|
||
|
||
<div class="form-group col-md-3 payby d-none">
|
||
<label for="remuneration_pay_by" class="mb-1">Remuneration Pay By</label>
|
||
<select id="bro_payable_by"name="bro_payable_by"class="form-control">
|
||
<option value="1">Pay By Leader</option>
|
||
<option value="0">Pay By Co-Insurers</option>
|
||
<option value="2">Pay By MIX</option>
|
||
</select>
|
||
</div>
|
||
|
||
</div>
|
||
<hr>
|
||
<div class="row">
|
||
|
||
<!-- <div class="form-group col-md-3">
|
||
<label for="location">Location<span id="base_danger"class="text-danger"></span></label>
|
||
<input type="text" class="form-control" id="location" name="location"placeholder="Enter location" >
|
||
</div> -->
|
||
|
||
<div class="form-group col-md-3">
|
||
<label for="renewal_date">Renewal Date<span id="base_danger"
|
||
class="text-danger">*</span></label>
|
||
<input type="text" class="form-control" id="renewal_date"
|
||
name="renewal_date" placeholder="DD/MM/YYYY">
|
||
</div>
|
||
|
||
<!-- <div class="form-group col-md-3">
|
||
<label for="sales_generated_by">Sales Generated By</label>
|
||
<select class="form-control" id="sales_generated_by" name="sales_generated_by">
|
||
<option value="" selected>Select Sales Person</option>
|
||
<?php if (isset($salse_team)) { ?>
|
||
<?php foreach ($salse_team as $value) { ?>
|
||
<option value="<?= $value['id'];?>">
|
||
<?= $value['first_name'];?>
|
||
</option>
|
||
<?php } ?>
|
||
<?php } ?>
|
||
</select>
|
||
</div>
|
||
|
||
<div class="form-group col-md-3">
|
||
<label for="serviced_by">Serviced By</label>
|
||
<select class="form-control" id="serviced_by" name="serviced_by">
|
||
<option value="" selected>Select Service Person</option>
|
||
<?php if (isset($ACM)) { ?>
|
||
<?php foreach ($ACM as $value) { ?>
|
||
<option value="<?= $value['id'];?>">
|
||
<?= $value['first_name'];?>
|
||
</option>
|
||
<?php } ?>
|
||
<?php } ?>
|
||
</select>
|
||
</div> -->
|
||
|
||
<div class="form-group col-md-3">
|
||
<label for="sales_generated_by" class="d-flex align-items-center">
|
||
<span class="flex-grow-1">Sales Generated By</span>
|
||
<small id="nhance_branch_info"
|
||
class="text-right"
|
||
style="font-size: x-small;">
|
||
</small>
|
||
<small id="salse_rm_info"
|
||
class="text-right"
|
||
style="font-size: x-small;">
|
||
</small>
|
||
</label>
|
||
<select class="form-control" id="sales_generated_by" name="sales_generated_by" onchange="setNhanceBranch(this, 'nhance_branch_info'); setRM(this, 'salse_rm_info')" autocomplete="off">
|
||
<option value="" selected>Select Sales Person</option>
|
||
<?php if (isset($salse_team)) { ?>
|
||
<?php foreach ($salse_team as $value) { ?>
|
||
<option value="<?= $value['id'];?>"
|
||
data-nbid="<?= $value['nhance_branch_id'];?>"
|
||
data-nbname="<?= $value['nhance_branch_name'];?>"
|
||
data-rmid="<?= $value['rm_id'];?>"
|
||
data-rmname="<?= $value['rm_name'];?>"
|
||
>
|
||
<?= $value['first_name'];?>
|
||
</option>
|
||
<?php } ?>
|
||
<?php } ?>
|
||
</select>
|
||
|
||
</div>
|
||
|
||
<div class="form-group col-md-3">
|
||
<label for="serviced_by" class="d-flex align-items-center" >
|
||
<span class="flex-grow-1">Serviced By</span>
|
||
<small id="service_nhance_branch_info"
|
||
class="text-right"
|
||
style="font-size: x-small;">
|
||
</small>
|
||
<small id="service_rm_info"
|
||
class="text-right"
|
||
style="font-size: x-small;">
|
||
</small>
|
||
</label>
|
||
<select class="form-control" id="serviced_by" name="serviced_by" onchange="setNhanceBranch(this, 'service_nhance_branch_info'); setRM(this, 'service_rm_info')">
|
||
<option value="" selected>Select Service Person</option>
|
||
<?php if (isset($ACM)) { ?>
|
||
<?php foreach ($ACM as $value) { ?>
|
||
<option value="<?= $value['id'];?>"
|
||
data-nbid="<?= $value['nhance_branch_id'];?>"
|
||
data-nbname="<?= $value['nhance_branch_name'];?>"
|
||
data-rmid="<?= $value['rm_id'];?>"
|
||
data-rmname="<?= $value['rm_name'];?>"
|
||
>
|
||
<?= $value['first_name'];?>
|
||
</option>
|
||
<?php } ?>
|
||
<?php } ?>
|
||
</select>
|
||
</div>
|
||
|
||
<div class="form-group col-md-3">
|
||
<label for="POS">POS</label>
|
||
<select class="form-control" id="pos_id" name="pos_id">
|
||
<option value="">Select POS</option>
|
||
<?php if (isset($pos_data)) { ?>
|
||
<?php foreach ($pos_data as $value) { ?>
|
||
<option value="<?= $value['id'];?>">
|
||
<?= $value['name']." - ". $value['pos_code'];?>
|
||
</option>
|
||
<?php } ?>
|
||
<?php } ?>
|
||
</select>
|
||
</div>
|
||
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div> <!-- accordion_2 div closed here -->
|
||
</div><!-- 1st col-md-12 div closed here -->
|
||
|
||
<!-- Premium Details -->
|
||
<div class="col-md-12">
|
||
<div id="accordion_3" class="mb-0">
|
||
<label id="policyAccordion" class="m-1 d-flex justify-content-between align-items-center">
|
||
<span class="font-color-black">Premium Details</span>
|
||
<a id="toggleIcon" class="text-dark float-right" data-toggle="collapse" href="#collapseFour"
|
||
aria-expanded="true">
|
||
<i id="icon" class="mdi mdi-chevron-up mr-1 text-primary" style="font-size: 28px;"></i>
|
||
</a>
|
||
</label>
|
||
<div class="card mb-0">
|
||
<div id="collapseFour" class="collapse show" aria-labelledby="headingOne" data-parent="#accordion_3">
|
||
<div class="card-body" style="background-color: #F5FFFF !important; border-radius: 10px; box-shadow: 4px 4px 4px 4px #00000040;">
|
||
<div class="row d-none" id="add_more_row">
|
||
<div class="col-md-2">
|
||
<!-- <label for="setInsurerCount">Insurer Count : </label> -->
|
||
<!-- <input type="number" id="setInsurerCount" class="form-control" placeholder="Enter count"> -->
|
||
<a id="setInsurerCount" class="btn btn-primary" >Add Insurer</a>
|
||
</div>
|
||
<!-- <div class="col-md-2">
|
||
<a id="addInsurer" class="btn btn-primary mb-3">Add Insurer</a>
|
||
</div> -->
|
||
<!-- <div class="col-md-1">
|
||
<a id="submitForm" class="btn btn-success mb-3">Submit</a>
|
||
</div> -->
|
||
</div>
|
||
|
||
<div id="insurerTableContainer" style="overflow: auto;">
|
||
<table data-custom-table-css="table" class="table co_share_table" id="insurerTable">
|
||
<thead>
|
||
<tr>
|
||
<th>Premium Details</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<tr id="table_tr_1">
|
||
<td>Insurer<span id="premium_details_insurer" class="text-danger">*</span></td>
|
||
</tr>
|
||
<tr id="table_tr_2" style="display: none;">
|
||
<td>Is Leader?</td>
|
||
</tr>
|
||
<tr id="table_tr_34">
|
||
<td>CD Acc No</td>
|
||
</tr>
|
||
|
||
<tr id="table_tr_37">
|
||
<td>CD Amount</td>
|
||
</tr>
|
||
<tr id="table_tr_35" style="display: none;">
|
||
<td>Follower Policy No</td>
|
||
</tr>
|
||
<tr id="table_tr_40">
|
||
<td>Policy Issue Date</td>
|
||
</tr>
|
||
<tr id="table_tr_3" style="display: none;">
|
||
<td>Co-Share %</td>
|
||
</tr>
|
||
<tr id="table_tr_36">
|
||
<td>Non-Commissionable <br> Premium Amount</td>
|
||
</tr>
|
||
<tr id="table_tr_4">
|
||
<td>Base Premium</td>
|
||
</tr>
|
||
<tr class="hidetp" id="table_tr_5" style="display: none;">
|
||
<td id="tp_premium_td">TP Premium</td>
|
||
</tr>
|
||
<tr class="hideter" id="table_tr_6" style="display: none;">
|
||
<td>TEP Premium</td>
|
||
</tr>
|
||
<tr id="table_tr_7" style="display: none;">
|
||
<td>Co-Premium</td>
|
||
</tr>
|
||
<tr class="hidecotp" id="table_tr_38" style="display: none;">
|
||
<td>Co-TP Premium</td>
|
||
</tr>
|
||
<tr class="hidecoter" id="table_tr_39" style="display: none;">
|
||
<td>Co-TEP Premium</td>
|
||
</tr>
|
||
<tr id="table_tr_8">
|
||
<td>CGST</td>
|
||
</tr>
|
||
<tr id="table_tr_9">
|
||
<td>SGST</td>
|
||
</tr>
|
||
<tr id="table_tr_10">
|
||
<td>IGST</td>
|
||
</tr>
|
||
<tr id="table_tr_11">
|
||
<td>GST Amount</td>
|
||
</tr>
|
||
<tr id="table_tr_12">
|
||
<td>Stamp Duty</td>
|
||
</tr>
|
||
<tr id="table_tr_13">
|
||
<td>Total</td>
|
||
</tr>
|
||
|
||
<tr id="table_tr_14">
|
||
<td>Agreed BP %</td>
|
||
</tr>
|
||
<tr class="hidetp" id="table_tr_15">
|
||
<td id="agree_tp_td">Agreed TP %</td>
|
||
</tr>
|
||
<tr class="hideter" id="table_tr_16" style="display: none;">
|
||
<td id="agree_tp_td">Agreed TEP %</td>
|
||
</tr>
|
||
|
||
<?php if (in_array(get_role_id(), [1,5]) || in_array(MANAGEMENT_TEAM_ID, user_team()) || in_array(FINANCE_TEAM_ID, user_team())) { ?>
|
||
|
||
<tr id="table_tr_17">
|
||
<td>Agreed Amount</td>
|
||
</tr>
|
||
|
||
<?php } ?>
|
||
|
||
<tr id="table_tr_18">
|
||
<td>Standard BP %</td>
|
||
</tr>
|
||
<tr class="hidetp" id="table_tr_19">
|
||
<td>Standard TP %</td>
|
||
</tr>
|
||
<tr class="hideter" id="table_tr_20" style="display: none;">
|
||
<td>Standard TEP %</td>
|
||
</tr>
|
||
|
||
<?php if (in_array(get_role_id(), [1,5]) || in_array(FINANCE_TEAM_ID, user_team()) || in_array(MANAGEMENT_TEAM_ID, user_team())) { ?>
|
||
|
||
<tr id="table_tr_21">
|
||
<td>Actual BP Amount</td>
|
||
</tr>
|
||
<tr class="hidetp" id="table_tr_22">
|
||
<td>Actual TP Amount</td>
|
||
</tr>
|
||
<tr class="hideter" id="table_tr_23" style="display: none;">
|
||
<td>Actual TEP Amount</td>
|
||
</tr>
|
||
<tr id="table_tr_24">
|
||
<td>Actual BP %</td>
|
||
</tr>
|
||
<tr class="hidetp" id="table_tr_25">
|
||
<td>Actual TP %</td>
|
||
</tr>
|
||
<tr class="hideter" id="table_tr_26" style="display: none;">
|
||
<td>Actual TEP %</td>
|
||
</tr>
|
||
<tr id="table_tr_27">
|
||
<td>Actual BP <br> Remuneration Amount</td>
|
||
</tr>
|
||
<tr class="hidetp" id="table_tr_28">
|
||
<td>Actual TP <br> Remuneration Amount</td>
|
||
</tr>
|
||
<tr class="hideter" id="table_tr_29" style="display: none;">
|
||
<td>Actual TEP <br> Remuneration Amount</td>
|
||
</tr>
|
||
<tr id="table_tr_30">
|
||
<td>Expected Amount</td>
|
||
</tr>
|
||
<!-- <tr id="table_tr_31">
|
||
<td>Variance</td>
|
||
</tr> -->
|
||
<!-- <tr id="table_tr_32">
|
||
<td>Reward</td>
|
||
</tr> -->
|
||
|
||
<?php } ?>
|
||
|
||
<tr id="table_tr_33" style="display: none;">
|
||
<td></td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
</div> <!-- insurerTableContainer div closed here-->
|
||
|
||
</div>
|
||
</div> <!-- collapseFour div closed here -->
|
||
</div>
|
||
</div> <!-- accordion_3 div closed here -->
|
||
</div> <!-- 2nd col-md-12 closed here -->
|
||
|
||
</div> <!-- sales_row div closed here -->
|
||
|
||
<div class="form-group text-right mt-2 m-b-0" id="submitButton">
|
||
<button type="submit" class="btn btn-primary waves-effect waves-light mr-1"
|
||
id="btnSubmit">Submit</button>
|
||
</div>
|
||
</form>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<!-- end form row -->
|
||
|
||
<!-- Vehicle form content modal-->
|
||
<div class="modal fade" id="vehicle_modal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" data-backdrop="static">
|
||
<div class="modal-dialog modal-dialog-centered">
|
||
<div class="modal-content">
|
||
<div class="modal-header">
|
||
<h4 class="modal-title" id="myCenterModalLabel">Add New Vehicle</h4>
|
||
<button type="button" id="vehicle_close_btn" class="close" data-dismiss="modal" aria-hidden="true">×</button>
|
||
</div>
|
||
<div class="modal-body" style="overflow-y: auto;height: 90vh;">
|
||
<form class="parsley-examples" method="post" id="vehicle_form" enctype="multipart/form-data">
|
||
<div class="form-group">
|
||
|
||
<div class="form-row">
|
||
|
||
<div class="form-group col-md-6 client_type_div">
|
||
<label for="Owner_type">Owner Type<span class="text-danger">*</span></label>
|
||
<select class="form-control" id="Owner_type" name="Owner_type" required>
|
||
<option value="">Select Owner type</option>
|
||
<option value="1">Group</option>
|
||
<option value="2">Individual</option>
|
||
</select>
|
||
</div>
|
||
|
||
<div class="form-group col-md-3">
|
||
<label for="new_vehicle_switch">New Vehicle</label>
|
||
<input id="new_vehicle_switch" type="checkbox" name="new_vehicle" value="1" data-toggle="toggle" data-on="Yes" data-off="No" data-onstyle="info" data-offstyle="primary" data-style="border" data-width="218">
|
||
</div>
|
||
|
||
<div class="form-group col-md-6">
|
||
<label for="modal_vehicle_no">Vehicle No<span class="text-danger">*</span></label>
|
||
<input type="text" class="form-control" id="modal_vehicle_no" placeholder="Enter Vehicle No" name="vehicle_no" onchange="validateInput(this, 'vehicle', 'vehicle_no')" required>
|
||
</div>
|
||
|
||
<div class="form-group col-md-6">
|
||
<label for="rc">Chassis No <span class="text-danger">*</span></label>
|
||
<input type="text" class="form-control" id="rc" placeholder="Enter Chassis No" name="rc" onchange="validateInput(this, 'vehicle', 'rc')" required>
|
||
</div>
|
||
|
||
<div class="form-group col-md-6">
|
||
<label for="type">Vehicle Type<span class="text-danger">*</span></label>
|
||
<select class="form-control" id="type" name="type" required>
|
||
<option value="">Select Type</option>
|
||
<?php
|
||
if (isset($vehicle_type) && count($vehicle_type)) {
|
||
foreach ($vehicle_type as $key => $value) {
|
||
echo "<option value=" . $value['id'] . ">" . $value['vehicle_type'] . "</option>";
|
||
}
|
||
}
|
||
?>
|
||
</select>
|
||
</div>
|
||
|
||
<div class="form-group col-md-6">
|
||
<label for="description">Description<span class="text-danger">*</span></label>
|
||
<select class="form-control" id="description" name="description" required>
|
||
<option value="">Select Description</option>
|
||
<?php
|
||
if (isset($vehicle_des) && count($vehicle_des)) {
|
||
foreach ($vehicle_des as $key => $value) {
|
||
echo "<option value=" . $key . ">" . $value . "</option>";
|
||
}
|
||
}
|
||
?>
|
||
</select>
|
||
</div>
|
||
|
||
<div class="form-group col-md-12">
|
||
<label for="owner">Owner Name <span class="text-danger">*</span></label>
|
||
<select class="form-control" id="owner" name="owner" required>
|
||
<option value="">Select Owner</option>
|
||
</select>
|
||
</div>
|
||
|
||
<div class="form-group col-md-12 ownerbranchdiv">
|
||
<label for="client_branch">Branch<span class="text-danger">*</span></label>
|
||
<select class="form-control" id="owner_branch" name="branch_id">
|
||
<option value="">Select Branch</option>
|
||
</select>
|
||
</div>
|
||
|
||
</div>
|
||
|
||
</div>
|
||
<div class="form-group text-right m-b-0" id="hide_smbt_btn">
|
||
<button type="submit" class="btn btn-primary waves-effect waves-light mr-1">Submit</button>
|
||
</div>
|
||
</form>
|
||
</div>
|
||
</div><!-- /.modal-content -->
|
||
</div><!-- /.modal-dialog -->
|
||
</div>
|
||
|
||
<!-- CD No form content modal-->
|
||
<div class="modal fade" id="cd_form_modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
|
||
<div class="modal-dialog">
|
||
<div class="modal-content">
|
||
<div class="modal-header">
|
||
<h4 class="modal-title" id="title">Add CD Account Number</h4>
|
||
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
|
||
</div>
|
||
|
||
<div class="modal-body p-4">
|
||
<div class="">
|
||
|
||
<form role="form" class="parsley-examples" method="post" id="CDMasterForm" enctype="multipart/form-data">
|
||
|
||
<div class="form-group">
|
||
|
||
<div class="form-row">
|
||
<div class="form-group col-md-12">
|
||
<label for="email">Opening Date<span class="text-danger">*</span></label>
|
||
<input type="text" class="form-control" name="opening_date" id="opening_date" required>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="form-row">
|
||
<div class="form-group col-md-12">
|
||
<label for="mobile">CD Account Number<span class="text-danger">*</span></label>
|
||
<input type="text" class="form-control" id="cd_ac_no_data" name="cd_ac_no" required>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="form-row">
|
||
<div class="form-group col-md-12">
|
||
<label for="mobile">Opening Amount<span class="text-danger">*</span></label>
|
||
<input type="text" class="form-control" id="opening_bal" name="opening_bal" onkeypress="return onlyNumbers(event)" required>
|
||
</div>
|
||
</div>
|
||
|
||
</div>
|
||
|
||
<div class="form-group text-right m-b-0">
|
||
<button type="submit" class="btn btn-primary waves-effect waves-light mr-1"
|
||
id="btnSubmit">Submit</button>
|
||
</div>
|
||
</form>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- Info Modal -->
|
||
<div class="modal fade" id="moreInfoModal" tabindex="-1" role="dialog" aria-labelledby="fullWidthModalLabel" aria-hidden="true">
|
||
<div class="modal-dialog modal-xl" role="document">
|
||
<div class="modal-content">
|
||
<div class="modal-header">
|
||
<h4 class="modal-title" id="fullWidthModalLabel">More Information</h4>
|
||
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
||
<span aria-hidden="true">×</span>
|
||
</button>
|
||
</div>
|
||
<div class="modal-body">
|
||
<form id="installmentForm">
|
||
<div id="dynamicDivFillInfo"></div>
|
||
</form>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<script>
|
||
|
||
$(document).ready(function(){
|
||
|
||
$('#sales_row').show();
|
||
$('#policy_no').prop('required', true);
|
||
$('#policy_issue_date').prop('required', true);
|
||
$('#policy_start_date').prop('required', true);
|
||
$('#policy_end_date').prop('required', true);
|
||
$('.follow_insurer').prop('required', true);
|
||
|
||
})
|
||
|
||
$("#infoIcon").click(function() {
|
||
var policyTransactionPK = $('#policy_tranction_primarykey').val();
|
||
getDataForInfo(policyTransactionPK, function(data) {
|
||
console.log("data: ", data);
|
||
if (data && Object.keys(data).length) {
|
||
// openModal();
|
||
var myModal = new bootstrap.Modal(document.getElementById('moreInfoModal'));
|
||
myModal.show();
|
||
|
||
appendHtmlToModal(data.bds_data);
|
||
} else {
|
||
// toastr.warning("Data not Found");
|
||
}
|
||
});
|
||
});
|
||
|
||
function getDataForInfo (policyTransactionPK,callback) {
|
||
// alert(policyTransactionPK)
|
||
$.ajax({
|
||
url: "<?= base_url('policy_tranction/getMoreInfo') ?>",
|
||
type: "POST",
|
||
data: {
|
||
pt_id: policyTransactionPK
|
||
},
|
||
success: function(response) {
|
||
if (response.status) {
|
||
console.log("Info Response: ", response);
|
||
callback(response.data); // pass data to the callback
|
||
} else {
|
||
toastr.warning("No Data Found");
|
||
callback(null);
|
||
}
|
||
},
|
||
error: function(xhr, status, error) {
|
||
console.error(xhr.responseText);
|
||
console.error(status, error);
|
||
callback(null);
|
||
}
|
||
});
|
||
|
||
}
|
||
|
||
function appendHtmlToModal(data) {
|
||
|
||
const items = Array.isArray(data) ? data : data?.bds_data || [];
|
||
|
||
const container = document.getElementById('dynamicDivFillInfo');
|
||
container.innerHTML = '';
|
||
|
||
if (!Array.isArray(items) || items.length === 0) {
|
||
container.innerHTML = '<p>No data available.</p>';
|
||
return;
|
||
}
|
||
|
||
items.forEach(function(item, index) {
|
||
// Create .row container
|
||
const row = document.createElement('div');
|
||
row.className = 'row mb-3';
|
||
|
||
// Hidden input for ID
|
||
const hiddenId = document.createElement('input');
|
||
hiddenId.type = 'hidden';
|
||
hiddenId.name = `installments[${index}][id]`;
|
||
hiddenId.value = item.id;
|
||
row.appendChild(hiddenId);
|
||
|
||
// Payment Date
|
||
const paymentCol = document.createElement('div');
|
||
paymentCol.className = 'col-md-3';
|
||
|
||
// Use type="text" for flatpickr
|
||
const paymentGroup = createEditableInputGroup('Payment Date', 'payment_date', index, '', 'text');
|
||
paymentCol.appendChild(paymentGroup);
|
||
row.appendChild(paymentCol);
|
||
|
||
// Flatpickr target
|
||
const paymentInput = paymentGroup.querySelector('input');
|
||
|
||
// Convert DB date to d-m-Y (Flatpickr display format)
|
||
if (item.payment_date) {
|
||
|
||
flatpickr(paymentInput, {
|
||
dateFormat: "d-m-Y",
|
||
defaultDate: item.payment_date,
|
||
allowInput: true
|
||
});
|
||
}
|
||
|
||
// Installment Amount
|
||
const amountCol = document.createElement('div');
|
||
amountCol.className = 'col-md-3';
|
||
amountCol.appendChild(createEditableInputGroup('Installment Amount', 'installment_amount', index, item.installment_amount, 'number'));
|
||
row.appendChild(amountCol);
|
||
|
||
// UTR Number
|
||
const utrCol = document.createElement('div');
|
||
utrCol.className = 'col-md-3';
|
||
utrCol.appendChild(createEditableInputGroup('UTR Number', 'utr_no', index, item.utr_no, 'text'));
|
||
row.appendChild(utrCol);
|
||
|
||
container.appendChild(row);
|
||
});
|
||
|
||
// Add submit button at the end
|
||
const submitRow = document.createElement('div');
|
||
submitRow.className = 'row';
|
||
|
||
const submitCol = document.createElement('div');
|
||
submitCol.className = 'col-md-12 text-end d-flex align-items-center justify-content-end';
|
||
|
||
const submitBtn = document.createElement('button');
|
||
submitBtn.type = 'submit';
|
||
submitBtn.id = 'submitInstallments';
|
||
submitBtn.className = 'btn btn-primary';
|
||
submitBtn.innerText = 'Save Installments';
|
||
|
||
submitCol.appendChild(submitBtn);
|
||
submitRow.appendChild(submitCol);
|
||
container.appendChild(submitRow);
|
||
}
|
||
|
||
$(document).on('click', '#submitInstallments', function (e) {
|
||
e.preventDefault();
|
||
|
||
const installments = [];
|
||
|
||
$('#dynamicDivFillInfo .row').each(function () {
|
||
const row = $(this);
|
||
const installment = {};
|
||
|
||
const id = row.find('input[name*="[id]"]').val();
|
||
const payment_date = row.find('input[name*="[payment_date]"]').val();
|
||
const installment_amount = row.find('input[name*="[installment_amount]"]').val();
|
||
const utr_no = row.find('input[name*="[utr_no]"]').val();
|
||
|
||
// Ignore empty rows
|
||
if (payment_date && installment_amount && utr_no) {
|
||
installment.id = id;
|
||
installment.payment_date = payment_date;
|
||
installment.installment_amount = installment_amount;
|
||
installment.utr_no = utr_no;
|
||
installments.push(installment);
|
||
}
|
||
});
|
||
|
||
if (installments.length === 0) {
|
||
toastr.warning("No valid installment data to save.");
|
||
return;
|
||
}
|
||
$('.loader').fadeIn();
|
||
$('.loader-mask').fadeIn();
|
||
$.ajax({
|
||
url: "<?= base_url('policy_tranction/saveInstallment') ?>",
|
||
type: "POST",
|
||
data: { installments },
|
||
success: function (response) {
|
||
if (response.status) {
|
||
toastr.success("Installments saved successfully!");
|
||
$('#moreInfoModal').modal('hide');
|
||
} else {
|
||
toastr.error(response.message || "Save failed.");
|
||
}
|
||
},
|
||
error: function (xhr) {
|
||
console.error(xhr.responseText);
|
||
toastr.error("Server error.");
|
||
}
|
||
});
|
||
|
||
$('.loader').fadeOut();
|
||
$('.loader-mask').delay(350).fadeOut('slow');
|
||
});
|
||
|
||
function createEditableInputGroup(labelText, fieldName, index, value, type) {
|
||
var group = document.createElement('div');
|
||
group.className = 'form-group mb-2';
|
||
|
||
var label = document.createElement('label');
|
||
label.innerText = labelText;
|
||
|
||
var input = document.createElement('input');
|
||
input.type = type;
|
||
input.className = 'form-control';
|
||
input.name = `installments[${index}][${fieldName}]`;
|
||
input.value = value;
|
||
|
||
group.appendChild(label);
|
||
group.appendChild(input);
|
||
|
||
return group;
|
||
}
|
||
|
||
var team_id = [];
|
||
var role_id = <?php echo get_role_id(); ?>;
|
||
let isClientFormSubmitting = false;
|
||
let isVehicleFormSubmitting = false;
|
||
var insurer_count_array = [];
|
||
var redirect_url = '<?= base_url('policy_tranction/inception/list') ?>';
|
||
let insurer_data = <?= json_encode($insurer_branch ?? []) ?>;
|
||
|
||
$(document).ready(function(){
|
||
|
||
// document.getElementById('vehicle_form').addEventListener('reset', function(event) {
|
||
// console.log('vehicle_form reset called', event.type);
|
||
// if(isVehicleFormSubmitting == false){
|
||
// event.preventDefault();
|
||
// }
|
||
// });
|
||
|
||
// document.getElementById('client_form').addEventListener('reset', function(event) {
|
||
// console.log('client_form reset called', event.type);
|
||
// if(isClientFormSubmitting == false){
|
||
// event.preventDefault();
|
||
// }
|
||
// });
|
||
|
||
$('#upload_enrollment_model').on('hide.bs.modal', function (e) {
|
||
|
||
console.log('Attempting to hide #upload_enrollment_model modal');
|
||
|
||
let policy_type_id = $('#policy_type_id').val();
|
||
console.log('policy_type_id:', policy_type_id);
|
||
|
||
let shouldClose = false;
|
||
if(isClientFormSubmitting == false){
|
||
|
||
shouldClose = confirm("Are you sure you want to close? Unsaved changes will be lost.");
|
||
// const shouldClose = true; // Always true, can be changed to confirm() if needed
|
||
console.log('User confirmation result:', shouldClose);
|
||
|
||
if (shouldClose) {
|
||
console.log('User confirmed closing. Resetting #client_form.');
|
||
|
||
$('#client_form')[0].reset();
|
||
console.log('#client_form reset successfully.');
|
||
|
||
if (policy_type_id == 8) {
|
||
$('#client_form').removeAttr('data-id');
|
||
console.log('data-id attribute removed from #client_form.');
|
||
|
||
console.log('Opening #vehicle_modal.');
|
||
const vehicleModal = new bootstrap.Modal(document.getElementById('vehicle_modal'));
|
||
vehicleModal.show();
|
||
|
||
console.log('Setting form data for #vehicle_form from localStorage.');
|
||
setFormDataFromLocalStorage("#vehicle_form", "vehicleFormData");
|
||
|
||
}else {
|
||
console.log('policy_type_id is not 8 — proceeding with default modal behavior.');
|
||
}
|
||
|
||
} else {
|
||
console.log('User cancelled closing. Preventing modal from hiding.');
|
||
e.preventDefault(); // stops modal from closing
|
||
}
|
||
}
|
||
|
||
|
||
});
|
||
|
||
$('#vehicle_modal').on('hide.bs.modal', function (e) {
|
||
|
||
console.log('Attempting to hide #vehicle_modal modal');
|
||
|
||
if(isVehicleFormSubmitting == false){
|
||
|
||
const shouldClose = confirm("Are you sure you want to close? Unsaved changes will be lost.");
|
||
console.log('User confirmation result:', shouldClose);
|
||
|
||
if (!shouldClose) {
|
||
console.log('User cancelled closing. Preventing modal from hiding.');
|
||
e.preventDefault();
|
||
}
|
||
|
||
if(shouldClose){
|
||
console.log("alert closed")
|
||
localStorage.removeItem('vehicleFormData');
|
||
$("#vehicle_form").find("input, select, textarea").val("");
|
||
}
|
||
|
||
}
|
||
|
||
});
|
||
|
||
$('#aadhar').attr('data-parsley-required', 'false');
|
||
$('#aadhar').removeAttr('required');
|
||
|
||
|
||
team_id = <?php echo json_encode(user_team()); ?>;
|
||
console.log('team_id', team_id);
|
||
|
||
if (team_id.includes('4')) {
|
||
console.log('Finance Team Logged in.');
|
||
} else if (team_id.includes('3')) {
|
||
console.log('Business Team Logged in.');
|
||
}
|
||
|
||
$('#listed_insurers').select2({
|
||
placeholder: "Select Insurers", // Placeholder for a better UX
|
||
});
|
||
|
||
$("textarea.select2-search__field").attr('rows', '1');
|
||
$("textarea.select2-search__field").css('resize', 'none');
|
||
|
||
// $('#listed_insurers').select2();
|
||
$('#owner').select2();
|
||
$('#owner_branch').select2();
|
||
$('#vehicle_no').select2();
|
||
$('#pos_id').select2();
|
||
var today = new Date();
|
||
|
||
var dob = flatpickr("#dob", {
|
||
dateFormat: "d/m/Y",
|
||
allowInput: false
|
||
});
|
||
|
||
var rollover_date = flatpickr("#rollover_date", {
|
||
dateFormat: "d/m/Y",
|
||
allowInput: false
|
||
});
|
||
|
||
var process_start_date = flatpickr("#process_start_date", {
|
||
dateFormat: "d/m/Y",
|
||
defaultDate: today,
|
||
allowInput: false
|
||
});
|
||
|
||
var last_action_date = flatpickr("#last_action_date", {
|
||
dateFormat: "d/m/Y", // Display format in DD/MM/YYYY
|
||
defaultDate: today, // Today's date as the default value
|
||
allowInput: false,
|
||
maxDate: today // Disallow future dates
|
||
});
|
||
|
||
var renewal_date1 = flatpickr("#renewal_policy_start_date", {
|
||
dateFormat: "d/m/Y",
|
||
defaultDate: 'today',
|
||
allowInput: false
|
||
});
|
||
|
||
var renewal_date2 = flatpickr("#renewal_policy_end_date", {
|
||
dateFormat: "d/m/Y",
|
||
defaultDate: 'today',
|
||
allowInput: false
|
||
});
|
||
|
||
|
||
})
|
||
|
||
$(document).ready(function(){
|
||
getURLParamsForReport();
|
||
})
|
||
|
||
$(document).ready(function(){
|
||
|
||
$('#vehicle_no').change(function(){
|
||
|
||
var val = $(this).val()
|
||
var selectedOption = $(this).find('option:selected');
|
||
var client_id = selectedOption.data('cid');
|
||
var branch_id = selectedOption.data('bid');
|
||
var client_type = selectedOption.data('cty');
|
||
$('#vehicle_row_div').empty();
|
||
$('#client_row_div').empty();
|
||
$('#actcual_clients').show();
|
||
|
||
let status = $('#policy_status').val(); // REF : Venkatesh R - Status html Remove. Doubt here ask him - Q: why we need this? remove pannava ?.
|
||
|
||
|
||
console.log(client_id);
|
||
console.log(branch_id);
|
||
console.log(client_type);
|
||
|
||
$('#client_id').val(client_id).change();
|
||
$('#client_type').val(client_type);
|
||
|
||
if(client_type == 1){
|
||
|
||
$('.branchdiv').show()
|
||
$('#client_branch_id').prop('required', true);
|
||
setTimeout(function(){
|
||
$('#client_branch_id').val(branch_id).change()
|
||
}, 800)
|
||
|
||
$('#table_tr_34').show();
|
||
$('#table_tr_37').show();
|
||
// $("select[name='cd_ac_no_for_child[]']").attr('required', 'required');
|
||
|
||
}else{
|
||
|
||
$('.branchdiv').hide()
|
||
$('#client_branch_id').prop('required', false);
|
||
|
||
$('#table_tr_34').hide();
|
||
$('#table_tr_37').hide();
|
||
// $("select[name='cd_ac_no_for_child[]']").removeAttr("required");
|
||
|
||
}
|
||
|
||
if(val == 'add_vehicle'){
|
||
|
||
$('#modal_vehicle_no').val('');
|
||
// var myModal = new bootstrap.Modal(document.getElementById('vehicle_modal'));
|
||
// myModal.show();
|
||
|
||
$(this).val('').select2();
|
||
$('#actcual_clients').hide();
|
||
appendVehicleForm();
|
||
|
||
$('#pre_sales_row').hide();
|
||
$('#sales_row').hide();
|
||
$('#submitButton').hide();
|
||
|
||
}else{
|
||
$('#pre_sales_row').show();
|
||
$('#submitButton').show();
|
||
// if(status == "completed"){
|
||
$('#sales_row').show(); // REF : Venkatesh R - Status html Remove. so i removed the 'if'.
|
||
// }
|
||
}
|
||
})
|
||
|
||
$('#owner').change(function(){
|
||
|
||
let owner_id = $(this).val();
|
||
console.log('owner_id', owner_id);
|
||
|
||
if(owner_id == 'add_client'){
|
||
|
||
$(this).val("");
|
||
|
||
if($('#client_type').val()){
|
||
|
||
isVehicleFormSubmitting = true;
|
||
$('#vehicle_close_btn').click();
|
||
|
||
if ($('#client_type').val() == 2) {
|
||
|
||
$('.branchdiv').hide();
|
||
$('.clienttypediv').show();
|
||
$('#entity_type_id_for_client').prop('required', false);
|
||
$('#branch_name').prop('required', false);
|
||
$('#client_branch_id').prop('required', false);
|
||
$('#branch_code').prop('required', false);
|
||
$('#name').prop('required', false);
|
||
// $('#mobile').prop('required', false);
|
||
$('#gst').prop('required', false);
|
||
$('#email').prop('required', false);
|
||
|
||
|
||
$('#dob').prop('required', true);
|
||
// $('#phone').prop('required', true)
|
||
$('#email2').prop('required', true);
|
||
$('#aadhar').prop('required', true);
|
||
|
||
$('#short_name').closest('.form-group').hide();
|
||
$('#short_name').removeAttr('required');
|
||
|
||
} else {
|
||
|
||
$('.branchdiv').show();
|
||
$('.clienttypediv').hide();
|
||
$('#entity_type_id_for_client').prop('required', true);
|
||
$('#branch_name').prop('required', true);
|
||
$('#client_branch_id').prop('required', true);
|
||
$('#branch_code').prop('required', true);
|
||
$('#name').prop('required', true);
|
||
// $('#mobile').prop('required', false);
|
||
$('#gst').prop('required', false);
|
||
$('#email').prop('required', true);
|
||
|
||
$('#dob').prop('required', false);
|
||
// $('#phone').prop('required', false);
|
||
$('#email2').prop('required', false);
|
||
$('#aadhar').prop('required', false);
|
||
|
||
$('#short_name').closest('.form-group').show();
|
||
$('#short_name').attr('required', 'required');
|
||
|
||
}
|
||
|
||
var myModal = new bootstrap.Modal(document.getElementById('upload_enrollment_model'));
|
||
myModal.show();
|
||
|
||
isVehicleFormSubmitting = false;
|
||
|
||
}else{
|
||
|
||
toastr.warning('Please select the Owner type', 'Warning');
|
||
}
|
||
|
||
|
||
$('#client_form').attr('data-id', 1);
|
||
|
||
// Save form data from the #vehicle_form to localStorage
|
||
saveFormDataToLocalStorage("#vehicle_form", "vehicleFormData");
|
||
|
||
|
||
}
|
||
|
||
if(branch_list != '') {
|
||
// console.log(branch_list[client_id]);
|
||
let data = branch_list[owner_id];
|
||
appendOwnerBranch(data);
|
||
}
|
||
|
||
})
|
||
|
||
$('#policy_type_id').change(function() {
|
||
|
||
$('#vehicle_no').val("").select2();
|
||
$('#client_type').val('');
|
||
$('#client_id').val('').select2();
|
||
$('#client_branch_id').val('').select2();
|
||
$('#vehicle_row_div').empty();
|
||
$('#client_row_div').empty();
|
||
$('#actcual_clients').show();
|
||
|
||
let status = $('#policy_status').val();
|
||
$('#pre_sales_row').show();
|
||
$('#submitButton').show();
|
||
// if(status == "completed"){
|
||
$('#sales_row').show(); // REF : Venkatesh R - Status html Remove. so i removed the 'if'.
|
||
// }
|
||
|
||
var client_type = $('#client_type').val();
|
||
var value = $(this).val();
|
||
var selectedOption = $(this).find('option:selected');
|
||
|
||
let category = insurer_category[value] ?? null;
|
||
console.log('insurer_category', category);
|
||
// console.log('insurer_data', insurer_data);
|
||
|
||
// loop through all select fields
|
||
$('[name="follow_insurer_id[]"]').each(function () {
|
||
let select = $(this);
|
||
if(select){
|
||
appendInsurerByCategory(insurer_data, select, category);
|
||
}
|
||
});
|
||
|
||
|
||
var ebp = selectedOption.data('ebp');
|
||
var etp = selectedOption.data('etp');
|
||
var etep = selectedOption.data('etep');
|
||
var iep = selectedOption.data('iep');
|
||
var itp = selectedOption.data('itp');
|
||
var itep = selectedOption.data('itep');
|
||
|
||
var bap = selectedOption.data('bap');
|
||
var allocg = selectedOption.data('allocg');
|
||
// console.log('allocg:', allocg);
|
||
|
||
// console.log('EBP:', ebp);
|
||
// console.log('ETP:', etp);
|
||
// console.log('ETEP:', etep);
|
||
// console.log('IEP:', iep);
|
||
// console.log('ITP:', itp);
|
||
// console.log('ITEP:', itep);
|
||
|
||
|
||
var client_type_id = $('#client_type').val() ?? 1;
|
||
var is_co_pay_yes = $('#cop_yes').prop('checked') ? 1 : 0;
|
||
|
||
if(allocg == "EB"){
|
||
|
||
$('.hideter').hide();
|
||
$('.hidetp').hide();
|
||
$('.hidecoter').hide()
|
||
$('.hidecotp').hide()
|
||
|
||
} else if(allocg == "Non-EB"){
|
||
|
||
$('.hidetp').hide();
|
||
$('.hidecotp').hide();
|
||
|
||
$('.hideter').show();
|
||
if(is_co_pay_yes == 1){
|
||
$('.hidecoter').show();
|
||
}else{
|
||
$('.hidecoter').hide();
|
||
}
|
||
|
||
} else if(value == 8){
|
||
|
||
$('.hideter').hide();
|
||
$('.hidecoter').hide();
|
||
|
||
$('.hidetp').show();
|
||
if(is_co_pay_yes == 1){
|
||
$('.hidecotp').show();
|
||
}else{
|
||
$('.hidecotp').hide();
|
||
}
|
||
|
||
} else{
|
||
|
||
if(bap == 'Fire' || bap == 'Marine Cargo' || bap == 'Marine Hull'){
|
||
$('.hideter').show();
|
||
if(is_co_pay_yes == 1){
|
||
$('.hidecoter').show();
|
||
}else{
|
||
$('.hidecoter').hide();
|
||
}
|
||
}else{
|
||
$('.hideter').hide();
|
||
}
|
||
}
|
||
|
||
|
||
// do not remove this commented item
|
||
// if(bap == 'Fire' || bap == 'Marine Cargo' || bap == 'Marine Hull'){
|
||
// $('.hideter').show();
|
||
// $('.hidetp').hide();
|
||
|
||
// if(is_co_pay_yes == 1){
|
||
// $('.hidecoter').show()
|
||
// $('.hidecotp').hide()
|
||
// }else{
|
||
// $('.hidecoter').hide()
|
||
// $('.hidecotp').hide()
|
||
// }
|
||
// }else{
|
||
|
||
// if(bap == 'Motor'){
|
||
|
||
// $('.hidetp').show()
|
||
// $('.hideter').hide()
|
||
|
||
// if(is_co_pay_yes == 1){
|
||
// $('.hidecotp').show()
|
||
// $('.hidecoter').hide()
|
||
// }else{
|
||
// $('.hidecoter').hide();
|
||
// $('.hidecotp').hide();
|
||
// }
|
||
|
||
// }else{
|
||
// $('.hideter').hide()
|
||
// $('.hidetp').hide()
|
||
// $('.hidecoter').hide()
|
||
// $('.hidecotp').hide()
|
||
// }
|
||
// }
|
||
|
||
var std_bp = 0;
|
||
var std_tp = 0;
|
||
var std_tep = 0;
|
||
|
||
if(client_type_id == 1){
|
||
std_bp = ebp;
|
||
std_tp = etp;
|
||
std_tep = etep;
|
||
}else{
|
||
std_bp = iep;
|
||
std_tp = itp;
|
||
std_tep = itep;
|
||
}
|
||
|
||
$('[name="standard_bp[]"]').val(std_bp);
|
||
$('[name="standard_tp[]"]').val(std_tp);
|
||
$('[name="standard_ter[]"]').val(std_tep);
|
||
|
||
if(value == 8){
|
||
$('#vhnodiv').show();
|
||
$('#client_type_div').hide();
|
||
$('#policyholdernamediv').hide();
|
||
// $('#hide_vehicle_tab').show();
|
||
$('#client_type').addClass('readonly-select ');
|
||
$('#client_id').addClass('readonly-select ').select2('destroy');
|
||
$('#client_branch_id').addClass('readonly-select ').select2('destroy');
|
||
}else{
|
||
$('#vehicle_no').val("").select2();
|
||
$('#vhnodiv').hide();
|
||
$('#client_type_div').show();
|
||
// $('#hide_vehicle_tab').hide();
|
||
$('#client_type').removeClass('readonly-select ');
|
||
$('#client_id').removeClass('readonly-select ').select2();
|
||
$('#client_branch_id').removeClass('readonly-select ').select2();
|
||
}
|
||
|
||
// do not remove this commented item for Client type list hide and show
|
||
// if(parseFloat(ebp) != 0.00 && parseFloat(iep) != 0.00){
|
||
// $('#client_type option[value="1"]').show();
|
||
// $('#client_type option[value="2"]').show();
|
||
// }else if(parseFloat(iep) == 0.00){
|
||
// $('#client_type option[value="2"]').hide();
|
||
// $('#client_type option[value="1"]').show();
|
||
// }else if(parseFloat(ebp) == 0.00){
|
||
// $('#client_type option[value="1"]').hide();
|
||
// $('#client_type option[value="2"]').show();
|
||
// }else{
|
||
// $('#client_type option[value="1"]').show();
|
||
// $('#client_type option[value="2"]').show();
|
||
// }
|
||
|
||
// if(value == 38 || value == 40){
|
||
// $('#tpa_div').hide();
|
||
// }else{
|
||
// $('#tpa_div').show();
|
||
// }
|
||
|
||
if(value == 1 || value == 2 || value == 3 || value == 4 || value == 5){
|
||
$('#tpa_div').show();
|
||
}else{
|
||
$('#tpa_div').hide();
|
||
}
|
||
|
||
if(value == 2 || value == 3 || value == 4 || value == 5){
|
||
$('#no_of_insured_div').show();
|
||
$('#no_of_dependents_div').show();
|
||
}else if(value == 1 || value == 6 || value == 7) {
|
||
$('#no_of_insured_div').show();
|
||
$('#no_of_dependents_div').hide();
|
||
}else{
|
||
$('#no_of_insured_div').hide();
|
||
$('#no_of_dependents_div').hide();
|
||
}
|
||
|
||
if(value == 1 || value == 2 || value == 3 || value == 4 || value == 5 || value == 6 || value == 7){
|
||
|
||
$('#is_cd_reduce_from_bds').prop('disabled',true).prop('checked', false);
|
||
|
||
$('#table_tr_34').hide();
|
||
$('#table_tr_37').hide();
|
||
// $("select[name='cd_ac_no_for_child[]']").removeAttr("required");
|
||
|
||
}else{
|
||
|
||
$('#is_cd_reduce_from_bds').prop('disabled',false);
|
||
|
||
$('#table_tr_34').show();
|
||
$('#table_tr_37').show();
|
||
// $("select[name='cd_ac_no_for_child[]']").attr('required', 'required');
|
||
}
|
||
|
||
if(value == 8){
|
||
addHTMLInputForVehicleFileUpload(null, 'vehicle_docs_div')
|
||
$('#vehicle_docs').show();
|
||
}else{
|
||
$('#vehicle_docs').hide();
|
||
$('#vehicle_docs_div').empty();
|
||
}
|
||
|
||
});
|
||
|
||
})
|
||
|
||
$(document).on('change', 'input[type="checkbox"][name="co_share_type[]"]', function() {
|
||
|
||
// $('[name="base_premium[]"]').val("");
|
||
// $('[name="co_premium[]"]').val("");
|
||
|
||
let isAnyChecked = $('input[type="checkbox"][name="co_share_type[]"]:checked').length > 1;
|
||
|
||
if (isAnyChecked) {
|
||
toastr.warning('Only one leader can be selected.', 'Warning!');
|
||
$(this).prop('checked', false);
|
||
return;
|
||
}
|
||
|
||
let val = $(this).val();
|
||
let uniqueid = $(this).data('id');
|
||
let insurer = $('#follow_insurer_id_'+uniqueid).val()
|
||
let policy_type_id = $('#policy_type_id').val();
|
||
let client_type = $('#client_type').val();
|
||
|
||
var client_id = $('#client_id').val()
|
||
var insurer_id = $('#follow_insurer_id_'+uniqueid).find('option:selected').attr('data-id');
|
||
var insurer_branch_id = $('#follow_insurer_id_'+uniqueid).find('option:selected').attr('data-bid');
|
||
|
||
// console.log('client_id', client_id);
|
||
// console.log('insurer_id', insurer_id);
|
||
|
||
if(insurer == ""){
|
||
toastr.warning('Please select the insurer.', 'Warning!');
|
||
$(this).prop('checked', false);
|
||
return;
|
||
}else{
|
||
$('#insurer_id').val(insurer)
|
||
}
|
||
|
||
$('[name="calc_policy_issue_date[]"]').each(function () {
|
||
$(this).val('').removeClass('readonly-select');
|
||
});
|
||
|
||
let policy_issue_date = $('#policy_issue_date').val();
|
||
if ($('#cop_yes').is(':checked') && $(this).is(':checked')) {
|
||
$('#follower_policy_no_' + uniqueid).prop('readonly', true);
|
||
$('#calc_policy_issue_date_' + uniqueid).val(policy_issue_date).addClass('readonly-select');;
|
||
} else {
|
||
$('#follower_policy_no_' + uniqueid).prop('readonly', false);
|
||
$('#calc_policy_issue_date_1').val(policy_issue_date).addClass('readonly-select');
|
||
}
|
||
|
||
if ($(this).is(':checked')) {
|
||
// Hide all
|
||
$('[name="cd_ac_no_for_child[]"]').val('');
|
||
$('[id^="cd_current_balance_"]').val('');
|
||
|
||
$('[name="cd_ac_no_for_child[]"]').hide();
|
||
$('[id^="cd_current_balance_"]').hide();
|
||
|
||
// Show only current one
|
||
$('#cd_ac_no_' + uniqueid).show();
|
||
$('#cd_current_balance_' + uniqueid).show();
|
||
} else {
|
||
|
||
$('[name="cd_ac_no_for_child[]"]').val('');
|
||
$('[id^="cd_current_balance_"]').val('');
|
||
|
||
// Show all back
|
||
$('[name="cd_ac_no_for_child[]"]').show();
|
||
$('[id^="cd_current_balance_"]').show();
|
||
}
|
||
|
||
if(policy_type_id > 7 || client_type == 1){
|
||
$('[name="cd_ac_no_for_child[]"]').removeAttr('onchange');
|
||
$('#cd_ac_no_' + uniqueid).attr('onchange', 'addCDAccountNumber(this); restrictCDACNO(this);');
|
||
|
||
if ($(this).is(':checked')) {
|
||
|
||
$('[name="cd_ac_no_for_child[]"]').each(function () {
|
||
$(this).prop('required', false).parsley().reset();
|
||
});
|
||
|
||
$('#cd_ac_no_' + uniqueid).prop('required', true).parsley().reset();
|
||
|
||
} else {
|
||
|
||
$('[name="cd_ac_no_for_child[]"]').each(function () {
|
||
$(this).prop('required', false).parsley().reset();
|
||
});
|
||
}
|
||
|
||
}
|
||
|
||
});
|
||
|
||
$(document).on('change', 'select[name="relationship[]"]', function() {
|
||
var selectedValues = [];
|
||
var hasDuplicate = false;
|
||
var currentSelect = $(this);
|
||
|
||
// Collect all selected values
|
||
$('select[name="relationship[]"]').each(function() {
|
||
var value = $(this).val();
|
||
if (value) {
|
||
if (selectedValues.indexOf(value) !== -1) {
|
||
hasDuplicate = true; // Mark if duplicate is found
|
||
}
|
||
selectedValues.push(value);
|
||
}
|
||
});
|
||
|
||
if (hasDuplicate) {
|
||
// Show toastr warning if duplicate is detected
|
||
toastr.warning('Duplicate relationship selected. Please choose a different one.');
|
||
|
||
// Reset the current selection to default (unselected)
|
||
currentSelect.val('');
|
||
}
|
||
|
||
// Highlight already selected options in other dropdowns
|
||
$('select[name="relationship[]"]').each(function() {
|
||
var current = $(this);
|
||
current.find('option').removeClass('highlighted'); // Remove previous highlights
|
||
current.find('option').each(function() {
|
||
if (selectedValues.indexOf($(this).val()) !== -1 && $(this).val() !== current.val()) {
|
||
$(this).addClass('highlighted'); // Add highlight class to duplicates
|
||
}
|
||
});
|
||
});
|
||
});
|
||
|
||
$(document).ready(function() {
|
||
|
||
$(document).on('change', '[name="follow_insurer_id[]"]', function() {
|
||
|
||
let currentSelect = $(this);
|
||
let insurer = $(this).val();
|
||
let unique_id = $(this).data('count');
|
||
let client_id = $('#client_id').val();
|
||
let policy_type_id = $('#policy_type_id').val();
|
||
|
||
console.log('insurer', insurer);
|
||
console.log('policy_type_id', policy_type_id);
|
||
console.log('follow_insurer_id client_id', client_id);
|
||
console.log('follow_insurer_id unique_id', unique_id);
|
||
|
||
$('#insurer_id').val(insurer)
|
||
|
||
if (!policy_type_id || !client_id) {
|
||
$(this).val('').select2();
|
||
toastr.warning(!policy_type_id ? 'Please select the Policy Type' : 'Please select the Client', 'Warning');
|
||
return false;
|
||
}
|
||
|
||
let isDuplicate = false;
|
||
|
||
$('[name="follow_insurer_id[]"]').not(currentSelect).each(function () {
|
||
if ($(this).val() === insurer) {
|
||
isDuplicate = true;
|
||
return false; // break loop
|
||
}
|
||
});
|
||
|
||
if (isDuplicate) {
|
||
$(this).val('').select2();
|
||
toastr.warning('Do not select the same insurer and branch again');
|
||
return false;
|
||
}
|
||
|
||
});
|
||
|
||
});
|
||
|
||
//---------------------------------------------------------------------------------------------------------
|
||
|
||
//edit function
|
||
function getPolicyTransactionDataForEdit(input) {
|
||
|
||
console.log('############################# Get Policy Transaction Data For Edit #############################');
|
||
|
||
$('.loader').fadeIn();
|
||
$('.loader-mask').fadeIn();
|
||
|
||
$('#inception_form_id')[0].reset();
|
||
// var id = $(input).attr('data-id');
|
||
var id = input;
|
||
console.log('Selected policy transaction ID:', id);
|
||
|
||
$.ajax({
|
||
url: '<?= base_url("/policy_tranction/inception/list/") ?>' + id,
|
||
type: "GET",
|
||
dataType: 'json',
|
||
success: function(res) {
|
||
console.log('getPolicyTransactionDataForEdit', res);
|
||
|
||
if (res.status == true) {
|
||
|
||
hide_list_show_add();
|
||
|
||
var page_title = 'Edit Policy' + (res.data.client_short_name || res.data.policy_type || res.data.policy_no ?
|
||
' - ' + [res.data.client_short_name, res.data.policy_type, res.data.policy_no]
|
||
.filter(Boolean).join('-') : '');
|
||
|
||
$('#page_title').text(page_title);
|
||
$('#client_id_kyc').val(res.data.client_id);
|
||
$('#policy_tranction_primarykey_for_file_upload').val(res.data.id);
|
||
$('#client_id_for_vehicle_file_upload').val(res.data.client_id);
|
||
$('#vehicle_id_for_file_upload').val(res.data.vehicle_id);
|
||
$('#client_policy_id_for_file_upload').val(res.data.client_policy_id);
|
||
$('#policy_tranction_policy_number').val(res.data.policy_no);
|
||
|
||
// $('#cd_ac_no_for_edit').val(res.data.cd_ac_no);
|
||
$('#cd_ac_pk_for_leader').val(res.data.cd_ac_pk);
|
||
|
||
// $('#entity_type_id').val(res.data.entity_type_id);
|
||
// getKYCEntityDocument(res.data.entity_type_id, res.data.client_id);
|
||
// appendKycTableListData(res.data.client_kyc);
|
||
|
||
$('#tbody').empty();
|
||
$('#tbody').append(res.data.client_kyc_primary_table);
|
||
|
||
$('#other_docs').empty();
|
||
$('#other_docs').append(res.data.client_kyc_other_table);
|
||
|
||
|
||
// Setting values to correct fields
|
||
$('#policy_tranction_primarykey').val(res.data.id);
|
||
$('#client_policy_id').val(res.data.client_policy_id);
|
||
$('#client_id_for_edit').val(res.data.client_id);
|
||
$('#issuer').val(res.data.issuer);
|
||
$('#issue_type').val(res.data.issue_type);
|
||
|
||
setTimeout(function() {
|
||
$('#client_id').val(res.data.client_id).change();
|
||
$('#client_type').val(res.data.client_type);
|
||
$('#insurer_id').val(res.data.insurer_branch_id + '-' + res.data.insurer_id);
|
||
$('#vehicle_no').val(res.data.vehicle_id).select2();
|
||
}, 1000);
|
||
|
||
var tpaValue = '';
|
||
if (res.data.master_tpa_branch_id && res.data.master_tpa_id) {
|
||
tpaValue = res.data.master_tpa_branch_id + '-' + res.data.master_tpa_id;
|
||
} else if (res.data.tpa_branch_id && res.data.tpa_id) {
|
||
tpaValue = res.data.tpa_branch_id + '-' + res.data.tpa_id;
|
||
}
|
||
|
||
$('#tpa').val(tpaValue).change();
|
||
|
||
let policy_type_id_for_hide_tpa = res.data.master_policy_type_id;
|
||
if(policy_type_id_for_hide_tpa == 1 || policy_type_id_for_hide_tpa == 2 || policy_type_id_for_hide_tpa == 3 || policy_type_id_for_hide_tpa == 4 || policy_type_id_for_hide_tpa == 5 || policy_type_id_for_hide_tpa == 38 || policy_type_id_for_hide_tpa == 40){
|
||
$('#tpa_div').hide();
|
||
}else{
|
||
$('#tpa_div').show();
|
||
}
|
||
|
||
if(policy_type_id_for_hide_tpa == 1 || policy_type_id_for_hide_tpa == 2 || policy_type_id_for_hide_tpa == 3 || policy_type_id_for_hide_tpa == 4 || policy_type_id_for_hide_tpa == 5 || policy_type_id_for_hide_tpa == 6 || policy_type_id_for_hide_tpa == 7){
|
||
$('#is_cd_reduce_from_bds').prop('disabled',true).prop('checked', false)
|
||
}else{
|
||
$('#is_cd_reduce_from_bds').prop('disabled',false)
|
||
}
|
||
|
||
// if(res.data.client_policy_id != 0 && res.data.client_policy_id != null){
|
||
// $('#hide_file_upload').show();
|
||
// }else{
|
||
// $('#hide_file_upload').hide();
|
||
// }
|
||
$('#hide_file_upload').show();
|
||
|
||
if (res.data.master_policy_type_id) {
|
||
$('#policy_type_id').val(res.data.master_policy_type_id).change();
|
||
} else {
|
||
$('#policy_type_id').val(res.data.policy_type_id).change();
|
||
}
|
||
|
||
if (res.data.issue_type == 2) {
|
||
appendRenewalPolicies(res.data.renewal_policy);
|
||
}
|
||
|
||
if (res.data.is_addon == 2 || res.data.is_addon == 3) {
|
||
appendBasePolicyList(res.data.base_policy_data);
|
||
}
|
||
|
||
appendFileTableBody(res.data.pt_files);
|
||
|
||
appendVehicleFileTableBody(res.data.vehicle_docs);
|
||
|
||
if (res.data.pt_co_share_details) {
|
||
setTimeout(function() {
|
||
populateTable(res.data.pt_co_share_details, res.data.cd_ac_pk);
|
||
}, 1000);
|
||
}
|
||
|
||
// if (res.data.listed_insurers) {
|
||
// selectListedInsurers(res.data.listed_insurers);
|
||
// }
|
||
|
||
if (res.data.pt_co_share_details && res.data.pt_co_share_details.length > 0) {
|
||
$('#tab_content').empty();
|
||
count = 0;
|
||
$.each(res.data.pt_co_share_details, function(index, item) {
|
||
// appendNewTab(item); // Uncomment when implementing tab addition logic
|
||
});
|
||
}
|
||
|
||
setTimeout(function() {
|
||
$('#cd_ac_pk_for_leader').val(res.data.cd_ac_pk);
|
||
$('#client_branch_id').val(res.data.client_branch_id).change();
|
||
$('#source_client_policy_id').val(res.data.source_client_policy_id).change();
|
||
$('#base_policy').val(res.data.base_policy).select2();
|
||
// $('.loader').fadeOut();
|
||
// $('.loader-mask').delay(350).fadeOut('slow');
|
||
}, 2000);
|
||
|
||
setTimeout(function(){
|
||
// $('select[name="cd_ac_no_for_child[]"]').val(res.data.cd_ac_no ?? "");
|
||
$('select[name="cd_ac_no_for_child[]"] option').each(function() {
|
||
if ($(this).val() == res.data.id) {
|
||
$(this).prop('selected', true);
|
||
$('.loader').fadeOut();
|
||
$('.loader-mask').delay(350).fadeOut('slow');
|
||
}else{
|
||
$('.loader').fadeOut();
|
||
$('.loader-mask').delay(350).fadeOut('slow');
|
||
}
|
||
});
|
||
|
||
if (res.data.policy_type_id == 1 || res.data.policy_type_id == 2 || res.data.policy_type_id == 3 || res.data.policy_type_id == 4 || res.data.policy_type_id == 5 || res.data.policy_type_id == 6 || res.data.policy_type_id == 7 || res.data.client_type == 2) {
|
||
$('#table_tr_34').hide();
|
||
$('#table_tr_37').hide();
|
||
}
|
||
|
||
$('#client_id').addClass('readonly-select ').select2('destroy');
|
||
$('#client_branch_id').addClass('readonly-select ').select2('destroy');
|
||
|
||
}, 4000)
|
||
|
||
// Set additional fields
|
||
$('#policy_status').val(res.data.status);
|
||
$('#ref').val(res.data.ref);
|
||
$('#spl').val(res.data.spl);
|
||
$('#fund_received').val(res.data.fund_received);
|
||
$('#revenue_type').val(res.data.revenue_type);
|
||
$('#month').val(res.data.month);
|
||
|
||
$('#policy_no').val(res.data.policy_no);
|
||
$('#policy_issue_date').val(res.data.policy_issue_date);
|
||
$('#policy_start_date').val(res.data.policy_start_date);
|
||
$('#policy_end_date').val(res.data.policy_end_date);
|
||
$('#emp_count').val(res.data.emp_count);
|
||
$('#dependent_count').val(res.data.dependent_count);
|
||
$('#ppteam').val(res.data.ppteam).change();
|
||
$('#fund_received').val(res.data.fund_received);
|
||
$('#renewal_date').val(res.data.renewal_date);
|
||
$('#rollover_date').val(res.data.rollover_date);
|
||
$('#policy_holder_name').val(res.data.policy_holder_name);
|
||
$('#location').val(res.data.location);
|
||
$('#installment').val(res.data.installment);
|
||
$('#installment_data').val(res.data.installment_data);
|
||
$('#last_action_date').val(res.data.last_action_date);
|
||
$('#process_start_date').val(res.data.created_at);
|
||
$('#remark').val(res.data.remarks);
|
||
// $('.current_date').show();
|
||
$('#sales_generated_by').val(res.data.sales_generated_by ?? '').change();
|
||
$('#serviced_by').val(res.data.serviced_by ?? '').change();
|
||
$('#base_cd_amount').val(res.data.base_cd_amount);
|
||
$('#issuer_branch').val(res.data.issuer_branch);
|
||
$('#pos_id').val(res.data.pos_id ?? '').change();
|
||
|
||
|
||
// Additional form handling logic
|
||
if (res.data.issue_type == 2) {
|
||
$('#renewal').show();
|
||
// $('#source_client_policy_id').attr('required', true);
|
||
} else {
|
||
$('#renewal').hide();
|
||
// $('#source_client_policy_id').attr('required', false);
|
||
}
|
||
|
||
// Handle base policy visibility
|
||
if (res.data.is_addon == 2 || res.data.is_addon == 3) {
|
||
$('#base_policy_id').show();
|
||
} else {
|
||
$('#base_policy_id').hide();
|
||
}
|
||
|
||
// Handle co-share percentage
|
||
if (res.data.co_share == 1) {
|
||
$('#cop_yes').prop('checked', true);
|
||
$('#add_more_row').removeClass('d-none');
|
||
$('.payby').removeClass('d-none');
|
||
$('#table_tr_2').show();
|
||
$('#table_tr_3').show();
|
||
$('#table_tr_7').show();
|
||
$('#table_tr_35').show();
|
||
} else {
|
||
$('#cop_yes').prop('checked', false);
|
||
$('#add_more_row').addClass('d-none');
|
||
$('.payby').addClass('d-none');
|
||
$('#table_tr_2').hide();
|
||
$('#table_tr_3').hide();
|
||
$('#table_tr_7').hide();
|
||
$('#table_tr_35').hide();
|
||
|
||
setTimeout(function(){
|
||
$('input[name="co_share_per[]"], input[name="co_premium[]"]').each(function () {
|
||
$(this).val(''); // Clear value
|
||
console.log('Input cleared:', $(this).attr('name'));
|
||
});
|
||
}, 4000);
|
||
}
|
||
|
||
// Handle "Same Insured Name"
|
||
if (res.data.same_as_proposer == 1) {
|
||
$('#same_as_proposer').prop('checked', true);
|
||
$('#dynamic-form-container-for-insured').empty();
|
||
$('#family_details').hide();
|
||
} else {
|
||
$('#same_as_proposer').prop('checked', false);
|
||
if (res.data.client_type == 2 && res.data.policy_type_id != 8) {
|
||
$('#family_details').show();
|
||
$.each(res.data.emp_data, function(index, emp) {
|
||
appendInsured(emp);
|
||
});
|
||
} else {
|
||
$('#dynamic-form-container-for-insured').empty();
|
||
$('#family_details').hide();
|
||
}
|
||
}
|
||
|
||
// Handle brokerage pay by
|
||
// if (res.data.bro_payable_by == 1) {
|
||
// $('#bro_payable_by').prop('checked', true);
|
||
// } else {
|
||
// $('#bro_payable_by').prop('checked', false);
|
||
// }
|
||
$('#bro_payable_by').val(res.data.bro_payable_by ?? 1);
|
||
|
||
// Policy transaction status handling
|
||
if (res.data.status == "completed") {
|
||
$('#sales_row').show();
|
||
$('#policy_no').prop('required', true);
|
||
$('#policy_issue_date').prop('required', true);
|
||
$('#policy_start_date').prop('required', true);
|
||
$('#policy_end_date').prop('required', true);
|
||
// $('#tpa').prop('required', true);
|
||
// $('#emp_count').prop('required', true);
|
||
// $('#dependent_count').prop('required', true);
|
||
$('.follow_insurer').prop('required', true);
|
||
} else {
|
||
$('#sales_row').hide();
|
||
$('#policy_no').prop('required', false);
|
||
$('#policy_issue_date').prop('required', false);
|
||
$('#policy_start_date').prop('required', false);
|
||
$('#policy_end_date').prop('required', false);
|
||
// $('#tpa').prop('required', false);
|
||
// $('#emp_count').prop('required', false);
|
||
// $('#dependent_count').prop('required', false);
|
||
$('.follow_insurer').prop('required', false);
|
||
}
|
||
|
||
// Client type changes
|
||
if (res.data.client_type == 2) {
|
||
if (res.data.policy_type_id == 8) {
|
||
$('#policyholdernamediv').hide();
|
||
} else {
|
||
$('#policyholdernamediv').show();
|
||
}
|
||
$('.branchdiv').hide();
|
||
$('#client_branch_id').prop('required', false);
|
||
$('#table_tr_34').hide();
|
||
$('#table_tr_37').hide();
|
||
// $("select[name='cd_ac_no_for_child[]']").removeAttr("required");
|
||
|
||
} else {
|
||
$('#policyholdernamediv').hide();
|
||
$('.branchdiv').show();
|
||
$('#client_branch_id').prop('required', true);
|
||
$('#table_tr_34').show();
|
||
$('#table_tr_37').show();
|
||
// $("select[name='cd_ac_no_for_child[]']").attr('required', 'required');
|
||
}
|
||
|
||
//Vehicle File Upload Tab Hide And show
|
||
if(res.data.policy_type_id == 8){
|
||
$('#hide_vehicle_tab').show();
|
||
}else{
|
||
$('#hide_vehicle_tab').hide();
|
||
}
|
||
|
||
if (res.data.policy_with_corr == 1) {
|
||
$('#policy_with_corr').prop('checked', true);
|
||
} else {
|
||
$('#policy_with_corr').prop('checked', false);
|
||
}
|
||
|
||
if (res.data.is_cd_reduce_from_bds == 1) {
|
||
$('#is_cd_reduce_from_bds').prop('checked', true).prop('checked', false);
|
||
} else {
|
||
$('#is_cd_reduce_from_bds').prop('checked', false);
|
||
}
|
||
|
||
$('#vehicle_docs').hide();
|
||
$('#vehicle_docs_div').empty();
|
||
|
||
|
||
} else {
|
||
console.log('No data found');
|
||
}
|
||
},
|
||
error: function(xhr, status, error) {
|
||
$('.loader').fadeOut();
|
||
$('.loader-mask').delay(350).fadeOut('slow');
|
||
console.error(xhr.responseText);
|
||
console.error(status, error);
|
||
}
|
||
});
|
||
|
||
//To check the invoice statement if statament is upload aginst this policy than change readonly the table fileds
|
||
checkInvoiceStatusToHideSubmitBtn(id)
|
||
|
||
console.log('############################# END Get Policy Transaction Data For Edit #############################');
|
||
|
||
}
|
||
|
||
//-------- CALCULATION PART -------------------------------------------------------------------------------------------------
|
||
|
||
// do not remove this
|
||
// function checkAndDistributeTax(input)
|
||
// {
|
||
// const event = window.event;
|
||
// // console.log("Event type:", event.type);
|
||
// // console.log("Event target:", event.target);
|
||
// console.log("Event id:", event.target.id);
|
||
|
||
// let cgst = parseFloat($('#cgst_' + input).val());
|
||
// let sgst = parseFloat($('#sgst_' + input).val());
|
||
// let igst = parseFloat($('#igst_' + input).val());
|
||
|
||
// if (((event.target.id).startsWith('cgst') || (event.target.id).startsWith('sgst'))) {
|
||
|
||
// if (!isFinite(cgst) || isNaN(cgst) || cgst === undefined) {
|
||
// cgst = 0;
|
||
// }
|
||
// if (!isFinite(sgst) || isNaN(sgst) || sgst === undefined) {
|
||
// sgst = 0;
|
||
// }
|
||
|
||
// if (cgst !== 0) {
|
||
// $('#sgst_' + input).val(cgst);
|
||
// } else if (sgst !== 0) {
|
||
// $('#cgst_' + input).val(sgst);
|
||
// }
|
||
|
||
// $('#igst_' + input).val(0);
|
||
// }
|
||
// else if ((event.target.id).startsWith('igst')) {
|
||
// $('#cgst_' + input).val(0);
|
||
// $('#sgst_' + input).val(0);
|
||
// }
|
||
|
||
// // Ensure IGST, CGST, and SGST are never NaN, undefined, or Infinity
|
||
// $('#igst_' + input).val(isFinite($('#igst_' + input).val()) ? $('#igst_' + input).val() : 0);
|
||
// $('#cgst_' + input).val(isFinite($('#cgst_' + input).val()) ? $('#cgst_' + input).val() : 0);
|
||
// $('#sgst_' + input).val(isFinite($('#sgst_' + input).val()) ? $('#sgst_' + input).val() : 0);
|
||
|
||
// }
|
||
|
||
function checkAndDistributeTax(input){
|
||
|
||
const event = window.event;
|
||
console.log("Event id:", event.target.id);
|
||
|
||
let policy_type_id = parseInt($('#policy_type_id').val());
|
||
console.log('policy_type_id', policy_type_id);
|
||
|
||
let cgst = parseFloat($('#cgst_' + input).val());
|
||
let sgst = parseFloat($('#sgst_' + input).val());
|
||
let igst = parseFloat($('#igst_' + input).val());
|
||
|
||
// ✅ Allow 0 only for policy types 2, 5, 7
|
||
const allowZero = [1,2,3,4,5,6,7,38,39,40].includes(policy_type_id);
|
||
console.log("allowZero", allowZero);
|
||
|
||
// 🔒 Validation: Disallow 0 or negative values for other policy types
|
||
if (!allowZero) {
|
||
if ((cgst <= 0 && (event.target.id).startsWith('cgst')) ||
|
||
(sgst <= 0 && (event.target.id).startsWith('sgst')) ||
|
||
(igst <= 0 && (event.target.id).startsWith('igst'))) {
|
||
|
||
toastr.warning('Tax value must be greater than 0 for this policy type.');
|
||
$('#'+ event.target.id).val('');
|
||
$('#igst_' + input).val('');
|
||
$('#cgst_' + input).val('');
|
||
$('#sgst_' + input).val('');
|
||
|
||
return;
|
||
}
|
||
}
|
||
|
||
if (((event.target.id).startsWith('cgst'))) {
|
||
|
||
if (!isFinite(cgst) || isNaN(cgst) || cgst === undefined) {
|
||
cgst = '';
|
||
}
|
||
|
||
$('#cgst_' + input).val(cgst);
|
||
if(cgst == ""){
|
||
$('#sgst_' + input).val(0);
|
||
}else{
|
||
$('#sgst_' + input).val(cgst);
|
||
}
|
||
$('#igst_' + input).val(0);
|
||
}
|
||
|
||
if (((event.target.id).startsWith('sgst'))) {
|
||
|
||
if (!isFinite(sgst) || isNaN(sgst) || sgst === undefined) {
|
||
sgst = '';
|
||
}
|
||
|
||
$('#sgst_' + input).val(sgst);
|
||
if(sgst == ""){
|
||
$('#cgst_' + input).val(0);
|
||
}else{
|
||
$('#cgst_' + input).val(sgst);
|
||
}
|
||
$('#igst_' + input).val(0);
|
||
}
|
||
|
||
if ((event.target.id).startsWith('igst')) {
|
||
$('#cgst_' + input).val(0);
|
||
$('#sgst_' + input).val(0);
|
||
}
|
||
|
||
// Ensure IGST, CGST, and SGST are never NaN, undefined, or Infinity
|
||
$('#igst_' + input).val(isFinite($('#igst_' + input).val()) ? $('#igst_' + input).val() : 0);
|
||
$('#cgst_' + input).val(isFinite($('#cgst_' + input).val()) ? $('#cgst_' + input).val() : 0);
|
||
$('#sgst_' + input).val(isFinite($('#sgst_' + input).val()) ? $('#sgst_' + input).val() : 0);
|
||
}
|
||
|
||
function amountCalculation(input, name = null) {
|
||
|
||
console.log('############################## AMOUNT CALCULATION ############################################')
|
||
console.log('amountCalculation : ' + input);
|
||
let selectedOption = $('#policy_type_id').find('option:selected');
|
||
let bap = selectedOption.data('bap');
|
||
let allocg = selectedOption.data('allocg');
|
||
// console.log('allocg:', allocg);
|
||
|
||
const event = window.event;
|
||
console.log("Event id:", event.target.id);
|
||
|
||
// Retrieve and parse the values or default to 0 if not a number
|
||
let bp = parseFloat($('#base_premium_' + input).val()) || 0;
|
||
let ncpa = parseFloat($('#non_comm_per_amt_' + input).val()) || 0;
|
||
|
||
var tp = 0;
|
||
if(allocg != 'EB'){
|
||
tp = parseFloat($('#tp_premium_' + input).val()) || 0;
|
||
}
|
||
// do not remove this commented item
|
||
// if(bap == 'Motor'){
|
||
// tp = parseFloat($('#tp_premium_' + input).val()) || 0;
|
||
// }
|
||
|
||
var tep = 0;
|
||
if(bap == 'Fire' || bap == 'Marine Cargo' || bap == 'Marine Hull'){
|
||
tep = parseFloat($('#ter_premium_' + input).val()) || 0;
|
||
}
|
||
|
||
//co-share premium
|
||
let cop = parseFloat($('#co_premium_' + input).val()) || 0;
|
||
|
||
var cotp = 0;
|
||
if(bap == 'Motor'){
|
||
cotp = parseFloat($('#co_tp_premium_' + input).val()) || 0;
|
||
}
|
||
|
||
var cotep = 0;
|
||
if(bap == 'Fire' || bap == 'Marine Cargo' || bap == 'Marine Hull'){
|
||
cotep = parseFloat($('#co_ter_premium_' + input).val()) || 0;
|
||
}
|
||
|
||
checkAndDistributeTax(input);
|
||
let cgst = parseFloat($('#cgst_' + input).val()) || 0;
|
||
let sgst = parseFloat($('#sgst_' + input).val()) || 0;
|
||
let igst = parseFloat($('#igst_' + input).val()) || 0;
|
||
|
||
|
||
let stamp_duty_amt = parseFloat($('#stamp_duty_' + input).val()) || 0;
|
||
let agreed_amount = parseFloat($('#agreed_amount_' + input).val()) || 0;
|
||
|
||
let agreed_bp_per = parseFloat($('#agreed_bp_' + input).val()) || 0;
|
||
let agreed_tp_per = parseFloat($('#agreed_tp_' + input).val()) || 0;
|
||
let agreed_tep_per = parseFloat($('#agreed_ter_' + input).val()) || 0;
|
||
|
||
let standard_bp_per = parseFloat($('#standard_bp_' + input).val()) || 0;
|
||
let standard_tp_per = parseFloat($('#standard_tp_' + input).val()) || 0;
|
||
let standard_tep_per = parseFloat($('#standard_tep_' + input).val()) || 0;
|
||
|
||
let co_share_per = parseFloat($('#co_share_per_' + input).val()) || 0;
|
||
let gst_amount = parseFloat($('#gst_amount_' + input).val()) || 0;
|
||
|
||
// console.log(standard_bp_per, standard_tp_per, standard_tep_per);
|
||
// console.log(agreed_bp_per, agreed_tp_per, agreed_tep_per);
|
||
|
||
|
||
// Calculate GST percentage
|
||
let gst_per = igst;
|
||
if (igst === 0) {
|
||
gst_per = parseFloat(cgst) + parseFloat(sgst);
|
||
}
|
||
|
||
// console.log('gst_per', gst_per);
|
||
// console.log('igst', igst);
|
||
// console.log('cgst', cgst);
|
||
// console.log('sgst', sgst);
|
||
|
||
// Calculate the total premium
|
||
|
||
let base_premium = cop;
|
||
let third_part_premium = cotp;
|
||
let terrisom_premium = cotep;
|
||
|
||
let tpTotal = cop + cotp + cotep;
|
||
// if($('#bro_payable_by').is(':checked')){
|
||
if($('#bro_payable_by').val() == 1){
|
||
|
||
tpTotal = bp + tp + tep;
|
||
|
||
base_premium = bp;
|
||
third_part_premium = tp;
|
||
terrisom_premium = tep;
|
||
|
||
}else if($('#bro_payable_by').val() == 2){
|
||
|
||
console.log("$('#bro_payable_by').val()", $('#bro_payable_by').val());
|
||
console.log("$('#co_share_type_' + input).is(':checked')", $('co_share_type_' + input).is(':checked'))
|
||
|
||
if($('#co_share_type_' + input).is(':checked')){
|
||
|
||
tpTotal = bp + tp + tep;
|
||
|
||
base_premium = bp;
|
||
third_part_premium = tp;
|
||
terrisom_premium = tep;
|
||
}
|
||
}
|
||
|
||
if (!$('#cop_yes').is(':checked')) {
|
||
$('#co_premium_' + input).val(bp);
|
||
$('#co_tp_premium_' + input).val(tp);
|
||
$('#co_ter_premium_' + input).val(tep);
|
||
$('#co_share_per_' + input).val(100);
|
||
}
|
||
|
||
console.log('tpTotal', tpTotal);
|
||
ncpaTotal = tpTotal + ncpa;
|
||
let ncpa_gst_per_amt = (ncpaTotal * gst_per) / 100;
|
||
console.log('ncpa_gst_per_amt', ncpa_gst_per_amt);
|
||
|
||
let gst_per_amt = (tpTotal * gst_per) / 100;
|
||
console.log('gst_per_amt', gst_per_amt);
|
||
|
||
// $('#gst_amount_' + input).val(gst_per_amt.toFixed(2));
|
||
if (event.target.id.startsWith('non_comm_per_amt')) {
|
||
$('#gst_amount_' + input).val(!isNaN(ncpa_gst_per_amt) && isFinite(ncpa_gst_per_amt) ? ncpa_gst_per_amt.toFixed(2) : '0.00');
|
||
}else if (event.target.id.startsWith('gst_amount')) {
|
||
$('#gst_amount_' + input).val(!isNaN(gst_amount) && isFinite(gst_amount) ? gst_amount.toFixed(2) : '0.00');
|
||
}else{
|
||
if(ncpa != 0 && ncpa != ""){
|
||
$('#gst_amount_' + input).val(!isNaN(ncpa_gst_per_amt) && isFinite(ncpa_gst_per_amt) ? ncpa_gst_per_amt.toFixed(2) : '0.00');
|
||
}else{
|
||
$('#gst_amount_' + input).val(!isNaN(gst_per_amt) && isFinite(gst_per_amt) ? gst_per_amt.toFixed(2) : '0.00');
|
||
}
|
||
}
|
||
|
||
let finalTotal = tpTotal + gst_per_amt + stamp_duty_amt;
|
||
console.log('Summed Amount:', finalTotal);
|
||
|
||
//Total Amount
|
||
$('#total_amt_' + input).val(!isNaN(finalTotal) && isFinite(finalTotal) ? finalTotal.toFixed(2) : '0.00');
|
||
|
||
//---------------------------------------------------------------------------------------------------
|
||
|
||
let sum_of_agreed_premium = agreed_bp_per + agreed_tp_per + agreed_tep_per;
|
||
// console.log('sum_of_agreed_precentage : ', sum_of_agreed_premium);
|
||
|
||
var expectedAmount = 0;
|
||
|
||
if(agreed_amount > 0 ){
|
||
expectedAmount = agreed_amount;
|
||
// console.log('Formula 1 AGREED AMOUNT');
|
||
}else if(sum_of_agreed_premium > 0){
|
||
|
||
let sumOfTheAggreedPer = agreed_bp_per + agreed_tp_per + agreed_tep_per;
|
||
|
||
let sum_of_bp_amt = (base_premium * agreed_bp_per) /100
|
||
let sum_of_tp_amt = (third_part_premium * agreed_tp_per) / 100
|
||
let sum_of_tep_amt = (terrisom_premium * agreed_tep_per) / 100
|
||
|
||
expectedAmount = (sum_of_bp_amt + sum_of_tp_amt + sum_of_tep_amt) ?? 0;
|
||
|
||
// console.log('Formula 2 AGREED BP TP/TEP %');
|
||
}else{
|
||
|
||
let sumOfTheStandardPer = standard_bp_per + standard_tp_per + standard_tep_per;
|
||
|
||
let sum_of_bp_amt = (base_premium * standard_bp_per) /100
|
||
let sum_of_tp_amt = (third_part_premium * standard_tp_per) / 100
|
||
let sum_of_tep_amt = (terrisom_premium * standard_tep_per) / 100
|
||
|
||
expectedAmount = (sum_of_bp_amt + sum_of_tp_amt + sum_of_tep_amt) ?? 0;
|
||
|
||
// console.log('Formula 3 STANDARD BP TP/TEP %');
|
||
}
|
||
|
||
console.log('expectedAmount', expectedAmount);
|
||
|
||
//Expected Amount
|
||
$('#exp_amt_' + input).val(!isNaN(expectedAmount) && isFinite(expectedAmount) ? expectedAmount.toFixed(2) : '0.00');
|
||
|
||
|
||
let actual_bp_brokerage_amount = parseFloat($('#actual_bp_brokerage_amt_' + input).val()) || 0;
|
||
let actual_tp_brokerage_amount = parseFloat($('#actual_tp_brokerage_amt_' + input).val()) || 0;
|
||
let actual_tep_brokerage_amount = parseFloat($('#actual_tep_brokerage_amt_' + input).val()) || 0;
|
||
|
||
// console.log('actual_bp_brokerage_amount', actual_bp_brokerage_amount);
|
||
// console.log('actual_tp_brokerage_amount', actual_tp_brokerage_amount);
|
||
// console.log('actual_tep_brokerage_amount', actual_tep_brokerage_amount);
|
||
|
||
|
||
// let variance = expectedAmount - (actual_bp_brokerage_amount + actual_tp_brokerage_amount + actual_tep_brokerage_amount)
|
||
let variance = (actual_bp_brokerage_amount + actual_tp_brokerage_amount + actual_tep_brokerage_amount) - expectedAmount;
|
||
// console.log('variance', variance);
|
||
|
||
// $('#variance_' + input).val(!isNaN(variance) && isFinite(variance) ? variance.toFixed(2) : '0.00');
|
||
let policy_type_id = $('#policy_type_id').val();
|
||
|
||
if(policy_type_id > 7 && name == "base_premium[]"){
|
||
// checkCDAmountForBasePremium(input);
|
||
}else{
|
||
console.log("First Skip the Ajax Call these are group policies");
|
||
}
|
||
setCoPremiums(input);
|
||
|
||
console.log('############################## END AMOUNT CALCULATION ############################################')
|
||
|
||
|
||
}
|
||
|
||
function actualAmountCalculation(input, field = null){
|
||
|
||
console.log('actualAmountCalculation function called')
|
||
console.log('actualAmountCalculation function input', input)
|
||
console.log('actualAmountCalculation function field', field)
|
||
|
||
let selectedOption = $('#policy_type_id').find('option:selected');
|
||
let bap = selectedOption.data('bap');
|
||
|
||
console.log('actualAmountCalculation function bap', bap)
|
||
|
||
let actual_bp_amt = parseFloat($('#actual_bp_amt_' + input).val()) || 0;
|
||
let actual_tp_amt = parseFloat($('#actual_tp_amt_' + input).val()) || 0;
|
||
let actual_tep_amt = parseFloat($('#actual_tep_amt_' + input).val()) || 0;
|
||
|
||
let actual_bp_per = parseFloat($('#actual_bp_per_' + input).val()) || 0;
|
||
let actual_tp_per = parseFloat($('#actual_tp_per_' + input).val()) || 0;
|
||
let actual_tep_per = parseFloat($('#actual_tep_per_' + input).val()) || 0;
|
||
|
||
let actual_bp_brokerage_amt = parseFloat($('#actual_bp_brokerage_amt_' + input).val()) || 0;
|
||
let actual_tp_brokerage_amt = parseFloat($('#actual_tp_brokerage_amt_' + input).val()) || 0;
|
||
let actual_tep_brokerage_amt = parseFloat($('#actual_tep_brokerage_amt_' + input).val()) || 0;
|
||
|
||
//------------------------------------------------------------------------------------------
|
||
|
||
if (field === 'bp_per') {
|
||
console.log()
|
||
if (actual_bp_amt > 0 && actual_bp_per >= 0) {
|
||
let actual_bp_brokerage_amount = (actual_bp_amt * actual_bp_per) / 100;
|
||
// $('#actual_bp_brokerage_amt_' + input).val(actual_bp_brokerage_amount.toFixed(2));
|
||
$('#actual_bp_brokerage_amt_' + input).val(!isNaN(actual_bp_brokerage_amount) && isFinite(actual_bp_brokerage_amount) ? actual_bp_brokerage_amount.toFixed(2) : '0.00');
|
||
|
||
}
|
||
} else if (field === 'bp_broker_amt') {
|
||
// If brokerage amount is changed, update percentage
|
||
if (actual_bp_amt > 0 && actual_bp_brokerage_amt >= 0) {
|
||
let actual_bp_percentage = (actual_bp_brokerage_amt / actual_bp_amt) * 100;
|
||
// $('#actual_bp_per_' + input).val(actual_bp_percentage.toFixed(2));
|
||
$('#actual_bp_per_' + input).val(!isNaN(actual_bp_percentage) && isFinite(actual_bp_percentage) ? actual_bp_percentage.toFixed(2) : '0.00');
|
||
|
||
}
|
||
} else if (field === 'bp_amt_for_calc') {
|
||
|
||
if(actual_bp_per > 0){
|
||
|
||
if (actual_bp_amt > 0 && actual_bp_per >= 0) {
|
||
let actual_bp_brokerage_amount = (actual_bp_amt * actual_bp_per) / 100;
|
||
// $('#actual_bp_brokerage_amt_' + input).val(actual_bp_brokerage_amount.toFixed(2));
|
||
$('#actual_bp_brokerage_amt_' + input).val(!isNaN(actual_bp_brokerage_amount) && isFinite(actual_bp_brokerage_amount) ? actual_bp_brokerage_amount.toFixed(2) : '0.00');
|
||
}
|
||
|
||
}else if(actual_bp_brokerage_amt > 0){
|
||
|
||
if (actual_bp_amt > 0 && actual_bp_brokerage_amt >= 0) {
|
||
let actual_bp_percentage = (actual_bp_brokerage_amt / actual_bp_amt) * 100;
|
||
// $('#actual_bp_per_' + input).val(actual_bp_percentage.toFixed(2));
|
||
$('#actual_bp_per_' + input).val(!isNaN(actual_bp_percentage) && isFinite(actual_bp_percentage) ? actual_bp_percentage.toFixed(2) : '0.00');
|
||
}
|
||
|
||
}else{
|
||
|
||
if (actual_bp_amt > 0 && actual_bp_per >= 0) {
|
||
let actual_bp_brokerage_amount = (actual_bp_amt * actual_bp_per) / 100;
|
||
// $('#actual_bp_brokerage_amt_' + input).val(actual_bp_brokerage_amount.toFixed(2));
|
||
$('#actual_bp_brokerage_amt_' + input).val(!isNaN(actual_bp_brokerage_amount) && isFinite(actual_bp_brokerage_amount) ? actual_bp_brokerage_amount.toFixed(2) : '0.00');
|
||
}
|
||
|
||
if (actual_bp_amt > 0 && actual_bp_brokerage_amt >= 0) {
|
||
let actual_bp_percentage = (actual_bp_brokerage_amt / actual_bp_amt) * 100;
|
||
// $('#actual_bp_per_' + input).val(actual_bp_percentage.toFixed(2));
|
||
$('#actual_bp_per_' + input).val(!isNaN(actual_bp_percentage) && isFinite(actual_bp_percentage) ? actual_bp_percentage.toFixed(2) : '0.00');
|
||
}
|
||
}
|
||
}
|
||
|
||
//-----------------------------------------------------------------------------------------
|
||
|
||
if(bap == 'Motor'){
|
||
|
||
if (field === 'tp_per') {
|
||
if (actual_tp_amt > 0 && actual_tp_per >= 0) {
|
||
let actual_tp_brokerage_amount = (actual_tp_amt * actual_tp_per) / 100;
|
||
// $('#actual_tp_brokerage_amt_' + input).val(actual_tp_brokerage_amount.toFixed(2));
|
||
$('#actual_tp_brokerage_amt_' + input).val(!isNaN(actual_tp_brokerage_amount) && isFinite(actual_tp_brokerage_amount) ? actual_tp_brokerage_amount.toFixed(2) : '0.00');
|
||
}
|
||
} else if (field === 'tp_broker_amt') {
|
||
// If brokerage amount is changed, update percentage
|
||
if (actual_tp_amt > 0 && actual_tp_brokerage_amt >= 0) {
|
||
let actual_tp_percentage = (actual_tp_brokerage_amt / actual_tp_amt) * 100;
|
||
// $('#actual_tp_per_' + input).val(actual_tp_percentage.toFixed(2));
|
||
$('#actual_tp_per_' + input).val(!isNaN(actual_tp_percentage) && isFinite(actual_tp_percentage) ? actual_tp_percentage.toFixed(2) : '0.00');
|
||
}
|
||
} else if (field === 'tp_amt_for_calc') {
|
||
|
||
if(actual_tp_amt > 0){
|
||
|
||
if (actual_tp_amt > 0 && actual_tp_per >= 0) {
|
||
let actual_tp_brokerage_amount = (actual_tp_amt * actual_tp_per) / 100;
|
||
// $('#actual_tp_brokerage_amt_' + input).val(actual_tp_brokerage_amount.toFixed(2));
|
||
$('#actual_tp_brokerage_amt_' + input).val(!isNaN(actual_tp_brokerage_amount) && isFinite(actual_tp_brokerage_amount) ? actual_tp_brokerage_amount.toFixed(2) : '0.00');
|
||
|
||
}
|
||
|
||
}else if(actual_tp_brokerage_amt > 0){
|
||
|
||
if (actual_tp_amt > 0 && actual_tp_brokerage_amt >= 0) {
|
||
let actual_tp_percentage = (actual_tp_brokerage_amt / actual_tp_amt) * 100;
|
||
// $('#actual_tp_per_' + input).val(actual_tp_percentage.toFixed(2));
|
||
$('#actual_tp_per_' + input).val(!isNaN(actual_tp_percentage) && isFinite(actual_tp_percentage) ? actual_tp_percentage.toFixed(2) : '0.00');
|
||
}
|
||
|
||
}else{
|
||
if (actual_tp_amt > 0 && actual_tp_per >= 0) {
|
||
let actual_tp_brokerage_amount = (actual_tp_amt * actual_tp_per) / 100;
|
||
// $('#actual_tp_brokerage_amt_' + input).val(actual_tp_brokerage_amount.toFixed(2));
|
||
$('#actual_tp_brokerage_amt_' + input).val(!isNaN(actual_tp_brokerage_amount) && isFinite(actual_tp_brokerage_amount) ? actual_tp_brokerage_amount.toFixed(2) : '0.00');
|
||
}
|
||
|
||
if (actual_tp_amt > 0 && actual_tp_brokerage_amt >= 0) {
|
||
let actual_tp_percentage = (actual_tp_brokerage_amt / actual_tp_amt) * 100;
|
||
// $('#actual_tp_per_' + input).val(actual_tp_percentage.toFixed(2));
|
||
$('#actual_tp_per_' + input).val(!isNaN(actual_tp_percentage) && isFinite(actual_tp_percentage) ? actual_tp_percentage.toFixed(2) : '0.00');
|
||
|
||
}
|
||
}
|
||
}
|
||
|
||
}else{
|
||
|
||
$('#actual_tp_brokerage_amt_' + input).val(0);
|
||
$('#actual_tp_per_' + input).val(0);
|
||
}
|
||
|
||
//-----------------------------------------------------------------------------------------
|
||
|
||
|
||
if(bap == 'Fire' || bap == 'Marine Cargo' || bap == 'Marine Hull'){
|
||
|
||
if (field === 'tep_per') {
|
||
if (actual_tep_amt > 0 && actual_tep_per >= 0) {
|
||
let actual_tep_brokerage_amount = (actual_tep_amt * actual_tep_per) / 100;
|
||
// $('#actual_tep_brokerage_amt_' + input).val(actual_tep_brokerage_amount.toFixed(2));
|
||
$('#actual_tep_brokerage_amt_' + input).val(!isNaN(actual_tep_brokerage_amount) && isFinite(actual_tep_brokerage_amount) ? actual_tep_brokerage_amount.toFixed(2) : '0.00');
|
||
|
||
}
|
||
} else if (field === 'tep_broker_amt') {
|
||
// If brokerage amount is changed, update percentage
|
||
if (actual_tep_amt > 0 && actual_tep_brokerage_amt >= 0) {
|
||
let actual_tep_percentage = (actual_tep_brokerage_amt / actual_tep_amt) * 100;
|
||
// $('#actual_tep_per_' + input).val(actual_tep_percentage.toFixed(2));
|
||
$('#actual_tep_per_' + input).val(!isNaN(actual_tep_percentage) && isFinite(actual_tep_percentage) ? actual_tep_percentage.toFixed(2) : '0.00');
|
||
|
||
}
|
||
} else if (field === 'tep_amt_for_calc') {
|
||
|
||
if(actual_tep_amt > 0){
|
||
|
||
if (actual_tep_amt > 0 && actual_tep_per >= 0) {
|
||
let actual_tep_brokerage_amount = (actual_tep_amt * actual_tep_per) / 100;
|
||
// $('#actual_tep_brokerage_amt_' + input).val(actual_tep_brokerage_amount.toFixed(2));
|
||
$('#actual_tep_brokerage_amt_' + input).val(!isNaN(actual_tep_brokerage_amount) && isFinite(actual_tep_brokerage_amount) ? actual_tep_brokerage_amount.toFixed(2) : '0.00');
|
||
|
||
}
|
||
|
||
}else if(actual_tep_brokerage_amt > 0){
|
||
|
||
if (actual_tep_amt > 0 && actual_tep_brokerage_amt >= 0) {
|
||
let actual_tep_percentage = (actual_tep_brokerage_amt / actual_tep_amt) * 100;
|
||
// $('#actual_tep_per_' + input).val(actual_tep_percentage.toFixed(2));
|
||
$('#actual_tep_per_' + input).val(!isNaN(actual_tep_percentage) && isFinite(actual_tep_percentage) ? actual_tep_percentage.toFixed(2) : '0.00');
|
||
}
|
||
|
||
}else{
|
||
|
||
if (actual_tep_amt > 0 && actual_tep_per >= 0) {
|
||
let actual_tep_brokerage_amount = (actual_tep_amt * actual_tep_per) / 100;
|
||
// $('#actual_tep_brokerage_amt_' + input).val(actual_tep_brokerage_amount.toFixed(2));
|
||
$('#actual_tep_brokerage_amt_' + input).val(!isNaN(actual_tep_brokerage_amount) && isFinite(actual_tep_brokerage_amount) ? actual_tep_brokerage_amount.toFixed(2) : '0.00');
|
||
}
|
||
|
||
if (actual_tep_amt > 0 && actual_tep_brokerage_amt >= 0) {
|
||
let actual_tep_percentage = (actual_tep_brokerage_amt / actual_tep_amt) * 100;
|
||
// $('#actual_tep_per_' + input).val(actual_tep_percentage.toFixed(2));
|
||
$('#actual_tep_per_' + input).val(!isNaN(actual_tep_percentage) && isFinite(actual_tep_percentage) ? actual_tep_percentage.toFixed(2) : '0.00');
|
||
|
||
}
|
||
}
|
||
|
||
}
|
||
|
||
}else{
|
||
|
||
$('#actual_tep_brokerage_amt_' + input).val(0);
|
||
$('#actual_tep_per_' + input).val(0);
|
||
}
|
||
|
||
//-----------------------------------------------------------------------------------------
|
||
|
||
let expectedAmount = parseFloat($('#exp_amt_' + input).val()) || 0;
|
||
var actual_bp_brokerage_amount2 = parseFloat($('#actual_bp_brokerage_amt_' + input).val()) || 0;
|
||
let actual_tp_brokerage_amount2 = parseFloat($('#actual_tp_brokerage_amt_' + input).val()) || 0;
|
||
let actual_tep_brokerage_amount2 = parseFloat($('#actual_tep_brokerage_amt_' + input).val()) || 0;
|
||
|
||
// let variance = expectedAmount - (actual_bp_brokerage_amount2 + actual_tp_brokerage_amount2 + actual_tep_brokerage_amount2)
|
||
let variance = (actual_bp_brokerage_amount2 + actual_tp_brokerage_amount2 + actual_tep_brokerage_amount2) - expectedAmount
|
||
|
||
// $('#variance_' + input).val(variance.toFixed(2));
|
||
$('#variance_' + input).val(!isNaN(variance) && isFinite(variance) ? variance.toFixed(2) : '0.00');
|
||
|
||
// console.log('expectedAmount', expectedAmount);
|
||
console.log('variance', variance);
|
||
}
|
||
|
||
function co_share_percentage_calculation(input, extra = null){
|
||
|
||
console.log('input', input)
|
||
var inputs = $('input[name="co_share_per[]"]'); // Specifically select input elements
|
||
console.log('Number of inputs:', inputs.length);
|
||
|
||
let insurer_count = insurer_count_array.length;
|
||
console.log('insurer_count', insurer_count);
|
||
console.log('insurer_count_array', insurer_count_array);
|
||
|
||
if(input){
|
||
if(insurer_count == 2){
|
||
|
||
// Find the index of the value
|
||
let index = insurer_count_array.indexOf(Number(input));
|
||
let second_value_index = "";
|
||
|
||
if (index !== -1) {
|
||
|
||
console.log(`Value ${input} exists at index ${index}.`);
|
||
|
||
let beforeValue = index > 0 ? insurer_count_array[index - 1] : null;
|
||
let afterValue = index < insurer_count_array.length - 1 ? insurer_count_array[index + 1] : null;
|
||
|
||
if (beforeValue != null) {
|
||
second_value_index = beforeValue;
|
||
} else if (afterValue != null) {
|
||
second_value_index = afterValue;
|
||
}
|
||
|
||
}
|
||
|
||
let value1 = $('#co_share_per_' + input).val();
|
||
let value2 = $('#co_share_per_' + second_value_index).val();
|
||
|
||
value1 = Number(value1);
|
||
value2 = Number(value2);
|
||
|
||
console.log('value1', value1);
|
||
console.log('value2', value2);
|
||
|
||
if(extra == "add"){
|
||
|
||
if(value2 == 0){
|
||
value1 = 50;
|
||
value2 = 50;
|
||
}else{
|
||
if(value2 == 100){
|
||
value1 = 50;
|
||
value2 = 50;
|
||
}else{
|
||
value1 = 100 - value2;
|
||
}
|
||
}
|
||
|
||
}else{
|
||
|
||
if(value1 == 100){
|
||
value2 = 0;
|
||
}else{
|
||
value2 = 100 - value1;
|
||
}
|
||
}
|
||
|
||
console.log('value1', value1);
|
||
console.log('value2', value2);
|
||
|
||
$('#co_share_per_' + input).val(value1);
|
||
$('#co_share_per_' + second_value_index).val(value2);
|
||
|
||
}else if(insurer_count > 2){
|
||
|
||
let total_val = 0;
|
||
|
||
// Calculate the total sum of input values
|
||
inputs.each(function () {
|
||
let val = Number($(this).val()) || 0;
|
||
if(val == 0){
|
||
$(this).val(0)
|
||
}
|
||
total_val += val;
|
||
});
|
||
|
||
// if (total_val < 100) {
|
||
// let remaining_val = 100 - total_val; // Calculate the remaining value
|
||
|
||
// // Assign the remaining value to the first empty input
|
||
// let assigned = false;
|
||
// inputs.each(function () {
|
||
// let current_val = Number($(this).val()) || 0;
|
||
// if (current_val === 0 && !assigned) { // Assign only once
|
||
// $(this).val(remaining_val);
|
||
// assigned = true;
|
||
// } else if (current_val === 0) {
|
||
// $(this).val(0); // Set other empty inputs to 0
|
||
// }
|
||
// });
|
||
// } else if (total_val > 100) {
|
||
// toastr.warning('Sum of the co-share is greater than 100');
|
||
// }
|
||
|
||
}
|
||
}else{
|
||
inputs.each(function (index) {
|
||
if (inputs.length === 1) {
|
||
$(this).val(100);
|
||
} else if(inputs.length === 2) {
|
||
let first = $('#co_share_per_1').val();
|
||
first = Number(first)
|
||
let second_val = 100 - first;
|
||
|
||
if (index === 1) {
|
||
$(this).val(second_val);
|
||
}
|
||
}
|
||
});
|
||
|
||
}
|
||
|
||
let val_sum = 0;
|
||
|
||
inputs.each(function () {
|
||
let val = Number($(this).val()) || 0;
|
||
val_sum += val;
|
||
});
|
||
|
||
if (val_sum > 100) {
|
||
toastr.warning('Sum of the co-share is greater than 100', 'Warning');
|
||
}
|
||
|
||
// // Find the empty input(s)
|
||
// var emptyInputs = inputs.filter(function() {
|
||
// return $(this).val().trim() === ''; // Check for empty values
|
||
// });
|
||
|
||
// // Get the number of empty inputs
|
||
// var emptyCount = emptyInputs.length;
|
||
// console.log('Number of empty inputs:', emptyCount);
|
||
|
||
// // If there's exactly one empty input, calculate and set its value
|
||
// if (emptyCount === 1) {
|
||
|
||
// // Calculate the sum of filled values
|
||
// let sumFilled = 0;
|
||
// inputs.each(function() {
|
||
// var val = parseFloat($(this).val()) || 0;
|
||
// sumFilled += val;
|
||
// });
|
||
|
||
// // Calculate the balance percentage
|
||
// let balance_per = 100 - sumFilled;
|
||
// console.log('Balance percentage:', balance_per);
|
||
|
||
// // Set the balance value to the empty input
|
||
// emptyInputs.val(balance_per);
|
||
// }
|
||
|
||
}
|
||
|
||
$(document).on('change', '[name="base_premium[]"], [name="co_share_per[]"]', function() {
|
||
|
||
console.log('Triggered change event.');
|
||
|
||
// Get the first non-empty base premium value
|
||
let basePremium = $('input[name="base_premium[]"]').toArray()
|
||
.map(input => parseFloat($(input).val()) || 0)
|
||
.find(value => value > 0) || 0;
|
||
|
||
console.log('Base Premium:', basePremium);
|
||
|
||
// Loop through all co_share_per[] fields
|
||
$('input[name="co_share_per[]"]').each(function(index) {
|
||
|
||
const coSharePer = parseFloat($(this).val()) || 0; // Get co_share_per value
|
||
const coPremium = (basePremium * coSharePer) / 100; // Calculate co_premium
|
||
|
||
console.log(`Index: ${index}, Co-Share Percentage: ${coSharePer}, Co-Premium: ${coPremium}`);
|
||
|
||
// Update corresponding co_premium field
|
||
$('input[name="co_premium[]"]').eq(index).val(coPremium.toFixed(2));
|
||
});
|
||
});
|
||
|
||
$(document).on('change', '[name="tp_premium[]"], [name="co_share_per[]"]', function() {
|
||
|
||
console.log('Triggered change event.');
|
||
|
||
// Get the first non-empty base premium value
|
||
let tpPremium = $('input[name="tp_premium[]"]').toArray()
|
||
.map(input => parseFloat($(input).val()) || 0)
|
||
.find(value => value > 0) || 0;
|
||
|
||
console.log('TP Premium:', tpPremium);
|
||
|
||
// Loop through all co_share_per[] fields
|
||
$('input[name="co_share_per[]"]').each(function(index) {
|
||
|
||
const coSharePer = parseFloat($(this).val()) || 0; // Get co_share_per value
|
||
const coPremium = (tpPremium * coSharePer) / 100; // Calculate co_premium
|
||
|
||
console.log(`Index: ${index}, Co-Share Percentage: ${coSharePer}, Co-TP-Premium: ${coPremium}`);
|
||
|
||
// Update corresponding co_premium field
|
||
$('input[name="co_tp_premium[]"]').eq(index).val(coPremium.toFixed(2));
|
||
});
|
||
});
|
||
|
||
$(document).on('change', '[name="ter_premium[]"], [name="co_share_per[]"]', function() {
|
||
|
||
console.log('Triggered change event.');
|
||
|
||
// Get the first non-empty base premium value
|
||
let terPremium = $('input[name="ter_premium[]"]').toArray()
|
||
.map(input => parseFloat($(input).val()) || 0)
|
||
.find(value => value > 0) || 0;
|
||
|
||
console.log('TEP Premium:', terPremium);
|
||
|
||
// Loop through all co_share_per[] fields
|
||
$('input[name="co_share_per[]"]').each(function(index) {
|
||
|
||
const coSharePer = parseFloat($(this).val()) || 0; // Get co_share_per value
|
||
const coPremium = (terPremium * coSharePer) / 100; // Calculate co_premium
|
||
|
||
console.log(`Index: ${index}, Co-Share Percentage: ${coSharePer}, Co-TEP-Premium: ${coPremium}`);
|
||
|
||
// Update corresponding co_premium field
|
||
$('input[name="co_ter_premium[]"]').eq(index).val(coPremium.toFixed(2));
|
||
});
|
||
});
|
||
|
||
function setCoPremiums(input) {
|
||
|
||
let bp = $('input[name="base_premium[]"]').toArray()
|
||
.map(input => parseFloat($(input).val()) || 0)
|
||
.find(value => value > 0) || 0;
|
||
let tp = $('input[name="tp_premium[]"]').toArray()
|
||
.map(input => parseFloat($(input).val()) || 0)
|
||
.find(value => value > 0) || 0;
|
||
let tep = $('input[name="ter_premium[]"]').toArray()
|
||
.map(input => parseFloat($(input).val()) || 0)
|
||
.find(value => value > 0) || 0;
|
||
|
||
// let bp = parseFloat($('#base_premium_' + input).val()) || 0;
|
||
// let tp = parseFloat($('#tp_premium_' + input).val()) || 0;
|
||
// let tep = parseFloat($('#ter_premium_' + input).val()) || 0;
|
||
let coSharePer = parseFloat($('#co_share_per_' + input).val()) || 0;
|
||
|
||
let cop = (bp * coSharePer) / 100;
|
||
let cotp = (tp * coSharePer) / 100;
|
||
let cotep = (tep * coSharePer) / 100;
|
||
|
||
// Log all values to console
|
||
console.log(`Input: ${input}`);
|
||
console.log(`Base Premium (bp): ${bp}`);
|
||
console.log(`TP Premium (tp): ${tp}`);
|
||
console.log(`TEP Premium (tep): ${tep}`);
|
||
console.log(`Co-Share Percentage (coSharePer): ${coSharePer}`);
|
||
console.log(`Co Premium (cop): ${cop.toFixed(2)}`);
|
||
console.log(`Co TP Premium (cotp): ${cotp.toFixed(2)}`);
|
||
console.log(`Co TEP Premium (cotep): ${cotep.toFixed(2)}`);
|
||
|
||
$('#co_premium_' + input).val(cop.toFixed(2));
|
||
$('#co_tp_premium_' + input).val(cotp.toFixed(2));
|
||
$('#co_ter_premium_' + input).val(cotep.toFixed(2));
|
||
}
|
||
|
||
function select_leader_disable_premium_amt(input, value) {
|
||
|
||
if ($(input).is(':checked')) {
|
||
// Disable and add readonly-select class to all premiums except the one with the given value
|
||
$('input[name="base_premium[]"]').addClass('readonly-select');
|
||
$('#base_premium_' + value).removeClass('readonly-select');
|
||
|
||
$('input[name="tp_premium[]"]').addClass('readonly-select');
|
||
$('#tp_premium_' + value).removeClass('readonly-select');
|
||
|
||
$('input[name="ter_premium[]"]').addClass('readonly-select');
|
||
$('#ter_premium_' + value).removeClass('readonly-select');
|
||
|
||
$('input[name="stamp_duty[]"]').addClass('readonly-select');
|
||
$('#stamp_duty_' + value).removeClass('readonly-select');
|
||
|
||
$('input[name="co_premium[]"]').addClass('readonly-select');
|
||
$('#co_premium_' + value).removeClass('readonly-select');
|
||
|
||
$('input[name="co_tp_premium[]"]').addClass('readonly-select');
|
||
$('#co_tp_premium_' + value).removeClass('readonly-select');
|
||
|
||
$('input[name="co_ter_premium[]"]').addClass('readonly-select');
|
||
$('#co_ter_premium_' + value).removeClass('readonly-select');
|
||
|
||
} else {
|
||
// Enable and remove readonly-select class from all premiums except the one with the given value
|
||
$('input[name="base_premium[]"]').removeClass('readonly-select');
|
||
$('input[name="tp_premium[]"]').removeClass('readonly-select');
|
||
$('input[name="ter_premium[]"]').removeClass('readonly-select');
|
||
$('input[name="stamp_duty[]"]').removeClass('readonly-select');
|
||
$('input[name="co_premium[]"]').removeClass('readonly-select');
|
||
$('input[name="co_tp_premium[]"]').removeClass('readonly-select');
|
||
$('input[name="co_ter_premium[]"]').removeClass('readonly-select');
|
||
|
||
}
|
||
}
|
||
|
||
function select_leader_disable_premium_amt_in_edit() {
|
||
|
||
$('#insurerTable thead th').each(function(value) {
|
||
|
||
if (value === 0) {
|
||
console.log("Premium Table columnIndexes is", value);
|
||
} else {
|
||
|
||
if ($('#co_share_type_' + value).is(':checked')) {
|
||
// Disable and add readonly-select class to all premiums except the one with the given value
|
||
$('input[name="base_premium[]"]').addClass('readonly-select');
|
||
$('#base_premium_' + value).removeClass('readonly-select');
|
||
|
||
$('input[name="tp_premium[]"]').addClass('readonly-select');
|
||
$('#tp_premium_' + value).removeClass('readonly-select');
|
||
|
||
$('input[name="ter_premium[]"]').addClass('readonly-select');
|
||
$('#ter_premium_' + value).removeClass('readonly-select');
|
||
|
||
$('input[name="stamp_duty[]"]').addClass('readonly-select');
|
||
$('#stamp_duty_' + value).removeClass('readonly-select');
|
||
|
||
$('input[name="co_premium[]"]').addClass('readonly-select');
|
||
$('#co_premium_' + value).removeClass('readonly-select');
|
||
|
||
$('input[name="co_tp_premium[]"]').addClass('readonly-select');
|
||
$('#co_tp_premium_' + value).removeClass('readonly-select');
|
||
|
||
$('input[name="co_ter_premium[]"]').addClass('readonly-select');
|
||
$('#co_ter_premium_' + value).removeClass('readonly-select');
|
||
|
||
$('[name="cd_ac_no_for_child[]"]').hide();
|
||
$('[id^="cd_current_balance_"]').hide();
|
||
|
||
// Show only current one
|
||
$('#cd_ac_no_' + value).show();
|
||
$('#cd_current_balance_' + value).show();
|
||
|
||
// $('input[name="cd_ac_no_for_child[]"]').addClass('readonly-select');
|
||
// $('#cd_ac_no_' + value).removeClass('readonly-select');
|
||
}
|
||
}
|
||
});
|
||
}
|
||
|
||
function validateRange(input) {
|
||
// if (input.value < 1) input.value = 1;
|
||
if (input.value > 100) input.value = 100;
|
||
}
|
||
|
||
function setRenewalPolicyData(input) {
|
||
|
||
var selectedOption = $(input).find('option:selected');
|
||
|
||
var policy_no = selectedOption.data('policy');
|
||
var insurer = selectedOption.data('insurer');
|
||
var insurer_branch_id = selectedOption.data('ib');
|
||
var tpa = selectedOption.data('tpa');
|
||
var tpa_branch_id = selectedOption.data('tpab');
|
||
var cd_ac_no = selectedOption.data('cd');
|
||
var policy_start_date = selectedOption.data('ps');
|
||
var policy_end_date = selectedOption.data('pe');
|
||
|
||
// console.log('policy_no', policy_no);
|
||
// console.log('insurer', insurer);
|
||
// console.log('cd_ac_no', cd_ac_no);
|
||
// console.log('insurer_branch_id', insurer_branch_id);
|
||
|
||
$('#renewal_policy_start_date').val(policy_start_date);
|
||
$('#renewal_policy_end_date').val(policy_end_date);
|
||
|
||
}
|
||
|
||
function appendInsured(data = null) {
|
||
const container = document.getElementById('dynamic-form-container-for-insured');
|
||
// console.log(container);
|
||
const newRow = document.createElement('div');
|
||
newRow.className = 'form-row insured-dynamic-form-row';
|
||
newRow.innerHTML = `
|
||
<input type="hidden" id="emp_id" name="emp_id[]">
|
||
<input type="hidden" id="emp_policy_id" name="emp_policy_id[]">
|
||
<div class="form-group col-md-5">
|
||
<label for="file_name">Name<span class="text-danger"></span></label>
|
||
<input type="text" class="form-control" id="name" name="family_name[]" placeholder="Enter Name" required>
|
||
</div>
|
||
|
||
<div class="form-group col-md-5">
|
||
<label for="relationship">Relationship<span class="text-danger"></span></label>
|
||
<select class="form-control" id="relationship" name="relationship[]" required>
|
||
<option value="" disabled selected>Select Relationship</option>
|
||
<option value="Father">Father</option>
|
||
<option value="Mother">Mother</option>
|
||
<option value="Son">Son</option>
|
||
<option value="Daughter">Daughter</option>
|
||
<option value="Father in law">Father-in-law</option>
|
||
<option value="Mother in law">Mother-in-law</option>
|
||
<option value="Spouse">Spouse</option>
|
||
</select>
|
||
</div>
|
||
|
||
|
||
<div class="form-group col-md-2" style="position: relative;top: 28px;">
|
||
<a class="btn btn-danger waves-effect waves-light" onclick="removeRemoveInsured(this)">x</a>
|
||
<a class="btn btn-primary waves-effect waves-light mr-1" onclick="appendInsured(this)">+</a>
|
||
</div>
|
||
`;
|
||
container.appendChild(newRow);
|
||
|
||
if (data !== null && data.db_column_name !== undefined) {
|
||
const selectElement = newRow.querySelector('.db-column-name-select');
|
||
selectElement.value = data.db_column_name;
|
||
}
|
||
|
||
if (data !== null) {
|
||
if (data.name) {
|
||
newRow.querySelector('#name').value = data.name;
|
||
}
|
||
if (data.relationship) {
|
||
newRow.querySelector('#relationship').value = data.relationship;
|
||
}
|
||
if (data.id) {
|
||
newRow.querySelector('#emp_id').value = data.id;
|
||
}
|
||
}
|
||
}
|
||
|
||
function removeRemoveInsured(element) {
|
||
const container = document.getElementById('dynamic-form-container');
|
||
const rows = container.querySelectorAll('.insured-dynamic-form-row');
|
||
|
||
if (rows.length > 1) {
|
||
const row = element.closest('.insured-dynamic-form-row');
|
||
row.remove();
|
||
}
|
||
}
|
||
|
||
function appendOwner(data) {
|
||
|
||
$('#owner').empty();
|
||
|
||
$('#owner').append($('<option>', {
|
||
value: '',
|
||
text: 'Select Owner'
|
||
}));
|
||
|
||
// $('#owner').append(
|
||
// $('<option>', {
|
||
// value: 'add_client',
|
||
// text: ' + Add Owner',
|
||
// })
|
||
// );
|
||
|
||
$.each(data, function(index, item) {
|
||
|
||
let client_show_name = item.client_name;
|
||
if (item.client_type == 2) {
|
||
client_show_name = item.client_name + ' - ' + (item.dob ?? 'N/A');
|
||
}
|
||
|
||
var option = $('<option>', {
|
||
value: item.id,
|
||
text: client_show_name,
|
||
});
|
||
|
||
$('#owner').append(option);
|
||
});
|
||
|
||
}
|
||
|
||
function appendOwnerBranch(data) {
|
||
|
||
$('#owner_branch').empty();
|
||
|
||
$('#owner_branch').append($('<option>', {
|
||
value: '',
|
||
text: 'Select Branch'
|
||
}));
|
||
|
||
$.each(data, function(index, item) {
|
||
|
||
var option = $('<option>', {
|
||
value: item.id,
|
||
text: item.branch_name
|
||
});
|
||
$('#owner_branch').append(option);
|
||
});
|
||
}
|
||
|
||
function selectListedInsurers(listedInsurers) {
|
||
listedInsurers = JSON.parse(listedInsurers);
|
||
// Loop through each insurer-branch combination
|
||
$.each(listedInsurers, function(index, value) {
|
||
// Use value in the format 'branch_id-insurer_id'
|
||
$('#listed_insurers option').each(function() {
|
||
if ($(this).val() === value) {
|
||
$(this).prop('selected', true); // Select the matching option
|
||
}
|
||
});
|
||
});
|
||
// Trigger change for plugins (like Select2)
|
||
$('#listed_insurers').trigger('change');
|
||
}
|
||
|
||
function checkInvoiceStatusToHideSubmitBtn(id){
|
||
|
||
$.ajax({
|
||
url: '<?php echo base_url('util/checkInvoiceStatus/');?>'+ id,
|
||
type: "GET",
|
||
dataType: 'json',
|
||
success: function (res) {
|
||
|
||
console.log('checkInvoiceStatusToHideSubmitBtn response', res)
|
||
|
||
if(res.status == true){
|
||
if(res.count > 0){
|
||
$('#submitButton').hide()
|
||
}else{
|
||
$('#submitButton').show()
|
||
}
|
||
}else{
|
||
console.log(res.message, 'warning');
|
||
}
|
||
},
|
||
error: function (xhr, status, error) {
|
||
console.error(xhr.responseText);
|
||
console.error(status, error);
|
||
}
|
||
});
|
||
|
||
}
|
||
|
||
function getCDAccountNumber(input)
|
||
{
|
||
console.log('##########################################')
|
||
console.log('getCDAccountNumber')
|
||
console.log('##########################################')
|
||
|
||
|
||
// var client_id = $('#client_id').val()
|
||
// var insurer_id = $('#insurer_id').find('option:selected').attr('data-id');
|
||
|
||
// var client_id = $('#client_id').val()
|
||
// var insurer_id = $(this).val();
|
||
|
||
let insurer = $(input).val();
|
||
let unique_id = $(input).data('count');
|
||
let client_id = $('#client_id').val();
|
||
let client_type = $('#client_type').val();
|
||
let policy_type_id = $('#policy_type_id').val();
|
||
let insurer_id = $(input).find('option:selected').attr('data-id');
|
||
let insurer_branch_id = $(input).find('option:selected').attr('data-bid');
|
||
|
||
console.log('insurer', insurer);
|
||
console.log('follow_insurer_id client_id', client_id);
|
||
console.log('follow_insurer_id insurer_id', insurer_id);
|
||
console.log('follow_insurer_id insurer_branch_id', insurer_branch_id);
|
||
console.log('follow_insurer_id unique_id', unique_id);
|
||
|
||
if(client_id && insurer_id){
|
||
if(client_type == 1 && policy_type_id > 7){
|
||
$.ajax({
|
||
url: '<?= base_url("/util/getCDAccNoByClientAndInsurer/") ?>' + client_id + '/' + insurer_id + '/' + insurer_branch_id,
|
||
type: "GET",
|
||
dataType: 'json',
|
||
success: function(res) {
|
||
|
||
console.log('cd_res', res);
|
||
if(res.status == true){
|
||
// appendCDAccountNumber(res.data[0].cd_ac_no, unique_id)
|
||
appendCDAccountNumber(res.data, unique_id)
|
||
// if(res.data[0].id){
|
||
// $('#cd_ac_pk_for_leader').val(res.data[0].id)
|
||
// }
|
||
}else{
|
||
var pt_id = $('#policy_tranction_primarykey').val();
|
||
if(pt_id == ''){
|
||
toastr.warning('The insurer does not has a CD account number');
|
||
}
|
||
console.log('The insurer does not has a CD account number');
|
||
|
||
$('#cd_ac_no_'+unique_id).empty();
|
||
$('#cd_ac_no_'+unique_id).append($('<option>', {
|
||
value: '',
|
||
text: 'Select CD No',
|
||
}));
|
||
$('#cd_ac_no_'+unique_id).append($('<option>', {
|
||
value: 'add_cd',
|
||
text: '+ Add CD'
|
||
}));
|
||
}
|
||
|
||
},
|
||
error: function(xhr, status, error) {
|
||
console.error(xhr.responseText);
|
||
console.error(status, error);
|
||
}
|
||
});
|
||
}else{
|
||
console.error('Client type Not found')
|
||
console.log('client_type', client_type);
|
||
}
|
||
}else{
|
||
console.error('Client ID or Insurer ID Not found')
|
||
console.log('client_id', client_id);
|
||
console.log('insurer_id', insurer_id);
|
||
}
|
||
}
|
||
|
||
function appendCDAccountNumber(data, unique_id, new_cd_ac_no = null)
|
||
{
|
||
console.log('appendCDAccountNumber', data);
|
||
|
||
$('#cd_ac_no_'+unique_id).empty();
|
||
|
||
$('#cd_ac_no_'+unique_id).append($('<option>', {
|
||
value: '',
|
||
text: 'Select CD No',
|
||
}));
|
||
|
||
if(data.length == 0){
|
||
$('#cd_ac_no_'+unique_id).append($('<option>', {
|
||
value: 'add_cd',
|
||
text: '+ Add CD'
|
||
}));
|
||
}
|
||
|
||
$.each(data, function(index, item) {
|
||
var option = $('<option>', {
|
||
value: item.id,
|
||
text: item.cd_ac_no,
|
||
});
|
||
if (new_cd_ac_no == item.id) {
|
||
option.attr('selected', true);
|
||
}
|
||
$('#cd_ac_no_'+unique_id).append(option);
|
||
});
|
||
}
|
||
|
||
function addCDAccountNumber(input)
|
||
{
|
||
var val = $(input).val();
|
||
var uniqueid = $(input).data('count');
|
||
$('#premium_details_unique_id').val(uniqueid);
|
||
var client_id = $('#client_id').val();
|
||
let insurer_id = $('#follow_insurer_id_'+uniqueid).val();
|
||
let leader = $('#co_share_type_' + uniqueid).is(':checked');
|
||
let isAnyLeaderChecked = $('input[type="checkbox"][name="co_share_type[]"]:checked').length == 0;
|
||
let cop_yes = $('#cop_yes').is(':checked');
|
||
|
||
|
||
console.log('addCDAccountNumber', 'addCDAccountNumber');
|
||
console.log('client_id', client_id);
|
||
console.log('insurer_id', insurer_id);
|
||
console.log('leader', leader);
|
||
|
||
|
||
if(client_id == '' || insurer_id == ''){
|
||
toastr.warning('Client, Insurer, or both do not exist.', 'Warning!');
|
||
$(input).val('')
|
||
return false;
|
||
}
|
||
|
||
if (isAnyLeaderChecked) {
|
||
if(cop_yes){
|
||
$('#cd_ac_no_'+uniqueid).val('');
|
||
toastr.warning('Please select the Leader.', 'Warning!');
|
||
return false;
|
||
}
|
||
}
|
||
|
||
if(!leader){
|
||
if(cop_yes){
|
||
$('#cd_ac_no_'+uniqueid).val('');
|
||
toastr.warning('The CD account number not for the Leader.', 'Warning!');
|
||
return false;
|
||
}
|
||
}
|
||
|
||
if(val == 'add_cd')
|
||
{
|
||
var myModal = new bootstrap.Modal(document.getElementById('cd_form_modal'));
|
||
myModal.show();
|
||
$(input).val('')
|
||
}else{
|
||
console.log('cd_ac_pk', val)
|
||
$('#cd_ac_pk_for_leader').val(val)
|
||
getCdAmount(val, uniqueid);
|
||
}
|
||
}
|
||
|
||
function restrictCDACNO(currentSelect){
|
||
|
||
const selectedValue = $(currentSelect).val();
|
||
|
||
// if (selectedValue) {
|
||
// $('.follow_insurer_cd').not(currentSelect).prop('disabled', true);
|
||
// } else {
|
||
// $('.follow_insurer_cd').prop('disabled', false);
|
||
// }
|
||
}
|
||
|
||
function removeAllColumnsExceptFirst(tableId) {
|
||
|
||
console.log('######################################')
|
||
console.log('removeAllColumnsExceptFirst function called');
|
||
console.log('######################################');
|
||
|
||
// Remove all headers except the first one
|
||
$('#' + tableId + ' thead tr th').each(function(index) {
|
||
if (index > 0) { // Keep the first column (index 0)
|
||
$(this).remove();
|
||
}
|
||
});
|
||
|
||
// Remove corresponding data cells in each row except the first one
|
||
$('#' + tableId + ' tbody tr').each(function() {
|
||
$(this).find('td').each(function(index) {
|
||
if (index > 0) { // Keep the first column (index 0)
|
||
$(this).remove();
|
||
}
|
||
});
|
||
});
|
||
|
||
insurerCount = 0;
|
||
}
|
||
|
||
//---------------------------------------------------------------------------------------------------------
|
||
|
||
function convertToMySQLDate(dateString) {
|
||
|
||
// console.log('convertToMySQLDate' + dateString);
|
||
if(dateString !== "" && dateString !== undefined)
|
||
{
|
||
// Split the input date string by '/'
|
||
const [day, month, year] = dateString.split('/');
|
||
|
||
// Return the date in MySQL format: YYYY-MM-DD
|
||
return `${year}-${month}-${day}`;
|
||
}
|
||
return '';
|
||
}
|
||
|
||
function convertMonthYearToMySQLDate(dateString) {
|
||
console.log('convertMonthYearToMySQLDate: ' + dateString);
|
||
|
||
if(dateString !== "" && dateString !== undefined) {
|
||
// Map month abbreviations to their respective numbers
|
||
const months = {
|
||
'jan': '01', 'feb': '02', 'mar': '03', 'apr': '04',
|
||
'may': '05', 'jun': '06', 'jul': '07', 'aug': '08',
|
||
'sep': '09', 'oct': '10', 'nov': '11', 'dec': '12'
|
||
};
|
||
|
||
// Split the input string by '/'
|
||
const parts = dateString.toLowerCase().split('/');
|
||
const month = months[parts[0]]; // Convert the month abbreviation to its numeric form
|
||
const year = parts[1]; // Year remains unchanged
|
||
|
||
// Format the date as YYYY-MM-DD
|
||
if (month && year) {
|
||
return `${year}-${month}-01`;
|
||
}
|
||
}
|
||
|
||
return '';
|
||
}
|
||
|
||
$("#inception_form_id").submit(function(event) {
|
||
|
||
if (!this.checkValidity()) { return; }
|
||
event.preventDefault();
|
||
|
||
let policy_type_id = $('#policy_type_id').val();
|
||
var isValid = $('#inception_form_id').parsley().validate();
|
||
var client_type_id = $('#client_type').val();
|
||
var policy_status = $('#policy_status').val();
|
||
var pt_form_sumbit_handler = $('#pt_form_sumbit_handler').val();
|
||
|
||
if (!isValid) {
|
||
$('#inception_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;
|
||
}
|
||
|
||
let hasEmptyInsurer = false;
|
||
let firstEmptyField = null;
|
||
|
||
// $('select[name="follow_insurer_id[]"]').each(function() {
|
||
// const $field = $(this);
|
||
// const errorId = 'error-' + $field.attr('id');
|
||
|
||
// // Remove any old message
|
||
// $('#' + errorId).remove();
|
||
|
||
// if ($field.val().trim() === "") {
|
||
// hasEmptyInsurer = true;
|
||
// $field.addClass('is-invalid');
|
||
|
||
// // Add error message only once
|
||
// if (!$field.next('.text-danger').length) {
|
||
// $field.after(`<small id="${errorId}" class="text-danger">This value is required.</small>`);
|
||
// }
|
||
|
||
// if (!firstEmptyField) {
|
||
// firstEmptyField = this; // store first empty field
|
||
// }
|
||
// } else {
|
||
// $field.removeClass('is-invalid');
|
||
// $('#' + errorId).remove(); // remove if filled
|
||
// }
|
||
// });
|
||
$('select[name="follow_insurer_id[]"]').each(function() {
|
||
if ($(this).val().trim() === "") {
|
||
hasEmptyInsurer = true;
|
||
$(this).addClass('is-invalid');
|
||
if (!firstEmptyField) {
|
||
firstEmptyField = this; // store the first invalid field
|
||
}
|
||
} else {
|
||
$(this).removeClass('is-invalid');
|
||
}
|
||
});
|
||
|
||
if (hasEmptyInsurer) {
|
||
if (firstEmptyField) {
|
||
$(firstEmptyField).focus();
|
||
}
|
||
toastr.warning('Please select all Insurers before submitting', 'Warning');
|
||
return;
|
||
}
|
||
|
||
if(pt_form_sumbit_handler == 0){
|
||
toastr.warning('Base premium greater than CD Amount', 'Warning');
|
||
return;
|
||
}
|
||
|
||
if(client_type_id == 1 && policy_status == 'completed' && policy_type_id > 7){
|
||
|
||
let isAnyDropdownSelected = $('select[name="cd_ac_no_for_child[]"]').filter(function() {
|
||
return $(this).val() !== "";
|
||
}).length > 0;
|
||
|
||
console.log('isAnyDropdownSelected', isAnyDropdownSelected);
|
||
|
||
if(!isAnyDropdownSelected){
|
||
toastr.warning('CD account number is Empty', 'Warning');
|
||
return;
|
||
}
|
||
}
|
||
|
||
let co_share_type = []; // Initialize an object to mimic the array structure
|
||
|
||
$('[name="co_share_type[]"]').each(function(index) {
|
||
let value = $(this).is(':checked');
|
||
if(value){
|
||
co_share_type.push(1); // Assign value with index as key
|
||
}else{
|
||
co_share_type.push(2); // Assign value with index as key
|
||
}
|
||
});
|
||
|
||
// console.log(co_share_type);
|
||
|
||
|
||
|
||
var shortListedInsurer = $("#listed_insurers").val();
|
||
// console.log('shortListedInsurer : ', shortListedInsurer);
|
||
|
||
|
||
form_action = '<?= base_url('policy_tranction/inception/create') ?>';
|
||
|
||
$('.loader').fadeIn();
|
||
$('.loader-mask').fadeIn();
|
||
|
||
var formData = new FormData($('#inception_form_id')[0]);
|
||
|
||
const jsonString = JSON.stringify(shortListedInsurer);
|
||
// console.log('jsonString', jsonString);
|
||
|
||
// Append the JSON string to the FormData object
|
||
formData.append('listed_insurers', jsonString);
|
||
co_share_type.forEach((value, index) => {
|
||
formData.append(`co_share_type[${index}]`, value);
|
||
});
|
||
//covert date to mysql format
|
||
// alert(formData.get('policy_issue_date'));
|
||
|
||
formData.set('policy_issue_date',convertToMySQLDate(formData.get('policy_issue_date')));
|
||
formData.set('policy_start_date',convertToMySQLDate(formData.get('policy_start_date')));
|
||
formData.set('policy_end_date',convertToMySQLDate(formData.get('policy_end_date')));
|
||
formData.set('renewal_date',convertToMySQLDate(formData.get('renewal_date')));
|
||
formData.set('rollover_date',convertToMySQLDate(formData.get('rollover_date')));
|
||
// formData.set('last_action_date',convertToMySQLDate(formData.get('last_action_date')));
|
||
formData.set('month',convertMonthYearToMySQLDate(formData.get('month')));
|
||
|
||
// formData['policy_start_date'] = convertToMySQLDate(formData['policy_start_date']);
|
||
// formData['policy_end_date'] = convertToMySQLDate(formData['policy_end_date']);
|
||
// formData['renewal_date'] = convertToMySQLDate(formData['renewal_date']);
|
||
// formData['rollover_date'] = convertToMySQLDate(formData['rollover_date']);
|
||
// formData['month'] = convertMonthYearToMySQLDate(formData['month']);
|
||
// console.log(formData);
|
||
// return false;
|
||
$.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');
|
||
|
||
show_list_hide_add();
|
||
window.location.href = redirect_url;
|
||
|
||
|
||
$('#policy_tranction_primarykey').val(res.pt_id);
|
||
$('#client_id_kyc').val(res.data.client_id);
|
||
$('#policy_tranction_primarykey_for_file_upload').val(res.pt_id);
|
||
$('#client_policy_id_for_file_upload').val(res.data.client_policy_id);
|
||
|
||
//if(res.data.client_policy_id != 0 && res.data.client_policy_id != null){
|
||
// $('#hide_file_upload').show();
|
||
//}else{
|
||
// $('#hide_file_upload').hide();
|
||
//}
|
||
$('#client_id_for_vehicle_file_upload').val(res.data.client_id);
|
||
$('#vehicle_id_for_file_upload').val(res.data.vehicle_id);
|
||
|
||
// getKYCEntityDocument(res.data.entity_type_id, res.data.client_id);
|
||
// appendKycTableListData(res.data.client_kyc);
|
||
|
||
$('#tbody').empty();
|
||
$('#tbody').append(res.data.client_kyc_primary_table);
|
||
|
||
$('#other_docs').empty();
|
||
$('#other_docs').append(res.data.client_kyc_other_table);
|
||
|
||
//setTimeout(function(){
|
||
//}, 1000)
|
||
|
||
if (res.data.pt_co_share_details && res.data.pt_co_share_details.length > 0) {
|
||
|
||
$('#tab_content').empty()
|
||
count = 0
|
||
$.each(res.data.pt_co_share_details, function(index, item) {
|
||
// appendNewTab(item);
|
||
});
|
||
}
|
||
|
||
} else {
|
||
toastr.error(res.message, 'Error');
|
||
}
|
||
|
||
// $('#kyc_tab2').click();
|
||
// $('#kyc_tab').click();
|
||
// $('#g_drive_file_upload_sbt_btn').show()
|
||
|
||
},
|
||
error: function(xhr, status, error) {
|
||
console.error(xhr.responseText);
|
||
console.error(status, error);
|
||
$('.loader').fadeOut();
|
||
$('.loader-mask').delay(350).fadeOut('slow');
|
||
}
|
||
});
|
||
});
|
||
|
||
$("#vehicle_form").submit(function(event) {
|
||
|
||
event.preventDefault();
|
||
|
||
var isValid = $('#vehicle_form').parsley().validate();
|
||
if (!isValid) {
|
||
console.log('Form is Empty', 'Warning');
|
||
return ;
|
||
}
|
||
|
||
isVehicleFormSubmitting = true;
|
||
|
||
form_action = '<?= base_url("util/createVehicleWithMinimalDataForBDS"); ?>';
|
||
|
||
$('.loader').fadeIn();
|
||
$('.loader-mask').fadeIn();
|
||
|
||
var formData = new FormData($('#vehicle_form')[0]);
|
||
|
||
$.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('create Vehicle With Minimal Data response', res);
|
||
|
||
if(res.status == true){
|
||
getClientAndBranchAndPolicy();
|
||
$('#client_type').val(res.owner_type);
|
||
setTimeout(function(){
|
||
appendVehicles(res.vehicles, res.vehicle_id);
|
||
$('#client_id').val(res.owner_id).change();
|
||
if(res.owner_type == 1){
|
||
|
||
$('.branchdiv').show()
|
||
$('#client_branch_id').prop('required', true);
|
||
|
||
setTimeout(function(){
|
||
$('#client_branch_id').val(res.owner_branch_id).change();
|
||
}, 1000)
|
||
}else{
|
||
$('.branchdiv').hide()
|
||
$('#client_branch_id').prop('required', false);
|
||
}
|
||
|
||
// if(res.owner_type == 2){
|
||
// $('#table_tr_34').hide();
|
||
// $('#table_tr_37').hide();
|
||
// $("select[name='cd_ac_no_for_child[]']").removeAttr("required");
|
||
// }else{
|
||
// $('#table_tr_34').show();
|
||
// $('#table_tr_37').show();
|
||
// $("select[name='cd_ac_no_for_child[]']").attr('required', 'required');
|
||
// }
|
||
|
||
$('.loader').fadeOut();
|
||
$('.loader-mask').delay(350).fadeOut('slow');
|
||
}, 2000)
|
||
toastr.success(res.message, 'Success');
|
||
}else{
|
||
toastr.error(res.message, 'Error');
|
||
}
|
||
|
||
$('#vehicle_form')[0].reset();
|
||
$('.close').click();
|
||
isVehicleFormSubmitting = false;
|
||
},
|
||
error: function (xhr, status, error) {
|
||
console.error(xhr.responseText);
|
||
console.error(status, error);
|
||
isVehicleFormSubmitting = false;
|
||
$('.loader').fadeOut();
|
||
$('.loader-mask').delay(350).fadeOut('slow');
|
||
}
|
||
});
|
||
});
|
||
|
||
$("#CDMasterForm").submit(function(event) {
|
||
|
||
event.preventDefault();
|
||
|
||
var isValid = $('#CDMasterForm').parsley().validate();
|
||
if (!isValid) {
|
||
console.log('Form is Empty', 'Warning');
|
||
return ;
|
||
}
|
||
|
||
form_action = '<?= base_url("util/createCDAccountNumberUsingAjax"); ?>';
|
||
|
||
$('.loader').fadeIn();
|
||
$('.loader-mask').fadeIn();
|
||
|
||
var unique_id = $('#premium_details_unique_id').val();
|
||
var client_id = $('#client_id').val();
|
||
var insurer_id = $('#follow_insurer_id_'+unique_id).find('option:selected').attr('data-id');
|
||
var insurer_and_insurer_branch = $('#follow_insurer_id_'+unique_id).val();
|
||
|
||
|
||
console.log('unique_id', unique_id);
|
||
console.log('client_id', client_id);
|
||
console.log('insurer_id', insurer_id);
|
||
|
||
var formData = new FormData($('#CDMasterForm')[0]);
|
||
formData.append('client_id', client_id);
|
||
formData.append('insurer_id', insurer_id);console.log(formData);
|
||
formData.append('insurer_and_insurer_branch', insurer_and_insurer_branch);
|
||
console.log(formData);
|
||
|
||
$.ajax({
|
||
data:formData,
|
||
url: form_action,
|
||
type: "POST",
|
||
dataType: 'json',
|
||
processData: false,
|
||
contentType: false,
|
||
success: function(res) {
|
||
|
||
console.log("CD FORM SUBMIT RESPONSE : ", res);
|
||
|
||
$('.loader').fadeOut();
|
||
$('.loader-mask').delay(350).fadeOut('slow');
|
||
|
||
if(res.status == true){
|
||
appendCDAccountNumber(res.data, unique_id, res.cd_ac_pk);
|
||
$('#cd_ac_pk_for_leader').val(res.cd_ac_pk)
|
||
console.log('cd_current_balance instance', $('#cd_current_balance_'+unique_id))
|
||
$('#cd_current_balance_'+unique_id).val(res.received_data.opening_bal);
|
||
|
||
toastr.success(res.message, 'Success');
|
||
}else{
|
||
toastr.error(res.message, 'Error');
|
||
}
|
||
|
||
$('#CDMasterForm')[0].reset();
|
||
$('.close').click();
|
||
},
|
||
error: function (xhr, status, error) {
|
||
console.error(xhr.responseText);
|
||
console.error(status, error);
|
||
$('.loader').fadeOut();
|
||
$('.loader-mask').delay(350).fadeOut('slow');
|
||
}
|
||
});
|
||
});
|
||
|
||
//-----------------------------------------------------------------------------------------------------------
|
||
|
||
$('#cop_yes').change(function() {
|
||
|
||
var selectedOption = $('#policy_type_id').find('option:selected');
|
||
var bap = selectedOption.data('bap');
|
||
var allocg = selectedOption.data('allocg');
|
||
var policy_type_id = $('#policy_type_id').val();
|
||
|
||
if(allocg == "EB"){
|
||
|
||
$('.hideter').hide();
|
||
$('.hidetp').hide();
|
||
$('.hidecoter').hide()
|
||
$('.hidecotp').hide()
|
||
|
||
} else if(allocg == "Non-EB"){
|
||
|
||
$('.hidetp').hide();
|
||
$('.hidecotp').hide();
|
||
|
||
$('.hideter').show();
|
||
if($(this).is(':checked')){
|
||
$('.hidecoter').show();
|
||
}else{
|
||
$('.hidecoter').hide();
|
||
}
|
||
|
||
} else if(policy_type_id == 8){
|
||
|
||
$('.hideter').hide();
|
||
$('.hidecoter').hide();
|
||
|
||
$('.hidetp').show();
|
||
if($(this).is(':checked')){
|
||
$('.hidecotp').show();
|
||
}else{
|
||
$('.hidecotp').hide();
|
||
}
|
||
|
||
} else{
|
||
|
||
if(bap == 'Fire' || bap == 'Marine Cargo' || bap == 'Marine Hull'){
|
||
$('.hideter').show();
|
||
if($(this).is(':checked')){
|
||
$('.hidecoter').show();
|
||
}else{
|
||
$('.hidecoter').hide();
|
||
}
|
||
}else{
|
||
$('.hideter').hide();
|
||
}
|
||
}
|
||
|
||
if ($(this).is(':checked')) {
|
||
|
||
$('#add_more_row').removeClass('d-none');
|
||
$('.payby').removeClass('d-none');
|
||
$('#table_tr_2').show()
|
||
$('#table_tr_3').show()
|
||
$('#table_tr_7').show()
|
||
$('#table_tr_35').show()
|
||
|
||
// do not remove this commented items
|
||
// if(bap == 'Fire' || bap == 'Marine Cargo' || bap == 'Marine Hull'){
|
||
// $('.hidecoter').show()
|
||
// $('.hidecotp').hide()
|
||
// }else{
|
||
|
||
// if(bap == 'Motor'){
|
||
// $('.hidecotp').show()
|
||
// $('.hidecoter').hide()
|
||
// }else{
|
||
// $('.hidecoter').hide()
|
||
// $('.hidecotp').hide()
|
||
// }
|
||
// }
|
||
|
||
// if(allocg == "EB"){
|
||
// $('.hideter').hide();
|
||
// $('.hidetp').hide();
|
||
// $('.hidecoter').hide()
|
||
// $('.hidecotp').hide()
|
||
// }else{
|
||
|
||
// $('.hidetp').show();
|
||
// if($(this).is(':checked')){
|
||
// $('.hidecotp').show();
|
||
// }else{
|
||
// $('.hidecotp').hide();
|
||
// }
|
||
|
||
// if(bap == 'Fire' || bap == 'Marine Cargo' || bap == 'Marine Hull'){
|
||
// $('.hideter').show();
|
||
// if($(this).is(':checked')){
|
||
// $('.hidecoter').show();
|
||
// }else{
|
||
// $('.hidecoter').hide();
|
||
// }
|
||
// }else{
|
||
// $('.hideter').hide();
|
||
// }
|
||
// }
|
||
|
||
// $('input[name="co_share_per[]"], input[name="co_premium[]"]').each(function () {
|
||
// $(this).val(''); // Clear value
|
||
// console.log('Input cleared:', $(this).attr('name')); // Log cleared input
|
||
// });
|
||
|
||
} else {
|
||
$('#add_more_row').addClass('d-none');
|
||
$('.payby').addClass('d-none');
|
||
// $('#bro_payable_by').prop('checked', false);
|
||
$('#table_tr_2').hide()
|
||
$('#table_tr_3').hide()
|
||
$('#table_tr_7').hide()
|
||
$('#table_tr_35').hide()
|
||
$('.hidecoter').hide()
|
||
$('.hidecotp').hide()
|
||
|
||
// $('input[name="co_share_per[]"], input[name="co_premium[]"]').each(function () {
|
||
// $(this).val(''); // Clear value
|
||
// console.log('Input cleared:', $(this).attr('name')); // Log cleared input
|
||
// });
|
||
}
|
||
});
|
||
|
||
$('#client_type').change(function() {
|
||
|
||
let policy_type_id = $('#policy_type_id').val();
|
||
console.log("client_policy_type_id", policy_type_id);
|
||
|
||
if ($(this).val() == 2) {
|
||
if($('#policy_type_id').val() == 8){
|
||
$('#policyholdernamediv').hide();
|
||
}else{
|
||
$('#policyholdernamediv').show();
|
||
}
|
||
} else {
|
||
$('#policyholdernamediv').hide();
|
||
}
|
||
|
||
|
||
var selectedOption = $('#policy_type_id').find('option:selected');
|
||
|
||
var ebp = selectedOption.data('ebp');
|
||
var etp = selectedOption.data('etp');
|
||
var etep = selectedOption.data('etep');
|
||
var iep = selectedOption.data('iep');
|
||
var itp = selectedOption.data('itp');
|
||
var itep = selectedOption.data('itep');
|
||
|
||
var std_bp = 0;
|
||
var std_tp = 0;
|
||
var std_tep = 0;
|
||
|
||
if ($(this).val() == 2) {
|
||
|
||
std_bp = iep;
|
||
std_tp = itp;
|
||
std_tep = itep;
|
||
|
||
$('.branchdiv').hide();
|
||
$('.clienttypediv').show();
|
||
$('#entity_type_id_for_client').prop('required', false);
|
||
$('#branch_name').prop('required', false);
|
||
$('#client_branch_id').prop('required', false);
|
||
$('#branch_code').prop('required', false);
|
||
$('#name').prop('required', false);
|
||
// $('#mobile').prop('required', false);
|
||
$('#gst').prop('required', false);
|
||
$('#email').prop('required', false);
|
||
|
||
$('#dob').prop('required', true);
|
||
// $('#phone').prop('required', true);
|
||
$('#email2').prop('required', true);
|
||
$('#aadhar').prop('required', true);
|
||
|
||
$('#owner_branch').prop('required', false);
|
||
|
||
$('#table_tr_34').hide();
|
||
$('#table_tr_37').hide();
|
||
$("select[name='cd_ac_no_for_child[]']").removeAttr("required");
|
||
|
||
} else {
|
||
|
||
std_bp = ebp;
|
||
std_tp = etp;
|
||
std_tep = etep;
|
||
|
||
$('.branchdiv').show();
|
||
$('.clienttypediv').hide();
|
||
$('#entity_type_id_for_client').prop('required', true);
|
||
$('#branch_name').prop('required', true);
|
||
$('#client_branch_id').prop('required', true);
|
||
$('#branch_code').prop('required', true);
|
||
$('#name').prop('required', true);
|
||
// $('#mobile').prop('required', false);
|
||
$('#gst').prop('required', false);
|
||
$('#email').prop('required', true);
|
||
|
||
$('#dob').prop('required', false);
|
||
// $('#phone').prop('required', false);
|
||
$('#email2').prop('required', false);
|
||
$('#aadhar').prop('required', false);
|
||
|
||
$('#owner_branch').prop('required', true);
|
||
|
||
if(policy_type_id == 1 || policy_type_id == 2 || policy_type_id == 3 || policy_type_id == 4 || policy_type_id == 5 || policy_type_id == 6 || policy_type_id == 7){
|
||
$('#table_tr_34').hide();
|
||
$('#table_tr_37').hide();
|
||
// $("select[name='cd_ac_no_for_child[]']").removeAttr("required");
|
||
}else{
|
||
$('#table_tr_34').show();
|
||
$('#table_tr_37').show();
|
||
// $("select[name='cd_ac_no_for_child[]']").attr('required', 'required');
|
||
}
|
||
}
|
||
|
||
$('[name="standard_bp[]"]').val(std_bp);
|
||
$('[name="standard_tp[]"]').val(std_tp);
|
||
$('[name="standard_ter[]"]').val(std_tep);
|
||
});
|
||
|
||
$('#same_as_proposer').change(function() {
|
||
var client_type = $('#client_type').val()
|
||
var policy_type = $('#policy_type_id').val()
|
||
if ($(this).is(':checked')) {
|
||
$('#dynamic-form-container-for-insured').empty();
|
||
$('#family_details').hide();
|
||
} else {
|
||
if(client_type == 2 && policy_type != 8){
|
||
$('#family_details').show();
|
||
appendInsured()
|
||
}else{
|
||
$('#dynamic-form-container-for-insured').empty();
|
||
$('#family_details').hide();
|
||
}
|
||
}
|
||
});
|
||
|
||
$('#client_type').on('change', function() {
|
||
var selectedClientType = $(this).val();
|
||
|
||
// console.log('selectedClientType', selectedClientType);
|
||
|
||
// Clear and add default options for client
|
||
$('#client_id').empty().append($('<option>', {
|
||
value: '',
|
||
text: 'Select Client'
|
||
})).append($('<option>', {
|
||
value: 'add_client',
|
||
text: '+ Add Client'
|
||
}));
|
||
|
||
// Populate client options based on selected client type
|
||
if (selectedClientType) {
|
||
|
||
$.each(client_list, function(index, item) {
|
||
if (item.client_type == selectedClientType) {
|
||
|
||
let client_show_name = item.client_name;
|
||
if (item.client_type == 2) {
|
||
// client_show_name = item.client_name + ' - ' + (item.dob ?? '') + (item.pan ?? '');
|
||
client_show_name = item.client_name + (item.dob ? ('- (' + item.dob + ' )' ) : '') + (item.pan ? ('- ' + item.pan ) : '');
|
||
}
|
||
var option = $('<option>', {
|
||
value: item.id,
|
||
text: client_show_name,
|
||
'data-cn': item.client_name,
|
||
'data-ct': item.client_type
|
||
});
|
||
$('#client_id').append(option);
|
||
}
|
||
});
|
||
|
||
}
|
||
|
||
// Initialize or refresh Select2 for both dropdowns
|
||
$('#client_id').select2();
|
||
});
|
||
|
||
$('#Owner_type').on('change', function() {
|
||
|
||
var selectedClientType = $(this).val();
|
||
|
||
$('#client_type').val(selectedClientType).change();
|
||
|
||
if ($(this).val() == 2) {
|
||
$('.ownerbranchdiv').hide();
|
||
$('#owner_branch').prop('required', false);
|
||
$('#table_tr_34').hide();
|
||
$('#table_tr_37').hide();
|
||
// $("select[name='cd_ac_no_for_child[]']").removeAttr("required");
|
||
} else {
|
||
$('.ownerbranchdiv').show();
|
||
$('#owner_branch').prop('required', true);
|
||
$('#table_tr_34').show();
|
||
$('#table_tr_37').show();
|
||
// $("select[name='cd_ac_no_for_child[]']").attr('required', 'required');
|
||
}
|
||
|
||
// console.log('selected Owner type', selectedClientType);
|
||
|
||
// Clear and add default options for vehicle
|
||
$('#owner').empty().append($('<option>', {
|
||
value: '',
|
||
text: 'Select Owner'
|
||
}))
|
||
|
||
// $('#owner').append(
|
||
// $('<option>', {
|
||
// value: 'add_client',
|
||
// text: ' + Add Owner',
|
||
// })
|
||
// );
|
||
|
||
// Populate client options based on selected client type
|
||
if (selectedClientType) {
|
||
// Populate vehicle options based on selected client type
|
||
$.each(client_list, function(index, owner) {
|
||
|
||
if (owner.client_type == selectedClientType) {
|
||
|
||
if(selectedClientType == '2'){
|
||
|
||
var option = $('<option>', {
|
||
value: owner.id,
|
||
text: (owner.client_name + ' - ' + (owner.pan ?? 'N/A'))
|
||
});
|
||
|
||
$('#owner').append(option);
|
||
|
||
}else{
|
||
|
||
var option = $('<option>', {
|
||
value: owner.id,
|
||
text: owner.client_name,
|
||
});
|
||
$('#owner').append(option);
|
||
|
||
}
|
||
|
||
}
|
||
});
|
||
}
|
||
|
||
// Initialize or refresh Select2 for both dropdowns
|
||
$('#owner').select2();
|
||
});
|
||
|
||
$('#policy_status').change(function(){
|
||
|
||
var pt_id = $('#policy_tranction_primarykey').val();
|
||
var status = $(this).val()
|
||
var policy_type_id = $('#policy_type_id').val()
|
||
var client_id = $('#client_id').val();
|
||
var client_branch_id = $('#client_branch_id').val();
|
||
|
||
if(status == 'completed'){
|
||
|
||
if(pt_id == ''){
|
||
removeAllColumnsExceptFirst('insurerTable');
|
||
}
|
||
addInsurerColumn() ;
|
||
$('#sales_row').show();
|
||
$('#policy_no').prop('required', true);
|
||
$('#policy_issue_date').prop('required', true);
|
||
$('#policy_start_date').prop('required', true);
|
||
$('#policy_end_date').prop('required', true);
|
||
// $('#tpa').prop('required', true);
|
||
// $('#emp_count').prop('required', true);
|
||
// $('#dependent_count').prop('required', true);
|
||
$('.follow_insurer').prop('required', true);
|
||
|
||
if(policy_type_id == 3 || policy_type_id == 4 || policy_type_id == 5){
|
||
$('#base_policy_id').show();
|
||
}else{
|
||
$('#base_policy_id').hide();
|
||
}
|
||
|
||
if(client_id && client_branch_id){
|
||
|
||
var url_for_get_policy_type_list = '<?php echo base_url('util/base_policy_for_policy_inception/') ?>' + client_id + '/' + client_branch_id;
|
||
$.get(url_for_get_policy_type_list, function(response){
|
||
console.log('base_policy_for_policy_inception response', response)
|
||
appendBasePolicyList(response.data);
|
||
}).fail(function(xhr, status, error) {
|
||
console.error(xhr.responseText);
|
||
console.error(status, error);
|
||
});
|
||
}
|
||
|
||
if(policy_type_id == 1 || policy_type_id == 2 || policy_type_id == 3 || policy_type_id == 4 || policy_type_id == 5){
|
||
$('#tpa_div').show();
|
||
}else{
|
||
$('#tpa_div').hide();
|
||
}
|
||
|
||
if(policy_type_id == 2 || policy_type_id == 3 || policy_type_id == 4 || policy_type_id == 5){
|
||
$('#no_of_insured_div').show();
|
||
$('#no_of_dependents_div').show();
|
||
}else if(policy_type_id == 1 || policy_type_id == 6 || policy_type_id == 7) {
|
||
$('#no_of_insured_div').show();
|
||
$('#no_of_dependents_div').hide();
|
||
}else{
|
||
$('#no_of_insured_div').hide();
|
||
$('#no_of_dependents_div').hide();
|
||
}
|
||
|
||
}else{
|
||
$('#sales_row').hide()
|
||
$('#policy_no').prop('required', false)
|
||
$('#policy_issue_date').prop('required', false)
|
||
$('#policy_start_date').prop('required', false)
|
||
$('#policy_end_date').prop('required', false)
|
||
// $('#tpa').prop('required', false)
|
||
// $('#emp_count').prop('required', false)
|
||
// $('#dependent_count').prop('required', false)
|
||
$('.follow_insurer').prop('required', false)
|
||
|
||
}
|
||
|
||
});
|
||
|
||
$('#policy_no').change(function(){
|
||
|
||
var policy_no = $(this).val();
|
||
policy_no = policy_no.trim();
|
||
let client_id = $('#client_id').val()?.trim();
|
||
let client_type = $('#client_type').val()?.trim();
|
||
let client_branch_id = $('#client_branch_id').val()?.trim();
|
||
let policy_type_id = $('#policy_type_id').val()?.trim();
|
||
|
||
if (!client_id || !client_branch_id || !policy_type_id) {
|
||
if(client_type == 1){
|
||
toastr.warning('Please select the policy type, client and branch', "Warning");
|
||
$('#policy_no').val('');
|
||
return;
|
||
}
|
||
}
|
||
|
||
$pt_id = $('#policy_tranction_policy_number').val();
|
||
console.log('$pt_id', $pt_id);
|
||
|
||
if($pt_id == "" && policy_no != ""){
|
||
$.ajax({
|
||
url: '<?php echo base_url('util/get_client_policy_data_using_policy_no/');?>',
|
||
type: "GET",
|
||
data : { policy_no : policy_no, client_id : client_id, client_branch_id : client_branch_id, policy_type_id : policy_type_id, client_type : client_type},
|
||
dataType: 'json',
|
||
success: function (res) {
|
||
|
||
console.log('get_client_policy_data_using_policy_no response', res)
|
||
|
||
if(res.status == true && res.code == 409){
|
||
toastr.warning(res.message,'Warning');
|
||
$('#policy_no').val("");
|
||
return;
|
||
}else{
|
||
$('#ct_type').val(2);
|
||
$('#client_policy_id').val('');
|
||
$('#policy_start_date').val('');
|
||
$('#policy_end_date').val('');
|
||
$('#tpa').val('').select2();
|
||
console.log(res.message, 'Warning');
|
||
}
|
||
|
||
// if(res.status == true){
|
||
// $('#ct_type').val(1);
|
||
// $('#client_policy_id').val(res.data.id);
|
||
// $('#policy_start_date').val(res.data.policy_start_date);
|
||
// $('#policy_end_date').val(res.data.policy_end_date);
|
||
// $('#tpa').val(res.data.tpa_branch_id+'-'+res.data.tpa_id).select2();
|
||
// }
|
||
},
|
||
error: function (xhr, status, error) {
|
||
console.error(xhr.responseText);
|
||
console.error(status, error);
|
||
}
|
||
});
|
||
}else{
|
||
|
||
$('#ct_type').val(2);
|
||
$('#client_policy_id').val();
|
||
$('#policy_start_date').val();
|
||
$('#policy_end_date').val();
|
||
$('#tpa').val('').select2();
|
||
console.log("This is new policy Could not get policy data")
|
||
}
|
||
});
|
||
|
||
$('.close').on('click', function(){
|
||
// $('#client_form')[0].reset();
|
||
// $('#vehicle_form')[0].reset();
|
||
$('#CDMasterForm')[0].reset();
|
||
});
|
||
|
||
$('#policy_issue_date').on('change', function(){
|
||
let date = $(this).val();
|
||
|
||
let date_set = false
|
||
$('[name="co_share_type[]"]').each(function () {
|
||
if($(this).is(':checked')){
|
||
let uniqueid = $(this).data('id');
|
||
$('#calc_policy_issue_date_' + uniqueid).val(date).addClass('readonly-select');
|
||
date_set = true;
|
||
}
|
||
});
|
||
|
||
if(!date_set){
|
||
$('#calc_policy_issue_date_1').val(date).addClass('readonly-select');
|
||
}
|
||
});
|
||
|
||
//------------------------------------------------------------------------------------------------------------
|
||
|
||
var insurerCount = 0;
|
||
|
||
$('#setInsurerCount').on('click', function() {
|
||
addInsurerColumn();
|
||
getColumnIndexes(1);
|
||
});
|
||
|
||
function addInsurerColumn() {
|
||
|
||
insurerCount = insurerCount + 1;
|
||
|
||
// Update header
|
||
$('#insurerTable thead tr').append(`
|
||
<th>
|
||
<span style="display:flex; justify-content:space-between; align-items:center;">
|
||
Insurer ${insurerCount}
|
||
${insurerCount > 1 ? `<a data-count="${insurerCount}" class="text-danger mdi mdi-delete delete-insurer" style="margin-left: 135px;"></a>` : ''}
|
||
</span>
|
||
</th>
|
||
`);
|
||
|
||
// Add a new column for each data row
|
||
$('#insurerTable tbody tr').each(function(index) {
|
||
|
||
let newCell = '';
|
||
|
||
if(role_id == 1 || role_id == 5 || team_id.includes('6') || team_id.includes('4')){
|
||
|
||
switch(index) {
|
||
|
||
case 0: // Insurer selection
|
||
newCell = `<td>
|
||
<select class="form-control follow_insurer" data-count="${insurerCount}" id="follow_insurer_id_${insurerCount}" name="follow_insurer_id[]" onchange="getCDAccountNumber(this)" required>
|
||
<option value="" selected>Select Insurer</option>
|
||
<?php foreach ($insurer_branch as $value) { ?>
|
||
<option value="<?= $value['id'] . '-' . $value['insurer_id'] ?>" data-id="<?= $value['insurer_id'] ?>" data-bid="<?= $value['id'] ?>" data-ic="<?= $value['category'] ?>">
|
||
<?= $value['insurer_name'] . '-' . $value['branch_code'] ?>
|
||
</option>
|
||
<?php } ?>
|
||
</select>
|
||
</td>`;
|
||
break;
|
||
case 1: // Is Leader?
|
||
newCell = `<td>
|
||
<label class="switch" style="position: relative; top: 5px; left: 35px;">
|
||
<input data-id="${insurerCount}" id="co_share_type_${insurerCount}" type="checkbox" name="co_share_type[]" onchange="select_leader_disable_premium_amt(this, '${insurerCount}')">
|
||
<span class="slider round" style="height: 27px;"></span>
|
||
</label>
|
||
<label for="inception_type" style="position: relative; top: 5px; left: 40px;">Leader Yes</label>
|
||
</td>`;
|
||
break;
|
||
case 2: // CD Account Number selectionclass="std_tp_td"
|
||
newCell = `<td>
|
||
<select class="form-control follow_insurer_cd" data-count="${insurerCount}" id="cd_ac_no_${insurerCount}" name="cd_ac_no_for_child[]" onchange="addCDAccountNumber(this); restrictCDACNO(this);">
|
||
<option value="" selected>Select CD No</option>
|
||
<option value="add_cd"> + Add CD No</option>
|
||
</select>
|
||
</td>`;
|
||
break;
|
||
case 3: // CD Amount
|
||
newCell = `<td class=""><input type="text" class="right-align-input" id="cd_current_balance_${insurerCount}" readonly></td>`;
|
||
break;
|
||
case 4: // follower policy no
|
||
newCell = `<td class=""><input type="text" class="" id="follower_policy_no_${insurerCount}" name="follower_policy_no[]" onchange="validateInput(this, 'client_policy', 'policy_no')"></td>`;
|
||
break;
|
||
case 5: // policy issue date
|
||
newCell = `<td class=""><input type="text" class="" id="calc_policy_issue_date_${insurerCount}" name="calc_policy_issue_date[]"></td>`;
|
||
break;
|
||
case 6: // Co-Share %
|
||
newCell = `<td class="input-with-percentage"><input type="text" class="right-align-input" id="co_share_per_${insurerCount}" name="co_share_per[]" oninput="validateRange(this); " onchange="co_share_percentage_calculation('${insurerCount}')" onkeypress="return onlyNumbers(event)"></td>`;
|
||
break;
|
||
case 7: // Non commissionable Premium amount %
|
||
newCell = `<td><input type="text" class="right-align-input" id="non_comm_per_amt_${insurerCount}" name="non_comm_per_amt[]" oninput="" onkeypress="return onlyNumbers(event)"></td>`;
|
||
break;
|
||
case 8: // Base Premium
|
||
newCell = `<td><input type="text" class="right-align-input" id="base_premium_${insurerCount}" name="base_premium[]" onchange="checkCDAmountForBasePremium(${insurerCount})" onkeypress="return onlyNumbers(event)"></td>`;
|
||
break;
|
||
case 9: // TP Premium
|
||
newCell = `<td><input type="text" class="right-align-input" id="tp_premium_${insurerCount}" name="tp_premium[]" oninput="" onkeypress="return onlyNumbers(event)"></td>`;
|
||
break;
|
||
case 10: // Ter Premium
|
||
newCell = `<td><input type="text" class="right-align-input" id="ter_premium_${insurerCount}" name="ter_premium[]" oninput="" onkeypress="return onlyNumbers(event)"></td>`;
|
||
break;
|
||
case 11: // co Premium
|
||
newCell = `<td><input type="text" class="right-align-input" id="co_premium_${insurerCount}" name="co_premium[]" oninput="" onkeypress="return onlyNumbers(event)"></td>`;
|
||
break;
|
||
|
||
case 12: // Co TP Premium
|
||
newCell = `<td><input type="text" class="right-align-input" id="co_tp_premium_${insurerCount}" name="co_tp_premium[]" oninput="" onkeypress="return onlyNumbers(event)"></td>`;
|
||
break;
|
||
case 13: // Co Ter Premium
|
||
newCell = `<td><input type="text" class="right-align-input" id="co_ter_premium_${insurerCount}" name="co_ter_premium[]" oninput="" onkeypress="return onlyNumbers(event)"></td>`;
|
||
break;
|
||
|
||
case 14: // CGST
|
||
newCell = `<td class="input-with-percentage"><input type="text" class="right-align-input" id="cgst_${insurerCount}" name="cgst[]" oninput="" onkeypress="return onlyNumbers(event)"></td>`;
|
||
break;
|
||
case 15: // SGST
|
||
newCell = `<td class="input-with-percentage"><input type="text" class="right-align-input" id="sgst_${insurerCount}" name="sgst[]" oninput="" onkeypress="return onlyNumbers(event)"></td>`;
|
||
break;
|
||
case 16: // IGST
|
||
newCell = `<td class="input-with-percentage"><input type="text" class="right-align-input" id="igst_${insurerCount}" name="igst[]" oninput="" onkeypress="return onlyNumbers(event)"></td>`;
|
||
break;
|
||
case 17: // GST Amount
|
||
newCell = `<td><input type="text" class="right-align-input" id="gst_amount_${insurerCount}" name="gst_amount[]" onchange="" onkeypress="return onlyNumbers(event)"></td>`;
|
||
break;
|
||
case 18: // Stamp Duty
|
||
newCell = `<td><input type="text" class="right-align-input" id="stamp_duty_${insurerCount}" name="stamp_duty[]" oninput="" onkeypress="return onlyNumbers(event)"></td>`;
|
||
break;
|
||
case 19: // Total
|
||
newCell = `<td><input type="text" class="readonly-color right-align-input" id="total_amt_${insurerCount}" name="total[]" readonly onkeypress="return onlyNumbers(event)"></td>`;
|
||
break;
|
||
case 20: // Agreed BP %
|
||
newCell = `<td class="input-with-percentage"><input type="text" class="right-align-input" id="agreed_bp_${insurerCount}" name="agreed_bp[]" oninput="validateRange(this); " onkeypress="return onlyNumbers(event)" ></td>`;
|
||
break;
|
||
case 21: // Agreed TP %
|
||
newCell = `<td class="input-with-percentage"><input type="text" class="right-align-input" id="agreed_tp_${insurerCount}" name="agreed_tp[]" oninput="validateRange(this); " onkeypress="return onlyNumbers(event)"></td>`;
|
||
break;
|
||
case 22: // Agreed Ter %
|
||
newCell = `<td class="input-with-percentage"><input type="text" class="right-align-input" id="agreed_ter_${insurerCount}" name="agreed_ter[]" oninput="validateRange(this); " onkeypress="return onlyNumbers(event)" ></td>`;
|
||
break;
|
||
case 23: // Agreed Amount
|
||
newCell = `<td><input type="text" class="right-align-input" id="agreed_amount_${insurerCount}" name="agreed_amount[]" oninput="" onkeypress="return onlyNumbers(event)"></td>`;
|
||
break;
|
||
case 24: // Standard BP %
|
||
newCell = `<td class="input-with-percentage"><input type="text" class="readonly-color right-align-input" id="standard_bp_${insurerCount}" name="standard_bp[]" onkeypress="return onlyNumbers(event)" readonly></td>`;
|
||
break;
|
||
case 25: // Standard TP %
|
||
newCell = `<td class="input-with-percentage"><input type="text" class="readonly-color right-align-input" id="standard_tp_${insurerCount}" name="standard_tp[]" onkeypress="return onlyNumbers(event)" readonly ></td>`;
|
||
break;
|
||
case 26: // Standard Ter %
|
||
newCell = `<td class="input-with-percentage"><input type="text" class="readonly-color right-align-input" id="standard_tep_${insurerCount}" name="standard_ter[]" onkeypress="return onlyNumbers(event)" readonly></td>`;
|
||
break;
|
||
case 27: // Actual BP Amount
|
||
newCell = `<td><input type="text" class="readonly-select right-align-input" id="actual_bp_amt_${insurerCount}" name="actual_bp_amt[]" onchange="actualAmountCalculation('${insurerCount}', 'bp_amt_for_calc')" onkeypress="return onlyNumbers(event)"></td>`;
|
||
break;
|
||
case 28: // Actual TP Amount
|
||
newCell = `<td><input type="text" class="readonly-select right-align-input" id="actual_tp_amt_${insurerCount}" name="actual_tp_amt[]" onchange="actualAmountCalculation('${insurerCount}', 'tp_amt_for_calc')" onkeypress="return onlyNumbers(event)"></td>`;
|
||
break;
|
||
case 29: // Actual TEP Amount
|
||
newCell = `<td><input type="text" class="readonly-select right-align-input" id="actual_tep_amt_${insurerCount}" name="actual_tep_amt[]" onchange="actualAmountCalculation('${insurerCount}', 'tep_amt_for_calc')" onkeypress="return onlyNumbers(event)"></td>`;
|
||
break;
|
||
case 30: // Actual BP %
|
||
newCell = `<td class="input-with-percentage"><input type="text" class="readonly-select right-align-input" id="actual_bp_per_${insurerCount}" name="actual_bp_per[]" onchange="actualAmountCalculation('${insurerCount}', 'bp_per')" onkeypress="return onlyNumbers(event)"></td>`;
|
||
break;
|
||
case 31: // Actual TP %
|
||
newCell = `<td class="input-with-percentage"><input type="text" class="readonly-select right-align-input" id="actual_tp_per_${insurerCount}" name="actual_tp_per[]" onchange="actualAmountCalculation('${insurerCount}', 'tp_per')" onkeypress="return onlyNumbers(event)"></td>`;
|
||
break;
|
||
case 32: // Actual TEP %
|
||
newCell = `<td class="input-with-percentage"><input type="text" class="readonly-select right-align-input" id="actual_tep_per_${insurerCount}" name="actual_tp_per[]" onchange="actualAmountCalculation('${insurerCount}', 'tep_per')" onkeypress="return onlyNumbers(event)"></td>`;
|
||
break;
|
||
case 33: // Actual BP Brokerage Amount
|
||
newCell = `<td><input type="text" class="readonly-select right-align-input" id="actual_bp_brokerage_amt_${insurerCount}" name="actual_bp_brokerage_amt[]" onchange="actualAmountCalculation('${insurerCount}', 'bp_broker_amt')" onkeypress="return onlyNumbers(event)"></td>`;
|
||
break;
|
||
case 34: // Actual TP Brokerage Amount
|
||
newCell = `<td><input type="text" class="readonly-select right-align-input" id="actual_tp_brokerage_amt_${insurerCount}" name="actual_tp_brokerage_amt[]" onchange="actualAmountCalculation('${insurerCount}', 'tp_broker_amt')" onkeypress="return onlyNumbers(event)"></td>`;
|
||
break;
|
||
case 35: // Actual TEP Brokerage Amount
|
||
newCell = `<td><input type="text" class="readonly-select right-align-input" id="actual_tep_brokerage_amt_${insurerCount}" name="actual_tep_brokerage_amt[]" onchange="actualAmountCalculation('${insurerCount}', 'tep_broker_amt')" onkeypress="return onlyNumbers(event)"></td>`;
|
||
break;
|
||
case 36: // Expected Amount
|
||
newCell = `<td><input type="text" class="readonly-select right-align-input" id="exp_amt_${insurerCount}" name="exp_amt[]" onchange="actual" onkeypress="return onlyNumbers(event)"></td>`;
|
||
break;
|
||
// case 34: // Variance
|
||
// newCell = `<td><input type="text" class="readonly-select right-align-input" id="variance_${insurerCount}" name="variance[]" onchange="actual" onkeypress="return onlyNumbers(event)"></td>`;
|
||
// break;
|
||
case 37: // ID For Update
|
||
newCell = `<td><input type="hidden" name="co_share_id[]" id="co_share_id[]" onkeypress="return onlyNumbers(event)"></td>`;
|
||
break;
|
||
|
||
}
|
||
|
||
}else if(team_id.includes('3') || team_id.includes('8')){
|
||
|
||
switch(index) {
|
||
case 0: // Insurer selection
|
||
newCell = `<td>
|
||
<select class="form-control follow_insurer" data-language="1" data-count="${insurerCount}" id="follow_insurer_id_${insurerCount}" name="follow_insurer_id[]" onchange="getCDAccountNumber(this)" required>
|
||
<option value="" selected>Select Insurer</option>
|
||
<?php foreach ($insurer_branch as $value) { ?>
|
||
<option value="<?= $value['id'] . '-' . $value['insurer_id'] ?>" data-id="<?= $value['insurer_id'] ?>" data-bid="<?= $value['id'] ?>" data-ic="<?= $value['category'] ?>">
|
||
<?= $value['insurer_name'] . '-' . $value['branch_code'] ?>
|
||
</option>
|
||
<?php } ?>
|
||
</select>
|
||
</td>`;
|
||
break;
|
||
case 1: // Is Leader?
|
||
newCell = `<td>
|
||
<label class="switch" style="position: relative; top: 5px; left: 35px;">
|
||
<input data-id="${insurerCount}" id="co_share_type_${insurerCount}" type="checkbox" name="co_share_type[]" onchange="select_leader_disable_premium_amt(this, '${insurerCount}')">
|
||
<span class="slider round" style="height: 27px;"></span>
|
||
</label>
|
||
<label for="inception_type" style="position: relative; top: 5px; left: 40px;">Leader Yes</label>
|
||
</td>`;
|
||
break;
|
||
case 2: // CD Account Number selectionclass="std_tp_td"
|
||
newCell = `<td>
|
||
<select class="form-control follow_insurer_cd" data-language="2" data-count="${insurerCount}" id="cd_ac_no_${insurerCount}" name="cd_ac_no_for_child[]" onchange="addCDAccountNumber(this); restrictCDACNO(this)">
|
||
<option value="" selected>Select CD No</option>
|
||
<option value="add_cd"> + Add CD No</option>
|
||
</select>
|
||
</td>`;
|
||
break;
|
||
case 3: // CD Amount %
|
||
newCell = `<td class=""><input type="text" class="right-align-input" id="cd_current_balance_${insurerCount}" readonly></td>`;
|
||
break;
|
||
case 4: // follower policy no %
|
||
newCell = `<td class=""><input type="text" class="" id="follower_policy_no_${insurerCount}" name="follower_policy_no[]" oninput="" onchange=""></td>`;
|
||
break;
|
||
case 5: // calc_policy_issue_date %
|
||
newCell = `<td class=""><input type="text" class="" id="calc_policy_issue_date_${insurerCount}" name="calc_policy_issue_date[]" oninput="" onchange=""></td>`;
|
||
break;
|
||
case 6: // Co-Share %
|
||
newCell = `<td class="input-with-percentage"><input type="text" class="right-align-input" id="co_share_per_${insurerCount}" name="co_share_per[]" oninput="validateRange(this); " onchange="co_share_percentage_calculation('${insurerCount}')" onkeypress="return onlyNumbers(event)"></td>`;
|
||
break;
|
||
case 7: // Non commissionable Premium amount %
|
||
newCell = `<td><input type="text" class="right-align-input" id="non_comm_per_amt_${insurerCount}" name="non_comm_per_amt[]" oninput="" onkeypress="return onlyNumbers(event)"></td>`;
|
||
break;
|
||
case 8: // Base Premium
|
||
newCell = `<td><input type="text" class="right-align-input" id="base_premium_${insurerCount}" name="base_premium[]" onchange="checkCDAmountForBasePremium(${insurerCount})" onkeypress="return onlyNumbers(event)"></td>`;
|
||
break;
|
||
case 9: // TP Premium
|
||
newCell = `<td><input type="text" class="right-align-input" id="tp_premium_${insurerCount}" name="tp_premium[]" oninput="" onkeypress="return onlyNumbers(event)"></td>`;
|
||
break;
|
||
case 10: // Ter Premium
|
||
newCell = `<td><input type="text" class="right-align-input" id="ter_premium_${insurerCount}" name="ter_premium[]" oninput="" onkeypress="return onlyNumbers(event)"></td>`;
|
||
break;
|
||
case 11: // co Premium
|
||
newCell = `<td><input type="text" class="right-align-input" id="co_premium_${insurerCount}" name="co_premium[]" oninput="" onkeypress="return onlyNumbers(event)"></td>`;
|
||
break;
|
||
case 12: // Co TP Premium
|
||
newCell = `<td><input type="text" class="right-align-input" id="co_tp_premium_${insurerCount}" name="co_tp_premium[]" oninput="" onkeypress="return onlyNumbers(event)"></td>`;
|
||
break;
|
||
case 13: // Co Ter Premium
|
||
newCell = `<td><input type="text" class="right-align-input" id="co_ter_premium_${insurerCount}" name="co_ter_premium[]" oninput="" onkeypress="return onlyNumbers(event)"></td>`;
|
||
break;
|
||
case 14: // CGST
|
||
newCell = `<td class="input-with-percentage"><input type="text" class="right-align-input" id="cgst_${insurerCount}" name="cgst[]" oninput="" onkeypress="return onlyNumbers(event)"></td>`;
|
||
break;
|
||
case 15: // SGST
|
||
newCell = `<td class="input-with-percentage"><input type="text" class="right-align-input" id="sgst_${insurerCount}" name="sgst[]" oninput="" onkeypress="return onlyNumbers(event)"></td>`;
|
||
break;
|
||
case 16: // IGST
|
||
newCell = `<td class="input-with-percentage"><input type="text" class="right-align-input" id="igst_${insurerCount}" name="igst[]" oninput="" onkeypress="return onlyNumbers(event)"></td>`;
|
||
break;
|
||
case 17: // GST Amount
|
||
newCell = `<td><input type="text" class="right-align-input" id="gst_amount_${insurerCount}" name="gst_amount[]" onchange="" onkeypress="return onlyNumbers(event)"></td>`;
|
||
break;
|
||
case 18: // Stamp Duty
|
||
newCell = `<td><input type="text" class="right-align-input" id="stamp_duty_${insurerCount}" name="stamp_duty[]" oninput="" onkeypress="return onlyNumbers(event)"></td>`;
|
||
break;
|
||
case 19: // Total
|
||
newCell = `<td><input type="text" class="readonly-color right-align-input" id="total_amt_${insurerCount}" name="total[]" readonly onkeypress="return onlyNumbers(event)"></td>`;
|
||
break;
|
||
case 20: // Agreed BP %
|
||
newCell = `<td class="input-with-percentage"><input type="text" class="right-align-input" id="agreed_bp_${insurerCount}" name="agreed_bp[]" oninput="validateRange(this); " onkeypress="return onlyNumbers(event)" ></td>`;
|
||
break;
|
||
case 21: // Agreed TP %
|
||
newCell = `<td class="input-with-percentage"><input type="text" class="right-align-input" id="agreed_tp_${insurerCount}" name="agreed_tp[]" oninput="validateRange(this); " onkeypress="return onlyNumbers(event)"></td>`;
|
||
break;
|
||
case 22: // Agreed Ter %
|
||
newCell = `<td class="input-with-percentage"><input type="text" class="right-align-input" id="agreed_ter_${insurerCount}" name="agreed_ter[]" oninput="validateRange(this); " onkeypress="return onlyNumbers(event)" ></td>`;
|
||
break;
|
||
case 23: // Standard BP %
|
||
newCell = `<td class="input-with-percentage"><input type="text" class="readonly-color right-align-input" id="standard_bp_${insurerCount}" name="standard_bp[]" onkeypress="return onlyNumbers(event)" readonly></td>`;
|
||
break;
|
||
case 24: // Standard TP %
|
||
newCell = `<td class="input-with-percentage"><input type="text" class="readonly-color right-align-input" id="standard_tp_${insurerCount}" name="standard_tp[]" onkeypress="return onlyNumbers(event)" readonly ></td>`;
|
||
break;
|
||
case 25: // Standard Ter %
|
||
newCell = `<td class="input-with-percentage"><input type="text" class="readonly-color right-align-input" id="standard_tep_${insurerCount}" name="standard_ter[]" onkeypress="return onlyNumbers(event)" readonly></td>`;
|
||
break;
|
||
case 26: // ID For Update
|
||
newCell = `<td><input type="hidden" name="co_share_id[]" id="co_share_id[]" onkeypress="return onlyNumbers(event)"></td>`;
|
||
break;
|
||
}
|
||
}
|
||
|
||
$(this).append(newCell);
|
||
|
||
let select = $('#follow_insurer_id_' + insurerCount);
|
||
let add_insurer_policy_type_id = $('#policy_type_id').val();
|
||
let category = insurer_category[add_insurer_policy_type_id] ?? null;
|
||
|
||
if(select && category){
|
||
appendInsurerByCategory(insurer_data, select, category);
|
||
}
|
||
|
||
$('#follow_insurer_id_' + insurerCount).select2();
|
||
|
||
|
||
var selectedOption = $('#policy_type_id').find('option:selected');
|
||
|
||
var ebp = selectedOption.data('ebp');
|
||
var etp = selectedOption.data('etp');
|
||
var etep = selectedOption.data('etep');
|
||
var iep = selectedOption.data('iep');
|
||
var itp = selectedOption.data('itp');
|
||
var itep = selectedOption.data('itep');
|
||
|
||
var bap = selectedOption.data('bap');
|
||
var allocg = selectedOption.data('allocg');
|
||
// console.log('allocg:', allocg);
|
||
|
||
|
||
var client_type_id = $('#client_type').val() ?? 1;
|
||
var is_co_pay_yes = $('#cop_yes').prop('checked') ? 1 : 0;
|
||
|
||
// do not remove this commented items
|
||
// if(bap == 'Fire' || bap == 'Marine Cargo' || bap == 'Marine Hull'){
|
||
// $('.hideter').show();
|
||
// $('.hidetp').hide();
|
||
|
||
// if(is_co_pay_yes == 1){
|
||
// $('.hidecoter').show()
|
||
// $('.hidecotp').hide()
|
||
// }else{
|
||
// $('.hidecoter').hide()
|
||
// $('.hidecotp').hide()
|
||
// }
|
||
// }else{
|
||
// if(bap == 'Motor'){
|
||
|
||
// $('.hidetp').show()
|
||
// $('.hideter').hide()
|
||
|
||
// if(is_co_pay_yes == 1){
|
||
// $('.hidecotp').show()
|
||
// $('.hidecoter').hide()
|
||
// }else{
|
||
// $('.hidecoter').hide()
|
||
// $('.hidecotp').hide()
|
||
// }
|
||
|
||
// }else{
|
||
// $('.hideter').hide()
|
||
// $('.hidetp').hide()
|
||
// $('.hidecoter').hide()
|
||
// $('.hidecotp').hide()
|
||
// }
|
||
// }
|
||
|
||
if(allocg == "EB"){
|
||
|
||
$('.hideter').hide();
|
||
$('.hidetp').hide();
|
||
$('.hidecoter').hide()
|
||
$('.hidecotp').hide()
|
||
|
||
} else if(allocg == "Non-EB"){
|
||
|
||
$('.hidetp').hide();
|
||
$('.hidecotp').hide();
|
||
|
||
$('.hideter').show();
|
||
if(is_co_pay_yes == 1){
|
||
$('.hidecoter').show();
|
||
}else{
|
||
$('.hidecoter').hide();
|
||
}
|
||
|
||
} else if(policy_type_id == 8){
|
||
|
||
$('.hideter').hide();
|
||
$('.hidecoter').hide();
|
||
|
||
$('.hidetp').show();
|
||
if(is_co_pay_yes == 1){
|
||
$('.hidecotp').show();
|
||
}else{
|
||
$('.hidecotp').hide();
|
||
}
|
||
|
||
} else{
|
||
|
||
if(bap == 'Fire' || bap == 'Marine Cargo' || bap == 'Marine Hull'){
|
||
$('.hideter').show();
|
||
if(is_co_pay_yes == 1){
|
||
$('.hidecoter').show();
|
||
}else{
|
||
$('.hidecoter').hide();
|
||
}
|
||
}else{
|
||
$('.hideter').hide();
|
||
}
|
||
}
|
||
|
||
// if(allocg == "EB"){
|
||
// $('.hideter').hide();
|
||
// $('.hidetp').hide();
|
||
// $('.hidecoter').hide()
|
||
// $('.hidecotp').hide()
|
||
// }else{
|
||
|
||
// $('.hidetp').show();
|
||
// if(is_co_pay_yes == 1){
|
||
// $('.hidecotp').show();
|
||
// }else{
|
||
// $('.hidecotp').hide();
|
||
// }
|
||
|
||
// if(bap == 'Fire' || bap == 'Marine Cargo' || bap == 'Marine Hull'){
|
||
// $('.hideter').show();
|
||
// if(is_co_pay_yes == 1){
|
||
// $('.hidecoter').show();
|
||
// }else{
|
||
// $('.hidecoter').hide();
|
||
// }
|
||
// }else{
|
||
// $('.hideter').hide();
|
||
// }
|
||
// }
|
||
|
||
var std_bp = 0;
|
||
var std_tp = 0;
|
||
var std_tep = 0;
|
||
|
||
if(client_type_id == 1){
|
||
std_bp = ebp;
|
||
std_tp = etp;
|
||
std_tep = etep;
|
||
}else{
|
||
std_bp = iep;
|
||
std_tp = itp;
|
||
std_tep = itep;
|
||
}
|
||
|
||
$('[name="standard_bp[]"]').val(std_bp);
|
||
$('[name="standard_tp[]"]').val(std_tp);
|
||
$('[name="standard_ter[]"]').val(std_tep);
|
||
|
||
// if(insurerCount > 1){
|
||
// $('.follow_insurer').prop('required', true);
|
||
// }else{
|
||
// $('.follow_insurer').prop('required', false);
|
||
// }
|
||
|
||
});
|
||
|
||
insurer_count_array.push(insurerCount);
|
||
|
||
// Add click event for delete button
|
||
// $('.delete-insurer').off('click').on('click', function() {
|
||
// const index = $(this).closest('th').index();
|
||
// let count_index = $(this).data('count');
|
||
// removeInsurerColumn(index, count_index);
|
||
// setTimeout(() => {
|
||
// getColumnIndexes();
|
||
// }, 2000);
|
||
// });
|
||
|
||
co_share_percentage_calculation(insurerCount, "add");
|
||
|
||
if (insurerCount === 0) {
|
||
$('.follow_insurer').prop('required', false);
|
||
} else {
|
||
$('.follow_insurer').prop('required', true);
|
||
}
|
||
|
||
var calc_policy_issue_date = flatpickr("#calc_policy_issue_date_" + insurerCount, {
|
||
dateFormat: "d/m/Y",
|
||
allowInput: false
|
||
});
|
||
}
|
||
|
||
function removeInsurerColumn(index, count_index) {
|
||
|
||
console.log('#################################### Remove Insurer Column ####################################');
|
||
|
||
// Remove the header
|
||
$('#insurerTable thead tr th').eq(index).remove();
|
||
|
||
// Remove the corresponding data cells in each row
|
||
let removedCoShareIds = [];
|
||
|
||
$('#insurerTable tbody tr').each(function() {
|
||
$(this).find('td').eq(index).remove();
|
||
let coShareId = $(this).find('td').eq(index).find('[name="co_share_id[]"]').val();
|
||
|
||
if (coShareId) {
|
||
removedCoShareIds.push(coShareId);
|
||
}
|
||
});
|
||
|
||
console.log('removedCoShareIds array', removedCoShareIds);
|
||
|
||
// Set the array as a comma-separated string in the hidden input
|
||
$('#remove_pt_co_id').val(removedCoShareIds.join(','));
|
||
console.log('remove_pt_co_id value', $('#remove_pt_co_id').val());
|
||
|
||
insurer_count_array = insurer_count_array.filter(item => item !== count_index);
|
||
co_share_percentage_calculation(null, "remove");
|
||
insurerCount--;
|
||
if (insurerCount === 0) {
|
||
$('.follow_insurer').prop('required', false);
|
||
} else {
|
||
$('.follow_insurer').prop('required', true);
|
||
}
|
||
|
||
console.log('#################################### END Remove Insurer Column ####################################');
|
||
|
||
}
|
||
|
||
function populateTable(dataArray, cd_ac_pk) {
|
||
|
||
console.log('#################################### Populate Table ####################################');
|
||
|
||
|
||
console.log('populateTable data', dataArray)
|
||
|
||
dataArray.forEach((data, index) => {
|
||
|
||
// Add a new insurer column for each entry in the data array
|
||
addInsurerColumn(); // This will add a new column dynamically
|
||
|
||
// let disable_td = disable_td ? true : false;
|
||
let disable_td = false;
|
||
if(data.record_count > 0){
|
||
disable_td = true;
|
||
}
|
||
|
||
console.log('disable_td', disable_td);
|
||
console.log('populate cd_ac_pk', cd_ac_pk);
|
||
|
||
|
||
if(data.co_share_type == 1){
|
||
if(index == 0) { index = 1;}
|
||
getCdAmount(cd_ac_pk, index);
|
||
}
|
||
|
||
// Populate the fields with the provided data
|
||
$('#insurerTable tbody tr').each(function(rowIndex, row) {
|
||
const cell = $(row).find('td').eq(insurerCount); // Get the newly added column by `insurerCount`
|
||
|
||
let insurer = data.insurer_branch_id + '-' + data.insurer_id;
|
||
|
||
if(role_id == 1 || role_id == 5 || team_id.includes('6') || team_id.includes('4')){
|
||
switch (rowIndex) {
|
||
case 0: // Insurer selection
|
||
cell.find('select').val(insurer).change().toggleClass('readonly-select', !!disable_td);
|
||
break;
|
||
case 1: // Is Leader?
|
||
cell.find('input[type="checkbox"]').prop('checked', data.co_share_type === '1').change().toggleClass('readonly-select', !!disable_td);
|
||
break;
|
||
case 2: // CD Account Number
|
||
cell.find('select').val(cd_ac_pk);
|
||
var selectElement = cell.find('select');
|
||
console.log('selectElement', selectElement);
|
||
selectElement.val(cd_ac_pk).prop('selected', true);
|
||
selectElement.toggleClass('readonly-select', !!disable_td);
|
||
setTimeout(function(){
|
||
console.log('selectElement setTimeout', selectElement);
|
||
selectElement.find('option[value="' + cd_ac_pk + '"]').prop('selected', true);
|
||
selectElement.toggleClass('readonly-select', !!disable_td)
|
||
}, 2000);
|
||
break;
|
||
case 3: // CD AMOUNT
|
||
console.log('------- CD AMOUNT -------')
|
||
break;
|
||
case 4: // follower_policy_no
|
||
cell.find('input').val(data.follower_policy_no).toggleClass('readonly-select', !!disable_td);
|
||
break;
|
||
case 5: // pt_policy_issue_date
|
||
cell.find('input').val(data.pt_policy_issue_date).toggleClass('readonly-select', !!disable_td);
|
||
break;
|
||
case 6: // Co-Share %
|
||
cell.find('input').val(data.co_share_per).toggleClass('readonly-select', !!disable_td);
|
||
break;
|
||
case 7: // non_comm_per_amt
|
||
cell.find('input').val(data.non_comm_per_amt);
|
||
break;
|
||
case 8: // Base Premium
|
||
cell.find('input').val(data.bp_amt).toggleClass('readonly-select', !!disable_td);
|
||
break;
|
||
case 9: // TP Premium
|
||
cell.find('input').val(data.tp_amt).toggleClass('readonly-select', !!disable_td);
|
||
break;
|
||
case 10: // Ter Premium
|
||
cell.find('input').val(data.tep_amt).toggleClass('readonly-select', !!disable_td);
|
||
break;
|
||
case 11: // Co Premium
|
||
cell.find('input').val(data.cop_amt).toggleClass('readonly-select', !!disable_td);
|
||
break;
|
||
case 12: // Co TP Premium
|
||
cell.find('input').val(data.cotp_amt).toggleClass('readonly-select', !!disable_td);
|
||
break;
|
||
case 13: // Co Ter Premium
|
||
cell.find('input').val(data.cotep_amt).toggleClass('readonly-select', !!disable_td);
|
||
break;
|
||
case 14: // CGST
|
||
cell.find('input').val(data.bp_cgst).toggleClass('readonly-select', !!disable_td);
|
||
break;
|
||
case 15: // SGST
|
||
cell.find('input').val(data.bp_sgst).toggleClass('readonly-select', !!disable_td);
|
||
break;
|
||
case 16: // IGST
|
||
cell.find('input').val(data.bp_igst).toggleClass('readonly-select', !!disable_td);
|
||
break;
|
||
case 17: // GST Amount
|
||
cell.find('input').val(data.bp_gst_amt).toggleClass('readonly-select', !!disable_td);
|
||
break;
|
||
case 18: // Stamp Duty
|
||
cell.find('input').val(data.stamp_duty).toggleClass('readonly-select', !!disable_td);
|
||
break;
|
||
case 19: // Total
|
||
cell.find('input').val(data.amount).toggleClass('readonly-select', !!disable_td);
|
||
break;
|
||
case 20: // Agreed BP %
|
||
cell.find('input').val(data.agreed_bp_per).toggleClass('readonly-select', !!disable_td);
|
||
break;
|
||
case 21: // Agreed TP %
|
||
cell.find('input').val(data.agreed_tp_per).toggleClass('readonly-select', !!disable_td);
|
||
break;
|
||
case 22: // Agreed Ter %
|
||
cell.find('input').val(data.agreed_tep_per).toggleClass('readonly-select', !!disable_td);
|
||
break;
|
||
case 23: // Agreed Amount
|
||
cell.find('input').val(data.agreed_amt).toggleClass('readonly-select', !!disable_td);
|
||
break;
|
||
case 24: // Standard BP %
|
||
cell.find('input').val(data.standerd_bp_per).toggleClass('readonly-select', !!disable_td);
|
||
break;
|
||
case 25: // Standard TP %
|
||
cell.find('input').val(data.standerd_tp_per).toggleClass('readonly-select', !!disable_td);
|
||
break;
|
||
case 26: // Standard Ter %
|
||
cell.find('input').val(data.standerd_tep_per).toggleClass('readonly-select', !!disable_td);
|
||
break;
|
||
case 27: // Actual BP Amount
|
||
cell.find('input').val(data.actual_bp_amount);
|
||
break;
|
||
case 28: // Actual TP Amount
|
||
cell.find('input').val(data.actual_tp_amount);
|
||
break;
|
||
case 29: // Actual Ter Amount
|
||
cell.find('input').val(data.actual_tep_amount);
|
||
break;
|
||
case 30: // Actual BP %
|
||
cell.find('input').val(data.actual_bp_percentage);
|
||
break;
|
||
case 31: // Actual TP %
|
||
cell.find('input').val(data.actual_tp_percentage);
|
||
break;
|
||
case 32: // Actual Ter %
|
||
cell.find('input').val(data.actual_tep_percentage);
|
||
break;
|
||
case 33: // Actual BP Brokerage Amount
|
||
cell.find('input').val(data.actual_bp_brokerage_amount);
|
||
break;
|
||
case 34: // Actual TP Brokerage Amount
|
||
cell.find('input').val(data.actual_tp_brokerage_amount);
|
||
break;
|
||
case 35: // Actual Ter Brokerage Amount
|
||
cell.find('input').val(data.actual_tep_brokerage_amount);
|
||
break;
|
||
case 36: // Expected Amount
|
||
cell.find('input').val(data.exp_amt);
|
||
break;
|
||
// case 34: // Variance
|
||
// cell.find('input').val(data.variance);
|
||
// break;
|
||
case 37: // Co-share ID (hidden field)
|
||
cell.find('input[type="hidden"]').val(data.id);
|
||
break;
|
||
}
|
||
}else if(team_id.includes('3') || team_id.includes('8')){
|
||
|
||
switch (rowIndex) {
|
||
case 0: // Insurer selection
|
||
cell.find('select').val(insurer).change().toggleClass('readonly-select', !!disable_td);
|
||
break;
|
||
case 1: // Is Leader?
|
||
cell.find('input[type="checkbox"]').prop('checked', data.co_share_type === '1').change().toggleClass('readonly-select', !!disable_td);
|
||
break;
|
||
case 2: // CD Account Number
|
||
cell.find('select').val(cd_ac_pk);
|
||
var selectElement = cell.find('select');
|
||
console.log('selectElement', selectElement);
|
||
selectElement.val(cd_ac_pk).prop('selected', true);
|
||
selectElement.toggleClass('readonly-select', !!disable_td)
|
||
setTimeout(function(){
|
||
console.log('selectElement setTimeout', selectElement);
|
||
selectElement.find('option[value="' + cd_ac_pk + '"]').prop('selected', true);
|
||
selectElement.toggleClass('readonly-select', !!disable_td)
|
||
}, 2000)
|
||
break;
|
||
case 3: // CD AMOUNT
|
||
console.log('------- CD AMOUNT -------')
|
||
break;
|
||
case 4: // follower_policy_no
|
||
cell.find('input').val(data.follower_policy_no).toggleClass('readonly-select', !!disable_td);
|
||
break;
|
||
case 5: // pt_policy_issue_date
|
||
cell.find('input').val(data.pt_policy_issue_date).toggleClass('readonly-select', !!disable_td);
|
||
break;
|
||
case 6: // co_share_per
|
||
cell.find('input').val(data.co_share_per).toggleClass('readonly-select', !!disable_td);
|
||
break;
|
||
case 7: // non_comm_per_amt
|
||
cell.find('input').val(data.non_comm_per_amt);
|
||
break;
|
||
case 8: // Base Premium
|
||
cell.find('input').val(data.bp_amt).toggleClass('readonly-select', !!disable_td);
|
||
break;
|
||
case 9: // TP Premium
|
||
cell.find('input').val(data.tp_amt).toggleClass('readonly-select', !!disable_td);
|
||
break;
|
||
case 10: // Ter Premium
|
||
cell.find('input').val(data.tep_amt).toggleClass('readonly-select', !!disable_td);
|
||
break;
|
||
case 11: // Co Premium
|
||
cell.find('input').val(data.cop_amt).toggleClass('readonly-select', !!disable_td);
|
||
break;
|
||
case 12: // Co TP Premium
|
||
cell.find('input').val(data.cotp_amt).toggleClass('readonly-select', !!disable_td);
|
||
break;
|
||
case 13: // Co Ter Premium
|
||
cell.find('input').val(data.cotep_amt).toggleClass('readonly-select', !!disable_td);
|
||
break;
|
||
case 14: // CGST
|
||
cell.find('input').val(data.bp_cgst).toggleClass('readonly-select', !!disable_td);
|
||
break;
|
||
case 15: // SGST
|
||
cell.find('input').val(data.bp_sgst).toggleClass('readonly-select', !!disable_td);
|
||
break;
|
||
case 16: // IGST
|
||
cell.find('input').val(data.bp_igst).toggleClass('readonly-select', !!disable_td);
|
||
break;
|
||
case 17: // GST Amount
|
||
cell.find('input').val(data.bp_gst_amt).toggleClass('readonly-select', !!disable_td);
|
||
break;
|
||
case 18: // Stamp Duty
|
||
cell.find('input').val(data.stamp_duty).toggleClass('readonly-select', !!disable_td);
|
||
break;
|
||
case 19: // Total
|
||
cell.find('input').val(data.amount).toggleClass('readonly-select', !!disable_td);
|
||
break;
|
||
case 20: // Agreed BP %
|
||
cell.find('input').val(data.agreed_bp_per).toggleClass('readonly-select', !!disable_td);
|
||
break;
|
||
case 21: // Agreed TP %
|
||
cell.find('input').val(data.agreed_tp_per).toggleClass('readonly-select', !!disable_td);
|
||
break;
|
||
case 22: // Agreed Ter %
|
||
cell.find('input').val(data.agreed_tep_per).toggleClass('readonly-select', !!disable_td);
|
||
break;
|
||
case 23: // Standard BP %
|
||
cell.find('input').val(data.standerd_bp_per).toggleClass('readonly-select', !!disable_td);
|
||
break;
|
||
case 24: // Standard TP %
|
||
cell.find('input').val(data.standerd_tp_per).toggleClass('readonly-select', !!disable_td);
|
||
break;
|
||
case 25: // Standard Ter %
|
||
cell.find('input').val(data.standerd_tep_per).toggleClass('readonly-select', !!disable_td);
|
||
break;
|
||
case 26: // Co-share ID (hidden field)
|
||
cell.find('input[type="hidden"]').val(data.id);
|
||
break;
|
||
}
|
||
|
||
}else {
|
||
}
|
||
});
|
||
|
||
if(index != 0){
|
||
// if(data.co_share_type != 0 && data.co_share_type != 1){
|
||
// let co_share_index = index + 1;
|
||
// select_leader_disable_premium_amt_in_edit(co_share_index);
|
||
// }
|
||
select_leader_disable_premium_amt_in_edit();
|
||
|
||
}
|
||
});
|
||
|
||
// $('input:disabled, select:disabled, textarea:disabled').addClass('readonly-color');
|
||
|
||
console.log('#################################### END Populate Table ####################################');
|
||
|
||
}
|
||
|
||
$(document).on('click', '.delete-insurer', function() {
|
||
const index = $(this).closest('th').index();
|
||
const count_index = $(this).data('count') || $(this).attr('data-count'); // Ensure data attribute is retrieved
|
||
removeInsurerColumn(index, count_index);
|
||
getColumnIndexes(1); // Remove setTimeout unless necessary
|
||
});
|
||
|
||
//-----------------------------------------------------------------------------------------------------------
|
||
|
||
function getURLParamsForReport() {
|
||
const params = new URLSearchParams(window.location.search);
|
||
const pt_id = params.get('pt_id') ?? 0;
|
||
|
||
// ✅ Get the previous page URL
|
||
const previousUrl = document.referrer || '';
|
||
|
||
console.log("PT ID:", pt_id);
|
||
console.log("Previous Page URL:", previousUrl);
|
||
|
||
if (pt_id != 0) {
|
||
hide_list_show_add();
|
||
setTimeout(() =>
|
||
getPolicyTransactionDataForEdit(pt_id),
|
||
1500); // Reduced timeout
|
||
} else {
|
||
show_list_hide_add();
|
||
}
|
||
|
||
if(previousUrl != "" && pt_id != 0){
|
||
redirect_url = previousUrl;
|
||
$('#btnAdd').attr('href', previousUrl);
|
||
}
|
||
|
||
console.log('getURLParamsForReport pt_id', pt_id); // Retain the log if necessary
|
||
}
|
||
|
||
function validateInput(input, table, field){
|
||
|
||
let value = $(input).val();
|
||
let label = $(input).closest('.form-group').find('label').text().replace('*', '').trim();
|
||
|
||
let message = "Value is duplicate!";
|
||
if(label){
|
||
message = label + " already exists!";
|
||
}
|
||
if(table == 'vehicle' && field == "vehicle_no"){
|
||
message = "Vehicle Number is already exists!";
|
||
}
|
||
|
||
checkDuplicateTableFieldValue(table, field, value, function(isDuplicate) {
|
||
if (isDuplicate) {
|
||
toastr.warning(message, 'Warning');
|
||
$(input).val('')
|
||
if(table == 'vehicle'){
|
||
resetVehicleField();
|
||
console.log("$('#vehicle_form_submit_btn_id_for_disable')", $('#vehicle_form_submit_btn_id_for_disable'));
|
||
console.log($('#vehicle_form_submit_btn_id_for_disable').length);
|
||
$('#vehicle_form_submit_btn').attr('disabled', true);
|
||
}
|
||
} else{
|
||
$('#vehicle_form_submit_btn').removeAttr('disabled', false);
|
||
}
|
||
});
|
||
|
||
}
|
||
|
||
function saveFormDataToLocalStorage(formSelector, storageKey) {
|
||
// Initialize an empty object to store form data
|
||
let formData = {};
|
||
|
||
// Iterate over all inputs in the form
|
||
$(formSelector + " :input").each(function() {
|
||
let input = $(this);
|
||
let name = input.attr("name"); // Get the input's name attribute
|
||
let value = input.val(); // Get the input's value
|
||
|
||
if (name) {
|
||
if (name !== 'owner' && name !== 'branch_id') {
|
||
formData[name] = value; // Add to the formData object if the input has a name
|
||
}
|
||
}
|
||
|
||
});
|
||
|
||
// Save the form data to local storage with the provided key
|
||
localStorage.setItem(storageKey, JSON.stringify(formData));
|
||
|
||
console.log("Form data saved to local storage:", formData);
|
||
}
|
||
|
||
function setFormDataFromLocalStorage(formSelector, storageKey) {
|
||
// Retrieve the saved form data from localStorage
|
||
let savedData = JSON.parse(localStorage.getItem(storageKey));
|
||
|
||
// If there's no saved data, do nothing
|
||
if (!savedData) return;
|
||
|
||
// Iterate through the saved data and set the form inputs accordingly
|
||
$.each(savedData, function(name, value) {
|
||
let input = $(formSelector + " :input[name='" + name + "']");
|
||
|
||
// Check if the input is a checkbox or radio button
|
||
if (input.is(':checkbox') || input.is(':radio')) {
|
||
input.prop('checked', value); // Set the checked property
|
||
} else {
|
||
input.val(value); // Set the value for other input types
|
||
}
|
||
});
|
||
|
||
console.log("Form data loaded from local storage:", savedData);
|
||
}
|
||
|
||
function checkCDAmountForBasePremium(input) {
|
||
|
||
console.log('#################################### Check CD Amount For Base Premium ####################################');
|
||
console.log(input)
|
||
|
||
let policy_type_id = $('#policy_type_id').val();
|
||
console.log("policy_type_id ", policy_type_id);
|
||
|
||
let client_type = $('#client_type').val();
|
||
console.log('client type', client_type);
|
||
|
||
let base_premium = $('#base_premium_' +input).val();
|
||
console.log("base_premium:", base_premium);
|
||
|
||
let tp_premium = $('#tp_premium_' +input).val();
|
||
console.log("tp_premium:", tp_premium);
|
||
|
||
// return;
|
||
|
||
if(client_type == 1 && policy_type_id > 7){
|
||
|
||
let current_total_amt = $('#base_cd_amount').val() ?? 0;
|
||
console.log('current_total_amt', current_total_amt);
|
||
|
||
// Extract increment value from input ID
|
||
// let input_id = input.id;
|
||
// console.log("input_id:", input_id);
|
||
|
||
// let increment = input_id.split("_").pop();
|
||
// console.log("increment:", increment);
|
||
|
||
let total_amt = $('#total_amt_' + input).val();
|
||
console.log("total_amt:", total_amt);
|
||
|
||
let differnce_bp_amt = 0;
|
||
|
||
if (total_amt == current_total_amt) {
|
||
differnce_bp_amt = 0;
|
||
} else if(total_amt < current_total_amt) {
|
||
differnce_bp_amt = total_amt - current_total_amt;
|
||
console.log("differnce_bp_amt 1:", differnce_bp_amt);
|
||
$('#cd_amt_changed').prop('disabled', false).val(differnce_bp_amt);
|
||
return;
|
||
} else {
|
||
differnce_bp_amt = total_amt - current_total_amt;
|
||
console.log("differnce_bp_amt 2:", differnce_bp_amt);
|
||
total_amt = differnce_bp_amt;
|
||
}
|
||
|
||
console.log("differnce_bp_amt:", differnce_bp_amt);
|
||
console.log("total_amt:", total_amt);
|
||
|
||
// Get the corresponding `cd_ac_no` value
|
||
let cd_ac_no = $('#cd_ac_no_' + input).val();
|
||
console.log("cd_ac_no:", cd_ac_no);
|
||
|
||
// Validate inputs
|
||
if (!base_premium || !cd_ac_no) {
|
||
toastr.warning('Base premium or CD account number is missing', 'Warning');
|
||
return;
|
||
}
|
||
|
||
let url = '<?= base_url('util/checkCDAmountForBasePremium') ?>';
|
||
|
||
// Data to send in the AJAX request
|
||
let requestData = {
|
||
base_premium: total_amt,
|
||
cd_ac_no: cd_ac_no
|
||
};
|
||
|
||
// Send AJAX request
|
||
sendAjaxRequestForGlobal(url, 'GET', requestData, function(response) {
|
||
|
||
console.log('#################################### Check CD Amount For Base Premium Response ####################################');
|
||
|
||
console.log('Data fetched successfully:', response);
|
||
|
||
if (response.status) {
|
||
if (!response.base_premium_greater_than_balance) {
|
||
console.log('Base premium is less than or equal to CD balance:', 'Success');
|
||
if(differnce_bp_amt !== 0){
|
||
$('#cd_amt_changed').prop('disabled', false).val(differnce_bp_amt);
|
||
}else{
|
||
$('#cd_amt_changed').prop('disabled', true).val("");
|
||
}
|
||
$('#pt_form_sumbit_handler').val(1);
|
||
} else {
|
||
toastr.warning('Base premium greater than CD Amount', 'Warning');
|
||
$('#cd_amt_changed').prop('disabled', true).val("");
|
||
$('#pt_form_sumbit_handler').val(0);
|
||
// $(input).val("0")
|
||
}
|
||
} else {
|
||
toastr.error(response.message || 'Unable to fetch data', 'Error');
|
||
}
|
||
|
||
console.log('#################################### End Check CD Amount For Base Premium Response ####################################');
|
||
|
||
}, function(xhr, status, error) {
|
||
console.error('Error fetching data:', error);
|
||
console.error(xhr.responseText);
|
||
toastr.error('An error occurred while checking the CD amount.', 'Error');
|
||
});
|
||
|
||
}else{
|
||
console.log("Skip the Ajax Call these are group policies");
|
||
}
|
||
|
||
console.log('#################################### END Check CD Amount For Base Premium ####################################');
|
||
|
||
}
|
||
|
||
function getCdAmount(cd_ac_pk, increment){
|
||
|
||
console.log('#################################### Get CD Amount ####################################');
|
||
|
||
// increment = increment + 1
|
||
console.log('cd_ac_pk', cd_ac_pk);
|
||
console.log('increment', increment);
|
||
|
||
let url = '<?= base_url('util/getCDAmount') ?>';
|
||
|
||
// Data to send in the AJAX request
|
||
let requestData = {
|
||
cd_ac_pk: cd_ac_pk
|
||
};
|
||
|
||
// Send AJAX request
|
||
sendAjaxRequestForGlobal(url, 'GET', requestData, function(response) {
|
||
|
||
console.log('Data fetched successfully:', response);
|
||
|
||
if (response.status == true) {
|
||
if(!response.data.balance){
|
||
$('#cd_current_balance_'+increment).val(0.00);
|
||
}else{
|
||
$('#cd_current_balance_'+increment).val(response.data.balance);
|
||
}
|
||
} else{
|
||
$('#cd_current_balance_'+increment).val(0.00);
|
||
}
|
||
|
||
}, function(xhr, status, error) {
|
||
console.error('Error fetching data:', error);
|
||
console.error(xhr.responseText);
|
||
toastr.error('An error occurred while checking the CD amount.', 'Error');
|
||
});
|
||
|
||
console.log('#################################### END Get CD Amount ####################################');
|
||
|
||
}
|
||
|
||
$('#bro_payable_by').on('change', function(){
|
||
|
||
var columnIndexes = [];
|
||
$('#insurerTable thead th').each(function(index) {
|
||
if(index == 0){
|
||
console.log("Premium Table columnIndexes is ", index);
|
||
}else{
|
||
amountCalculation(index);
|
||
}
|
||
columnIndexes.push(index);
|
||
});
|
||
});
|
||
|
||
$(document).on('change', '#insurerTable input, #insurerTable select, #insurerTable textarea', function() {
|
||
console.log('Changed in table:', $(this).attr('name'), 'Value:', $(this).val());
|
||
getColumnIndexes(0, $(this).attr('name'))
|
||
});
|
||
|
||
function getColumnIndexes(count = 0, name = null) {
|
||
$('#insurerTable thead th').each(function(index) {
|
||
if (index === 0) {
|
||
console.log("Premium Table columnIndexes is", index);
|
||
} else {
|
||
|
||
amountCalculation(index, name);
|
||
|
||
if(count == 1){
|
||
amountCalculation(index);
|
||
}
|
||
co_share_percentage_calculation(index);
|
||
}
|
||
});
|
||
}
|
||
|
||
$('#new_vehicle_switch').change(function () {
|
||
if ($(this).is(':checked')) {
|
||
$('#modal_vehicle_no').prop('required', false);
|
||
$('label[for="modal_vehicle_no"] span.text-danger').remove(); // Remove the asterisk
|
||
} else {
|
||
$('#modal_vehicle_no').prop('required', true);
|
||
// Add asterisk only if not already present
|
||
if ($('label[for="modal_vehicle_no"] span.text-danger').length === 0) {
|
||
$('label[for="modal_vehicle_no"]').append('<span class="text-danger">*</span>');
|
||
}
|
||
}
|
||
});
|
||
|
||
|
||
// ---------------------------------------------------------------------------------------------------------------
|
||
|
||
function toggleClient(input) {
|
||
let btn = $("#vehicle_client_btn");
|
||
let client_type = $('#owner_client_type').val();
|
||
|
||
// if (btn.text().trim() === "New Client") {
|
||
// btn.text("Existing Client");
|
||
// console.log("✅ Switched to Existing Client");
|
||
// $('.new_client').show();
|
||
// $('.old_client').hide();
|
||
// $(".old_client").find("select, input, textarea").val("").prop("required", false);
|
||
// $(".new_client").find("select, input, textarea").val("").prop("required", true);
|
||
// $('#owner').select2();
|
||
// $('#owner_branch').select2();
|
||
|
||
// } else {
|
||
// btn.text("New Client");
|
||
// console.log("✅ Switched to New Client");
|
||
// $('.new_client').hide();
|
||
// $('.old_client').show();
|
||
// $(".old_client").find("select, input, textarea").prop("required", true);
|
||
// $(".new_client").find("select, input, textarea").val("").prop("required", false);
|
||
// $('#owner').select2();
|
||
// $('#owner_branch').select2();
|
||
|
||
// }
|
||
|
||
if($(input).is(":checked")){
|
||
|
||
if(client_type == 1){
|
||
$('.new_client').show();
|
||
$('.old_client').hide();
|
||
$(".old_client").find("select, input, textarea").val("").prop("required", false);
|
||
$(".new_client").find("select, input, textarea").val("").prop("required", true);
|
||
}else{
|
||
$('.new_client').show();
|
||
$('.old_client').hide();
|
||
$(".old_client").find("select, input, textarea").val("").prop("required", false);
|
||
$(".new_client").find("select, input, textarea").val("").prop("required", true);
|
||
$('.v_group_client').hide();
|
||
$('.v_individual_client').show();
|
||
$(".v_group_client").find("select, input, textarea").val("").prop("required", true);
|
||
$(".v_individual_client").find("select, input, textarea").val("").prop("required", true);
|
||
}
|
||
|
||
$('#owner').select2();
|
||
$('#owner_branch').select2();
|
||
|
||
}else {
|
||
|
||
if(client_type == 1){
|
||
$('.new_client').hide();
|
||
$('.old_client').show();
|
||
$(".old_client").find("select, input, textarea").prop("required", true);
|
||
$(".new_client").find("select, input, textarea").val("").prop("required", false);
|
||
}else{
|
||
$('.new_client').hide();
|
||
$('.old_client').show();
|
||
$(".old_client").find("select, input, textarea").prop("required", true);
|
||
$(".new_client").find("select, input, textarea").val("").prop("required", false);
|
||
$('.old_group_client').hide();
|
||
$(".old_group_client").find("select, input, textarea").val("").prop("required", false);
|
||
}
|
||
$('#owner').select2();
|
||
$('#owner_branch').select2();
|
||
}
|
||
toggleRequiredWithAsterisk('#mobile', false);
|
||
toggleRequiredWithAsterisk('#gst', false);
|
||
}
|
||
|
||
function removeVehicleForm(){
|
||
$('#vehicle_row_div').empty();
|
||
$('#actcual_clients').show();
|
||
let status = $('#policy_status').val();
|
||
$('#pre_sales_row').show();
|
||
$('#submitButton').show();
|
||
// if(status == "completed"){
|
||
$('#sales_row').show();// REF : Venkatesh R - Status html Remove. so i removed the 'if'.
|
||
// }
|
||
}
|
||
|
||
function removeClientForm(){
|
||
$('#client_row_div').empty();
|
||
let status = $('#policy_status').val();
|
||
$('#pre_sales_row').show();
|
||
$('#submitButton').show();
|
||
// if(status == "completed"){
|
||
$('#sales_row').show();// REF : Venkatesh R - Status html Remove. so i removed the 'if'.
|
||
// }
|
||
}
|
||
|
||
function getVehicleFormData() {
|
||
|
||
console.log("🔹 Collecting Vehicle Form Data...");
|
||
let vhno = $('#modal_vehicle_no').val();
|
||
let rc = $('#rc').val();
|
||
let client_type = $('#client_type').val();
|
||
let vehicle_no_validation = $('#vehicle_no_validation').val();
|
||
|
||
|
||
if (vhno === "" && rc === "") {
|
||
toastr.warning("Please enter any one of these: Vehicle No or Chassis No", "Warning");
|
||
return;
|
||
}
|
||
|
||
if(vehicle_no_validation == 1){
|
||
toastr.warning("Invalid Vehicle Number Format", "Warning");
|
||
return;
|
||
}
|
||
|
||
var $form = $('#vehicle_form_row_div');
|
||
var isValid = $form.parsley().validate();
|
||
|
||
if (!isValid) {
|
||
console.log("❌ Validation failed for Vehicle Form section");
|
||
|
||
// Get all invalid fields
|
||
var invalidFields = $form.parsley().fields.filter(function (field) {
|
||
return !field.isValid();
|
||
});
|
||
|
||
invalidFields.forEach(function (field, index) {
|
||
console.log(
|
||
"🚫 Invalid Field " + (index + 1) + ":",
|
||
field.$element.attr('name') || field.$element.attr('id') || field.$element
|
||
);
|
||
});
|
||
|
||
return false;
|
||
}
|
||
|
||
let data = {};
|
||
$("#vehicle_form_row_div").find("input, select, textarea").each(function () {
|
||
let name = $(this).attr("name");
|
||
let value = $.trim($(this).val());
|
||
|
||
if (name) {
|
||
data[name] = value;
|
||
console.log("✅ Added field:", name, "=", value);
|
||
}
|
||
});
|
||
// data["client_type"] = client_type;
|
||
|
||
console.log("📌 Final Data Object:", data);
|
||
|
||
let url = '<?= base_url("util/createVehicleWithMinimalDataForBDS"); ?>';
|
||
|
||
$('.loader').fadeIn();
|
||
$('.loader-mask').fadeIn();
|
||
|
||
// Send AJAX request
|
||
sendAjaxRequestForGlobal(url, 'POST', data, function(response) {
|
||
console.log('Data fetched successfully:', response);
|
||
|
||
$('.loader').fadeOut();
|
||
$('.loader-mask').delay(350).fadeOut('slow');
|
||
|
||
if (response.status == true) {
|
||
getClientAndBranchAndPolicy(false);
|
||
toastr.success(response.message, 'Success');
|
||
appendClients(response.clients, response.client_id);
|
||
appendVehicles(response.vehicles, response.vehicle_id);
|
||
appendBranch(response.branches, response.branch_id);
|
||
if(response.data.client_type == 1){
|
||
$('.branchdiv').show();
|
||
$('#table_tr_34').show();
|
||
$('#table_tr_37').show();
|
||
$("select[name='cd_ac_no_for_child[]']").attr("required", true);
|
||
}else{
|
||
$('.branchdiv').hide();
|
||
$('#table_tr_34').hide();
|
||
$('#table_tr_37').hide();
|
||
$("select[name='cd_ac_no_for_child[]']").removeAttr("required");
|
||
}
|
||
$('#client_type').val(response.data?.client_type ?? "").trigger('change');
|
||
} else {
|
||
toastr.warning(response.message, 'Warning');
|
||
}
|
||
|
||
$('#client_row_div').empty();
|
||
$('#vehicle_row_div').empty();
|
||
$('#actcual_clients').show();
|
||
let status = $('#policy_status').val();
|
||
$('#pre_sales_row').show();
|
||
$('#submitButton').show();
|
||
// if(status == "completed"){
|
||
$('#sales_row').show(); // REF : Venkatesh R - Status html Remove. so i removed the 'if'.
|
||
// }
|
||
|
||
}, function(xhr, status, error) {
|
||
console.error('Error fetching data:', error);
|
||
console.error(xhr.responseText);
|
||
toastr.error('An error occurred while checking the CD amount.', 'Error');
|
||
$('.loader').fadeOut();
|
||
$('.loader-mask').delay(350).fadeOut('slow');
|
||
});
|
||
}
|
||
|
||
function getClientFormData() {
|
||
|
||
let client_type = $('#client_type').val();
|
||
console.log("🔹 Collecting Client Form Data...");
|
||
|
||
var isValid = $('#client_form_row_div').parsley().validate();
|
||
|
||
if (!isValid) {
|
||
console.log("❌ Validation failed for Client Form section");
|
||
return false;
|
||
}
|
||
|
||
let data = {};
|
||
$("#client_form_row_div").find("input, select, textarea").each(function () {
|
||
let name = $(this).attr("name");
|
||
let value = $.trim($(this).val());
|
||
|
||
if (name) {
|
||
data[name] = value;
|
||
console.log("✅ Added field:", name, "=", value);
|
||
}
|
||
});
|
||
data["client_type"] = client_type;
|
||
|
||
console.log("📌 Final Data Object:", data);
|
||
|
||
let url = '<?= base_url("util/createClientWithMinimalData"); ?>';
|
||
|
||
$('.loader').fadeIn();
|
||
$('.loader-mask').fadeIn();
|
||
|
||
// Send AJAX request
|
||
sendAjaxRequestForGlobal(url, 'POST', data, function(response) {
|
||
console.log('Data fetched successfully:', response);
|
||
|
||
$('.loader').fadeOut();
|
||
$('.loader-mask').delay(350).fadeOut('slow');
|
||
|
||
if (response.status == true) {
|
||
getClientAndBranchAndPolicy(false);
|
||
toastr.success(response.message, 'Success');
|
||
appendClients(response.clients, response.client_id);
|
||
appendBranch(response.branches, response.branch_id);
|
||
} else {
|
||
toastr.warning(response.message, 'Warning');
|
||
}
|
||
|
||
$('#client_row_div').empty();
|
||
$('#vehicle_row_div').empty();
|
||
|
||
let status = $('#policy_status').val();
|
||
$('#pre_sales_row').show();
|
||
$('#submitButton').show();
|
||
// if(status == "completed"){
|
||
$('#sales_row').show(); // REF : Venkatesh R - Status html Remove. so i removed the 'if' Submit la locked. "Empty field ID: Empty field ID: policy_issue_date"
|
||
// }
|
||
|
||
}, function(xhr, status, error) {
|
||
console.error('Error fetching data:', error);
|
||
console.error(xhr.responseText);
|
||
toastr.error('An error occurred while checking the CD amount.', 'Error');
|
||
$('.loader').fadeOut();
|
||
$('.loader-mask').delay(350).fadeOut('slow');
|
||
|
||
});
|
||
|
||
|
||
}
|
||
|
||
function appendVehicleForm(){
|
||
$('#vehicle_row_div').empty();
|
||
|
||
let html = `
|
||
<div class="col-md-12">
|
||
<div class="form-section">
|
||
<div id="vehicle_form_row_div" data-parsley-validate>
|
||
<h4 class="m-1">
|
||
Add New Vehicle
|
||
<a class="text-dark float-right" aria-expanded="true">
|
||
<i class="mdi mdi-close" style="font-size: 28px;" onclick="removeVehicleForm()"></i>
|
||
</a>
|
||
</h4>
|
||
|
||
<div class="row">
|
||
|
||
<div class="form-group col-md-2">
|
||
<label class="switch" style="position: relative;top: 32px;left: 20px;">
|
||
<input id="vehicle_client_btn" type="checkbox" name="vehicle_client_btn" onchange="toggleClient(this)">
|
||
<span class="slider round" style="height: 27px;"></span>
|
||
</label>
|
||
|
||
<label for="vehicle_client_btn" style="position: relative;top: 33px;left: 25px;"> New Client </label>
|
||
</div>
|
||
|
||
<!-- <div class="form-group col-md-3">
|
||
<label for="modal_vehicle_no">Vehicle No</label>
|
||
<input type="text" class="form-control" id="modal_vehicle_no" name="vehicle_no"
|
||
placeholder="Enter Vehicle No"
|
||
onchange="validateInput(this, 'vehicle', 'vehicle_no')">
|
||
</div> -->
|
||
|
||
<div class="form-group col-md-4">
|
||
<label for="modal_vehicle_no">
|
||
Vehicle No
|
||
<small style="font-size: x-small;">( Normal: AA##AA#### | Bharat: ##BH####AA )</small>
|
||
</label>
|
||
<div class="vehicle-input-wrapper">
|
||
<div class="vehicle-otp-container" id="vehicle_otp_container"></div>
|
||
<input
|
||
type="hidden"
|
||
id="modal_vehicle_no"
|
||
name="vehicle_no"
|
||
required
|
||
data-parsley-required="true"
|
||
data-parsley-required-message="Vehicle number is required"
|
||
data-parsley-minlength="[9, 10]"
|
||
data-parsley-minlength-message="Please enter complete vehicle number"
|
||
data-parsley-vehicle-format="true"
|
||
data-parsley-vehicle-format-message="Invalid vehicle number format"
|
||
data-parsley-trigger="change"
|
||
oninput="validateInput(this, 'vehicle', 'vehicle_no')"
|
||
>
|
||
<input type="hidden" id="vehicle_no_validation">
|
||
<div class="vehicle-result" id="vehicle_result"></div>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="form-group col-md-3">
|
||
<label for="rto_id">RTO</label>
|
||
<select class="form-control readonly-color readonly-select" id="rto_id" name="rto_id" style="appearance:none;-webkit-appearance:none;-moz-appearance:none;cursor:not-allowed;">
|
||
<option value=""></option>
|
||
<?php
|
||
if (isset($rto_details) && count($rto_details)) {
|
||
foreach ($rto_details as $key => $value) {
|
||
echo '<option value="' . $value['id'] . '" data-state="' . $value['rto_state'] . '" data-code="' . $value['rto_code'] . '">' . $value['rto_name'] . '</option>';
|
||
}
|
||
}
|
||
?>
|
||
</select>
|
||
</div>
|
||
|
||
<div class="form-group col-md-3">
|
||
<label for="rc">Chassis No</label>
|
||
<input type="text" class="form-control" id="rc" name="rc"
|
||
placeholder="Enter Chassis No"
|
||
onchange="validateInput(this, 'vehicle', 'rc')">
|
||
</div>
|
||
|
||
<div class="form-group col-md-3">
|
||
<label for="type"> Vehicle Type <span class="text-danger">*</span></label>
|
||
<select class="form-control" id="type" name="type" required>
|
||
<option value="">Select Type</option>
|
||
<?php
|
||
if (isset($vehicle_type) && count($vehicle_type)) {
|
||
foreach ($vehicle_type as $key => $value) {
|
||
echo "<option value='" . $value['id'] . "'>" . $value['vehicle_type'] . "</option>";
|
||
}
|
||
}
|
||
?>
|
||
</select>
|
||
</div>
|
||
|
||
<div class="form-group col-md-3">
|
||
<label for="client_type">Client Type<span class="text-danger">*</span></label>
|
||
<select class="form-control" id="owner_client_type" name="client_type" required>
|
||
<option value="">Select Client type</option>
|
||
<option value="1">Group</option>
|
||
<option value="2">Individual</option>
|
||
</select>
|
||
</div>
|
||
|
||
<div class="form-group col-md-3 old_client">
|
||
<label for="owner">Owner Name <span class="text-danger">*</span></label>
|
||
<select class="form-control" id="owner" name="owner" required>
|
||
<option value="">Select Owner</option>
|
||
</select>
|
||
</div>
|
||
|
||
<div class="form-group col-md-3 old_client old_group_client">
|
||
<label for="owner_branch">Branch <span class="text-danger">*</span></label>
|
||
<select class="form-control" id="owner_branch" name="branch_id">
|
||
<option value="">Select Branch</option>
|
||
</select>
|
||
</div>
|
||
|
||
<div class="form-group col-md-3 v_common new_client" style="display: none;">
|
||
<label for="client_name">Client Name <span class="text-danger">*</span></label>
|
||
<input type="text" class="form-control" id="client_name" name="client_name">
|
||
</div>
|
||
|
||
<div class="form-group col-md-3 v_group_client new_client" style="display: none;">
|
||
<label for="short_name">Client Short Name <span class="text-danger">*</span></label>
|
||
<input type="text" class="form-control" id="short_name" name="short_name"
|
||
onkeyup="validateInputForClient(this, 'clients', 'short_name')">
|
||
</div>
|
||
|
||
<div class="form-group col-md-3 v_group_client new_client" style="display: none;">
|
||
<label for="branch_name">Client Branch Name <span class="text-danger">*</span></label>
|
||
<input type="text" class="form-control" id="branch_name" name="branch_name">
|
||
</div>
|
||
|
||
<div class="form-group col-md-3 v_group_client new_client" style="display: none;">
|
||
<label for="contact_name">Contact Name <span class="text-danger">*</span></label>
|
||
<input type="text" class="form-control" id="contact_name" name="name">
|
||
</div>
|
||
|
||
<div class="form-group col-md-3 v_common new_client" style="display: none;">
|
||
<label for="email">Email <span class="text-danger">*</span></label>
|
||
<input type="email" class="form-control" id="email" name="email"
|
||
placeholder="Enter Email">
|
||
</div>
|
||
|
||
<div class="form-group col-md-3 new_client v_individual_client" style="display: none;">
|
||
<label for="mobile">Mobile <span class="text-danger"></span></label>
|
||
<input type="number" class="form-control" id="mobile" name="mobile"
|
||
placeholder="Enter Mobile">
|
||
</div>
|
||
|
||
<div class="form-group col-md-3 v_group_client new_client" style="display: none;">
|
||
<label for="gst">GST <span class="text-danger"></span></label>
|
||
<input type="text" class="form-control" id="gst" name="gst"
|
||
placeholder="Enter GST Number"
|
||
oninput="validateInputForClient(this, 'client_branch', 'gst')">
|
||
</div>
|
||
|
||
</div> <!-- /.row -->
|
||
|
||
<div class="row">
|
||
<div class="col-md-12 text-right m-b-0">
|
||
<a class="btn btn-primary waves-effect waves-light mr-1" id="vehicle_form_submit_btn_id_for_disable" onclick="getVehicleFormData()">Submit</a>
|
||
</div>
|
||
</div>
|
||
</div> <!-- /#vehicle_form_row_div -->
|
||
</div>
|
||
</div>`;
|
||
|
||
$('#vehicle_row_div').append(html);
|
||
appendOwner(client_list);
|
||
$('#owner').select2();
|
||
$('#owner_branch').select2();
|
||
$('#client_name').on('input', generateShortName);
|
||
/** $("#client_name").on("input change keyup", function() {
|
||
clearTimeout(shortNameTimer); // cancel previous call
|
||
shortNameTimer = setTimeout(() => {
|
||
generateShortName(); // only runs after 200ms pause
|
||
}, 200); // adjust debounce delay as needed
|
||
}); **/
|
||
|
||
// $("#vehicle_form_row_div").on("input change", "input, select, textarea", function () {
|
||
// if ($("#client_type").val() === "") {
|
||
// alert("Please select the client type first");
|
||
// if ($(this).is(":checkbox")) {
|
||
// // uncheck checkbox
|
||
// $(this).prop("checked", false);
|
||
// } else {
|
||
// // clear text/select/textarea
|
||
// $(this).val("");
|
||
// }
|
||
// $("#client_type").focus(); // focus back to client_type
|
||
// }
|
||
// });
|
||
|
||
$('#owner').change(function(){
|
||
|
||
let owner_id = $(this).val();
|
||
console.log('owner_id', owner_id);
|
||
if(branch_list != '') {
|
||
// console.log(branch_list[client_id]);
|
||
let data = branch_list[owner_id];
|
||
appendOwnerBranch(data);
|
||
}
|
||
|
||
})
|
||
|
||
$('#owner_client_type').on('change', function() {
|
||
|
||
let btn = $("#vehicle_client_btn");
|
||
let client_type = $(this).val();
|
||
|
||
if(client_type == 1){
|
||
|
||
if(btn.is(':checked')){
|
||
$('.v_group_client').show();
|
||
$('.v_individual_client').hide();
|
||
$(".v_group_client").find("select, input, textarea").val("").prop("required", true);
|
||
$(".v_individual_client").find("select, input, textarea").val("").prop("required", false);
|
||
}else{
|
||
$('.v_group_client').hide();
|
||
$('.v_individual_client').hide();
|
||
$(".v_group_client").find("select, input, textarea").val("").prop("required", false);
|
||
$(".v_individual_client").find("select, input, textarea").val("").prop("required", false);
|
||
|
||
$('.old_group_client').show();
|
||
$(".old_group_client").find("select, input, textarea").val("").prop("required", true);
|
||
$(".v_common").find("select, input, textarea").val("").prop("required", false);
|
||
}
|
||
toggleRequiredWithAsterisk('#mobile', false);
|
||
|
||
}else{
|
||
|
||
if(btn.is(':checked')){
|
||
$('.v_group_client').hide();
|
||
$('.v_individual_client').show();
|
||
$(".v_group_client").find("select, input, textarea").val("").prop("required", false);
|
||
$(".v_individual_client").find("select, input, textarea").val("").prop("required", true);
|
||
}else{
|
||
$('.v_group_client').hide();
|
||
$('.v_individual_client').hide();
|
||
$(".v_group_client").find("select, input, textarea").val("").prop("required", false);
|
||
$(".v_individual_client").find("select, input, textarea").val("").prop("required", false);
|
||
|
||
$('.old_group_client').hide();
|
||
$(".old_group_client").find("select, input, textarea").val("").prop("required", false);
|
||
$(".v_common").find("select, input, textarea").val("").prop("required", false);
|
||
|
||
}
|
||
toggleRequiredWithAsterisk('#mobile', false);
|
||
}
|
||
toggleRequiredWithAsterisk('#gst', false);
|
||
|
||
$.each(client_list, function(index, item) {
|
||
if (item.client_type == client_type) {
|
||
|
||
let client_show_name = item.client_name;
|
||
if (item.client_type == 2) {
|
||
// client_show_name = item.client_name + ' - ' + (item.dob ?? '') + (item.pan ?? '');
|
||
client_show_name = item.client_name + (item.dob ? ('- (' + item.dob + ' )' ) : '') + (item.pan ? ('- ' + item.pan ) : '');
|
||
}
|
||
var option = $('<option>', {
|
||
value: item.id,
|
||
text: client_show_name,
|
||
'data-cn': item.client_name,
|
||
'data-ct': item.client_type
|
||
});
|
||
$('#owner').append(option);
|
||
}
|
||
});
|
||
|
||
});
|
||
|
||
// for this function to validate the vehicle number and making text
|
||
(function() {
|
||
const totalBoxes = 10;
|
||
let vehicleInputs = [];
|
||
const container = document.getElementById('vehicle_otp_container');
|
||
const hiddenInput = document.getElementById('modal_vehicle_no');
|
||
const resultDiv = document.getElementById('vehicle_result');
|
||
|
||
// Create input boxes
|
||
function createVehicleInputs() {
|
||
container.innerHTML = '';
|
||
vehicleInputs = [];
|
||
|
||
for (let i = 0; i < totalBoxes; i++) {
|
||
const input = document.createElement('input');
|
||
input.type = 'text';
|
||
input.className = 'vehicle-otp-box';
|
||
input.maxLength = 1;
|
||
input.dataset.index = i;
|
||
|
||
input.addEventListener('input', handleInput);
|
||
input.addEventListener('keydown', handleKeydown);
|
||
input.addEventListener('paste', handlePaste);
|
||
|
||
container.appendChild(input);
|
||
vehicleInputs.push(input);
|
||
}
|
||
}
|
||
|
||
function handleInput(e) {
|
||
|
||
const input = e.target;
|
||
const index = parseInt(input.dataset.index);
|
||
const value = input.value.toUpperCase();
|
||
console.log('toUpperCase value :', value);
|
||
|
||
if (value && /[A-Z0-9]/.test(value)) {
|
||
input.value = value;
|
||
input.classList.add('filled');
|
||
|
||
if (index < totalBoxes - 1) {
|
||
vehicleInputs[index + 1].focus();
|
||
}
|
||
} else {
|
||
input.value = '';
|
||
input.classList.remove('filled');
|
||
}
|
||
|
||
updateHiddenInput();
|
||
validateVehicle();
|
||
|
||
// Trigger Parsley validation
|
||
if ($(hiddenInput).parsley) {
|
||
$(hiddenInput).parsley().validate();
|
||
}
|
||
}
|
||
|
||
function handleKeydown(e) {
|
||
const input = e.target;
|
||
const index = parseInt(input.dataset.index);
|
||
|
||
if (e.key === 'Backspace' && !input.value && index > 0) {
|
||
vehicleInputs[index - 1].focus();
|
||
vehicleInputs[index - 1].value = '';
|
||
vehicleInputs[index - 1].classList.remove('filled');
|
||
updateHiddenInput();
|
||
validateVehicle();
|
||
|
||
// Trigger Parsley validation
|
||
if ($(hiddenInput).parsley) {
|
||
$(hiddenInput).parsley().validate();
|
||
}
|
||
} else if (e.key === 'ArrowLeft' && index > 0) {
|
||
vehicleInputs[index - 1].focus();
|
||
} else if (e.key === 'ArrowRight' && index < totalBoxes - 1) {
|
||
vehicleInputs[index + 1].focus();
|
||
}
|
||
}
|
||
|
||
function handlePaste(e) {
|
||
e.preventDefault();
|
||
const pastedData = e.clipboardData.getData('text').toUpperCase().replace(/[^A-Z0-9]/g, '');
|
||
|
||
for (let i = 0; i < pastedData.length && i < totalBoxes; i++) {
|
||
vehicleInputs[i].value = pastedData[i];
|
||
vehicleInputs[i].classList.add('filled');
|
||
}
|
||
|
||
const nextEmpty = Math.min(pastedData.length, totalBoxes - 1);
|
||
vehicleInputs[nextEmpty].focus();
|
||
|
||
updateHiddenInput();
|
||
validateVehicle();
|
||
|
||
// Trigger Parsley validation
|
||
if ($(hiddenInput).parsley) {
|
||
$(hiddenInput).parsley().validate();
|
||
}
|
||
}
|
||
|
||
function updateHiddenInput() {
|
||
const value = vehicleInputs.map(input => input.value).join('');
|
||
hiddenInput.value = value;
|
||
|
||
// Trigger change event for Parsley
|
||
$(hiddenInput).trigger('change');
|
||
}
|
||
|
||
function getInputValue() {
|
||
console.log('vehicleInputs', vehicleInputs);
|
||
return vehicleInputs.map(input => input.value).join('');
|
||
}
|
||
|
||
function maskNormalFormat(input) {
|
||
const cleaned = input.replace(/[^A-Z0-9]/g, '');
|
||
// Match exactly: 2 letters + 2 digits + 1-2 letters + 4 digits (total 9-10 chars)
|
||
const pattern = /^([A-Z]{2})(\d{2})([A-Z]{1,2})(\d{4})$/;
|
||
const match = cleaned.match(pattern);
|
||
|
||
if (match) {
|
||
return `${match[1]} ${match[2]} ${match[3]} ${match[4]}`;
|
||
}
|
||
return null;
|
||
}
|
||
|
||
function maskBharatFormat(input) {
|
||
const cleaned = input.replace(/[^A-Z0-9]/g, '');
|
||
// Match exactly: 2 digits + BH + 4 digits + 1-2 letters (total 9-10 chars)
|
||
const pattern = /^(\d{2})(BH)(\d{4})([A-Z]{1,2})$/;
|
||
const match = cleaned.match(pattern);
|
||
|
||
if (match && cleaned.length === 10) {
|
||
return `${match[1]} ${match[2]} ${match[3]} ${match[4]}`;
|
||
}
|
||
return null;
|
||
}
|
||
|
||
function validateVehicle() {
|
||
const input = getInputValue();
|
||
console.log('getInputValue :', input);
|
||
console.log('totalBoxes :', totalBoxes);
|
||
|
||
if (input.length == 0) {
|
||
resultDiv.classList.remove('show');
|
||
return;
|
||
}
|
||
|
||
// if (input.length < totalBoxes || input.length < (totalBoxes - 1)) {
|
||
// return;
|
||
// }
|
||
|
||
const normalFormatted = maskNormalFormat(input);
|
||
const bharatFormatted = maskBharatFormat(input);
|
||
console.log('normalFormatted :', normalFormatted);
|
||
console.log('normalFormatted :', normalFormatted);
|
||
|
||
if (normalFormatted) {
|
||
resultDiv.innerHTML = normalFormatted + '<span class="vehicle-badge success">✓ Normal</span>';
|
||
resultDiv.classList.add('show');
|
||
$('#vehicle_no_validation').val('0');
|
||
} else if (bharatFormatted) {
|
||
resultDiv.innerHTML = bharatFormatted + '<span class="vehicle-badge success">✓ Bharat</span>';
|
||
resultDiv.classList.add('show');
|
||
$('#vehicle_no_validation').val('0');
|
||
} else {
|
||
// resultDiv.innerHTML = 'Invalid Format <span class="vehicle-badge error">✗</span>';
|
||
// resultDiv.classList.add('show');
|
||
$('#vehicle_no_validation').val('1');
|
||
}
|
||
|
||
// call here
|
||
autoFetchRtoName(input);
|
||
}
|
||
|
||
// Custom Parsley validator for vehicle format
|
||
window.Parsley.addValidator('vehicleFormat', {
|
||
validateString: function(value) {
|
||
if (!value) {
|
||
return false;
|
||
}
|
||
|
||
const cleaned = value.replace(/[^A-Z0-9]/g, '');
|
||
|
||
// Check if it's Bharat series (must be exactly 10 chars)
|
||
if (cleaned.includes('BH')) {
|
||
if (cleaned.length !== 10) {
|
||
return false;
|
||
}
|
||
return !!maskBharatFormat(value);
|
||
}
|
||
|
||
// Must be 9 or 10 characters (9 for 1 series letter, 10 for 2 series letters)
|
||
if (value.length < 9 || value.length > 10) {
|
||
return false;
|
||
}
|
||
|
||
const normalFormatted = maskNormalFormat(value);
|
||
const bharatFormatted = maskBharatFormat(value);
|
||
|
||
return !!(normalFormatted || bharatFormatted);
|
||
},
|
||
messages: {
|
||
en: 'Invalid vehicle number format'
|
||
}
|
||
});
|
||
|
||
// Add error class to OTP boxes when Parsley shows error
|
||
window.Parsley.on('field:error', function() {
|
||
if (this.$element.attr('id') === 'modal_vehicle_no') {
|
||
vehicleInputs.forEach(input => {
|
||
if (input.value) {
|
||
input.classList.add('parsley-error');
|
||
}
|
||
});
|
||
}
|
||
});
|
||
|
||
// Remove error class when validation passes
|
||
window.Parsley.on('field:success', function() {
|
||
if (this.$element.attr('id') === 'modal_vehicle_no') {
|
||
vehicleInputs.forEach(input => {
|
||
input.classList.remove('parsley-error');
|
||
});
|
||
}
|
||
});
|
||
|
||
// Reset function - can be called from outside
|
||
window.resetVehicleField = function() {
|
||
vehicleInputs.forEach(input => {
|
||
input.value = '';
|
||
input.classList.remove('filled');
|
||
input.classList.remove('parsley-error');
|
||
});
|
||
hiddenInput.value = '';
|
||
resultDiv.classList.remove('show');
|
||
|
||
// Reset Parsley validation
|
||
if ($(hiddenInput).parsley) {
|
||
$(hiddenInput).parsley().reset();
|
||
}
|
||
|
||
// Focus first input
|
||
vehicleInputs[0].focus();
|
||
};
|
||
|
||
// Initialize
|
||
createVehicleInputs();
|
||
})();
|
||
|
||
}
|
||
|
||
function appendClientForm(){
|
||
let client_type = $('#client_type').val();
|
||
$('#client_row_div').empty();
|
||
|
||
let html = `
|
||
<div class="col-md-12">
|
||
<div class="form-section">
|
||
<div id="client_form_row_div" data-parsley-validate>
|
||
<h4 class="m-1">
|
||
Add New Client
|
||
<a class="text-dark float-right" aria-expanded="true">
|
||
<i class="mdi mdi-close" style="font-size: 28px;" onclick="removeClientForm()"></i>
|
||
</a>
|
||
</h4>
|
||
<div class="row">
|
||
|
||
<div class="form-group col-md-3 new_client">
|
||
<label for="client_name">Client Name <span class="text-danger">*</span></label>
|
||
<input type="text" class="form-control" id="client_name" name="client_name" required>
|
||
</div>
|
||
|
||
<div class="form-group col-md-3 group_client new_client">
|
||
<label for="short_name">Client Short Name <span class="text-danger">*</span></label>
|
||
<input type="text" class="form-control" id="short_name" name="short_name"
|
||
onkeyup="validateInputForClient(this, 'clients', 'short_name')" required>
|
||
</div>
|
||
|
||
<div class="form-group col-md-3 group_client new_client">
|
||
<label for="branch_name">Client Branch Name <span class="text-danger">*</span></label>
|
||
<input type="text" class="form-control" id="branch_name" name="branch_name" required>
|
||
</div>
|
||
|
||
<div class="form-group col-md-3 group_client new_client">
|
||
<label for="contact_name">Contact Name <span class="text-danger">*</span></label>
|
||
<input type="text" class="form-control" id="contact_name" name="name" required>
|
||
</div>
|
||
|
||
<div class="form-group col-md-3 new_client" >
|
||
<label for="email">Email <span class="text-danger">*</span></label>
|
||
<input type="email" class="form-control" id="email" name="email"
|
||
placeholder="Enter Email" required>
|
||
</div>
|
||
|
||
<div class="form-group col-md-3 individual_client new_client">
|
||
<label for="mobile">Mobile <span class="text-danger">*</span></label>
|
||
<input type="number" class="form-control" id="mobile" name="mobile"
|
||
placeholder="Enter Mobile" required>
|
||
</div>
|
||
|
||
<div class="form-group col-md-3 group_client new_client">
|
||
<label for="gst">GST <span class="text-danger"></span></label>
|
||
<input type="text" class="form-control" id="gst" name="gst"
|
||
placeholder="Enter GST Number"
|
||
oninput="validateInputForClient(this, 'client_branch', 'gst')">
|
||
</div>
|
||
|
||
</div>
|
||
<div class="row">
|
||
<div class="col-md-12 text-right m-b-0">
|
||
<a class="btn btn-primary waves-effect waves-light mr-1" id="client_form_submit_btn" onclick="getClientFormData()">Submit</a>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>`;
|
||
|
||
$('#client_row_div').append(html);
|
||
$('#client_name').on('input', generateShortName);
|
||
/** $("#client_name").on("input change keyup", function() {
|
||
clearTimeout(shortNameTimer); // cancel previous call
|
||
shortNameTimer = setTimeout(() => {
|
||
generateShortName(); // only runs after 200ms pause
|
||
}, 200); // adjust debounce delay as needed
|
||
}); **/
|
||
|
||
|
||
if(client_type == 1){
|
||
$('.group_client').show();
|
||
$('.individual_client').hide();
|
||
$(".group_client").find("select, input, textarea").val("").prop("required", true);
|
||
$(".individual_client").find("select, input, textarea").val("").prop("required", false);
|
||
}else{
|
||
$('.group_client').hide();
|
||
$('.individual_client').show();
|
||
$(".group_client").find("select, input, textarea").val("").prop("required", false);
|
||
$(".individual_client").find("select, input, textarea").val("").prop("required", true);
|
||
|
||
}
|
||
toggleRequiredWithAsterisk('#gst', false);
|
||
toggleRequiredWithAsterisk('#mobile', false);
|
||
|
||
$("#client_form_row_div").on("input change", "input, select, textarea", function () {
|
||
if ($("#client_type").val() === "") {
|
||
alert("Please select the client type first");
|
||
if ($(this).is(":checkbox")) {
|
||
// uncheck checkbox
|
||
$(this).prop("checked", false);
|
||
} else {
|
||
// clear text/select/textarea
|
||
$(this).val("");
|
||
}
|
||
$("#client_type").focus(); // focus back to client_type
|
||
}
|
||
});
|
||
|
||
}
|
||
|
||
function generateShortName() {
|
||
let clientInput = $("#client_name");
|
||
let shortInput = $("#short_name");
|
||
let newClientName = clientInput.val().trim();
|
||
|
||
console.log(`LN : NEW - ${newClientName}`);
|
||
if (newClientName.length == 0){ shortInput.val(''); return; }
|
||
|
||
if (newClientName.length > 0) {
|
||
let shortName = newClientName.substring(0, 10).replace(/\s+/g, '').toUpperCase();
|
||
makeUniqueShortName(shortName);
|
||
}
|
||
}
|
||
|
||
function makeUniqueShortName(baseName) {
|
||
let input = $("#short_name")[0]; // input element
|
||
checkDuplicateTableFieldValue("clients", "short_name", baseName, function(isDuplicate) {
|
||
if (isDuplicate) {
|
||
// Append sequence until unique
|
||
let counter = 1;
|
||
function tryNext() {
|
||
let padded = String(counter).padStart(3, '0'); // 001, 002, 003
|
||
let newName = baseName + padded;
|
||
|
||
checkDuplicateTableFieldValue("clients", "short_name", newName, function(exists) {
|
||
if (exists) {
|
||
counter++;
|
||
tryNext(); // keep checking
|
||
} else {
|
||
$("#short_name").val(newName);
|
||
validateInputForClient(input, "clients", "short_name");
|
||
}
|
||
});
|
||
}
|
||
tryNext();
|
||
} else {
|
||
$("#short_name").val(baseName);
|
||
validateInputForClient(input, "clients", "short_name");
|
||
}
|
||
});
|
||
}
|
||
|
||
function validateInputForClient(input, table, field) {
|
||
|
||
let owner_type = $('#Owner_type').val();
|
||
let client_type = $('#client_type').val();
|
||
|
||
console.log('owner_type', owner_type);
|
||
console.log('client_type', client_type);
|
||
|
||
if((client_type == 2 || owner_type == 2) && field == 'short_name'){
|
||
return;
|
||
}
|
||
|
||
let value = $(input).val();
|
||
if (!value) return;
|
||
|
||
let label = $(input).closest('.form-group').find('label').text().replace('*', '').trim();
|
||
let message = label ? label + " already exists!" : "Value is duplicate!";
|
||
|
||
// Set validating state
|
||
isGSTValidating = true;
|
||
isGSTValid = false;
|
||
$('#hide_smbt_btn button').prop('disabled', true);
|
||
|
||
checkDuplicateTableFieldValue(table, field, value, function(isDuplicate) {
|
||
isGSTValidating = false;
|
||
if (isDuplicate) {
|
||
toastr.warning(message, 'Warning');
|
||
// $(input).val('');
|
||
isGSTValid = false;
|
||
$('#client_form_submit_btn').prop('disabled', true);
|
||
$('#vehicle_form_submit_btn_id_for_disable').prop('disabled', true);
|
||
} else {
|
||
isGSTValid = true;
|
||
$('#client_form_submit_btn').prop('disabled', false);
|
||
$('#vehicle_form_submit_btn_id_for_disable').prop('disabled', false);
|
||
}
|
||
});
|
||
|
||
$('#hide_smbt_btn_button').prop('disabled', false);
|
||
|
||
}
|
||
|
||
$('#client_type').on('change', function() {
|
||
|
||
let client_type = $(this).val();
|
||
console.log( "client_type", client_type);
|
||
|
||
if(client_type == 1){
|
||
$('.group_client').show();
|
||
$('.individual_client').hide();
|
||
$(".group_client").find("select, input, textarea").val("").prop("required", true);
|
||
$(".individual_client").find("select, input, textarea").val("").prop("required", false);
|
||
toggleRequiredWithAsterisk('#gst', false);
|
||
}else{
|
||
$('.group_client').hide();
|
||
$('.individual_client').show();
|
||
$(".group_client").find("select, input, textarea").val("").prop("required", false);
|
||
$(".individual_client").find("select, input, textarea").val("").prop("required", true);
|
||
toggleRequiredWithAsterisk('#gst', false);
|
||
}
|
||
|
||
});
|
||
|
||
function toggleRequiredWithAsterisk(inputSelector, makeRequired) {
|
||
|
||
var $input = $(inputSelector);
|
||
var $label = $input.closest('.form-group').find('label');
|
||
|
||
console.log('Toggling required for:', inputSelector, 'Make required:', makeRequired);
|
||
|
||
if(makeRequired) {
|
||
$input.attr('required', true);
|
||
console.log('Added required attribute');
|
||
|
||
// Add asterisk if not already present
|
||
if($label.find('span.text-danger').length === 0) {
|
||
$label.append(' <span class="text-danger">*</span>');
|
||
console.log('Added * to label');
|
||
} else {
|
||
console.log('* already exists in label');
|
||
}
|
||
} else {
|
||
$input.removeAttr('required');
|
||
console.log('Removed required attribute');
|
||
|
||
// Remove asterisk
|
||
$label.find('span.text-danger').remove();
|
||
console.log('Removed * from label');
|
||
}
|
||
|
||
console.log('Current input attributes:', $input.prop('outerHTML'));
|
||
console.log('Current label html:', $label.html());
|
||
}
|
||
|
||
$(document).on("input change", "input[name='total[]']", function () {
|
||
let val = $(this).val();
|
||
console.log("✅ total[] changed:", val);
|
||
});
|
||
|
||
function autoFetchRtoName(val) {
|
||
console.log(`i am here ${val}`);
|
||
val = val.toUpperCase().trim();
|
||
|
||
let stateCode = val.slice(0, 2); // 1st 2 here i am split the state code
|
||
let numberCode = val.slice(2, 4); // 2nd 2 here i am split the number code
|
||
|
||
console.log(`Ln ST: ${stateCode} | NC: ${numberCode}`);
|
||
|
||
let matched = false;
|
||
|
||
$('#rto_id option').each(function() {
|
||
let optionState = $(this).attr('data-state');
|
||
let optionCode = $(this).attr('data-code');
|
||
console.log(`Ln optionState : ${optionState} | optionCode : ${optionCode}`);
|
||
|
||
if (stateCode === optionState && numberCode === optionCode) {
|
||
$('#rto_id').val($(this).val()).trigger('change'); // ✅ select it
|
||
matched = true;
|
||
return false; // break the loop
|
||
}
|
||
});
|
||
|
||
if (!matched) {
|
||
$('#rto_id').val('').trigger('change'); // reset select
|
||
}
|
||
}
|
||
|
||
function setNhanceBranch(select, show_id) {
|
||
|
||
if (!select || !select.options || select.selectedIndex < 0) {
|
||
console.warn('No option selected yet');
|
||
return;
|
||
}
|
||
|
||
let selectedOption = select.options[select.selectedIndex];
|
||
|
||
let nbID = selectedOption.getAttribute('data-nbid');
|
||
let nbName = selectedOption.getAttribute('data-nbname');
|
||
|
||
console.log('NB ID:', nbID);
|
||
console.log('NB Name:', nbName);
|
||
|
||
if(show_id == "nhance_branch_info"){
|
||
$('#issuer_branch').val(nbID ? nbID : '');
|
||
}else{
|
||
$('#service_person_branch_id').val(nbID ? nbID : '');
|
||
}
|
||
|
||
let nbDiv = document.getElementById(show_id);
|
||
|
||
if (!nbID || !nbName) {
|
||
nbDiv.innerHTML = '';
|
||
nbDiv.classList.remove('show');
|
||
return;
|
||
}
|
||
|
||
nbDiv.innerHTML =
|
||
'<span class="text-success">' + nbName + '</span>' +
|
||
' <span class="vehicle-badge success">✓ Nhance Branch</span>';
|
||
|
||
nbDiv.classList.add('show');
|
||
}
|
||
|
||
function setRM(select, show_id) {
|
||
|
||
if (!select || !select.options || select.selectedIndex < 0) {
|
||
console.warn('No option selected yet');
|
||
return;
|
||
}
|
||
|
||
let selectedOption = select.options[select.selectedIndex];
|
||
|
||
let rmid = selectedOption.getAttribute('data-rmid');
|
||
let rmname = selectedOption.getAttribute('data-rmname');
|
||
|
||
console.log('RM ID:', rmid);
|
||
console.log('RM Name:', rmname);
|
||
|
||
if(show_id == "salse_rm_info"){
|
||
$('#salse_person_manager_id').val(rmid ? rmid : '');
|
||
}else{
|
||
$('#service_person_manager_id').val(rmid ? rmid : '');
|
||
}
|
||
|
||
let rmDiv = document.getElementById(show_id);
|
||
|
||
if (!rmid || !rmname) {
|
||
rmDiv.innerHTML = '';
|
||
rmDiv.classList.remove('show');
|
||
return;
|
||
}
|
||
|
||
rmDiv.innerHTML =
|
||
'<span class="text-success">' + rmname + '</span>' +
|
||
' <span class="vehicle-badge success">✓ RM</span>';
|
||
|
||
rmDiv.classList.add('show');
|
||
}
|
||
|
||
</script>
|