<script type="text/javascript">	
$(document).ready(function() {	
	$("#tabs").tabs({selected:0});	
	$("#info_rmb").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){
				$("#t_tglawal").val(data.tanggal);
				$("#t_tglakhir").val(data.tanggal);
				$("#txt_tglaw").val(data.tanggal);
				$("#txt_tglak").val(data.tanggal);
				$("#rec_tglaw").val(data.tanggal);
				$("#rec_tglak").val(data.tanggal);
			}
		});
	}

	$("#cari_data").click(function(){
		var tgl_awal  = $("#txt_tglaw").val();
		var tgl_akhir = $("#txt_tglak").val();
		var gdasl  	  = $("#b_gdasl").val();
		
		if(tgl_awal.length==0){
			alert('Maaf, Variabel tanggal belum lengkap');
			$("#txt_tglaw").focus();
			return false;
		}
		if(tgl_akhir.length==0){
			alert('Maaf, Variabel tanggal belum lengkap');
			$("#txt_tglak").focus();
			return false;
		}
		$("#tampil_data").show();
		$("#tampil_data").load('spv/retur_mbr/tampil_data.php?tgl_awal='+tgl_awal+'&tgl_akhir='+tgl_akhir+'&gdasl='+gdasl);
	});
	
	$("#batal_rmb").click(function(){
		var kode		= $("#txt_kode").val();		
		var tgl_awal 	= $("#txt_tglaw").val();
		var tgl_akhir	= $("#txt_tglak").val();
		
		var pilih = confirm('Apakah Anda sungguh-sungguh ingin batalkan pengembalian barang kode '+kode+' ini ?');
		
		if(pilih==true){
			$.ajax({
				type	: "POST",
				url		: "spv/retur_mbr/batal.php",
				data	: "kode="+kode,
				timeout: 2000,
				beforeSend	: function(){		
					$("#info").html("<img src='loading.gif' />");			
				},
				success	: function(data){
					$("#info").html(data);					
					$("#info_rmb").hide();
					$("#tampil_detail").hide();
					$("#pencarian").show();
					$("#tampil_data").show();
					$("#tampil_data").load('spv/retur_mbr/tampil_data.php?tgl_awal='+tgl_awal+'&tgl_akhir='+tgl_akhir);
				}
			});
		}
	});
		
	$("#tutup_detail").click(function(){
		$("#pencarian").show();
		$("#info_rmb").hide();
		$("#tampil_detail").hide();
		$("#tampil_data").show();		
	});
	
	$("#tutup_batal").click(function(){
		document.location='?module=home';
	});

	$("#cari_rmb").click(function(){
		var tgl_awal = $("#t_tglawal").val();
		var tgl_akhir= $("#t_tglakhir").val();
		var gdasl  	 = $("#t_gdasl").val();
		var cari   	 = $("#txt_carist").val();

		$.ajax({
			type	: "GET",
			url	    : "md_gdg/retur_mbr/tampil_daftar.php",
			data	: "cari="+cari+
				"&gdasl="+gdasl+
				"&tgl_awal="+tgl_awal+
				"&tgl_akhir="+tgl_akhir,
			success	: function(data){
				$("#tampil_daftar").html(data);
			}
		});
	});
	
	$("#txt_carist").keyup(function(){
		var tgl_awal = $("#t_tglawal").val();
		var tgl_akhir= $("#t_tglakhir").val();
		var gdasl  	 = $("#t_gdasl").val();
		var cari   	 = $("#txt_carist").val();

		$.ajax({
			type	: "GET",
			url	    : "md_gdg/retur_mbr/tampil_daftar.php",
			data	: "cari="+cari+
				"&gdasl="+gdasl+
				"&tgl_awal="+tgl_awal+
				"&tgl_akhir="+tgl_akhir,
			success	: function(data){
				$("#tampil_daftar").html(data);
			}
		});
	});
	
	$("#cetak_rmb").click(function(){
		var tgl_awal = $("#t_tglawal").val();
		var tgl_akhir= $("#t_tglakhir").val();
		var gdasl  	 = $("#t_gdasl").val();
		var cari   	 = $("#txt_carist").val();
		
		window.location.href='modul/laporan/daftar_rmbgd.php?gdasl='+gdasl+'&tgl_awal='+tgl_awal+'&tgl_akhir='+tgl_akhir+'&cari='+cari;
	});
	
	$("#tutup").click(function(){
		document.location='?module=home';
	});
	
	$("#cari_rec").click(function(){
		var tgl_awal  = $("#rec_tglaw").val();
		var tgl_akhir = $("#rec_tglak").val();
		var gdasl  	  = $("#rec_gdasl").val();
		
		if(tgl_awal.length==0){
			alert('Maaf, Variabel tanggal belum lengkap');
			$("#rec_tglaw").focus();
			return false;
		}
		if(tgl_akhir.length==0){
			alert('Maaf, Variabel tanggal belum lengkap');
			$("#rec_tglak").focus();
			return false;
		}
		$("#info_rec").hide();
		$("#tampil_data_rec").show();
		$("#tampil_data_rec").load('spv/retur_mbr/tampil_data_rec.php?tgl_awal='+tgl_awal+'&tgl_akhir='+tgl_akhir+'&gdasl='+gdasl);
	});
	
	$("#recov_rmb").click(function(){
		var kode	 = $("#rec_kode").val();		
		var tgl_awal = $("#rec_tglaw").val();
		var tgl_akhir= $("#rec_tglak").val();
		
		var pilih = confirm('Apakah Anda sungguh-sungguh ingin merecover mutasi barang kode '+kode+' ini ?');
		
		if(pilih==true){
			$.ajax({
				type	: "POST",
				url	    : "spv/retur_mbr/recover.php",
				data	: "kode="+kode,
				timeout: 2000,
				beforeSend	: function(){		
					$("#info").html("<img src='loading.gif' />");			
				},
				success	: function(data){
					$("#info").html(data);					
					$("#info_rec").hide();
					$("#tampil_detail_rec").hide();
					$("#pencarian_rec").show();
					$("#tampil_data_rec").show();
					$("#tampil_data_rec").load('spv/retur_mbr/tampil_data_rec.php?tgl_awal='+tgl_awal+'&tgl_akhir='+tgl_akhir);
				}
			});
		}
	});
		
	$("#tutup_detail_rec").click(function(){
		$("#pencarian_rec").show();
		$("#info_rec").hide();
		$("#tampil_detail_rec").hide();
		$("#tampil_data_rec").show();
	});
	
	$("#tutup_rec").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_batal'>BATAL PENGEMBALIAN BARANG</a></li>
		<li><a href='#data'>DAFTAR PENGEMBALIAN BARANG</a></li>
		<li><a href='#form_recover'>RECOVER BATAL PENGEMBALIAN</a></li>
    </ul>";

