<script type="text/javascript">
	$(document).ready(function(){
		
	cari_itf();
	
	function cari_itf(){
		var no = 1;
		$.ajax({
			type	: "POST",
			url		: "modul/pener_kas/cari_itf.php",
			data	: "no="+no,
			dataType: "json",
			success	: function(data){
				$("#txt_piut").val(data.nopiut);
				$("#txt_persed").val(data.nopers);
				$("#txt_utang").val(data.noutdg);
				$("#txt_labapb").val(data.labapb);
				$("#txt_jual").val(data.jual);
				$("#txt_labrug").val(data.labrug);
			}
		});
	}

	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_tanggal").val(data.tanggal);
				$("#txt_tanggaljt").val(data.tanggal);
			}
		});
	}
	
	$("#txt_tanggal").focus();
		
	$('#form_cari_bkm').dialog({
		autoOpen: false,
		modal	: true,
		width: 600,
	});
		
	$('#cari_bkm').click(function(){
		$('#form_cari_bkm').dialog('open');
		
		var no=1;
		$.ajax({
			type	: "POST",
			url		: "modul/pener_kas/tampil_nobkm.php",
			data	: "no="+no,
			timeout	: 3000,
			beforeSend	: function(){		
				$("#info_km").html("<img src='loading.gif' />");			
			},				  
			success	: function(data){
				$("#info_km").html(data);				
			}
		});
	});
			
	$('#form_cari_kas').dialog({
		autoOpen: false,
		modal	: true,
		width: 600,
	});
		
	$('#txt_namakas').keyup(function(){		
		$('#form_cari_kas').dialog('open');
		$("#txt_carikas").focus();		
		return false;
	});
	
	$('#txt_namakas').click(function(){		
		$('#form_cari_kas').dialog('open');
		$("#txt_carikas").focus();		
		return false;
	});
	
	$("#txt_carikas").keyup(function(){
		var cari= $("#txt_carikas").val();
		
		var no=1;
		$.ajax({
			type	: "POST",
			url		: "modul/pener_kas/tampil_data_kas.php",
			data	: "cari="+cari,
			timeout	: 3000,
			beforeSend	: function(){		
				$("#info_kas").html("<img src='loading.gif' />");			
			},				  
			success	: function(data){
				$("#info_kas").html(data);				
			}
		});
	});
	
	$('#form_cari_akun').dialog({
		autoOpen: false,
		modal	: true,
		width: 600,
	});
	
	$('#txt_naakun').keyup(function(){		
		$('#form_cari_akun').dialog('open');
		$("#txt_caribb").focus();		
		return false;
	});
	
	$('#txt_naakun').click(function(){		
		$('#form_cari_akun').dialog('open');
		$("#txt_caribb").focus();		
		return false;
	});
	
	$("#txt_caribb").keyup(function(){
		var cari	= $("#txt_caribb").val();
				
		$.ajax({
			type	: "POST",
			url		: "modul/pener_kas/tampil_data_akun.php",
			data	: "cari="+cari,
			timeout	: 3000,
			beforeSend	: function(){		
				$("#info_bb").html("<img src='loading.gif' />");			
			},				  
			success	: function(data){
				$("#info_bb").show();
				$("#info_bb").html(data);
			}
		});
	});
	
	$('#form_cari_bp').dialog({
		autoOpen: false,
		modal	: true,
		width: 600,
	});
	
	$("#txt_namabp").keyup(function(){
		var adabp = $("#txt_adabp").val();
		var nobb = $("#txt_noakun").val();
		
		if(adabp==''){
			alert('Kode akun '+nobb+' tidak memiliki buku pembantu.');
			$("#txt_jumlah").focus();
			return (false);
		}else{
			$('#form_cari_bp').dialog('open');
			$("#txt_caribp").focus();		
			return false;
		}
	});
	
	$("#txt_namabp").click(function(){
		var adabp = $("#txt_adabp").val();
		var nobb = $("#txt_noakun").val();
		
		if(adabp==''){
			alert('Kode akun '+nobb+' tidak memiliki buku pembantu.');
			$("#txt_jumlah").focus();
			return (false);
		}else{
			$('#form_cari_bp').dialog('open');
			$("#txt_caribp").focus();		
			return false;
		}
	});
	
	$("#txt_caribp").keyup(function(){
		var cari = $("#txt_caribp").val();
		var nobb = $("#txt_noakun").val();
		var piut = $("#txt_piut").val();
		
		$.ajax({
			type	: "POST",
			url		: "modul/pener_kas/tampil_data_bp.php",
			data	: "cari="+cari+
					"&nobb="+nobb+
					"&piut="+piut,
			timeout	: 3000,
			beforeSend	: function(){		
				$("#info_bp").html("<img src='loading.gif' />");			
			},				  
			success	: function(data){
				$("#info_bp").html(data);				
			}
		});
	});
	
	$('#form_cari_pd').dialog({
		autoOpen: false,
		modal	: true,
		width: 600,
	});
	
	$("#txt_nofak").keyup(function(){
		var piut = $("#txt_piut").val();
		var nobb = $("#txt_noakun").val();
		
		if(piut==''){
			alert('Kode akun '+nobb+' bukan piutang dagang.');
			$("#txt_jumlah").focus();
			return (false);
		}else{
			$('#form_cari_pd').dialog('open');
			$("#txt_caripd").focus();		
			return false;
		}
	});
	
	$("#txt_nofak").click(function(){
		var piut = $("#txt_piut").val();
		var nobb = $("#txt_noakun").val();
		
		if(piut==''){
			alert('Kode akun '+nobb+' bukan piutang dagang.');
			$("#txt_jumlah").focus();
			return (false);
		}else{
			$('#form_cari_pd').dialog('open');
			$("#txt_caripd").focus();		
			return false;
		}
	});
	
	$("#txt_caripd").keyup(function(){
		var cari = $("#txt_caripd").val();
		var nobp = $("#txt_nobp").val();
		
		$.ajax({
			type	: "POST",
			url		: "modul/pener_kas/tampil_data_pd.php",
			data	: "cari="+cari+
					"&nobp="+nobp,
			timeout	: 3000,
			beforeSend	: function(){		
				$("#info_pd").html("<img src='loading.gif' />");
			},				  
			success	: function(data){
				$("#info_pd").html(data);
			}
		});
	});
	
	$("#simpan").click(function(){
		simpan_data();
	});
			
	function simpan_data(){
		var	kode	= $("#txt_kode").val();
		var	tanggal	= $("#txt_tanggal").val();
		var	nokas   = $("#txt_nokas").val();		
		var	nakas  	= $("#txt_namakas").val();		
		var	idbkm  	= $("#txt_idbkm").val();
		var	noakun	= $("#txt_noakun").val();
		var	nobp  	= $("#txt_nobp").val();
		var	nofak 	= $("#txt_nofak").val();
		var	naakun 	= $("#txt_naakun").val();
		var	namabp 	= $("#txt_namabp").val();
		var	ket    	= $("#txt_ket").val();
		var	jumlah	= $("#txt_jumlah").val();
		
		var error = false;

		if(tanggal.length == 0){
           var error = true;
           alert("Maaf, Tanggal BKM tidak boleh kosong.");
		   return (false);
        }
		
		if(nokas.length == 0){
			var error = true;
			alert("Maaf, Nomor akun kas masih kosong");
			$("#txt_nokas").focus();
			return (false);
        }
		
		if(noakun.length == 0){
           var error = true;
           alert("Maaf, Kode Akun  tidak boleh kosong");
		   $("#txt_noakun").focus();
		   return (false);
        }
		
		if(nobp.length == 0){
			var adabp = $("#txt_adabp").val();
			
			if(!adabp==''){
				var error = true;
				alert("Maaf, Anda belum memilih kode Buku Pembantu.");
				$("#txt_noakun").focus();
				return (false);
			}
        }
		
		if(nofak.length == 0){
			var piut = $("#txt_piut").val();
			
			if(noakun==piut){
				var error = true;
				alert("Maaf, Untuk akun piutang dagang, Nomor faktur tidak boleh kosong.");
				$("#txt_noakun").focus();
				return (false);
			}
        }
		
		if(ket.length == 0){
           var error = true;
           alert("Maaf, Kolom keterangan tidak boleh kosong");
		   $("#txt_ket").focus();
		   return (false);
         }
		 
		if(jumlah.length == 0){
			var error = true;
			alert("Maaf, Kolom jumlah tidak boleh kosong.");
			$("#txt_jumlah").focus();
			return (false);
        }
		 
		if(error == false){
		$.ajax({
			type	: "POST",
			url		: "modul/pener_kas/simpan.php",
			data	: "kode="+kode+
					"&tanggal="+tanggal+
					"&nokas="+nokas+
					"&nakas="+nakas+					
					"&idbkm="+idbkm+
					"&noakun="+noakun+
					"&nobp="+nobp+
					"&naakun="+naakun+
					"&namabp="+namabp+
					"&nofak="+nofak+
					"&ket="+ket+					
					"&jumlah="+jumlah,
								
			timeout	: 2000,
			beforeSend	: function(){		
				$("#info").html("<img src='loading.gif' />");			
			},				  
			success	: function(data){
				$("#info").html(data);
				$(".input_detail").val('');
				$("#txt_noakun").focus();
				cek_idbkm();
				tampil_data_detail();
				$("#txt_naakun").focus();
			}
		});
		}
		return false;
	}
	
	function cek_idbkm(){
		var kode 	= $("#txt_kode").val();
		
		$.ajax({
			type	: "POST",
			url		: "modul/pener_kas/cari_idbkm.php",
			data	: "kode="+kode,
			dataType: "json",
			success	: function(data){
				$("#txt_idbkm").val(data.nomor);
			}
		});
	}
	
	$("#cetak_bkm").click(function(){
		var	kode	= $("#txt_kode").val();
		var	tgl		= $("#txt_tanggal").val();		
		var	pemby	= $("#txt_pemby").val();
		var	total	= $("#txt_total").val();
		var	tbl		= $("#txt_terbilang").val();
		
		if(total.length == 0){
			var error = true;
			alert("Maaf, data penerimaan kas belum direkam.");			
			return (false);
        }		
		window.location.href='modul/laporan/bukti_km.php?kode='+kode+'&tgl='+tgl+'&pemby='+pemby+'&total='+total+'&tbl='+tbl;
	});
	
	$("#tutup").click(function(){		
		document.location='?module=home';
	});
});
</script>

