<script type="text/javascript">	
$(document).ready(function() {
	$("#tabs").tabs({selected:0});
	$("#form").load('modul/piutang_dg/form.php');
	$("#tampil_data").load('modul/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_tgljt1").val(data.tanggal);
				$("#txt_tgljt2").val(data.tanggal);
			}
		});
	}
	
	$("#txt_cariplg").keyup(function() {
		var cari 	= $("#txt_cariplg").val()
		
		$.ajax({
			type	: "GET",
			url		: "modul/piutang_dg/tampil_data.php",
			data	: "cari="+cari,
			success	: function(data){
				$("#tampil_data").html(data);
			}
		});
	});
	
	$("#cetak_pd").click(function(){
		var cari 	= $("#txt_cariplg").val()
		window.location.href='modul/laporan/piutang_dg.php?cari='+cari;		
	});
	
	$("#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		: "modul/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 width='15%'>Cari Pelanggan</td>
					<td width='2%'>:</td>
					<td><input type='text' name='txt_cariplg' id='txt_cariplg' size='40'></td>
					<td colspan='6' align='right'>
						<button name='cetak_pd' id='cetak_pd'>Cetak</button>
						<button name='tutup_pd' 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</td>
					<td>:</td>
					<td><input type='text' name='txt_caripljt' id='txt_caripljt' size='20'></td>
					<td>Jatuh Tempo</td>
					<td>:</td>
					<td><input type='date' name='txt_tgljt1' id='txt_tgljt1'></td>
					<td>s/d</td>
					<td><input type='date' name='txt_tgljt2' id='txt_tgljt2'></td>
				</tr>
				<tr>
					<td colspan='12' align='center'>						
						<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>";
?>