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

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


 if (($start_date !='') AND ($end_date !='')){
 
 if ($portal==1){
   
    require_once("../includes/initialize4.php");
      global $database;
     $tag="tranzact_t";
    //  $portal']=$portal;
    
   
    
      $allsession= ONLINEPAY::searchbydateportal1($tag, $start_date, $end_date);
     
     
 }else{
     
     $portal=2;
     
     $tag = $_POST['tag'];
    

    //  echo "From Excel Page". $tag." ". $start_date." ". $end_date;
    
 $allsession= ONLINEPAY::searchbydate($tag, $start_date, $end_date);
 

 }

 }
 
 
    

   
    
    // if (isset($portal)){
    
        if ($portal==1){
            $portal='PORTAL1';
        }else if ($portal==2){
            $portal='PORTAL2';
        }
    // }
  
    
    

      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("","","","","FEES COLLECTION PAYMENT LIST","","","",""));
 
  
     fputcsv($output, array("SN","FORM NO","PROGRAMME TYPE","TRANSACTION REF","SURNAME","OTHERNAMES","DEPARTMENT","LEVEL","AMOUNT","PAYMENT DATE"));
 
 
  $sn=0;$totalamount=0;
    foreach($allsession as $studentdata){
        if ($portal=='PORTAL1'){
            
            
            $sn++;
            $formno = $studentdata['fno'];
            $transref=$studentdata['txn_ref'];
            $surname=strtoupper($studentdata['surname']);
            $othernames=strtoupper($studentdata['othername']);
            $department=strtoupper($studentdata['department']);
            $level=strtoupper($studentdata['level']);
            $desc=strtoupper($studentdata['status']);
            $amount=$studentdata['amount'];
            $totalamount+=$studentdata->amount;
            $datetime=$studentdata['date_time'];
		    
		  
                            
                            if ((substr($studentdata['fno'],2,1)=='2') AND ($studentdata['level']=='NDI')){
		                     $programtype="ND I DPT";
		                     
		                    }else if ((substr($studentdata['fno'],2,1)=='2') AND ($studentdata['level']=='NDII')){
		                        $programtype="ND II DPT"; 
		                        
		                   }else if ((substr($studentdata['fno'],2,1)=='1')AND ($studentdata['level']=='NDI')){
		                    $programtype="ND I FT";
		                    
		                    }else if ((substr($studentdata['fno'],2,1)=='1')AND ($studentdata['level']=='NDII')){
		                      $programtype="ND II FT";  
		                      
		                    }else if ((substr($studentdata['fno'],2,1)=='1')AND ($studentdata['level']=='HNDI')){
		                    $programtype="HND I FT";
		                    
		                    }else if ((substr($studentdata['fno'],2,1)=='2')AND ($studentdata['level']=='HNDI')){
		                    $programtype="HND I DPT";
		                    
		                    }else if ((substr($studentdata['fno'],2,1)=='1')AND ($studentdata['level']=='HNDII')){
		                    $programtype="HND II FT";
		                    
		                    }else if ((substr($studentdata['fno'],2,1)=='2')AND ($studentdata['level']=='HNDII')){
		                    $programtype="HND II DP";
		                    }
                           
            
            
            
            
        }else if ($portal=='PORTAL2'){
            $sn++;
            $formno = $studentdata->formno;
            $transref=$studentdata->txt_ref;
            $surname=strtoupper($studentdata->surname);
            $othernames=strtoupper($studentdata->othernames);
            $department=strtoupper($studentdata->department);
            $level=strtoupper($studentdata->level);
            $desc=strtoupper($studentdata->status);
            $amount=$studentdata->amount;
            $datetime=$studentdata->datetime;
		    
		  
                            
                            if ((substr($studentdata->formno,0,2)=='DP') AND ($studentdata->level=='ND I')){
		                     $programtype="ND I DPT";
		                    }else if ((substr($studentdata->formno,0,2)=='DP') AND ($studentdata->level=='ND II')){
		                        $programtype="ND II DPT"; 
		                   }else if ((substr($studentdata->formno,0,2)=='PU')AND ($studentdata->level=='ND I')){
		                    $programtype="ND I FT";
		                    
		                    }else if ((substr($studentdata->formno,0,2)=='PU')AND ($studentdata->level=='ND II')){
		                      $programtype="ND II FT";  
		                    }else if ((substr($studentdata->formno,0,2)=='FT')AND ($studentdata->level=='HND I')){
		                    $programtype="HND I FT";
		                    }else if ((substr($studentdata->formno,0,2)=='DP')AND ($studentdata->level=='HND I')){
		                    $programtype="HND I DP";
		                    }
		                    else if ((substr($studentdata->formno,0,2)=='FT')AND ($studentdata->level=='HND II')){
		                    $programtype="HND II FT";
		                    }else if ((substr($studentdata->formno,0,2)=='DP')AND ($studentdata->level=='HND II')){
		                    $programtype="HND II DP";
		                    }
                           
		   
		  
		    
		 } 
 
        fputcsv($output,array($sn,$formno,$programtype,$transref,$surname,$othernames,$department,$level,$amount,$datetime));
            
    
 }
          fputcsv($output,array('','','','','','','Total Amount',$totalamount,''));
     
//  echo json($output);
  fclose($output);
// }
?>