<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);
				$("#mulai").focus();
			}
		});
	}

	$("#mulai").click(function(){
		$(".input_detail").val('');
		$(".input_header").val('');
		$("#txt_total").val('');
		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_tanggal").focus();
				cari_nomor();
			}
		});
	}
	
	function cari_nomor(){
		var tanggal = $("#txt_tanggal").val();
		
		$.ajax({
			type	: "POST",
			url		: "modul/pener_bank/cari_nomor.php",
			data	: "tanggal="+tanggal,
			dataType: "json",
			success	: function(data){				
				$("#txt_kode").val(data.nomor);				
				$('#data_detail').show();				
				cek_nourut();
				tampil_data_detail();
			}
		});
	}
	
	function cek_nourut(){
		var kode 	= $("#txt_kode").val();
		
		$.ajax({
			type	: "POST",
			url		: "modul/pener_bank/cari_nourut.php",
			data	: "kode="+kode,
			dataType: "json",
			success	: function(data){
				$("#txt_nourut").val(data.nourut);
			}
		});
	}
	
	function tampil_data_detail(){
		var kode = $("#txt_kode").val();
		$("#data_detail").load("modul/pener_bank/tampil_data_detail.php?kode="+kode);
		cari_total();
	}
	
	$("#txt_tanggal").keyup(function(){
		cari_nomor();
	});
	
	function cari_total(){
		var kode = $("#txt_kode").val();
		
		$.ajax({
			type	: "POST",
			url		: "modul/pener_bank/cari_total.php",
			data	: "kode="+kode,
			dataType: "json",
			success	: function(data){
				$("#txt_total").val(data.total);
				terbilang();
			}
		});
	}
	
	function terbilang(){
		var total = $("#txt_total").val();
		
		if(total.length==1)
			konversi1();
		else if(total.length==2)
			konversi2();
		else if(total.length==3)
			konversi3();
		else if(total.length==4)
			konversi4();
		else if(total.length==5)
			konversi5();
		else if(total.length==6)
			konversi6();
		else if(total.length==7)
			konversi7();
		else if(total.length==8)
			konversi8();
		else if(total.length==9)
			konversi9();
	}
	
	function konversi1(){
		var	total= $("#txt_total").val();
		
		$.ajax({
			type	: "POST",
			url		: "modul/konversi/konversi1.php",
			data	: "total="+total,
			dataType: "json",
			success	: function(data){				
				$("#txt_terbilang").val(data.terbilang);				
			}
		});
	}
	
	function konversi2(){
		var	total = $("#txt_total").val();
		
		$.ajax({
			type	: "POST",
			url		: "modul/konversi/konversi2.php",
			data	: "total="+total,
			dataType: "json",
			success	: function(data){				
				$("#txt_terbilang").val(data.terbilang);
			}
		});
	}
	
	function konversi3(){
		var	total = $("#txt_total").val();
		
		$.ajax({
			type	: "POST",
			url		: "modul/konversi/konversi3.php",
			data	: "total="+total,
			dataType: "json",
			success	: function(data){
				$("#txt_terbilang").val(data.terbilang);				
			}
		});		
	}
	
	function konversi4(){
		var	total = $("#txt_total").val();
		
		$.ajax({
			type	: "POST",
			url		: "modul/konversi/konversi4.php",
			data	: "total="+total,
			dataType: "json",
			success	: function(data){				
				$("#txt_terbilang").val(data.terbilang);				
			}
		});
	}
	
	function konversi5(){
		var	total = $("#txt_total").val();
		
		$.ajax({
			type	: "POST",
			url		: "modul/konversi/konversi5.php",
			data	: "total="+total,
			dataType: "json",
			success	: function(data){				
				$("#txt_terbilang").val(data.terbilang);				
			}
		});
	}
	
	function konversi6(){
		var	total = $("#txt_total").val();
		
		$.ajax({
			type	: "POST",
			url		: "modul/konversi/konversi6.php",
			data	: "total="+total,
			dataType: "json",
			success	: function(data){
				$("#txt_terbilang").val(data.terbilang);
			}
		});		
	}
	
	function konversi7(){
		var	total = $("#txt_total").val();
		
		$.ajax({
			type	: "POST",
			url		: "modul/konversi/konversi7.php",
			data	: "total="+total,
			dataType: "json",
			success	: function(data){				
				$("#txt_terbilang").val(data.terbilang);				
			}
		});
	}
	
	function konversi8(){
		var	total = $("#txt_total").val();
				
		$.ajax({
			type	: "POST",
			url		: "modul/konversi/konversi8.php",
			data	: "total="+total,
			dataType: "json",
			success	: function(data){				
				$("#txt_terbilang").val(data.terbilang);				
			}
		});
	}
	
	function konversi9(){
		var	total = $("#txt_total").val();
		
		$.ajax({
			type	: "POST",
			url		: "modul/konversi/konversi9.php",
			data	: "total="+total,
			dataType: "json",
			success	: function(data){				
				$("#txt_terbilang").val(data.terbilang);				
			}
		});		
	}
		
	$('#form_cari_bbm').dialog({
		autoOpen: false,
		modal	: true,
		width: 700,
	});
		
	$('#cari_bbm').click(function(){
		$('#form_cari_bbm').dialog('open');
		$("#txt_carikode").focus();
	});
		
	$("#txt_carikode").keyup(function(){
		var cari = $("#txt_carikode").val();
		
		$.ajax({
			type	: "POST",
			url		: "modul/pener_bank/tampil_nobbm.php",
			data	: "cari="+cari,
			timeout	: 3000,
			beforeSend	: function(){		
				$("#info_bbm").html("<img src='loading.gif' />");			
			},				  
			success	: function(data){
				$("#info_bbm").html(data);				
			}
		});
	});
		
	$('#form_cari_bank').dialog({
		autoOpen: false,
		modal	: true,
		width: 600,
	});
		
	$('#txt_namabank').keyup(function(){		
		$('#form_cari_bank').dialog('open');
		$("#info_bank").load('modul/pener_bank/tampil_data_bank.php');
		$("#txt_caribk").focus();				
	});
	
	$("#txt_caribk").keyup(function(){
		var cari	= $("#txt_caribk").val();
		
		var no=1;
		$.ajax({
			type	: "POST",
			url		: "modul/pener_bank/tampil_data_bank.php",
			data	: "cari="+cari,
			timeout	: 3000,
			beforeSend	: function(){		
				$("#info_bank").html("<img src='loading.gif' />");			
			},				  
			success	: function(data){
				$("#info_bank").html(data);				
			}
		});
	});
	
	$('#form_cari_akun').dialog({
		autoOpen: false,
		modal	: true,
		width: 600,
	});
	
	$('#txt_naakun').keyup(function(){		
		$('#form_cari_akun').dialog('open');
		$("#info_bb").load('modul/pener_kas/tampil_data_akun.php');
		$("#txt_caribb").focus();				
	});
	
	$("#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: 700,
	});
	
	$("#txt_namabp").keyup(function(){
		var adabp = $("#txt_adabp").val();
		var nobb = $("#txt_noakun").val();
		var cari = $("#txt_caribp").val();
		
		if(adabp==''){
			alert('Kode akun '+nobb+' tidak memiliki buku pembantu.');
			$("#txt_jumlah").focus();
			return (false);
		}else{
			$('#form_cari_bp').dialog('open');
			$("#info_bp").show();
			$("#info_bp").load('modul/pener_kas/tampil_data_bp.php?nobb='+nobb+'&cari='+cari);
			$("#txt_caribp").focus();
		}
	});
	
	$("#txt_caribp").keyup(function(){
		var cari = $("#txt_caribp").val();
		var nobb = $("#txt_noakun").val();
		
		$.ajax({
			type	: "POST",
			url		: "modul/pener_kas/tampil_data_bp.php",
			data	: "cari="+cari+
					"&nobb="+nobb,
			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: 700,
	});
	
	$("#txt_nofak").keyup(function(){
		var piut = $("#txt_piut").val();
		var nobb = $("#txt_noakun").val();		
		var nobp = $("#txt_nobp").val();
		
		if(piut==''){
			alert('Kode akun '+nobb+' bukan piutang dagang.');
			$("#txt_jumlah").focus();
			return (false);
		}else{
			var cari = $("#txt_caripd").val();
			$('#form_cari_pd').dialog('open');
			$("#info_pd").show();
			$("#info_pd").load('modul/pener_kas/tampil_data_pd.php?nobp='+nobp+'&cari='+cari);
			$("#txt_caripd").focus();
		}
	});
	
	$("#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	nobank  = $("#txt_nobank").val();		
		var	nabank  = $("#txt_namabank").val();		
		var	nourut  = $("#txt_nourut").val();
		var	noakun	= $("#txt_noakun").val();
		var	nobp  	= $("#txt_nobp").val();
		var	kodecab	= $("#txt_kodecab").val();
		var	naakun 	= $("#txt_naakun").val();
		var	namabp 	= $("#txt_namabp").val();
		var	nofak  	= $("#txt_nofak").val();
		var	ket    	= $("#txt_ket").val();
		var	jumlah	= $("#txt_jumlah").val();
		
		if(tanggal.length == 0){
           alert("Maaf, Tanggal bbm tidak boleh kosong.");
		   return (false);
        }
		if(nobank.length == 0){
			var error = true;
			alert("Maaf, Nomor akun bank masih kosong");
			$("#txt_nobank").focus();
			return (false);
        }
		if(noakun.length == 0){
           alert("Maaf, Kode Akun  tidak boleh kosong");
		   $("#txt_noakun").focus();
		   return (false);
        }
        if(kodecab.length == 0){
           alert("Maaf, Kode cabang  tidak boleh kosong");
		   $("#txt_kodecab").focus();
		   return (false);
        }
		
		if(nobp.length == 0){
			var adabp = $("#txt_adabp").val();
			
			if(!adabp==''){
				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){
				alert("Maaf, Untuk akun piutang dagang, Nomor faktur tidak boleh kosong.");
				$("#txt_noakun").focus();
				return (false);
			}
        }
		
		if(ket.length == 0){
           alert("Maaf, Kolom keterangan tidak boleh kosong");
		   $("#txt_ket").focus();
		   return (false);
         }
		 
		if(jumlah.length == 0){
			alert("Maaf, Kolom jumlah tidak boleh kosong.");
			$("#txt_jumlah").focus();
			return (false);
        }
		
		$.ajax({
			type	: "POST",
			url		: "modul/pener_bank/simpan.php",
			data	: "kode="+kode+
					"&tanggal="+tanggal+
					"&nobank="+nobank+
					"&nabank="+nabank+					
					"&nourut="+nourut+
					"&noakun="+noakun+
					"&nobp="+nobp+
					"&kodecab="+kodecab+
					"&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_nourut();
				tampil_data_detail();				
			}
		});		
	}
	
	$("#tutup").click(function(){		
		document.location='?module=home';
	});
});
</script>

