<script type="text/javascript">	
$(document).ready(function() {	
	$("#tabs").tabs({selected:0});	
	$("#info_mbr").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 gdtjn  	  = $("#b_gdtjn").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/mutasi_br/tampil_data.php?tgl_awal='+tgl_awal+'&tgl_akhir='+tgl_akhir+'&gdtjn='+gdtjn);
	});
	
	$("#batal_mbr").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 mutasi barang kode '+kode+' ini ?');
		
		if(pilih==true){
			$.ajax({
				type	: "POST",
				url		: "spv/mutasi_br/batal.php",
				data	: "kode="+kode,
				timeout: 2000,
				beforeSend	: function(){		
					$("#info").html("<img src='loading.gif' />");			
				},
				success	: function(data){
					$("#info").html(data);					
					$("#info_mbr").hide();
					$("#tampil_detail").hide();
					$("#pencarian").show();
					$("#tampil_data").show();
					$("#tampil_data").load('spv/mutasi_br/tampil_data.php?tgl_awal='+tgl_awal+'&tgl_akhir='+tgl_akhir);
				}
			});
		}
	});
		
	$("#tutup_detail").click(function(){
		$("#pencarian").show();
		$("#info_mbr").hide();
		$("#tampil_detail").hide();
		$("#tampil_data").show();		
	});
	
	$("#tutup_batal").click(function(){
		document.location='?module=home';
	});

	$("#cari_mbr").click(function(){
		var tgl_awal = $("#t_tglawal").val();
		var tgl_akhir= $("#t_tglakhir").val();
		var gdtjn  	 = $("#t_gdtjn").val();
		var cari   	 = $("#txt_carist").val();

		$.ajax({
			type	: "GET",
			url	    : "md_gdg/mutasi_br/tampil_daftar.php",
			data	: "cari="+cari+
				"&gdtjn="+gdtjn+
				"&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 gdtjn  	 = $("#t_gdtjn").val();
		var cari   	 = $("#txt_carist").val();
		
		$.ajax({
			type	: "GET",
			url	    : "md_gdg/mutasi_br/tampil_daftar.php",
			data	: "cari="+cari+
				"&gdtjn="+gdtjn+
				"&tgl_awal="+tgl_awal+
				"&tgl_akhir="+tgl_akhir,
			success	: function(data){
				$("#tampil_daftar").html(data);
			}
		});
	});
	
	$("#cetak_mbr").click(function(){
		var tgl_awal = $("#t_tglawal").val();
		var tgl_akhir= $("#t_tglakhir").val();
		var gdtjn  	 = $("#t_gdtjn").val();
		var cari   	 = $("#txt_carist").val();
		
		window.location.href='modul/laporan/daftar_mbgd.php?gdtjn='+gdtjn+'&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 gdtjn  	  = $("#rec_gdtjn").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/mutasi_br/tampil_data_rec.php?tgl_awal='+tgl_awal+'&tgl_akhir='+tgl_akhir+'&gdtjn='+gdtjn);
	});
	
	$("#recov_mbr").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/mutasi_br/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/mutasi_br/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 PEMINDAHAN BARANG</a></li>
		<li><a href='#data'>DAFTAR PEMINDAHAN BARANG</a></li>
		<li><a href='#form_recover'>RECOVER BATAL PEMINDAHAN</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 Tujuan :  <select id='b_gdtjn'>
					        <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_mbr'>
			<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 Tujuan :  <input typr='text' id='txt_gdtujuan' 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_mbr'>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>Pemindahan tanggal : <input type='date' id='t_tglawal' size='10'> Sampai dengan <input type='date' id='t_tglakhir' size='10'></td>
					<td>Gudang Tujuan :  <select id='t_gdtjn'>
					        <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_mbr'>Cari</button>
						<button id='cetak_mbr'>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 Tujuan :  <select id='rec_gdtjn'>
					        <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 Tujuan :  <input type='text' id='rec_gdtujuan' 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_mbr'>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>";
?>
