<script type="text/javascript">	
$(document).ready(function(){
	cari_tgl();
	
	function cari_tgl(){
		var no = 1;
		$.ajax({
			type	: "POST",
			url		: "modul/report/cari_tanggal.php",
			data	: "no="+no,
			dataType: "json",
			success	: function(data){								
				$("#t_tgl_awal").val(data.tanggal);
				$("#t_tgl_akhir").val(data.tanggal);
				$("#t_tgl_awal").focus();
			}
		});
	}
	
	$('#form_cari_sup').dialog({
		autoOpen: false,
		modal	: true,
		width: 600,
	});
		
	$('#txt_namasup').keyup(function(){
		$('#form_cari_sup').dialog('open');
		$("#info_supplier").load('modul/pembelian/tampil_data_sup.php');
		$("#txt_carisup").focus();
	});
	
	$('#txt_namasup').click(function(){
		$('#form_cari_sup').dialog('open');
		$("#info_supplier").load('modul/pembelian/tampil_data_sup.php');
		$("#txt_carisup").focus();
	});
	
	$("#txt_carisup").keyup(function(){
		var cari = $("#txt_carisup").val();
		
		$.ajax({
			type	: "POST",
			url		: "modul/pembelian/tampil_data_sup.php",
			data	: "cari="+cari,
			timeout	: 2000,
			beforeSend	: function(){
				$("#info_supplier").html("<img src='loading.gif' />");
			},
			success	: function(data){
				$("#info_supplier").html(data);
			}
		});
	});

	$("#cari").click(function(){
		var tgl_awal	= $("#t_tgl_awal").val();
		var tgl_akhir 	= $("#t_tgl_akhir").val(); 
		var kodesup  	= $("#t_kodesup").val();
		
		if(tgl_awal.length==''){
			alert('Maaf, Tanggal awal periode masih kosong.');
			$("#t_tgl_awal").focus();
			return false;
		}
		if(tgl_akhir.length==''){
			alert('Maaf, Tanggal akhir periode belum terisi.');
			$("#t_tgl_akhir").focus();
			return false;
		}
		$("#data_pb").show();
		$("#data_pb").load('modul/report/tampil_data_pb.php?tgl_awal='+tgl_awal+'&tgl_akhir='+tgl_akhir+'&kodesup='+kodesup);
	});
	
	$("#refresh").click(function() {
		window.location.reload();		
	});
	
	$("#cetak").click(function() {
		var tgl_awal	= $("#t_tgl_awal").val();
		var tgl_akhir	= $("#t_tgl_akhir").val();
		var kodesup  	= $("#t_kodesup").val();
		var namasup  = $("#t_namasup").val();
		
		if(tgl_awal.length==''){
			alert('Maaf, Tanggal awal periode belum terisi.');
			$("#t_tgl_awal").focus();
			return false;
		}
		if(tgl_akhir.length==''){
			alert('Maaf, Tanggal akhir periode masih kosong.');
			$("#t_tgl_akhir").focus();
			return false;
		}		
		window.location.href='modul/laporan/daftar_pbl.php?tgl_awal='+tgl_awal+'&tgl_akhir='+tgl_akhir+'&kodesup='+kodesup+'&namasup='+namasup;
	});
	
	$("#tutup_daftar").click(function(){
		document.location='?module=home';
	});
	
});
</script>
<style type="text/css">
#data_pb{
	font-size:12px;
	font-weight:bold;
	color:#F00;
}
</style>

<?php
include '../../inc/inc.koneksi.php';
	
echo "<div span='12' style='background-color:white'>";
echo "<div id='form' align='center'><h3>DAFTAR PEMBELIAN BARANG DAGANGAN<h3></div>";
echo "<div id='filter' align='left'>
	<fieldset>
		<legend>Filter Data</legend>
		<table width='100%'>
			<tr>
				<td>Tanggal pembelian : <input type='date' name='t_tgl_awal' id='t_tgl_awal' size='10'> sampai dengan <input type='date' name='t_tgl_akhir' id='t_tgl_akhir' size='10'></td>
				<td>Supplier : <input type='text' name='t_namasup' id='t_namasup' size='22' class='input_header'>
					<input type='text' name='t_kodesup' id='t_kodesup' size='3' class='input_header' readonly />
				</td>
				<td>
					<button name='cari' id='cari'>Cari</button>
					<button name='cetak' id='cetak'>Cetak</button>
					<button name='refresh' id='refresh'>Refresh</button>
					<button name='tutup_daftar' id='tutup_daftar'>Tutup</button>
				</td>
			</tr>
		</table>
	</fieldset>
	</div><br>";
	
echo "<div id='data_pb' align='center' style='overflow-x: auto;height: 400px;scroll-behavior: smooth'></div>";

echo "</div>";
?>
