4946 lines
225 KiB
PHP
4946 lines
225 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%;
|
||
}
|
||
#insurerTable th,
|
||
#insurerTable td {
|
||
padding: 5px;
|
||
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: 5px;
|
||
top: 50%;
|
||
transform: translateY(-50%);
|
||
font-weight: bold;
|
||
color: #000;
|
||
}
|
||
|
||
/* .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;
|
||
}
|
||
|
||
</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" id="cd_ac_no_for_edit"> -->
|
||
<input type="hidden" id="premium_details_unique_id">
|
||
<input type="hidden" id="policy_tranction_policy_number">
|
||
|
||
<!-- Client Row -->
|
||
<div class="row">
|
||
<!-- Section 1 -->
|
||
<div class="col-md-12">
|
||
<div class="form-section">
|
||
<div id="accordion_0" class="mb-0">
|
||
<div class="card mb-0">
|
||
<h4 class="m-1">Client Details
|
||
<a id="toggleIcon" class="text-dark float-right" data-toggle="collapse" href="#collapseOne" aria-expanded="true">
|
||
<i id="icon" class="mdi mdi-chevron-down mr-1 text-primary" style="font-size: 28px;"></i>
|
||
</a>
|
||
</h4>
|
||
<div id="collapseOne" class="collapse show" aria-labelledby="headingOne" data-parent="#accordion_0">
|
||
<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'] . "'
|
||
>" .
|
||
$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">
|
||
|
||
<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">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>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- Pre sales Row -->
|
||
<div class="row">
|
||
<div class="col-md-12">
|
||
<div class="form-section">
|
||
<div id="accordion_1" class="mb-0">
|
||
<div class="card mb-0">
|
||
<h4 class="m-1">Pre Sales
|
||
<a id="toggleIcon" class="text-dark float-right" data-toggle="collapse" href="#collapseTwo" aria-expanded="true">
|
||
<i id="icon" class="mdi mdi-chevron-down mr-1 text-primary" style="font-size: 28px;"></i>
|
||
</a>
|
||
</h4>
|
||
<div id="collapseTwo" class="collapse show" aria-labelledby="headingOne" data-parent="#accordion_1">
|
||
|
||
<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>
|
||
<hr>
|
||
<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="ppteam">PP Team</label>
|
||
<!-- <input id="ppteam" type="text" class="form-control" name="ppteam"> -->
|
||
<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="fa fa-info-circle 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>
|
||
|
||
<!-- sales Row -->
|
||
<div class="row" id="sales_row" style="display: none;">
|
||
<div class="col-md-12">
|
||
<div class="form-section">
|
||
<div id="accordion_2" class="mb-0">
|
||
<div class="card mb-0">
|
||
<h4 class="m-1">Sales
|
||
<a id="toggleIcon" class="text-dark float-right" data-toggle="collapse" href="#collapseThree" aria-expanded="true">
|
||
<i id="icon" class="mdi mdi-chevron-down mr-1 text-primary" style="font-size: 28px;"></i>
|
||
</a>
|
||
</h4>
|
||
<div id="collapseThree" class="collapse show" aria-labelledby="headingOne" data-parent="#accordion_2">
|
||
<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" 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="fas fa-info-circle 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-2">
|
||
<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>
|
||
<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>
|
||
<hr>
|
||
|
||
<!-- Premium Details -->
|
||
<div class="row">
|
||
<div class="col-md-12">
|
||
<div class="form-section">
|
||
<div id="accordion_3" class="mb-0">
|
||
<div class="card mb-0">
|
||
<h4 class="m-1">Premium Details
|
||
<a id="toggleIcon" class="text-dark float-right" data-toggle="collapse" href="#collapseFour" aria-expanded="true">
|
||
<i id="icon" class="mdi mdi-chevron-down mr-1 text-primary" style="font-size: 28px;"></i>
|
||
</a>
|
||
</h4>
|
||
<div id="collapseFour" class="collapse show" aria-labelledby="headingOne" data-parent="#accordion_3">
|
||
<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 class="table table-bordered co_share_table" id="insurerTable">
|
||
<thead>
|
||
<tr>
|
||
<th>Premium Details</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<tr id="table_tr_1">
|
||
<td>Insurer</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">
|
||
<td>Follower Policy No</td>
|
||
</tr>
|
||
<tr id="table_tr_3" style="display: none;">
|
||
<td>Co-Share %</td>
|
||
</tr>
|
||
<tr id="table_tr_36">
|
||
<td>Non Commitional <br> Premium Amount</td>
|
||
</tr>
|
||
<tr id="table_tr_4">
|
||
<td>Base Premium</td>
|
||
</tr>
|
||
<tr class="hidetp" id="table_tr_5">
|
||
<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" <?= in_array(FINANCE_TEAM_ID, user_team()) ? 'style="display:none"' : '' ?>>
|
||
<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>
|
||
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="form-group text-right m-b-0" id="submitButton">
|
||
<button type="submit" class="btn btn-primary waves-effect waves-light mr-1"
|
||
id="btnSubmit">Submit</button>
|
||
</div>
|
||
</form>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<!-- end form row -->
|
||
|
||
<?php include("newClientModal.php") ?>
|
||
|
||
<!-- 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="dark" 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">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>
|
||
|
||
$("#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 = [];
|
||
|
||
$(document).ready(function(){
|
||
|
||
// $('#upload_enrollment_model').modal({
|
||
// backdrop: 'static',
|
||
// keyboard: false
|
||
// })
|
||
|
||
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();
|
||
}
|
||
|
||
}
|
||
|
||
});
|
||
|
||
|
||
|
||
$('#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();
|
||
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')
|
||
|
||
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)
|
||
}else{
|
||
$('.branchdiv').hide()
|
||
$('#client_branch_id').prop('required', false);
|
||
|
||
}
|
||
|
||
if(val == 'add_vehicle'){
|
||
|
||
$('#modal_vehicle_no').val('');
|
||
var myModal = new bootstrap.Modal(document.getElementById('vehicle_modal'));
|
||
myModal.show();
|
||
|
||
$(this).val('').select2();
|
||
}
|
||
})
|
||
|
||
$('#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', true);
|
||
$('#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() {
|
||
|
||
$('#client_type').val('');
|
||
$('#client_id').val('').select2();
|
||
$('#client_branch_id').val('').select2();
|
||
|
||
var client_type = $('#client_type').val();
|
||
var value = $(this).val();
|
||
var selectedOption = $(this).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');
|
||
|
||
// 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(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{
|
||
$('#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();
|
||
}
|
||
|
||
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 == 1 || value == 2 || value == 3 || value == 4 || value == 5 || value == 38 || value == 40){
|
||
$('#tpa_div').hide();
|
||
}else{
|
||
$('#tpa_div').show();
|
||
}
|
||
|
||
if( value == 38 || value == 40 ){
|
||
$('#tpa_div').hide();
|
||
}
|
||
else if(value > 7){
|
||
$('#tpa_div').hide();
|
||
$('#no_of_insured_div').hide();
|
||
$('#no_of_dependents_div').hide();
|
||
}
|
||
else{
|
||
$('#tpa_div').show();
|
||
$('#no_of_insured_div').show();
|
||
$('#no_of_dependents_div').show();
|
||
}
|
||
|
||
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)
|
||
}else{
|
||
$('#is_cd_reduce_from_bds').prop('disabled',false)
|
||
}
|
||
|
||
});
|
||
|
||
})
|
||
|
||
$(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);
|
||
}
|
||
});
|
||
|
||
$(document).on('click', '[name="co_share_type[]"]', function() {
|
||
|
||
let val = $(this).val();
|
||
let uniqueid = $(this).data('id');
|
||
let insurer = $('#follow_insurer_id_'+uniqueid).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);
|
||
}else{
|
||
$('#insurer_id').val(insurer)
|
||
}
|
||
|
||
});
|
||
|
||
$(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 insurer = $(this).val();
|
||
let unique_id = $(this).data('count');
|
||
let client_id = $('#client_id').val();
|
||
|
||
console.log('insurer', insurer);
|
||
console.log('follow_insurer_id client_id', client_id);
|
||
console.log('follow_insurer_id unique_id', unique_id);
|
||
|
||
$('#insurer_id').val(insurer)
|
||
|
||
if(!client_id){
|
||
$(this).val('').select2();
|
||
toastr.warning('Please select the Client', 'WARNING');
|
||
}
|
||
|
||
});
|
||
|
||
});
|
||
|
||
//---------------------------------------------------------------------------------------------------------
|
||
|
||
//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);
|
||
|
||
|
||
// 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');
|
||
}
|
||
});
|
||
}, 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();
|
||
|
||
// 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);
|
||
}
|
||
|
||
// 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();
|
||
|
||
} else {
|
||
$('#policyholdernamediv').hide();
|
||
$('.branchdiv').show();
|
||
$('#client_branch_id').prop('required', true);
|
||
$('#table_tr_34').show();
|
||
$('#table_tr_37').show();
|
||
}
|
||
|
||
//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);
|
||
}
|
||
|
||
} 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 -------------------------------------------------------------------------------------------------
|
||
|
||
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 amountCalculation(input) {
|
||
|
||
console.log('############################## AMOUNT CALCULATION ############################################')
|
||
console.log('amountCalculation : ' + input);
|
||
let selectedOption = $('#policy_type_id').find('option:selected');
|
||
let bap = selectedOption.data('bap');
|
||
|
||
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(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')){
|
||
|
||
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');
|
||
|
||
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');
|
||
|
||
$('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 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){
|
||
$.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',
|
||
}));
|
||
|
||
$('#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) {
|
||
|
||
event.preventDefault();
|
||
|
||
var isValid = $('#inception_form_id').parsley().validate();
|
||
var client_type_id = $('#client_type').val();
|
||
var policy_status = $('#policy_status').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;
|
||
}
|
||
|
||
|
||
if(client_type_id == 1 && policy_status == 'completed'){
|
||
|
||
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="cd_ac_no_for_child[]"]').each(function(index) {
|
||
let value = $(this).val();
|
||
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]);
|
||
|
||
console.log(formData);
|
||
|
||
|
||
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 = '<?= base_url('policy_tranction/inception/list') ?>';
|
||
|
||
|
||
$('#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);
|
||
|
||
//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');
|
||
}
|
||
});
|
||
});
|
||
|
||
// $("#client_form").submit(function(event) {
|
||
|
||
// let form_type = $(this).data('id') || 0;
|
||
|
||
// console.log('onsubmit event', this)
|
||
// console.log('onsubmit event get data value',form_type)
|
||
// console.log('client_type', $('#client_type').val());
|
||
|
||
// event.preventDefault();
|
||
|
||
|
||
// $('#aadhar').attr('data-parsley-required', 'false');
|
||
// $('#aadhar').removeAttr('required');
|
||
|
||
|
||
// isClientFormSubmitting = true;
|
||
// var isValid = $('#client_form').parsley().validate();
|
||
// if (!isValid) {
|
||
// console.log('Form is Empty', 'Warning');
|
||
// return ;
|
||
// }
|
||
|
||
// form_action = '<?= base_url("util/createClientWithMinimalData"); ?>';
|
||
|
||
// $('.loader').fadeIn();
|
||
// $('.loader-mask').fadeIn();
|
||
|
||
// var client_type = $('#client_type').val() || $('#Owner_type').val();
|
||
// console.log('client_type:', client_type);
|
||
|
||
// //FORM Data
|
||
// var formData = new FormData($('#client_form')[0]);
|
||
// formData.append('client_type', client_type);
|
||
|
||
// $.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_Client_With_Minimal_Data', res)
|
||
|
||
// if(res.status == true){
|
||
// getClientAndBranchAndPolicy(res.client_id, res.branch_id);
|
||
|
||
// if(form_type != 1){
|
||
|
||
// setTimeout(function(){
|
||
// $('#client_id').val(res.client_id).change();
|
||
// setTimeout(function(){
|
||
// $('#client_branch_id').val(res.branch_id).change();
|
||
// }, 1000)
|
||
// }, 2000)
|
||
|
||
// }else{
|
||
|
||
// setTimeout(function(){
|
||
// $('#owner').val(res.client_id).change();
|
||
// $('#owner_branch').val(res.branch_id).change();
|
||
|
||
// $('.loader').fadeOut();
|
||
// $('.loader-mask').delay(350).fadeOut('slow');
|
||
|
||
// }, 2000)
|
||
// }
|
||
|
||
// toastr.success(res.message, 'Success');
|
||
|
||
// }else{
|
||
// toastr.error(res.message, 'Error');
|
||
// }
|
||
|
||
// $('#client_form')[0].reset();
|
||
// $('.close').click();
|
||
|
||
// if(form_type == 1){
|
||
|
||
// var myModal = new bootstrap.Modal(document.getElementById('vehicle_modal'));
|
||
// myModal.show();
|
||
|
||
// $('#client_form').removeAttr('data-id');
|
||
|
||
// // Load form data into #vehicle_form from localStorage
|
||
// setFormDataFromLocalStorage("#vehicle_form", "vehicleFormData");
|
||
// }
|
||
|
||
// isClientFormSubmitting = false;
|
||
// },
|
||
// 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/createVehicleWithMinimalData"); ?>';
|
||
|
||
$('.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);
|
||
}
|
||
$('.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');
|
||
|
||
|
||
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);
|
||
|
||
$.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');
|
||
|
||
if(res.status == true){
|
||
appendCDAccountNumber(res.data, unique_id, res.id)
|
||
$('#cd_ac_pk_for_leader').val(res.id)
|
||
$('#cd_current_balance_'+unique_id).val(res.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() {
|
||
|
||
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()
|
||
|
||
var selectedOption = $('#policy_type_id').find('option:selected');
|
||
var bap = selectedOption.data('bap');
|
||
|
||
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()
|
||
}
|
||
}
|
||
|
||
|
||
// $('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() {
|
||
|
||
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();
|
||
|
||
} 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', true);
|
||
$('#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);
|
||
|
||
$('#table_tr_34').show();
|
||
$('#table_tr_37').show();
|
||
|
||
}
|
||
|
||
$('[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);
|
||
} else {
|
||
$('.ownerbranchdiv').show();
|
||
$('#owner_branch').prop('required', true);
|
||
}
|
||
|
||
// 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 || policy_type_id == 38 || policy_type_id == 40){
|
||
$('#tpa_div').hide();
|
||
}else{
|
||
$('#tpa_div').show();
|
||
}
|
||
|
||
}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;
|
||
}
|
||
|
||
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();
|
||
}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');
|
||
}
|
||
},
|
||
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("Could not get policy data")
|
||
}
|
||
});
|
||
|
||
// $('.follow_insurer_cd').on('change', function(){
|
||
|
||
// const selectedValue = $(this).val();
|
||
// const unique_id = $(this).data('count');
|
||
// let leader = $('#co_share_type_' + unique_id).is(':checked');
|
||
|
||
// console.log('leader', leader);
|
||
// console.log('selectedValue', selectedValue);
|
||
// console.log('unique_id', unique_id);
|
||
|
||
// if (!leader) {
|
||
// $(this).val('');
|
||
// toastr.warning('Please select the Leader.', 'WARNING!');
|
||
// }
|
||
// });
|
||
|
||
$('.close').on('click', function(){
|
||
$('#client_form')[0].reset();
|
||
$('#vehicle_form')[0].reset();
|
||
$('#CDMasterForm')[0].reset();
|
||
});
|
||
|
||
//------------------------------------------------------------------------------------------------------------
|
||
|
||
var insurerCount = 0;
|
||
|
||
$('#setInsurerCount').on('click', function() {
|
||
addInsurerColumn();
|
||
getColumnIndexes(1);
|
||
});
|
||
|
||
function addInsurerColumn() {
|
||
|
||
insurerCount = insurerCount + 1;
|
||
|
||
// Update header
|
||
$('#insurerTable thead tr').append(`
|
||
<th>
|
||
Insurer ${insurerCount}
|
||
${insurerCount > 1 ? `<a data-count="${insurerCount}" class="text-danger fa fa-trash delete-insurer" style="margin-left: 135px;"></a>` : ''}
|
||
</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)">
|
||
<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'] ?>">
|
||
<?= $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: // 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 6: // 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 7: // Base Premium
|
||
newCell = `<td><input type="text" class="right-align-input" id="base_premium_${insurerCount}" name="base_premium[]" oninput="" onkeypress="return onlyNumbers(event)" onchange="checkCDAmountForBasePremium(this);"></td>`;
|
||
break;
|
||
case 8: // 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 9: // 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 10: // 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 11: // 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 12: // 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 13: // 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 14: // 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 15: // 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 16: // 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 17: // 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 18: // 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 19: // 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 20: // 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 21: // 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 22: // 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 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: // 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 27: // 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 28: // 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 29: // 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 30: // 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 31: // 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 32: // 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 33: // 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 34: // 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 35: // 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 36: // 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-count="${insurerCount}" id="follow_insurer_id_${insurerCount}" name="follow_insurer_id[]" onchange="getCDAccountNumber(this)">
|
||
<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'] ?>">
|
||
<?= $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[]" oninput="" onchange=""></td>`;
|
||
break;
|
||
case 5: // 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 6: // 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 7: // Base Premium
|
||
newCell = `<td><input type="text" class="right-align-input" id="base_premium_${insurerCount}" name="base_premium[]" oninput="" onkeypress="return onlyNumbers(event)"></td>`;
|
||
break;
|
||
case 8: // 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 9: // 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 10: // 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 11: // 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 12: // 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 13: // 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 14: // 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 15: // 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 16: // 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 17: // 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 18: // 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 19: // 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 20: // 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 21: // 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 22: // 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 23: // 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 24: // 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 25: // 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);
|
||
|
||
$('#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 client_type_id = $('#client_type').val() ?? 1;
|
||
var is_co_pay_yes = $('#cop_yes').prop('checked') ? 1 : 0;
|
||
|
||
|
||
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;
|
||
}
|
||
|
||
// console.log('client_type_id', client_type_id);
|
||
// console.log('std_bp', std_bp);
|
||
// console.log('std_tp', std_tp);
|
||
// console.log('std_tep', std_tep);
|
||
|
||
$('[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");
|
||
}
|
||
|
||
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--;
|
||
|
||
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: // Co-Share %
|
||
cell.find('input').val(data.co_share_per).toggleClass('readonly-select', !!disable_td);
|
||
break;
|
||
case 6: // non_comm_per_amt
|
||
cell.find('input').val(data.non_comm_per_amt);
|
||
break;
|
||
case 7: // Base Premium
|
||
cell.find('input').val(data.bp_amt).toggleClass('readonly-select', !!disable_td);
|
||
break;
|
||
case 8: // TP Premium
|
||
cell.find('input').val(data.tp_amt).toggleClass('readonly-select', !!disable_td);
|
||
break;
|
||
case 9: // Ter Premium
|
||
cell.find('input').val(data.tep_amt).toggleClass('readonly-select', !!disable_td);
|
||
break;
|
||
case 10: // Co Premium
|
||
cell.find('input').val(data.cop_amt).toggleClass('readonly-select', !!disable_td);
|
||
break;
|
||
case 11: // Co TP Premium
|
||
cell.find('input').val(data.cotp_amt).toggleClass('readonly-select', !!disable_td);
|
||
break;
|
||
case 12: // Co Ter Premium
|
||
cell.find('input').val(data.cotep_amt).toggleClass('readonly-select', !!disable_td);
|
||
break;
|
||
case 13: // CGST
|
||
cell.find('input').val(data.bp_cgst).toggleClass('readonly-select', !!disable_td);
|
||
break;
|
||
case 14: // SGST
|
||
cell.find('input').val(data.bp_sgst).toggleClass('readonly-select', !!disable_td);
|
||
break;
|
||
case 15: // IGST
|
||
cell.find('input').val(data.bp_igst).toggleClass('readonly-select', !!disable_td);
|
||
break;
|
||
case 16: // GST Amount
|
||
cell.find('input').val(data.bp_gst_amt).toggleClass('readonly-select', !!disable_td);
|
||
break;
|
||
case 17: // Stamp Duty
|
||
cell.find('input').val(data.stamp_duty).toggleClass('readonly-select', !!disable_td);
|
||
break;
|
||
case 18: // Total
|
||
cell.find('input').val(data.amount).toggleClass('readonly-select', !!disable_td);
|
||
break;
|
||
case 19: // Agreed BP %
|
||
cell.find('input').val(data.agreed_bp_per).toggleClass('readonly-select', !!disable_td);
|
||
break;
|
||
case 20: // Agreed TP %
|
||
cell.find('input').val(data.agreed_tp_per).toggleClass('readonly-select', !!disable_td);
|
||
break;
|
||
case 21: // Agreed Ter %
|
||
cell.find('input').val(data.agreed_tep_per).toggleClass('readonly-select', !!disable_td);
|
||
break;
|
||
case 22: // Agreed Amount
|
||
cell.find('input').val(data.agreed_amt).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: // Actual BP Amount
|
||
cell.find('input').val(data.actual_bp_amount);
|
||
break;
|
||
case 27: // Actual TP Amount
|
||
cell.find('input').val(data.actual_tp_amount);
|
||
break;
|
||
case 28: // Actual Ter Amount
|
||
cell.find('input').val(data.actual_tep_amount);
|
||
break;
|
||
case 29: // Actual BP %
|
||
cell.find('input').val(data.actual_bp_percentage);
|
||
break;
|
||
case 30: // Actual TP %
|
||
cell.find('input').val(data.actual_tp_percentage);
|
||
break;
|
||
case 31: // Actual Ter %
|
||
cell.find('input').val(data.actual_tep_percentage);
|
||
break;
|
||
case 32: // Actual BP Brokerage Amount
|
||
cell.find('input').val(data.actual_bp_brokerage_amount);
|
||
break;
|
||
case 33: // Actual TP Brokerage Amount
|
||
cell.find('input').val(data.actual_tp_brokerage_amount);
|
||
break;
|
||
case 34: // Actual Ter Brokerage Amount
|
||
cell.find('input').val(data.actual_tep_brokerage_amount);
|
||
break;
|
||
case 35: // Expected Amount
|
||
cell.find('input').val(data.exp_amt);
|
||
break;
|
||
// case 34: // Variance
|
||
// cell.find('input').val(data.variance);
|
||
// break;
|
||
case 36: // 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: // co_share_per
|
||
cell.find('input').val(data.co_share_per).toggleClass('readonly-select', !!disable_td);
|
||
break;
|
||
case 6: // non_comm_per_amt
|
||
cell.find('input').val(data.non_comm_per_amt);
|
||
break;
|
||
case 7: // Base Premium
|
||
cell.find('input').val(data.bp_amt).toggleClass('readonly-select', !!disable_td);
|
||
break;
|
||
case 8: // TP Premium
|
||
cell.find('input').val(data.tp_amt).toggleClass('readonly-select', !!disable_td);
|
||
break;
|
||
case 9: // Ter Premium
|
||
cell.find('input').val(data.tep_amt).toggleClass('readonly-select', !!disable_td);
|
||
break;
|
||
case 10: // Co Premium
|
||
cell.find('input').val(data.cop_amt).toggleClass('readonly-select', !!disable_td);
|
||
break;
|
||
case 11: // Co TP Premium
|
||
cell.find('input').val(data.cotp_amt).toggleClass('readonly-select', !!disable_td);
|
||
break;
|
||
case 12: // Co Ter Premium
|
||
cell.find('input').val(data.cotep_amt).toggleClass('readonly-select', !!disable_td);
|
||
break;
|
||
case 13: // CGST
|
||
cell.find('input').val(data.bp_cgst).toggleClass('readonly-select', !!disable_td);
|
||
break;
|
||
case 14: // SGST
|
||
cell.find('input').val(data.bp_sgst).toggleClass('readonly-select', !!disable_td);
|
||
break;
|
||
case 15: // IGST
|
||
cell.find('input').val(data.bp_igst).toggleClass('readonly-select', !!disable_td);
|
||
break;
|
||
case 16: // GST Amount
|
||
cell.find('input').val(data.bp_gst_amt).toggleClass('readonly-select', !!disable_td);
|
||
break;
|
||
case 17: // Stamp Duty
|
||
cell.find('input').val(data.stamp_duty).toggleClass('readonly-select', !!disable_td);
|
||
break;
|
||
case 18: // Total
|
||
cell.find('input').val(data.amount).toggleClass('readonly-select', !!disable_td);
|
||
break;
|
||
case 19: // Agreed BP %
|
||
cell.find('input').val(data.agreed_bp_per).toggleClass('readonly-select', !!disable_td);
|
||
break;
|
||
case 20: // Agreed TP %
|
||
cell.find('input').val(data.agreed_tp_per).toggleClass('readonly-select', !!disable_td);
|
||
break;
|
||
case 21: // Agreed Ter %
|
||
cell.find('input').val(data.agreed_tep_per).toggleClass('readonly-select', !!disable_td);
|
||
break;
|
||
case 22: // Standard BP %
|
||
cell.find('input').val(data.standerd_bp_per).toggleClass('readonly-select', !!disable_td);
|
||
break;
|
||
case 23: // Standard TP %
|
||
cell.find('input').val(data.standerd_tp_per).toggleClass('readonly-select', !!disable_td);
|
||
break;
|
||
case 24: // Standard Ter %
|
||
cell.find('input').val(data.standerd_tep_per).toggleClass('readonly-select', !!disable_td);
|
||
break;
|
||
case 25: // 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);
|
||
}
|
||
}
|
||
});
|
||
|
||
// $('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;
|
||
|
||
if (pt_id != 0) {
|
||
hide_list_show_add();
|
||
setTimeout(() =>
|
||
getPolicyTransactionDataForEdit(pt_id),
|
||
1500); // Reduced timeout
|
||
} else {
|
||
show_list_hide_add();
|
||
}
|
||
|
||
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!";
|
||
}
|
||
|
||
checkDuplicateTableFieldValue(table, field, value, function(isDuplicate) {
|
||
if (isDuplicate) {
|
||
toastr.warning(message, 'WARNING');
|
||
$(input).val('')
|
||
}
|
||
});
|
||
|
||
}
|
||
|
||
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 client_type = $('#client_type').val();
|
||
console.log('client type', client_type);
|
||
|
||
if(client_type == 1){
|
||
|
||
let base_premium = $(input).val();
|
||
console.log("base_premium:", base_premium);
|
||
|
||
// 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);
|
||
|
||
// Get the corresponding `cd_ac_no` value
|
||
let cd_ac_no = $('#cd_ac_no_' + increment).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: base_premium,
|
||
cd_ac_no: cd_ac_no
|
||
};
|
||
|
||
// Send AJAX request
|
||
sendAjaxRequestForGlobal(url, 'GET', requestData, function(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');
|
||
} else {
|
||
toastr.warning('Base premium greater than CD Amount', 'WARNING');
|
||
$(input).val("0")
|
||
}
|
||
} else {
|
||
toastr.error(response.message || 'Unable to fetch data', 'ERROR');
|
||
}
|
||
}, 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 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()
|
||
});
|
||
|
||
function getColumnIndexes(count = 0) {
|
||
$('#insurerTable thead th').each(function(index) {
|
||
if (index === 0) {
|
||
console.log("Premium Table columnIndexes is", index);
|
||
} else {
|
||
amountCalculation(index);
|
||
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>');
|
||
}
|
||
}
|
||
});
|
||
|
||
|
||
</script>
|