 <?php
// error_reporting(E_ALL);
// ini_set('display_errors',1);
 require_once("../includes/initialize2.php");

       $start_date=$_POST['start_date'];
       $end_date=$_POST['end_date'];
         $portal=$_POST['portal'];
        // $tag=$_GET['tag'];



    $tag = 'admission_online_payment';

     $portal= $_POST['portal'];
   
  if (($portal=='') OR ($portal=='2')){
   $start_date = date('Y-m-d', strtotime($_POST['start_date']));
   $end_date = date('Y-m-d', strtotime($_POST['end_date']));
  $_SESSION['amount']=$amount='9100.00';

        $allsession = ONLINEPAY2::searchbydate($tag, $amount, $start_date, $end_date);
    
  }else{
      
  }
    

      header("Content-Type: text/csv");
      header("Content-Disposition: attachment; filename=$portal".".csv");
      header("Cache-Control: no-cache, no-store, must-revalidate");
      header("Pragma: no-cache");
      header("Expires: 0");
      ob_end_clean();
      $output = fopen("php://output", "w");
     
    
    
          fputcsv($output, array("","","","","ADMISSION FORM PAYMENT LIST","","","",""));
 
    
     fputcsv($output, array("SN","MATRIC NO","PROGRAMME TYPE","TRANSACTION REF","FULL NAME","DEPARTMENT","LEVEL","AMOUNT","PAYMENT DATE"));
 
 
  $sn=0;$totalamount=0;
    foreach($allsession as $studentdata){
        
             if (isset($portal) AND ($portal==1)){
                        $output='';
                        $output='No record found';
 							    
                        }else if (isset($studentdata->formno)){
                            
                            if ((substr($studentdata->formno,0,2)=='DP') and ($studentdata->level=='ND')) {
		                     $programtype="ND DPT";
		                   
		                   }else if (substr($studentdata->formno,0,2)=='PU'){
		                    $programtype="ND PU";
		                    
		                      
		                    }else if (substr($studentdata->formno,0,2)=='FT'){
		                    $programtype="HND FT";
		                    
		                    }else{
		                       $programtype="HND DPT"; 
		                    }
                            $student_number =$studentdata->formno;
                            $dept=$student->department;
                            
                            
                        }
                        
    
            $sn++;
            $formno = $student_number;
            $transref=$studentdata->txt_ref;
            $surname=strtoupper($studentdata->surname.' '.$studentdata->othernames);
     
            $department=strtoupper($dept);
            $level=strtoupper($studentdata->level);
            $ptype=strtoupper($programtype);
            // $amount=$studentdata->amount;
            $amount=8500;
            $totalamount+=$amount;
            $datetime=$studentdata->datetime;
		    
		  
                          
		    
		 
 
        fputcsv($output,array($sn,$formno,$ptype,$transref,$surname,$department,$level,8500.00,$datetime));
            
    
 }
         fputcsv($output,array('','','','','','','Total Amount',$totalamount,''));
     
//  echo json($output);
  fclose($output);
// }
?>