<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();
			}
		});
	}
	
	$('#txt_jenis').keyup(function(){
		cari_nomor();
		cari_hbeli();
		tampil_data_detail();
	});
	
	$('#txt_jenis').click(function(){
		cari_nomor();
		cari_hbeli();
		tampil_data_detail();
	});
	
	function cari_nomor(){
		var tanggal	= $("#txt_tanggal").val();
		
		$.ajax({
			type	: "POST",
			url		: "modul/penguapan/cari_nomor.php",
			data	: "tanggal="+tanggal,
			dataType: "json",
			success	: function(data){
				$("#txt_kode").val(data.nomor);
			}
		});
	}
	
	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);
			}
		});
	}
	
	function tampil_data_detail(){
		var tanggal = $("#txt_tanggal").val();
		$("#data_detail").load('modul/penguapan/tampil_data_detail.php?tanggal='+tanggal);
	}
	
	$('#txt_tanki').keyup(function(){
		cari_stok();
	});
	
	$('#txt_tanki').click(function(){
		cari_stok();
	});
	
	function cari_stok(){
		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();
		var tanki 	= $("#txt_tanki").val();
		var tanggal = $("#txt_tanggal").val();
		
		$.ajax({
			type	: "POST",
			url		: "modul/penguapan/cari_stok.php",
			data	: "jenis="+jenis+
				"&prem="+prem+
				"&solar="+solar+
				"&ptmx="+ptmx+
				"&ptmp="+ptmp+
				"&ptlt="+ptlt+
				"&dex="+dex+
				"&dexlite="+dexlite+
				"&solek="+solek+
				"&tanki="+tanki+
				"&tanggal="+tanggal,
			dataType: "json",
			success	: function(data){
				$("#txt_jmlstok").val(data.stok);
			}
		});
	}
	
	$('#txt_jmlstik').keyup(function(){
		hitung_sls();
	});
	
	function hitung_sls(){
		var jmlstok = $("#txt_jmlstok").val();
		var jmlstik = $("#txt_jmlstik").val();
		var hgbeli  = $("#txt_hgbeli").val();
		var jmlsls	= parseFloat(jmlstok)-parseFloat(jmlstik);
		var jmlsls  = jmlsls.toFixed(2);
		var nilai	= jmlsls*parseInt(hgbeli);
		var nilai	= nilai.toFixed(2);
		$("#txt_jmlsls").val(jmlsls);
		$("#txt_nilaisls").val(nilai);
	}
			
	$('#simpan').click(function(){
		simpan_data();
	});
	
	function simpan_data(){
		var kode	= $("#txt_kode").val();
		var tanggal = $("#txt_tanggal").val();		
		var jenis  	= $("#txt_jenis").val();
		var tanki  	= $("#txt_tanki").val();
		var jmlstok	= $("#txt_jmlstok").val();
		var jmlstik	= $("#txt_jmlstik").val();
		var jmlsls 	= $("#txt_jmlsls").val();
		var hgbeli 	= $("#txt_hgbeli").val();
		var nilai   = $("#txt_nilaisls").val();
		
		var error = false;

		if(kode.length == 0){
           var error = true;
           alert("Maaf, Form input belum diisi secara lengkap.");
		   $("#txt_tanggal").focus();
		   return (false);
        }
		
		if(jenis.length == 0){
           var error = true;
           alert("Maaf, Jenis bbm belum dipilih.");
		   $("#txt_jenis").focus();
		   return (false);
        }
		
		if(tanki.length == 0){
           var error = true;
           alert("Maaf, Nomor tanki belum dipilih.");
		   $("#txt_tanki").focus();
		   return (false);
        }
		
		if(jmlstik.length == 0){
           var error = true;
           alert("Maaf, Kolom hasil stik masih kosong.");
		   $("#txt_jmlstik").focus();
		   return (false);
        }
		 
		if(error == false){
		$.ajax({
			type	: "POST",
			url		: "modul/penguapan/simpan.php",
			data	: "kode="+kode+
					"&tanggal="+tanggal+					
					"&jenis="+jenis+
					"&tanki="+tanki+
					"&jmlstok="+jmlstok+
					"&jmlstik="+jmlstik+
					"&jmlsls="+jmlsls+
					"&hgbeli="+hgbeli+
					"&nilai="+nilai,
			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_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 />
		
		<td width='10%'>Kode Penguapan</td>
		<td>: <input type='text' name='txt_kode' id='txt_kode' size='9' class='input' readonly /></td>
		<td>Tanggal : <input type='date' name='txt_tanggal' id='txt_tanggal'></td>
		<td>Jenis BBM : <select name='txt_jenis' id='txt_jenis' >
			<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>
			<option value='Solar Keekonomian'>Solar Keekonomian</option>
			</select>
		</td>
		<td>Tanki : <select name='txt_tanki' id='txt_tanki' >
			<option value='' selected>-Pilih-</option>
			<option value='1'>1</option>
			<option value='2'>2</option>
			<option value='3'>3</option></select>
		</td>
	
		<td>Jumlah Stok : <input type='text' name='txt_jmlstok' id='txt_jmlstok' size='9' class='input' readonly /> liter</td>
		<td>Hasil Stik : <input type='text' name='txt_jmlstik' id='txt_jmlstik' size='7' class='input'> liter</td>
	</tr>
	</table>
	
	<table width='100%'>
	<tr>
		<td width='10%'>Penguapan</td>
		<td width='9%'>: <input type='text' name='txt_jmlsls' id='txt_jmlsls' size='5' class='input' readonly /> ltr</td>
		<td width='19%'>Harga Beli : <input type='text' name='txt_hgbeli' id='txt_hgbeli' size='7' class='input' readonly /></td>
		<td>Nilai : <input type='text' name='txt_nilaisls' id='txt_nilaisls' size='10' class='input' readonly /></td>
		<td>
			<button name='simpan' id='simpan'>Rekam</button>
			<button name='mulai' id='mulai'>Input</button>
			<button name='tutup' id='tutup'>Tutup</button>
		</td>
	</tr>
	</table>";

echo "<div id='data_detail' align='center'><div>";
?>
