<script type="text/javascript">	
$(document).ready(function() {	
	$("#tabs").tabs({selected:0});		
	$("#data").load('modul/report/daftar_rb.php');
	$("#info_retur").hide();
	
	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_tglaw").val(data.tanggal);
				$("#txt_tglak").val(data.tanggal);				
			}
		});
	}
	
	$("#cari_tgl").click(function(){
		var tgl_awal	= $("#txt_tglaw").val();
		var tgl_akhir	= $("#txt_tglak").val();
		
		if(tgl_awal.length==''){
			alert('Maaf, Variabel tanggal belum lengkap');
			$("#txt_tglaw").focus();
			return false;
		}
		if(tgl_akhir.length==''){
			alert('Maaf, Variabel tanggal belum lengkap');
			$("#txt_tglak").focus();
			return false;
		}
		$("#info_retur").hide();	
		$("#tampil_data").show();
		$("#tampil_data").load('spv/returbeli/tampil_data.php?tgl_awal='+tgl_awal+'&tgl_akhir='+tgl_akhir);
	});
	
	$("#batal_rb").click(function(){
		var kode 	= $("#t_kode").val();
		var kodesup = $("#t_kodesup").val();
		var nomorfk = $("#t_nomorfk").val();
		var total 	= $("#t_total").val();
		var caraby 	= $("#t_caraby").val();
		var pilih 	= confirm('Apakah Anda sungguh-sungguh ingin batalkan '+kode+' ?');
		
		if(pilih==true){
			var tgl_awal 	= $("#txt_tglaw").val();
			var tgl_akhir 	= $("#txt_tglak").val();
				
			$.ajax({
				type	: "POST",
				url		: "spv/returbeli/batal.php",
				data	: "kode="+kode+					
					"&kodesup="+kodesup+
					"&nomorfk="+nomorfk+
					"&total="+total+
					"&caraby="+caraby,
				timeout: 2000,
				beforeSend	: function(){		
					$("#info").html("<img src='loading.gif' />");			
				},
				success	: function(data){
					$("#info").html(data);					
					$("#info_retur").hide();
					$("#tampil_detail").hide();
					$("#pencarian").show();
					$("#tampil_data").show();
					$("#tampil_data").load('spv/returbeli/tampil_data.php?tgl_awal='+tgl_awal+'&tgl_akhir='+tgl_akhir);
				}
			});
		}
	});
	
	$("#tutup_detail").click(function(){
		$("#pencarian").show();
		$("#info_retur").hide();
		$("#tampil_detail").hide();
		$("#tampil_data").show();		
	});
	
	$("#tutup").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='#data'>DAFTAR RETUR PEMBELIAN</a></li>
		   <li><a href='#form_batal'>BATAL RETUR PEMBELIAN</a></li>
      </ul>";
	  
echo "<div id='data'></div>";
	
echo "<div id='form_batal'>
		<div id='pencarian'>
			<table width='100%'>
				<tr>
					<td>Tanggal retur : <input type='date' name='txt_tglaw' id='txt_tglaw' size='10'> sampai dengan <input type='date' name='txt_tglak' id='txt_tglak' size='10'></td>					
					<td align='right'>
						<button name='cari_tgl' id='cari_tgl'>Cari</button>
						<button name='tutup' id='tutup'>Tutup</button>
					</td>
				</tr>
			</table>
		</div>
			
		<div id='tampil_data' align='center' style='overflow-x: auto;height: 400px;scroll-behavior: smooth'></div>
			
		<div id='info_retur'>
			<table>
				<tr>
					<input type='text' name='t_total' id='t_total' size='9' hidden />
					<td width='8%'>Kode Retur</td>
					<td width='17%'>: <input type='text' name='t_kode' id='t_kode' size='12' readonly /></td>					
					<td width='10%'>Tanggal</td>
					<td width='12%'>: <input type='date' name='t_tanggal' id='t_tanggal' size='10' readonly /></td>					
					<td width='8%'>Supplier</td>
					<td>: <input type='text' name='t_kodesup' id='t_kodesup' size='3' readonly/>
						<input type='text' name='t_namasup' id='t_namasup' size='22' readonly/>
					</td>
				</tr>			
				<tr>				
					<td>No. Faktur</td>
					<td>: <input type='text' id='t_nomorfk' size='14' readonly/></td>
					<td>Tanggal Faktur</td>
					<td>: <input type='date' name='t_tanggalfk' id='t_tanggalfk' size='10' readonly /></td>				
					<td>Cara Bayar</td>
					<td>: <input type='text' name='t_caraby' id='t_caraby' size='8' readonly /></td>
				</tr>
			</table>
			<hr>
			
			<table align='center'>
				<tr>
					<td>
						<button name='batal_rb' id='batal_rb'>Batal</button>
						<button name='tutup_detail' id='tutup_detail'>Tutup Detail</button>
					</td>
				</tr>
			</table>
	
			<div id='tampil_detail' align='center' style='overflow-x: auto;height: 400px;scroll-behavior: smooth'></div>
		</div>
	</div>";
		
echo "<div id='info' align='center'></div>";

echo "</div>";
?>