<script type="text/javascript">
$(document).ready(function(){
	$("#tabs").tabs({selected:0});
	$("#form").load('modul/ubahstatus/form.php');
	$("#info_psb").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_tgl_awal").val(data.tanggal);
				$("#t_tgl_akhir").val(data.tanggal);
				$("#txt_tglaw").val(data.tanggal);
				$("#txt_tglak").val(data.tanggal);
			}
		});
	}
	
	$('#cari_tgl').click(function(){
		var tglawal = $("#t_tgl_awal").val();
		var tglakhir= $("#t_tgl_akhir").val();
		var cari    = $("#txt_caribrg").val();
		var kodetk  = $("#t_kodetk").val();
		
		if(tglawal==''){
			alert('Maaf, tanggal awal belum diisi');
			return (false);
		}
		if(tglakhir==''){
			alert('Maaf, tanggal akhir belum diisi');
			return (false);
		}		
		$("#tampil_data_psb").show();
		$("#tampil_data_psb").load('modul/ubahstatus/tampil_data.php?tglawal='+tglawal+'&tglakhir='+tglakhir+'&cari='+cari+'&kodetk='+kodetk);
	});
		
	$("#cetak_psb").click(function(){
		var tglawal = $("#t_tgl_awal").val();
		var tglakhir= $("#t_tgl_akhir").val();
		var cari    = $("#txt_caripm").val();
		var kodetk  = $("#t_kodetk").val();
		
		if(tglawal==''){
			alert('Maaf, tanggal awal belum diisi');
			return (false);
		}
		if(tglakhir==''){
			alert('Maaf, tanggal akhir belum diisi');
			return (false);
		}
		
		window.location.href='modul/laporan/daftar_psb.php?tglawal='+tglawal+'&tglakhir='+tglakhir+'&cari='+cari+'&kodetk='+kodetk;
	});
		
	$("#tutup_psb").click(function(){
		document.location='?module=home';
	});
	
	$("#cari").click(function(){
		var tgl_awal = $("#txt_tglaw").val();
		var tgl_akhir= $("#txt_tglak").val();
		var kodetk   = $("#txt_kodetk").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_psb").hide();	
		$("#tampil_data").show();
		$("#tampil_data").load('spv/ubahstatus/tampil_data.php?tgl_awal='+tgl_awal+'&tgl_akhir='+tgl_akhir+'&kodetk='+kodetk);
	});
	
	$("#batal_rb").click(function(){
		var kode 	= $("#txt_kode").val();
		var kodetk  = $("#txt_kodetk").val();
		var kodest  = $("#txt_kodest").val();
		var jmlunit = $("#txt_jmlunit").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/ubahstatus/batal.php",
				data	: "kode="+kode+	
					"&kodetk="+kodetk+
					"&kodest="+kodest+
					"&jmlunit="+jmlunit,
				timeout: 2000,
				beforeSend	: function(){		
					$("#info").html("<img src='loading.gif' />");			
				},
				success	: function(data){
					$("#info").html(data);					
					$("#info_psb").hide();
					$("#tampil_detail").hide();
					$("#pencarian").show();
					$("#tampil_data").show();
					$("#tampil_data").load('spv/ubahstatus/tampil_data.php?tgl_awal='+tgl_awal+'&tgl_akhir='+tgl_akhir+'&kodetk='+kodetk);
				}
			});
		}
		return false; 		
	});
	
	$("#tutup_detail").click(function(){
		$("#pencarian").show();
		$("#info_psb").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_psb'>DAFTAR PERUBAHAN STATUS</a></li>
		<li><a href='#form_batal'>BATAL PERUBAHAN STATUS</a></li>
	</ul>";

	echo "<div id='data_psb'>
			<div id='pencarian_psb'>
				<fieldset>
				<legend>Filter Data</legend>
				<table>
				<tr>
					<td>Unit Usaha : <select name='t_kodetk' id='t_kodetk'>";
						$sql= mysql_query("SELECT * FROM toko ");
						while($r=mysql_fetch_array($sql)){
							echo "<option value='$r[kode_tk]'>$r[kode_tk] - $r[nama_tk]</option>";
						}
						echo "</select>
					</td>
					
					<td>Tanggal : <input type='date' name='t_tgl_awal' id='t_tgl_awal' size='10'></td>
					<td>Sampai dengan <input type='date' name='t_tgl_akhir' id='t_tgl_akhir' size='10'></td>
				</tr>
				</table>
				
				<table width='100%'>
				<tr>
					<td>Cari barang :<input type='text' name='txt_caribrg' id='txt_caribrg' size='40'></td>
					<td align='center'>
						<button name='cari_tgl' id='cari_tgl'>Cari</button>
						<button name='cetak_psb' id='cetak_psb'>Cetak</button>
						<button name='tutup_psb' id='tutup_psb'>Tutup</button>
					</td>
				</tr>
				</table>
				
				</fieldset>
			</div><br>
			
			<div id='tampil_data_psb' align='center'></div>
		</div>";
	
	echo "<div id='form_batal'>
			<div id='pencarian'>
				<table width='100%'>
				<tr>
					<td>Tanggal PSB : <input type='date' name='txt_tglaw' id='txt_tglaw' size='10'></td>
					<td>Sampai dengan <input type='date' name='txt_tglak' id='txt_tglak' size='10'></td>
					<td>Unit Usaha : <select name='txt_kodetk' id='txt_kodetk'>";
						$sql= mysql_query("SELECT * FROM toko ");
						while($r=mysql_fetch_array($sql)){
							echo "<option value='$r[kode_tk]'>$r[kode_tk] - $r[nama_tk]</option>";
						}
						echo "</select>
					</td>
				</table>
				<table width='100%'>
					<td align='center'>
						<button name='cari' id='cari'>Cari</button>
						<button name='tutup' id='tutup'>Tutup</button>
					</td>
				</tr>
				</table>
			</div>
			
			<div id='tampil_data' align='center'></div>
			
			<div id='info_psb'>
			<table width='100%'>
				<tr>
					<input type='text' name='txt_total' id='txt_total' class='input_header' hidden />
					<td>Kode Transaksi : <input type='text' name='txt_kode' id='txt_kode' class='input_header' size='15' readonly />
					<td>Tanggal : <input type='date' name='txt_tanggal' id='txt_tanggal' class='input_header' readpnly/></td>
					<td align='right'>Nilai : <input type='text' name='txt_jumlahasl' id='txt_jumlahasl' class='input_header' size='10' readonly/>
				</tr>
			</table>
	
			<table width='100%'>
				<tr>
					<td width='14%'>Nama Barang</td>
					<td>: <input type='text' name='txt_namast' id='txt_namast' class='input_header' size='20' readonly/>
						<input type='text' name='txt_kodest' id='txt_kodest' class='input_header' size='8' readonly />
					</td>
					<td>Jumlah</td>
					<td>: <input type='text' name='txt_jmlunit' id='txt_jmlunit' class='input_header' size='9' readonly/>
						<input type='text' name='txt_satuan' id='txt_satuan' class='input_header' size='5' readonly/>
					</td>
					<td>Selisih</td>
					<td>: <input type='text' name='txt_selisih' id='txt_selisih' class='input_header' size='10' readonly/>
				</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'></div>
		</div>";
			
	echo "<div id='info' align='center'></div>";
	
echo "</div>";
?>