echo "<div id='form_batal'>
		<div id='pencarian'>
			<table width='100%'>
				<tr>
					<td>Pembelian tanggal : <input type='date' id='txt_tglaw' size='10'> Sampai dengan <input type='date' id='txt_tglak' size='10'></td>
					<td>Gudang Asal :  <select id='b_gdasl'>
					        <option value=''></option>";
							$sql=mysql_query("SELECT * FROM cabang WHERE 1 ORDER BY kode_cab");
				            while($r=mysql_fetch_array($sql)){
				                $kodecab=$r[kode_cab];
				                echo "<option value='$kodecab'>$r[nama_cab]</option>";
				            }
			            echo "</select>
                   	</td>
					<td>
						<button id='cari_data'>Cari</button>
						<button id='tutup_batal'>Tutup</button>
					</td>
				</tr>
			</table>
		</div>
		<div id='tampil_data' align='center' style='overflow-x: auto;height: 450px;scroll-behavior: smooth'></div>
			
		<div id='info_rmb'>
			<table>
				<tr>
					<td>Kode Mutasi : <input type='text' id='txt_kode' size='14' readonly class='input_header'></td>
					<td>Tanggal : <input type='date' id='txt_tanggal' readonly  class='input_header' ></td>
					<td>Gudang Asal :  <input typr='text' id='txt_gdAsal' width='4' readonly ></td>
					<td>Petugas : <input type='text' id='txt_petugas' class='input_header' width='20' readonly></td>
				</tr>
			</table>
			<table width='100%'>
				<tr>
					<td align='center'>
						<button id='batal_rmb'>Batal</button>
						<button id='tutup_detail'>Kembali</button>
					</td>
				</tr>
			</table>
			<hr>
		</div>
			
		<div id='tampil_detail' align='center' style='overflow-x: auto;height: 450px;scroll-behavior: smooth'></div>
	</div>";

