<?php

ob_start();


//include my own function
include 'includes/functions.php';



//customly collect the id and session
if(isset($_GET['me']))
{
	$u = $_GET['me'];
	$s = $_GET['s'];
	//$sem = $_GET['sem'];
}
else
{
	header("Location:dashboard.php?sms=hostel_fee_payment&qlk=".md5(2)."");

}
//============================================================+
// File name   : create_payment_slip.php
// Description : This prints a slip per session
//               Custom Header and Footer
//
// Author: aslapai
//
//============================================================+



$session = 6; //current session is always
$st = get_session_title($session);

//$semester = get_current_semester($id = 1); //current semester
//$sem = get_semester_title($sem);
//$sem = strtoupper($sem);


// Include the main TCPDF library (search for installation path).
require_once('tcpdf/tcpdf_include.php');


// Extend the TCPDF class to create custom Header and Footer
class MYPDF extends TCPDF {

	//Page header
	public function Header() {
		// Logo
	//	$image_file = K_PATH_IMAGES.'logo.jpg';
		//$this->Image($image_file, 10, 10, 15, '', 'JPG', '', 'T', false, 300, '', false, false, 0, false, false, false);
		// Set font
	//	$this->SetFont('helvetica', 'B', 14);
		// Title
		//$this->Cell(0, 15, '<< TCPDF Example 003 >>', 0, false, 'C', 0, '', 0, false, 'M', 'M'); original commented
	//	$this->Cell(0, 15, 'NIGER STATE COLLEGE OF EDUCATION MINNA', 0, false, 'C', 0, '', 0, false, 'M', 'M');
	}

	// Page footer
	public function Footer() {
		// Position at 15 mm from bottom
		$this->SetY(-15);
		// Set font
		$this->SetFont('helvetica', 'I', 8);
		// Page number
		$this->Cell(0, 10, "SOURCE: http://accommodation.coeminna-edu.ng - ACCOMMODATION Portal,  Page ".$this->getAliasNumPage().'/'.$this->getAliasNbPages(), 0, false, 'C', 0, '', 0, false, 'T', 'M');
	}
}


// create new PDF document
$pdf = new MYPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);



//customly collect the title
$title = str_replace ('/','_',get_user_mat_no($u)). '-PAYMENT SLIP';
$title =strtoupper($title);
$author = get_user_fullname($u).'_ COE MX';


// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor($author);
$pdf->SetTitle($title);
$pdf->SetSubject('Payment Slip');
$pdf->SetKeywords('COE MX, PDF, invoice, slip, '.$session.'');


// set default header data
//$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE, PDF_HEADER_STRING);
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE, PDF_HEADER_STRING);



// set header and footer fonts
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));

// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);

// set margins
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);

// set auto page breaks
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);

// set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);

// set some language-dependent strings (optional)
if (@file_exists(dirname(__FILE__).'/lang/eng.php')) {
	require_once(dirname(__FILE__).'/lang/eng.php');
	$pdf->setLanguageArray($l);
}

// ---------------------------------------------------------

// set font
//$pdf->SetFont('times', 'BI', 12) original;
$pdf->SetFont('times', '', 12);

// add a page
$pdf->AddPage();


//set the content //this is my own function

//set the content //this is my own function
$output_ = '';
$output = '';

 //$output_ .= '<br/><h5  style="color:#00000; font-weight:normal" ><i>(Office of the Vice Chancellor)</i></h5>';
 //$output_ .= '<h3>INSTITUTE OF CONTINUING EDUCATION & e-LEARNING</h3>';
 $output_ .= '<span align="center"> <img  src="images/coe.png" border="0" height="79" width="80" /></span>';
 $output_ .= '<br/><h2  style="color:#00000; font-weight:normal" >NIGER STATE COLLEGE OF EDUCATION MINNA</h2>';
 $output_  .= '<h6   style="color:#00000; font-weight:normal"> '. $st .' ACADEMIC SESSION. - '.$sem.'</h6>';
 $output_  .= '<h5  style="color:#9999; font-weight:normal;"  >GENERAL RECEIPT </h5>';


//collect other dinfo
$dept_id = get_user_department_id($u);
$level = get_user_level($u); //get user level

//manipulate if level is greater than 200
//$level = get_level_from_courses_registered_by_session($u,$s);
//if($s == '2')
 //{
 	//$level = $level - 100;

// }