<style type="text/css">
#txt_kode {
	background:#CCC;
}
#cari_produk{
	cursor:pointer;
}
#cari_buyer{
	cursor:pointer;
}
.input_detail readonly {
	background:#666;
}
</style>

<?php
echo "<table width='100%'>	
	<tr>
		<input type='text' name='txt_piut' id='txt_piut' size='4' hidden />
		<input type='text' name='txt_persed' id='txt_persed' size='4' hidden />
		<input type='text' name='txt_utang' id='txt_utang' size='4' hidden />
		<input type='text' name='txt_labapb' id='txt_labapb' size='4' hidden />
		<input type='text' name='txt_jual' id='txt_jual' size='4' hidden />
		<input type='text' name='txt_labrug' id='txt_labrug' size='4' hidden />
		
		<td width='9.5%'>No. BKM</td>
		<td>:</td>
		<td>
			<input type='text' name='txt_kode' id='txt_kode' size='8' class='input_header' readonly />
			<img src='images/view.png' width='18' height='18' title='Cari BKM' id='cari_bkm'>
		</td>
		<td>Tanggal</td>
		<td>:</td>
		<td><input type='date' name='txt_tanggal' id='txt_tanggal' size='10' class='input_header' ></td>		
		<td>Akun Kas</td>
		<td>:</td>
		<td>			
			<input type='text' name='txt_namakas' id='txt_namakas' size='20' class='input_header'>
			<input type='text' name='txt_nokas' id='txt_nokas' size='4' class='input_header' readonly />
		</td>
	</tr>
	</table>
	<hr>";

