<script type="text/javascript">
	$(document).ready(function(){
	$("#input_bon").hide();
	
	$("#mulai").focus();
	
	$('#mulai').click(function(){
		cari_itf();
		cari_tgl();
	});
	
	function cari_itf(){
		var no = 1;
		$.ajax({
			type	: "POST",
			url		: "modul/setor_bbm/cari_itf.php",
			data	: "no="+no,
			dataType: "json",
			success	: function(data){
				$("#txt_prem").val(data.prem);
				$("#txt_solar").val(data.solar);
				$("#txt_ptmx").val(data.ptmx);
				$("#txt_ptmp").val(data.ptmp);
				$("#txt_ptlt").val(data.ptlt);
				$("#txt_dex").val(data.dex);
				$("#txt_dexlite").val(data.dexlite);
				$("#txt_solek").val(data.solek);
			}
		});
	}
	
	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_bank').dialog({
		autoOpen: false,
		modal	: true,
		width: 600,
	});
		
	$('#txt_namabank').keyup(function(){		
		$('#form_cari_bank').dialog('open');
		$("#txt_caribk").focus();
	});
	
	$('#txt_namabank').click(function(){
		cari_nomor();
		tampil_data_detail();
		$('#form_cari_bank').dialog('open');
		$("#txt_caribk").focus();
	});
	
	$("#txt_caribk").keyup(function(){
		var cari	= $("#txt_caribk").val();
		
		$.ajax({
			type	: "POST",
			url		: "modul/tebus_do/tampil_data_bank.php",
			data	: "cari="+cari,
			success	: function(data){
				$("#info_bank").html(data);				
			}
		});
	});
	
	$('#txt_jenis').keyup(function(){
		cari_nomor();
		cari_hbeli();
	});
	
	$('#txt_jenis').click(function(){
	    cari_nomor();
		cari_hbeli();
	});
	
	function cari_nomor(){
		var tanggal	= $("#txt_tanggal").val();
		
		$.ajax({
			type	: "POST",
			url		: "spv/outstan_do/cari_nomor.php",
			data	: "tanggal="+tanggal,
			dataType: "json",
			success	: function(data){
				$("#txt_kode").val(data.nomor);
			}
		});
	}
	
	function tampil_data_detail(){
		var tanggal = $("#txt_tanggal").val();
		$("#data_detail").load('modul/tebus_do/tampil_data_detail.php?tanggal='+tanggal);
	}
	
	function cari_hbeli(){
		var jenis	= $("#txt_jenis").val();
		var prem	= $("#txt_prem").val();
		var solar	= $("#txt_solar").val();
		var ptmx	= $("#txt_ptmx").val();
		var ptmp	= $("#txt_ptmp").val();
		var ptlt 	= $("#txt_ptlt").val();
		var dex		= $("#txt_dex").val();
		var dexlite	= $("#txt_dexlite").val();
		var solek 	= $("#txt_solek").val();
		
		$.ajax({
			type	: "POST",
			url		: "spv/outstan_do/cari_hbeli.php",
			data	: "jenis="+jenis+
				"&prem="+prem+
				"&solar="+solar+
				"&ptmx="+ptmx+
				"&ptmp="+ptmp+
				"&ptlt="+ptlt+
				"&dex="+dex+
				"&dexlite="+dexlite+
				"&solek="+solek,
			dataType: "json",
			success	: function(data){
				$("#txt_hgbeli").val(data.hbeli);
				$("#txt_hgjual").val(data.hjual);
			}
		});
	}
		
	$('#txt_jmlliter').keyup(function(){
		hitung_jumlah();
	});
	
	function hitung_jumlah(){
		var hgbeli  = $("#txt_hgbeli").val();
		var hgjual  = $("#txt_hgjual").val();
		var jmlliter= $("#txt_jmlliter").val();
		var jmlpph  = ((parseInt(jmlliter)/100)*25*parseInt(hgjual))/115;
		var jmlpph  = jmlpph.toFixed(0);
		var jumlah  = parseFloat(hgbeli)*parseInt(jmlliter);
		var jmlsetor= jumlah;
		
		$("#txt_jumlah").val(jumlah);
		$("#txt_jmlpph").val(jmlpph);
		$("#txt_jmlsetor").val(jmlsetor);
	}
		
	$('#simpan').click(function(){
		simpan_data();
	});
		
	function simpan_data(){
		var kode	= $("#txt_kode").val();
		var tanggal	= $("#txt_tanggal").val();
		var nobukti	= $("#txt_nobukti").val();
		var nobank 	= $("#txt_nobank").val();
		var namabank= $("#txt_namabank").val();
		var jenis  	= $("#txt_jenis").val();
		var jmlliter= $("#txt_jmlliter").val();
		var hgbeli 	= $("#txt_hgbeli").val();
		var jmlpph	= $("#txt_jmlpph").val();
		var jumlah	= $("#txt_jumlah").val();
		var jmlsetor= $("#txt_jmlsetor").val();		
		var prem	= $("#txt_prem").val();
		var solar	= $("#txt_solar").val();
		var ptmx	= $("#txt_ptmx").val();
		var ptmp	= $("#txt_ptmp").val();
		var ptlt 	= $("#txt_ptlt").val();
		var dex		= $("#txt_dex").val();
		var dexlite	= $("#txt_dexlite").val();
		var solek 	= $("#txt_solek").val();
		
		if(kode.length == 0){
           alert("Maaf, Form input belum diisi secara lengkap.");
		   $("#txt_tanggal").focus();
		   return (false);
        }
		if(jenis.length == 0){
           alert("Maaf, Jenis BBM belum dipilih.");
		   $("#txt_jenis").focus();
		   return (false);
        }
		if(jmlliter.length == 0){
           alert("Maaf, Jumlah liter masih kosong.");
		   $("#txt_jmlliter").focus();
		   return (false);
        }
		if(jmlpph.length == 0){
           alert("Maaf, Kolom jumlah pajak harus diisi.");
		   $("#txt_jmlpph").focus();
		   return (false);
        }
		
		$.ajax({
			type	: "POST",
			url		: "modul/tebus_do/rekam.php",
			data	: "kode="+kode+
					"&tanggal="+tanggal+
					"&nobukti="+nobukti+
					"&nobank="+nobank+
					"&namabank="+namabank+
					"&jenis="+jenis+
					"&jmlliter="+jmlliter+
					"&hgbeli="+hgbeli+
					"&jmlpph="+jmlpph+
					"&jumlah="+jumlah+
					"&jmlsetor="+jmlsetor+
					"&prem="+prem+
					"&solar="+solar+
					"&ptmx="+ptmx+
					"&ptmp="+ptmp+
					"&ptlt="+ptlt+
					"&dex="+dex+
					"&dexlite="+dexlite+
					"&solek="+solek,
			timeout	: 2000,
			beforeSend	: function(){		
				$("#info").html("<img src='loading.gif' />");			
			},				  
			success	: function(data){
				$("#info").html(data);
				$(".input").val('');
				$("#txt_tanggal").focus();
				tampil_data_detail();
			}
		});
	}
	
	$("#tutup").click(function(){
		document.location='?module=home';
	});
});
</script>

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