$name = strtoupper (get_user_fullname($u));
$mat_no = strtoupper (get_user_mat_no($u));
$so = strtoupper(show_state(get_user_state_id($u)));
$lo = strtoupper(show_lga(get_user_lga_id($u)));


//collect academic info
//$pt = strtoupper(show_programme_type(get_user_programme_type($u)));
//$study_mode = strtoupper(show_study_mode(get_user_study_mode($u)));

$department = strtoupper(get_department_title(get_user_department_id($u)));
$programme = strtoupper(get_programme_title(get_user_programme_id($u)));


//pdf generated
$pdf_generated = date('d-m-Y / H:i:s');

$output = '';

$q = "SELECT `id`, `student_id`, `session_id`, `payment_status`, `payment_type`, `payment_method`,
	 `invoice_id`, `title`, `description`, `amount`,  DATE_FORMAT(`date_added`, '%M %e, %Y  %l:%i:%p') as date_added, `added_by`
	 FROM `hostel_app_fee_payments`
	 WHERE student_id = '$u'  AND session_id = '$session'";

$r =mysqli_query($conn_1,$q);


	if(mysqli_num_rows($r) > 0)
	{//show table



	  $output  .= '<table cellspacing="1"   cellpadding="2" border="0.5"  style="border:#000 solid 1px; font-size:12px;">';
	  $output .=	'<thead>';

	  $output .=	'<tr> <th width="75%" ><b> Description </b></th><th width="25%"> <b> Total </b></th></tr>';
	  $output .=	'</thead>';
	  $output .=	'<tbody>';


		while($row = mysqli_fetch_array($r, MYSQLI_ASSOC))
		{

			$output .="" ;
			$output .= '<tr> <td width="75%"> '.strtoupper($row['title']).' </td> <td width="25%">  '.'N'.number_format($row['amount'],2).'K </td></tr> ';
			$output .= '<tr> <td width="75%"><b> Hostel Application Fee </b></td> <td width="25%"> N 1, 000  </td></tr> ';
			$output .= '<tr> <td width="75%"><b> ICT Infrastructure Fee </b></td> <td width="25%"> N 0.00 </td></tr> ';
			$output .= '<tr> <td width="75%"><b> Remita Processing Fee </b></td> <td width="25%"> N 323</td></tr> ';
			
			$output .= '<tr> <td width="75%" align="right"> <b> Sub Total </b> </td><td width="25%"> <b>'.'N'.number_format($row['amount'],2).'K </b> </td> </tr>';
			$output .= '<tr> <td width="75%" align="right"> <b> Total </b> </td><td width="25%"> <b>'.'N'.number_format($row['amount'],2).'K </b> </td> </tr>';

			$output .= "<tr><td colspan='2'> DATE / TIME Generated: &nbsp;&nbsp;&nbsp;".$row['date_added']."</td></tr>";
			$output .="" ;



		}
	}
	else
	{//show the msg

			$output =
				   ' No record found in the system.';


	}



	$output .=	'</tbody>';
	$output .=	'</table>';



// set some text to print
$txt = <<<EOD
<div align="center"> $output_ </div>

<h6 style="border-bottom:solid thin #000; margin-bottom:3px;">BASIC INFORMATION</h6>

 <table cellspacing="1"  border="1" cellpadding="3" style="font-size:12px;">

			  <tr>
			  <td width="30%"> <b>MATRIC No. :</b> $mat_no</td>
			  <td width="50%"> <b>NAME :</b> $name</td>
			   <td width="20%"> <b>LEVEL :</b> $level</td>
			  </tr>


			  <tr>
			   <td width="30%"><b>SESSION:</b> $st</td>
			<td width="30%"> <b>DEPARTMENT:</b> $department</td>
			   <td width="40%"> <b>PROGRAMME :</b> $programme</td>
			  </tr>

			  



 </table>

 <br><br>
 <br><br>


$output
<br><br>
PDF generated - $pdf_generated.
EOD;

// print a block of text using Write()
//$pdf->Write(0, $txt, '', 0, 'C', true, 0, false, false, 0);

//$pdf->writeHTML($txt, true, false, false, false, '');

// ---------------------------------------------------------




$pdf->writeHTML($txt, true, false, false, false, '');

// ---------------------------------------------------------




//Close and output PDF document
//$pdf->Output('example_003.pdf', 'I');
$pdf->Output($title.'.pdf', 'D');

//============================================================+
// END OF FILE
//============================================================+
