<style>
body{background:#EAEDED;}
#fee_permission{display:none;}
#admission_fee_permission{display:none;}
</style>

<div class="container bg-white mt-3 pt-3">
<div class="row">
<div class="col-sm-12">


<div class="table-responsive">
<table class="table table-bordered table-striped">
<thead>
<tr>
<th colspan="2" class="text-center">Student Information</th>
</tr>
</thead>    
<tbody>
    
<?php
$table='enquiry';
$enq_id=$this->uri->segment('3');
$course='';
$get_student_information=$this->WelcomeModel->get_item_data($enq_id,$table);
if($get_student_information){
foreach($get_student_information as $student_information){
$course=$student_information['class'];
?>
    
<tr>
<th>Name</th>
<td><?php echo $student_information['first_name']; echo " "; echo $student_information['last_name'];?></td>
</tr>


<tr>
<th>Father's Name</th>
<td><?php echo $student_information['father_name'];?></td>
</tr>


<tr>
<th>Contact Number</th>
<td><?php echo $student_information['mobile_number'];?></td>
</tr>

<tr>
<th>Class</th>
<td><?php echo $student_information['class']; echo " "; echo $student_information['section'];?></td>
</tr>
<?php

}
}

?>

</tbody>
</table>
</div>
<?php
$ac_table='academic_session_details';
$acedemic_session_current='';
$get_current_acedemic_Session=$this->WelcomeModel->get_data($ac_table);
if($get_current_acedemic_Session){
    foreach($get_current_acedemic_Session as $acedemic_Session_data){
        if($acedemic_Session_data['status'] ==1){
            $acedemic_session_current=$acedemic_Session_data['id'];
        }
    }
}
$fee_heads_table='fee_heads';
$get_fee_heads_annual=$this->EnquiryModel->get_annual_fee_data($acedemic_session_current,$fee_heads_table);
if($get_fee_heads_annual){
    foreach($get_fee_heads_annual as $fee_heads_annual){
        $fee_head_id=$fee_heads_annual['id'];
        $get_fee_structure=$this->EnquiryModel->get_fee_structure_for_head_and_ac_session($fee_head_id,$acedemic_session_current,$course);
        if($get_fee_structure){
            foreach($get_fee_structure as $fee_structure){
                ?>
<p class="" style="float:left;margin:10px;">
<button type="button" class="btn btn-sm btn-success" id="<?php echo  $fee_heads_annual['fee_info']; ?>" fee_amount="<?php echo $fee_structure['amount']; ?>">
    <?php echo $fee_heads_annual['title']; ?>
</button>
</p>                    
                <?php
            }
        } 
    }
}
?>




</div>
<div class="col-sm-12 p-3"  >
<div style="box-shadow: 0 0 2px blue;" id="load-invoices">
    
</div>
</div>


<div class="col-sm-12 p-3"  id="prospectus_fee_form">
<div style="box-shadow: 0 0 2px blue;" class="p-3">
    
<form id=" ">
        <div class="form-group">
            <label>Prospectus Fee</label>
            <input type="number" value="" id="prospectus_fee_amount" class="form-control" readonly>
        </div>
        <div class="form-group">
            <label>Fee Date</label>
            <input type="date"  class="form-control" id="fee_date">
        </div>
        <div class="form-group">
            <label>Received Amount</label>
            <input type="number" class="form-control" placeholder="Received Amount" id="paid_amount">
        </div>
        
         
        <div class="form-group" id="fee_permission">
            
            <label>By Permission</label>
           
            <select name="permission" id="permission" class="form-control">
                <?php
        $table='school_staff';
        $get_school_staff_permission=$this->NewFeeModel->get_permission($table);
        if($get_school_staff_permission){
            foreach($get_school_staff_permission as $get_permission){
                
        ?>
                <option value="<?php echo $get_permission['name']; ?>"><?php echo $get_permission['name']; ?></option>
                     <?php 
        }
        }
        ?>
            </select>
        
        </div>
        
       
        <div class="form-group">
            <button type="button" class="btn btn-sm btn-success" id="prospectus-fee-submit">Submit</button>
        </div>
    </form>
</div>    
</div>


<div class="col-sm-12 p-3"  id="admission_fee_form">
<div style="box-shadow: 0 0 2px blue;" class="p-3">
    
<form id=" ">
        <div class="form-group">
            <label>Admission Fee</label>
            <input type="number" value="" id="admission_fee_amount" class="form-control" readonly>
        </div>
        <div class="form-group">
            <label>Fee Date</label>
            <input type="date"  class="form-control" id="admission_fee_date">
        </div>
        
        <div class="form-group">
            <label>Received Amount</label>
            <input type="number" class="form-control" id="received_amount" placeholder="Received Amount">
        </div>
        
        <div class="form-group" id="admission_fee_permission">
            
            <label>By Permission</label>
           
            <select name="admission_permission" id="admission_permission" class="form-control">
        <?php
        $table='school_staff';
        $get_school_staff_permission=$this->NewFeeModel->get_permission($table);
        if($get_school_staff_permission){
            foreach($get_school_staff_permission as $get_permission){
                
        ?>
                <option value="<?php echo $get_permission['name']; ?>"><?php echo $get_permission['name']; ?></option>
        <?php 
        }
        }
        ?>
            </select>
        
        </div>
        
        <div class="form-group">
            <button type="button" class="btn btn-sm btn-success" id="admission-fee-submit">Submit</button>
        </div>
    </form>
</div>    
</div>



</div>
</div>


<script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>



<script>
$(document).ready(function(){
$("#prospectus_fee_form").hide(); 
$("#admission_fee_form").hide(); 

loadallfeeinvoices();
function loadallfeeinvoices(){
var enquiry_id='<?php echo $this->uri->segment('3');?>';
$.ajax({
    
url: '<?php echo base_url() ?>Enquiry/loadallfeeinvoices',
type: 'POST', 
data: {enquiry_id:enquiry_id},
success: function(data){
$("#load-invoices").html(data);
// location.reload(); 
}
});
    
}

// $("#list_invoice").hide(); 
$("#prospectus_fee").click(function () {
    $("#prospectus_fee_form").show(); 
    
// var fee_amount= $(this).val();
var fee_amount= $(this).attr("fee_amount");
// alert(fee_amount);
$("#prospectus_fee_amount").val(fee_amount);

// document.getElementById("prospectus_fee_amount").innerHTML = fee_amount;
} ); 


$("#prospectus-fee-submit").click(function(){
var fee_amount=$("#prospectus_fee_amount").val();
// discount_value = $("#discount_value").val();
// alert(prospectus_fee_amount);

var fee_type='Prospectus Fee';
var enquiry_id='<?php echo $this->uri->segment('3');?>';
var fee_info='prospectus_fee';
var fee_date=$("#fee_date").val();
var received_amount=$("#paid_amount").val();
var balance_amount =0;
var extra_amount =0;
var permission_by=$("#permission").val();


if(fee_amount > received_amount){
    balance_amount=fee_amount - received_amount;
}else if(received_amount > fee_amount){
    extra_amount=received_amount - fee_amount;
}
if(balance_amount >0 ){
    $("#fee_permission").css("display", "block");
}
if(fee_date ==''){swal("Select Fee Date");}
if(received_amount ==''){swal("Received Amount Pending");}

if(fee_date !='' && received_amount !='' ){
$.ajax({
url: '<?php echo base_url() ?>Enquiry/add_fee',
type: 'POST', 
data: { fee_amount:fee_amount,fee_type:fee_type,enquiry_id:enquiry_id,fee_info:fee_info,fee_date:fee_date,received_amount:received_amount,extra_amount:extra_amount,balance_amount:balance_amount,permission_by:permission_by},
success: function(data){
$("#form1").hide();  
loadallfeeinvoices();
getmonths();
swal("Fee Submitted Successfully");
// location.reload(); 
}
});
}
});


$("#admission_fee").click(function () {
    $("#admission_fee_form").show(); 
    var admission_fee_amount= $(this).attr("fee_amount");

    $("#admission_fee_amount").val(admission_fee_amount);
});


$("#admission-fee-submit").click(function(){
var admission_fee_amount=$("#admission_fee_amount").val();
// discount_value = $("#discount_value").val();
var fee_type='Admission Fee';
var enquiry_id='<?php echo $this->uri->segment('3');?>';
var fee_info='admission_fee';
var fee_date=$("#admission_fee_date").val();
var received_amount=$("#received_amount").val();
var balance_amount =0;
var extra_amount =0;
var permission_by=$("#admission_permission").val();

if(admission_fee_amount > received_amount){
    balance_amount=admission_fee_amount - received_amount;
}else if(received_amount > admission_fee_amount){
    extra_amount=received_amount - admission_fee_amount;
}

if(balance_amount >0 ){
    $("#admission_fee_permission").css("display", "block");
}

if(fee_date ==''){swal("Select Fee Date");}
if(received_amount ==''){swal("Received Amount Pending");}

if(fee_date !='' && received_amount !=''){
$.ajax({
url: '<?php echo base_url() ?>Enquiry/add_fee',
type: 'POST', 
data: { fee_amount:admission_fee_amount,fee_type:fee_type,enquiry_id:enquiry_id,fee_info:fee_info,fee_date:fee_date,received_amount:received_amount,extra_amount:extra_amount,balance_amount:balance_amount,permission_by:permission_by},
success: function(data){
// $("#form1").hide();  
// loadallfeeinvoices();
// getmonths();
swal("Fee Submitted Successfully");
// location.reload(); 
}
});    
}


});

});

</script>

<script>
function myFunction() {
    debugger;
    var prospectus = document.getElementById("prospectus_fee_amount").value
    var amount = document.getElementById("paid_amount").value
}

if(amount > prospectus){
$("#permission").show();    
}
else{
$("#permission").hide();    
}
</script>

<script>
function myFunction() {
    debugger;
    var admission = document.getElementById("admission_fee_amount").value
    var admission_amount = document.getElementById("received_amount").value
}

if(admission_amount > admission){
$("#admission_permission").show();    
}
else{
$("#admission_permission").hide();    
}
</script>