<style type="text/css">
#txt_kode {
	background:#CCC;
}
</style>

<?php
include "../../inc/inc.koneksi.php";
echo "<table width='100%'>	
	<tr>
		<input type='text' name='txt_piut' id='txt_piut' hidden />
		<input type='text' name='txt_persed' id='txt_persed' hidden />
		<input type='text' name='txt_utang' id='txt_utang' hidden />
		<input type='text' name='txt_labapb' id='txt_labapb' hidden />
		<input type='text' name='txt_jual' id='txt_jual' hidden />
		<input type='text' name='txt_labrug' id='txt_labrug' hidden />
		
		<td width='7%'>Nomor BBM</td>
		<td>: <input type='text' name='txt_kode' id='txt_kode' size='12' class='input_header' readonly />
			<img src='images/view.png' width='18' height='18' title='Cari BBM' id='cari_bbm'>
		</td>
		<td>Tanggal : <input type='date' name='txt_tanggal' id='txt_tanggal' size='10' class='input_header' ></td>		
		<td>Akun bank : <input type='text' name='txt_namabank' id='txt_namabank' size='17' class='input_header'> 
			<input type='text' name='txt_nobank' id='txt_nobank' size='4' class='input_header' readonly />
		</td>
	</tr>
	</table>
	<table width='100%'>
	<tr>		
		<td width='7%'>Terbilang</td>
		<td>: <input type='text' name='txt_terbilang' id='txt_terbilang' size='80' class='input_header' readonly /></td>
	</tr>
	</table>
	<hr>";

