<?php
	include '../../inc/inc.koneksi.php';
	include '../../inc/fungsi_tanggal.php';
	
	$kode 		= $_GET[kode];
	$kodeplg	= $_GET[kodeplg];
	$tanggal	= $_GET[tgl];
	
	$sql1		= "SELECT * FROM customer WHERE kode_pl='$kodeplg' ORDER BY kode_pl";		
	$query1 	= mysql_query($sql1);
		
	while($r1=mysql_fetch_array($query1)){
		$namaplg = $r1[nama];
		$alamat 	= $r1[alamat];
	}
	
	$sql2		= "SELECT * FROM company";		
	$query2 	= mysql_query($sql2);
		
	while($r2=mysql_fetch_array($query2)){
		$kop1 = $r2[nama1];
		$kop2 = $r2[alamat];
	}
	
	$sql1	= "SELECT * FROM faktur_pj WHERE kode_pj='$kode' ORDER BY kode_pj";		
	$query1 = mysql_query($sql1);
	$r=mysql_fetch_assoc($query1);
	$user=$r[user];
	
	$handle= printer_open("EPSON TM-U220 Receipt");
	printer_set_option($handle, PRINTER_MODE, "RAW");
	printer_start_doc($handle, "PHP Direct Printer");
	printer_start_page($handle);
	
	$cetak = "$kop1\n";
	$cetak .= "$kop2\n";
	$cetak .= "----------------------------------------\n";
	$cetak .= "Nota \t : $kode \t  ".jin_date_str($tanggal)."\n";
	$cetak .= "Plg. \t : $namaplg \n";
	$cetak .= "Kasir \t : $user \n";
	$cetak .= "----------------------------------------\n";
				
		$sql	= "SELECT * FROM faktur_pj WHERE kode_pj='$kode' ORDER BY kode_pj";		
		$query = mysql_query($sql);
		
		$no=1;				
		$tjumlah=0;
		$tbayar=0;
		
		while($r_data=mysql_fetch_array($query)){
			$hgnet=$r_data[hg_jual]-$r_data[potongan];
			
			$cetak .= "$r_data[nama_st] \n";
			$cetak .= "$r_data[jml_unit] $r_data[satuan] \t x ".number_format($hgnet,0)."  = ".number_format($r_data[jumlah],0)."\n";
			$tjumlah=$tjumlah+$r_data[jumlah];
			$tbayar=$tbayar+$r_data[bayar];
			$no++;
		}
		if($tbayar>$tjumlah){
			$tsisa=$tbayar-$tjumlah;
			$text="Kembali  ";}
		else{
			$tsisa=$tjumlah-$tbayar;
			$text="Terhutang";}
			
		$cetak .= "----------------------------------------\n";
		$cetak .= "\t \tJumlah    : ".number_format($tjumlah,0)."\n";
		$cetak .= "\t \tDibayar   : ".number_format($tbayar,0)."\n";
		$cetak .= "\t \t$text : ".number_format($tsisa,0)."\n";
		$cetak .= "\t \t---------------------\n";
		$cetak .= "\n";												
		$cetak .= "Terima kasih, selamat datang kembali.\n";
	printer_write($handle, $cetak);
	printer_end_page($handle);		
	printer_end_doc($handle);
	printer_close($handle);
	echo "<a href=\"javascript:history.back()\">Kembali</a>";
?>
