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

<?php


     $branch=$_SESSION['branch'];

     if (isset($_REQUEST['from'])) {
         
     $from=date("Y-m-d",strtotime($_REQUEST['from'])); 
     $to=date("Y-m-d",strtotime($_REQUEST['to']));

     } else {

     $to=date("Y-m-t"); 
     $from=date("Y-m-01");

     }


   $session;

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

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


     /* code for advance Search*/


$sql = "SELECT esd.student_id, esd.first_name, esd.last_name, esd.class_id, esd.section_id, esd.ref_no, esd.candidate_roll_no, ecrf.branch_id, ecrf.received, ecrf.feetypeid, ecrf.paid_date, ecrf.against_challan_id, ecrf.receipt_no
FROM edu_student_details AS esd
INNER JOIN eduportal_challan_fee_receiving AS ecrf ON esd.student_id = ecrf.student_id
WHERE ecrf.paid_date BETWEEN '$from' AND '$to'
AND ecrf.branch_id = '$branch'";

if (isset($_REQUEST['class_id'])) {
if ($_REQUEST['class_id'] != "All") {
$sql .= " AND esd.class_id = '" . $_REQUEST['class_id'] . "'";
}

if (isset($_REQUEST['section']) && $_REQUEST['section'] != "All") {
$sql .= " AND esd.section_id = '" . $_REQUEST['section'] . "'";
}
}
//$sql .= " GROUP BY esd.student_id, esd.first_name, esd.last_name, esd.class_id, esd.section_id, esd.ref_no, esd.candidate_roll_no, ecrf.branch_id, ecrf.paid_date";

$sql .= " GROUP BY ecrf.receipt_no, esd.student_id ";

$sql .= " ORDER BY esd.class_id, esd.section_id ASC";
//echo $sql;
$WorkAssignListings = $m->query($sql);

 

 ?>

<!DOCTYPE html>
<html lang="en">
  <head>
   
    <title> Fee Collection Report </title>
     <?php include('RootMe/css_links.php');?> 

 <link href="https://cdn.datatables.net/1.10.25/css/dataTables.bootstrap4.min.css" rel="stylesheet">
  </head>
  

 <script type="text/javascript">


function getsecall(str)

