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

<?php
$branch=$_SESSION['branch'];
$sessionID=$_REQUEST['session'];
$month=$_REQUEST['month'];



       
$sql = " select std.*, fee.* from  edu_student_details as std, eduportal_student_fee_structure as fee where std.student_id=fee.student_id AND std.session_id='$sessionID' AND std.status='0' AND std.branch_id='$branch' group by std.cell_no order by std.last_name asc";

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





 ?>

<!DOCTYPE html>
<html lang="en">
  <head>
   
    <title> Family Repors | EduPortal </title>
     <?php include('RootMe/css_links.php');?> 
  </head>
  
  <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="row" style="background-color: white;">
  

<section class="add_sub_agent" id="table_sub_agent">
  <div class="container">

<form action="family_reports.php?<?php echo session_id().session_id().session_id().session_id().session_id(); ?>">

                
                
          <div class="col-md-12">      
                 <div class="col-md-3 col-sm-12 col-xs-12" style="padding:8px; float:left;"  id="col1">
                 <div class="form-group ">

                 <label class="required"> Session</label>
                   <select name="session" class="form-control" >

                    <!-- <option value="">All</option> -->
              

              <?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-sm-12 col-xs-12" style="padding:8px; float:left;"  id="col2">

                       <div class="form-group ">

                          <label class="required"> 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 col-sm-12 col-xs-12" style="padding:8px; float:left;"  id="col2">

                       <div class="form-group ">
                        <?php 
                        $Code;
                        if(!isset($_REQUEST['SearchBy'])){
                                    
                                  }else { $Code=$_REQUEST['SearchBy']; }
                        ?>
                          <label class="required"> Search By</label>
                          <select id="SearchBy" required name="SearchBy" class="form-control">

                          <option value="">Select</option>
                          <option <?php if($Code=="Paid"){echo "Selected";} ?> value="1">Paid</option>
                          <option <?php if($Code=="Unpaid"){echo "Selected";} ?> value="0">Unpaid</option>         
                                                              
                                                
                          </select>
                       
                          </div>
                  </div> -->
                  
                  
                  <div class="col-md-1 " style="padding:8px;">
                <div class="form-group ">
                   <input type="hidden" name="addaccountAdmin" value="1">
                <button type="submit" class="btn btn-primary" style="margin-top: 24px;">Search</button>
                </div>
              </div> 
              
               
        </div>            
 </form>
    <br>

<?php  if(!isset($_GET['month'])){?>


      <div class="alert alert-danger col-md-12" id="msg">
       <a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>
        <strong>Caution!</strong> Please select Cell/Family Code and click search!!!
      </div>

    <?php  } ?>


<div style="">

  
<h3>Family Report Unpaid List</h3>
<table id="listofstudents" class="table table-striped table-bordered" style="width:100%">
 
        <thead>
            <tr>
              
                <th width="1%">S.No</th>
                <th width="10%">Father Name</th>
                <th width="8%">Students Name</th> 
                <th width="8%">Cell No</th>              
                <th width="10%">Total</th>
                <th width="10%">Received</th>
                <th width="10%">Remaining</th>
                                
            </tr>
        </thead>
        <tbody>


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

  $m->where("Month_Id", $_REQUEST['month']);
  $months=$m->get("eduportal_month_config");

  $cell=$WorkAssignListVal['cell_no'];

  $sqll = " select std.* from  edu_student_details as std where std.status='0' AND std.branch_id='$branch' And std.cell_no='$cell'";
  //print_r($sqll);
  $studentDatas = $m->query($sqll);

  
  $sessionID=$_REQUEST['session'];
  $qr="SELECT SUM(fee.tutionfee) as tution,SUM(fee.transportfee) as trans,SUM(fee.total_fine) as fine, SUM(fee.disc_amount) as disc, SUM(fee.balance) as balance,SUM(fee.misc_fee) as misc,SUM(fee.collected_amount) as received,SUM(fee.paid_again_amount) as againreceived FROM eduportal_monthly_challan as fee, edu_student_details as std WHERE fee.branch_id='$branch' and std.status='0' and fee.month_id='$month' and std.session_id='$sessionID' and std.student_id=fee.student_id AND std.cell_no='$cell'";
//print_r($qr);
  $details = $m->query($qr);

  foreach ($studentDatas as $studentIds) {
    
    $stdID=$studentIds['student_id'];

    $qr1="SELECT * FROM eduportal_monthly_challan WHERE branch_id='$branch' and month_id='$month' and session_id='$sessionID' and student_id='$stdID'";
//print_r($qr1);
  $monthlChallan = $m->query($qr1);


   $adm=getFeeOfOtherParameter($studentIds['student_id'],$monthlChallan[0]['challan_id'],1,$m);
  $papr=getFeeOfOtherParameter($studentIds['student_id'],$monthlChallan[0]['challan_id'],2,$m);
  $misc=getFeeOfOtherParameter($studentIds['student_id'],$monthlChallan[0]['challan_id'],3,$m);
  $stati=getFeeOfOtherParameter($studentIds['student_id'],$monthlChallan[0]['challan_id'],4,$m);
  $oth=getFeeOfOtherParameter($studentIds['student_id'],$monthlChallan[0]['challan_id'],5,$m);
  $reg=getFeeOfOtherParameter($studentIds['student_id'],$monthlChallan[0]['challan_id'],6,$m);
  $sec=getFeeOfOtherParameter($studentIds['student_id'],$monthlChallan[0]['challan_id'],7,$m);
  $anual=getFeeOfOtherParameter($studentIds['student_id'],$monthlChallan[0]['challan_id'],8,$m);

$other_totals=$adm+$papr+$misc+$stati+$oth+$reg+$sec+$anual;

  }

  



  

$payableAmount=$details[0]['tution']+$details[0]['trans']+$details[0]['fine']+$details[0]['balance']+$details[0]['misc']+$other_totals-$details[0]['disc'];

$totalReceived=$details[0]['received']+$details[0]['againreceived'];

$remaningAmount=$payableAmount-$totalReceived;


  
  if ($remaningAmount==0) {
    
  continue;
}



     
      ?>

        <tr>

          <td style="text-align:center; padding: 2px;"><?php echo $count++;?></td>
          <td><a href="pay_fee.php?student=<?php echo $WorkAssignListVal['student_id'];?>"><?php echo $WorkAssignListVal['last_name'];?></a></td>
          <td><?php foreach ($studentDatas as $studentData) {
            echo $studentData['first_name'].",";  } ?></td>      
          <td><?php echo $WorkAssignListVal['cell_no'];?></td>
          <td><?php echo $payableAmount;?></td>
          <td><?php echo $totalReceived;?></td>
          <td><?php echo $remaningAmount;?></td>

        </tr>

              <?php
      }  ?>
 
        </tbody>
        
    </table>

  </div>



    <br><br>


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

        </div> 
        </div>


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


     
        <!-- /page content -->


 <!-- jQuery -->
  <script src="js/ajax_functions.js"></script>
  <?php include('RootMe/js_linksscript.php');?> 
  <!-- Links for Datatable-->

 <script src="https://cdn.datatables.net/1.10.13/js/jquery.dataTables.min.js"></script>
 <script>
        
  $(document).ready(function() {
    $('#listofstudents').DataTable({
      "pageLength": 100
    });
    } 
  );

   $("#checkAll").change(function () {

      $("input:checkbox").prop('checked', $(this).prop("checked"));
  });

 </script>
  
  </body>
</html>
