<script type="text/javascript">
	$(document).ready(function(){
	$("#data_detail").load('spv/outstan_do/tampil_data_detail.php?');
	
	cari_itf();
	
	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);
			}
		});
	}
	
	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();
	
	$('#txt_nobukti').keyup(function(){
		cari_nomor();
		return false;
	});
	
	$('#txt_jenis').keyup(function(){
		cari_nomor();
		cari_hbeli();
		return false;
	});
	
	$('#txt_jenis').click(function(){
		cari_hbeli();
		return false;
	});
	
	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 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_jmlliter').keyup(function(){
		hitung_jumlah();
		return false;
	});
	
	function hitung_jumlah(){
		var hgbeli  = $("#txt_hgbeli").val();
		var jmlliter	= $("#txt_jmlliter").val();
		var jumlah	= parseInt(hgbeli)*parseInt(jmlliter);
		
		$("#txt_jumlah").val(jumlah);
	}
	
	$('#simpan').click(function(){
		simpan_data();
		return false;
	});
		
	function simpan_data(){
		var	kode		= $("#txt_kode").val();
		var	tanggal	= $("#txt_tanggal").val();
		var	nobukti	= $("#txt_nobukti").val();
		var	jenis  	= $("#txt_jenis").val();
		var	jmlliter	= $("#txt_jmlliter").val();
		var	hgbeli 	= $("#txt_hgbeli").val();
		var	jumlah	= $("#txt_jumlah").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(jmlliter.length == 0){
           var error = true;
           alert("Maaf, Jumlah liter masih kosong.");
		   $("#txt_jmlliter").focus();
		   return (false);
        }
		 
		if(error == false){
		$.ajax({
			type	: "POST",
			url	: "spv/outstan_do/simpan.php",
			data	: "kode="+kode+
					"&tanggal="+tanggal+
					"&nobukti="+nobukti+
					"&jenis="+jenis+
					"&jmlliter="+jmlliter+
					"&hgbeli="+hgbeli+
					"&jumlah="+jumlah,
			timeout	: 2000,
			beforeSend	: function(){		
				$("#info").html("<img src='loading.gif' />");			
			},				  
			success	: function(data){
				$("#info").html(data);
				$(".input_detail").val('');
				$("#txt_tanggal").focus();
				tampil_data_detail();
			}
		});
		}
	}
	
	function tampil_data_detail(){
		$("#data_detail").load('spv/outstan_do/tampil_data_detail.php?');
	}
	
	$("#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
include "../../inc/inc.koneksi.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>Kode</td>
		<td>:</td>
		<td><input type='text' name='txt_kode' id='txt_kode' size='8' readonly class='input_header' ></td>
		<td>Tanggal</td>
		<td>:</td>
		<td><input type='date' name='txt_tanggal' id='txt_tanggal'  size='10' ></td>
		<td>Nomor Bukti</td>
		<td>:</td>
		<td><input type='text' name='txt_nobukti' id='txt_nobukti'  size='10' ></td>
		<td>Jenis</td>
		<td>:</td>
		<td><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 Plus'>Pertamax Plus</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>
	</tr>
	</table>
	
	<table>
	<tr>
		<td>Jumlah Liter</td>
		<td>:</td>
		<td><input type='text' name='txt_jmlliter' id='txt_jmlliter' size='5' ></td>
		<td>Harga Beli</td>
		<td>:</td>
		<td><input type='text' name='txt_hgbeli' id='txt_hgbeli' size='9' ></td>
		<td>Jumlah Harga</td>
		<td>:</td>
		<td><input type='text' name='txt_jumlah' id='txt_jumlah' size='15' readonly /></td>
		<td width='4%'></td>
		<td align='right'>
			<button name='simpan' id='simpan'>Rekam</button>	
			<button name='tutup' id='tutup'>Tutup</button>
		</td>
	</tr>
	</table>";

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