<script type="text/javascript">	
$(document).ready(function() {	
	$("#tabs").tabs({selected:0});
	$("#info_tebus").hide();
	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);
				$("#t_tglawal").val(data.tanggal);
				$("#t_tglakhir").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;
	});
	
	$("#cari_batal").click(function(){
		var tgl_awal	= $("#t_tglawal").val();
		var tgl_akhir	= $("#t_tglakhir").val();
		
		$("#tampil_data_batal").load('spv/tebus_do/tampil_data.php?tgl_awal='+tgl_awal+'&tgl_akhir='+tgl_akhir);
	});
	
	$("#batal_tebus").click(function(){
		var kode	= $("#bt_kode").val();
		var pilih 	= confirm('Apakah Anda sungguh-sungguh ingin batalkan penebusan '+kode+' ini ?');
		
		if (pilih==true) {
			var nobank	    = $("#bt_nobank").val();
			var kodesp	    = $("#bt_kodesp").val();
			var jmlunit		= $("#bt_jmlunit").val();	
			var jumlah		= $("#bt_jumlah").val();	
			var setor 		= $("#bt_setor").val();
			var bulat		= $("#bt_bulat").val();		
			var tgl_awal	= $("#t_tglawal").val();
			var tgl_akhir	= $("#t_tglakhir").val();
		
			$.ajax({
				type	: "POST",
				url	    : "spv/tebus_do/batal.php",
				data	: "kode="+kode+
					"&nobank="+nobank+
					"&kodesp="+kodesp+
					"&jmlunit="+jmlunit+
					"&jumlah="+jumlah+
					"&setor="+setor+
					"&bulat="+bulat,
				timeout: 2000,
				beforeSend	: function(){		
					$("#info").html("<img src='loading.gif' />");			
				},
				success	: function(data){
					$("#info").html(data);
					$("#info_tebus").hide();
					$("#pencarian_batal").show();
					$("#tampil_data_batal").show();
					$("#tampil_data_batal").load('spv/tebus_do/tampil_data.php?tgl_awal='+tgl_awal+'&tgl_akhir='+tgl_akhir);
				}
			});
		}
	});
	
	$("#tutup").click(function(){
		document.location='?module=home';
	});
	
	$("#tutup_osdo").click(function(){
		document.location='?module=home';
	});
	
	$("#tutup_batal").click(function(){
		document.location='?module=home';
	});
	
	$("#tutup_detail").click(function(){
		$("#info_tebus").hide();
		$("#pencarian_batal").show();
		$("#tampil_data_batal").show();
	});
});
</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='#data'>DAFTAR PENEBUSAN DO</a></li>
		   <li><a href='#outstand'>OUTSTANDING DO</a></li>
		   <li><a href='#batal'>BATAL PENEBUSAN DO</a></li>
      </ul>";
	
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='batal'>
		<div id='pencarian_batal'>
			<table width='100%'>
				<tr>
					<td>Penebusan tanggal : <input type='date' name='t_tglawal' id='t_tglawal' size='10'> Sampai dengan <input type='date' name='t_tglakhir' id='t_tglakhir' size='10'></td>
					<td>
						<button name='cari_batal' id='cari_batal'>Cari</button>
						<button name='tutup_batal' id='tutup_batal'>Tutup</button>
					</td>
				</tr>
			</table>
		</div>
		
		<div id='tampil_data_batal' align='center' style='overflow-x: auto;height: 400px;scroll-behavior: smooth'></div>
		
		<div id='info_tebus'>
			<table width='100%'>	
				<tr>
					<td width='9%'>Kode Transaksi</td>
					<td width='11%'>: <input type='text' name='bt_kode' id='bt_kode' size='12' readonly class='input' ></td>
					<td width='18%'>Tanggal : <input type='date' name='bt_tanggal' id='bt_tanggal' size='10' ></td>
					<td width='6%'>Nomor SA</td>
					<td width='18%'>: <input type='text' name='bt_nomorsa' id='bt_nomorsa' size='15' class='input'></td>
					<td>Rekening Bank : <input type='text' name='bt_namabank' id='bt_namabank' size='30'>
						<input type='text' name='bt_nobank' id='bt_nobank' size='5' readonly />
					</td>
				</tr>
			</table>
	
			<table width='100%'>
				<tr>
					<td width='9%'>SPBE</td>
					<td width='29%'>: <input name='bt_kodesp' id='bt_kodesp' class='input' > <input name='bt_namasp' id='bt_namasp' class='input' ></td>
					<td width='24%'>Jumlah Unit : <input type='text' name='bt_jmlunit' id='bt_jmlunit' size='6' class='input' ></td>
					<td>Harga Beli : <input type='text' name='bt_hgbeli' id='bt_hgbeli' size='9' class='input'></td>
					<td>Jumlah Harga : <input type='text' name='bt_jumlah' id='bt_jumlah' size='12' class='input' readonly /></td>
				</tr>
			</table>
	
			<table width='100%'>
				<tr>
					<td width='9%'>Jumlah Setor</td>
					<td width='29%'>: <input type='text' name='bt_setor' id='bt_setor' size='12' class='input' ></td>
					<td>Pembulatan : <input type='text' name='bt_bulat' id='bt_bulat' size='9' class='input' readonly /></td>
					<td>
						<button name='batal_tebus' id='batal_tebus'>Batal</button>	
						<button name='tutup_detail' id='tutup_detail'>Tutup</button>
					</td>
				</tr>
			</table>
		</div>
	</div>";

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

echo "</div>";
?>
