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

<?php


     $branch=$_SESSION['branch'];
     
     $classes = $m->query("select * from edu_class_config where branch_id=".$branch." order by class_id asc limit 1");
     // print_r($classes);    


   $session;

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

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


     /* code for advance Search*/


$sql = "SELECT * FROM  eduportal_challan_fee_settlement  WHERE branch_id='$branch' ";

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

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

    }       

     }

    //   if($_REQUEST['settlement_no']==""){
    //   $sql;
    // } else {
    // $sql .= " AND settellment_no = '" .$_REQUEST['settlement_no']. "' ";

    // }

     if($_REQUEST['fee_heads']=="All"){
    $sql;
     } else {
     $sql .= " AND feetypeid = '" .$_REQUEST['fee_heads']. "' ";

     }


    if($_REQUEST['settledBy']=="All"){
    $sql;
    } else {
    $sql .= " AND user_id = '" .$_REQUEST['settledBy']. "' ";
    }
    
      if($_REQUEST['from']!=" " && $_REQUEST['from']!=NULL ) {
        $from=date("Y-m-d",strtotime($_REQUEST['from']));  

      }else {
        $from=date("Y-m-01");  
      }
     
      if($_REQUEST['to']!=" " && $_REQUEST['to']!=NULL   ) {
        $to=date("Y-m-d",strtotime($_REQUEST['to']));
      }else {
        $to=date("Y-m-t");  
      } 
      
    
    $sql .= " AND settellment_date BETWEEN '" .$from. "' AND '" .$to. "'";


     
            if($_REQUEST['orderBy']=='GradeWise'){

            $sql .= "order by CAST(class_id as UNSIGNED) asc";

            }



            if($_REQUEST['orderBy']=='SettlWise'){

            $sql .= "order by CAST(settellment_no as UNSIGNED) asc";

            }



            if($_REQUEST['orderBy']=='UserWise'){

           // $sql .= "order by CAST(user_id as UNSIGNED) asc";
            $sql .= " ORDER BY CAST(user_id AS UNSIGNED) ASC, CAST(settellment_no AS UNSIGNED) ASC";


            }

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

 

 ?>

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