{

//alert(str);

   if(str=="")

      alert("Please select any Class");

  else

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

  

  if(window.XMLHttpRequest)

  ajx=new XMLHttpRequest();

  ajx.onreadystatechange = function()

  {



    if(ajx.readyState == 4)

    {

          // alert(ajx.responseText); 

         document.getElementById("txt_section").innerHTML= ajx.responseText;

    }

  }

  ajx.open("GET", "get_section_all.php?class_id="+str);

  ajx.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="row" style="background-color: white;">
  
   <a href="<?php echo $_SESSION['dashboard'];?>">Dashboard </a> &nbsp; <i style="" class="fa fa-angle-double-right"></i>  &nbsp; 
    
     <a href="multi_fee_reports.php">Fee Reports </a> &nbsp; <i style="" class="fa fa-angle-double-right"></i>  &nbsp; 
          
      Fee Collection Report

      <br><br>

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



 <div class="" style="margin-top:10px;">



      <form class="" action="fee_collection_report.php" enctype="multipart/form-data" method="get">
        <div class="panel panel-default">
          <div class="panel-heading"><?php //echo count($WorkAssignListings);?> <!-- 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" />



          </span><div class="clearfix"></div> </div>
          <div class="panel-body">
          
            <div class="col-md-12" id="" style="">
            
              <div class="col-md-2 col-xs-12" style="padding: 8px;">
                <div class="form-group ">
                  <label class="required">Grade</label>

            
                    <select name="class_id" onChange="getsecall(this.value)" class="form-control" >
                     <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-2 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($_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-2 col-xs-12" style="padding:8px;">

                       <div class="form-group ">

                          <label class="required"> From Date</label>
                              <input name="from"  id="from" value="<?php echo $from;?>" type="date" class="form-control"  >
                       
                          </div>
                  </div>                     
             

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

                       <div class="form-group ">

                          <label class="required"> To Date</label>
                             <input name="to" id="to" value="<?php echo $to;?>" type="date" class="form-control"  >
                       
                       </div>
                  </div>


        <div class="col-md-2" style="padding:2px;margin-top: 29px;float: right;">
        <div class="form-group ">
        <input type="hidden" name="addaccountAdmin" value="1">
        <button type="submit" class="btn btn-primary">Search</button>
        <a style="" href="print_fees_collection_report.php?session=d702958bebc5b126fcc2ecba847749b7d702958bebc5b126fcc2ecba847749b7d702958bebc5b126fcc2ecba847749b7d702958bebc5b126fcc2ecba847749b7d702958bebc5b126fcc2ecba847749b7&class_id=<?php echo $_REQUEST['class_id'];?>&section=<?php echo $_REQUEST['section'];?>&from=<?php echo $_REQUEST['from'];?>&to=<?php echo $_REQUEST['to'];?>" class="btn btn-primary">Print</a>

        </div>

        </div>

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

     

 
<table class="table table-bordered table-striped" id="myTable">   
   
        <thead>
            <tr style="background-color: #042954; color: white;">

              
                <th width="3%">S.No</th>               
                <th width="8%" style="text-align:center;">Adm/Roll</th>             
                <th width="8%" style="text-align:center;"> Student Name </th>
                <th width="8%" style="text-align:center;"> Father Name </th>
                <th width="8%" style="text-align:center;"> Grade </th>
                <th width="8%" style="text-align:center;"> Section </th>
                <th width="8%" style="text-align:center;"> Reg.Fee </th>
                <th width="8%" style="text-align:center;"> Adm.Fee </th>
                <th width="8%" style="text-align:center;"> M.Fee </th>
                <th width="8%" style="text-align:center;"> A.fund </th>
                <th width="8%" style="text-align:center;"> Prspct</th>                
                <th width="8%" style="text-align:center;"> Fine</th>
                <th width="8%" style="text-align:center;"> O.Chargs</th>
                <th width="8%" style="text-align:center;"> Total </th>
          
                                
            </tr>
        </thead>
        <tbody>

     <?php 

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

        // if ($WorkAssignListVal['received']==0) {
        //   continue;
        // }

        $c_id=$WorkAssignListVal['against_challan_id'];
        $reeptNo=$WorkAssignListVal['receipt_no'];
        $sq = "SELECT SUM(CASE WHEN feetypeid = 1 THEN received ELSE 0 END) AS monthly, SUM(CASE WHEN feetypeid = 5 THEN received ELSE 0 END) AS Afund, SUM(CASE WHEN feetypeid = 4 THEN received ELSE 0 END) AS Fine, SUM(CASE WHEN feetypeid = 6 THEN received ELSE 0 END) AS Reg, SUM(CASE WHEN feetypeid = 2 THEN received ELSE 0 END) AS Adm, SUM(CASE WHEN feetypeid = 3 THEN received ELSE 0 END) AS prscts, SUM(CASE WHEN feetypeid NOT IN (1, 5, 4, 6, 2, 3) THEN received ELSE 0 END) AS Other FROM  eduportal_challan_fee_receiving  WHERE branch_id='$branch' and against_challan_id='$c_id' and receipt_no='$reeptNo' ";        
        $sumAmt = $m->query($sq);


         $totalRec=$sumAmt[0]['Reg']+$sumAmt[0]['Adm']+$sumAmt[0]['monthly']+$sumAmt[0]['Afund']+$sumAmt[0]['prscts']+$sumAmt[0]['Fine']+$sumAmt[0]['Other'];

     
  $sumAmt[0]['Reg'];
  $t_adm+=$sumAmt[0]['Adm'];
  $t_fee+=$sumAmt[0]['monthly'];
  $t_aFund+=$sumAmt[0]['Afund'];
  $t_prspcts+=$sumAmt[0]['prscts'];
  $t_fine+=$sumAmt[0]['Fine'];
  $t_other+=$sumAmt[0]['Other'];
  $t_recevd+=$sumAmt[0]['Reg']+$sumAmt[0]['Adm']+$sumAmt[0]['monthly']+$sumAmt[0]['Afund']+$sumAmt[0]['prscts']+$sumAmt[0]['Fine']+$sumAmt[0]['Other'];


      ?>

<tr>
<td><?php echo $count++;?></td>
<td><?php echo $WorkAssignListVal['ref_no']."/".$WorkAssignListVal['candidate_roll_no'];?></td>
<td><?php echo $WorkAssignListVal['first_name'];?></td>
<td><?php echo $WorkAssignListVal['last_name'];?></td>
<td><?php echo getClassName($m,$WorkAssignListVal['class_id']);?></td>
<td><?php echo getSectionName($m,$WorkAssignListVal['section_id']);?></td>

<td><?php echo $sumAmt[0]['Reg'] ?></td>
<td><?php echo $sumAmt[0]['Adm']; ?></td>
<td><?php echo $sumAmt[0]['monthly']; ?></td>
<td><?php echo $sumAmt[0]['Afund']; ?></td>
<td><?php echo $sumAmt[0]['prscts']; ?></td>
<td><?php echo $sumAmt[0]['Fine']; ?></td>
<td><?php echo $sumAmt[0]['Other']; ?></td>

<td><?php echo $totalRec;?></td>


</tr> <?php  } ?>

<!-- <tr>
  <td></td>
  <td colspan="5">Total</td>
  <td><?php echo $t_reg;?></td>
  <td><?php echo $t_adm;?></td>
  <td><?php echo $t_fee;?></td>
  <td><?php echo $t_aFund;?></td>
  <td><?php echo $t_prspcts;?></td>
  <td><?php echo $t_fine;?></td>
  <td><?php echo $t_other;?></td>
  <td><?php echo $t_recevd;?></td>
 
</tr> -->
 
        </tbody>
        
    </table>

  </div>

    </form>

    <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');?> 
    <!-- <script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script> -->
    <script src="https://cdn.datatables.net/1.10.25/js/jquery.dataTables.min.js"></script>
    <script src="https://cdn.datatables.net/1.10.25/js/dataTables.bootstrap4.min.js"></script>
    <script src="https://cdn.datatables.net/buttons/1.7.1/js/dataTables.buttons.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.1.3/jszip.min.js"></script>
    <script src="https://cdn.datatables.net/buttons/1.7.1/js/buttons.html5.min.js"></script>
    <script src="https://cdn.datatables.net/buttons/1.7.1/js/buttons.print.min.js"></script>

    <link rel="stylesheet" href="https://cdn.datatables.net/buttons/1.7.1/css/buttons.bootstrap4.min.css">

    <script>
        $(document).ready(function() {
            var table = $('#myTable').DataTable({
                dom: 'Bfrtip',
                buttons: [
                    'excel'
                ]
            });
        });
    </script>
  
  </body>
</html>
