<script type="text/javascript">	
$(document).ready(function() {	
	$("#tabs").tabs({selected:0});		
	$("#data").load('modul/report/daftar_rb.php');
	$("#tampil_data").load('spv/returbeli/tampil_data.php');
	$("#tampil_data").hide();
	$("#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 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+					
					"&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").load('spv/returbeli/tampil_data.php?tgl_awal='+tgl_awal+'&tgl_akhir='+tgl_akhir);
				}
			});
		}
		return false; 		
	});
	
	$("#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 width='13%'>Tanggal retur</td>
					<td width='2%'>:</td>
					<td><input type='date' name='txt_tglaw' id='txt_tglaw' size='10'></td>
					<td width='15%'>Sampai dengan</td>
					<td><input type='date' name='txt_tglak' id='txt_tglak' size='10'></td>
					<td width='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='11%'>Kode Retur</td>
					<td>:</td>
					<td><input type='text' name='t_kode' id='t_kode' size='8' readonly /></td>
					<td width='1%'></td>
					<td>Tanggal</td>
					<td>:</td>
					<td><input type='date' name='t_tanggal' id='t_tanggal' size='10' readonly /></td>		
					<td width='1%'></td>
					<td>Supplier</td>
					<td>:</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>
			</table>
	
			<table>
			<tr>				
				<td width='11%'>No. Faktur</td>
				<td>:</td>
				<td><input type='text' name='t_nomorfk' id='t_nomorfk' size='9' readonly />
					<img src='images/view.png' width='18' height='18' title='Cari Faktur' id='cari_faktur'>
				</td>
				<td width='2%'></td>
				<td>Tanggal Faktur</td>
				<td>:</td>
				<td><input type='date' name='t_tanggalfk' id='t_tanggalfk' size='10' readonly /></td>
				<td width='1.3%'></td>
				<td>Cara Pengembalian :</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>";
		
echo "<div id='info' align='center'></div>";

echo "</div>";
?>