<?php

 require_once("includes/initialize.php");  


session_start();

 $alldept = ONLINEPAY::showdept();

// date_default_timezone_set('Africa/Lagos');
// $dprepare ="";
// $allsession = ONLINEPAY::showsession();

 $tag = $_GET['type'];
$_SESSION['type'] =$tag;







 $output=''; $output2='';$prog='';



 if (isset($_POST['getpayment']))
 {
     
     $start_date = date('Y-m-d', strtotime($_POST['datefrom']));
  $end_date = date('Y-m-d', strtotime($_POST['dateto']));
  $level = $_POST['lev'];
   $prog = $_POST['prog'];
   
   if (($prog=='ft') && ($level=='ND')){
       $prog='PU';
   }else if (($prog=='ft') && ($level=='HND')){
        $prog='FT';
   }else {
       $prog="DP";
   }
   $session = $_POST['sess'];
 

 
  
    
  
  
 
  $_SESSION['prog']= $prog;
  $_SESSION['lev']= $level;
  $_SESSION['sess']= $session;
  
  $_SESSION['start']= $start_date;
  $_SESSION['end']= $end_date;
  
  
 $count = 0; $total_sum=0; $brief='';
 
     $allacceptance= ONLINEPAY::countacceptance('acceptance_tranzact',$start_date, $end_date, $prog, $level, $session);
    
     $allschoolfees= ONLINEPAY::countschoolfees('schoolfees_tranzact',$start_date, $end_date, $prog, $level, $session);
    
      $allcertificate= ONLINEPAY::countcertificate('certificate_tranzact',$start_date, $end_date, $prog, $level, $session);
    
  $brief='All Payment Report From '.$start_date .' To '. $end_date;
   
    
 }else if (isset($_POST['submitall'])){
     
   $start_date = date('Y-m-d', strtotime($_POST['datefrom']));
   $end_date = date('Y-m-d', strtotime($_POST['dateto']));
  
   $session = $_POST['sess'];
   
   
  $_SESSION['start']= $start_date;
  $_SESSION['end']= $end_date;
  $_SESSION['sess']= $session;
   
 $count = 0; $total_sum=0; $brief='';
 
    $allacceptance= ONLINEPAY::countacceptance('acceptance_tranzact',$start_date, $end_date, $session);
    
    $allschoolfees= ONLINEPAY::countschoolfees('schoolfees_tranzact',$start_date, $end_date, $session);
    
     $allcertificate= ONLINEPAY::countcertificate('certificate_tranzact',$start_date, $end_date, $session);
   
    $brief='All Payment Report Between '.$start_date .' To '. $end_date;
    

 }
  $output ='<h3><center>'.ucwords($brief).' </center></h3>';
  
 $output.= ' <table id="bursar" class="table table-striped table-bordered">
             <thead>
                                     <tr>
                                     <th>S/N</th>  
                                         <th>PAYMENT TYPE</th>  
                                         <th>NUMBER OF STUDENTS</th>
                                         <th>TOTAL AMOUNT</th>     
                                         <th>GROUND TOTAL</th> 
                                        
                                     </tr>
                                 </thead>
         ';


 if (isset($allacceptance) && isset($allschoolfees) && isset($allcertificate)){
    
                        
                     $output .='<tr>'
 							.'<td>'.++$count.'</td>'
 							.'<td>'.'Acceptance'.'</td>'
 							.'<td>'.$allacceptance->allAc.'</td>'
 							.'<td>'.$allacceptance->sumAc.'</td>'
 							.'<td>'.'---'.'</td>'
 							
 						.'</tr>'; 
 						
 						
 				   $output .='<tr>'
 							.'<td>'.++$count.'</td>'
 							.'<td>'.'School Fees'.'</td>'
 							.'<td>'.$allschoolfees->allSchl.'</td>'
 							.'<td>'.$allschoolfees->sumSchl.'</td>'
 							.'<td>'.'---'.'</td>'
 							
 						.'</tr>'; 
 						
 						
 						 $output .='<tr>'
 							.'<td>'.++$count.'</td>'
 							.'<td>'.'School Fees'.'</td>'
 							.'<td>'.$allcertificate->allCr.'</td>'
 							.'<td>'.$allcertificate->sumCr.'</td>'
 							.'<td>'.'---'.'</td>'
 							
 						.'</tr>'; 
 						
 						
 						
 						$output .='<tr>'
 							.'<td>'.++$count.'</td>'
 							.'<td colspan="3">'.'Ground Total'.'</td>'
 							
 							.'<td>'.($allacceptance->sumAc+ $allschoolfees->sumSchl +$allcertificate->sumCr).'</td>'
 							
 						.'</tr>'; 
 						
                   
                     
                                     
                 $output.='</table>';
                
                
 } else {
   $output= "<center><h4>No record to display</h4></center>";
   
 }

              
