<?php

// error_reporting(E_ALL);
// ini_set('display_errors',1);
require_once("./includes/initialize.php");
global $database;
session_start();
// require_once("./includes/pdf_mc_table.php");
// include('pdf_mc_table.php');

$allsession =array();
date_default_timezone_set('Africa/Lagos');
$table = $_SESSION['tablename'];
$fac =$_SESSION['fac'];
$depta = $_SESSION['dept'];
$session = $_SESSION['sess'];
$level = $_SESSION['lev'];

$prog = $_SESSION['prog'];
$start_date =$_SESSION['start'];
$end_date =$_SESSION['end'];

$faculty='';
$msg='';
$start='';


if (isset($_SESSION['portal'])){
    
     $portal=$_SESSION['portal'];
}
 if ($portal==1){
      
        
      require_once("includes/initialize4.php");
      global $database;
      $tag="tranzact_t";
      
    $table=$tag;


      $_SESSION['tablename']=$tag;
      if ($level=='ND I'){
          $level='NDI';
      }else if ($level=='ND II'){
          $level='NDII';
      }else if ($level=='HND I'){
          $level='HNDI';
      }else{
          $level='HNDII';
      }

 }else{
     $tag="schoolfees_tranzact";
 }




if (($portal==1) AND isset($start_date) AND isset($end_date)){
    //  echo "Portal 1: ".$tag." ". $start_date." ". $end_date;
    
  
      $allsession= ONLINEPAY::searchbydateportal1($tag, $start_date, $end_date);
     
     
 }else if (($portal==2) AND isset($start_date) AND isset($end_date)){
     
    //  echo "Portal 2: ".$tag." ". $start_date." ". $end_date;
 $allsession= ONLINEPAY::searchbydate($tag, $start_date, $end_date);
 }


if(($depta!="") && ($depta !='all') && ($level !='') && ($session !=''))
{
    $count = 0;

    $allsession= ONLINEPAY:: showsessiondetails($table, $depta, $level, $session);

}
else if (($depta=='all') && ($level !='') && ($session !=''))
{

    $count = 0;
    
    $allsession= ONLINEPAY::showalltranzact($table, $level, $session);
}
else if (($faculty !='') && ($level !='') && ($session !=''))
{
    $count = 0;
    $allsession= ONLINEPAY::showallbyfac($table, $facul, $level, $session);
// }  
// else if (($start_date!='') && ($end_date!='')){
    
    
//     $count = 0;
    
//  $allsession= ONLINEPAY::searchbydate($table, $start_date, $end_date);
 
}else if (($prog !='') && ($level !='')){
    
    
      $allsession= ONLINEPAY::searchbyprogramme($table, $prog, $level);
      if ($level == 'ND' && $prog == 'PU')
    {
        $msg = ' Full-Time Programme';
    }
    elseif ($level == 'ND' && $prog == 'DP')
    {
        $msg = ' Daily Part-Time Programme';
    }elseif ($level == 'HND' && $prog == 'FT')
    {
        $msg = ' Full-Time Programme';
    }elseif ($level == 'HND' && $prog == 'DP')
    {
        $msg = ' Daily Part-Time Programme';
    }
      }
 else
{
     "No record to display";
}
$sum = 0;

if ($table == 'acceptance_tranzact'){ $ftab = 'Portal II: Acceptance Fees Summary';}
elseif($table == 'schoolfees_tranzact'){$ftab = 'Portal II: School Fees Summary';}
elseif($table=='tranzact_t'){$ftab = 'Portal I: School Fees Summary';}

if (isset($_SESSION['brief'])){
    
     $brief = $_SESSION['brief'];
}
$output = '';



class coursePDF extends PDF_MC_TABLE
{
    
public $table;
public $start_date;
public $end_date;
public $fac ;
public $depta;
public $session;
public $level;
public $portal;

	function Head()
	{
		$this->Image('images/icon.png',10,15);
		$this->SetFont('Arial','B',14);
		$this->Cell(320,5,'OSUN STATE COLLEGE OF TECHNOLOGY, ESA-OKE.',0,0,'C');
		$this->Ln();
		$this->SetFont('Times','',12);
		$this->Cell(320,5,'P.M.B 1011, ESA-OKE, OSUN STATE.',0,0,'C');
		$this->Ln(10);
	}
	function Background(){
          $this->Image('images/img2.png',0,0,210,300);
   }

