BBnepal-Accounts/application/views/admin/ae_fee_course.php
Sampanna Rimal 9cd05ef3cb commitall
2024-07-10 18:28:19 +05:45

1007 lines
34 KiB
PHP

<link rel="stylesheet" href="<?php echo base_url(); ?>assets_admin/css/bootstrap-select.css">
<style>
.multiple-fields-fees .form-div {
width: auto;
margin-right: 12px;
}
label.error,
label#Nameerr,
#dublicateErr {
color: red;
}
select.form-control:not([size]):not([multiple]) {
height: calc(2rem + 2px);
}
/*input {
height: calc(2.25rem + 2px);;
}*/
.form-control[readonly] {
background-color: rgb(255 255 255 / 0%);
opacity: 1;
}
.form-control[disabled] {
background-color: #e9ecef;
opacity: 1;
}
.dropdown.bootstrap-select {
width: 240px !important;
display: block !important;
}
</style>
<script src="<?php echo base_url(); ?>assets_admin/js/moment.min.js"></script>
<main class="wraper responsive-width" id="main">
<div class="from-group adding-class form-group_lng">
<a href="<?= base_url(); ?>admin/scholarship">
<button type="button" class="btn btn-outline-primary btn-sm">Scholarships</button>
</a> &nbsp;&nbsp;
<a href="<?= base_url(); ?>admin/assign-due-fees">
<button type="button" class="btn btn-outline-primary btn-sm">Opening Balance</button>
</a> &nbsp;&nbsp;
<!-- <a href="<?= base_url(); ?>admin/ae-fee-course/0">
<button type="button" class="btn btn-outline-primary btn-sm ">Add fees</button>
</a> -->
</div>
<div class="main-wrap">
<div class="dashboard-cover">
<?php if ($this->session->flashdata('success')) { ?>
<div class="alert alert-success alert-dismissible fade show" role="alert">
<p><?php echo $this->session->flashdata('success') ?></p>
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<?php } ?>
<?php if ($this->session->flashdata('failed')) { ?>
<div class="alert alert-danger alert-dismissible fade show" role="alert">
<p><?php echo $this->session->flashdata('failed') ?></p>
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<?php } ?>
<div class="common-heading">
<!-- <div class="calendar-type mb-3">
<p class="mb-2">Note : Click below button to change type of calendar</p>
<input type="checkbox" id="cal_language" name="cal_language" checked data-toggle="toggle" data-on="Bikram Sambat" data-off="Gregorian" data-onstyle="primary" data-offstyle="success">
</div> -->
<!-- <nav aria-label="breadcrumb ">
<ol class="breadcrumb">
<li class="breadcrumb-item"><a class="font-weight-bold text-primary" href="<?= base_url() ?>admin">Dashboard</a></li>
<li class="breadcrumb-item active text-dark" aria-current="page">Add Fee</li>
</ol>
</nav> -->
<h4>Fee</h4>
</div>
<form action="<?= base_url() ?>admin/ae-fee-course/<?= $fees_id ?>" id="fee_form" method="post">
<?php if ($fees_id == 0) { ?>
<div class="feeForm-wrap">
<div class="form-group">
<label for="">Batch<span class="text-danger font-weight-bold">*</span></label>
<select name="batch_id" class="form-control custom-select" id="batch_id">
<option selected disabled value=''>Select one batch</option>
<?php foreach ($batches as $key => $value) {
$selected = '';
if ($current_batch == $value['id']) {
$selected = 'selected';
}
echo '<option value="' . $value['id'] . '" ' . $selected . '>' . $value['b_name'] . '</option>';
} ?>
</select>
<div class="empty_batch_err" style="display:none;color:red"></div>
</div>
<div class="form-group">
<label for="">Course<span class="text-danger font-weight-bold">*</span></label>
<select name="course_id[]" multiple class="form-control selectpicker" id="course_id" onchange="CourseChange(this)">
<option disabled value=''>Select Courses</option>
<?php foreach ($courses as $key => $value) {
echo '<option value="' . $value['id'] . '">' . $value['course_name'] . '</option>';
} ?>
</select>
</div>
<div class="form-group">
<label for="">Fees Type<span class="text-danger font-weight-bold">*</span></label>
<select name="feetype" onchange="check_hostel_type(this)" class="form-control custom-select" id="feetype">
<option selected disabled value=''>Select fee type</option>
<?php foreach ($feeTypes as $key => $value) {
echo '<option value="' . $value['id'] . '">' . $value['feetype_name'] . '</option>';
} ?>
</select>
<label id="Nameerr" style="display : none"></label>
</div>
<div class="form-group" id="group-checkbox-id">
<label>Group Fees</label>
<label class="checkBox">
<input type="checkbox" id="checkBx" name="grouped" onchange="valueChanged()">
<span class="checkmark"></span>
</label>
<div class="form-group-h">
<div class="form-group">
<label for="">Due date<span class="text-danger font-weight-bold">*</span></label>
<input type="text" name="common_bs_due_date" class="form-control cm-datepicker common_date_picker" id="cm-datepicker" placeholder="Select Date" />
<input type="date" onchange="applyEnglishDate(this, event)" name="common_ad_due_date" placeholder="Select Date" class="form-control eng-date english-datepicker common_date_picker" style="display: none;">
</div>
</div>
</div>
<div id="newdropdowns"></div>
<div class="multiple-fields-fees">
<div class="form-group form-group-div">
<div class="form-div" id="feename-field">
<label for="">Fees Name<span class="text-danger font-weight-bold">*</span></label>
<div class="fees-name-container">
<input type="text" name="feename[0]" id="" class="form-control feeNameClass" placeholder="Enter fees name">
</div>
</div>
<!-- <div class="form-div" id="monthly-select" style="width: 20%">
<label for="month-label">Select Month<span class="text-danger font-weight-bold">*</span></label>
<select name="feename[0]" class="form-control custom-select" id="month-label">
<option selected disabled value=''>Select Month</option>
<?php foreach ($nepali_months as $key => $value) {
echo '<option value="' . $value['month_name'] . '">' . $value['month_name'] . '</option>';
} ?>
</select>
</div> -->
<div class="form-div">
<label for="">Amount<span class="text-danger font-weight-bold">*</span></label>
<input type="text" name="feeamount[0]" id="" class="form-control feeAmountClass" placeholder="Enter fees amount">
</div>
<div class="form-div" id="due-date">
<label for="">Due date<span class="text-danger font-weight-bold">*</span></label>
<input type="text" name="bsdate[0]" class="form-control cm-datepicker nepali-datepicker" id="nepali-datepicker" placeholder="Select Date" />
</div>
<!-- <div class="form-div add-remove-btns">
<button style="display:none" class="add-delete-btn" onclick="addExtraFields(this, event)" name="Add new Course" id="addBtn1">+</button>
</div> -->
</div>
</div>
<div id="dublicateErr" class="mb-2" style="display:none"></div>
<hr>
<input type="submit" class="subject_addbtn" value="Save">
<a href="<?php echo base_url() ?>admin/fee-course"><button type="button" class=" ml-2 subject_addbtn bg-dark">Back</button></a>
</div>
<?php } else { // UPDATE FORM STARTS HERE
?>
<div class="feeForm-wrap">
<div class="form-group">
<label for="">Batch<span class="text-danger font-weight-bold">*</span></label>
<select name="batch_id" class="form-control" id="batch_id">
<?php foreach ($batches as $key => $value) {
if (in_array($course_fees[0]['batch'], $value)) {
echo '<option selected value="' . $value['id'] . '">' . $value['b_name'] . ' : ' . $value['b_name'] . '</option>';
} else {
echo '<option value="' . $value['id'] . '">' . $value['b_name'] . ' : ' . $value['b_name'] . '</option>';
}
} ?>
</select>
</div>
<div class="form-group">
<label for="">Course<span class="text-danger font-weight-bold">*</span></label>
<select name="course_id" class="form-control" id="course_id">
<?php foreach ($courses as $key => $value) {
if (in_array($course_fees[0]['course'], $value)) {
echo '<option selected value="' . $value['id'] . '">' . $value['course_name'] . '</option>';
} else {
echo '<option value="' . $value['id'] . '">' . $value['course_name'] . '</option>';
}
} ?>
</select>
</div>
<div class="form-group">
<?php
$disabled_var = $course_fees[0]['fee_id'] == 8 ? 'enabled' : '';
?>
<label for="">Fees Type<span class="text-danger font-weight-bold">*</span></label>
<select name="feetype" <?= $disabled_var ?> onchange="check_hostel_type(this)" class="form-control" id="feetype">
<?php foreach ($feeTypes as $key => $value) {
if (in_array($course_fees[0]['feetype'], $value)) {
echo '<option selected value="' . $value['id'] . '">' . $value['feetype_name'] . '</option>';
} else {
echo '<option value="' . $value['id'] . '">' . $value['feetype_name'] . '</option>';
}
} ?>
</select>
<label id="Nameerr" style="display : none"></label>
</div>
<?php
$div_style = $course_fees[0]['fee_id'] == 8 ? 'none' : 'block';
?>
<div class="form-group" id="group-checkbox-id" style="display:<?= $div_style ?>">
<label>Group Fees</label>
<label class="checkBox">
<?php if ($course_fees[0]['grouped'] == 'yes') {
echo '<input type="checkbox" checked name="grouped" id="checkBx" onchange="valueChanged()">';
} else {
echo '<input type="checkbox" name="grouped" id="checkBx" onchange="valueChanged()">';
} ?>
<span class="checkmark"></span>
</label>
<div class="form-group-h">
<div class="form-group">
<label for="">Due date<span class="text-danger font-weight-bold">*</span></label>
<?php if ($course_fees[0]['grouped'] == 'yes') { ?>
<input type="text" value="<?= $course_fees[0]['due_date'] ?>" name="common_bs_due_date" class="form-control cm-datepicker common_date_picker" id="cm-datepicker" placeholder="Select Date" />
<?php } else { ?>
<input type="text" name="common_bs_due_date" class="form-control cm-datepicker common_date_picker" id="cm-datepicker" placeholder="Select Date" />
<?php } ?>
<input type="date" name="common_ad_due_date" placeholder="Select Date" class="form-control english-datepicker eng-date common_date_picker" style="display: none;">
</div>
</div>
</div>
<?php
// dd($course_fees);
$route_div_style = $course_fees[0]['fee_id'] == 4 ? '' : 'd-none';
?>
<div class="form-group <?= $route_div_style; ?>">
<?php //dd($course_fees);
?>
<label for="">Route Name<span class="text-danger font-weight-bold">*</span></label>
<select name="new_route_id" class="form-control" id="new_route_id">
<?php
foreach ($edit_route_list as $rt_key => $rt_value) {
if ($course_fees[0]['route_id'] == $rt_value['id']) {
echo '<option selected value="' . $rt_value['id'] . '">' . $rt_value['route_name'] . '</option>';
} else {
echo '<option value="' . $rt_value['id'] . '">' . $rt_value['route_name'] . '</option>';
}
} ?>
</select>
</div>
<div class="multiple-fields-fees">
<?php $selectedPlan = '' ?>
<!-- // Used only for Hostel -->
<?php
// dd($course_fees);
foreach ($course_fees as $key => $value) {
$feenames = (array)json_decode($value['fees_name']);
$nameLength = count($feenames);
// print_r($value);
// dd($feenames);
foreach ($feenames as $index => $ele) {
$selectedPlan = $ele->name; // Ignore if fee type is not hostel
?>
<div class="form-group form-group-div ">
<div class="form-div" id="feename-field">
<?php
// echo $index . "<br>" . $ele->name;
?>
<label for="">Fees Name<span class="text-danger font-weight-bold">*</span></label>
<div class="fees-name-container">
<input type="text" value="<?= $ele->name ?>" name="feename[<?= $index ?>]" id="" class="form-control feeNameClass checkfeename" placeholder="Enter fees name">
</div>
</div>
<div class="form-div" id="monthly-select" style="width: 20%">
<label for="month-label[<?= $index ?>]">Select Month<span class="text-danger font-weight-bold">*</span></label>
<select name="feename[<?= $index ?>]" class="form-control custom-select" id="month-label[<?= $index ?>]">
<option selected disabled value=''>Select Month</option>
<?php
foreach ($nepali_months as $key => $month) {
?>
<option value="<?= $month['month_name'] ?>" <?= $ele->name == $month['month_name'] ? 'selected' : '' ?>> <?= $month['month_name'] ?> </option>;
<?php }
?>
</select>
</div>
<?php
?>
<div class="form-div">
<label for="">Amount<span class="text-danger font-weight-bold">*</span></label>
<input type="text" value="<?= $ele->amount ?>" name="feeamount[<?= $index ?>]" id="" class="form-control feeAmountClass" placeholder="Enter fees amount">
</div>
<?php if ($value['grouped'] == 'no') { ?>
<div class="form-div">
<label for="">Due date<span class="text-danger font-weight-bold">*</span></label>
<input type="text" value="<?= $value['due_date'] ?>" name="bsdate[0]" class="form-control cm-datepicker nepali-datepicker" id="nepali-datepicker" placeholder="Select Date" />
<input type="date" name="englishdate[<?= $index ?>]" class="form-control english-datepicker" style="display: none;" placeholder="Select Date">
</div>
<?php } else { ?>
<div class="form-div">
<label for="">Due date<span class="text-danger font-weight-bold">*</span></label>
<input type="text" disabled value="<?= $value['due_date'] ?>" name="bsdate[0]" class="form-control cm-datepicker nepali-datepicker" id="nepali-datepicker" placeholder="Select Date" />
<input type="date" disabled name="englishdate[<?= $index ?>]" class="form-control english-datepicker" style="display: none;" placeholder="Select Date">
</div>
<?php } ?>
<?php if ($nameLength == 1) { ?>
<div class="form-div add-remove-btns">
<button style="display:none" class="add-delete-btn" onclick="addExtraFields(this, event)" name="Add new Course" id="addBtn1">+</button>
</div>
<?php } else if ($index == ($nameLength - 1)) { ?>
<div class="form-div add-remove-btns">
<button style="display:none" class="add-delete-btn" onclick="addExtraFields(this, event)" name="Add new Course" id="addBtn1">+</button>
</div>
<div class="form-div add-remove-btns remove-btn">
<button class="add-delete-btn" onclick="removeExtraField(this, event)" name="Add new Course" id="addBtn1">-</button>
</div>
<?php } else if ($index > 0) { ?>
<div class="form-div add-remove-btns remove-btn">
<button class="add-delete-btn" onclick="removeExtraField(this, event)" name="Add new Course" id="addBtn1">-</button>
</div>
<?php } ?>
</div>
<?php }
} ?>
</div>
<div id="dublicateErr" class="mb-2" style="display:none"></div>
<input type="submit" class="subject_addbtn" value="Update">
<a href="<?php echo base_url() ?>admin/fee-course"><button type="button" class=" ml-2 subject_addbtn bg-dark">Back</button></a>
</div>
<?php } ?>
</form>
</div>
</div>
</main>
<script defer src="<?php echo base_url(); ?>assets_admin/js/bootstrap-select.min.js"></script>
<script type="text/javascript">
function CourseChange(element) {
// alert(element.id);
$('#feetype').val('');
$('#newdropdowns').empty();
}
function CheckRouteFee(inputelement) {
let batchid = $('#batch_id option:selected').val();
// alert(BatchId);
// let CourseId=$('#cousrse_id option:selected').val();
let feeTypeId = $('#feetype option:selected').val();
var selectedValues = [];
let checkfeename = $('.checkfeename').val();
$('#course_id option:selected').each(function() {
let selectedItem = $(this).val();
// alert('course_ids'+selectedItem);
if (selectedItem != '') {
selectedValues.push(selectedItem);
}
});
let routeId = $('#' + inputelement.id).val();
if (batchid === '')
alert("Please Select Batch");
else if (feeTypeId === '')
alert("Please Select Fees Type");
else if (selectedValues.length === 0)
alert("Please Select course");
else if (routeId === '')
alert("Please Select Route");
if (batchid !== '' && feeTypeId !== '' && (selectedValues.length > 0) && routeId !== '') {
var errdiv = '';
$.ajax({
url: '<?php echo base_url() ?>' + 'admin/check_route_fees',
type: 'POST',
data: {
batch_id: batchid,
feetype_id: feeTypeId,
course_ids: selectedValues,
route_id: routeId
},
dataType: "json",
success: function(response) {
if (response != 0) {
errdiv += '<p ><strong class="text-danger" style="font-size:16px;">NOTE : </strong> <span style="font-size:14px;" class="text-success">The existing fee names can not be created again.</span></p>';
// for(let i=0;i<response.length;i++){
// errdiv +='<p class="text-danger" style="font-size:12px;"> <strong>'+ response[i].fee_values +'</strong> Fees already created for Batch and Course <strong>'+response[i].course_name+'</strong></p>';
// }
$('#errorDiv').empty().append(errdiv);
}
}
});
} else {
console.log(selectedValues.length);
}
// alert("batch "+BatchId);
// alert("feestype "+feeTypeId);
// alert(inputelement.id);
}
$('#batch_id').on('change', function() {
$('.empty_batch_err').hide();
$('#Nameerr').hide();
})
const check_hostel_type = function(ele) {
$('#newdropdowns').empty();
$('#Nameerr').hide();
$('#dublicateErr').empty().hide();
$('#group-checkbox-id').show();
let feenameContainer = $('.fees-name-container');
let notFirstChild = $('.multiple-fields-fees .form-group.form-group-div:not(:first-child)');
if (ele.value == 3) {
$("#monthly-select").show();
$("#feename-field").hide();
$("#due-date").hide();
$('#group-checkbox-id').hide();
$('.main_installments_container').hide();
if (notFirstChild.length > 0) {
notFirstChild.remove();
$('.multiple-fields-fees .form-control').each(function(index, ele) {
ele.value = '';
})
}
$('#group-checkbox-id').hide();
$.ajax({
url: '<?php echo base_url() ?>' + 'admin/ajax_get_hostel_plans',
type: 'POST',
async: false,
success: function(data) {
feenameContainer.empty();
feenameContainer.append(data);
}
});
} else if (ele.value == 4) {
$("#monthly-select").show();
$("#feename-field").hide();
$(".add-delete-btn").show();
$('#group-checkbox-id').hide();
$('.empty_batch_err').hide();
$("#due-date").hide();
$('#Nameerr').hide();
$('.main_installments_container').hide();
if (notFirstChild.length > 0) {
notFirstChild.remove();
$('.multiple-fields-fees .form-control').each(function(index, ele) {
ele.value = '';
})
}
$('#group-checkbox-id').hide();
let batch_id = $('#batch_id').val();
if (batch_id) {
$.ajax({
url: '<?php echo base_url() ?>' + 'admin/ajax_get_transport_routes_new',
type: 'POST',
data: {
batch_id
},
async: false,
success: function(data) {
// console.log(data);
if (!data) {
$('#Nameerr').show();
$('#Nameerr').text('There are no routes for selected batch to create Transport fees');
$(ele).val('');
} else {
$('#newdropdowns').empty();
$('#newdropdowns').append(data);
feenameContainer.empty();
feenameContainer.append('<input type="text" name="feename[0]" id="" class="form-control feeNameClass" placeholder="Enter fees name">');
}
}
});
} else {
$('.empty_batch_err').show();
$('.empty_batch_err').text('Please select a batch');
$(ele).val('');
}
} else if (ele.value == 8) {
$("#group-checkbox-id").hide();
$(".add-delete-btn").show();
$("#monthly-select").show();
$("#due-date").hide();
$("#feename-field").hide();
} else {
$("#monthly-select").hide();
$("#feename-field").show();
$("#due-date").show();
$('.main_installments_container').show();
$('#group-checkbox-id').show();
feenameContainer.empty();
feenameContainer.append('<input type="text" name="feename[0]" id="" class="form-control feeNameClass" placeholder="Enter fees name">');
$('.multiple-fields-fees .form-control').each(function(index, ele) {
ele.value = '';
})
}
}
const set_plan_id = function(ele) {
let id = $(ele).find(':selected').data('id');
$('#hostel_plan_id').val(id);
}
const set_transport_route_id = function(ele) {
let id = $(ele).find(':selected').data('id');
$('#route_id').val(id);
}
$(document).ready(function() {
$("#monthly-select").hide();
if ($('#checkBx').is(":checked")) {
$(".form-group-h").show();
$(".add-delete-btn").show();
} else {
$(".form-group-h").hide();
$(".add-delete-btn").hide();
}
$('.english-datepicker').attr('min', moment().format('YYYY-MM-DD'))
var mainInput = $(".cm-datepicker");
let NDate = NepaliFunctions.GetCurrentBsDate();
let todayDate = `${NDate.year}-${NDate.month}-${NDate.day}`;
mainInput.nepaliDatePicker({
disableBefore: todayDate,
language: 'english',
onChange: function(data) {
$('.nepali-datepicker').val(data.bs);
},
});
// *************************************************************************
<?php if ($fees_id > 0) { ?>
$("#monthly-select").hide();
$("#feename-field").show();
if ($('#feetype').val() == 3) {
$("#monthly-select").show();
$("#feename-field").hide();
$('#group-checkbox-id').hide();
$.ajax({
url: '<?php echo base_url() ?>' + 'admin/ajax_get_hostel_plans',
type: 'POST',
data: {
selected_plan: '<?= $selectedPlan ?>'
},
async: false,
success: function(data) {
let feenameContainer = $('.fees-name-container');
feenameContainer.empty();
feenameContainer.append(data);
}
});
}
if ($('#feetype').val() == 4) {
$("#monthly-select").show();
$("#feename-field").hide();
$('#newdropdowns').empty();
$('#group-checkbox-id').hide();
let batch_id = $('#batch_id').val();
$.ajax({
url: '<?php echo base_url() ?>' + 'admin/ajax_get_transport_routes_new',
type: 'POST',
data: {
selected_plan: '<?= $selectedPlan ?>',
batch_id
},
async: false,
success: function(data) {
$('#newdropdowns').append(data);
// let feenameContainer = $('.fees-name-container');
// feenameContainer.empty();
// feenameContainer.append();
}
});
}
if ($('#feetype').val() == 8) {
$("#monthly-select").show();
$("#feename-field").hide();
}
<?php } ?>
});
</script>
<script type="text/javascript">
const applyEnglishDate = (ele) => {
$('.english-datepicker').val(ele.value);
}
</script>
<script type="text/javascript">
let clonedItems = [];
$('.nepali-datepicker').attr('readonly', 'readonly');
function valueChanged() {
let notFirstChild = $('.multiple-fields-fees .form-group.form-group-div:not(:first-child)');
if ($('#checkBx').is(":checked")) {
$(".form-group-h").show();
$(".add-delete-btn").show();
if (notFirstChild.length > 0) {
$('.multiple-fields-fees').append(notFirstChild);
}
$('.english-datepicker').attr("disabled", true);
$('.nepali-datepicker').attr("disabled", true);
$('.eng-date').prop('disabled', false);
} else {
$('.english-datepicker').removeAttr('disabled');
$('.nepali-datepicker').removeAttr('disabled');
$('.english-datepicker').removeAttr('readonly');
$('.nepali-datepicker').removeAttr('readonly');
$(".form-group-h").hide();
$(".add-delete-btn").hide();
if (notFirstChild.length > 0) {
notFirstChild.remove();
}
}
if ($('#checkBx').is(":checked")) {
let updatedMultipleFields = $('.multiple-fields-fees .form-group.form-group-div');
$('.add-remove-btns').remove();
for (var i = updatedMultipleFields.length - 1; i >= 0; i--) {
if (i == 0 && (updatedMultipleFields.length == 1)) {
$(updatedMultipleFields[i]).append('<div class="form-div add-remove-btns"><button class="add-delete-btn" onclick="addExtraFields(this, event)" name="Add new Course" id="addBtn1">+</button></div>');
} else if (i == updatedMultipleFields.length - 1) {
$(updatedMultipleFields[i]).append('<div class="form-div add-remove-btns"><button class="add-delete-btn" onclick="addExtraFields(this, event)" name="Add new Course" id="addBtn1">+</button></div><div class="form-div add-remove-btns remove-btn"><button class="add-delete-btn" onclick="removeExtraField(this, event)" name="Add new Course" id="addBtn1">-</button></div>');
} else if (i == 0) {
$(updatedMultipleFields[i]).append('');
} else {
$(updatedMultipleFields[i]).append('<div class="form-div add-remove-btns remove-btn"><button class="add-delete-btn" onclick="removeExtraField(this, event)" name="Add new Course" id="addBtn1">-</button></div>');
}
}
}
}
// Add extra field
let count = 1;
let idCount = $('.multiple-fields-fees .form-group.form-group-div').length - 1;
function addExtraFields(ele, e) {
e.preventDefault();
count = count + parseInt($(ele).parent().prev().find('input').attr('id'));
let extra = $(ele).parent().parent().clone();
$(extra).children('.remove-btn').remove();
$(extra).find('.feeAmountClass').val(null);
$(extra).find('.feeNameClass').val(null);
let newDatePicker = $(extra).find('.nepali-datepicker');
newDatePicker.attr('id', count);
extra.append('<div class="form-div add-remove-btns remove-btn"><button class="add-delete-btn" onclick="removeExtraField(this, event)" name="Add new Course" id="addBtn1">-</button></div>');
$('.multiple-fields-fees').append(extra);
let multipleFieldslength = $('.multiple-fields-fees .form-group.form-group-div').length;
let allinputs = $(extra).find('input');
let allselects = $(extra).find('select');
console.log(allselects);
let nameVal = '';
for (let i = 0; i < allinputs.length; i++) {
if (multipleFieldslength == 2) {
idCount = 0;
nameVal = allinputs[i].name.replace('[0]', '[' + (idCount + 1) + ']')
} else {
nameVal = allinputs[i].name.replace('[' + idCount + ']', '[' + (idCount + 1) + ']')
}
allinputs[i].setAttribute('name', nameVal);
}
for (let i = 0; i < allselects.length; i++) {
if (multipleFieldslength == 2) {
idCount = 0;
// nameVal = allinputs[i].name.replace('[0]', '[' + (idCount + 1) + ']')
selNameVal = allselects[i].name.replace('[0]', '[' + (idCount + 1) + ']')
console.log("=============> " + allselects[i].name + " --------------> " + idCount);
} else {
// nameVal = allinputs[i].name.replace('[' + idCount + ']', '[' + (idCount + 1) + ']')
selNameVal = allselects[i].name.replace('[' + idCount + ']', '[' + (idCount + 1) + ']')
console.log("<<<<<<<<<<<=============> " + idCount);
}
allinputs[i].setAttribute('name', nameVal);
allselects[i].setAttribute('name', selNameVal);
}
idCount++;
ele.remove();
}
function removeExtraField(ele, e) {
e.preventDefault();
let CurrentParent = $(ele).parent().parent();
let removedIndex = 0;
let multipleFields = $('.multiple-fields-fees .form-group.form-group-div');
for (var i = multipleFields.length - 1; i >= 0; i--) {
if (multipleFields[i] == CurrentParent[0]) {
removedIndex = i;
}
}
$(ele).parent().parent().remove();
let updatedMultipleFields = $('.multiple-fields-fees .form-group.form-group-div');
$('.add-remove-btns').remove();
for (var i = updatedMultipleFields.length - 1; i >= 0; i--) {
if (i == 0 && (updatedMultipleFields.length == 1)) {
$(updatedMultipleFields[i]).append('<div class="form-div add-remove-btns"><button class="add-delete-btn" onclick="addExtraFields(this, event)" name="Add new Course" id="addBtn1">+</button></div>');
} else if (i == updatedMultipleFields.length - 1) {
$(updatedMultipleFields[i]).append('<div class="form-div add-remove-btns"><button class="add-delete-btn" onclick="addExtraFields(this, event)" name="Add new Course" id="addBtn1">+</button></div><div class="form-div add-remove-btns remove-btn"><button class="add-delete-btn" onclick="removeExtraField(this, event)" name="Add new Course" id="addBtn1">-</button></div>');
} else if (i == 0) {
$(updatedMultipleFields[i]).append('');
} else {
$(updatedMultipleFields[i]).append('<div class="form-div add-remove-btns remove-btn"><button class="add-delete-btn" onclick="removeExtraField(this, event)" name="Add new Course" id="addBtn1">-</button></div>');
}
}
}
</script>
<script>
$("#fee_form").validate({
ignore: ":hidden",
rules: {
batch_id: "required",
course_id: "required",
common_bs_due_date: "required",
common_ad_due_date: "required",
common_fee_name: "required",
feetype: "required",
<?php for ($i = 0; $i < 20; $i++) {
echo "'feename[$i]' : {
required : true,
},";
} ?>
<?php for ($i = 0; $i < 20; $i++) {
echo "'feeamount[$i]' : {
required : true,
digits : true
},";
} ?>
<?php for ($i = 0; $i < 20; $i++) { ?> 'bsdate[<?php echo $i ?>]': "required",
'englishdate[<?php echo $i ?>]': "required",
<?php } ?>
},
messages: {
course_id: "Please select a course id",
batch_id: "Please select a batch id",
common_ad_due_date: "Please select a date",
common_bs_due_date: "Please select a date",
common_fee_name: "Please provide a common fee name",
feetype: "Please select a fee type",
<?php for ($i = 0; $i < 20; $i++) {
echo "'feename[$i]' : {
required : 'Please provide a fee name',
},";
} ?>
<?php for ($i = 0; $i < 20; $i++) {
echo "'feeamount[$i]' : {
required : 'Please provide a fee amount',
},";
} ?>
<?php for ($i = 0; $i < 20; $i++) { ?> 'bsdate[<?php echo $i ?>]': "Please select a date",
'englishdate[<?php echo $i ?>]': "Please select a date",
<?php } ?>
},
submitHandler: function(form, e) {
e.preventDefault();
fee_type_id = $('#feetype').val()
var flag = false;
$('#Nameerr').hide();
$('#dublicateErr').hide();
if (fee_type_id != 1 && fee_type_id != 2) { // Non-Unique Validation
// alert(fee_type_id);
let feeVal = [];
let selectedCourseIds = [];
$('.feeNameClass').each(function(index, ele) {
let val = ele.value.toLowerCase();
feeVal.push(val);
});
$('#course_id option:selected').each(function() {
let selectedCourseItem = $(this).val();
// alert('course_ids'+selectedItem);
if (selectedCourseItem != '') {
selectedCourseIds.push(selectedCourseItem);
}
});
let routeId = '';
if (fee_type_id == 4) {
routeId = $('#new_route_id option:selected').val();
}
let inputDataArr = {
id: <?= $fees_id ?>,
batch_id: $('#batch_id').val(),
course_id: selectedCourseIds,
fee_type: $('#feetype').val(),
fee_names: feeVal,
route_id: routeId,
}
let inputValue = JSON.stringify(inputDataArr);
if (fee_type_id == 4) {
let errordiv = '';
$.ajax({
url: '<?php echo base_url() ?>' + "admin/ajax_check_fee_names_new",
data: {
info: inputValue,
},
type: 'POST',
async: false,
dataType: "json",
success: function(data) {
console.log(data);
if (data) {
var arr;
errordiv += '<p class="text-danger" style="font-size:16px;">Please correct the following errors</p>';
for (var key in data) {
arr = data[key];
errordiv += '<p class="text-danger" style="font-size:14px;"> The Feetype <b>' + key + '</b> Already exists for <b>' + arr.join(",") + '</b></p>';
}
$('#dublicateErr').show();
$('#dublicateErr').empty().append(errordiv);
} else {
flag = true
}
console.log(flag);
}
});
} else {
$.ajax({
url: '<?php echo base_url() ?>' + 'admin/ajax_check_fee_names',
data: {
info: inputValue,
},
type: 'POST',
async: false,
success: function(data) {
if (data) {
flag = true
} else {
$('#dublicateErr').show();
$('#dublicateErr').text('Provided Fee Names have been used with the same batch,course and feetype id. Please change atleast 1 name');
}
}
});
}
} else { // Unique Validation
let inputDataArr = {
id: <?= $fees_id ?>,
batch_id: $('#batch_id').val(),
course_id: $('#course_id').val(),
fee_type: $('#feetype').val(),
}
console.log(inputDataArr);
let inputValue = JSON.stringify(inputDataArr);
$.ajax({
url: '<?php echo base_url() ?>' + 'admin/ajax_check_fee_names',
data: {
info: inputValue,
},
type: 'POST',
async: false,
success: function(data) {
console.log(data);
if (data == 'success') {
flag = true
} else {
$('#dublicateErr').show();
$('#dublicateErr').text('Application Fee and Course Fee cannot be created twice for the same batch,course,feetype combination');
}
}
});
}
// console.log("hello------", flag);
if (flag) {
form.submit();
}
}
});
</script>
<script>
$('#cal_language').change(function() {
$('.english-datepicker').hide();
$('.nepali-datepicker').hide();
$('.cm-datepicker').hide();
if ($(this).prop('checked')) {
$('.nepali-datepicker').show();
$('.cm-datepicker').show();
} else {
$('.english-datepicker').show();
}
})
</script>