<?php
 //error_reporting();
// set_time_limit(105000000);

require_once("includes/initialize2.php");

session_start();

$alldept = ONLINEPAY2::showdept();

//print_r($alldept);

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

$tag = $_GET['type'];
if ($tag=='screening_tranzact'){
    $tag = 'admission_online_payment';
}
$_SESSION['tablename'] =$tag;







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


// //if(isset($_POST['fac']) || ($_POST['dpt']))
 if (isset($_POST['search']))
 {
 $fac =$_POST['fac'];
 $dept = $_POST['depart'];
 $session = $_POST['sess'];
 $level = $_POST['lev'];
 //$_SESSION['amount']=array();
 $_SESSION['amount']= $amount='2500';
//  $view = $_POST['view'];
  $prog = $_POST['prog'];
  
  $start_date = date('Y-m-d', strtotime($_POST['start_date']));
  $end_date = date('Y-m-d', strtotime($_POST['end_date']));
  
  
  $_SESSION['fac']= $fac;
  $_SESSION['dept']= $dept;
  $_SESSION['sess']= $session;
  $_SESSION['lev']= $level;
  $_SESSION['view']= $view;
  $_SESSION['prog']= $prog;
  $_SESSION['start']= $start_date;
 $_SESSION['end']= $end_date;
  
 $table = $_POST['ptype'];
   
  
 $count = 0; $total_sum=0; $brief='';
 if (isset($dept) && ($dept=='all')){
     $allsession= ONLINEPAY2::allfee($tag,$amount);
    $brief=$dept.' Departments';
 
    
 }else if ($fac !=''){
     
      $allsession= ONLINEPAY2::showsessionfaculty($tag, $fac, $level, $session);
    $brief='Faculty of '. $fac;
 
     
 }else if (($prog!='') && ($level !='') && ($session!='')){
 
 $allsession= ONLINEPAY2::showsessionprog($tag, $prog, $level, $session);
 if (($prog=='PU') OR ($prog=='FT')){
     $dept='Full Time';
     
 }else if ($prog=='DP'){
  $dept='Daily Part Time';
 
 }
 $brief=$dept.' Payments';
 
 }else if (($prog !='') && ($level !='')){
    
    //  $table = $_SESSION['tablename'];
    //  $prog = $_POST['prog'];
    //  $level = $_POST['lev'];
      $allsession= ONLINEPAY2::searchbyprogramme($tag, $prog, $level);
      
      $brief='All '.$prog.' Payments';
 }
 else if ((isset($start_date) && $start_date !='') AND (isset($end_date) && ($end_date !=''))){
 
 $allsession= ONLINEPAY2::searchbydate($tag, $amount, $start_date, $end_date);
 $brief='Between '.$start_date .' AND '.$end_date;
 }
 
 
 else{
 
 $allsession= ONLINEPAY2::showsessiondetails($tag, $dept, $level, $session);
 $brief=$dept.' Department';
 }
 //print_r($allsession);
 $output= ' <table id="bursar" class="table table-striped table-bordered">
             <thead>
                                     <tr>
                                     <th>S/N</th>  
                                         <th>MATRIC NO</th>  
                                         <th>TRAN. REF</th>
                                         <th>SURNAME</th>     
                                         <th>OTHER NAME</th> 
                                         
                                         <th>DEPARTMENT</th>
                                         <th>LEVEL</th> 
                                         <th>DESCR</th>  
                                         <th>AMOUNT</th>
                                         <th>DATE/TIME</th>                         
                                     </tr>
                                 </thead>
         ';


if (isset($allsession)){
 foreach ($allsession as $student){
    
                        if (isset($student->department)){
                            $dept = $student->department;
                        }
                        $total_sum += $student->amount;
                     $output .='<tr>'
 							.'<td>'.++$count.'</td>'
 							.'<td>'.$student->formno.'</td>'
 							.'<td>'.$student->txt_ref.'</td>'
 							.'<td>'.strtoupper($student->surname).'</td>'
 							.'<td>'.strtoupper($student->othernames).'</td>'
 							.'<td>'.strtoupper($dept).'</td>'
 							.'<td>'.$student->level.'</td>'
 							.'<td>'.$student->status.'</td>'
 							.'<td>'.$student->amount.'</td>'
 							.'<td>'.$student->datetime.'</td>'
 						.'</tr>'; 
                     } 
}
                     $output .='<tr><td colspan="10"><center><h3>Brief Summary: '.ucwords($brief).' </h3></center></td></tr>';
                    $output .=' <tr>
                                     <td colspan="3">Total Number of Students</td> <td colspan="2">'.$count.'</td> 
                                         <th colspan="3">Total receivable</th>  <td colspan="2">'.$total_sum.'</td>
                                                                  
                                     </tr>';
                 $output.='</table>';
                
                
 } else {
   $output= "<center><h4>No record to display</h4></center>";
   
 }

        // $output2 = '<h3>'.'Brief Summary'.'</h3>';
        //  $output2.= ' <table id="summary" class="table table-striped table-bordered">
        //      <thead>
                                     
        //                          </thead>
        //  ';

 
    
  
        //              $output2 .='<tr>'
 							// .'<td>'.$count.'</td>'
 							// .'<td>'.$total_sum.'</td>'
 							
 					  //  	.'</tr>'; 
        //              //} 
        //          $output2.='</table>';
                echo $output2;
                