	function footer()
	{
		$this->SetY(-20);
		$this->SetFont('Times','',10);
		$this->Cell(320,2,'Directorate of ICT, Esa-Oke Copyright © 2018. All Rights Reserved.',0,0,'C');
		$this->Ln();
		$this->SetFont('Arial','',8);
		$this->Cell(0,10,'Page '.$this->PageNo().'/{nb}',0,0,'C');
	}
}


$pdf = new coursePDF('L','mm','A4');
$pdf->AliasNbPages();
$pdf->AddPage();//AddPage([string orientation [, mixed size [, int rotation]]])
$pdf->Head();
// $pdf->Background();
// $pdf->headerTable($depta, $level, $session,$fac, $table);
$pdf->SetFont('Times','BU',14);
$pdf->Cell(320,20,$ftab,0,0,'C');
$pdf->Ln(7);
$pdf->Cell(320,20,$brief,0,0,'C');
$pdf->Ln(1);
if(isset($level) AND !isset($start_date)){
$pdf->Cell(320,20,'Level '.$level."  ".$msg,0,0,'C');}
$pdf->Ln(7);
if ($start){
$pdf->Cell(320,20,'DATE '.$start."  TO  ".$end,0,0,'C');}
$pdf->Ln(7);
$pdf->SetFont('Times','',10);
$pdf->Cell(270,10,'Printed Date: '.date('d/m/Y h:i a'),0,1,'R');
$pdf->SetFont('Times','B',10);
$pdf->SetFillColor(150,255,150);
$pdf->SetWidths(Array(15,25,35,35,50,60,25,25));//width for each column
$pdf->SetAligns(Array('C','C','C','C','C','C','C','C'));
$pdf->SetLineHeight(5);//Height of text lines
$pdf->SetFont('Times','',12);
$pdf->Cell(15,10,'S/N',1,0,'C',true);
$pdf->Cell(25,10,"Form No.",1,0,"C",true);
$pdf->Cell(35,10,"Tranzaction ID",1,0,"C",true);
$pdf->Cell(35,10,"Surname",1,0,"C",true);
$pdf->Cell(50,10,"Other Names",1,0,"C",true);
$pdf->Cell(60,10,"Department",1,0,"C",true);
// $pdf->Cell(14,10,"Level",1,0,"C",true);
// $pdf->Cell(10,10,"Status",1,0,"C",true);
$pdf->Cell(25,10,"Amount",1,0,"C",true);
$pdf->Cell(25,10,"Payment Date",1,1,"C",true);

// $allsession=array();
// $allsession=$_SESSION['allsession'];

//print_r($allsession);
$count=0;
foreach($allsession as $student)
{
    if (isset($_SESSION['portal']) AND $_SESSION['portal']==1 ){
        
     $formno=$student['fno'];
        $txt_ref=$student['txn_ref'];
        $surname=trim(strtoupper($student['surname']));
      $othernames= trim(strtoupper($student['othername']));
        $department=trim(strtoupper($student['programme']));
        // $student->level,
        // $student->status,
        $amount=$student['amount'];
        $datetime=$student['date_time'];
        
    }else{
        
       $formno = $student->formno;
       $txt_ref=  $student->txt_ref;
     $surname = trim(strtoupper($student->surname));
     $othernames=  trim(strtoupper($student->othernames));
    $department= trim(strtoupper($student->department));
        // $student->level,
        // $student->status,
     $amount= $student->amount;
     $datetime=   $student->datetime;
    }
    // }
        
$pdf->Row(Array(
        ++$count,
        $formno,
        $txt_ref,
        $surname,
        $othernames,
        $department,
        // $student->level,
        // $student->status,
        $amount,
        $datetime,
    ));
    $sum = $sum + $amount;
}
setlocale(LC_MONETARY,"en_NGN");
// $money = money_format('%.2n', $sum);
$money = number_format($sum, 2, '.',',');
$pdf->Cell(320,10,'TOTAL SUM:  NGN '.$money,0,0,"C");

$pdf->Output();
?>