echo "<table width='100%' >
		<tr>
			<th>Nama Akun</th>
			<th>Kode Akun</th>
			<th>Nama BP</th>
			<th>Kode BP</th>			
			<th>No.Faktur</th>			
			<th>Jumlah</th>
		</tr>		
		<tr>
			<input type='text' name='txt_idbkm' id='txt_idbkm' hidden />
			<input type='text' name='txt_adabp' id='txt_adabp' hidden />
			<input type='text' name='txt_piut' id='txt_piut' hidden />
			<input type='text' name='txt_total' id='txt_total' hidden />
			<td align='center'><input type='text' name='txt_naakun' id='txt_naakun' class='input' size='20' ></td>
			<td align='center'><input type='text' name='txt_noakun' id='txt_noakun' class='input' size='5' readonly /></td>
			<td align='center'><input type='text' name='txt_namabp' id='txt_namabp' class='input' size='20' ></td>
			<td align='center'><input type='text' name='txt_nobp' id='txt_nobp' class='input' size='8' maxlength='6' readonly /></td>
			<td align='center'><input type='text' name='txt_nofak' id='txt_nofak' class='input_detail' size='8'></td>
			<td align='center'><input type='text' name='txt_jumlah' id='txt_jumlah' class='input_detail' size='8' ></td>
		</tr>
	</table>
		
	<table>
		<tr>
			<td>Keterangan</td>
			<td>:</td>
			<td align='center'><input type='text' name='txt_ket' id='txt_ket' class='input' size='40' ></td>
			<td colspan='6' align='right'>
				<button name='simpan' id='simpan'>Rekam</button>				
				<button name='tutup' id='tutup'>Tutup</button>
			</td>
		</tr>
	</table>";

