<script type="text/javascript">	
$(document).ready(function() {	
	$("#tabs").tabs({selected:0});		
	$("#data").load('modul/report/daftar_pj.php');
	$("#info_jual").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);
			}
		});
	}
	
	$("#cari_data").click(function(){
		var tgl_awal = $("#txt_tglaw").val();
		var tgl_akhir = $("#txt_tglak").val();
		
		if(tgl_awal.length==''){
			return false;
			alert('Maaf, Variabel tanggal belum lengkap');
			$("#txt_tglaw").focus();
		}
		if(tgl_akhir.length==''){
			alert('Maaf, Variabel tanggal belum lengkap');
			$("#txt_tglak").focus();
			return false;
		}
		$("#info_jual").hide();
		$("#tampil_data").show();
		$("#tampil_data").load('spv/penjualan/tampil_data.php?tgl_awal='+tgl_awal+'&tgl_akhir='+tgl_akhir);
	});

	$("#batal_pj").click(function(){
		var kode	  = $("#t_kode").val();
		var tgl_awal  = $("#txt_tglaw").val();
		var tgl_akhir = $("#txt_tglak").val();
		
		var pilih = confirm('Apakah Anda sungguh-sungguh ingin batalkan '+kode+' ?');
		
		if (pilih==true){
			var	kodeplg	= $("#t_kodeplg").val();
			var	total	= $("#t_total").val();
			var	tbayar	= $("#t_bayar").val();
			var tkurang	= $("#t_kurang").val();
			var thpp	= $("#t_thpp").val();

			$.ajax({
				type	: "POST",
				url		: "spv/penjualan/batal.php",
				data	: "kode="+kode+
					"&kodeplg="+kodeplg+
					"&total="+total+
					"&tbayar="+tbayar+
					"&tkurang="+tkurang+
					"&thpp="+thpp,
				timeout		: 2000,
				beforeSend	: function(){		
					$("#info").html("<img src='loading.gif' />");			
				},
				success	: function(data){
					$("#info").html(data);			
					$("#info_jual").hide();
					$("#tampil_detail").hide();
					$("#pencarian").show();
					$("#tampil_data").show();
					$("#tampil_data").load('spv/penjualan/tampil_data.php?tgl_awal='+tgl_awal+'&tgl_akhir='+tgl_akhir);
				}
			});
		}
	});
	
	$("#tutup_detail").click(function(){
		$("#pencarian").show();
		$("#info_jual").hide();
		$("#tampil_detail").hide();
		$("#tampil_data").show();		
	});
	
	$("#tutup_pj").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 PENJUALAN</a></li>		   
	       <li><a href='#form_batal'>BATAL PENJUALAN</a></li>
      </ul>";
	  
echo "<div id='data'></div>";

echo "<div id='form_batal'>
		<div id='pencarian'>
			<table width='100%'>
				<tr>
					<td>Penjualan 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_pj' id='tutup_pj'>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_jual'>
			<table width='100%'>
				<tr>					
					<td>No.Faktur : <input type='text' id='t_kode' size='12' class='input_header' readonly/></td>
					<td>Tanggal : <input type='date' id='t_tanggal' size='10' class='input_header' readonly/></td>
					<td>Pelanggan : <input type='text' id='t_namaplg' size='23' class='input_header'>
						<input type='text' id='t_kodeplg' size='3' class='input_header' readonly />
					</td>
					<td>Jatuh Tempo : <input type='text' id='t_jttempo' size='2' class='input_header'> hari 
					    <input type='date' id='t_tanggaljt' size='10' class='input_header' readonly />
					</td>
				</tr>
				<tr>
					<td>Total : <input style='color:maroon' align='right' type='text' name='t_total' id='t_total' class='input_bayar' size='9' readonly /></td>
					<td>Dibayar : <input align='right' type='text' name='t_bayar' id='t_bayar' class='input_bayar' size='9' maxlength='10'></td>
					<td>Kurang bayar : <input style='color:maroon' align='right' type='text' name='t_kurang' id='t_kurang' class='input_bayar' size='9' readonly /></td>
					<td>
						<button id='batal_pj'>Batal</button>
						<button 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 id='form_cari_plg' title='Pencarian Data Pelanggan'>
		<table width='100%'>
			<tr>
				<td width='20%'>Cari Pelanggan</td>
				<td width='2%'>:</td>
				<td><input type='text' name='txt_cariplg' id='txt_cariplg' size='40'</td>
			</tr>
		</table>
		<div id='info_pelanggan' align='center' style='overflow-x: auto;height: 400px;scroll-behavior: smooth'></div>
	</div>";
	
echo "<div id='info' align='center'></div>";

echo "</div>";
?>