echo "<div id='data'>
        <div id='pencarian'>
			<table width='100%'>
				<tr>
					<td>PENGEMBALIAN tanggal : <input type='date' id='t_tglawal' size='10'> Sampai dengan <input type='date' id='t_tglakhir' size='10'></td>
					<td>Gudang Asal :  <select id='t_gdasl'>
					        <option value=''></option>";
							$sql=mysql_query("SELECT * FROM cabang WHERE 1 ORDER BY kode_cab");
				            while($r=mysql_fetch_array($sql)){
				                $kodecab=$r[kode_cab];
				                echo "<option value='$kodecab'>$r[nama_cab]</option>";
				            }
			            echo "</select>
                   	</td>
					<td>Cari barang : <input type='text' id='txt_carist' size='30'></td>
				</tr>
			</table>
			<table width='100%'>
				<tr>
					<td align='center'>
						<button id='cari_rmb'>Cari</button>
						<button id='cetak_rmb'>Cetak</button>
						<button id='tutup'>Tutup</button>
					</td>
				</tr>
			</table>
		</div>
		<div id='tampil_daftar' align='center'></div>
    </div>";
	
echo "<div id='form_recover'>
		<div id='pencarian_rec'>
			<table width='100%'>
				<tr>
					<td>Pembelian tanggal : <input type='date' id='rec_tglaw' size='10'> Sampai dengan <input type='date' id='rec_tglak' size='10'></td>
                    <td>Gudang Asal :  <select id='rec_gdasl'>
					        <option value=''></option>";
							$sql=mysql_query("SELECT * FROM cabang WHERE 1 ORDER BY kode_cab");
				            while($r=mysql_fetch_array($sql)){
				                $kodecab=$r[kode_cab];
				                echo "<option value='$kodecab'>$r[nama_cab]</option>";
				            }
			            echo "</select>
                   	</td>
					<td>
						<button id='cari_rec'>Cari</button>
						<button id='tutup_rec'>Tutup</button>
					</td>
				</tr>
			</table>
		</div>
		<div id='tampil_data_rec' align='center' style='overflow-x: auto;height: 450px;scroll-behavior: smooth'></div>
			
		<div id='info_rec'>
			<table>
				<tr>
					<td>Kode Mutasi : <input type='text' id='rec_kode' size='14' class='input_header' readonly/></td>
					<td>Tanggal : <input type='date' id='rec_tanggal' class='input_header' readonly/></td>
					<td>Gudang Asal :  <input type='text' id='rec_gdasal' size='4' readonly/></td>
					<td>Petugas : <input type='text' id='rec_petugas' class='input_header' size='20' readonly/></td>
				</tr>
			</table>
			<table width='100%'>
				<tr>
					<td align='center'>
						<button id='recov_rmb'>Recover</button>
						<button id='tutup_rec'>Kembali</button>
					</td>
				</tr>
			</table>
			<hr>
		</div>
			
		<div id='tampil_detail_rec' align='center' style='overflow-x: auto;height: 450px;scroll-behavior: smooth'></div>
	</div>";

echo "</div>";

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

?>