<link href="https://cdn.datatables.net/1.10.25/css/dataTables.bootstrap4.min.css" rel="stylesheet">
  </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;">
  
   <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; 
          
      Settlement Report

      <br><br>

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



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



      <form class="" action="settlement_reports.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="getsec(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"> 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 col-xs-12" style="padding:8px;" >

                       <div class="form-group ">

                          <label class=""> Settlement Number</label>
                             <input name="settlement_no" id="settlement_no" value="<?php echo $_REQUEST['settlement_no'];?>" type="number" class="form-control"  >
                       
                       </div>
                  </div> -->


                   <div class="col-md-2 col-xs-12" style="padding: 8px;">
                <div class="form-group ">
                  <label class="required">Heads</label>

            
                    <select name="fee_heads" class="form-control" >
                     <option value="All">All</option> 
                    <?php
                  
                    $fee_types = $m->get("eduportal_fee_types");
                    foreach($fee_types as $type)
                    { 

                    $query11="SELECT * FROM eduportal_manage_fee_heads_details WHERE  branch_id='$branch' and fee_head_id=".$type['feetype_id'];

                    $feeHeads = $m->query($query11);

                        ?>

                       <option <?php if($_REQUEST['fee_heads']==$type['feetype_id']){echo 'selected';}?> value="<?php echo $type['feetype_id']; ?>"><?php if ($feeHeads[0]['fee_head_title']!=NULL){echo $feeHeads[0]['fee_head_title'];}else {echo $type['feetype_name'];} ?></option>


                            <?php
                    } ?>

                    </select>

                  
                </div>
              </div>


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

       <div class="form-group ">

          <label class=""> Order By</label>
        <select name="orderBy" id="orderBy" class="form-control" >
       
       <option <?php if($_REQUEST['orderBy']=='SettlWise'){echo 'selected';}?>  value="SettlWise">Settlement No Wise</option>
       <option <?php if($_REQUEST['orderBy']=='GradeWise'){echo 'selected';}?>  value="GradeWise">Grade Wise</option>
       <option  <?php if($_REQUEST['orderBy']=='UserWise'){echo 'selected';}?> value="UserWise">User Wise</option>
                              
       </select>
       
       </div>
  </div>


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

                       <div class="form-group ">

                          <label class=""> Settled By</label>
                             <select name="settledBy" id="settledBy" class="form-control" >
                       
                       <option  value="All">All</option>              
                        <?php

                    $usrs="SELECT * FROM eduportal_challan_fee_settlement WHERE  branch_id='$branch' group by user_id";
                    $users = $m->query($usrs);

                    foreach($users as $user)

                    { 

                    $m->where("user_id", $user['user_id']);
                    $usrName=$m->get("edu_user_config");
                        ?>
                       <option <?php if($_REQUEST['settledBy']==$usrName[0]['user_id']){echo 'selected';}?> value="<?php echo $usrName[0]['user_id']; ?>"><?php echo $usrName[0]['user_fname']; ?></option>
                    <?php  } ?>
                                              
                       </select>
                       
                       </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 href="print_fee_settlement_report_classwise.php?<?php echo session_id().session_id().session_id().session_id().session_id(); ?>&from=<?php echo $from;?>&to=<?php echo $to;?>&class_id=<?php echo $_REQUEST['class_id'];?>&fee_heads=<?php echo $_REQUEST['fee_heads'];?>&orderBy=<?php echo $_REQUEST['orderBy'];?>&settledBy=<?php echo $_REQUEST['settledBy'];?>"style="" class="btn btn-success"target="_blank" > <i class="fa fa-print"></i>&nbsp;&nbsp;Print</a>

      

        </div>

        </div>

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

     
          

<form action="settlement_reports.php" enctype="multipart/form-data" method="post">

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

              
                <th width="3%">S.No</th>
                <th width="3%">Settl#</th>
                <th width="8%" style="text-align:center;">Adm/Roll</th>
                <!-- <th width="8%" style="text-align:center;">Month</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;"> Invc# </th>
                <th width="8%" style="text-align:center;"> Invc Mon </th>
                <th width="8%" style="text-align:center;"> Fee </th>
                <th width="8%" style="text-align:center;"> Settlement<br> Amount </th>
                <th width="8%"> Date/Time</th>                
                <th width="8%"> Settled By</th>
                <th width="8%" style="text-align:center;"> Remarks </th>
          
                                
            </tr>
        </thead>
        <tbody>

     <?php 

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

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

        $m->where("feetype_id", $WorkAssignListVal['feetypeid']);
        $feeTypeName=$m->get("eduportal_fee_types");

        $m->where("user_id", $WorkAssignListVal['user_id']);
        $userName=$m->get("edu_user_config");


        // get Invoice Month
        $c_ids=$WorkAssignListVal['against_challan_id'];
        $getChl = "select from_year_month from eduportal_monthly_challan where challan_id='$c_ids' AND branch_id='$branch' "; 
        $getChlMonth = $m->query($getChl);

        // get student data
        $s_ids=$WorkAssignListVal['student_id'];
        $getStd = "select first_name, last_name, section_id,ref_no,candidate_roll_no from edu_student_details where student_id='$s_ids' AND branch_id='$branch' "; 
        $getStudentData = $m->query($getStd);

        $toMonthYear=explode("-",$WorkAssignListVal['month']);

        $t_settlmnt+=$WorkAssignListVal['settellment_amount'];

      ?>

<tr>
<td><?php echo $count++;?></td>
<td><?php echo $WorkAssignListVal['settellment_no'];?></td>
<td><?php echo $getStudentData[0]['ref_no']."/".$getStudentData[0]['candidate_roll_no'];?></td>
<!-- <td><?php echo $WorkAssignListVal['month']; ?></td> -->
<td><?php echo $getStudentData[0]['first_name'];?></td>
<td><?php echo $getStudentData[0]['last_name'];?></td>
<td><?php echo getClassName($m,$WorkAssignListVal['class_id']);?></td>
<td><?php echo getSectionName($m,$getStudentData[0]['section_id']);?></td>
<td><?php echo $WorkAssignListVal['against_challan_id'];?></td>
<td><?php 
$originalDate = $getChlMonth[0]['from_year_month'];
$formattedDate = date("M-y", strtotime($originalDate));
echo $formattedDate;
?></td>
<td><?php echo $feeTypeName[0]['feetype_name'];?> (<?php echo substr(getMonthName($m,$toMonthYear[1]), 0, 3)."-".$toMonthYear[0];?>)</td>
<td><?php echo $WorkAssignListVal['settellment_amount'];?></td>
<td><?php echo date("d-M-Y", strtotime($WorkAssignListVal['settellment_date']));?> <small><?php echo $WorkAssignListVal['settellment_time']; ?></small></td>

<td><?php echo $userName[0]['user_fname']; ?></td>
<td><?php echo $WorkAssignListVal['settellment_remarks'];?></td>

</tr> <?php   } ?>

<!-- <tr style="background-color: #042954; color: white;">
    <td style="color:#042954;" ><?php echo $count+1;?></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td>Total</td>
    <td><?php echo $t_settlmnt;?></td>
    <td></td>
    <td></td>
    <td></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>
