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

<?php


     $branch=$_SESSION['branch'];
     
     
   $session;

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

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


     /* code for advance Search*/


// $sql = "SELECT receipt_no,branch_id,against_challan_id,received,paid_by,paid_date,paid_time,paid_user_id,student_id FROM  eduportal_challan_fee_receiving  WHERE branch_id='$branch' ";

$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, ecrf.paid_by, ecrf.paid_time, ecrf.paid_user_id, ecrf.student_id, ecrf.month, ecrf.year, ecrf.challan_id
FROM edu_student_details AS esd
INNER JOIN eduportal_challan_fee_receiving AS ecrf ON esd.student_id = ecrf.student_id
WHERE ecrf.branch_id = '$branch'";
   
   
    if (isset($_REQUEST['PiadBy'])) { 

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

     }

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

} // end isset

    
    
      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");  
      } 
      
    if ($_REQUEST['searchBy']!="All") {
        $sql .= " AND ecrf.paid_date BETWEEN '" .$from. "' AND '" .$to. "'";
    }    

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

        if (!isset($_REQUEST['orderBy'])) {
        $sql .= "ORDER BY CAST(ecrf.receipt_no AS UNSIGNED) DESC ";
        }

        if ($_REQUEST['orderBy'] == 'RecptWise') {
        $sql .= "ORDER BY CAST(ecrf.receipt_no AS UNSIGNED) ASC ";
        }

        if ($_REQUEST['orderBy'] == 'UserWise') {
        $sql .= "ORDER BY CAST(ecrf.paid_user_id AS UNSIGNED) ASC, CAST(ecrf.receipt_no AS UNSIGNED) ASC ";
        }

        if ($_REQUEST['orderBy'] == 'GradeWise') {
        $sql .= "ORDER BY CAST(esd.class_id AS UNSIGNED), CAST(esd.section_id AS UNSIGNED), CAST(ecrf.receipt_no AS UNSIGNED) ASC";
        }
  
//echo $sql;
  $WorkAssignListings = $m->query($sql);

 

 ?>

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


 <link href="https://cdn.datatables.net/1.10.25/css/dataTables.bootstrap4.min.css" rel="stylesheet">
    <!-- <link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet"> -->



  <!--  -->

  </head>
  <script type="text/javascript">