?>

<!--<head>-->
 
  
            <script src="javascripts/jquery.min.js"></script>  
           <link rel="stylesheet" href="javascripts/bootstrap.min.css" />  
           <script src="javascripts/jquery.dataTables.min.js"></script>  
           <script src="javascripts/dataTables.bootstrap.min.js"></script>
           
           <!--<body>-->
   
  
  
  
  <script>

  $( function() {
      $( "#datefrom" ).datepicker();
      $( "#dateto" ).datepicker();
      
      $( "#datefrom2" ).datepicker();
      $( "#dateto2" ).datepicker();
     
  } );
</script>           
             
   
  
 
   <!--<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />-->
   <!--     <link rel="stylesheet" href="https://cdn.datatables.net/1.10.12/css/dataTables.bootstrap.min.css" />-->
   <!-- <link rel="stylesheet" href="https://cdn.datatables.net/1.10.19/css/jquery.dataTables.min.css"/>-->
   <!-- <link rel="stylesheet" href="https://cdn.datatables.net/buttons/1.5.2/css/buttons.dataTables.min.css"/>-->
<!--</head>-->
    <!--<body>       -->
		<!--<div class="container" align="center">-->
		       	
	<!--<div class="container" style="position:relative;">-->
<form method="post"  id="insert_data" style="margin-top:0">
   
    <table class="table table-bordered table-hover" align="center">
        <tr>
<div style="margin-top:0px; border-bottom:1px inset #000">
<td>

<input type="text" autocomplete="off" name="datefrom"  id="datefrom"  style="width:100%" placeholder="Date from">
        
</td>


<td>

<input type="text" autocomplete="off" name="dateto"  id="dateto"  style="width:100%" placeholder="Date to">
        
</td>



<td>
<select name="pro" class="pro" style="width:100%">
            <option value="">PROGRAMME...</option>
            <option value="ft">FULL TIME</option>
             <option value="dp">DAILY PART TIME</option>
              
        </select>

</td>
<td>

<select name="leve" class="lev" style="width:100%">
            <option value="">LEVEL...</option>
            <option value="ND I">ND I</option>
             <option value="ND II">ND II</option>
              <option value="HND I">HND I</option>
             <option value="HND II">HND II</option>
        </select>
</td>

<td>


<select name="session" class="sess" style="width:100%">
            <option value="">SESSION...</option>
               
               <?php foreach($allsession as $sess){?>
            <option value="<?php echo $sess->session?>"><?php echo $sess->session?></option>
            <?php }?>
            
        </select>
</td>

<td>
  
      
        <div class="col-md-12">
    <input type="submit" name="getpayment" id="search" value="Show payments" class="btn btn-info" />
</div>
</td>
</tr>

<tr>
    
    <td colspan="7" style="border-bottom-width: 3px; border-bottom-style:inset; border-bottom-color: #green; font-weight:bolder; Text-align:center">For All Payments Display Only</td>
</tr>
       
 
 <tr>       
<div style="margin-top:0px; border-bottom:1px inset #000">
<td>
<input type="text" autocomplete="off" name="datefrom2"  id="datefrom2" style="width:100%" placeholder="Date from">
        
</td>


<td>

