<script type="text/javascript">
$(document).ready(function(){
	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){				
				$("#t_tgl_awal").val(data.tanggal);
				$("#t_tgl_akhir").val(data.tanggal);				
			}
		});
	}
	
	$("#cari").click(function(){
		var tgl_awal = $("#t_tgl_awal").val();
		var tgl_akhir= $("#t_tgl_akhir").val();
		var	kodesl 	 = $("#txt_kodesl").val();
		
		if(tgl_awal.length==''){
			alert('Maaf, Tanggal awal periode masih kosong.');
			$("#t_tgl_awal").focus();
			return false;
		}
		if(tgl_akhir.length==''){
			alert('Maaf, Tanggal akhir periode belum terisi.');
			$("#t_tgl_akhir").focus();
			return false;
		}
		$("#data_pj").show();
		$("#data_pj").load('modul/report/tampil_laba_pj.php?tgl_awal='+tgl_awal+'&tgl_akhir='+tgl_akhir+'&kodesl='+kodesl);
	});
	
	$('#form_cari_sl').dialog({
		autoOpen: false,
		modal	: true,
		width: 600,
	});
		
	$('#txt_namasl').click(function(){
		var cari	= $("#txt_carisl").val();
		$('#form_cari_sl').dialog('open');
		$("#info_salesman").load('adm_jual/penjualan/tampil_data_sl.php?cari='+cari);
		$("#txt_carisl").focus();
	});
	
	$('#txt_namasl').keyup(function(){
		var cari	= $("#txt_carisl").val();
		$('#form_cari_sl').dialog('open');
		$("#info_salesman").load('adm_jual/penjualan/tampil_data_sl.php?cari='+cari);
		$("#txt_carisl").focus();
	});
	
	$("#txt_carisl").keyup(function(){
		$("#info_salesman").show();
		var cari	= $("#txt_carisl").val();
		
		$.ajax({
			type	: "POST",
			url		: "adm_jual/penjualan/tampil_data_sl.php",
			data	: "cari="+cari,
			timeout	: 3000,
			beforeSend	: function(){
				$("#info_salesman").html("<img src='loading.gif' />");			
			},				  
			success	: function(data){
				$("#info_salesman").html(data);
			}
		});
	});
	
	$("#refresh").click(function() {
		window.location.reload();		
	});
	
	$("#cetak").click(function() {
		var tgl_awal = $("#t_tgl_awal").val();
		var tgl_akhir= $("#t_tgl_akhir").val();
		var	kodesl 	 = $("#txt_kodesl").val();
		var	namasl 	 = $("#txt_namasl").val();
		
		if(tgl_awal.length==''){
			alert('Maaf, Tanggal awal periode belum terisi.');
			$("#t_tgl_awal").focus();
			return false;
		}
		if(tgl_akhir.length==''){
			alert('Maaf, Tanggal akhir periode masih kosong.');
			$("#t_tgl_akhir").focus();
			return false;
		}		
		window.location.href='modul/laporan/laba_pjl.php?tgl_awal='+tgl_awal+'&tgl_akhir='+tgl_akhir+'&kodesl='+kodesl+'&namasl='+namasl;
	});
	
	$("#tutup").click(function(){
		document.location='?module=home';
	});
	
});
</script>
<style type="text/css">
#info {
	font-size:12px;
	font-weight:bold;
	color:#F00;
}
</style>

<?php
include '../../inc/inc.koneksi.php';
	
echo "<div span='12' style='background-color:white'>";

echo "<div id='form' align='center'><h3>LAPORAN LABA RUGI PENJUALAN<h3></div>";

echo "<div id='filter' align='left'>
	<fieldset>
		<legend>Filter Data </legend>
		<table width='100%'>
			<tr>
				<td>Tanggal</td>				
				<td>: <input type='date' name='t_tgl_awal' id='t_tgl_awal' size='10'></td>
				<td>Sampai dengan</td>
				<td><input type='date' name='t_tgl_akhir' id='t_tgl_akhir' size='10'></td>
				<td align='right'>
					<button name='cari' id='cari'>Cari</button>
					<button name='cetak' id='cetak'>Cetak</button>
					<button name='refresh' id='refresh'>Refresh</button>
					<button name='tutup' id='tutup'>Tutup</button>
				</td>
			</tr>
		</table>
		
		<table width='100%'>
			<tr>
				<td>Salesman : <input type='text' name='txt_namasl' id='txt_namasl' size='23' class='input_header'>	<input type='text' name='txt_kodesl' id='txt_kodesl' size='3' class='input_header' readonly />
				</td>
			</tr>
		</table>
	</fieldset>
	</div><br>";
	
echo "<div id='data_pj' align='center' style='overflow-x: auto;height: 400px;scroll-behavior: smooth'></div>";

echo "<div id='form_cari_sl' title='Pencarian Data Salesman'>
		<table width='100%'>
			<tr>
				<td width='20%'>Cari data</td>
				<td width='2%'>:</td>
				<td><input type='text' name='txt_carisl' id='txt_carisl' size='40'</td>
			</tr>
		</table>
		<div id='info_salesman' align='center' style='overflow-x: auto;height: 400px;scroll-behavior: smooth'></div>
	</div>";

echo "</div>";
?>
