<script type="text/javascript">
$(document).ready(function() {	
	$("#tabs").tabs({selected:0});			
	$("#info_beli").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);
			}
		});
	}
		
	$("#data").load('modul/report/daftar_pb.php');
	
	$("#cari_data").click(function(){
		var tgl_awal  = $("#txt_tglaw").val();
		var tgl_akhir = $("#txt_tglak").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;
		}
		$("#info_beli").hide();
		$("#tampil_data").show();
		$("#tampil_data").load('spv/pembelian/tampil_data.php?tgl_awal='+tgl_awal+'&tgl_akhir='+tgl_akhir);
	});
	
	$("#batal").click(function(){
		var kode	= $("#t_kodepb").val();
		var kodesup	= $("#t_kodesup").val();		
		var total	= $("#t_total").val();	
		var potong	= $("#t_potong").val();
		var bayar	= $("#t_bayar").val();		
		var kurang	= $("#t_kurang").val();
		var tgl_awal = $("#txt_tglaw").val();
		var tgl_akhir= $("#txt_tglak").val();
		var pilih = confirm('Apakah Anda sungguh-sungguh ingin batalkan '+kode+' ini ?');
		
		if (pilih==true) {			
				
			$.ajax({
				type	: "POST",
				url		: "spv/pembelian/batal.php",
				data	: "kode="+kode+
					"&kodesup="+kodesup+					
					"&total="+total+
					"&potong="+potong+
					"&bayar="+bayar+
					"&kurang="+kurang,
				timeout: 2000,
				beforeSend	: function(){		
					$("#info").html("<img src='loading.gif' />");			
				},
				success	: function(data){
					$("#info").html(data);					
					$("#info_beli").hide();
					$("#tampil_detail").hide();
					$("#pencarian").show();
					$("#tampil_data").show();
					$("#tampil_data").load('spv/pembelian/tampil_data.php?tgl_awal='+tgl_awal+'&tgl_akhir='+tgl_akhir);
				}
			});
		}
	});
		
	$("#tutup_detail").click(function(){
		$("#pencarian").show();
		$("#info_beli").hide();
		$("#tampil_detail").hide();
		$("#tampil_data").show();		
	});
	
	$("#tutup_batal").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 PEMBELIAN BARANG</a></li>
		   <li><a href='#form_batal'>BATAL PEMBELIAN</a></li>
      </ul>";
	  
echo "<div id='data'></div>";
	  
echo "<div id='form_batal'>
			<div id='pencarian'>
				<table width='100%'>
				<tr>
					<td width='17%'>Pembelian tanggal</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='5%'></td>
					<td align='right'>
						<button name='cari_data' id='cari_data'>Cari</button>
						<button name='tutup_batal' id='tutup_batal'>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_beli'>
				<table width='100%'>
				<tr>
					<td>Kode</td>
					<td>:</td>
					<td><input type='text' name='t_kodepb' id='t_kodepb' size='7' readonly></td>										
					<td width='20%'>No.Faktur</td>
					<td>:</td>
					<td><input type='text' name='t_nomorfk' id='t_nomorfk' size='8' readonly></td>
					<td></td>
					<td>Tanggal</td>
					<td>:</td>
					<td><input type='date' name='t_tanggal' id='t_tanggal' size='9' readonly /></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='20' readonly />
					</td>
				</tr>
				</table>
				
				<table>
				<tr>
					<td>Total : <input type='text' name='t_total' id='t_total' class='input_header' size='10' readonly /></td>
					<td>Potongan : <input type='text' name='t_potong' id='t_potong' class='input_header' size='10' readonly /></td>
					<td>Dibayar : <input type='text' name='t_bayar' id='t_bayar' class='input_header' size='9' readonly/> </td>					
					<td width='7.5%'>Kurang : <input type='text' name='t_kurang' id='t_kurang' class='input_header' size='9' readonly/></td>
					<td width='19%'></td>
					<td>
						<button name='batal' id='batal'>Batal</button>
						<button name='tutup_detail' id='tutup_detail'>Tutup</button>
					</td>
				</tr>
				</table>						
			</div>
			
			<div id='tampil_detail' align='center' style='overflow-x: auto;height: 400px;scroll-behavior: smooth'></div>
		</div>";

echo "</div>";
?>