<?php

echo "<table width='100%'>	
	<tr>
		<input type='text' name='txt_kodelm' id='txt_kodelm' hidden />
		<input type='text' name='txt_prem' id='txt_prem' hidden />
		<input type='text' name='txt_solar' id='txt_solar' hidden />
		<input type='text' name='txt_ptmx' id='txt_ptmx' hidden />
		<input type='text' name='txt_ptmp' id='txt_ptmp' hidden />
		<input type='text' name='txt_ptlt' id='txt_ptlt' hidden />
		<input type='text' name='txt_dex' id='txt_dex' hidden />
		<input type='text' name='txt_dexlite' id='txt_dexlite' hidden />
		<input type='text' name='txt_solek' id='txt_solek' hidden />
		<input type='text' name='txt_hgjual' id='txt_hgjual' class='input' hidden />
		
		<td width='7%'>Kode DO</td>
		<td>: <input type='text' name='txt_kode' id='txt_kode' size='10' readonly class='input' ></td>
		<td width='8%'>Tanggal</td>
		<td>: <input type='date' name='txt_tanggal' id='txt_tanggal' size='10' ></td>
		<td width='8%'>Nomor Bukti</td>
		<td>: <input type='text' name='txt_nobukti' id='txt_nobukti' size='10' class='input'></td>
		<td width='8%'>Rekening Bank</td>
		<td>: <input type='text' name='txt_namabank' id='txt_namabank' size='22' >
			<input type='text' name='txt_nobank' id='txt_nobank' size='5' readonly />
		</td>
	</tr>
	<tr>
		<td>Jenis</td>
		<td>: <select name='txt_jenis' id='txt_jenis' class='input' >
			    <option value='' selected>-Pilih-</option>
			    <option value='Premium'>Premium</option>
			    <option value='Bio Solar'>Bio Solar</option>
			    <option value='Pertamax'>Pertamax</option>
			    <option value='Pertamax Turbo'>Pertamax Turbo</option>
			    <option value='Pertalite'>Pertalite</option>
			    <option value='Pertamina Dex'>Pertamina Dex</option>
			    <option value='Dexlite'>Dexlite</option>
			</select>
		</td>		
		<td>Jumlah Liter</td>
		<td>: <input type='text' name='txt_jmlliter' id='txt_jmlliter' size='5' class='input' ></td>
		<td>Harga Beli</td>
		<td>: <input type='text' name='txt_hgbeli' id='txt_hgbeli' size='9' class='input'></td>
		<td>Jumlah Harga</td>
		<td>: <input type='text' name='txt_jumlah' id='txt_jumlah' size='10' class='input' readonly /></td>
	</tr>
	<tr>
	    <td>PPh Pasal 22</td>
		<td>: <input type='text' name='txt_jmlpph' id='txt_jmlpph' size='10' class='input' readonly /></td>
		<td>Jumlah Disetor</td>
		<td>: <input type='text' name='txt_jmlsetor' id='txt_jmlsetor' size='10' class='input' readonly /></td>
		<td></td>
		<td></td>
		<td></td>
		<td>
			<button name='simpan' id='simpan'>Rekam BBM</button>	
			<button name='mulai' id='mulai'>Mulai</button>	
			<button name='tutup' id='tutup'>Tutup</button>
		</td>
	</tr>
</table>";

echo "<div id='form_cari_bank' title='Pencarian Akun bank'>
		<table width='100%'>
			<tr>
				<td>Cari Akun bank : <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' align='center'><div>";
?>
