3026 lines
144 KiB
PHP
3026 lines
144 KiB
PHP
<style>
|
|
.co_share_table {
|
|
width: 39% !important;
|
|
/* margin-bottom: 1rem;
|
|
color: #212529; */
|
|
}
|
|
|
|
#insurerCardContainer {
|
|
/* max-height: 400px; */
|
|
overflow-y: auto;
|
|
margin-top: 20px;
|
|
/* overflow-x: auto; */
|
|
position: relative;
|
|
}
|
|
|
|
</style>
|
|
|
|
<style>
|
|
.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;
|
|
}
|
|
|
|
.right-align-input {
|
|
text-align: right;
|
|
}
|
|
|
|
.input-with-percentage {
|
|
position: relative;
|
|
}
|
|
|
|
.input-with-percentage input {
|
|
padding-right: 20px;
|
|
text-align: right;
|
|
}
|
|
|
|
.input-with-percentage::after {
|
|
content: '%';
|
|
position: absolute;
|
|
right: 10px;
|
|
top: 50%;
|
|
transform: translateY(-50%);
|
|
font-weight: bold;
|
|
color: #000;
|
|
}
|
|
|
|
</style>
|
|
<style>
|
|
.insurer-card .compact-details-section .small { font-size: 75%; }
|
|
.insurer-card .compact-details-section .form-control { width: 100%; }
|
|
.insurer-card .compact-details-section .col-md-5 .col-6 label { margin-bottom: 0.2rem; }
|
|
.insurer-card .input-wrap { display: flex; align-items: center; }
|
|
.insurer-card .input-content { flex-grow: 1; padding-right: 1.8rem !important; /* Create space inside the input for the symbol */ }
|
|
.insurer-card .input-symbol {
|
|
margin-left: -1.5rem; /* Position the symbol over the padding space */
|
|
pointer-events: none; /* Prevents symbol from interfering with input clicks */
|
|
font-weight: bold;
|
|
color: #6c757d; /* Optional: Make symbol slightly less prominent */
|
|
}
|
|
|
|
.readonly-select { background-color: #f3f3f3; cursor: not-allowed; }
|
|
|
|
.readonly-select:focus {
|
|
outline: none;
|
|
}
|
|
|
|
.readonly-select[readonly] {
|
|
pointer-events: none;
|
|
}
|
|
|
|
|
|
</style>
|
|
|
|
<style>
|
|
.vehicle-input-wrapper {
|
|
position: relative;
|
|
}
|
|
|
|
.vehicle-otp-container {
|
|
display: flex;
|
|
gap: 3px;
|
|
flex-wrap: wrap;
|
|
}
|
|
|
|
.vehicle-otp-box {
|
|
width: 34px;
|
|
height: 38px;
|
|
text-align: center;
|
|
font-size: 16px;
|
|
font-weight: 100;
|
|
font-family: 'Courier New', monospace;
|
|
border: 2px solid #ced4da;
|
|
border-radius: 6px;
|
|
text-transform: uppercase;
|
|
transition: all 0.2s ease;
|
|
}
|
|
|
|
.vehicle-otp-box:focus {
|
|
outline: none;
|
|
border-color: #007bff;
|
|
box-shadow: 0 0 0 0.2rem rgba(0, 123, 255, 0.25);
|
|
}
|
|
|
|
.vehicle-otp-box.filled {
|
|
background-color: #e7f3ff;
|
|
border-color: #007bff;
|
|
}
|
|
|
|
.vehicle-otp-box.parsley-error {
|
|
border-color: #dc3545;
|
|
background-color: #f8d7da;
|
|
}
|
|
|
|
.vehicle-format-info {
|
|
font-size: 11px;
|
|
color: #6c757d;
|
|
margin-top: 5px;
|
|
}
|
|
|
|
.vehicle-result {
|
|
margin-top: 8px;
|
|
/* padding: 6px 10px; */
|
|
background: #f8f9fa;
|
|
border-radius: 4px;
|
|
font-family: 'Courier New', monospace;
|
|
font-size: 13px;
|
|
font-weight: 600;
|
|
text-align: center;
|
|
letter-spacing: 1px;
|
|
display: none;
|
|
/* max-width: fit-content; */
|
|
margin-left: auto;
|
|
margin-right: auto;
|
|
}
|
|
|
|
.vehicle-result.show {
|
|
display: block;
|
|
}
|
|
|
|
.vehicle-badge {
|
|
display: inline-block;
|
|
padding: 2px 6px;
|
|
border-radius: 3px;
|
|
font-size: 10px;
|
|
font-weight: 700;
|
|
margin-left: 5px;
|
|
}
|
|
|
|
.vehicle-badge.success {
|
|
background: #d4edda;
|
|
color: #155724;
|
|
}
|
|
|
|
.vehicle-badge.error {
|
|
background: #f8d7da;
|
|
color: #721c24;
|
|
}
|
|
|
|
/* Parsley error styling */
|
|
.parsley-errors-list {
|
|
list-style: none;
|
|
padding: 0;
|
|
margin: 5px 0 0 0;
|
|
}
|
|
|
|
.parsley-errors-list li {
|
|
color: #dc3545;
|
|
font-size: 12px;
|
|
}
|
|
</style>
|
|
|
|
<div class="row" id="endorsement_form" style="display: none;">
|
|
<div class="col-12">
|
|
<div class="card">
|
|
<div class="card-body">
|
|
<div class="row" style="margin-bottom:1rem;">
|
|
<div class="col-6" style="align-self: center;">
|
|
<h4 id="page_title" style="position: relative;">Add Endorsement</h4>
|
|
</div>
|
|
<div class="col-6" style="text-align: right;">
|
|
<a href="<?= base_url('policy_tranction/endorsement/list2') ?>" id="btnAdd" class="btn btn-primary waves-effect waves-light"
|
|
>Back</a>
|
|
</div>
|
|
</div>
|
|
<form role="form" class="parsley-examples" method="post" id="endorsement_form_id" enctype="multipart/form-data">
|
|
|
|
<input type="hidden" name="id" id="policy_tranction_primarykey">
|
|
<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_no">
|
|
<input type="hidden" name="cd_ac_pk" id="cd_ac_pk">
|
|
<input type="hidden" name="ct_type" id="ct_type">
|
|
<input type="hidden" name="bro_payable_by" id="bro_payable_by">
|
|
<input type="hidden" name="cop_yes" id="cop_yes">
|
|
<input type="hidden" name="base_cd_amount" id="base_cd_amount">
|
|
<input type="hidden" name="cd_amt_changed" id="cd_amt_changed" disabled>
|
|
|
|
|
|
<!-- Client Row -->
|
|
<div class="row">
|
|
<!-- Section 1 -->
|
|
<div class="col-md-12">
|
|
<div id="accordion_0" class="mb-0">
|
|
<label id="policyAccordion" class="m-1 d-flex justify-content-between align-items-center">
|
|
<span class="font-color-black">Client Details</span>
|
|
<a id="toggleIcon" class="text-dark float-right" data-toggle="collapse" href="#collapseOne"
|
|
aria-expanded="true">
|
|
<i id="icon" class="mdi mdi-chevron-up mr-1 text-primary" style="font-size: 28px;"></i>
|
|
</a>
|
|
</label>
|
|
<div class="card mb-1">
|
|
<div id="collapseOne" class="collapse show" aria-labelledby="headingOne" data-parent="#accordion_0">
|
|
<div class="card-body">
|
|
<div class="row">
|
|
|
|
<div class="form-group col-md-3">
|
|
<label for="client_type">Client Type<span class="text-danger"></span></label>
|
|
<select class="form-control" id="client_type" name="client_type" >
|
|
<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="email"> Policy <span class="text-danger">*</span></label>
|
|
<select class="form-control" id="client_policy_id" name="client_policy_id" required>
|
|
<option value="">Select Policy</option>
|
|
</select>
|
|
</div>
|
|
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Endorsement details -->
|
|
<div class="row">
|
|
<div class="col-md-12">
|
|
<div id="accordion_2" class="mb-0">
|
|
<label id="policyAccordion" class="m-1 d-flex justify-content-between align-items-center">
|
|
<span class="font-color-black">Endorsement</span>
|
|
<a id="toggleIcon" class="text-dark float-right" data-toggle="collapse" href="#collapseThree"
|
|
aria-expanded="true">
|
|
<i id="icon" class="mdi mdi-chevron-up mr-1 text-primary" style="font-size: 28px;"></i>
|
|
</a>
|
|
</label>
|
|
<div class="card mb-1">
|
|
<div id="collapseThree" class="collapse show" aria-labelledby="headingOne" data-parent="#accordion_2">
|
|
<div class="card-body">
|
|
<div class="row">
|
|
|
|
<!-- <div class="form-group col-md-3" id="tpa_endorse_div">
|
|
<label for="tpa"> TPA <span id="tpa_danger"class="text-danger"></span></label>
|
|
<select class="form-control readonly-select" 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">
|
|
<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" readonly>
|
|
</div>
|
|
|
|
<div class="form-group col-md-3">
|
|
<label for="bp_cgst">D.O.C <span id="base_danger" class="text-danger"></span></label>
|
|
<input id="policy_start_date" type="text" class="form-control" placeholder="DD/MM/YYYY" readonly>
|
|
</div>
|
|
|
|
<div class="form-group col-md-3">
|
|
<label for="bp_igst">D.O.E <span id="base_danger" class="text-danger"></span></label>
|
|
<input id="policy_end_date" type="text" class="form-control" placeholder="DD/MM/YYYY" readonly>
|
|
</div>
|
|
|
|
<div class="form-group col-md-3">
|
|
<label for="addon_policy"> Endorsement Type <span id="base_danger" class="text-danger">*</span></label>
|
|
<select class="form-control" id="action_type" name="action_type" required>
|
|
<option value="" selected>Select Endorsement Type</option>
|
|
<?php
|
|
if (isset($action_type) && count($action_type)) {
|
|
foreach ($action_type as $key => $value) {
|
|
echo "<option value=" . $key . ">" . $value . "</option>";
|
|
}
|
|
}
|
|
?>
|
|
</select>
|
|
</div>
|
|
|
|
<div class="form-group col-md-3">
|
|
<label for="addon_policy">Endorsement No<span id="base_danger" class="text-danger"></span></label>
|
|
<input type="text" class="form-control" id="endorsement_no" name="endorsement_no" placeholder="Enter Endorsement No" onchange="validateInput(this, 'policy_transaction', 'endorsement_no')">
|
|
</div>
|
|
|
|
<div class="form-group col-md-3">
|
|
<label for="addon_policy">Data Received Date<span id="base_danger" class="text-danger">*</span></label>
|
|
<input type="text" class="form-control" id="data_received_date" name="data_received_date" placeholder="DD/MM/YYYY" required>
|
|
</div>
|
|
|
|
<div class="form-group col-md-3">
|
|
<label for="policy_issue_date" class="d-flex align-items-center">
|
|
<span class="flex-grow-1">Endorsement Issue Date<span id="base_danger" class="text-danger">*</span></span>
|
|
<small id="policy_issue_month_info"
|
|
class="text-right"
|
|
style="font-size: x-small;">
|
|
</small>
|
|
</label>
|
|
<input type="text" class="form-control" id="policy_issue_date" name="policy_issue_date" placeholder="DD/MM/YYYY" required>
|
|
</div>
|
|
|
|
<div class="d-none">
|
|
<label for="month">Endorsement Issue Month<span id="base_danger" class="text-danger">*</span></label>
|
|
<input type="text" class="form-control readonly-select" id="month" name="month" placeholder="MM/YYYY" required>
|
|
</div>
|
|
|
|
<div class="form-group col-md-3">
|
|
<label for="endorse_eff_date">Endorsement Effective Date<span id="base_danger" class="text-danger"></span></label>
|
|
<input type="text" class="form-control" id="endorse_eff_date" name="endorse_eff_date" placeholder="DD/MM/YYYY" >
|
|
</div>
|
|
|
|
<div class="form-group col-md-3" id="no_of_insured_endorse_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_endorse_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>
|
|
|
|
<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="last_action_date">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 install_due_date_div" style="display: none;">
|
|
<label for="install_due_date">Installment due Date</label>
|
|
<input id="install_due_date" type="text" class="form-control" name="install_due_date" placeholder="DD/MM/YYYY">
|
|
</div>
|
|
|
|
<div class="form-group col-md-3">
|
|
<label class="card_label_4">Base Premium<span id="base_danger" class="text-danger">*</span></label>
|
|
<input type="text" class="form-control right-align-input" id="base_premium" name="base_premium" oninput="" onkeypress="return onlyNumbers(event)" onchange="setBPValue(this.value)" required>
|
|
</div>
|
|
|
|
|
|
<div class="form-group col-md-3 hidetp">
|
|
<label class="card_label_5">TP Premium</label>
|
|
<input type="text" class="form-control right-align-input" id="tp_premium" name="tp_premium" oninput="" onkeypress="return onlyNumbers(event)" onchange="setTPValue(this.value)">
|
|
</div>
|
|
|
|
|
|
<div class="form-group col-md-3 hideter card_group_6" style="display:none;">
|
|
<label class="card_label_6">TEP Premium</label>
|
|
<input type="text" class="form-control right-align-input" id="ter_premium" name="ter_premium" oninput="" onkeypress="return onlyNumbers(event)" onchange="setTEPValue(this.value)">
|
|
</div>
|
|
|
|
<!-- <div class="form-group col-md-3">
|
|
<label class="switch" style="position: relative;top: 32px;left: 20px;">
|
|
<input id="policy_with_corr" type="checkbox" name="policy_with_corr">
|
|
<span class="slider round" style="height: 27px;"></span>
|
|
</label>
|
|
|
|
<label for="policy_with_corr" style="position: relative;top: 33px;left: 25px;"> Policy with Correction</label>
|
|
</div> -->
|
|
|
|
<!-- <div class="form-group col-md-3">
|
|
<label class="switch" style="position: relative;top: 32px;left: 20px;">
|
|
<input id="is_cd_reduce_from_bds" type="checkbox" name="is_cd_reduce_from_bds">
|
|
<span class="slider round" style="height: 27px;"></span>
|
|
</label>
|
|
|
|
<label for="is_cd_reduce_from_bds" style="position: relative;top: 33px;left: 25px;">Make Entry in CD <i class="mdi mdi-information-outline" 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>
|
|
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Premium Details -->
|
|
<div class="row">
|
|
<div class="col-md-12">
|
|
<div id="accordion_3" class="mb-0">
|
|
<label id="policyAccordion" class="m-1 d-flex justify-content-between align-items-center">
|
|
<span class="font-color-black">Premium Details</span>
|
|
<a id="toggleIcon" class="text-dark float-right" data-toggle="collapse" href="#collapseTwo"
|
|
aria-expanded="true">
|
|
<i id="icon" class="mdi mdi-chevron-up mr-1 text-primary" style="font-size: 28px;"></i>
|
|
</a>
|
|
</label>
|
|
<div class="card mb-0">
|
|
<div id="collapseTwo" class="collapse show" aria-labelledby="headingOne" data-parent="#accordion_3">
|
|
<div class="card-body">
|
|
|
|
<div id="allInsurerCards"></div>
|
|
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="form-group text-right mt-3 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>
|
|
<!-- end form row -->
|
|
|
|
<script>
|
|
|
|
var team_id = [];
|
|
var role_id = <?php echo get_role_id(); ?>;
|
|
console.log(" role_id : ", role_id);
|
|
var insurer_count_array = [];
|
|
var pt_co_share_count_data = 0;
|
|
var redirect_url = '<?= base_url('policy_tranction/endorsement/list') ?>';
|
|
|
|
$(document).ready(function(){
|
|
|
|
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.');
|
|
}
|
|
|
|
getURLParamsForReport()
|
|
})
|
|
|
|
$(document).ready(function(){
|
|
|
|
$('#client_id').change(function(){
|
|
|
|
let client_id = $(this).val();
|
|
|
|
// console.log('client_id', client_id);
|
|
// console.log('branch_list', branch_list);
|
|
|
|
if(client_id == 'add_client') {
|
|
$('#client_id').val('').change();
|
|
var myModal = new bootstrap.Modal(document.getElementById('upload_enrollment_model'));
|
|
myModal.show();
|
|
}
|
|
|
|
if(branch_list != '') {
|
|
// console.log(branch_list[client_id]);
|
|
let data = branch_list[client_id];
|
|
appendBranch(data);
|
|
}
|
|
|
|
if(policyListByClient != '') {
|
|
// console.log(branch_list[client_id]);
|
|
let data = policyListByClient[client_id];
|
|
if (data) {
|
|
appendPolicies(data);
|
|
|
|
}
|
|
}
|
|
|
|
})
|
|
|
|
$('#client_branch_id').change(function(){
|
|
|
|
let branch_id = $(this).val();
|
|
// console.log(policy_list)
|
|
// console.log(branch_id)
|
|
|
|
if(policy_list != '') {
|
|
console.log(policy_list[branch_id]);
|
|
let data = policy_list[branch_id];
|
|
appendPolicies(data);
|
|
}
|
|
|
|
|
|
});
|
|
|
|
$('#client_policy_id').change(function(){
|
|
|
|
console.log('######################################')
|
|
console.log('client_policy_id onchange called')
|
|
console.log('######################################')
|
|
|
|
let client_id = $('#client_id').val();
|
|
let policy_tranction_primarykey = $('#policy_tranction_primarykey').val();
|
|
let client_policy_id = $(this).val();
|
|
var policy_no = $(this).find('option:selected').attr('data-policy');
|
|
var insurer = $(this).find('option:selected').attr('data-insurer');
|
|
var tpa = $(this).find('option:selected').attr('data-tpa');
|
|
var cd_ac_no = $(this).find('option:selected').attr('data-cd');
|
|
var start_date = $(this).find('option:selected').attr('data-sd');
|
|
var end_date = $(this).find('option:selected').attr('data-ed');
|
|
var policy_type_id = $(this).find('option:selected').attr('data-ptid');
|
|
|
|
// if(policy_type_id == 1 || policy_type_id == 2 || policy_type_id == 3 || policy_type_id == 4 || policy_type_id == 5 || policy_type_id == 6 || policy_type_id == 7){
|
|
// $('#is_cd_reduce_from_bds').prop('disabled',true).prop('checked', false)
|
|
// }else{
|
|
// $('#is_cd_reduce_from_bds').prop('disabled',false)
|
|
// }
|
|
|
|
if( policy_type_id > 7 ){
|
|
$('#tpa_endorse_div').hide();
|
|
$('#card_label_34').show();
|
|
$('#card_label_37').show();
|
|
}else{
|
|
$('#tpa_endorse_div').show();
|
|
$('#card_label_34').hide();
|
|
$('#card_label_37').hide();
|
|
}
|
|
|
|
|
|
if(policy_type_id == 2 || policy_type_id == 3 || policy_type_id == 4 || policy_type_id == 5){
|
|
$('#no_of_insured_endorse_div').show();
|
|
$('#no_of_dependents_endorse_div').show();
|
|
}else if(policy_type_id == 1 || policy_type_id == 6 || policy_type_id == 7) {
|
|
$('#no_of_insured_endorse_div').show();
|
|
$('#no_of_dependents_endorse_div').hide();
|
|
}else{
|
|
$('#no_of_insured_endorse_div').hide();
|
|
$('#no_of_dependents_endorse_div').hide();
|
|
}
|
|
|
|
|
|
// console.log('client_id', client_id);
|
|
// console.log('client_policy_id', client_policy_id);
|
|
// console.log('policy_tranction_primarykey', policy_tranction_primarykey);
|
|
// console.log('policy_no', policy_no);
|
|
// console.log('cd_ac_no',cd_ac_no);
|
|
// console.log('tpa',tpa);
|
|
|
|
$('#policy_no').val(policy_no);
|
|
$('#insurer_id').val(insurer);
|
|
$('#tpa').val(tpa).change();
|
|
// $('#cd_ac_no').val(cd_ac_no);
|
|
$('#policy_start_date').val(start_date);
|
|
$('#policy_end_date').val(end_date);
|
|
|
|
if(!policy_tranction_primarykey && client_id && client_policy_id){
|
|
|
|
removeAllInsurerCards();
|
|
|
|
form_action = '<?= base_url("util/getPTCOShareCount/"); ?>' + client_id + '/' + client_policy_id;
|
|
|
|
$.ajax({
|
|
url: form_action,
|
|
type: "GET",
|
|
dataType: 'json',
|
|
processData: false,
|
|
contentType: false,
|
|
success: function(res) {
|
|
|
|
console.log('policy co share data', res);
|
|
|
|
if(res.status == true){
|
|
if(res.data.length > 0){
|
|
|
|
$('#ct_type').val(2);
|
|
$('#cd_ac_pk').val(res?.is_copay_yes?.cd_ac_pk || "");
|
|
$('#cd_ac_no').val(res?.cd_master_data?.cd_ac_no || "");
|
|
$('#bro_payable_by').val(res.data[0].bro_payable_by);
|
|
|
|
if(res.is_copay_yes && res.is_copay_yes.co_share == 1){
|
|
console.log('copay yes', res.is_copay_yes);
|
|
$('#cop_yes').val(1);
|
|
}else{
|
|
console.log('copay no', res.is_copay_yes);
|
|
$('#cop_yes').val(0);
|
|
}
|
|
|
|
populateCards(res.data);
|
|
|
|
if (res?.data?.length) {
|
|
console.log('PT Co Share Count :', res.data.length);
|
|
pt_co_share_count_data = res.data.length;
|
|
}
|
|
|
|
$('#btnSubmit').prop('disabled', false).data('disable', false);
|
|
|
|
}else{
|
|
$('#ct_type').val(1)
|
|
// addInsurerColumn()
|
|
toastr.warning("There is no policy inception data.", 'Warning!');
|
|
$('#btnSubmit').prop('disabled', true).data('disable', true);
|
|
}
|
|
}else{
|
|
$('#ct_type').val(1)
|
|
// addInsurerColumn()
|
|
toastr.warning(res.message, 'Warning!');
|
|
$('#btnSubmit').prop('disabled', true).data('disable', true);
|
|
}
|
|
},
|
|
error: function (xhr, status, error) {
|
|
console.error(xhr.responseText);
|
|
console.error(status, error);
|
|
}
|
|
});
|
|
}
|
|
});
|
|
})
|
|
|
|
$(document).on('change', 'input[type="checkbox"][name="co_share_type[]"]', function() {
|
|
|
|
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{
|
|
if(client_id && insurer_id){
|
|
$('#insurer_id').val(insurer)
|
|
// getCDAccountNumber(client_id, insurer_id);
|
|
}else{
|
|
console.log('getCDAccountNumber cannot be call because of absence of client id and insurer id');
|
|
}
|
|
}
|
|
|
|
console.log('co_share_type value', val);
|
|
console.log('co_share_type uniqueid', uniqueid);
|
|
console.log('co_share_type insurer', insurer);
|
|
});
|
|
|
|
$(document).ready(function() {
|
|
$(document).on('change', '[name="follow_insurer_id[]"]', function() {
|
|
|
|
let insurer = $(this).val();
|
|
let client_id = $('#client_id').val();
|
|
let insurer_id = $(this).find('option:selected').attr('data-id');
|
|
let insurer_branch_id = $(this).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_id', insurer_branch_id);
|
|
|
|
if (!$('#cop_yes').is(':checked')) {
|
|
|
|
if(client_id && insurer_id){
|
|
$('#insurer_id').val(insurer)
|
|
// getCDAccountNumber(client_id, insurer_id);
|
|
} else {
|
|
console.log('getCDAccountNumber cannot be called because of the absence of client id and insurer id');
|
|
}
|
|
}
|
|
});
|
|
});
|
|
|
|
//---------------------------------------------------------------------------------------------------------
|
|
|
|
$("#endorsement_form_id").submit(function(event) {
|
|
|
|
event.preventDefault();
|
|
|
|
var isValid = $('#endorsement_form_id').parsley().validate();
|
|
|
|
if (!isValid) {
|
|
$('#endorsement_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;
|
|
}
|
|
|
|
form_action = '<?= base_url('policy_tranction/endorsement/create') ?>';
|
|
|
|
$('.loader').fadeIn();
|
|
$('.loader-mask').fadeIn();
|
|
|
|
var formData = new FormData($('#endorsement_form_id')[0]);
|
|
|
|
let bp = document.getElementById("base_premium").value;
|
|
let tp = document.getElementById("tp_premium").value;
|
|
let ter = document.getElementById("ter_premium").value;
|
|
|
|
for (let i = 0; i < insurerCount; i++) {
|
|
formData.append(`base_premium[${i}]`, bp);
|
|
formData.append(`tp_premium[${i}]`, tp);
|
|
formData.append(`ter_premium[${i}]`, ter);
|
|
}
|
|
|
|
$.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('ENDORSEMENT FOR SUBMIT RESPONSE : ', res);
|
|
|
|
if (res.status == true) {
|
|
toastr.success(res.message, 'Success');
|
|
$('#policy_tranction_primarykey').val(res.pt_id);
|
|
window.location.href = redirect_url;
|
|
} else {
|
|
toastr.error(res.message, 'Error');
|
|
}
|
|
|
|
},
|
|
error: function(xhr, status, error) {
|
|
console.error(xhr.responseText);
|
|
console.error(status, error);
|
|
$('.loader').fadeOut();
|
|
$('.loader-mask').delay(350).fadeOut('slow');
|
|
}
|
|
});
|
|
});
|
|
|
|
//---------------------------------------------------------------------------------------------------------
|
|
|
|
$('#client_type').on('change', function() {
|
|
|
|
var selectedClientType = $(this).val();
|
|
|
|
if (selectedClientType == 2) {
|
|
$('.branchdiv').hide();
|
|
$('#card_label_34').hide();
|
|
$('#card_label_37').hide();
|
|
} else {
|
|
$('.branchdiv').show();
|
|
$('#card_label_34').show();
|
|
$('#card_label_37').show();
|
|
}
|
|
|
|
console.log('selectedClientType', selectedClientType);
|
|
|
|
// Clear and add default options for client
|
|
$('#client_id').empty().append($('<option>', {
|
|
value: '',
|
|
text: 'Select Client'
|
|
}))
|
|
|
|
if (selectedClientType) {
|
|
|
|
$.each(client_list, function(index, item) {
|
|
if (item.client_type == selectedClientType) {
|
|
var option = $('<option>', {
|
|
value: item.id,
|
|
text: item.client_name,
|
|
'data-cn': item.client_name,
|
|
'data-ct': item.client_type
|
|
});
|
|
$('#client_id').append(option);
|
|
}
|
|
});
|
|
|
|
}
|
|
|
|
if(selectedClientType == 1){
|
|
$('#client_policy_id').empty().append($('<option>', {
|
|
value: '',
|
|
text: 'Select Policy'
|
|
}));
|
|
}
|
|
|
|
// Initialize or refresh Select2 for both dropdowns
|
|
$('#client_id').select2();
|
|
$('#client_policy_id').select2();
|
|
});
|
|
|
|
$('#endorsement_no').on('change', function(){
|
|
|
|
var policy_no = $('#policy_no').val();
|
|
console.log(policy_no +'-'+policy_no.length);
|
|
policy_no = policy_no.trim();
|
|
console.log(policy_no +'-'+policy_no.length);
|
|
|
|
var endorsement_no = $(this).val();
|
|
console.log(endorsement_no +'-'+endorsement_no.length);
|
|
endorsement_no = endorsement_no.trim();
|
|
console.log(endorsement_no +'-'+endorsement_no.length);
|
|
|
|
if(policy_no && endorsement_no){
|
|
$.ajax({
|
|
url: '<?php echo base_url('util/get_client_policy_data_using_policy_no_and_endo_no/');?>',
|
|
type: "GET",
|
|
data : {policy_no : policy_no, endorsement_no : endorsement_no},
|
|
dataType: 'json',
|
|
success: function (res) {
|
|
|
|
console.log("get_client_policy_data_using_policy_no_and_endo_no Response : ", res);
|
|
if(res.status == true){
|
|
$('#ct_type').val(1)
|
|
}else{
|
|
$('#ct_type').val(2)
|
|
console.log(res.message, 'warning');
|
|
}
|
|
},
|
|
error: function (xhr, status, error) {
|
|
console.error(xhr.responseText);
|
|
console.error(status, error);
|
|
}
|
|
});
|
|
}else{
|
|
console.log('Policy number or Endorsement Number is empty')
|
|
}
|
|
|
|
})
|
|
|
|
//------------- EDIT FUNCTION -----------------------------------------------------------------------------------------------
|
|
|
|
function getPolicyTransactionDataForEndorsementEdit(input){
|
|
|
|
$('.loader').fadeIn();
|
|
$('.loader-mask').fadeIn();
|
|
|
|
$('#endorsement_form_id')[0].reset();
|
|
// var id = $(input).attr('data-id');
|
|
var id = input;
|
|
|
|
$.ajax({
|
|
url: '<?= base_url("/policy_tranction/endorsement/list/") ?>' + id,
|
|
type: "GET",
|
|
dataType: 'json',
|
|
success: function(res) {
|
|
|
|
console.log('getPolicyTransactionDataForEndorsementEdit', res);
|
|
if(res.status == true){
|
|
|
|
hide_list_show_add()
|
|
|
|
var page_title = 'Edit Endorsement' + (res.data.client_short_name || res.data.policy_no || res.data.endorsement_no ?
|
|
' - ' + [res.data.client_short_name, res.data.policy_no,res.data.endorsement_no]
|
|
.filter(Boolean).join('-') : '');
|
|
|
|
$('#page_title').text(page_title);
|
|
|
|
$('#bro_payable_by').val(res.data.bro_payable_by)
|
|
|
|
if(res.data && res.data.co_share == 1){
|
|
console.log('copay yes', res.data);
|
|
$('#cop_yes').val(1);
|
|
}else{
|
|
console.log('copay no', res.data);
|
|
$('#cop_yes').val(0);
|
|
}
|
|
|
|
$('#policy_tranction_primarykey').val(res.data.id);
|
|
$('#client_type').val(res.data.client_type).trigger('change');
|
|
$('#client_id').val(res.data.client_id).change();
|
|
$('#base_cd_amount').val(res.data.base_cd_amount);
|
|
|
|
var tpaValue = '';
|
|
if (res.data.tpa_branch_id && res.data.tpa_id) {
|
|
tpaValue = res.data.tpa_branch_id + '-' + res.data.tpa_id;
|
|
}
|
|
$('#tpa').val(tpaValue).change();
|
|
|
|
|
|
setTimeout(function(){
|
|
$('.loader').fadeOut();
|
|
$('.loader-mask').delay(350).fadeOut('slow');
|
|
$('#client_branch_id').val(res.data.client_branch_id).select2();
|
|
// $('#client_policy_id').val(res.pt_id).select2();
|
|
}, 1000)
|
|
|
|
if(res.data.client_type == 2){
|
|
let data1 = policyListByClient[res.data.client_id];
|
|
appendPolicies(data1, res.pt_id);
|
|
}else{
|
|
let data2 = policy_list[res.data.client_branch_id];
|
|
appendPolicies(data2, res.pt_id);
|
|
}
|
|
|
|
setTimeout(function(){
|
|
$('#policy_start_date').val(res.data.policy_start_date);
|
|
$('#policy_end_date').val(res.data.policy_end_date);
|
|
$('#insurer_id').val(res.data.insurer_branch_id + '-' + res.data.insurer_id);
|
|
}, 1500)
|
|
|
|
$('#policy_no').val(res.data.policy_no);
|
|
$('#action_type').val(res.data.action_type);
|
|
$('#endorsement_no').val(res.data.endorsement_no);
|
|
$('#data_received_date').val(res.data.data_received_date);
|
|
$('#policy_issue_date').val(res.data.policy_issue_date);
|
|
$('#emp_count').val(res.data.emp_count);
|
|
$('#dependent_count').val(res.data.dependent_count);
|
|
$('#policy_status').val(res.data.status);
|
|
$('#endorse_eff_date').val(res.data.endorse_eff_date);
|
|
$('#month').val(res.data.month);setPolicyIssueMonth();
|
|
$('#last_action_date').val(res.data.last_action_date);
|
|
$('#install_due_date').val(res.data.install_due_date);
|
|
$('#bro_payable_by').val(res.data.bro_payable_by);
|
|
$('#cd_ac_pk').val(res.data.cd_ac_pk);
|
|
$('#cd_ac_no').val(res.data.cd_ac_no);
|
|
$('#ct_type').val(res.data.ct_type);
|
|
|
|
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);
|
|
// }
|
|
|
|
if (res.data.action_type == 'policy_instalment') {
|
|
$('.install_due_date_div').show()
|
|
}else{
|
|
$('.install_due_date_div').hide()
|
|
}
|
|
|
|
if (res?.data?.pt_co_share_details?.length > 0) {
|
|
let new_data = res.data.pt_co_share_details[0];
|
|
$('#base_premium').val(new_data.bp_amt ?? '');
|
|
$('#tp_premium').val(new_data.tp_amt ?? '');
|
|
$('#ter_premium').val(new_data.tep_amt ?? '');
|
|
}
|
|
|
|
removeAllInsurerCards();
|
|
|
|
if(res.data.pt_co_share_details.length > 0){
|
|
if (!res.data.pt_co_share_details[0].follower_policy_no) {res.data.pt_co_share_details[0].follower_policy_no = res.data.policy_no;}
|
|
setTimeout(function(){
|
|
populateCards(res.data.pt_co_share_details, true);
|
|
}, 2000);
|
|
}else{
|
|
addInsurerColumn();
|
|
}
|
|
|
|
if (res.data.client_type == 2) {
|
|
$('.branchdiv').hide();
|
|
$('#card_label_34').hide();
|
|
$('#card_label_37').hide();
|
|
} else {
|
|
$('.branchdiv').show();
|
|
$('#card_label_34').show();
|
|
$('#card_label_37').show();
|
|
}
|
|
|
|
if (res.data.policy_type_id == 1 || res.data.policy_type_id == 2 || res.data.policy_type_id == 3 || res.data.policy_type_id == 4 || res.data.policy_type_id == 5 || res.data.policy_type_id == 6 || res.data.policy_type_id == 7 || res.data.client_type == 2) {
|
|
$('#card_label_34').hide();
|
|
$('#card_label_37').hide();
|
|
}
|
|
|
|
// if(res.data.policy_type_id == 1 || res.data.policy_type_id == 2 || res.data.policy_type_id == 3 || res.data.policy_type_id == 4 || res.data.policy_type_id == 5 || res.data.policy_type_id == 6 || res.data.policy_type_id == 7){
|
|
// $('#is_cd_reduce_from_bds').prop('disabled',true).prop('checked', false);
|
|
// }else{
|
|
// $('#is_cd_reduce_from_bds').prop('disabled',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);
|
|
}
|
|
});
|
|
|
|
checkInvoiceStatusToHideSubmitBtn(id)
|
|
|
|
}
|
|
|
|
//------------- END EDIT FUNCTION --------------------------------------------------------------------------------------------
|
|
|
|
// do not remove this function
|
|
// 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(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);
|
|
// }
|
|
// }
|
|
|
|
// function amountCalculation(input) {
|
|
|
|
// console.log('############################## AMOUNT CALCULATION ############################################')
|
|
// console.log('amountCalculation : ' + input);
|
|
// let selectedOption = $('#client_policy_id').find('option:selected');
|
|
// console.log("selectedOption", selectedOption);
|
|
// let bap = selectedOption.data('bap');
|
|
// let allocg = selectedOption.data('allocg');
|
|
|
|
// const event = window.event;
|
|
// console.log("Event id:", event.target.id);
|
|
|
|
// let endorsement_type = $('#action_type').val();
|
|
// console.log('endorsement_type', endorsement_type);
|
|
|
|
// let isDeletion = (endorsement_type == "deletion");
|
|
// console.log('isDeletion:', isDeletion);
|
|
|
|
// // Retrieve and parse the values or default to 0 if not a number
|
|
// let bp = parseFloat($('#base_premium_' + input).val()) || 0;
|
|
// console.log("bp base premium", bp);
|
|
// let ncpa = parseFloat($('#non_comm_per_amt_' + input).val()) || 0;
|
|
// console.log("ncpa non comm base premium", ncpa);
|
|
|
|
// var tp = 0;
|
|
// if(allocg != 'EB'){
|
|
// tp = parseFloat($('#tp_premium_' + input).val()) || 0;
|
|
// }
|
|
// // do not remove this commented item
|
|
// // if(bap == 'Motor'){
|
|
// // tp = parseFloat($('#tp_premium_' + input).val()) || 0;
|
|
// // }
|
|
|
|
// var tep = 0;
|
|
// if(bap == 'Fire' || bap == 'Marine Cargo' || bap == 'Marine Hull'){
|
|
// tep = parseFloat($('#ter_premium_' + input).val()) || 0;
|
|
// }
|
|
|
|
// //co-share premium
|
|
// let cop = parseFloat($('#co_premium_' + input).val()) || 0;
|
|
|
|
// var cotp = 0;
|
|
// if(bap == 'Motor'){
|
|
// cotp = parseFloat($('#co_tp_premium_' + input).val()) || 0;
|
|
// }
|
|
|
|
// var cotep = 0;
|
|
// if(bap == 'Fire' || bap == 'Marine Cargo' || bap == 'Marine Hull'){
|
|
// cotep = parseFloat($('#co_ter_premium_' + input).val()) || 0;
|
|
// }
|
|
|
|
// checkAndDistributeTax(input);
|
|
// let cgst = parseFloat($('#cgst_' + input).val()) || 0;
|
|
// let sgst = parseFloat($('#sgst_' + input).val()) || 0;
|
|
// let igst = parseFloat($('#igst_' + input).val()) || 0;
|
|
|
|
|
|
// let stamp_duty_amt = parseFloat($('#stamp_duty_' + input).val()) || 0;
|
|
// let agreed_amount = parseFloat($('#agreed_amount_' + input).val()) || 0;
|
|
|
|
// let agreed_bp_per = parseFloat($('#agreed_bp_' + input).val()) || 0;
|
|
// let agreed_tp_per = parseFloat($('#agreed_tp_' + input).val()) || 0;
|
|
// let agreed_tep_per = parseFloat($('#agreed_tep_' + 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;
|
|
|
|
|
|
// // 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').val() == 1){
|
|
|
|
// tpTotal = bp + tp + tep;
|
|
|
|
// base_premium = bp;
|
|
// third_part_premium = tp;
|
|
// terrisom_premium = tep;
|
|
// }
|
|
|
|
// console.log('base_premium', base_premium);
|
|
// console.log('third_part_premium', third_part_premium);
|
|
// console.log('terrisom_premium', terrisom_premium);
|
|
|
|
// if ($('#cop_yes').val() == 0) {
|
|
// $('#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 = (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 ############################################')
|
|
|
|
// applyDeletionSymbolsToFields(input, isDeletion);
|
|
|
|
// }
|
|
|
|
// 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));
|
|
// }
|
|
|
|
// Apply Deletion (Negative) Values
|
|
// function applyDeletionSymbolsToFields(input, isDeletion) {
|
|
// console.log('========== APPLYING DELETION SYMBOLS ==========');
|
|
|
|
// if (!isDeletion) return;
|
|
|
|
// const fieldIds = [
|
|
// 'base_premium',
|
|
// 'tp_premium',
|
|
// 'ter_premium',
|
|
// 'co_premium',
|
|
// 'co_tp_premium',
|
|
// 'co_ter_premium',
|
|
// 'gst_amount',
|
|
// 'agreed_amount',
|
|
// 'non_comm_per_amt',
|
|
// 'total_amt',
|
|
// 'exp_amt'
|
|
// ];
|
|
|
|
// fieldIds.forEach(field => {
|
|
// const $el = $('#' + field + '_' + input);
|
|
// console.log('$el', '#' + field + '_' + input);
|
|
// console.log('$el', $el);
|
|
// let val = $el.val()?.trim();
|
|
// console.log('$val', val);
|
|
// if (!val || val.startsWith('-')) return;
|
|
|
|
// let num = parseFloat(val);
|
|
// if (!isNaN(num) && num > 0) $el.val(-num);
|
|
// });
|
|
|
|
// console.log('========== COMPLETED DELETION SYMBOL APPLICATION ==========');
|
|
// }
|
|
|
|
function checkAndDistributeTax(input){
|
|
|
|
const event = window.event;
|
|
console.log("Event id:", event.target.id);
|
|
|
|
let policy_type_id = $('#client_policy_id').find('option:selected').attr('data-ptid');
|
|
policy_type_id = parseInt(policy_type_id);
|
|
console.log('policy_type_id', policy_type_id);
|
|
|
|
let cgst = parseFloat($('#cgst_' + input).val());
|
|
let sgst = parseFloat($('#sgst_' + input).val());
|
|
let igst = parseFloat($('#igst_' + input).val());
|
|
|
|
// ✅ Allow 0 only for policy types 2, 5, 7
|
|
const allowZero = [1,2,3,4,5,6,7,38,39,40].includes(policy_type_id);
|
|
console.log("allowZero", allowZero);
|
|
|
|
// 🔒 Validation: Disallow 0 or negative values for other policy types
|
|
if (!allowZero) {
|
|
if ((cgst <= 0 && (event.target.id).startsWith('cgst')) ||
|
|
(sgst <= 0 && (event.target.id).startsWith('sgst')) ||
|
|
(igst <= 0 && (event.target.id).startsWith('igst'))) {
|
|
|
|
toastr.warning('Tax value must be greater than 0 for this policy type.');
|
|
$('#'+ event.target.id).val('');
|
|
$('#igst_' + input).val('');
|
|
$('#cgst_' + input).val('');
|
|
$('#sgst_' + input).val('');
|
|
|
|
return;
|
|
}
|
|
}
|
|
|
|
if (((event.target.id).startsWith('cgst'))) {
|
|
|
|
if (!isFinite(cgst) || isNaN(cgst) || cgst === undefined) {
|
|
cgst = '';
|
|
}
|
|
|
|
$('#cgst_' + input).val(cgst);
|
|
if(cgst == ""){
|
|
$('#sgst_' + input).val(0);
|
|
}else{
|
|
$('#sgst_' + input).val(cgst);
|
|
}
|
|
$('#igst_' + input).val(0);
|
|
}
|
|
|
|
if (((event.target.id).startsWith('sgst'))) {
|
|
|
|
if (!isFinite(sgst) || isNaN(sgst) || sgst === undefined) {
|
|
sgst = '';
|
|
}
|
|
|
|
$('#sgst_' + input).val(sgst);
|
|
if(sgst == ""){
|
|
$('#cgst_' + input).val(0);
|
|
}else{
|
|
$('#cgst_' + input).val(sgst);
|
|
}
|
|
$('#igst_' + input).val(0);
|
|
}
|
|
|
|
if ((event.target.id).startsWith('igst')) {
|
|
$('#cgst_' + input).val(0);
|
|
$('#sgst_' + input).val(0);
|
|
}
|
|
|
|
// Ensure IGST, CGST, and SGST are never NaN, undefined, or Infinity
|
|
$('#igst_' + input).val(isFinite($('#igst_' + input).val()) ? $('#igst_' + input).val() : 0);
|
|
$('#cgst_' + input).val(isFinite($('#cgst_' + input).val()) ? $('#cgst_' + input).val() : 0);
|
|
$('#sgst_' + input).val(isFinite($('#sgst_' + input).val()) ? $('#sgst_' + input).val() : 0);
|
|
}
|
|
|
|
// Main calculation function
|
|
function amountCalculation(input) {
|
|
|
|
console.log('############################## AMOUNT CALCULATION ############################################');
|
|
console.log('amountCalculation:', input);
|
|
|
|
let selectedOption = $('#client_policy_id').find('option:selected');
|
|
let bap = selectedOption.data('bap') || '';
|
|
let allocg = selectedOption.data('allocg') || '';
|
|
let endorsement_type = $('#action_type').val();
|
|
let isDeletion = false;
|
|
// let isDeletion = endorsement_type === "deletion" || endorsement_type === "policy_cancellation";
|
|
console.log({bap, allocg, isDeletion});
|
|
|
|
const event = window.event || {};
|
|
|
|
// Helper functions
|
|
const rawVal = id => {
|
|
const v = $('#' + id + '_' + input).val();
|
|
return v === undefined || v === null ? '' : String(v).trim();
|
|
};
|
|
const numVal = id => {
|
|
const n = parseFloat(rawVal(id));
|
|
return isNaN(n) ? 0 : n;
|
|
};
|
|
const absNum = id => Math.abs(numVal(id));
|
|
|
|
// Read input values
|
|
let bp = absNum('base_premium');
|
|
let ncpa = absNum('non_comm_per_amt');
|
|
let tp = (allocg !== 'EB') ? absNum('tp_premium') : 0;
|
|
let tep = (['Fire', 'Marine Cargo', 'Marine Hull'].includes(bap)) ? absNum('ter_premium') : 0;
|
|
let cop = absNum('co_premium');
|
|
let cotp = (allocg !== 'EB') ? absNum('co_tp_premium') : 0;
|
|
let cotep = (['Fire', 'Marine Cargo', 'Marine Hull'].includes(bap)) ? absNum('co_ter_premium') : 0;
|
|
|
|
console.log('premiums :', { bp, tp, tep, cop, cotp, cotep, ncpa });
|
|
|
|
// let bp_raw_val = parseFloat($('#base_premium_' + input).val());
|
|
let bp_raw_val = parseFloat($('#base_premium').val()) || 0;
|
|
console.log('bp_raw_val', bp_raw_val);
|
|
|
|
// handel the positive(+), negative(-) symbole add the value
|
|
if(endorsement_type === "addition" || endorsement_type === "baby_addition" || endorsement_type === "addition_inception"){
|
|
isDeletion = false
|
|
}else if(endorsement_type === "deletion" || endorsement_type === "policy_cancellation"){
|
|
isDeletion = true
|
|
}else if(bp_raw_val < 0){
|
|
isDeletion = true;
|
|
console.log('Value is negative:', bp_raw_val);
|
|
}
|
|
|
|
let co_share_type_val = numVal('co_share_type');
|
|
console.log('co_share_type_val :', co_share_type_val);
|
|
|
|
// GST & Tax Setup
|
|
checkAndDistributeTax(input);
|
|
let cgst = numVal('cgst'), sgst = numVal('sgst'), igst = numVal('igst');
|
|
let gst_per = igst || (cgst + sgst);
|
|
|
|
let stamp_duty_amt = absNum('stamp_duty');
|
|
let agreed_amount = absNum('agreed_amount');
|
|
let agreed_bp_per = numVal('agreed_bp');
|
|
let agreed_tp_per = numVal('agreed_tp');
|
|
let agreed_tep_per = numVal('agreed_tep');
|
|
let standard_bp_per = numVal('standard_bp');
|
|
let standard_tp_per = numVal('standard_tp');
|
|
let standard_tep_per = numVal('standard_tep');
|
|
|
|
let gst_amount = numVal('gst_amount');
|
|
|
|
// Premiums for calculation
|
|
let base_premium = ($('#bro_payable_by').val() == 1) ? bp : cop;
|
|
let third_part_premium = ($('#bro_payable_by').val() == 1) ? tp : cotp;
|
|
let terrisom_premium = ($('#bro_payable_by').val() == 1) ? tep : cotep;
|
|
let tpTotal = base_premium + third_part_premium + terrisom_premium;
|
|
|
|
// Co-premium defaults
|
|
if ($('#cop_yes').val() == 0) {
|
|
if (!rawVal('co_premium')) $('#co_premium_' + input).val(bp);
|
|
if (!rawVal('co_tp_premium') && bap === 'Motor') $('#co_tp_premium_' + input).val(tp);
|
|
if (!rawVal('co_ter_premium') && ['Fire', 'Marine Cargo', 'Marine Hull'].includes(bap)) $('#co_ter_premium_' + input).val(tep);
|
|
if (!rawVal('co_share_per')) $('#co_share_per_' + input).val(100);
|
|
}
|
|
|
|
// GST Calculations
|
|
let ncpaTotal = tpTotal + ncpa;
|
|
let gst_per_amt = (tpTotal * gst_per) / 100;
|
|
let ncpa_gst_per_amt = (ncpaTotal * gst_per) / 100;
|
|
|
|
let gstValue =
|
|
event.target?.id?.startsWith('non_comm_per_amt') ? ncpa_gst_per_amt :
|
|
event.target?.id?.startsWith('gst_amount') ? gst_amount :
|
|
ncpa ? ncpa_gst_per_amt : gst_per_amt;
|
|
|
|
$('#gst_amount_' + input).val(isFinite(gstValue) ? gstValue : 0);
|
|
|
|
// Final total
|
|
let finalTotal = tpTotal + gst_per_amt + stamp_duty_amt;
|
|
$('#total_amt_' + input).val(isFinite(finalTotal) ? finalTotal : 0);
|
|
|
|
// Expected amount
|
|
let expectedAmount = 0;
|
|
let sum_agreed_per = agreed_bp_per + agreed_tp_per + agreed_tep_per;
|
|
|
|
if (agreed_amount > 0) {
|
|
expectedAmount = agreed_amount;
|
|
} else if (sum_agreed_per > 0) {
|
|
expectedAmount =
|
|
(base_premium * agreed_bp_per) / 100 +
|
|
(third_part_premium * agreed_tp_per) / 100 +
|
|
(terrisom_premium * agreed_tep_per) / 100;
|
|
} else {
|
|
expectedAmount =
|
|
(base_premium * standard_bp_per) / 100 +
|
|
(third_part_premium * standard_tp_per) / 100 +
|
|
(terrisom_premium * standard_tep_per) / 100;
|
|
}
|
|
|
|
$('#exp_amt_' + input).val(isFinite(expectedAmount) ? expectedAmount : 0);
|
|
|
|
setCoPremiums(input);
|
|
|
|
// ✅ Apply deletion symbols last (safely);
|
|
// if (isDeletion) {
|
|
applyDeletionSymbolsToFields(input, isDeletion);
|
|
// }
|
|
|
|
console.log('############################## END AMOUNT CALCULATION ############################################');
|
|
}
|
|
|
|
// Apply Deletion (Negative) Values
|
|
function applyDeletionSymbolsToFields(input, isDeletion) {
|
|
|
|
console.log('========== APPLYING DELETION SYMBOLS ==========');
|
|
|
|
const fieldIds = [
|
|
'base_premium',
|
|
'tp_premium',
|
|
'ter_premium',
|
|
'co_premium',
|
|
'co_tp_premium',
|
|
'co_ter_premium',
|
|
'gst_amount',
|
|
'agreed_amount',
|
|
'non_comm_per_amt',
|
|
'total_amt',
|
|
'exp_amt'
|
|
];
|
|
|
|
fieldIds.forEach(field => {
|
|
const $el = $('#' + field + '_' + input);
|
|
let val = $el.val()?.trim();
|
|
if (!val) return;
|
|
|
|
let num = parseFloat(val.replace(/^-/, '')); // remove any existing minus first
|
|
console.log('num', num);
|
|
if (isNaN(num)) return;
|
|
|
|
if (isDeletion) {
|
|
// Apply minus sign
|
|
if (num > 0) $el.val(-num);
|
|
} else {
|
|
// Remove minus sign
|
|
$el.val(num);
|
|
}
|
|
});
|
|
|
|
console.log('========== COMPLETED DELETION SYMBOL APPLICATION ==========');
|
|
}
|
|
|
|
function setCoPremiums(input) {
|
|
// Get base, TP, and TEP premiums for the given input row
|
|
let bp = parseFloat($('#base_premium').val()) || 0;
|
|
let tp = parseFloat($('#tp_premium').val()) || 0;
|
|
let tep = parseFloat($('#ter_premium').val()) || 0;
|
|
let coSharePer = parseFloat($('#co_share_per_' + input).val()) || 0;
|
|
|
|
// Calculate co-share premiums
|
|
let cop = (bp * coSharePer) / 100;
|
|
let cotp = (tp * coSharePer) / 100;
|
|
let cotep = (tep * coSharePer) / 100;
|
|
|
|
// Log for debugging
|
|
console.log(`Row: ${input}`);
|
|
console.log(`Base Premium: ${bp}`);
|
|
console.log(`TP Premium: ${tp}`);
|
|
console.log(`TEP Premium: ${tep}`);
|
|
console.log(`Co-Share %: ${coSharePer}`);
|
|
console.log(`Co Base Premium: ${cop.toFixed(2)}`);
|
|
console.log(`Co TP Premium: ${cotp.toFixed(2)}`);
|
|
console.log(`Co TEP Premium: ${cotep.toFixed(2)}`);
|
|
|
|
// Set calculated values
|
|
$('#co_premium_' + input).val(cop.toFixed(2));
|
|
$('#co_tp_premium_' + input).val(cotp.toFixed(2));
|
|
$('#co_ter_premium_' + input).val(cotep.toFixed(2));
|
|
}
|
|
|
|
function actualAmountCalculation(input, field = null){
|
|
|
|
console.log('actualAmountCalculation function called')
|
|
console.log('actualAmountCalculation function input', input)
|
|
console.log('actualAmountCalculation function field', field)
|
|
|
|
let selectedOption = $('#client_policy_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;
|
|
});
|
|
}
|
|
|
|
}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');
|
|
}
|
|
|
|
}
|
|
|
|
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="base_premium"]').addClass('readonly-select');
|
|
$('#base_premium').removeClass('readonly-select');
|
|
|
|
$('input[name="tp_premium"]').addClass('readonly-select');
|
|
$('#tp_premium').removeClass('readonly-select');
|
|
|
|
$('input[name="ter_premium"]').addClass('readonly-select');
|
|
$('#ter_premium').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');
|
|
} 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="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');
|
|
}
|
|
}
|
|
|
|
function validateRange(input) {
|
|
// if (input.value < 1) input.value = 1;
|
|
if (input.value > 100) input.value = 100;
|
|
}
|
|
|
|
function checkInvoiceStatusToHideSubmitBtn(id){
|
|
|
|
$.ajax({
|
|
url: '<?php echo base_url('util/checkInvoiceStatus/');?>'+ id,
|
|
type: "GET",
|
|
dataType: 'json',
|
|
success: function (res) {
|
|
|
|
console.log(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 getpolicyDataForEndorsement(input){
|
|
|
|
var client_policy_id = $(input).val();
|
|
console.log(client_policy_id);
|
|
|
|
if(client_policy_id){
|
|
$.ajax({
|
|
url: '<?php echo base_url('util/get_client_policy_data_using_client_policy_id/');?>'+ client_policy_id,
|
|
type: "GET",
|
|
dataType: 'json',
|
|
success: function (res) {
|
|
|
|
console.log(res)
|
|
if(res.status == true){
|
|
$('#ct_type').val(1)
|
|
}else{
|
|
$('#ct_type').val(2)
|
|
console.log(res.message, 'warning');
|
|
}
|
|
},
|
|
error: function (xhr, status, error) {
|
|
console.error(xhr.responseText);
|
|
console.error(status, error);
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
//---------------------------------------------------------------------------------------------------------
|
|
|
|
var insurerCount = 0;
|
|
|
|
function addInsurerColumn() {
|
|
insurerCount++;
|
|
const isFinanceOrBrokerage = (role_id == 1 || role_id == 5 || team_id.includes('6') || team_id.includes('4'));
|
|
|
|
let showDelete = insurerCount > 1 ? `
|
|
<button type="button"
|
|
class="btn btn-sm btn-danger delete-insurer"
|
|
data-count="${insurerCount}">
|
|
Delete
|
|
</button>` : '';
|
|
|
|
|
|
let showAdd = insurerCount == 1 ? '' : '';
|
|
|
|
let cardHTML = `<div class="p-1 mb-2 insurer-card" id="insurerCardContainer_${insurerCount}" data-count="${insurerCount}">
|
|
|
|
<div class="d-flex justify-content-between align-items-center border-bottom pb-2 mb-3">
|
|
<div class="fw-bold text-primary insurer-card-title">Insurer - ${insurerCount}</div>
|
|
|
|
<div class="d-flex align-items-center gap-2">
|
|
${showAdd}
|
|
${showDelete}
|
|
</div>
|
|
</div>
|
|
|
|
<div id="insurerCardContainer">
|
|
|
|
<div class="form-row mb-2">
|
|
|
|
<div class="col-md-4 mb-2 card_group_1">
|
|
|
|
<div class="d-flex align-items-center justify-content-between mb-1">
|
|
|
|
<label class="card_label_1 mb-0 d-flex align-items-center">
|
|
Insurer <span class="text-danger">*</span>
|
|
</label>
|
|
|
|
<div class="card_group_2" style="display:none">
|
|
<label class="card_label_2 mb-0 d-flex align-items-center">
|
|
<span class="mr-1">Is Leader?</span>
|
|
|
|
<input data-id="${insurerCount}" id="co_share_type_${insurerCount}"
|
|
type="checkbox" name="co_share_type[]"
|
|
onchange="select_leader_disable_premium_amt(this, '${insurerCount}')"
|
|
class="mr-1">
|
|
|
|
|
|
</label>
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<select class="form-control follow_insurer readonly-select" data-count="${insurerCount}" id="follow_insurer_id_${insurerCount}" name="follow_insurer_id[]">
|
|
<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>
|
|
</div>
|
|
<div class="col-md-4 mb-2 card_group_34" style="display:none;">
|
|
<!-- <label class="card_label_34">CD Acc No</label> -->
|
|
<label class="card_label_34 d-flex align-items-center">
|
|
<span class="flex-grow-1">CD Acc No</span>
|
|
|
|
<small id="cd_current_balance_info_${insurerCount}"
|
|
class="text-right"
|
|
style="font-size: x-small;">
|
|
</small>
|
|
</label>
|
|
<input type="text" class="form-control readonly-color" id="cd_account_no_${insurerCount}" readonly>
|
|
<input type="hidden" class="form-control readonly-color right-align-input" id="cd_current_balance_${insurerCount}" readonly>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="form-row mb-2">
|
|
<div class="col-md-4 mb-2 card_group_35">
|
|
<label class="card_label_35">Policy No</label>
|
|
<input type="text" class="form-control readonly-color" id="follower_policy_no_${insurerCount}" name="follower_policy_no[]" readonly>
|
|
</div>
|
|
<div class="col-md-4 mb-2 card_group_40">
|
|
<label class="card_label_40"> Endorsement Issue Date </label>
|
|
<input type="text" class="form-control" id="calc_policy_issue_date_${insurerCount}" name="calc_policy_issue_date[]">
|
|
</div>
|
|
<div class="col-md-4 mb-2 card_group_3" id="coshare_wrap_${insurerCount}" style="display:none;">
|
|
<label class="card_label_3">Co-Share %</label>
|
|
<div class="input-wrap">
|
|
<input type="text" class="form-control right-align-input input-content" id="co_share_per_${insurerCount}" name="co_share_per[]" oninput="validateRange(this)" onchange="co_share_percentage_calculation('${insurerCount}')" onkeypress="return onlyNumbers(event)">
|
|
<span class="input-symbol">%</span>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="form-row compact-details-section mb-2">
|
|
|
|
<div class="col-md-6">
|
|
|
|
<div class="form-row mb-1 text-success small font-weight-bold">
|
|
<div class="col-6">Premium</div>
|
|
<div class="col-6"></div>
|
|
</div>
|
|
|
|
<div class="form-row mb-2 align-items-center">
|
|
<div class="col-6"><label class="card_label_36">Non Commissionable </label></div>
|
|
<div class="col-6">
|
|
<input type="text" class="form-control right-align-input" id="non_comm_per_amt_${insurerCount}" name="non_comm_per_amt[]" oninput="amountCalculation('${insurerCount}')" onkeypress="return onlyNumbers(event)">
|
|
</div>
|
|
</div>
|
|
|
|
<div class="form-row mb-2 card_group_7">
|
|
<div class="col-6"><label class="card_label_7">Base </label></div>
|
|
<div class="col-6">
|
|
<input type="text" class="form-control right-align-input" id="co_premium_${insurerCount}" name="co_premium[]" oninput="amountCalculation('${insurerCount}')" onkeypress="return onlyNumbers(event)">
|
|
</div>
|
|
</div>
|
|
|
|
<div class="form-row mb-2 card_group_38 hidecotp" style="display:none;">
|
|
<div class="col-6"><label class="card_label_38">TP </label></div>
|
|
<div class="col-6">
|
|
<input type="text" class="form-control right-align-input" id="co_tp_premium_${insurerCount}" name="co_tp_premium[]" oninput="" onkeypress="return onlyNumbers(event)">
|
|
</div>
|
|
</div>
|
|
|
|
<div class="form-row mb-2 card_group_39 hidecoter" style="display:none;">
|
|
<div class="col-6"><label class="card_label_39">TEP </label></div>
|
|
<div class="col-6">
|
|
<input type="text" class="form-control right-align-input" id="co_ter_premium_${insurerCount}" name="co_ter_premium[]" oninput="" onkeypress="return onlyNumbers(event)">
|
|
</div>
|
|
</div>
|
|
|
|
<div class="form-row mb-2">
|
|
<div class="col-2 card_group_8">
|
|
<label class="card_label_8 small">CGST</label>
|
|
<div class="input-wrap mr-2">
|
|
<input type="text" class="form-control right-align-input input-content" id="cgst_${insurerCount}" name="cgst[]" oninput="amountCalculation('${insurerCount}')" onkeypress="return onlyNumbers(event)">
|
|
<span class="input-symbol">%</span>
|
|
</div>
|
|
</div>
|
|
<div class="col-2 card_group_9">
|
|
<label class="card_label_9 small">SGST</label>
|
|
<div class="input-wrap mr-2">
|
|
<input type="text" class="form-control right-align-input input-content" id="sgst_${insurerCount}" name="sgst[]" oninput="amountCalculation('${insurerCount}')" onkeypress="return onlyNumbers(event)">
|
|
<span class="input-symbol">%</span>
|
|
</div>
|
|
</div>
|
|
<div class="col-2 card_group_10">
|
|
<label class="card_label_10 small">IGST</label>
|
|
<div class="input-wrap mr-2">
|
|
<input type="text" class="form-control right-align-input input-content" id="igst_${insurerCount}" name="igst[]" oninput="amountCalculation('${insurerCount}')" onkeypress="return onlyNumbers(event)">
|
|
<span class="input-symbol">%</span>
|
|
</div>
|
|
</div>
|
|
<div class="col-6 card_group_11">
|
|
<label class="card_label_11">GST Amount</label>
|
|
<input type="text" class="form-control right-align-input" id="gst_amount_${insurerCount}" name="gst_amount[]" onchange="amountCalculation('${insurerCount}')" onkeypress="return onlyNumbers(event)">
|
|
</div>
|
|
</div>
|
|
|
|
<div class="form-row mb-2 align-items-center">
|
|
<div class="col-6"><label class="card_label_12">Stamp Duty</label></div>
|
|
<div class="col-6">
|
|
<input type="text" class="form-control right-align-input" id="stamp_duty_${insurerCount}" name="stamp_duty[]" oninput="amountCalculation('${insurerCount}')" onkeypress="return onlyNumbers(event)">
|
|
</div>
|
|
</div>
|
|
|
|
<div class="form-row mb-2 align-items-center">
|
|
<div class="col-6"><label class="card_label_13">Total</label></div>
|
|
<div class="col-6">
|
|
<input type="text" class="form-control readonly-color right-align-input" id="total_amt_${insurerCount}" name="total[]" readonly onkeypress="return onlyNumbers(event)">
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="col-md-1"></div>
|
|
<div class="col-md-5">
|
|
<div class="form-row">
|
|
<div class="col-12">
|
|
<div class="form-row mb-1 text-success small font-weight-bold">
|
|
<div class="col-4 csslabel">Remuneration</div>
|
|
<div class="col-4 cssbp"></div>
|
|
<div class="col-4 hidetp csstp"></div>
|
|
<div class="col-4 hideter csstep" style="display:none;"></div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="col-12">
|
|
<div class="form-row mb-2 align-items-center">
|
|
<div class="col-4 csslabel"><label class="card_label_14">Agreed (%)</label></div>
|
|
<div class="col-4 card_group_14 cssbp">
|
|
<div class="input-wrap mr-2">
|
|
<span class="input-prefix">BP </span>
|
|
<input type="text" class="form-control right-align-input input-content" id="agreed_bp_${insurerCount}" name="agreed_bp[]" oninput="amountCalculation('${insurerCount}'); validateRange(this)" onkeypress="return onlyNumbers(event)" >
|
|
<span class="input-symbol">%</span>
|
|
</div>
|
|
</div>
|
|
<div class="col-4 card_group_15 hidetp csstp">
|
|
<div class="input-wrap mr-2">
|
|
<span class="input-prefix">TP </span>
|
|
<input type="text" class="form-control right-align-input input-content" id="agreed_tp_${insurerCount}" name="agreed_tp[]" oninput="amountCalculation('${insurerCount}'); validateRange(this)" onkeypress="return onlyNumbers(event)">
|
|
<span class="input-symbol">%</span>
|
|
</div>
|
|
</div>
|
|
<div class="col-4 card_group_16 hideter csstep" style="display:none;">
|
|
<div class="input-wrap">
|
|
<span class="input-prefix">TEP </span>
|
|
<input type="text" class="form-control right-align-input input-content" id="agreed_tep_${insurerCount}" name="agreed_ter[]" oninput="amountCalculation('${insurerCount}'); validateRange(this)" onkeypress="return onlyNumbers(event)" >
|
|
<span class="input-symbol">%</span>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
${isFinanceOrBrokerage ? `
|
|
<div class="col-12">
|
|
<div class="form-row mb-2 align-items-center">
|
|
<div class="col-4"><label class="card_label_17">Agreed Amount</label></div>
|
|
<div class="col-8 card_group_17">
|
|
<input type="text" class="form-control right-align-input" id="agreed_amount_${insurerCount}" name="agreed_amount[]" oninput="amountCalculation('${insurerCount}')" onkeypress="return onlyNumbers(event)">
|
|
</div>
|
|
</div>
|
|
</div>
|
|
` : ''}
|
|
|
|
<div class="col-12">
|
|
<div class="form-row mb-2 align-items-center">
|
|
<div class="col-4 csslabel"><label class="card_label_18">Standard</label></div>
|
|
<div class="col-4 card_group_18 cssbp">
|
|
<div class="input-wrap mr-2">
|
|
<span class="input-prefix">BP </span>
|
|
<input type="text" class="form-control readonly-color right-align-input input-content" id="standard_bp_${insurerCount}" name="standard_bp[]" onkeypress="return onlyNumbers(event)" readonly>
|
|
<span class="input-symbol">%</span>
|
|
</div>
|
|
</div>
|
|
<div class="col-4 card_group_19 hidetp csstp">
|
|
<div class="input-wrap mr-2">
|
|
<span class="input-prefix">TP </span>
|
|
<input type="text" class="form-control readonly-color right-align-input input-content" id="standard_tp_${insurerCount}" name="standard_tp[]" onkeypress="return onlyNumbers(event)" readonly >
|
|
<span class="input-symbol">%</span>
|
|
</div>
|
|
</div>
|
|
<div class="col-4 card_group_20 hideter csstep" style="display:none;">
|
|
<div class="input-wrap">
|
|
<span class="input-prefix">TEP </span>
|
|
<input type="text" class="form-control readonly-color right-align-input input-content" id="standard_tep_${insurerCount}" name="standard_ter[]" onkeypress="return onlyNumbers(event)" readonly></td>
|
|
<span class="input-symbol">%</span>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
|
|
${isFinanceOrBrokerage ? `
|
|
<div class="col-12">
|
|
<div class="form-row mb-2 align-items-center">
|
|
<div class="col-4"><label class="card_label_30">Expected</label></div>
|
|
<div class="col-8 card_group_30">
|
|
<input type="text" class="form-control readonly-select right-align-input" id="exp_amt_${insurerCount}" name="exp_amt[]" onchange="actualAmountCalculation('${insurerCount}')" onkeypress="return onlyNumbers(event)">
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
|
|
<div class="col-12">
|
|
<div class="form-row mb-2 align-items-center">
|
|
<div class="col-4 csslabel"><label class="card_label_24">Actual (%)</label></div>
|
|
<div class="col-4 card_group_24 cssbp">
|
|
<div class="input-wrap mr-2">
|
|
<span class="input-prefix">BP </span>
|
|
<input type="text" class="form-control readonly-select right-align-input input-content" id="actual_bp_per_${insurerCount}" name="actual_bp_per[]" onchange="actualAmountCalculation('${insurerCount}', 'bp_per')" onkeypress="return onlyNumbers(event)">
|
|
<span class="input-symbol">%</span>
|
|
</div>
|
|
</div>
|
|
<div class="col-4 card_group_22 hidetp csstp">
|
|
<div class="input-wrap mr-2">
|
|
<span class="input-prefix">TP </span>
|
|
<input type="text" class="form-control readonly-select right-align-input input-content" id="actual_tp_per_${insurerCount}" name="actual_tp_per[]" onchange="actualAmountCalculation('${insurerCount}', 'tp_per')" onkeypress="return onlyNumbers(event)">
|
|
<span class="input-symbol">%</span>
|
|
</div>
|
|
</div>
|
|
<div class="col-4 card_group_23 hideter csstep" style="display:none;">
|
|
<div class="input-wrap">
|
|
<span class="input-prefix">TEP </span>
|
|
<input type="text" class="form-control readonly-select right-align-input input-content" id="actual_tep_per_${insurerCount}" name="actual_tep_per[]" onchange="actualAmountCalculation('${insurerCount}', 'tep_per')" onkeypress="return onlyNumbers(event)">
|
|
<span class="input-symbol">%</span>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
` : ''}
|
|
<div class="col-12">
|
|
<div class="form-row mb-2 align-items-center">
|
|
<div class="col-4 csslabel "><label class="card_label_21">Actual Amount</label></div>
|
|
<div class="col-4 card_group_21 cssbp">
|
|
<div class="input-wrap">
|
|
<span class="input-prefix">BP </span>
|
|
<input type="text" class="form-control 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)">
|
|
</div>
|
|
</div>
|
|
<div class="col-4 card_group_22 hidetp csstp">
|
|
<div class="input-wrap">
|
|
<span class="input-prefix">TP </span>
|
|
<input type="text" class="form-control 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)">
|
|
</div>
|
|
</div>
|
|
<div class="col-4 card_group_23 hideter csstep" style="display:none;">
|
|
<div class="input-wrap">
|
|
<span class="input-prefix">TEP </span>
|
|
<input type="text" class="form-control 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)">
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
|
|
</div>
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="form-row mb-2">
|
|
<div class="col-md-12 card_group_33" style="display:none;">
|
|
<label class="card_label_33">all Hidden</label>
|
|
<input type="hidden" name="co_share_id[]" id="co_share_id[]" onkeypress="return onlyNumbers(event)">
|
|
|
|
<input type="hidden" id="base_premium_${insurerCount}" name="base_premium[]" oninput="amountCalculation('${insurerCount}')" onkeypress="return onlyNumbers(event)" class="bp_value">
|
|
<input type="hidden" id="tp_premium_${insurerCount}" name="tp_premium[]" oninput="amountCalculation('${insurerCount}')" onkeypress="return onlyNumbers(event)" class="tp_value">
|
|
<input type="hidden" id="ter_premium_${insurerCount}" name="ter_premium[]" oninput="amountCalculation('${insurerCount}')" onkeypress="return onlyNumbers(event)" class="ter_value">
|
|
</div>
|
|
</div>
|
|
|
|
</div>
|
|
</div>`;
|
|
|
|
$('#allInsurerCards').append(cardHTML);
|
|
|
|
// --- Post-Insertion Logic (Initializations and dynamic setting) ---
|
|
|
|
// 1. Initialize Flatpickr for Policy Issue Date
|
|
flatpickr(`#calc_policy_issue_date_${insurerCount}`, {
|
|
dateFormat: "d/m/Y",
|
|
allowInput: false
|
|
});
|
|
|
|
// 2. Apply Visibility and Set Standard Percentages
|
|
applyPolicyVisibilityAndStandards(insurerCount);
|
|
|
|
// 3. Attach Delete Event Listener
|
|
$('.delete-insurer').off('click').on('click', function() {
|
|
const count_index = $(this).data('count');
|
|
removeInsurerCard(count_index);
|
|
});
|
|
|
|
return insurerCount;
|
|
|
|
|
|
}
|
|
|
|
/**
|
|
* Applies visibility classes and sets standard percentages based on selected policy data.
|
|
* @param {number} currentInsurerCount - The index of the card to update.
|
|
*/
|
|
function applyPolicyVisibilityAndStandards(currentInsurerCount) {
|
|
|
|
const cardElement = $(`#insurerCardContainer_${currentInsurerCount}`);
|
|
|
|
// --- 1. Get Policy Data ---
|
|
var selectedOption = $('#client_policy_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'); // Base Agreement Policy Type (e.g., 'Fire', 'Motor')
|
|
var allocg = selectedOption.data('allocg'); // Allocation Group (e.g., "EB")
|
|
|
|
console.log('allocg:', allocg);
|
|
|
|
var client_type_id = $('#client_type').val() ?? 1;
|
|
var is_co_pay_yes = $('#cop_yes').val();
|
|
if(is_co_pay_yes == "" || is_co_pay_yes == null){
|
|
is_co_pay_yes = 0;
|
|
}
|
|
|
|
console.log('#cop_yes', $('#cop_yes').val());
|
|
console.log('is_co_pay_yes', is_co_pay_yes);
|
|
|
|
// --- 2. Apply Visibility (Hiding/Showing Card Sections) ---
|
|
// Instead of manipulating global classes like $('.hideter').show(), we manipulate classes on the card elements.
|
|
|
|
// General reset/hide for the current card
|
|
console.log(allocg);
|
|
console.log("*(");
|
|
var $allPremiumCols = $('.csslabel, .cssbp , .csstp,.csstep');
|
|
|
|
if (allocg == "EB") {
|
|
// ----------------------------------------------------
|
|
// CASE: 2 Columns Visible (Label, BP)
|
|
// Goal: Both must be col-6 to fill the row (6 + 6 = 12)
|
|
// ----------------------------------------------------
|
|
$('.hideter').hide();
|
|
$('.hidetp').hide();
|
|
$('.hidecoter').hide();
|
|
$('.hidecotp').hide();
|
|
|
|
// Select ONLY the currently visible columns and set them to col-6
|
|
// Since TP and TEP have the hidetp/hideter classes, they are hidden and excluded by :visible.
|
|
$allPremiumCols.filter(':visible').removeClass('col-3 col-4').addClass('col-6');
|
|
|
|
} else {
|
|
// TP column is visible here
|
|
$('.hidetp').show();
|
|
|
|
if (is_co_pay_yes == 1) {
|
|
$('.hidecotp').show();
|
|
$('#table_tr_7').show();
|
|
$('#table_tr_35').show();
|
|
$('#table_tr_3').show();
|
|
} else {
|
|
$('.hidecotp').hide();
|
|
$('#table_tr_7').hide();
|
|
$('#table_tr_35').hide();
|
|
$('#table_tr_3').hide();
|
|
}
|
|
|
|
if (bap == 'Fire' || bap == 'Marine Cargo' || bap == 'Marine Hull') {
|
|
// ----------------------------------------------------
|
|
// CASE: 4 Columns Visible (Label, BP, TP, TEP)
|
|
// Goal: All must be col-3 (3 + 3 + 3 + 3 = 12)
|
|
// ----------------------------------------------------
|
|
$('.hideter').show();
|
|
|
|
if (is_co_pay_yes == 1) {
|
|
$('.hidecoter').show();
|
|
} else {
|
|
$('.hidecoter').hide();
|
|
}
|
|
|
|
// Action for 4 visible columns: Select ALL and set them to col-3
|
|
$allPremiumCols.removeClass('col-4 col-6').addClass('col-3');
|
|
|
|
} else {
|
|
// ----------------------------------------------------
|
|
// CASE: 3 Columns Visible (Label, BP, TP)
|
|
// Goal: All three must be col-4 (4 + 4 + 4 = 12)
|
|
// ----------------------------------------------------
|
|
$('.hideter').hide();
|
|
|
|
// Action for 3 visible columns: Select ONLY visible and set them to col-4
|
|
// TEP is hidden and excluded by :visible.
|
|
$allPremiumCols.filter(':visible').removeClass('col-3 col-6').addClass('col-4');
|
|
}
|
|
}
|
|
// --- 3. Set Standard Percentages ---
|
|
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;
|
|
}
|
|
|
|
// Set values using the unique card IDs
|
|
$(`#standard_bp_${currentInsurerCount}`).val(std_bp);
|
|
|
|
$('[name="standard_tp[]"]').val(std_tp);
|
|
$('[name="standard_tep[]"]').val(std_tep);
|
|
|
|
if(currentInsurerCount > 1){
|
|
$('.follow_insurer').prop('required', true);
|
|
}else{
|
|
$('.follow_insurer').prop('required', false);
|
|
}
|
|
|
|
var calc_policy_issue_date = flatpickr("#calc_policy_issue_date_" + currentInsurerCount, {
|
|
dateFormat: "d/m/Y",
|
|
allowInput: false
|
|
});
|
|
}
|
|
|
|
$(document).on('click', '.delete-insurer', function () {
|
|
|
|
const count_index = $(this).data('count') || $(this).attr('data-count');
|
|
|
|
if (!count_index) {
|
|
console.error('Missing data-count');
|
|
return;
|
|
}
|
|
|
|
removeInsurerCard(count_index);
|
|
getCardIndexes(1); // keep if you still use it
|
|
|
|
});
|
|
|
|
|
|
function removeInsurerCard(count_index) {
|
|
|
|
console.log('#################################### Remove Insurer Card ####################################');
|
|
|
|
let removedCoShareIds = [];
|
|
|
|
// Get co_share_id[] only from this card
|
|
const coShareId = $('#insurerCardContainer_' + count_index)
|
|
.find('[name="co_share_id[]"]')
|
|
.val();
|
|
|
|
if (coShareId) {
|
|
removedCoShareIds.push(coShareId);
|
|
}
|
|
|
|
console.log('removedCoShareIds array', removedCoShareIds);
|
|
|
|
// Store removed IDs in hidden input
|
|
let existing = $('#remove_pt_co_id').val();
|
|
let finalArr = [];
|
|
|
|
if (existing) {
|
|
finalArr = existing.split(',');
|
|
}
|
|
|
|
finalArr = finalArr.concat(removedCoShareIds);
|
|
$('#remove_pt_co_id').val(finalArr.join(','));
|
|
|
|
console.log('remove_pt_co_id value', $('#remove_pt_co_id').val());
|
|
|
|
// Remove the CARD
|
|
$('#insurerCardContainer_' + count_index).remove();
|
|
// renumberCards(); // don't forgot
|
|
|
|
// Remove from insurer_count_array
|
|
insurer_count_array = insurer_count_array.filter(item => item !== count_index);
|
|
|
|
// Recalculate co-share
|
|
if (typeof co_share_percentage_calculation === "function") {
|
|
co_share_percentage_calculation(null, "remove");
|
|
}
|
|
|
|
// Decrease count
|
|
insurerCount--;
|
|
|
|
if (insurerCount === 0) {
|
|
$('.follow_insurer').prop('required', false);
|
|
} else {
|
|
$('.follow_insurer').prop('required', true);
|
|
}
|
|
|
|
console.log('#################################### END Remove Insurer Card ####################################');
|
|
}
|
|
|
|
function removeAllInsurerCards() {
|
|
console.log('######################################');
|
|
console.log('removeAllInsurerCards function called');
|
|
console.log('######################################');
|
|
|
|
// Assuming all insurer cards are contained within #allInsurerCards
|
|
$('#allInsurerCards').empty();
|
|
|
|
// Reset the global counter
|
|
// Assuming 'insurerCount' and 'insurer_count_array' are global variables
|
|
insurerCount = 0;
|
|
insurer_count_array = [];
|
|
}
|
|
|
|
|
|
function populateCards(dataArray, status = false) {
|
|
|
|
console.log('####################################');
|
|
console.log('populateCards function called');
|
|
console.log('####################################');
|
|
|
|
// Make sure you define/reset this globally if needed
|
|
// insurerCount = 0;
|
|
|
|
dataArray.forEach((data, index) => {
|
|
|
|
// 🚨 MISTAKE 1: You must call the card creation function first!
|
|
// This function will increment insurerCount and build the HTML card
|
|
addInsurerColumn();
|
|
|
|
// Use the newly incremented global counter, which is now the correct card index.
|
|
const cardIndex = insurerCount;
|
|
|
|
let disable_td = false;
|
|
if(data.record_count > 0){
|
|
disable_td = true;
|
|
}
|
|
|
|
const cardContainer = $(`#insurerCardContainer_${cardIndex}`);
|
|
if (cardContainer.length === 0) {
|
|
console.error(`Card container for index ${cardIndex} not found.`);
|
|
return;
|
|
}
|
|
|
|
let insurer = data.insurer_branch_id + '-' + data.insurer_id;
|
|
|
|
// --- Populate fields based on available data (NO ROLE CHECK HERE) ---
|
|
|
|
// All fields should be populated if they exist in the card created by addInsurerColumn()
|
|
|
|
// Insurer/Basic Details
|
|
$(`#follow_insurer_id_${cardIndex}`).val(insurer).trigger('change');
|
|
$(`#co_share_type_${cardIndex}`).val(data.co_share_type ?? '');
|
|
$(`#follower_policy_no_${cardIndex}`).val(data.follower_policy_no);
|
|
$(`#calc_policy_issue_date_${cardIndex}`).val(data.pt_policy_issue_date);
|
|
$(`#co_share_per_${cardIndex}`).val(data.co_share_per).toggleClass('readonly-select', !!disable_td);
|
|
$(`#non_comm_per_amt_${cardIndex}`).val(data.non_comm_per_amt);
|
|
|
|
// Premium Fields
|
|
$(`#base_premium_${cardIndex}`).val(status ? data.bp_amt : '').toggleClass('readonly-select', !!disable_td);
|
|
$(`#tp_premium_${cardIndex}`).val(status ? data.tp_amt : '').toggleClass('readonly-select', !!disable_td);
|
|
$(`#ter_premium_${cardIndex}`).val(status ? data.tep_amt : '').toggleClass('readonly-select', !!disable_td);
|
|
|
|
$(`#co_premium_${cardIndex}`).val(status ? data.cop_amt : '').toggleClass('readonly-select', !!disable_td);
|
|
$(`#co_tp_premium_${cardIndex}`).val(status ? data.cotp_amt : '').toggleClass('readonly-select', !!disable_td);
|
|
$(`#co_ter_premium_${cardIndex}`).val(status ? data.cotep_amt : '').toggleClass('readonly-select', !!disable_td);
|
|
|
|
// GST/Tax Fields
|
|
$(`#cgst_${cardIndex}`).val(data.bp_cgst).toggleClass('readonly-select', !!disable_td);
|
|
$(`#sgst_${cardIndex}`).val(data.bp_sgst).toggleClass('readonly-select', !!disable_td);
|
|
$(`#igst_${cardIndex}`).val(data.bp_igst).toggleClass('readonly-select', !!disable_td);
|
|
$(`#gst_amount_${cardIndex}`).val(status ? data.bp_gst_amt : '').toggleClass('readonly-select', !!disable_td);
|
|
$(`#stamp_duty_${cardIndex}`).val(status ? data.stamp_duty : '').toggleClass('readonly-select', !!disable_td);
|
|
$(`#total_amt_${cardIndex}`).val(status ? data.amount : '');
|
|
|
|
// Agreed Percentages
|
|
$(`#agreed_bp_${cardIndex}`).val(data.agreed_bp_per).toggleClass('readonly-select', !!disable_td);
|
|
$(`#agreed_tp_${cardIndex}`).val(data.agreed_tp_per).toggleClass('readonly-select', !!disable_td);
|
|
$(`#agreed_tep_${cardIndex}`).val(data.agreed_tep_per).toggleClass('readonly-select', !!disable_td);
|
|
|
|
// Standard Percentages (Read-only)
|
|
$(`#standard_bp_${cardIndex}`).val(data.standerd_bp_per);
|
|
// Note: You must ensure standard_tp/ter now have unique IDs in your card HTML if you use ID selector
|
|
$(`input[name="standard_tp[]"]`).filter((i, el) => $(el).closest('.insurer-card').attr('data-count') == cardIndex).val(data.standerd_tp_per);
|
|
$(`input[name="standard_ter[]"]`).filter((i, el) => $(el).closest('.insurer-card').attr('data-count') == cardIndex).val(data.standerd_tep_per);
|
|
|
|
// Hidden ID
|
|
cardContainer.find('input[name="co_share_id[]"]').val(status ? data.id : '');
|
|
|
|
|
|
// --- 🚨 MISTAKE 2: Role-Specific Fields (FIXED) ---
|
|
// These fields only exist in the card if they were created by addInsurerColumn()
|
|
// under the finance/management roles. We check if the field exists before populating.
|
|
|
|
// Finance/Management/Brokerage fields
|
|
const agreedAmountField = $(`#agreed_amount_${cardIndex}`);
|
|
if (agreedAmountField.length) {
|
|
agreedAmountField.val(data.agreed_amt).toggleClass('readonly-select', !!disable_td);
|
|
|
|
// Actual Amounts
|
|
$(`#actual_bp_amt_${cardIndex}`).val(status ? data.actual_bp_amt : '');
|
|
$(`#actual_tp_amt_${cardIndex}`).val(status ? data.actual_tp_amt : '');
|
|
$(`#actual_tep_amt_${cardIndex}`).val(status ? data.actual_tep_amt : '');
|
|
|
|
// Actual Percentages
|
|
$(`#actual_bp_per_${cardIndex}`).val(status ? data.actual_bp_per : '');
|
|
$(`#actual_tp_per_${cardIndex}`).val(status ? data.actual_tp_per : '');
|
|
$(`#actual_tep_per_${cardIndex}`).val(status ? data.actual_tep_per : '');
|
|
|
|
// Actual Brokerage Amounts
|
|
$(`#actual_bp_brokerage_amt_${cardIndex}`).val(status ? data.actual_bp_brokerage_amt : '');
|
|
$(`#actual_tp_brokerage_amt_${cardIndex}`).val(status ? data.actual_tp_brokerage_amt : '');
|
|
$(`#actual_tep_brokerage_amt_${cardIndex}`).val(status ? data.actual_tep_brokerage_amt : '');
|
|
|
|
// Expected Amount
|
|
$(`#exp_amt_${cardIndex}`).val(status ? data.exp_amt : '');
|
|
}
|
|
|
|
// --- Post-Population Logic ---
|
|
|
|
if(data.co_share_type == 1){
|
|
// Ensure appendCDData uses the correct cardIndex
|
|
appendCDData(data.cd_account_no, data.cd_amount, cardIndex);
|
|
}
|
|
|
|
// We push the final, correct insurerCount
|
|
insurer_count_array.push(insurerCount)
|
|
|
|
});
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------------------------------------
|
|
|
|
// function getURLParamsForReport()
|
|
// {
|
|
// console.log('getURLParamsForReport() function called')
|
|
// const url = new URL(window.location.href);
|
|
// const params = new URLSearchParams(url.search);
|
|
// const pt_id = params.get('pt_id') ?? 0
|
|
|
|
// console.log('policy tranction id ', pt_id);
|
|
|
|
// if(pt_id != 0){
|
|
// setTimeout(function(){
|
|
// hide_list_show_add()
|
|
// getPolicyTransactionDataForEndorsementEdit(pt_id)
|
|
// }, 2000)
|
|
// }else{
|
|
// show_list_hide_add()
|
|
// }
|
|
|
|
// console.log('pt_id', pt_id)
|
|
|
|
// }
|
|
|
|
function getURLParamsForReport() {
|
|
const params = new URLSearchParams(window.location.search);
|
|
const pt_id = params.get('pt_id') ?? 0;
|
|
|
|
// ✅ Get the previous page URL
|
|
const previousUrl = document.referrer || '';
|
|
|
|
console.log("PT ID:", pt_id);
|
|
console.log("Previous Page URL:", previousUrl);
|
|
|
|
if (pt_id != 0) {
|
|
hide_list_show_add();
|
|
setTimeout(() =>
|
|
getPolicyTransactionDataForEndorsementEdit(pt_id),
|
|
1500); // Reduced timeout
|
|
} else {
|
|
show_list_hide_add();
|
|
}
|
|
|
|
if(previousUrl != "" && pt_id != 0){
|
|
redirect_url = previousUrl;
|
|
$('#btnAdd').attr('href', previousUrl);
|
|
}
|
|
|
|
console.log('getURLParamsForReport pt_id', pt_id); // Retain the log if necessary
|
|
}
|
|
|
|
|
|
function onlyNumbers(event)
|
|
{
|
|
var charcode = event.which || event.keyCode;
|
|
|
|
// Allow: 0-9 (48-57), dot (46), minus (45)
|
|
if ((charcode >= 48 && charcode <= 57) || charcode === 46 || charcode === 45) {
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
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 = 'Given ' + label + " already exists!";
|
|
}
|
|
|
|
checkDuplicateTableFieldValue(table, field, value, function(isDuplicate) {
|
|
if (isDuplicate) {
|
|
toastr.warning(message, 'Warning');
|
|
$(input).val('')
|
|
}
|
|
});
|
|
|
|
}
|
|
|
|
function appendCDData(cd_ac_no, cd_amt, increment){
|
|
|
|
increment = increment + 1
|
|
$('#cd_account_no_'+increment).val(cd_ac_no)
|
|
$('#cd_current_balance_'+increment).val(cd_amt)
|
|
}
|
|
|
|
$('#action_type').on('change', function(){
|
|
|
|
let action_type = $(this).val();
|
|
console.log('action_type', action_type);
|
|
console.log('action_type', action_type);
|
|
if (action_type == 'policy_instalment') {
|
|
$('.install_due_date_div').show()
|
|
}else{
|
|
$('.install_due_date_div').hide()
|
|
}
|
|
|
|
if(action_type == "deletion"){
|
|
console.log('pt_co_share_count_data', pt_co_share_count_data);
|
|
for (let i = 1; i <= pt_co_share_count_data; i++) {
|
|
applyDeletionSymbolsToFields(String(i), true);
|
|
}
|
|
}else{
|
|
|
|
const fieldIds = [
|
|
'base_premium',
|
|
'tp_premium',
|
|
'ter_premium',
|
|
'co_premium',
|
|
'co_tp_premium',
|
|
'co_ter_premium',
|
|
'gst_amount',
|
|
'agreed_amount',
|
|
'non_comm_per_amt',
|
|
'total_amt',
|
|
'exp_amt'
|
|
];
|
|
|
|
for (let input = 1; input <= pt_co_share_count_data; input++) {
|
|
fieldIds.forEach(field => {
|
|
const $el = $('#' + field + '_' + input);
|
|
console.log('$el', '#' + field + '_' + input);
|
|
let val = $el.val()?.trim();
|
|
console.log('$val', val);
|
|
if (!val) return;
|
|
|
|
let num = parseFloat(val);
|
|
if (!isNaN(num)) $el.val(Math.abs(num)); // Removes '-' sign
|
|
});
|
|
}
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
$('#policy_issue_date').on('change', function(){
|
|
let date = $(this).val();
|
|
|
|
let date_set = false
|
|
$('[name="co_share_type[]"]').each(function () {
|
|
console.log('co_share_type[] value', $(this).val());
|
|
if($(this).val() == 1){
|
|
let uniqueid = $(this).data('id');
|
|
$('#calc_policy_issue_date_' + uniqueid).val(date).addClass('readonly-select');
|
|
date_set = true;
|
|
}
|
|
});
|
|
|
|
if(!date_set){
|
|
$('#calc_policy_issue_date_1').val(date).addClass('readonly-select');
|
|
}
|
|
|
|
let monthDiv = document.getElementById('policy_issue_month_info');
|
|
monthAbbr = document.getElementById('month').value;
|
|
|
|
if (!monthAbbr) {
|
|
monthDiv.innerHTML = '';
|
|
monthDiv.classList.remove('show');
|
|
return;
|
|
}
|
|
|
|
monthDiv.innerHTML =
|
|
'<span class="text-success">' + monthAbbr + '</span>' +
|
|
' <span class="vehicle-badge success">✓ Month</span>';
|
|
|
|
monthDiv.classList.add('show');
|
|
});
|
|
|
|
|
|
//-----------------------------------------------------------------------------------------------------------
|
|
|
|
|
|
// Add the new card-based event listener
|
|
$(document).on('change', '#allInsurerCards input, #allInsurerCards select, #allInsurerCards textarea', function() {
|
|
// The changed field is inside a card. Find its index (data-count).
|
|
const cardIndex = $(this).closest('.insurer-card').data('count');
|
|
|
|
// Call the new card iteration function, passing the specific card index.
|
|
processCardData(cardIndex);
|
|
});
|
|
|
|
/**
|
|
* Processes data and runs calculations for one or all insurer cards.
|
|
* @param {number} specificIndex - The data-count of the specific card to process.
|
|
* If 0 or undefined, processes all cards.
|
|
*/
|
|
function processCardData(specificIndex = 0) {
|
|
|
|
// If a specific card index is provided (from the change event), run calculations for only that card.
|
|
if (specificIndex > 0) {
|
|
// The original logic assumes 'index' is the insurerCount
|
|
amountCalculation(specificIndex);
|
|
co_share_percentage_calculation(specificIndex);
|
|
return;
|
|
}
|
|
|
|
// If no specific index is provided, iterate through all existing cards.
|
|
console.log("Processing all insurer cards for full recalculation.");
|
|
|
|
$('#allInsurerCards .insurer-card').each(function() {
|
|
// Retrieve the unique ID/count from the card's data attribute
|
|
const cardIndex = $(this).data('count');
|
|
|
|
// Check if the cardIndex is valid (index 0 is the fixed column/header, so we start at 1)
|
|
if (cardIndex >= 1) {
|
|
// Note: The original 'getColumnIndexes' called amountCalculation twice if count == 1.
|
|
// I'm omitting that redundant double call unless specifically requested,
|
|
// as it seems like a potential bug or specific timing requirement.
|
|
|
|
amountCalculation(cardIndex);
|
|
co_share_percentage_calculation(cardIndex);
|
|
}
|
|
});
|
|
}
|
|
|
|
function setPolicyIssueMonth(){
|
|
let monthDiv = document.getElementById('policy_issue_month_info');
|
|
monthAbbr = document.getElementById('month').value;
|
|
|
|
if (!monthAbbr) {
|
|
monthDiv.innerHTML = '';
|
|
monthDiv.classList.remove('show');
|
|
return;
|
|
}
|
|
|
|
monthDiv.innerHTML =
|
|
'<span class="text-success">' + monthAbbr + '</span>' +
|
|
' <span class="vehicle-badge success">✓ Month</span>';
|
|
|
|
monthDiv.classList.add('show');
|
|
}
|
|
|
|
function setBPValue(inputValue) {
|
|
let bpValueField = document.querySelectorAll('.bp_value');
|
|
|
|
if(bpValueField){
|
|
bpValueField.forEach((field) => { field.value = inputValue; });
|
|
console.log("Updated", bpValueField.length, "hidden base premiums");
|
|
} else {
|
|
console.error("Error: Element with class '.bp_value' not found.");
|
|
}
|
|
|
|
}
|
|
|
|
function setTPValue(inputValue) {
|
|
let tpValueField = document.querySelectorAll('.tp_value');
|
|
|
|
if (tpValueField) {
|
|
tpValueField.forEach((field) => { field.value = inputValue; });
|
|
console.log("Updated", tpValueField.length, "hidden tp premiums");
|
|
} else {
|
|
console.error("Error: Element with class '.tp_value' not found.");
|
|
}
|
|
|
|
}
|
|
|
|
function setTEPValue(inputValue) {
|
|
let tepValueField = document.querySelectorAll('.ter_value');
|
|
tepValueField.forEach((field) => { field.value = inputValue; });
|
|
if (tepValueField) {
|
|
tepValueField.value = inputValue;
|
|
console.log("Updated", tepValueField.length, "hidden tep premiums");
|
|
} else {
|
|
console.error("Error: Element with class '.tep_value' not found.");
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|