<?php include("parent/callMe.php"); ?>
<?php  include("sessioncheck.php"); ?>
<?php

   $branch=$_SESSION['branch'];
      
     $session1;
      if($_REQUEST['session']!=NULL){

       $session1=$_REQUEST['session'];
     }else {
       $session1=$_SESSION['current_session'];
     }

    if($_REQUEST['student']!=NULL){

       $m->where("status", '0');
       $m->where("branch_id", $_SESSION['branch']);
       $m->where("student_id", $_REQUEST['student']);
       $WorkAssignListVal = $m->get("edu_student_details");

      }
     // print_r($WorkAssignListVal)

      $m->where("student_id", $WorkAssignListVal[0]['student_id']);
      /*$m->where("class_id", $WorkAssignListVal[0]['class_id']);*/
      $m->where("session_id", $_SESSION['current_session']);
      $m->where("branch_id", $_SESSION['branch']);
      $details2 = $m->get("eduportal_student_fee_structure");

      $m->where("class_id", $WorkAssignListVal[0]['class_id']);
      $class=$m->get("edu_class_config");

      $m->where("section_id", $WorkAssignListVal[0]['section_id']);
      $section=$m->get("edu_adm_section_detail");

      $m->where("session_id", $WorkAssignListVal[0]['session_id']);
      $session=$m->get("edu_session_config");

      $m->where("branch_id", $_SESSION['branch']);
      $branch_details = $m->get("edu_branch_config");

    // settings month details

    $default;
    
    if($_GET["month"]!=NULL ){
      $default= $_GET["month"];
    }
    else{
      $default= date("m");
    }
  
      $m->where("Month_Id", $default);
      $month_name=$m->get("eduportal_month_config");


      $m->where("user_id", $_SESSION['user_id']);
      $user_designation=$m->get("edu_user_config");
 
     ?>

<!DOCTYPE html>
<html lang="en">
  <head>
    
    <title>Pay Student Fee | EduPortal</title>
    <?php include('RootMe/css_links.php');?>

<style>

.thStyle{background-color:gray;color:white;}

tr th {padding:1.5%;border:1px solid white;}
tr td {padding:1%;}

@media only screen and (max-width: 768px) {

/* For mobile phones: */
.popup_style{margin-top:20%;}

}
</style>   
  </head>
  
