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

 $sql = "SELECT * FROM eduportal_monthly_challan as fee, edu_student_details as std WHERE fee.student_id=std.student_id and std.status='0' and std.branch_id=".$_SESSION['branch']. " ";



 if($_REQUEST['class_id']!=NULL){
  
  
    
    if($_REQUEST['class_id']=="All"){
    
    } else {
     $sql .= " AND fee.classs_id = '" .$_REQUEST['class_id']. "' ";

    }

  if($_REQUEST['section']=='All'){
  } else {
      $sql .= " AND std.section_id =" . $_REQUEST['section']. " ";
 }
   
  if($_REQUEST['session']!=NULL){
    $sql .= " AND fee.session_id = '" .$_REQUEST['session']. "' ";
  }

  if($_REQUEST['month']!=NULL){
    $sql .= " AND fee.month_id = '" .$_REQUEST['month']. "' ";
  }

  

  $WorkAssignListings = $m->query($sql);

}


  // getting branch details
  
  $branch=getBranch($m);

  // getting details of total records


       $records=0;
      foreach($WorkAssignListings as $WorkAssignListVal)
      { 

  
      $totalAmount= $WorkAssignListVal['tutionfee']+$WorkAssignListVal['transportfee']+$WorkAssignListVal['balance']+$WorkAssignListVal['misc_fee']-$WorkAssignListVal['disc_amount'];
            
        if($totalAmount==0 ||  $totalAmount=="0"){
        
        continue;
        }
        else {
        $records++; 
        }
   }
 
     ?>


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

.thStyle{background-color:lightgray;text-align:center;}

</style>   
  </head>
 <script>  


function getsec(id){

    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 (xmlhttp.readyState==4 && xmlhttp.status==200) {

        document.getElementById("txt_section").innerHTML=xmlhttp.responseText;
        // alert(xmlhttp.responseText);

      }

    }

    xmlhttp.open("GET","get_section_all.php?class_id="+id,true);

    xmlhttp.send();

  }
    
</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;">
      
    <form class="" action="all_fee_receivables.php" enctype="multipart/form-data" method="get">
        <div class="panel panel-default">
          <div class="panel-heading " id="heading"><?php echo $records;?> Students Records <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 onClick="$('#advanceSearch').toggle('blind')" class="btn btn-primary" style="cursor:pointer;">Advance Search</a>

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

  <a target="_blank" class="btn btn-success fa fa-print" style="height: 34px;padding: 9px;" title="Print Fee Report" href="print_all_receivables.php?<?php echo session_id().session_id().session_id(); ?>&class_id=<?php echo $_GET['class_id'];?>&session=<?php echo $_GET['session'];?>&month=<?php echo $_GET['month'];?>&from=<?php echo $_GET['from'];?>&to=<?php echo $_GET['to'];?>&fee=<?php echo $_GET['fee'];?>&section=<?php echo $_GET['section'];?>&8lqc1oclfi4llgnioo156a61oe8lqc1oclfi4llgnioo156a61oe8lqc1&others=<?php echo $_GET['others'];?>">
   Print All Receivables
  </a>
<?php } ?>

