<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);
				$("#rec_tglaw").val(data.tanggal);
				$("#rec_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_pbl").click(function(){
		var kode	= $("#t_kodepb").val();
		var kodesup	= $("#t_kodesup").val();
		var nomorfk	= $("#t_nomorfk").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 pembelian kode '+kode+' ini ?');
		
		if(pilih==true){
			$.ajax({
				type	: "POST",
				url		: "spv/pembelian/batal.php",
				data	: "kode="+kode+
					"&kodesup="+kodesup+
					"&nomorfk="+nomorfk+
					"&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';
	});

	$("#cari_rec").click(function(){
		var tgl_awal  = $("#rec_tglaw").val();
		var tgl_akhir = $("#rec_tglak").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_detail_rec").hide();
		$("#tampil_data_rec").show();
		$("#tampil_data_rec").load('spv/pembelian/tampil_data_rec.php?tgl_awal='+tgl_awal+'&tgl_akhir='+tgl_akhir);
	});
	
	$("#rec_pbl").click(function(){
		var kode		= $("#rec_kodepb").val();		
		var tgl_awal 	= $("#rec_tglaw").val();
		var tgl_akhir	= $("#rec_tglak").val();
		
		var pilih = confirm('Apakah Anda sungguh-sungguh ingin merecover data pembelian kode '+kode+' ini ?');
		
		if(pilih==true){
			$.ajax({
				type	: "POST",
				url		: "spv/pembelian/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/pembelian/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='#data'>DAFTAR PEMBELIAN BARANG</a></li>
		   <li><a href='#form_batal'>BATAL PEMBELIAN</a></li>
		   <li><a href='#form_recover'>RECOVER DATA PEMBATALAN</a></li>
      </ul>";
	  
echo "<div id='data'></div>";
	  
echo "<div id='form_batal'>
		<div id='pencarian'>
			<table width='100%'>
				<tr>
					<td>Pembelian tanggal : <input type='date' name='txt_tglaw' id='txt_tglaw' size='10'> Sampai dengan <input type='date' name='txt_tglak' id='txt_tglak' size='10'></td>
					<td>
						<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: 450px;scroll-behavior: smooth'></div>
			
		<div id='info_beli'>
			<table width='100%'>
				<tr>
					<td>Kode Transaksi  : <input type='text' name='t_kodepb' id='t_kodepb' size='13' readonly></td>										
					<td>No.Faktur : <input type='text' name='t_nomorfk' id='t_nomorfk' size='8' readonly></td>
					<td>Tanggal : <input type='date' name='t_tanggal' id='t_tanggal' size='9' readonly /></td>
					<td>Supplier : <input type='text' name='t_kodesup' id='t_kodesup' size='4' readonly /> <input type='text' name='t_namasup' id='t_namasup' size='25' readonly /></td>
				</tr>
			</table>
			<table width='100%'>
				<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>Kurang : <input type='text' name='t_kurang' id='t_kurang' class='input_header' size='9' readonly/></td>
					<td>
						<button name='batal_pbl' id='batal_pbl'>Batal</button>
						<button name='tutup_detail' id='tutup_detail'>Kembali</button>
					</td>
				</tr>
			</table>						
		</div>
			
		<div id='tampil_detail' align='center' style='overflow-x: auto;height: 450px;scroll-behavior: smooth'></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>
						<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 width='100%'>
				<tr>
					<td>Kode Transaksi  : <input type='text' id='rec_kodepb' size='13' readonly></td>
					<td>No.Faktur : <input type='text' id='rec_nomorfk' size='13' readonly></td>
					<td>Tanggal : <input type='date' id='rec_tanggal' readonly /></td>
					<td>Supplier : <input type='text' id='rec_kodesup' size='3' readonly/> <input type='text' id='rec_namasup' size='25' readonly/></td>
				</tr>
			</table>
			<table width='100%'>
				<tr>
					<td>Total : <input type='text' id='rec_total' class='input_header' size='10' readonly /></td>
					<td>Potongan : <input type='text' id='rec_potong' class='input_header' size='10' readonly /></td>
					<td>Dibayar : <input type='text' id='rec_bayar' class='input_header' size='10' readonly/> </td>					
					<td>Kurang : <input type='text' id='rec_kurang' class='input_header' size='10' readonly/></td>
					<td>
						<button id='rec_pbl'>Recover</button>
						<button id='tutup_detail_rec'>Kembali</button>
					</td>
				</tr>
			</table>						
		</div>
			
		<div id='tampil_detail_rec' align='center' style='overflow-x: auto;height: 450px;scroll-behavior: smooth'></div>
	</div>";

echo "<div id='info'></div>";
		
echo "</div>";
?>
