<?php
if(count(get_included_files()) ==1) exit("Direct access not permitted.");
require_once('include/global.php');
if (!isset($_SESSION)) session_start();

if(isset($_GET['idpembayaran'])){
	$db=pDatabase::getInstance();
	$datacetak=array();
	
	$query="select t1.`id`,
			t1.`tanggal`,
			t1.`ta`,
			t1.`bulan`,
			t1.`idjenis`,
			t1.`idsiswa`,
			t1.`jumlah`, 
			t2.nama as namasiswa,
			if(t3.nama is null,'...................',t3.nama) as namauser,
			t4.nama as namapembayaran,
			if(t5.nama is null,'',concat(', Bulan ',t5.nama)) as namabulan
		from tb_pembayaran_siswa as t1
		inner join tb_siswa as t2 on t1.idsiswa=t2.id
		left join tb_username as t3 on t1.iduser=t3.id
		inner join tb_jenis_pembayaran as t4 on t1.idjenis=t4.id
		left join tb_bulan as t5 on t1.bulan=t5.id
		where t1.id=?";
	$datacetak=$db->loadAssoc($query,array($_GET['idpembayaran']));
	
	$datacetak['ukurantextjudul']="13";
	$datacetak['ukurantext']="12";
	$datacetak['ukurantextduit']="14";
	$datacetak['nomor']=$datacetak['id'];
	$datacetak['jumlahhuruf']=$db->uanghuruf($datacetak['jumlah']);
	$datacetak['jumlahbayar']="  Rp. ".number_format($datacetak['jumlah'],"2",".",".");
	$datacetak['tanggalfull']=$db->fulldate($datacetak['tanggal']);
	$datacetak['namapembayaran']="Pembayaran ".$datacetak['namapembayaran'].$datacetak['namabulan']." TA. ".$datacetak['ta'];
	
	$handle = fopen("cetak/notaspp.html", "r");
	$newline="";
	while(!feof($handle)){
	    $line = fgets($handle);
		$newline.=$line;
	}
	fclose($handle);
	
	$obj=(object) array("data"=>$newline);
	
	$datahasil['status']=1;
	$datahasil['pesan']="SUKSES";
	$datahasil['data']=$db->renderdata($obj,$datacetak);
	
	
	echo json_encode($datahasil,true);
}
?>