</div>



          </span><div class="clearfix"></div> </div>
          <div class="panel-body">
          
            <div class="col-md-12" id="advanceSearch" style="display:none;">
             <div class="col-md-3 col-xs-12" style="padding: 8px;">
                <div class="form-group ">
                  <label class="required">Class</label>
 
                  <select name="class_id" class="form-control" onChange="getsec(this.value)"  >
                    <option value="All">All</option>

                    <?php
                    $m->where("branch_id", $_SESSION['branch']);
                    $WorkAssignList = $m->get("edu_class_config");
                    foreach($WorkAssignList as $WorkAssignListVal)
                    { ?>

                       <option <?php if($_REQUEST['class_id']==$WorkAssignListVal['class_id']){echo 'selected';}?> value="<?php echo $WorkAssignListVal['class_id']; ?>"><?php echo $WorkAssignListVal['Class_Name']; ?></option>


                            <?php
                    } ?>

                </select> 
                </div>
              </div>
              
              
     
            
              <div class="col-md-3 col-xs-12" style="padding: 8px;">
                <div class="form-group ">
                  <label class="required">Section</label>
                    <select name="section" id="txt_section" class="form-control"   >
                      <option value="All">All</option>
                   <?php
                              if(isset($_REQUEST['section']))
                              { 

                              $m->where("class_id", $_REQUEST['class_id']);    

                              $secondLevel = $m->get("edu_adm_section_detail");
                              
                              foreach($secondLevel as $secondLevel_val)
                              {
                              
                               ?>
                                <option <?php if($_REQUEST['section']==$secondLevel_val['section_id']){echo "selected";} ?> value="<?php echo $secondLevel_val['section_id']; ?>"><?php echo trim(utf8_encode_all($secondLevel_val['section_name'])); ?></option>

                              <?php }   ?>
                                
                          <?php } ?>

                    </select>

                  
                </div>
              </div>         
                      
              
              <div class="col-md-3 col-xs-12" style="padding:8px;">
                <div class="form-group ">
                  <label class="required">Session</label>
                    <select name="session" class="form-control" >
                            

                        <?php

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

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


                                <?php
                        } ?>

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


                 <div class="col-md-3 col-xs-12" style="padding: 8px;">

                       <div class="form-group ">

                          <label class="required">Challan Month</label>
                              <select name="month" id="month" class="form-control"  required>

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

                                  <?php
                                 
                                  $match;
                                  if(!isset($_REQUEST['month'])){
                                    $match=date('m');
                                  }else { $match=$_REQUEST['month']; }
                                  
                                  $WorkAssignList = $m->get("eduportal_month_config");
                                  foreach($WorkAssignList as $WorkAssignListVal)
                                  { ?>

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


                                          <?php
                                  } ?>

                              </select>
                            </div>


                    </div> 
                                     

              <div class="col-md-3 pull-right" style="padding:2px;">
                <div class="form-group ">
                   <input type="hidden" name="addaccountAdmin" value="1">
                <button type="submit" class="btn btn-primary" style="margin-top: 24px;float: right;">Search</button>
                </div>
              </div>

             
            </div>
            <div class="clearfix"></div>
          </div>
        </div>
      </form>
      <div class="clearfix"></div>
    </div>
    <br>

   
<?php 

 if(!isset($_REQUEST['class_id'])){
?>
          <div class="col-md-12">
                  <div  style="display:block;" class="alert alert-danger alert-dismissible">
                      <a href="#" class="close" data-dismiss="alert" aria-label="close">X</a>
                       <strong>Warning !</strong> Please select class and month from advance search to view fee report !!!
                  </div>
              </div>
<?php 
 }
?>  

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

<div class="col-md-9 col-xs-12">
 
    <div class="alert alert-success" id="msg">
     <a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>
      <strong>Success!</strong> Fee challan is paid successfully...
    </div>

