<script type="text/javascript">	
$(document).ready(function() {
	$("#tabs").tabs({selected:0});
	$("#form").load('spv/piutang_dg/form.php');
	$("#tampil_data").load('spv/piutang_dg/tampil_data.php');
	
	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){				
				$("#txt_tglawal").val(data.tanggal);
				$("#txt_tglakhir").val(data.tanggal);
				$("#txt_tgljt1").val(data.tanggal);
				$("#txt_tgljt2").val(data.tanggal);
			}
		});
	}
	
	$('#form_cari_plg').dialog({
		autoOpen: false,
		modal	: true,
		width: 600,
	});
		
	$('#t_namapl').keyup(function(){
		$('#form_cari_plg').dialog('open');
		$("#txt_cariplg").focus();
	});
	
	$("#txt_cariplg").keyup(function(){
		var cari= $("#txt_cariplg").val();
		
		var no=1;
		$.ajax({
			type	: "POST",
			url		: "modul/pener_piut/tampil_data_plg.php",
			data	: "cari="+cari,
			timeout	: 3000,
			beforeSend	: function(){		
				$("#info_plg").html("<img src='loading.gif' />");			
			},				  
			success	: function(data){
				$("#info_plg").html(data);
			}
		});
	});
	
	$("#cari_pd").click(function(){
		var tglawal = $("#txt_tglawal").val();
		var tglakhir= $("#txt_tglakhir").val();
		var kodepl  = $("#t_kodepl").val();
		
		$.ajax({
			type	: "GET",
			url		: "spv/piutang_dg/tampil_data.php",
			data	: "kodepl="+kodepl+
			        "&tglawal="+tglawal+
			        "&tglakhir="+tglakhir,
			success	: function(data){
				$("#tampil_data").html(data);
			}
		});
	});
	
	$("#cetak_pd").click(function(){
		var tglawal = $("#txt_tglawal").val();
		var tglakhir= $("#txt_tglakhir").val();
		var kodepl  = $("#t_kodepl").val();
		var namapl  = $("#t_namapl").val();
		window.location.href='modul/laporan/piutang_dg.php?tglawal='+tglawal+'&tglakhir='+tglakhir+'&kodepl='+kodepl+'&namapl='+namapl;
	});
	
	$("#tutup_pd").click(function(){
		document.location='?module=home';
	});
	
	$("#cari_jt").click(function() {
		var tgljt1	= $("#txt_tgljt1").val();
		var tgljt2	= $("#txt_tgljt2").val();
		var cari 	= $("#txt_caripljt").val();		
		
		if(tgljt1.length==0){
			alert('Maaf, tanggal jatuh tempo awal masih kosong.')
			return (false);
		}
		
		if(tgljt2.length==0){
			alert('Maaf, tanggal jatuh tempo akhir masih kosong.')
			return (false);
		}
				
		$.ajax({
			type	: "GET",
			url		: "spv/piutang_dg/tampil_data_jt.php",
			data	: "cari="+cari+
					"&tgljt1="+tgljt1+
					"&tgljt2="+tgljt2,
			timeout	: 2000,
			beforeSend	: function(){		
				$("#tampil_data_jt").html("<img src='loading.gif' />");			
			},				  
			success	: function(data){
				$("#tampil_data_jt").html(data);
				$("#tampil_data_jt").show();				
			}
		});
	});
		
	$("#cetak_jt").click(function(){
		var tgljt1	= $("#txt_tgljt1").val();
		var tgljt2	= $("#txt_tgljt2").val();
		var cari 	= $("#txt_caripljt").val();
		
		window.location.href='modul/laporan/piutang_jt.php?tgljt1='+tgljt1+'&tgljt2='+tgljt2+'&cari='+cari;
	});
	
	$("#tutup_jt").click(function(){
		document.location='?module=home';
	});
});
</script>

<style type="text/css">
#info {
	font-size:12px;
	font-weight:bold;
	color:#F00;
}
</style>
<?php
echo "<div id='tabs'>";
echo "<ul >
	       <li><a href='#form'>INPUT SALDO AWAL</a></li>
	       <li><a href='#data'>PIUTANG KESELURUHAN</a></li>
		   <li><a href='#data_jt'>PIUTANG JATUH TEMPO</a></li>		   
      </ul>";
	echo "<div id='form'></div>";
	
	echo "<div id='data'>
			<div id='pencarian'>
			<fieldset>
			<legend>Filter Data</legend>
			<table width='100%'>
				<tr>
					<td>Pelanggan : <input type='text' name='t_namapl' id='t_namapl' size='25' class='input_header'>
			            <input type='text' name='t_kodepl' id='t_kodepl' size='4' class='input_header' readonly />
			        </td>
					<td>Tanggal penjualan : <input type='date' id='txt_tglawal'> s/d <input type='date' id='txt_tglakhir'></td>
					<td>
					    <button id='cari_pd'>Cari</button>
						<button id='cetak_pd'>Cetak</button>
						<button id='tutup_pd'>Tutup</button>
					</td>
				</tr>
			</table>
			</fieldset>
			</div><br>
			<div id='tampil_data' align='center'></div>
		</div>";
	
	echo "<div id='data_jt'>
		<div id='pencarian_jt'>
			<fieldset>
			<legend>Filter Data</legend>
			<table width='100%'>
				<tr>
					<td>Pelanggan : <input type='text' name='txt_caripljt' id='txt_caripljt' size='20'></td>
					<td>Jatuh Tempo : <input type='date' name='txt_tgljt1' id='txt_tgljt1'> s/d <input type='date' name='txt_tgljt2' id='txt_tgljt2'></td>
					<td>						
						<button name='cari_jt' id='cari_jt'>Cari</button>
						<button name='cetak_jt' id='cetak_jt'>Cetak</button>
						<button name='tutup_jt' id='tutup_jt'>Tutup</button>
					</td>
				</tr>
			</table>
			</fieldset>
			</div><br>
		<div id='tampil_data_jt' align='center'></div>
	</div>";
	
	echo "<div id='info' align='center'></div>";
	
	echo "<div id='form_cari_plg' title='Pencarian Data Pelanggan'>
		<table width='100%'>
			<tr>
				<td width='20%'>Cari Pelanggan</td>
				<td width='1%'>:</td>
				<td><input type='text' name='txt_cariplg' id='txt_cariplg' size='40'</td>
			</tr>
		</table>
		<div id='info_plg' align='center'></div>
	</div>";

echo "</div>";
?>