echo "<table>
		<tr>
			<th>Nama Akun</th>
			<th>Kode Akun</th>
			<th>Nama BP</th>
			<th>Kode BP</th>			
			<th>No.Faktur</th>
			<th>Cabang</th>
			<th>Jumlah</th>
			<th>Keterangan</th>
		</tr>
		<tr>
			<input type='text' name='txt_nourut' id='txt_nourut' class='input_detail' hidden />
			<input type='text' name='txt_adabp' id='txt_adabp' class='input_detail' hidden />			
			<input type='text' name='txt_total' id='txt_total' class='input_detail' hidden />
			<input type='text' name='txt_posting' id='txt_posting' class='input_detail' hidden />
			<td align='center'><input type='text' name='txt_naakun' id='txt_naakun' class='input_detail' size='20' ></td>
			<td align='center'><input type='text' name='txt_noakun' id='txt_noakun' class='input_detail' size='5' readonly /></td>
			<td align='center'><input type='text' name='txt_namabp' id='txt_namabp' class='input_detail' size='20' ></td>
			<td align='center'><input type='text' name='txt_nobp' id='txt_nobp' class='input_detail' 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><select id='txt_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 align='center'><input type='text' name='txt_jumlah' id='txt_jumlah' class='input_detail' size='8' ></td>
			<td align='center'><input type='text' name='txt_ket' id='txt_ket' class='input_detail' size='50' ></td>
		</tr>
	</table>
		
	<table width='100%'>
		<tr>						
			<td align='center'>
				<button name='simpan' id='simpan'>Rekam</button>
				<button name='mulai' id='mulai'>Input BBM</button>
				<button name='tutup' id='tutup'>Tutup</button>
			</td>
		</tr>
	</table>";

echo "<div id='form_cari_bbm' title='Pencarian Bukti Bank Masuk'>
		<table width='100%'>
			<tr>
				<td>Cari Nomor BBM : <input type='text' name='txt_carikode' id='txt_carikode' size='15'></td>
			</tr>
		</table>
		
		<div id='info_bbm' align='center'></div>
	</div>";
	
echo "<div id='form_cari_bank' title='Pencarian Akun bank'>
		<table width='100%'>
			<tr>
				<td width='20%'>Cari Akun bank</td>
				<td width='1%'>:</td>
				<td><input type='text' name='txt_caribk' id='txt_caribk' size='40'</td>
			</tr>
		</table>
		<div id='info_bank' 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>";
?>
