<script type="text/javascript">
	window.print();
</script>

<?php
	include '../../inc/inc.koneksi.php';
	include '../../inc/fungsi_tanggal.php';
			
	$kode 		= $_GET[kode];
	$kodeplg	= $_GET[kodeplg];
	$namaplg	= $_GET[namaplg];
	$tanggaljt	= $_GET[tanggaljt];
	$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)){
		$alamat = $r1[alamat];
	}
	
	$sql   = "SELECT * FROM faktur_pj WHERE kode_pj='$kode' ORDER BY no_urut";		
	$query = mysql_query($sql);
	$row   = mysql_num_rows($query);
	$hal   = 1;
	
	echo "<table width='700'>
		<tr>
			<td style='font:15px verdana;line-height:100%'><b>$unit</b></td>
		</tr>
		</table>
		<br>
		<table width='700'>
		<tr>
			<td align='center' style='font:15px verdana;line-height:100%'><b>BUKTI TITIPAN</b></td>
		</tr>
		</table>
		<br>";

	echo "<table width='700'>
		<tr>
			<td width='13%' style='font:13px verdana;line-height:100%'>Kepada Yth :</td>
			<td width='40%' style='font:13px verdana;line-height:100%'>$namaplg</td>
			<td width='14%' style='font:13px verdana;line-height:100%'></td>
			<td width='14%' style='font:13px verdana;line-height:100%'>No.Faktur</td>
			<td width='19%' style='font:13px verdana;line-height:100%'>: $kode</td>
		</tr>
		
		<tr>
			<td></td>
			<td style='font:13px verdana;line-height:100%'>$alamat</td>
			<td></td>
			<td style='font:13px verdana;line-height:100%'>Tanggal</td>";
			if($row>12)
				echo "<td style='font:13px verdana;line-height:100%'>: ".jin_date_str($tanggal)." ------ Halaman : $hal</td>";
			else
				echo "<td style='font:13px verdana;line-height:100%'>: ".jin_date_str($tanggal)."</td>";
		echo "</tr>
		<tr>
			<td width='10%' style='font:13px verdana;line-height:100%'></td>
			<td style='font:13px verdana;line-height:100%'></td>
			<td></td>			
			<td style='font:13px verdana;line-height:100%'>Jatuh Tempo</td>
			<td style='font:13px verdana;line-height:100%'>: ".jin_date_str($tanggaljt)."</td>
		</tr>
		</table>
		
		<table width='700'>
		<tr>
			<th width='4%' style='border-top:double 1px;border-bottom:double 1px;font:13px verdana;line-height:100%'>No.</th>
			<th width='8%' style='border-top:double 1px;border-bottom:double 1px;font:13px verdana;line-height:100%'>Kode</th>
			<th width='30%' style='border-top:double 1px;border-bottom:double 1px;font:13px verdana;line-height:100%'>Nama Barang</th>			
			<th width='12%' style='border-top:double 1px;border-bottom:double 1px;font:13px verdana;line-height:100%'>Jumlah Unit</th>
			<th width='8%' style='border-top:double 1px;border-bottom:double 1px;font:13px verdana;line-height:100%'>Satuan</th>
			<th width='10%' style='border-top:double 1px;border-bottom:double 1px;font:13px verdana;line-height:100%'>Harga Jual</th>
			<th width='12%' style='border-top:double 1px;border-bottom:double 1px;font:13px verdana;line-height:100%'>Total Harga</th>
		</tr>
		</table>";
		
	echo "<table width='700'>";
		$no=1;				
		$tjumlah=0;
		$tbayar=0;
		$brs=1;
		
		while($r_data=mysql_fetch_array($query)){
			
			if($brs<12){
				if(!($no==$row)){
					echo "<tr>
						<td width='4%' align='center' style='font:13px verdana;line-height:100%'>$no</td>
						<td width='8%' align='center' style='font:13px verdana;line-height:100%'>$r_data[kode_st]</td>
						<td width='30%' style='font:13px verdana;line-height:100%'>$r_data[nama_st]</td>
						<td width='12%' align='right' style='font:13px verdana;line-height:100%'>$r_data[jml_unit]</td>
						<td width='8%' align='center' style='font:13px verdana;line-height:100%'>$r_data[satuan]</td>
						<td width='10%' align='right' style='font:13px verdana;line-height:100%'>".number_format($r_data[hg_jual],0)."</td>
						<td width='12%' align='right' style='font:13px verdana;line-height:100%'>".number_format($r_data[jumlah],0)."</td>
					</tr>";
				}else{
					echo "<tr>
						<td width='4%' align='center' style='font:13px verdana;line-height:100%'>$no</td>
						<td width='8%' align='center' style='font:13px verdana;line-height:100%'>$r_data[kode_st]</td>
						<td width='30%' style='font:13px verdana;line-height:100%'>$r_data[nama_st]</td>					
						<td width='12%' align='right' style='font:13px verdana;line-height:100%'>$r_data[jml_unit]</td>
						<td width='8%' align='center' style='font:13px verdana;line-height:100%'>$r_data[satuan]</td>
						<td width='10%' align='right' style='font:13px verdana;line-height:100%'>".number_format($r_data[hg_jual],0)."</td>
						<td width='12%' align='right' style='font:13px verdana;line-height:100%'>".number_format($r_data[jumlah],0)."</td>
					</tr>
					</table>";
					
					while($brs<=12){
						echo "<br>";
						$brs++;
					}
					
					echo "<table width='700'>
					<tr>
						<td width='4%' align='center' style='border-bottom:double 1px;font:13px verdana;line-height:100%'></td>
						<td width='8%' align='center' style='border-bottom:double 1px;font:13px verdana;line-height:100%'></td>
						<td width='30%' style='border-bottom:double 1px;font:13px verdana;line-height:100%'></td>
						<td width='12%' align='right' style='border-bottom:double 1px;font:13px verdana;line-height:100%'></td>
						<td width='8%' align='center' style='border-bottom:double 1px;font:13px verdana;line-height:100%'></td>
						<td width='10%' align='right' style='border-bottom:double 1px;font:13px verdana;line-height:100%'></td>
						<td width='12%' align='right' style='border-bottom:double 1px;font:13px verdana;line-height:100%'></td>
					</tr>";
				}
			}
				
			if($brs==12){
				echo "<tr>
					<td width='4%' align='center' style='border-bottom:double 1px;font:13px verdana;line-height:100%'></td>
					<td width='8%' align='center' style='border-bottom:double 1px;font:13px verdana;line-height:100%'></td>
					<td width='30%' style='border-bottom:double 1px;font:13px verdana;line-height:100%'></td>
					<td width='12%' align='right' style='border-bottom:double 1px;font:13px verdana;line-height:100%'></td>
					<td width='8%' align='center' style='border-bottom:double 1px;font:13px verdana;line-height:100%'></td>
					<td width='10%' align='right' style='border-bottom:double 1px;font:13px verdana;line-height:100%'></td>
					<td width='12%' align='right' style='border-bottom:double 1px;font:13px verdana;line-height:100%'></td>
				</tr>";
				
				If(!($no==$row)){
					$brs=0;
					$hal++;
					echo "</table>
					<br>
					<br>
					<br>
					<br>
					
					<table width='700'>
					<tr>
						<td style='font:13px verdana;line-height:100%'><b>$kop1</b></td>
					</tr>
					<tr>
						<td align='center' style='font:13px verdana;line-height:100%'><b>BUKTI TITIPAN</b></td>
					</tr>
					</table>
					
					<table width='700'>
					<tr>
						<td width='10%' style='font:13px verdana;line-height:100%'>Kepada Yth :</td>
						<td width='30%' style='font:13px verdana;line-height:100%'>$namaplg</td>
						<td width='30%' style='font:13px verdana;line-height:100%'></td>
						<td width='10%' style='font:13px verdana;line-height:100%'>No.Faktur</td>
						<td width='20s%' style='font:13px verdana;line-height:100%'>: $kode</td>
					</tr>
					
					<tr>
						<td width='10%' style='font:13px verdana;line-height:100%'></td>
						<td style='font:13px verdana;line-height:100%'></td>
						<td></td>			
						<td style='font:13px verdana;line-height:100%'>Jatuh Tempo</td>
						<td style='font:13px verdana;line-height:100%'>: ".jin_date_str($tanggaljt)."</td>
					</tr>
					<tr>
						<td></td>
						<td style='font:13px verdana;line-height:100%'>$alamat</td>
						<td style='font:13px verdana;line-height:100%'></td>
						<td style='font:13px verdana;line-height:100%'>Tanggal</td>
						<td style='font:13px verdana;line-height:100%'>: ".jin_date_str($tanggal)." ------ Halaman : $hal</td>
					</tr>
					</table>
				
					<table width='700'>
					<tr>
						<th width='4%' style='border-top;border-bottom;font:13px verdana;line-height:100%'>No.</th>
						<th width='8%' style='border-top;border-bottom;font:13px verdana;line-height:100%'>Kode</th>
						<th width='30%' style='border-top;border-bottom;font:13px verdana;line-height:100%'>Nama Barang</th>
						<th width='12%' style='border-top;border-bottom;font:13px verdana;line-height:100%'>Satuan</th>
						<th width='8%' style='border-top;border-bottom;font:13px verdana;line-height:100%'>Jumlah Unit</th>
						<th width='10%' style='border-top;border-bottom;font:13px verdana;line-height:100%'>Harga Jual</th>
						<th width='12%' style='border-top;border-bottom;font:13px verdana;line-height:100%'>Total Harga</th>
					</tr>
					</table>";
				}
			}
			$tjumlah=$tjumlah+$r_data[jumlah];
			$tbayar=$tbayar+$r_data[bayar];
			$no++;
			$brs++;
		}
		if($tbayar>$tjumlah){
			$tsisa=$tbayar-$tjumlah;
			$text="Kembali";}
		else{
			$tsisa=$tjumlah-$tbayar;
			$text="Terhutang";}
			
	echo "<table width='700'>
		<tr>
			<td width='25%' style='font:12px verdana;line-height:100%'>TRANSFER TO :</td>
			<td width='20%' align='center' style='font:13px verdana;line-height:100%'>Adm</td>
			<td width='15%' style='font:13px verdana;line-height:100%'></td>
			<td width='20%' align='center' style='font:13px verdana;line-height:100%'>Penerima</td>
			<td width='10%' align='left' style='font:13px verdana;line-height:100%'>Jumlah</td>
			<td width='10%' align='right' style='font:13px verdana;line-height:100%'>".number_format($tjumlah,0)."</td>
		</tr>
		<tr>
			<td style='font:12px verdana;line-height:100%'>BANK </td>
			<td style='font:13px verdana;line-height:100%'></td>
			<td style='font:13px verdana;line-height:100%'></td>
			<td style='font:13px verdana;line-height:100%'></td>
			<td align='left' style='font:13px verdana;line-height:100%'>Dibayar</td>
			<td align='right' style='font:13px verdana;line-height:100%'>".number_format($tbayar,0)."</td>
		</tr>
			
		<tr>
			<td style='font:12px verdana;line-height:100%'>A/C. </td>
			<td style='font:13px verdana;line-height:100%'></td>
			<td style='font:13px verdana;line-height:100%'></td>
			<td style='font:13px verdana;line-height:100%'></td>
			<td align='left' style='border-bottom:double 1px;font:13px verdana'>$text</td>
			<td align='right' style='border-bottom:double 1px;font:13px verdana'>".number_format($tsisa,0)."</td>
		</tr>
		<tr>
			<td style='font:12px verdana;line-height:100%'>A/N. </td>
			<td style='border-bottom:double 1px;font:13px verdana;line-height:100%'></td>
			<td style='font:12px verdana;line-height:100%'></td>
			<td align='center' style='border-bottom:double 1px;font:13px verdana;line-height:100%'></td>
			<td></td>
			<td></td>
		</tr>
	</table>";
?>
<script type="text/javascript">
	history.back();
</script>