//  } else {
//   $output= "No record to display";
   
//  }
        
?>


 
  <!--        <head>-->
  <!--           <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>--> 
  <!--         <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />  -->
  <!--         <script src="https://cdn.datatables.net/1.10.12/js/jquery.dataTables.min.js"></script>  -->
  <!--         <script src="https://cdn.datatables.net/1.10.12/js/dataTables.bootstrap.min.js"></script> -->
  <!--         <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.6.4/css/bootstrap-datepicker.css" />-->
  <!--      <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.6.4/js/bootstrap-datepicker.js"></script>-->
  <!--</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() {
      $( "#start_date" ).datepicker();
      $( "#end_date" ).datepicker();
     
  } );
</script>           
             
   
       
           
		<!--<div class="container" style="position:relative;">-->
<form method="POST"  id="insert_data" style="margin-top:0">
    <!--<div class="form-group input-group" align="Right">-->
    <table class="table table-bordered table-hover" align="center">
        <tr>
<div style="margin-top:0px; border-bottom:1px inset #000">
<!--<td>-->
<!--<label style="margin-left:10px">Faculty</label>-->

<!--<select id="fac" name="fac" style="width:100px" >-->
<!--<option value="">Choose...</option>-->
<!--<option value="Business and Management Sciences">Business and Management Sciences</option>-->
<!--<option value="Environmental Studies">Environmental Studies</option>-->
<!--<option value="Applied Sciences">Applied Sciences</option>-->
<!--<option value="Engineering">Engineering</option>-->
<!--<option value="Information Communication and Technology">Information Communication and Technology</option>-->
<!--</select>-->
<!--</td>-->
<td>
<label style="margin-left:20px" >Department</label>
<select id="depart" name="depart" style="width:100px">
<option value="">Choose...</option>
<option value="all">All departments</option>
<?php foreach($alldept as $dept){?>
<option value="<?php echo $dept->dept;?>"><?php 
$dprepare= strtolower($dept->dept);
echo ucwords($dprepare);?></option>
<?php }?>
</select>
</td>
<td>
<label style="margin-left:20px" >Session</label>
<select id="sess" name="sess"  style="width:100px" >
<option value="">Choose...</option>
           <option value"2020/2021">2020/2021</option>
</select>
</td>

<td>
<label style="margin-left:20px">Programme</label>

<select id="prog" name="prog" style="width:100px" >
<option value="">Choose...</option>
<option value="DP">Daily Part-Time</option>
<option value="FT">Full-Time</option>
<option value="PU">Post UTME</option>
</select>
</td>

<td>
<label  style="margin-left:20px" >Level</label>
<select id="lev" name="lev">
<option value="">Choose...</option>
<option value="ND">ND I</option>
<!--<option value="ndii">ND II</option>-->
<option value="HND">HND I</option>
<!--<option value="hndii">HND II</option>-->
</select>
</td>
<td>
<!--<div class="input-daterange">-->

<div><label  style="margin-left:10px" >Start Date</label></div>
<div class="col-md-12">
    <input type="text"  autocomplete="off" name="start_date" id="start_date" style="width:100%" placeholder="StartDate"/>
</div>
</td>


<td>
<div><label  style="margin-left:10px" >End Date</label></div>
<div class="col-md-12">
    <input type="text" autocomplete="off" name="end_date" id="end_date" style="width:100%"   placeholder="EndDate"/>
</div>


</td>


<td>
    <div><label  style="margin-left:20px" >Action</label></div>
<div class="col-md-12">
    <input type="submit" name="search" id ="search" value="Search" class="btn btn-info" />
</div>
</td>

<td>
    <div><label  style="margin-left:20px" >Action</label></div>
   <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:500px; overflow:scroll; background-color:; margin-left:3px ">
 
 <?php
 if (isset($output)){
 
    echo $output;
 
 }
?>                  
</div>

<div id="summary" style="width:100%; height:40px; background-color:; margin-left:3px ">
                        
        <?php
 if (isset($output2)){
 
    echo $output2;
 
 }
?>                  
                  
</div>
</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);?>;

$(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
//  });

	 
$('#btn').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_report2.php");
        }
 });
    
    
    
    
    
});

</script>