<?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'];
}
else
{
	header("Location:dashboard.php?act=school_fee_payments&qlk=".md5(2)."");

}

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



$session = get_current_session_4($id = '4'); //current session is always
$st = get_session_title($session);

$semester = get_current_semester($id = 1); //current semester
$sem = get_semester_title($semester);
$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: www.coeminna-edu.ng/summmer_sales/students Niger State College of Education Minna. STUDENT 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 MINNA';


// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor($author);
$pdf->SetTitle($title);
$pdf->SetSubject('Payment Slip');
$pdf->SetKeywords('Niger State College of Education, 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

//for imge
$image = get_user_image($u);//get image
if($image != '')
{
	$passport = '<img  src="../uploads/'.$image.'" border="0" height="71" width="61" />';



}
else
{
	$passport = '<img  src="../uploads/img.jpg" border="0" height="71" width="61" />';



}


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

 $output_ .= '<br/><h5  style="color:#00000; font-weight:normal" ><i>P.M.B 39, MINNA, NIGER STATE</i></h5>';
 //$output_ .= '<h3>NON-DEGREE PROGRAMME UNIT</h3>';
 $output_ .= '<h5  style="color:#00000; font-weight:normal" >NIGERIA CERTIFICATE IN EDUCATION</h5>';
 $output_  .= '<h6   style="color:#00000; font-weight:normal"> '. $st .' ACADEMIC SESSION.</h6>';
 $output_  .= '<h5  style="color:#9999; font-weight:normal;"  >SUMMER GENERAL RECEIPT  </h5>';


//collect other dinfo
$dept_id = get_user_department_id($u);
$level = "SUMMER"; //get_user_level($u); //get user level
$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)));

//phone number
$ph = get_user_phone_no($u);
$gender = get_user_gender($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)));


$school = strtoupper(get_school_title(get_user_school_id($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`, `payment_status`, `payment_type`, `payment_method`,  `payment_mode`,
	 `invoice_id`, `title`, `description`, `amount`,  DATE_FORMAT(`date_added`, '%M %e, %Y  %l:%i:%p') as date_added, `added_by`
	 FROM `summer_school_fee_payments_nce`
	 WHERE student_id = '$u'  AND session = '$s' AND semester = 1";

$r =mysqli_query(dbc(),$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))
		{
			$payment_method = show_payment_method($row['payment_method']);
			$payment_mode = show_payment_mode($row['payment_mode']);
			$invoice_id = $row['invoice_id'];

			$output .="" ;
			$output .= '<tr> <td width="75%"> '.strtoupper($row['title']).' </td> <td width="25%">  '.'N'.number_format($row['amount'] - 480,2).'K </td></tr> ';
			$output .= '<tr> <td width="75%">'.$row['description'].' </td> <td width="25%">  </td></tr> ';
			$output .= '<tr> <td width="75%" align="right"> <b> Processing Fee </b> </td><td width="25%"> <b>'.'N'.number_format(315,2).'K </b> </td> </tr>';  		     $output .= '<tr> <td width="75%" align="right"> <b> Infrastructure Fee </b> </td><td width="25%"> <b>'.'N'.number_format(165,2).'K </b> </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>

<div align="right"> $passport </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> <br/> $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>GENDER:</b> $gender</td>
			   <td width="30%"> <b>GSM NO. :</b> $ph</td>
			    <td width="40%"><b>SESSION:</b> $st</td>

			  </tr>


			  <tr>

			  <td width="50%"> <b>SCHOOL :</b> $school</td>
			  <td width="25%"> <b>PROG. TYPE :</b> $pt</td>
			  <td width="25%"> <b>PROG.MODE :</b> $study_mode </td>
			  </tr>

			   <tr>

			   <td width="30%"> <b>DEPARTMENT:</b> $department</td>
			   <td width="70%"> <b>PROGRAMME :</b> $programme</td>

			  </tr>





 </table>

 <br><br>

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

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

			  <tr>
			  <td width="30%"> <b>INVOICE NO. :</b>  $invoice_id</td>
			  <td width="30%"> <b>PAYMENT MODE :</b> $payment_mode</td>
			  <td width="40%"> <b>PAYMENT METHOD :</b> $payment_method</td>
			  </tr>

			  <tr>

			  <td width="100%" style="font-size:10px;"> <b>NOTE:</b> Please attached a copy of your bank teller to this payment slip and submit to Bursary Department for verification of your payment.</td>
			  </tr>



 </table>

 <br><br>

$output


 <br><br>
 <br><br>
 <h6 style="border-bottom:solid thin #000; margin-bottom:3px;">OFFICIAL USE ONLY</h6>

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



			  <tr>
			  <td width="100%"> </td>

			  </tr>

			   <tr>
			  <td width="100%"> </td>

			  </tr>
			   <tr>
			  <td width="100%"> </td>

			  </tr>



			  <tr>
			  <td width="30%"> _______________________ <br/>  Checked By</td>
			  <td width="30%">  </td>
			  <td width="40%"> _______________________ <br/>  Date & Stamp</td>
			  </tr>



 </table>

 <br><br>



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, '');

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



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

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