</div>
  <?php  unset($_SESSION['upsuccess']); }?>

    <table id="listofstudents" data-page-length='200' class="table table-striped table-bordered" style="width:100%;font-size:11px;">
          
          <thead>
            <tr>
                <th width="2%">S.No</th>
                <th width="20%">Student Name</th>
                <th width="10%">Roll#</th>
                <th width="10%" style="text-align:center;"> Class </th>
                <th width="8%" style="text-align:center;">  Month </th>
                <th width="6%">DueDate </th>
                <th width="8%" style="text-align:center;">  Monthly Fee </th>
                <th width="5%">Balance </th>
                <th width="8%">Total </th>               
                <th width="10%">Status </th>
                <th width="6%">Paid </th>
                <th width="6%">Paid Again </th>
                <th width="6%">Remaning </th>
                


            </tr>
        </thead>
        <tbody>

     <?php 

     $count=1;
      foreach($WorkAssignListings as $WorkAssignListVal)
      { 

  $others_fee_parameter=0+getFeeAllOtherFee($WorkAssignListVal['student_id'],$WorkAssignListVal['challan_id'],$m);

      $totalAmount= $WorkAssignListVal['tutionfee']+$WorkAssignListVal['transportfee']+$WorkAssignListVal['balance']+$WorkAssignListVal['misc_fee']+$others_fee_parameter-$WorkAssignListVal['disc_amount'];
            
        if($totalAmount==0 ||  $totalAmount=="0"){
        
        continue;
      } 

      $remainingFee=$totalAmount-$WorkAssignListVal['collected_amount']-$WorkAssignListVal['paid_again_amount'];

      if($remainingFee==0 ||  $remainingFee=="0"){
        
        continue;
      }
                     
       // getting students details 
        if($totalAmount>$WorkAssignListVal['collected_amount']) {
        $m->where("student_id", $WorkAssignListVal['student_id']);
        $m->where("status", 0);
        $student=$m->get("edu_student_details");


      } else {
        continue;
      }
      ?>

        <tr>
                  
                  <td style="text-align:center;"> <?php echo $count; ?> </td>
                  <td>                  
                   <?php echo $student[0]['first_name'];?> <?php echo $student[0]['last_name'];?>
                   </td>

                  <td> <?php echo $student[0]['candidate_roll_no'];?> </td>
                  <td style="text-align:center;"> <?php echo getClassName($m,$WorkAssignListVal['class_id']);?>  </td>

                  <td> <?php echo getMonthName($m,$_REQUEST['month']);?> </td>                 
                  <td> <?php echo date("d-M",strtotime($WorkAssignListVal['challan_duedate']));?> </td>
                  <td style="text-align:center;"> <?php echo $WorkAssignListVal['tutionfee'];?> </td>
                  <td style="text-align:center;"> <?php echo $WorkAssignListVal['balance'];?> </td>
                  
                  <td style="text-align:center;"> <?php echo $totalAmount." Rs";?> 
                  </td>

          <td> 

      <?php if($WorkAssignListVal['paid_status']==0 || $WorkAssignListVal['paid_status']=="0"){ ?>    

          <a style="padding: 0px 5px; font-size:14px;"  class="btn btn-danger">

                  Not Paid <?php //echo $others_fee; ?>

          </a> 
         

         <?php } else { ?>    


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

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

          </a> 


         <?php } ?>   


                  </td>



                <td style="text-align:center;" >
                 
                  <input style="width:100px" class="form-control" readonly id="totalAmount_col<?php echo $count;?>" type="text" value=" <?php if($WorkAssignListVal['collected_amount']!=NULL){echo $WorkAssignListVal['collected_amount'];} else {echo "0";} ?>" />

                 </td>

                 <td style="text-align:center;" >
                 
                  <input style="width:100px" class="form-control" readonly id="totalAgainAmount_col<?php echo $count;?>" type="text" value=" <?php if($WorkAssignListVal['paid_again_amount']!=NULL){echo $WorkAssignListVal['paid_again_amount'];} else {echo "0";} ?>" />

                 </td>

                 <td><?php echo $totalAmount-$WorkAssignListVal['collected_amount']-$WorkAssignListVal['paid_again_amount'];?></td>
               

              </tr>

             


 <?php   $count++;      } ?>



           
            
           
        </tbody>
        
    </table>






    <br><br>


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

           
          </div>
        </div>

            </div>
          </div>
        </div>
        <!-- /page content -->
  

    
  <?php include('RootMe/js_linksscript.php');?>
  <script src="https://cdn.datatables.net/1.10.13/js/jquery.dataTables.min.js"></script>
    <script>
       

    $(document).ready(function() {
    $('#listofstudents').DataTable( {
        dom: 'Bfrtip',
              buttons: [
                  'print'
              ]
          } );
      } );
    </script>
  </body>
</html>