function HideDate(str){
  
  if(str=="All"){
    
    document.getElementById("from1").style.display="none";
    document.getElementById("to1").style.display="none";
   
  }
  else {
    
    document.getElementById("from1").style.display="block";
    document.getElementById("to1").style.display="block";
   
   
  }
}

  </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 Receipt 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_receipt_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="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=""> Search By</label>
            <select name="searchBy" id="searchBy" onChange="HideDate(this.value);" class="form-control" >

            <option <?php if($_REQUEST['searchBy']=='dateWise'){echo 'selected';}?>  value="dateWise">Date Wise</option>
            <option <?php if($_REQUEST['searchBy']=='All'){echo 'selected';}?>  value="All">All</option>        

            </select>

            </div>
            </div>
              


                <div class="col-md-2 col-xs-12" id="from1" 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" id="to1" 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">Received In</label>

            
                    <select name="PiadBy" id="PiadBy" class="form-control" >

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

                    <option value="Cash">Cash</option>

                    <option value="JazzCash">JazzCash</option>

                    <option value="Easypaisa">Easypaisa</option>

                    <option value="BankAccount">Bank Account</option>

                    <option value="UblOmni">Ubl Omni</option>

                    </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']=='RecptWise'){echo 'selected';}?>  value="RecptWise">Receipt 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=""> Received By</label>
                             <select name="userPaid" id="userPaid" class="form-control" >
                       
                       <option  value="All">All</option>              
                        <?php

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

                    foreach($users as $user)

                    { 

                    $m->where("user_id", $user['paid_user_id']);
                    $usrName=$m->get("edu_user_config");
                        ?>
                       <option <?php if($_REQUEST['userPaid']==$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>
        <?php if (isset($_REQUEST['PiadBy'])) {?>
            
              <a style="" href="print_fee_receipt_report.php?kldjasfihasdfdsfjkdfshenkcihasndfnsadcihasdnfsandchsdcaksfnoicdh&class_id=<?php echo $_REQUEST['class_id'];?>&from=<?php echo $_REQUEST['from'];?>&to=<?php echo $_REQUEST['to'];?>&PiadBy=<?php echo $_REQUEST['PiadBy'];?>&orderBy=<?php echo $_REQUEST['orderBy'];?>&userPaid=<?php echo $_REQUEST['userPaid'];?>&searchBy=<?php echo $_REQUEST['searchBy'];?>" class="btn btn-primary">Print</a>

        <?php } ?>
        
        
        </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="3%">Rec#</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;"> Invc# </th>
                <th width="8%" style="text-align:center;"> Invc Month </th>
                <th width="8%" style="text-align:center;"> Fee Recv </th>
                <th width="8%" style="text-align:center;"> Fine Recv </th>
                <th width="8%" style="text-align:center;"> Total Recv</th>
                <th width="8%" style="text-align:center;"> Print</th>
                <th width="8%"> Date/Time</th>                
                <th width="8%"> Recv In</th>
                <th width="8%" style="text-align:center;"> Recv By </th>
          
                                
            </tr>
            </thead>
            <tbody>
               <?php 

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

   
        $r_no=$WorkAssignListVal['receipt_no'];
        $s_ids=$WorkAssignListVal['student_id'];
        $sq = "SELECT SUM(CASE WHEN feetypeid = 4 THEN received ELSE 0 END) AS fine, SUM(CASE WHEN feetypeid != 4 THEN received ELSE 0 END) AS recvd FROM  eduportal_challan_fee_receiving  WHERE branch_id='$branch' and receipt_no='$r_no' and student_id='$s_ids' ";        
        $sumAmt = $m->query($sq);

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




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




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




        // $toMonthYear=explode("-",$WorkAssignListVal['month']);
        if (isset($_REQUEST['class_id']) && $_REQUEST['class_id'] === 'All') {

        } else {

        if (isset($_REQUEST['class_id']) && $getStudentData[0]['class_id']!=$_REQUEST['class_id']) {
          continue;
        }

        }

        $totalRec+=$sumAmt[0]['recvd'];
        $totalFin+=$sumAmt[0]['fine'];
      ?>

<tr>
<td><?php echo $count++;?></td>
<td><?php echo $WorkAssignListVal['receipt_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,$getStudentData[0]['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]['challan_created'];
$formattedDate = date("M-Y", strtotime($originalDate));
echo $formattedDate;
?></td>
<td> <?php echo $sumAmt[0]['recvd']; ?> </td>
<td> <?php echo $sumAmt[0]['fine']; ?> </td>

<td>  <?php echo $sumAmt[0]['recvd']+$sumAmt[0]['fine'];  ?> </td>

<td>  

<div class="btn-group">
<button data-toggle="dropdown" style="padding:2px;" 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">

<li><a href="print_single_voucher_paid.php?a61oe8lqc1oclfi4llgnioo156a61oe8lqc1oclfi4llgnioo156a61oe8lqc1oclfi4llgnioo156a61oe8lqc1oclfi4llgnioo156a61oe8lqc1oclfi4llgnioo156&amp;receipt=<?php echo $WorkAssignListVal['receipt_no'];?>&student_id=<?php echo $WorkAssignListVal['student_id'];?>&month_id=<?php echo $WorkAssignListVal['month'];?>&year=<?php echo $WorkAssignListVal['year'];?>&challan=<?php echo $WorkAssignListVal['challan_id'];?>&againstchallan=<?php echo $WorkAssignListVal['against_challan_id'];?>" target="_blank">
Single Receipt
</a></li>

<li><a href="print_double_voucher_paid.php?a61oe8lqc1oclfi4llgnioo156a61oe8lqc1oclfi4llgnioo156a61oe8lqc1oclfi4llgnioo156a61oe8lqc1oclfi4llgnioo156a61oe8lqc1oclfi4llgnioo156&amp;receipt=<?php echo $WorkAssignListVal['receipt_no'];?>&student_id=<?php echo $WorkAssignListVal['student_id'];?>&month_id=<?php echo $WorkAssignListVal['month'];?>&year=<?php echo $WorkAssignListVal['year'];?>&challan=<?php echo $WorkAssignListVal['challan_id'];?>&againstchallan=<?php echo $WorkAssignListVal['against_challan_id'];?>" target="_blank">Double Receipt</a></li>


</ul>
</div>

 </td>

<td><?php echo date("d-M-Y", strtotime($WorkAssignListVal['paid_date']));?> <small><?php echo $WorkAssignListVal['paid_time']; ?></small></td>
<td><?php echo $WorkAssignListVal['paid_by'];?></td>

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


</tr> 

<?php   } ?>
<!-- 
<tr style="background-color: #042954; color: white;">
  <th><?php echo $count+1;?></th>
  <th></th>
  <th></th>
  <th></th>
  <th></th>
  <th></th>
  <th></th>
  <th></th>
  <th>Total</th>
  <th><?php echo $totalRec;?></th>
  <th><?php echo $totalFin;?></th>
  <th><?php echo $totalRec+$totalFin;?></th>
  <th></th>
  <th></th>
  <th></th>
</tr> -->
               
                
            </tbody>
        </table>



  

    <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>
