<script type="text/javascript">	
$(document).ready(function() {	
	$("#tabs").tabs({selected:0});
	$("#form").load('modul/tebus_do/form.php');
	var kodesp = $("#x_kodesp").val();
	$("#tampil_data_osdo").load('modul/tebus_do/tampil_data_osdo.php?kodesp='+kodesp);
	
	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);				
			}
		});
	}
	
	$("#cari_tebus").click(function(){
		var tgl_awal	= $("#t_tgl_awal").val();
		var tgl_akhir	= $("#t_tgl_akhir").val();
		var kodesp 	    = $("#t_kodesp").val();
		
		if(tgl_awal.length==''){
			alert('Maaf, Variabel tanggal belum lengkap');
			$("#t_tgl_awal").focus();
			return false;
		}
		if(tgl_akhir.length==''){
			alert('Maaf, Variabel tanggal belum lengkap.');
			$("#t_tgl_akhir").focus();
			return false;
		}
		$("#tampil_data").load('modul/tebus_do/tampil_data.php?tgl_awal='+tgl_awal+'&tgl_akhir='+tgl_akhir+'&kodesp='+kodesp);
	});
	
	$("#cetak_tebus").click(function(){
		var tgl_awal	= $("#t_tgl_awal").val();
		var tgl_akhir	= $("#t_tgl_akhir").val();
		var kodesp 	    = $("#t_kodesp").val();
		
		if(tgl_awal.length==''){
			alert('Maaf, Variabel tanggal belum lengkap');
			$("#t_tgl_awal").focus();
			return false;
		}
		if(tgl_akhir.length==''){
			alert('Maaf, Variabel tanggal belum lengkap');
			$("#t_tgl_akhir").focus();
			return false;
		}
		window.location.href='modul/laporan/daftar_tbdo.php?tgl_awal='+tgl_awal+'&tgl_akhir='+tgl_akhir+'&cari='+cari+'&kodesp='+kodesp;
	});
	
	$("#x_kodesp").keyup(function(){
		var kodesp= $("#x_kodesp").val();
		$("#tampil_data_osdo").load('modul/tebus_do/tampil_data_osdo.php?kodesp='+kodesp);
	});
	
	$("#cetak_osdo").click(function(){
		var kodesp = $("#x_kodesp").val();
		window.location.href='modul/laporan/daftar_osdo.php?kodesp='+kodesp;
	});
	
	$("#tutup").click(function(){
		document.location='?module=home';
	});
	
	$("#tutup_osdo").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 PENEBUSAN DO</a></li>
	       <li><a href='#data'>DAFTAR PENEBUSAN DO</a></li>
		   <li><a href='#outstand'>OUTSTANDING DO</a></li>
      </ul>";
	  
echo "<div id='form'></div>";
	
echo "<div id='data'>
			<div id='pencarian'>
				<table width='100%'>
				<tr>
					<td>Penebusan tanggal : <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>SPBE : <select name='t_kodesp' id='t_kodesp' class='input' >";
						echo "<option value=''> - </option>";
						$sql = mysql_query("SELECT * FROM supplier ORDER BY kode_sp");
						while($r=mysql_fetch_array($sql)){
							$kodesp = $r[kode_sp];
							echo "<option value='$kodesp'>$kodesp - $r[nama]</option>";
						}
						echo "</select>
					</td>
					
					<td>
						<button name='cari_tebus' id='cari_tebus'>Cari</button>
						<button name='cetak_tebus' id='cetak_tebus'>Cetak</button>
						<button name='tutup' id='tutup'>Tutup</button>
					</td>
				</tr>
				</table>
			</div>
			<div id='tampil_data' align='center'></div>
		</div>";

echo "<div id='outstand'>
			<table width='100%'>
				<tr>
					<td align='center'>
						<td>SPBE : <select name='x_kodesp' id='x_kodesp' class='input' >";
							echo "<option value=''> - </option>";
							$sql = mysql_query("SELECT * FROM supplier ORDER BY kode_sp");
							while($r=mysql_fetch_array($sql)){
								$kodesp = $r[kode_sp];
								echo "<option value='$kodesp'>$kodesp - $r[nama]</option>";
							}
							echo "</select>
					</td>
					<td>
						<button name='cetak_osdo' id='cetak_osdo'>Cetak Outstanding DO</button>
						<button name='tutup_osdo' id='tutup_osdo'>Tutup</button>
					</td>
				</tr>
			</table>
		
			<div id='tampil_data_osdo' align='center'></div>
		</div>";

echo "<div id='info' align='center'></div>";

echo "</div>";
?>