<input type="text" autocomplete="off" name="dateto2"  id="dateto2" style="width:100%" placeholder="Date to">
        
</td>
 
 
 <td>
     
     

<select name="session" class="sess" style="width:100%">
            <option value="">SESSION...</option>
               
               <?php foreach($allsession as $sess){?>
            <option value="<?php echo $sess->session?>"><?php echo $sess->session?></option>
            <?php }?>
            
        </select>
</td>
   
   
   <td>
      <div class="col-md-12">
    <input type="submit" name="submitall" id="search" value="All Payment" class="btn btn-info" />
        </div> 
       
   </td>
   
   <td colspan="2">
       
        <div class="col-md-12">
        <input type="submit" name="Print_pdf" id="Print_pdf" class="btn btn-danger" value="Print PDF" />
    </div>
      
   </td>
</tr>



</table>
</form>

 <div id="bursar" style="width:100%; height:550px; overflow:scroll; background-color:; margin-left:3px ">
 
 <?php
 if (isset($output)){
 
    echo $output;
 
 }
?>                  
</div>



</body>

                               

 
 <!--<script src="../javascripts/jquery.min.js"></script>        -->
<!--<script src="../javascripts/bootstrap.min.js" type="text/javascript"></script>-->



                               

 
 
  
<script type="text/javascript">


var ptype = <?php echo json_encode($tag);?>;

alert(ptype);
$(document).ready(function() {
  
  /*
    //e.preventdefault(e);
// 	$('#bursar').DataTable();
	$('#fac').on('change', function(){
	//	alert($('#fac').val());
	if($('#fac').val() != '')
		{
			var fac = $(this).val();
			//alert("value" + faculty);
			$('#depart').attr('disabled', 'disabled');
		}else {
		$('#depart').attr('disabled', 'false');
	}
		 
	})
	
	$('#depart').on('change', function(){
	    //e.preventdefault(e);
	//	alert($('#fac').val());
	if($('#depart').val() != '')
		{
			var dpt = $(this).val();
			//alert("value" + faculty);
			$('#fac').attr('disabled', 'disabled');
		}else {
		$('#depart').attr('disabled', 'false');
	}
		 
	})
	
// 	$('.input-daterange').datepicker({
//   todayBtn:'linked',
//   format: "yyyy-mm-dd",
//   autoclose: true
//  });

	 
$('#search').on('click', function(e){
    e.preventDefault(e);
    var fac= $('#fac').val();
    var dpt =$('#depart').val();
    var lev = $('#lev').val();
    var ses = $('#sess').val();
    var prog = $('#prog').val();
    var view = $('#view').val();
    	alert(ptype);
    alert(fac);
    alert(dpt);
    alert(lev);
    alert(ses);
    alert(ses);
    
		
        $.ajax({                    
            method:"POST",
			url: "fetch_details.php",
            data:{ptye:ptype,fac:fac,dpt:dpt,lev:lev,ses:ses,prog:prog,view:view},
            success:function(data)
            {
				alert(data);
               $('#bursar').html(data);
            }
        })
    });
    
    $('#search').on("click", function(e){
    e.preventDefault(e);
    
    var fac= $('#fac').val();
    var dpt =$('#depart').val();
    var lev = $('#lev').val();
    var ses = $('#sess').val();
    var prog = $('#prog').val();
    var start = $('#start_date').datepicker();
    var end = $('#end_date').datepicker();
    
    alert(ptype);
    alert(fac);
    alert(dpt);
    alert(lev);
    alert(ses);
   
    
        {
            $.ajax({
            	url:"fetch_details.php",
            	method:"POST",
            	data:{fac:fac,ptype:ptype,dpt:dpt,lev:lev,ses:ses,prog:prog,start:start,end:end},
            	success:function(data)
            	{
            	    alert(data);
            		$('#bursar').html(data);
            	}
            });
        }
 });*/
 
 
 $('#Print_pdf').on("click", function(e){
    e.preventDefault(e);
        {
    		window.open("bursary_report.php");
        }
 });
    
    
    
    
    
});

</script>