<?php
require_once("./includes/initialize2.php");
global $database2;
// require_once("./includes/pdf_mc_table.php");
// include('pdf_mc_table.php');

$allsession ='';
date_default_timezone_set('Africa/Lagos');
  $table = $_SESSION['tablename'];
$fac =$_SESSION['fac'];
  $depta = $_SESSION['dept'];
$session = $_SESSION['sess'];
$level = $_SESSION['lev'];
  $amount=$_SESSION['amount'];
$prog = $_SESSION['prog'];
  $start_date =$_SESSION['start'];
 $end_date =$_SESSION['end'];


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

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

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

    $count = 0;
    //echo $table." ". $amount;
    
    $allsession= ONLINEPAY2::allfee($table, $amount);
}
else if (($faculty !='') && ($level !='') && ($session !=''))
{
    $count = 0;
    $allsession= ONLINEPAY2::showallbyfac($table, $facul, $level, $session);
}  
else if (($start_date!='') && ($end_date!='')){
    
    
    $count = 0;
    
 $allsession= ONLINEPAY2::searchbydate($table,$amount, $start_date, $end_date);
 
 //print_r($allsession);
 
}else if (($prog !='') && ($level !='')){
    
    
      $allsession= ONLINEPAY2::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 = 'Acceptance Fees Summary';}
elseif($table == 'schoolfees_tranzact'){$ftab = 'School Fees Summary';}

$output = '';



class coursePDF extends PDF_MC_TABLE
{
    
public $table;
public $start_date;
public $end_date;
public $fac ;
public $depta;
public $session;
public $level;
	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(5);
if($level){
$pdf->Cell(320,20,'Level '.$level." I ".$msg,0,0,'C');}
$pdf->Ln(10);
if ($start){
$pdf->Cell(320,20,'DATE '.$start."  TO  ".$end,0,0,'C');}
$pdf->Ln(10);
$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);

foreach($allsession as $student)
{
$pdf->Row(Array(
        ++$count,
        $student->formno,
        $student->txt_ref,
        trim(strtoupper($student->surname)),
        trim(strtoupper($student->othernames)),
        trim(strtoupper($student->department)),
        // $student->level,
        // $student->status,
        $student->amount,
        $student->datetime,
    ));
    $sum = $sum + $student->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();
?>