<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);
			}
		});
	}
	
	$("#txt_kodepj").keyup(function(){
		var tgl_awal = $("#txt_tglaw").val();
		var tgl_akhir= $("#txt_tglak").val();
		var kodepj   = $("#txt_kodepj").val();
		var kodecab  = $("#b_kodecab").val();
				
		$("#info_jual").hide();
		$("#tampil_data").show();
		$("#tampil_data").load('spv/penjualan/tampil_data.php?tgl_awal='+tgl_awal+'&tgl_akhir='+tgl_akhir+'&kodepj='+kodepj+'&kodecab='+kodecab);
	});
	
	$("#cari_data").click(function(){
		var tgl_awal = $("#txt_tglaw").val();
		var tgl_akhir= $("#txt_tglak").val();
		var kodepj   = $("#txt_kodepj").val();
		var kodecab  = $("#b_kodecab").val();
				
		$("#info_jual").hide();
		$("#tampil_data").show();
		$("#tampil_data").load('spv/penjualan/tampil_data.php?tgl_awal='+tgl_awal+'&tgl_akhir='+tgl_akhir+'&kodepj='+kodepj+'&kodecab='+kodecab);
	});

	$("#batal_pj").click(function(){
		var kode		= $("#t_kodepj").val();
		var kodecab     = $("#t_kodecab").val();
		var tgl_awal  	= $("#txt_tglaw").val();
		var tgl_akhir 	= $("#txt_tglak").val();
		
		var pilih = confirm('Apakah Anda sungguh-sungguh ingin batalkan faktur '+kode+' ?');
		
		if (pilih==true){
			var kodepl	= $("#t_kodepl").val();
			var jenisby	= $("#t_jenisby").val();
			var nobank 	= $("#t_nobank").val();
			var total	= $("#t_total").val();			
			var charge	= $("#t_charge").val();
			var tbayar	= $("#t_bayar").val();
			var tpotong	= $("#t_potong").val();
			var thpp	= $("#t_thpp").val();
						
			$.ajax({
				type	: "POST",
				url		: "spv/penjualan/batal.php",
				data	: "kode="+kode+
				    "&kodecab="+kodecab+
					"&kodepl="+kodepl+
					"&jenisby="+jenisby+
					"&nobank="+nobank+
					"&total="+total+
					"&charge="+charge+
					"&tbayar="+tbayar+
					"&tpotong="+tpotong+
					"&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").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
include '../../inc/inc.koneksi.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>Cabang : <select id='b_kodecab'>";
				        $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_pj'>Tutup</button>
					</td>
					<td>Nomor Nota : <input type='text' id='txt_kodepj' size='15'></td>
				</tr>
			</table>
		</div>
			
		<div id='tampil_data' align='center'></div>
			
		<div id='info_jual'>
			<table>
				<tr>
				    <input type='text' id='t_kodecab' size='13' hidden/>
					<td>No.Faktur : <input type='text' name='t_kodepj' id='t_kodepj' size='13' readonly></td>
					<td>Tanggal : <input type='date' name='t_tanggal' id='t_tanggal' size='10' readonly></td>
					<td>Kasir : <input type='text' name='t_user' id='t_user' size='3' readonly></td>
					<td>Member : <input type='text' id='t_namamb' size='25' readonly />
						<input type='text' id='t_kodepl' size='3' readonly />
					</td>
					<td>Jenis Bayar : <input type='text' id='t_jenisby' size='15' readonly/></td>
					<td>Bank : <input type='text' id='t_nobank' size='10' readonly/></td>
				</tr>
			</table>
				
			<table>
				<tr>					
					<input type='text' id='t_thpp' class='input_header' hidden />
					<input type='text' id='t_poin' class='input_header' hidden />
					<td>Total : <input type='text' id='t_total' class='input_header' size='10' readonly /></td>
					<td>Potongan : <input type='text' id='t_potong' class='input_header' size='10' readonly /></td>					
					<td>Charge : <input type='text' id='t_charge' class='input_header' size='10' readonly /></td>
					<td>Dibayar : <input type='text' id='t_bayar' class='input_header' size='10'></td>
					<td>Kembali : <input type='text' id='t_kembali' class='input_header' size='10' readonly /></td>
					<td>
						<button name='batal_pj' id='batal_pj'>Batal</button>
						<button name='tutup_detail' id='tutup_detail'>Tutup</button>
					</td>
				</tr>
			</table>						
		</div>
			
		<div id='tampil_detail' align='center'></div>
	</div>";

echo "<div id='info' align='center'></div>";

echo "</div>";
?>