<script>
function showResult1(str) {
  if (str.length==0) { 
    document.getElementById("livesearch1").innerHTML="";
    document.getElementById("livesearch1").style.border="0px";
    return;
  }
  if (window.XMLHttpRequest) {
    // code for IE7+, Firefox, Chrome, Opera, Safari
    xmlhttp=new XMLHttpRequest();
  } else {  // code for IE6, IE5
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
  xmlhttp.onreadystatechange=function() {
    if (this.readyState==4 && this.status==200) {
      document.getElementById("livesearch1").innerHTML=this.responseText;
      document.getElementById("livesearch1").style.border="1px solid #A5ACB2";
      //alert(this.responseText);
    }
  }
  xmlhttp.open("GET","livesearch_std_profile.php?q="+str,true);
  xmlhttp.send();
}
</script>

<script>  

function PayFullFee() {

 // others fee parameters
 var date=document.getElementById("date").value;
 var month=document.getElementById("month").value;
 //alert(date);
// general parameters to submit the fee

 var student=document.getElementById("student").value;
 var month_name=document.getElementById("month_name").value;
 var fine=document.getElementById("fine").value;
 var challan_id=document.getElementById("challan_id").value;
 var fee_recv_sms=document.getElementById("fee_recv_sms").value;
 var double_sms=document.getElementById("double_confirmation_sms_to_principal").value;
 var std_name=document.getElementById("std_name").value;
 var std_no=document.getElementById("std_no").value;
 var Owner_no=document.getElementById("Owner_no").value;
 var totalAmount=document.getElementById("totalAmount").value;
 var collected=totalAmount;

   //alert(std_no);

    if (window.XMLHttpRequest) {
      xmlhttp=new XMLHttpRequest();
    } else { // code for IE6, IE5
      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  xmlhttp.onreadystatechange=function() {

      if (xmlhttp.readyState==4 && xmlhttp.status==200) {

       if(xmlhttp.responseText=="1" || xmlhttp.responseText==1){

         // alert(xmlhttp.responseText);
         
          document.getElementById("paynow").style.display="none";
          document.getElementById("pay").style.display="none";
          document.getElementById("fullpaid").style.display="block";

          document.getElementById("paid_fee").innerHTML=totalAmount;
          
          // div empty text
          var div = document.getElementById('remaining_fee');
          while(div.firstChild){
              div.removeChild(div.firstChild);
          }
          document.getElementById("remaining_fee").innerHTML="0";
         //alert(xmlhttp.responseText);
       }// ending main if condition 

      }

    }

  xmlhttp.open("GET","PayFullFee.php?action=PayChallan&collected="+collected+"&challan_id="+challan_id+"&fee_recv_sms="+fee_recv_sms+"&double_confirmation_sms_to_principal="+double_sms+"&student="+student+"&fine="+fine+"&std_name="+std_name+"&std_no="+std_no+"&Owner_no="+Owner_no+"&totalAmount="+totalAmount+"&paid_date="+date+"&month="+month+"&month_name="+month_name,true);

  xmlhttp.send();

}


function FamilyData(studentid,cell_no)
    {
     // alert(studentid+"=="+cell_no);

   
        mySelectFunction(studentid);

        var ajx;  // The variable that makes Ajax possible!

        if (window.XMLHttpRequest)
            ajx = new XMLHttpRequest();
        ajx.onreadystatechange = function ()
        {
          //alert("786");
            if (ajx.readyState == 4)
            {
               // alert(ajx.responseText);  
                document.getElementById("myID"+studentid).innerHTML = ajx.responseText;

            }
        }
        
        ajx.open("GET", "get_family_data1.php?student_id="+studentid+"&cell_no="+cell_no);
        ajx.send();

    }


    function mySelectFunction(studentid) {

  var x = document.getElementById("myID"+studentid);
  if (x.style.display === "none") {
    x.style.display = "block";
  } else {
    x.style.display = "none";
  }
}

 </script>

 <!-- jQuery -->
    <script src="js/ajax_functions.js"></script>  
  <body class="nav-md">
    <div class="container body">
      <div class="main_container">
        <div class="col-md-3 left_col">
     
            <?php include('RootMe/sidebar.php');?>

              <?php include('RootMe/header.php');?>
     
        <!-- page content -->
          <div class="right_col" role="main">
          <div class="" style="background-color: white;">
           
<section class="add_sub_agent" id="table_sub_agent">
  <div class="container">

 <div class="" style="margin-top:10px;">
      
        <div class="panel panel-default">
             <div class="panel-heading" id="std_section">
      

            <div class="col-md-6">  
            
              <form>
                <input type="text" class="form-control" placeholder="Enter | Name | Father Name | Roll No" onkeyup="showResult1(this.value)" value="<?php echo $_GET['qr'];?>">
                <div id="livesearch1"></div>
              </form>
            
              <br>
             </div>      
           <div class="col-md-6"> 
              <span style="float:right;margin-top: -7px;">
              <input type="hidden" value="<?php echo session_id().session_id().session_id().session_id().session_id(); ?>" name="session" />

 <div class="pull-right">         


<a href="student_profile.php?<?php echo session_id().session_id().session_id().session_id().session_id(); ?>&student=<?php echo $WorkAssignListVal[0]['student_id'];?>" class="btn btn-primary"> Student Profile</a>

  &nbsp;

<a href="print_monthly_fee_report.php?<?php echo session_id().session_id().session_id().session_id().session_id(); ?>&std=<?php echo $WorkAssignListVal[0]['student_id'];?>&month=<?php echo $_GET['month'][0]['Month_Name'];?>" class="btn btn-primary" target="_blank"> Print Fee History</a>

  </div>

    </span><div class="clearfix"></div> 

</div>

<?php if(isset($_SESSION['FeeUpdated'])){?>

          <div id="check_std_msg1" class="col-md-12 col-sm-12 col-xs-12" style="margin-bottom:10px;">
                <div class="alert alert-success">
                 <a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>
                  <strong>Great !</strong> Fee details are updated successfully...
                </div>
          </div>

  <?php unset($_SESSION['FeeUpdated']); }?>

  <?php if(isset($_SESSION['alredy_Added'])){?>

          <div id="toastdelete"><script type="text/javascript"> launch_toastdelete();</script><div id="imgdelete"><b>Warning</b></div><div id="descdelete">Your Record is Already Added..</div></div>

  <?php unset($_SESSION['alredy_Added']); }?>

<div class="panel-body">

<div class="container">
  <div class="row">

   <div class="col-md-11" style="background-color: white;">

      <!-- Nav tabs -->
      <div class="card">
                <ul class="nav nav-tabs" role="tablist">

                 <li  class="active" role="presentation"><a href="#Fee<?php echo $WorkAssignListVal[0]['student_id'];?>" aria-controls="home" role="tab" data-toggle="tab">Fee History</a></li>

                 <li role="presentation"><a href="#Family<?php echo $WorkAssignListVal[0]['student_id'];?>" aria-controls="profile" role="tab" data-toggle="tab">Family Fee</a></li>
           
                    <li role="presentation"><a href="#EditFee<?php echo $WorkAssignListVal[0]['student_id'];?>" aria-controls="profile" role="tab" data-toggle="tab">Edit Student Fee</a></li>

                    <li role="presentation"><a href="#AdvanceChallan<?php echo $WorkAssignListVal[0]['student_id'];?>" aria-controls="profile" role="tab" data-toggle="tab">Creat New Challan</a></li>

                    
            
                </ul>

                <!-- Tab panes -->
                <div class="tab-content">

<div role="tabpanel" class="tab-pane" id="Family<?php echo $WorkAssignListVal[0]['student_id'];?>">

<!-- <div class="col-md-2">
    <div class="form-group ">
          <label class="required" style="color:white; "> . </label> <br>
           <a data-toggle="modal" data-target="#payFamilyChallan" style=" font-size:14px;" href="#" class="btn btn-success">

                  Family Fee
                  
              </a>      
    </div>
</div> -->

     <!-- Modal -->
  <div id="payFamilyChallan" class="modal fade" role="dialog">
    <div class="modal-dialog">

      <!-- Modal content-->
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal">&times;</button>
          <h4 class="modal-title"> Family Fee (<?php echo date("M");?>)   </h4>
        </div>


        <div class="modal-body">

        <h4> Sibling Details)

        </h4>


      </div>


  <table border="1" width="100%">  


              <tr>  

                <th class="thStyle" style="text-align: center;padding:1%;"> Student Name  </th>
                <th class="thStyle" style="text-align: center;padding:1%;"> Father Name </th>
                <th class="thStyle" style="text-align: center;padding:1%;"> Class/Sec </th>
                <th class="thStyle" style="text-align: center;padding:1%;"> Roll No </th>
                <th class="thStyle" style="text-align: center;padding:1%;"> Total Fee </th>
              
              </tr>
<?php 
 $m->where("status", 0);
 $m->where("branch_id", $_SESSION['branch']);
 $m->where("cell_no", $WorkAssignListVal[0]['cell_no']);
 $childs = $m->get("edu_student_details"); 
//print_r($childs);

 $fee_types = $m->get("eduportal_fee_types");

 foreach ($childs as $child) {

  $m->where("class_id", $child['class_id']);
  $class=$m->get("edu_class_config");

  $m->where("section_id", $child['section_id']);
  $section=$m->get("edu_adm_section_detail");

  $month_id=date("m");
  $branchId=$_SESSION['branch'];
   $sql = " select * from eduportal_monthly_challan where month_id='$month_id' AND 
branch_id='$branchId' AND student_id='".$child['student_id']."' AND session_id='".$_SESSION['current_session']."' ";
//print_r($sql);
$FmilyFee = $m->query($sql);


foreach ($fee_types as $type) {

$other_fees=getFeeOfOtherParameter($child['student_id'],$FmilyFee[0]['challan_id'],$type['feetype_id'],$m);

}

$totalAM=$FmilyFee[0]['balance']+$FmilyFee[0]['tutionfee']+$FmilyFee[0]['transportfee']+$FmilyFee[0]['misc_fee']+ $other_fees + $fee_fine;
          $total_month_fee=$totalAM-$FmilyFee[0]['disc_amount'];


$GrandTotal+=$total_month_fee;
?>            
              <tr>  

                <td> <?php echo $child['first_name'];?> </td> 
                <td> <?php echo $child['last_name'];?> </td>
                <td> <?php echo $class[0]['Class_Name']."-".$section[0]['section_name'];?> </td> 
                <td> <?php echo $child['candidate_roll_no'];?> </td>
                <td> <?php echo $total_month_fee;?> </td>
              </tr>

<?php   } ?>

          
 
             </table>

              <div class="col-md-4" >
                          <div class="form-group" >
                            
                            <label> Grand Total </label>
                              
                              <input style="height:40px;padding-left:1%;" name="totalFamilyAmount" type="text"  value="<?php echo $GrandTotal; ?>"  class="form-control field"  readonly/>
                          </div>
               </div>

               <!-- <a id="paynow" onClick="PayFullFee();" style="padding: 0px 5px; font-size:14px;margin-top: 32px;"  class="btn btn-danger">

                  Pay Full 

              </a> -->

            


             <br><br><br><br>

          </div>

        </div>
      </div>

      <!-- ending -->


<div class="col-md-2">
                <div class="form-group ">
                      <label class="required" style="color:white; "> . </label> <br>
                      <a onclick="FamilyData(<?php echo $WorkAssignListVal[0]['student_id'];?>,'<?php echo $WorkAssignListVal[0]['cell_no'];?>')" class="btn btn-success"> Show Family Data </a>      
                  </div>
</div>


            <div id="myID<?php echo $WorkAssignListVal[0]['student_id'];?>" style="display:none">
   

            </div> 

</div>

<div role="tabpanel" class="tab-pane" id="AdvanceChallan<?php echo $WorkAssignListVal[0]['student_id'];?>">

<form class="form-style-7" action="<?php echo DOMAIN.AgentDirectory;?>parent/InsertMe.php" method="post" enctype="multipart/form-data">
        
       <input type="hidden" value="" class="form-control"  id="validate_status" />

       <input type="hidden" name="action" value="CreateStudentChallan"  />
       <input type="hidden" name="session" value="<?php echo $session1; ?>"  />
       <input type="hidden" name="class_id"   value="<?php echo $WorkAssignListVal[0]['class_id']; ?>"  />
       <input type="hidden" name="section_id" value="<?php echo $WorkAssignListVal[0]['section_id']; ?>"  />
       <input type="hidden" name="student_id" value="<?php echo $WorkAssignListVal[0]['student_id']; ?>"  />
       <input name="balance" type="hidden" value="<?php echo $student_balance;?>" />


        <h2>Creat Voucher  
          <span style="color:red;font-size:14px;">
         (These fee parameters will only include on selected month of voucher)  </span>
       </h2>

       <div class="col-md-3 col-sm-12 col-xm-12 floatm" style="">
                <div class="form-group ">
             
                    <select name="session" class="form-control">

                              
                        <?php

                       $match;
                        if(!isset($_REQUEST['session'])){
                          $match=$_SESSION['current_session'];
                        }else { $match=$_REQUEST['session']; }
                       
                                 
                        $Sessions = $m->get("edu_session_config");
                        foreach($Sessions as $Session)
                        { ?>

                           <option <?php if($match==$Session['session_id']){echo 'selected';}?> value="<?php echo $Session['session_id']; ?>"><?php echo $Session['session_year']; ?></option>


                                <?php
                        } ?>

                    </select>
                </div>
              </div>


        <div class="col-md-3 col-sm-6 col-xs-12 form-group has-feedback">
            <select name="month_id" id="month_id" class="form-control"  required>

                  <option value="">Select Month</option>
            

            <?php
            $Months = $m->get("eduportal_month_config");
            foreach($Months as $Month)
            { ?>

               <option <?php if(date("m")==$Month['Month_Id']){echo 'selected';}?> value="<?php echo $Month['Month_Id']; ?>"><?php echo $Month['Month_Name']; ?></option>


                    <?php
            } ?>

        </select>
            
        </div>

<?php 
  $student_balance;                    
// check if the challan is already created
  
  $qr = "select * from  eduportal_monthly_challan where branch_id=".$_SESSION['branch'];

  if ($_REQUEST['student']!=NULL) {
      $qr .= " AND student_id=" . $_REQUEST['student']. " ";
  }

  $qr .= " order by challan_id  desc limit 1";

//print_r($qr);
  $student_challan =  $m->query ($qr);  

   // print_r($student_challan);

    if(count($student_challan)>0){

      $std_others_total=getFeeAllOtherFee($_REQUEST['student'],$student_challan[0]['challan_id'],$m);
  
        $total=$student_challan[0]['tutionfee']+$student_challan[0]['misc_fee']+$student_challan[0]['transportfee']+$student_challan[0]['balance']+$std_others_total-$student_challan[0]['disc_amount'];

        $student_balance=$total-$student_challan[0]['collected_amount'];
        //echo $total."--b--".$collected_amount;

    }else {
      
        $student_balance=$details2['std_outstanding_blc'];
    
    } 

    // code to check if the last challan is not paid then add fine to previous balance...
    $std_id=$details2['student_id'];
    $qr=" select * from eduportal_monthly_challan where student_id='$std_id' order by challan_id desc limit 1";
    $fee_data = $m->query($qr);

    // echo $qr;

        $fee_fine;

    if(count($fee_data)>0 && $fee_data[0]['paid_status']==0){

      if($brid[0]['fine_type']=="0" || $brid[0]['fine_type']==0){ 

    $student_balance+=$brid[0]['late_fee_fine'];
  }  else {
    
    $student_balance+= ($datediffrence * $brid[0]['late_fee_fine']);
   }

    } else {
      
    $fee_fine=0;  
    }


?> 
         

         <div class="col-md-3 col-sm-6 col-xs-12 form-group has-feedback">

            <input type="date" class="form-control" id="duedate" name="duedate" placeholder="Date of Birth" value="<?php echo date("Y-m-d") ?>">
            <span class="form-control-feedback right" aria-hidden="true">Ddate</span>
        </div>

         <div class="col-md-3 col-sm-6 col-xs-12 form-group has-feedback">
          <input type="text" value="<?php  if($details2[0]['std_tution_fee']!=0){ echo $details2[0]['std_tution_fee'];} ?>" class="form-control has-feedback-left" id="tution_fee" name="tution_fee" placeholder="Monthly Fee" autocomplete="off" />
          <span class="form-control-feedback left" aria-hidden="true">Fee</span>
        </div>

         <div class="col-md-3 col-sm-6 col-xs-12 form-group has-feedback">
          <input type="text" value="<?php  if($details2[0]['std_transport_fee']!=0){ echo $details2[0]['std_transport_fee'];} ?>" class="form-control" name="transport_fee" id="transport_fee" placeholder="Transport Fee" autocomplete="off" />
          <span class="form-control-feedback right" aria-hidden="true">Tr.Fe</span>
        </div>

         <div class="col-md-3 col-sm-6 col-xs-12 form-group has-feedback">
          <input type="text" value="<?php  if($student_balance!=0){ echo $student_balance;} ?>"
                  class="form-control" name="outstanding" id="outstanding" placeholder="Old Balance" autocomplete="off" />
          <span class="form-control-feedback right" aria-hidden="true">Baln.</span>
        </div>

          <div class="col-md-3 col-sm-6 col-xs-12 form-group has-feedback">
            <input type="text"  value="<?php  if($details2[0]['std_misc_fee']!=0){ echo $details2[0]['std_misc_fee'];} ?>" class="form-control" name="std_misc_fee" id="std_misc_fee" placeholder="Miscellaneous Fee" autocomplete="off" />
            <span class="form-control-feedback right" aria-hidden="true">Mis.</span>
          </div>


      <div class="col-md-3 col-sm-6 col-xs-12 form-group has-feedback">
        
        <select name="disc_type" id="disc_type" class="form-control">

              <!-- <option <?php if($details['disc_type']=="Fixed"){echo 'selected';}?> 
              value="Fixed">Fixed</option> -->
              <option <?php if($details['disc_type']=="Percentage"){echo 'selected';}?> 
              value="Percentage">Disc. in Percentage</option>
           </select>

          </div>




        <div class="col-md-3 col-sm-6 col-xs-12 form-group has-feedback">
           <input name="disc_amount" placeholder="Discount in Percentage..." value="<?php echo $discount_fee; ?>" type="number" min="0" max="100" class="form-control"  
                      > 
            <span class="form-control-feedback right" aria-hidden="true">Val.</span>
          </div>





  <?php 

/*printing all the fee types variables*/
 $fee_types1 = $m->get("eduportal_fee_types");
 foreach ($fee_types1 as $type) {

?>

        <div class="col-md-3 col-sm-6 col-xs-12 form-group has-feedback">

          <input type="text" class="form-control" name="type<?php echo $type['feetype_id']; ?>" id="proc_fee" placeholder="<?php echo $type['feetype_name']; ?>" autocomplete="off" />
          <span class="fa fa-dollar form-control-feedback right" aria-hidden="true"></span>
        </div>


<?php  } ?>

      <div class="col-md-1 col-sm-6 col-xs-12 form-group">
      <input type="submit" value="Save" class="form-control btn btn-primary" name="submit" />
     </div>

</form>

</div>



<div role="tabpanel" class="tab-pane" id="EditFee<?php echo $WorkAssignListVal[0]['student_id'];?>">
<form class="form-style-7" action="<?php echo DOMAIN.AgentDirectory;?>parent/InsertMe.php" method="post" onSubmit="return student_check();" enctype="multipart/form-data">
  
       <input type="hidden" value="" class="form-control"  id="validate_status" />

  <?php 

     if(isset($_REQUEST['rollno'])){

      $m->where("candidate_roll_no", $_REQUEST['rollno']);
      $m->where("status", "0");
      $m->where("branch_id", $_SESSION['branch']);
      $student = $m->get("edu_student_details");

        $m->where("class_id", $student[0]['class_id']);
        $m->where("branch_id", $_SESSION['branch']);
        $class=$m->get("edu_class_config");

        $m->where("section_id", $student[0]['section_id']);
        $m->where("branch_id", $_SESSION['branch']);
        $section=$m->get("edu_adm_section_detail");
    }

   if(isset($_REQUEST['student'])){

    $m->where("student_id", $_REQUEST['student']);
    $student = $m->get("edu_student_details");

      $m->where("class_id", $student[0]['class_id']);
      $class=$m->get("edu_class_config");

      $m->where("section_id", $student[0]['section_id']);
      $section=$m->get("edu_adm_section_detail");

  }

  /*$m->where("session_id", $_SESSION['session']);*/
  $m->where("class_id", $student[0]['class_id']);
  $m->where("branch_id", $_SESSION['branch']);

  $details = $m->get("eduportal_class_fee_details");

  // print_r($details);
  $total=$details[0]['tution_fee']+$details[0]['transport_fee']+$details[0]['admission_fee'];
?>              

<?php 

  $m->where("student_id", $student[0]['student_id']);
  $m->where("class_id", $student[0]['class_id']);
  $m->where("session_id", $_SESSION['current_session']);
  $m->where("branch_id", $_SESSION['branch']);
  $details1 = $m->get("eduportal_student_fee_structure");

 // print_r($details1);

  $show_fee=0;
  if($details1[0]['std_tution_fee']!=""){
    $show_fee=$details1[0]['std_tution_fee'];
  }else {
    $show_fee=$details[0]['tution_fee'];
  }

?>
    
<?php 
// if search with rollnumber

   if(isset($_REQUEST['rollno'])){
?>

<input type="hidden" name="student_id"  value="<?php echo $student[0]['student_id']; ?>" />
<input type="hidden" name="rollno"  value="<?php echo $student[0]['candidate_roll_no']; ?>" />
<input type="hidden" name="fee_id"  value="<?php echo $details[0]['fee_id']; ?>" />
<input type="hidden" name="class_id"  value="<?php echo $WorkAssignListVal[0]['class_id']; ?>" />
<input type="hidden" name="action"  value="StudentFeeStructure">

<?php 
}
  if(isset($_REQUEST['student'])){
?>

  <input type="hidden" name="action"  value="StudentFeeStructure">

  <input type="hidden" name="student_id"  value="<?php echo $_REQUEST['student']; ?>" />
  <input type="hidden" name="fee_id"  value="<?php echo $details[0]['fee_id']; ?>" />
  <input type="hidden" name="class_id"  value="<?php echo $WorkAssignListVal[0]['class_id']; ?>" />

<?php }  ?>


<h3 style="text-align:left;margin-top:2%;margin-left:1.3%;"> Fee Parameters (Regular Monthly)  </h3>

        <div class="row">

               
             <div class="col-md-2 col-xs-12" style="margin-left:1.3%;" >
                        <div class="form-group" >
                          
                          <label>  Balance (Initial) </label>
                            <input style="height:40px;padding-left:1%;" type="text"  value="<?php echo 0+$details1[0]['std_outstanding_blc']; ?>"  class="form-control field" name="std_outstanding_blc" id="std_outstanding_blc" />
                        </div>
                    </div>

                    <div class="col-md-2 col-xs-12" style="margin-left:1.3%;" >
                        <div class="form-group" >
                          
                          <label>  Transport Fee </label>
                            <input style="height:40px;padding-left:1%;" type="text"  value="<?php echo 0+$details1[0]['std_transport_fee']; ?>"  class="form-control field" name="transport_fee" id="transport_fee" />
                        </div>
                    </div>

                   <div class="col-md-2 col-xs-12" >
                        <div class="form-group" >
                          
                          <label>  <?php if ($brid[0]['misc_title']!=NULL){echo $brid[0]['misc_title'];}else {echo 'Miscellaneous';} ?> </label>
                            <input style="height:40px;padding-left:1%;" type="text"  value="<?php echo 0+$details1[0]['std_misc_fee']; ?>"  class="form-control field" name="std_misc_fee" id="std_misc_fee" />
                        </div>
                    </div>

                    <div class="col-md-2 col-xs-12" >
                          <div class="form-group" >

                            <label>  Montly Fee </label>
                              <input style="height:40px;padding-left:1%;" type="text"  value="<?php echo $show_fee; ?>"  class="form-control field" name="tution_fee" id="tution_fee" />
                          </div>
                      </div>

                  <div class="col-md-5 col-xs-12" >
                          <div class="form-group" >

                            <label>  Fee Discount Reason </label>
                              <input style="height:40px;padding-left:1%;" type="text"  value="<?php echo $details1[0]['discount_reason']; ?>"  class="form-control field" name="discount_reason" id="discount_reason" />
                          </div>
                      </div>

      </div>  <!-- ending row-->     

        <div class="row">
              
         <div class="col-md-3" >
              <div class="form-group" >
                
                <input type="submit" class="btn btn-primary" value="Save Record" style="margin-top:10%;"  >
      
          </div>


    </div>


    </div>   <!--  ending 12 column-->


    </form>
</div>


<div role="tabpanel" class="tab-pane active" id="Fee<?php echo $WorkAssignListVal[0]['student_id'];?>">

<br>
<div style="overflow-x:auto;">

<?php if($_GET['student']!=NULL){ ?>

<span style="font-size:20px; float:left;"> Pay Fee: &nbsp; <?php echo $WorkAssignListVal[0]['first_name']." | ".$WorkAssignListVal[0]['last_name']." | ".$class[0]['Class_Name']."-".$section[0]['section_name']." | ".$WorkAssignListVal[0]['candidate_roll_no']." | ".$WorkAssignListVal[0]['ref_no'];?> </span>
<?php }else { ?>

   <div class="alert alert-danger" id="msg">
             <a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>
              <strong>Caution!</strong> Please search student to view fee details!!!
    </div>

<?php } ?>

    
            <table border="1" width="100%" style="font-size:10px;" class="responsive">  


              <tr>  

                <th width="5%" class="thStyle"> Month  </th>
                <th width="5%" class="thStyle"> Due Date  </th>
                <th width="5%" class="thStyle"> Monthly Fee  </th>
                <th width="5%" class="thStyle"> Balance  </th>
                <th width="5%" class="thStyle"> Fine  </th>
                <th width="5%" class="thStyle"> Other  </th>
                <th width="5%" class="thStyle"> Total  </th>
                <th width="12%" class="thStyle"> Challan  </th>
                <th width="8%" class="thStyle"> Status  </th>
                <th width="5%" class="thStyle"> Paid Amount </th>
                <th width="4%" class="thStyle"> Remaining  </th>
                <th width="4%" class="thStyle"> Paid Date </th>
                
              </tr>

<?php 


  $m->where("student_id", $WorkAssignListVal[0]['student_id']);
  $m->where("session_id", $session1);
  $m->orderBy("challan_id","desc");
  $history = $m->get("eduportal_monthly_challan");
  $ck=count($history);
  $counter=0;

foreach($history as $details){
    
    $counter++;
    $m->where("Month_Id", $details['month_id']);
    $month=$m->get("eduportal_month_config");


    $m->where("user_id", $details['paid_fee_user_id']);
    $PaidFeeUser=$m->get("edu_user_config");


    $m->where("challan_id", $details['challan_id']);
    $m->where("month_id", $details['month_id']);
    $m->where("student_id", $WorkAssignListVal[0]['student_id']);
    $m->where("branch_id", $_SESSION['branch']);
    $againData=$m->get("eduportal_again_paid_challan");

//print_r($againData);
     // getting students details 

    $m->where("student_id", $WorkAssignListVal[0]['student_id']);
    $m->where("status", 0);
    $student=$m->get("edu_student_details");

   
    $OthersTotal=0+getFeeAllOtherFee($student[0]['student_id'],$details['challan_id'],$m);

    $totalAmount= $details['tutionfee']+$details['transportfee']+$details['balance']+$details['misc_fee']+$OthersTotal; 

    

    $start_date = strtotime($details['challan_duedate']); 
    $end_date = strtotime(date("Y-m-d"));
    $datediffrence =($end_date - $start_date)/60/60/24;

    // calculating student discount
    $discount_fee=($details['disc_amount']/$details['tutionfee'])*100;
      

    $totalAmount1=$totalAmount-$details['disc_amount']; 
?>            
          <tr>  

            <td> <?php echo $month[0]['Month_Name'];?> </td>
            <td> <?php echo date("d-M",strtotime($details['challan_duedate']));?> </td>
            <td> <?php echo $details['tutionfee'];?> </td>
            <td> <?php echo 0+$details['balance'];?> </td>
            
          <td> <?php 

    $student_fine=0;
    $actual_fine=0;



  
   if($branch_details[0]['fine_type']=="0" || $branch_details[0]['fine_type']==0){  

    $student_fine= $branch_details[0]['late_fee_fine']; } 

  else {
    
    $student_fine= ($datediffrence * $branch_details[0]['late_fee_fine']);
   }


  //if(date("Y-m-d")>$details['challan_duedate'] && $details['paid_status']==1){

// if row is first 

   if ($counter==1){

        // if row is first and fee is paid then show only collected fine
          if($details['paid_status']==1){
             echo $details['collected_fine'];
             $actual_fine=$details['collected_fine'];
           
          } 
        // if row is first and fee is not paid then calculate fine
          else if(date("Y-m-d")>$details['challan_duedate'] && $details['paid_status']==0){
            echo $student_fine; 
            $actual_fine=$student_fine;
          }
      
    } 
// if not row is first and then show only collected fine
    else {

         echo $details['collected_fine'];
         $actual_fine=$details['collected_fine'];
    }
    


    $totalAmount1+=$actual_fine;

        ?> 

        </td>

        <td style="text-align:center;"> 


        <a data-toggle="modal" data-target="#otherFee<?php echo $WorkAssignListVal['student_id'];?>" style="padding: 0px 4px; font-size:14px;"  class="btn btn-warning">
          <?php echo $OthersTotal;?>  
        </a> 


      <!-- Modal -->
      <div id="otherFee<?php echo $WorkAssignListVal['student_id'];?>" class="modal fade" role="dialog">
        <div class="modal-dialog">

          <!-- Modal content-->
          <div class="modal-content" style="width: 900px;margin-left: -25%;">
            <div class="modal-header">
              <button type="button" class="close" data-dismiss="modal">&times;</button>
              <h4 class="modal-title"> Other Fee Parameters  </h4>
            </div>


            <div class="modal-body">



              <p> <?php echo $student[0]['first_name'];?>  <?php echo $student[0]['last_name'];?>  </b>
                (<?php echo getClassName($m,$_GET['class_id']);?>)

              </p>


            </div>


          <br>
          <div class="col-md-12" >
            

            <table border="1" width="100%">  


              <tr>  

                <th class="thStyle" style="text-align: center;padding:1%;"> Fee Type  </th>
                <th class="thStyle" style="text-align: center;padding:1%;"> Amount  </th>
              
              </tr>
<?php 

 $fee_types = $m->get("eduportal_fee_types"); 

if(count($fee_types)<=0){
  echo "<tr> <td colspan='10' style='color:red;text-align:center;'> No record found ! </td> </tr> ";

}

 foreach ($fee_types as $type) {

  $fee=getFeeOfOtherParameter($student[0]['student_id'],$details['challan_id'],$type['feetype_id'],$m);
  if($fee==NULL){
    continue;
  }

?>            
              <tr>  

                <td> <?php echo $type['feetype_name'];?> </td> 
                <td> <?php echo $fee;?> </td> 
                
              </tr>

<?php   } ?>

             </table>

          </div>

          <br><br>


            <div class="modal-footer">

             <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>


            </div>

          </div>

        </div>
      </div>

      <!-- ending modal -->

               </td>

              <td style="text-align:center;"> <?php echo $totalAmount1 ; ?>   </td>
             

                <td>

                <div class="btn-group">
                      <button data-toggle="dropdown" class="btn btn-warning dropdown-toggle btn-sm" type="button" aria-expanded="true">Print <span class="caret"></span>
                      </button>
                      <ul role="menu" class="dropdown-menu">
       <?php 

    $page;

    if($brid[0]['triple_single_voucher']!=NULL){
      $page=$brid[0]['triple_single_voucher'];
    }else{
      $page="print_voucher.php";  
    }

    ?>
     
   
            <li><a href="print_single_voucher.php?a61oe8lqc1oclfi4llgnioo156a61oe8lqc1oclfi4llgnioo156a61oe8lqc1oclfi4llgnioo156a61oe8lqc1oclfi4llgnioo156a61oe8lqc1oclfi4llgnioo156&amp;student_id=<?php echo $WorkAssignListVal[0]['student_id'];?>&month=<?php echo $month[0]['Month_Name'];?>&month_id=<?php echo $month[0]['Month_Id'];?>&session=<?php echo $session1; ?>" target="_blank">Single Voucher</a></li>

            <li><a href="print_double_voucher.php?a61oe8lqc1oclfi4llgnioo156a61oe8lqc1oclfi4llgnioo156a61oe8lqc1oclfi4llgnioo156a61oe8lqc1oclfi4llgnioo156a61oe8lqc1oclfi4llgnioo156&amp;student_id=<?php echo $WorkAssignListVal[0]['student_id'];?>&month=<?php echo $month[0]['Month_Name'];?>&month_id=<?php echo $month[0]['Month_Id'];?>&session=<?php echo $session1; ?>" target="_blank">Double Voucher</a></li>

            <li><a href="<?php echo $page;?>?a61oe8lqc1oclfi4llgnioo156a61oe8lqc1oclfi4llgnioo156a61oe8lqc1oclfi4llgnioo156a61oe8lqc1oclfi4llgnioo156a61oe8lqc1oclfi4llgnioo156&amp;student_id=<?php echo $WorkAssignListVal[0]['student_id'];?>&month=<?php echo $month[0]['Month_Name'];?>&month_id=<?php echo $month[0]['Month_Id'];?>&session=<?php echo $session1; ?>" target="_blank">Triple Voucher</a></li>

                      </ul>
                </div>
                &nbsp;

                <?php if($counter==1 && $details['paid_status']==1 && $user_designation[0]['designation_id']==12){ ?>

                <a data-toggle="modal" data-target="#EditPaidChallan<?php echo $details['challan_id'];?>" style="padding: 0px 5px; font-size:14px;" href="#" class="btn btn-warning">
                  <i class="fa fa-pencil" aria-hidden="true"></i>
                  </a>
                        
                <?php } if($counter==1 && $details['paid_status']==0 && $user_designation[0]['designation_id']==12){ ?>

                <a data-toggle="modal" data-target="#EditChallan<?php echo $details['challan_id'];?>" style="padding: 0px 5px; font-size:14px;" href="#" class="btn btn-warning">
                  <i class="fa fa-pencil" aria-hidden="true"></i>
                  </a>
                        
                <?php } ?>

             <?php if($counter==1){ ?>

                <a onclick="return confirm('Are you sure you want to delte this challan???');" style="padding: 0px 5px; font-size:14px;"
                 href="<?php echo DOMAIN.AgentDirectory;?>parent/InsertMe.php?action=DeleteVoucher&challan=<?php echo $details['challan_id'];?>&student_id=<?php echo $_GET['student']?>&session=<?php echo $session1?>" class="btn btn-danger">
                  <i class="fa fa-remove" aria-hidden="true"></i>
                </a>
                        
            <?php } ?>



               
      <!-- Modal -->
      <div id="EditChallan<?php echo $details['challan_id'];?>" class="modal fade" role="dialog">
        <div class="modal-dialog">

          <!-- Modal content-->
          <div class="modal-content">
            <div class="modal-header">
              <button type="button" class="close" data-dismiss="modal">&times;</button>
              <h4 class="modal-title"> Edit Fee Challan   </h4>
            </div>


            <div class="modal-body">

<?php 

$sql_fee = " select * from  eduportal_class_fee_details where branch_id=".$_SESSION['branch']." AND class_id=".$WorkAssignListVal[0]['class_id'];
$class_fee = $m->query($sql_fee);


// now checking if the fee is not paid then put class standard dues on parameters...

?>

              <h4> <?php echo $student[0]['first_name'];?> <?php echo $student[0]['last_name'];?>  </b>
                (<?php echo $class[0]['Class_Name'];?>)

              </h4>


            </div>

<form class="form-style-7" action="<?php echo DOMAIN.AgentDirectory;?>parent/InsertMe.php" method="post"  enctype="multipart/form-data">

  
          <div class="col-md-4" >

          <input type="hidden" name="action" value="EditChallan">
          <input type="hidden" name="challan_id" value="<?php echo $details['challan_id']; ?>">
          <input type="hidden" name="month_id" value="<?php echo $details['month_id']; ?>">
          <input type="hidden" name="class_id" value="<?php echo $student[0]['class_id']; ?>">
          <input type="hidden" name="session" value="<?php echo $session1; ?>">
          <input type="hidden" name="call" value="pay_fee">
          <input type="hidden" name="student" value="<?php echo $_GET['student']; ?>">



                <div class="form-group" >
                        
                        <label>  Monthly Fee </label>
                          <input style="height:40px;padding-left:1%;" type="text" value="<?php echo $details['tutionfee']; ?>"  class="form-control field" name="tutionfee" id="tutionfee" />
                      </div>
                </div>

                 <div class="col-md-4" >
                      <div class="form-group" >
                        
                        <label>  Transport Fee </label>
                          <input style="height:40px;padding-left:1%;" type="text"  value="<?php echo $details['transportfee']; ?> "  class="form-control field" name="transportfee" id="transportfee" />
                      </div>
                  </div>


                 <div class="col-md-4" >
                      <div class="form-group" >
                        
                        <label>  <?php if ($brid[0]['misc_title']!=NULL){echo $brid[0]['misc_title'];}else {echo 'Miscellaneous';} ?>  </label>
                          <input style="height:40px;padding-left:1%;" type="text"  value="<?php echo $details['misc_fee']; ?> "  class="form-control field" name="misc_fee" id="misc_fee" />
                      </div>
                  </div>
          
          
            <div class="col-md-4" >
                          <div class="form-group" >
                            
                            <label>  Due Date </label>
                                   
                  <?php
                  $Date = date("Y-m-d");
                  
                  ?>

      <input style="height:40px;padding-left:1%;" type="date" name="challan_duedate"  value="<?php echo $details['challan_duedate']; ?>" required  class="form-control field" id="paidDate" />

                    </div>
              </div>



                 <div class="col-md-4" >
                      <div class="form-group" >
                        
                        <label>  Prev.Balance </label>
                          <input style="height:40px;padding-left:1%;" type="text"  value="<?php echo $details['balance']; ?>" name="balance"  class="form-control field" />
                      </div>
                  </div>


              <div class="col-md-4" >
                  <div class="form-group" >
                    
                    <label>  Fine  </label>
                      <input style="height:40px;padding-left:1%;" type="text" id="fine" 
                      value="<?php echo $actual_fine;?>"  class="form-control field" name="fine" />
                  </div>
              </div>




            <div class="col-md-4">

                           <div class="form-group ">

                        <label class="required">Fee Discount</label>
                            <select name="disc_type" id="disc_type" class="form-control">

              <!-- <option <?php if($details['disc_type']=="Fixed"){echo 'selected';}?> 
              value="Fixed">Fixed</option> -->
              <option <?php if($details['disc_type']=="Percentage"){echo 'selected';}?> 
              value="Percentage">Percentage</option>


                            </select>
                        </div>

                </div> 
        

            <div class="col-md-4">
               <div class="form-group ">

                  <label class="required"> Discount (%)</label>
                      <input name="disc_amount"  
                      value="<?php echo $discount_fee; ?>" type="text" class="form-control"  
                      >      
                  </div>
              </div>   






  <table>     
<?php 

 $fee_types = $m->get("eduportal_fee_types"); 

if(count($fee_types)<=0){
  echo "<tr> <td colspan='10' style='color:red;text-align:center;'> No record found ! </td> </tr> ";

}

 foreach ($fee_types as $type) {

  $fee=getFeeOfOtherParameter($student[0]['student_id'],$details['challan_id'],$type['feetype_id'],$m);
  if($fee==NULL){
    
  }

?>            
              <tr>  

                

                <div class="col-md-4" >
                  <div class="form-group" >
                    
                    <label> <?php echo $type['feetype_name'];?></label>
                     

   <input  style="height:40px;padding-left:1%;" type="text" class="form-control" name="type<?php echo $type['feetype_id']; ?>" id="proc_fee" value="<?php echo $fee;?>"  placeholder="<?php echo $type['feetype_name']; ?>" autocomplete="off" />



                  </div>
              </div>



               
                
              </tr>

<?php   } ?>
             
</table>

            <div class="modal-footer col-md-12 col-xs-12">

              <button type="submit" class="btn btn-primary" name="submit" >Update Fee </button>
              <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>


            </div>

                 
                 </form>

          </div>

        </div>
      </div>

      <!-- ending -->
      
      <!-- Eid Paid Challan Modal -->
      <div id="EditPaidChallan<?php echo $details['challan_id'];?>" class="modal fade" role="dialog">
        <div class="modal-dialog">

          <!-- Modal content-->
          <div class="modal-content">
            <div class="modal-header">
              <button type="button" class="close" data-dismiss="modal">&times;</button>
              <h4 class="modal-title"> Edit Paid Fee  </h4>
            </div>


            <div class="modal-body">

<?php 



$sql_fee = " select * from  eduportal_class_fee_details where branch_id=".$_SESSION['branch']." AND class_id=".$WorkAssignListVal[0]['class_id'];
$class_fee = $m->query($sql_fee);


// now checking if the fee is not paid then put class standard dues on parameters...

?>

              <h4> <?php echo $student[0]['first_name'];?> <?php echo $student[0]['last_name'];?>  </b>
                (<?php echo $class[0]['Class_Name'];?>)

              </h4>


            </div>


<form class="form-style-7" action="<?php echo DOMAIN.AgentDirectory;?>parent/InsertMe.php" method="post"  enctype="multipart/form-data">
           
          <?php 

           $fee_types = $m->get("eduportal_fee_types"); 

          if(count($fee_types)<=0){
            echo "<tr> <td colspan='10' style='color:red;text-align:center;'> No record found ! </td> </tr> ";

          }

           foreach ($fee_types as $type) {

            $fee=getFeeOfOtherParameter($student[0]['student_id'],$details['challan_id'],$type['feetype_id'],$m);
            if($fee==NULL){
              
            }

          ?>            
             
                  <div class="col-md-4" >
                    <div class="form-group" >
                      
                      <label> <?php echo $type['feetype_name']; ?>   </label>
                        <input style="height:40px;padding-left:1%;" type="text" name="type<?php echo $type['feetype_id']; ?>" id="proc_fee" value="<?php echo $fee;?>"  placeholder="<?php echo $type['feetype_name']; ?>" autocomplete="off"  class="form-control field" name="fine" />
                    </div>
                </div>  




          <?php   } ?>

                <div class="col-md-4" >



          <input type="hidden" name="action" value="EditPaidChallan">
          <input type="hidden" name="challan_id" value="<?php echo $details['challan_id']; ?>">
          <input type="hidden" name="month_id" value="<?php echo $details['month_id']; ?>">
          <input type="hidden" name="class_id" value="<?php echo $student[0]['class_id']; ?>">
          <input type="hidden" name="session" value="<?php echo $student[0]['session_id']; ?>">
          <input type="hidden" name="call" value="profile">
          <input type="hidden" name="student" value="<?php echo $_GET['student']; ?>">



                      <div class="form-group" >
                        
                        <label>  Montly Fee </label>
                          <input style="height:40px;padding-left:1%;" type="text" value="<?php echo $details['tutionfee']; ?>"  class="form-control field" name="tutionfee" id="tutionfee" />
                      </div>
                </div>

                 <div class="col-md-4" >
                      <div class="form-group" >
                        
                        <label>  Transport Fee </label>
                          <input style="height:40px;padding-left:1%;" type="text"  value="<?php echo $details['transportfee']; ?> "  class="form-control field" name="transportfee" id="transportfee" />
                      </div>
                  </div>


                 <div class="col-md-4" >
                      <div class="form-group" >
                        
                        <label>  <?php if ($brid[0]['misc_title']!=NULL){echo $brid[0]['misc_title'];}else {echo 'Miscellaneous';} ?>  </label>
                          <input style="height:40px;padding-left:1%;" type="text"  value="<?php echo $details['misc_fee']; ?> "  class="form-control field" name="misc_fee" id="misc_fee" />
                      </div>
                  </div>
          
          
            <div class="col-md-4" >
                          <div class="form-group" >
                            
                            <label>  Due Date </label>
                                   
                  <?php
                  $Date = date("Y-m-d");
                  $dd=date('Y-m-d', strtotime($details['paying_date']));
                  ?>

      <input style="height:40px;padding-left:1%;" type="date" name="challan_duedate"  value="<?php echo $details['challan_duedate']; ?>" required  class="form-control field" id="paidDate" />

                    </div>
              </div>


              <div class="col-md-4" >
                          <div class="form-group" >
                            
                            <label>  Paid Date </label>
                                   
        
                            <input style="height:40px;padding-left:1%;" type="date" name="paid_date"  value="<?php echo $dd; ?>" required  class="form-control field" id="paidDate" />
                          </div>
                    </div>



                 <div class="col-md-4" >
                      <div class="form-group" >
                        
                        <label>  Prev.Balance </label>
                          <input style="height:40px;padding-left:1%;" type="text"  value="<?php echo $details['balance']; ?>" name="balance"  class="form-control field" />
                      </div>
                  </div>




              <div class="col-md-4" >
                  <div class="form-group" >
                    
                    <label>  Fine  </label>
                      <input style="height:40px;padding-left:1%;" type="text" id="fine"
                       value="<?php echo $actual_fine; ?>"  class="form-control field" name="fine" readonly/>
                  </div>
              </div>



            <div class="col-md-4">
               <div class="form-group ">

                  <label class="required">Fee Discount</label>
                      <input name="disc_amount"  
                      value="<?php echo $details['disc_amount']; ?>" type="text" class="form-control"  
                      >      
                  </div>
              </div>   


                 <div class="col-md-4" >
                          <div class="form-group" >
                            
                            <label>  Total Fee </label>
                              <input type="hidden" name="totalAmount" value="<?php echo $totalAmount1+$others_fee; ?>">
                              <input style="height:40px;padding-left:1%;" type="text"  value="<?php echo $totalAmount1; ?>"  class="form-control field" readonly/>
                          </div>
                    </div>




                 <div class="col-md-4" >
                          <div class="form-group" >
                            
                            <label>  Paid Fee </label>
                            
                              <input style="height:40px;padding-left:1%;" type="text"  value="<?php echo ($details['collected_amount']+$details['collected_fine']); ?>"  class="form-control field" name="total_paid" />
                          </div>
                    </div>

            <div class="modal-footer">

              <button type="submit" class="btn btn-primary" name="submit" >Update Fee </button>
              <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>


            </div>



                 </form>

          </div>

        </div>
      </div>

      <!-- ending -->
      

          </td>


      <!-- these are the hidden fields... -->

  <input  type="hidden"  value="<?php echo $details['month_id']; ?>" id="month"/>
  <input  type="hidden"  value="<?php echo $month[0]['Month_Name']; ?>" id="month_name"/>

  <input  type="hidden"  value="<?php echo date("Y-m-d"); ?>" id="date"/>
  

  <input  type="hidden"  value="<?php echo $totalAmount+$actual_fine-$details['disc_amount']; ?>" id="totalAmount"/>
  <input  type="hidden"  value="<?php echo $details['student_id']; ?>" id="student"/>
  <input  type="hidden"  value="0" id="fine"/>
  <input  type="hidden"  value="<?php echo $details['challan_id']; ?>" id="challan_id"/>
  <input  type="hidden"  value="<?php echo $brid[0]['fee_recv_sms']; ?>"  id="fee_recv_sms"/>
  <input  type="hidden"  value="<?php echo $brid[0]['double_confirmation_sms_to_principal']; ?>" id="double_confirmation_sms_to_principal"/>
  <input  type="hidden"  value="<?php echo $student[0]['first_name']; ?>"  id="std_name"/>
  <input  type="hidden"  value="<?php echo $student[0]['cell_no']; ?>"  id="std_no"/> 
  <input  type="hidden"  value="<?php echo $brid[0]['Owner_no']; ?>" id="Owner_no"/>
   

            <td>

                
             <?php if($counter==1 && $details['paid_status']==0){ ?>    

              <a id="pay" data-toggle="modal" data-target="#payChallan<?php echo $details['challan_id'];?>" style="padding: 0px 5px; font-size:14px;" href="#" class="btn btn-warning">

                  PAY
                  
              </a> 

              <a id="paynow" onClick="PayFullFee();" style="padding: 0px 5px; font-size:14px;"  class="btn btn-danger">

                  Pay Full 

              </a>

               <a id="fullpaid<?php echo $count;?>" style="padding: 0px 5px; font-size:14px;display:none;"  class="btn btn-success">

                  Fully Paid <i class="fa fa-check" aria-hidden="true"></i><i class="fa fa-check" aria-hidden="true"></i>

               </a>

                 <?php } else if($counter!=1 && $details['paid_status']==0) { ?>    


                <a data-toggle="modal" style="padding: 0px 5px; font-size:14px;"  class="btn btn-danger">Not Paid </a> 

              <?php }else{ ?>   

                <a data-toggle="modal" style="padding: 0px 5px; font-size:14px;"  class="btn btn-success">Paid </a> 

                <a id="pay" data-toggle="modal" data-target="#againpayChallan<?php echo $details['challan_id'];?>" style="padding: 0px 5px; font-size:14px;" href="#" class="btn btn-warning">

                  Again Paid
                  
              </a>
                   
                 <a data-toggle="modal" data-target="#ViewPaidFee<?php echo $details['challan_id'];?>" style="padding: 0px 5px; font-size:14px;" href="#" class="btn btn-warning">
                  <i class="fa fa-search" aria-hidden="true"></i>
                </a>  
                  
               <?php } ?>   
             
 <!-- Modal -->
  <div id="ViewPaidFee<?php echo $details['challan_id'];?>" class="modal fade" role="dialog">
    <div class="modal-dialog">

      <!-- Modal content-->
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal">&times;</button>
          <h4 class="modal-title"> View Paid Fee Details   </h4>
        </div>


        <div class="modal-body">


        <h4> <?php echo $student[0]['first_name'];?> <?php echo $student[0]['last_name'];?>  </b>
          (<?php echo $class[0]['Class_Name'];?>)

        </h4>


      </div>


        <form class="form-style-7" action="<?php echo DOMAIN.AgentDirectory;?>parent/InsertMe.php" method="post"  enctype="multipart/form-data">

         
          <?php 

           $fee_types = $m->get("eduportal_fee_types"); 

          if(count($fee_types)<=0){
            echo "<tr> <td colspan='10' style='color:red;text-align:center;'> No record found ! </td> </tr> ";

          }

           foreach ($fee_types as $type) {

            $fee=getFeeOfOtherParameter($student[0]['student_id'],$details['challan_id'],$type['feetype_id'],$m);
            if($fee==NULL){
              
            }

          ?>            
             
                  <div class="col-md-4" >
                    <div class="form-group" >
                      
                      <label>  <?php echo $type['feetype_name']; ?>  </label>
                        <input style="height:40px;padding-left:1%;" type="text" name="type<?php echo $type['feetype_id']; ?>" id="proc_fee" value="<?php echo $fee;?>"  placeholder="<?php echo $type['feetype_name']; ?>" autocomplete="off"  class="form-control field" name="fine" />
                    </div>
                </div>  




          <?php   } ?>

             <div class="col-md-4" >
                      <div class="form-group" >
                        
                        <label>  <?php if ($brid[0]['misc_title']!=NULL){echo $brid[0]['misc_title'];}else {echo 'Miscellaneous';} ?> Charges </label>
                          <input style="height:40px;padding-left:1%;" type="text"  value="<?php echo $details['misc_fee'];?>"  class="form-control field" name="misc" id="misc" readonly/>
                      </div>
                  </div>


                <br>

                 <div class="col-md-4" >
                      <div class="form-group" >
                        
                        <label>  Monthly Fee </label>
                          <input style="height:40px;padding-left:1%;" type="text" value="<?php echo $details['tutionfee']; ?>"  class="form-control field" id="lname" readonly/>
                      </div>
                </div>

                 <div class="col-md-4" >
                      <div class="form-group" >
                        
                        <label>  Transport Fee </label>
                          <input style="height:40px;padding-left:1%;" type="text"  value="<?php echo $details['transportfee']; ?> "  class="form-control field" name="" id="lname" readonly/>
                      </div>
                  </div>


                 <div class="col-md-4" >
                      <div class="form-group" >
                        
                        <label>  Prev.Balance </label>
                          <input style="height:40px;padding-left:1%;" type="text"  value="<?php echo $details['balance']; ?>"  class="form-control field" readonly/>
                      </div>
                  </div>


              <div class="col-md-4" >
                  <div class="form-group" >
                    
                    <label>  Fine  </label>
                      <input style="height:40px;padding-left:1%;" type="text" id="fine" 
                      value="<?php echo $actual_fine;?>"  class="form-control field" name="fine" readonly/>
                  </div>
              </div>

            <div class="col-md-4" >
                  <div class="form-group" >
                    
                    <label>  Fee Discount  </label>
                      <input style="height:40px;padding-left:1%;" type="text" id="fine" 
                      value="<?php echo $details['disc_amount'];?>"  class="form-control field" name="fine" readonly/>
                  </div>
              </div>

                 <div class="col-md-4" >
                          <div class="form-group" >
                            
                            <label>  Total </label>
                            <input type="hidden" name="totalAmount" value="<?php echo $totalAmount1+$others_fee; ?>">
                              <input style="height:40px;padding-left:1%;" type="text"  value="<?php echo $totalAmount1+$others_fee; ?>"  class="form-control field" id="total" readonly/>
                          </div>
                    </div>


                 <div class="col-md-4" >
                          <div class="form-group" >
                            
                            <label>  Due Date </label>
                         
                            <input style="height:40px;padding-left:1%;" type="text" name="duedate" 
                             value="<?php echo date('d-M-Y', strtotime($details['challan_duedate'])); ?>" readonly   class="form-control field" />
                          </div>
                    </div>


                 <div class="col-md-4" >
                          <div class="form-group" >
                            
                            <label>  Paid Date </label>
                         
                            <input style="height:40px;padding-left:1%;" type="text" name="duedate" 
                             value="<?php echo date('d-M-Y', strtotime($details['paying_date'])); ?>" readonly   class="form-control field" />
                          </div>
                    </div>



               <div class="col-md-4" >
                      <div class="form-group" >
                        
                        <label>  Paid Amount </label>
                          <input style="height:40px;padding-left:1%;" type="text" value="<?php echo $details['collected_amount']; ?>"  class="form-control field" readonly/>
                      </div>
                </div>
   
            <div class="modal-footer">

              <!-- <button type="submit" class="btn btn-primary" name="submit" >Save </button> -->
              <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>


            </div>



                 </form>

          </div>

        </div>
      </div>

      <!-- ending -->

  <!-- Modal -->
  <div id="payChallan<?php echo $details['challan_id'];?>" class="modal fade" role="dialog">
    <div class="modal-dialog">

      <!-- Modal content-->
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal">&times;</button>
          <h4 class="modal-title"> Pay Student Fee   </h4>
        </div>


        <div class="modal-body">

        <h4> <?php echo $student[0]['first_name'];?> <?php echo $student[0]['last_name'];?>  </b>
          (<?php echo $class[0]['Class_Name'];?>)

        </h4>


      </div>


        <form class="form-style-7" action="<?php echo DOMAIN.AgentDirectory;?>parent/InsertMe.php" method="post"  enctype="multipart/form-data">

  

           
          <?php 

           $fee_types = $m->get("eduportal_fee_types"); 

          if(count($fee_types)<=0){
            echo "<tr> <td colspan='10' style='color:red;text-align:center;'> No record found ! </td> </tr> ";

          }

           foreach ($fee_types as $type) {

            $fee=getFeeOfOtherParameter($student[0]['student_id'],$details['challan_id'],$type['feetype_id'],$m);
            if($fee==NULL){
              
            }

          ?>            
             
                  <div class="col-md-4" >
                    <div class="form-group" >
                      
                      <label>  <?php echo $type['feetype_name']; ?>  </label>
                        <input style="height:40px;padding-left:1%;" readonly type="text" name="type<?php echo $type['feetype_id']; ?>" id="proc_fee" value="<?php echo $fee;?>"  placeholder="<?php echo $type['feetype_name']; ?>" autocomplete="off"  class="form-control field" name="fine" />
                    </div>
                </div>  

          <?php   } ?>


        <input type="hidden" name="action" value="PayChallan">
        <input  type="hidden" name="month_name" value="<?php echo $month[0]['Month_Name']; ?>"/>
        <input type="hidden" name="challan_id" value="<?php echo $details['challan_id']; ?>">
        <input type="hidden" name="month_id" value="<?php echo $details['month_id']; ?>">
        <input type="hidden" name="class_id" value="<?php echo $student[0]['class_id']; ?>">
        <input type="hidden" name="session" value="<?php echo $student[0]['session_id']; ?>">
        <input type="hidden" name="std_name" value="<?php echo $student[0]['first_name'];?>">
        <input type="hidden" name="std_no" value="<?php echo $student[0]['cell_no'];?>">
        <input type="hidden" name="fee_recv_sms" value="<?php echo $brid[0]['fee_recv_sms']; ?>">
        <input type="hidden" name="call" value="pay_fee">
        <input type="hidden" name="student" value="<?php echo $_GET['student']; ?>">
        <!-- fee details  -->
        <input type="hidden" name="adm" value="<?php echo $adm_fee; ?>">
        <input type="hidden" name="paper" value="<?php echo $paper; ?>">
        <input type="hidden" name="lab" value="<?php echo $lab; ?>">
        <input type="hidden" name="lib" value="<?php echo $library; ?>">
        <input type="hidden" name="other" value="<?php echo $oth_fee; ?>">


             <div class="col-md-4" >
                      <div class="form-group" >
                        
                        <label>  <?php if ($brid[0]['misc_title']!=NULL){echo $brid[0]['misc_title'];}else {echo 'Miscellaneous';} ?> Charges </label>
                          <input style="height:40px;padding-left:1%;" type="text"  value="<?php echo $details['misc_fee'];?>"  class="form-control field" name="misc" id="misc" readonly/>
                      </div>
                  </div>


                <br>

                 <div class="col-md-4" >
                      <div class="form-group" >
                        
                        <label>  Montly Fee </label>
                          <input style="height:40px;padding-left:1%;" type="text" value="<?php echo $details['tutionfee']; ?>"  class="form-control field" id="lname" readonly/>
                      </div>
                </div>

                 <div class="col-md-4" >
                      <div class="form-group" >
                        
                        <label>  Transport Fee </label>
                          <input style="height:40px;padding-left:1%;" type="text"  value="<?php echo $details['transportfee']; ?> "  class="form-control field" name="" id="lname" readonly/>
                      </div>
                  </div>


                 <div class="col-md-4" >
                      <div class="form-group" >
                        
                        <label>  Prev.Balance </label>
                          <input style="height:40px;padding-left:1%;" type="text"  value="<?php echo $details['balance']; ?>"  class="form-control field" readonly/>
                      </div>
                  </div>



              <div class="col-md-4" >
                      <div class="form-group" >
                        
                        <label>  Fine </label>
                          <input style="height:40px;padding-left:1%;" type="text" value="<?php echo $actual_fine;?>"  class="form-control field" id="fine5<?php echo $details['challan_id'];?>" 
                        onkeyup="net_totals(<?php echo $details['challan_id'];?>)" name="fine"/>
                      </div>
                </div>


      

               <div class="col-md-4" >
                      <div class="form-group" >
                        
                        <label>  Discount </label>
                          <input style="height:40px;padding-left:1%;" type="text" value="<?php echo $details['disc_amount'];?>"  class="form-control field" id="discount<?php echo $details['challan_id'];?>" onkeyup="net_totals(<?php echo $details['challan_id'];?>)" name="disc_amount"/>
                      </div>
                </div>

                <input id="totlamt<?php echo $details['challan_id'];?>" type="hidden" name="" value="<?php echo $totalAmount;?>">
                
                 <div class="col-md-4" >
                          <div class="form-group" >
                            
                            <label>  Total </label>
                              
                              <input style="height:40px;padding-left:1%;" name="totalAmount" type="text"  value="<?php echo $totalAmount1; ?>"  class="form-control field" id="totalamt<?php echo $details['challan_id'];?>" readonly/>
                          </div>
                    </div>


                 <div class="col-md-4" >
                          <div class="form-group" >
                            
                            <label>  Paid Date </label>
                         
        <?php
        $Date = date("Y-m-d");
        $days=' +'.$brid[0]['default_pay_date'].'days';


        ?>

                            <input style="height:40px;padding-left:1%;" type="date" name="paid_date"  value="<?php echo date('Y-m-d', strtotime($Date.$days)); ?>" required  class="form-control field" id="paidDate" />
                          </div>
                    </div>



 
                     <div class="col-md-4" >
                          <div class="form-group" >
                            
                            <label>  Pay Amount </label>
                              <input style="height:40px;padding-left:1%;" autofocus="autofocus" onKeyUp="calculate_amount(this.value);" type="text"  required  class="form-control field" name="collected" autocomplete="off" />
                          </div>
                      </div>

          <script>

          function calculate_amount(str){

            var id = document.getElementById("total").value;   
            document.getElementById("balance").value=id-str;   


          }

            function net_totals(id) {
        
        
        var discount=document.getElementById("discount"+id).value;
        var fine=document.getElementById("fine5"+id).value;
        var total_amt=document.getElementById("totlamt"+id).value;
        
       

        
        
        var total_amount= (Number(fine) + Number(total_amt)) - Number(discount);
        
        document.getElementById("totalamt"+id).value=total_amount;



        
      }
          </script>



            <div class="modal-footer">

              <button type="submit" class="btn btn-primary" name="submit" >Save </button>
              <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>


            </div>



                 </form>

          </div>

        </div>
      </div>

      <!-- ending -->

                 </td>

  <!-- Modal -->
  <div id="againpayChallan<?php echo $details['challan_id'];?>" class="modal fade" role="dialog">
    <div class="modal-dialog">

      <!-- Modal content-->
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal">&times;</button>
          <h4 class="modal-title"> Again Pay Student Fee   </h4>
        </div>


        <div class="modal-body">

        <h4> <?php echo $student[0]['first_name'];?> <?php echo $student[0]['last_name'];?>  </b>
          (<?php echo $class[0]['Class_Name'];?>)

        </h4>


      </div>


        <form class="form-style-7" action="<?php echo DOMAIN.AgentDirectory;?>parent/InsertMe.php" method="post"  enctype="multipart/form-data">

  

        <input type="hidden" name="action" value="AgainAmountPayChallan">
        <input  type="hidden" name="month_name" value="<?php echo $month[0]['Month_Name']; ?>"/>
        <input type="hidden" name="challan_id" value="<?php echo $details['challan_id']; ?>">
        <input type="hidden" name="month_id" value="<?php echo $details['month_id']; ?>">
        <input type="hidden" name="class_id" value="<?php echo $student[0]['class_id']; ?>">
        <input type="hidden" name="session" value="<?php echo $student[0]['session_id']; ?>">
        <input type="hidden" name="std_name" value="<?php echo $student[0]['first_name'];?>">
        <input type="hidden" name="std_no" value="<?php echo $student[0]['cell_no'];?>">
        <input type="hidden" name="fee_recv_sms" value="<?php echo $brid[0]['fee_recv_sms']; ?>">
       
        <input type="hidden" name="student" value="<?php echo $_GET['student']; ?>">
       
            

                 <div class="col-md-12" >
                          <div class="form-group" >
                            
                            <label>  Paid Date </label>
                         
        <?php
        $Date = date("Y-m-d");
        $days=' +'.$brid[0]['default_pay_date'].'days';


        ?>

                            <input style="height:40px;padding-left:1%;" type="date" name="again_paid_date"  value="<?php echo date('Y-m-d', strtotime($Date.$days)); ?>" required  class="form-control field" id="" />
                          </div>
                    </div>



 
                     <div class="col-md-12" >
                          <div class="form-group" >
                            
                            <label>  Again Pay Amount </label>
                              <input style="height:40px;padding-left:1%;" autofocus="autofocus" type="text"  required  class="form-control field" name="again_paid" autocomplete="off" />
                          </div>
                      </div>

         

            <div class="modal-footer">

              <button type="submit" class="btn btn-primary" name="submit" >Save </button>
              <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>


            </div>



                 </form>

          </div>

        </div>
      </div>
 
      <!-- ending -->
      <td id="paid_fee"> 
        <?php echo 0+($details['collected_amount']+$details['collected_fine']+$details['paid_again_amount']+getMoreFee($details['challan_id'],$m));?> / By <?php echo $PaidFeeUser[0]['user_fname'] ?> </td>

      <td id="remaining_fee" style="background-color:pink;"> 
        
        <?php echo $totalAmount1-($details['collected_amount']+$details['collected_fine']+$details['paid_again_amount']);?> </td>

      <td> <?php  if($details['paying_date']!=NULL){ ?>
      <?php echo date("d-M",strtotime($details['paying_date']));?> <br/>

      <?php echo $details['paying_time'];?>

      <?php } ?> </td>

    </tr>


<?php 

}
?>            

             </table>

</div>


                    </div>
                    



                </div>
      

      </div>

       </div> <!-- col 9 -->
  </div>
</div>  <!-- container -->


    <br><br>

<div class="clearfix"></div>
</div>
</div>
      
    </div>
 
  </div>
  <div class="clearfix"></div>
</section>            
               
          </div>
        </div>

            </div>
          </div>
        </div>
        <!-- /page content -->
      
  <?php include('RootMe/js_linksscript.php');?>
  </body>
</html>
