<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_tglawal").val(data.tanggal);
				$("#t_tglakhir").val(data.tanggal);				
			}
		});
	}

	$('#form_cari_sp').dialog({
		autoOpen: false,
		modal	: true,
		width: 600,
	});
		
	$('#t_namasp').keyup(function(){
		var cari = $("#carisup").val();
		$('#form_cari_sp').dialog('open');
		$("#info_sp").load('modul/report/tampil_data_sup.php?cari='+cari);
		$("#carisup").focus();
	});
	
	$("#carisup").keyup(function(){
		var cari = $("#carisup").val();
		
		$.ajax({
			type	: "POST",
			url		: "modul/report/tampil_data_sup.php",
			data	: "cari="+cari,
			success	: function(data){
				$("#info_sp").html(data);
			}
		});
	});
	
	$("#cari").click(function(){
		var tglawal = $("#t_tglawal").val();
		var tglakhir= $("#t_tglakhir").val();
		var kodesp	= $("#t_kodesp").val();
		var cari	= $("#txt_carist").val();
		
		if(tglawal.length==''){
			alert('Maaf, Tanggal awal periode masih kosong.');
			$("#t_tglawal").focus();
			return false;
		}
		if(tglakhir.length==''){
			alert('Maaf, Tanggal akhir periode belum terisi.');
			$("#t_tglakhir").focus();
			return false;
		}		
		$("#data_pb").load('modul/report/tampil_data_pb.php?tglawal='+tglawal+'&tglakhir='+tglakhir+'&kodesp='+kodesp+'&cari='+cari);
	});
	
	$("#txt_carist").keyup(function(){
		var tglawal	= $("#t_tglawal").val();
		var tglakhir= $("#t_tglakhir").val();
		var kodesp	= $("#t_kodesp").val();
		var cari	= $("#txt_carist").val();
		
		$.ajax({
			type	: "GET",
			url		: "modul/report/tampil_data_pb.php",
			data	: "tglawal="+tglawal+
					"&tglakhir="+tglakhir+
					"&kodesp="+kodesp+
					"&cari="+cari,
			success	: function(data){
				$("#data_pb").html(data);
			}
		});
	});
	
	$("#refresh").click(function() {
		$(".input").val('');
	});
	
	$("#cetak").click(function() {
		var tglawal 	= $("#t_tglawal").val();
		var tglakhir	= $("#t_tglakhir").val();
		var kodesp		= $("#t_kodesp").val();
		var namasp		= $("#t_namasp").val();
		var cari		= $("#txt_carist").val();
		
		window.location.href='modul/laporan/daftar_pbl.php?tglawal='+tglawal+'&tglakhir='+tglakhir+'&kodesp='+kodesp+'&namasp='+namasp+'&cari='+cari;
	});
	
	$("#tutup_daftar").click(function(){
		document.location='?module=home';
	});
	
});
</script>
<style type="text/css">
#info {
	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 : <input type='date' id='t_tglawal' size='10'> s.d <input type='date' id='t_tglakhir' size='10'></td>
				<td>Supplier : <input type='text' id='t_namasp' size='25' class='input' >
					<input type='text' id='t_kodesp' size='3' class='input' class='filter_ds' readonly />
				</td>
				<td>Cari barang : <input type='text' id='txt_carist' class='input' size='30'></td>
			</tr>
		</table>
		<table width='100%'>
			<tr>
				<td align='center'>
					<button id='cari'>Cari</button>
					<button id='cetak'>Cetak</button>
					<button id='refresh'>Refresh</button>
					<button 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 id='form_cari_sp' title='Pencarian Data Supplier'>
		<table>
			<tr>
				<td>Cari Supplier : <input type='text' id='carisup' size='40'></td>
			</tr>
		</table>
		<div id='info_sp' align='center' style='overflow-x: auto;height: 400px;scroll-behavior: smooth'></div>
	</div>";

echo "</div>";
?>