echo "<div id='form_cari_bkm' title='Pencarian Bukti Kas Masuk'>		
		<div id='info_km' align='center'></div>
	</div>";
	
echo "<div id='form_cari_kas' title='Pencarian Akun Kas'>
		<table width='100%'>
			<tr>
				<td width='20%'>Cari Akun Kas</td>
				<td width='1%'>:</td>
				<td><input type='text' name='txt_carikas' id='txt_carikas' size='40'</td>
			</tr>
		</table>
		<div id='info_kas' align='center'></div>
	</div>";

echo "<div id='data_detail'></div>";

echo "<div id='form_cari_akun' title='Pencarian Akun Buku Besar'>
		<table width='100%'>
			<tr>
				<td width='20%'>Cari Buku Besar</td>
				<td width='1%'>:</td>
				<td><input type='text' name='txt_caribb' id='txt_caribb' size='40'</td>
			</tr>
		</table>
		<div id='info_bb' align='center'></div>
	</div>";

echo "<div id='form_cari_bp' title='Pencarian Akun Buku Pembantu'>
		<table width='100%'>
			<td>
				<td width='25%'>Cari Buku Pembantu</td>
				<td width='1%'>:</td>
				<td><input type='text' name='txt_caribp' id='txt_caribp' size='30'</td>
			</td>
		</table>		
		<div id='info_bp' align='center'></div>
	</div>";

echo "<div id='form_cari_pd' title='Pencarian Data Piutang'>
		<table width='100%'>
			<td>
				<td width='20%'>Cari No.Faktur</td>
				<td width='1%'>:</td>
				<td><input type='text' name='txt_caripd' id='txt_caripd' size='30'</td>
			</td>
		</table>
		<div id='info_pd' align='center'></div>
	</div>";
?>
