<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);
				$("#t_user").val(data.user);
			}
		});
	}
	
	$('#form_cari_gr').dialog({
		autoOpen: false,
		modal	: true,
		width: 600,
	});
	
	$('#cari_gr').click(function(){		
		$('#form_cari_gr').dialog('open');
		$("#info_gr").load("modul/inventory/tampil_data_grds.php?");
		$("#txt_carigr").focus();
	});
	
	$('#txt_carigr').keyup(function(){		
		var cari	= $("#txt_carigr").val();
		
		$.ajax({
			type	: "GET",
			url	    : "modul/inventory/tampil_data_grds.php",
			data	: "cari="+cari,			
			success	: function(data){
				$("#info_gr").html(data);				
			}
		});
	});
		
	$("#t_kodegr").keyup(function(){
		var kode 	= $("#t_kodegr").val();
		
		if(kode.length==3){
		$.ajax({
			type	: "POST",
			url		: "modul/inventory/cari_grup.php",
			data	: "kode="+kode,
			dataType: "json",
			success	: function(data){
				$("#t_kodegr").val(kode);
				$("#t_namagr").val(data.namagr);
				var nagr = $("#t_namagr").val();
				
				if(nagr.length==0){
					alert('Kode kelompok '+kode+' tidak ditemukan.');
					$("#t_kodegr").focus();
					return (false);
				}
			}
		});
		}
	});
	
	$('#form_cari_sup').dialog({
		autoOpen: false,
		modal	: true,
		width: 600,
	});
		
	$('#t_namasp').keyup(function(){
		$('#form_cari_sup').dialog('open');
		$("#info_supplier").load('modul/inventory/tampil_data_sup.php');
		$("#txt_carisup").focus();
	});
	
	$("#txt_carisup").keyup(function(){
		var cari = $("#txt_carisup").val();
		
		$.ajax({
			type	: "POST",
			url	    : "modul/inventory/tampil_data_sup.php",
			data	: "cari="+cari,
			success	: function(data){
				$("#info_supplier").html(data);
			}
		});
	});
	
	$('#form_cari_dokter').dialog({
		autoOpen: false,
		modal	: true,
		width: 800,
	});
		
	$('#t_namadt').keyup(function(){
		$('#form_cari_dokter').dialog('open');
		$("#info_dokter").load('kasir/penjualan/tampil_data_dokter.php');
		$("#txt_caridt").focus();
	});
	
	$("#txt_caridt").keyup(function(){
		$("#info_dokter").show();
		var cari= $("#txt_caridt").val();
		
		$.ajax({
			type	: "POST",
			url		: "kasir/penjualan/tampil_data_dokter.php",
			data	: "cari="+cari,
			success	: function(data){
				$("#info_dokter").html(data);
			}
		});
	});
	
	$("#cari").click(function(){
		var tgl_awal	= $("#t_tgl_awal").val();
		var tgl_akhir 	= $("#t_tgl_akhir").val();
		var kodesp   	= $("#t_kodesp").val();
		var kodegr   	= $("#t_kodegr").val();
		var kodecab	    = $("#txt_kodecab").val();
		var urut      	= $("#x_urut").val();
		var user      	= $("#t_user").val();
		var kodedt      = $("#t_kodedt").val();
		
		$("#data_pj").show();
		$("#data_pj").load('modul/report/tampil_rekap_pj.php?tgl_awal='+tgl_awal+'&tgl_akhir='+tgl_akhir+'&kodesp='+kodesp+'&kodegr='+kodegr+'&kodecab='+kodecab+'&urut='+urut+'&user='+user+'&kodedt='+kodedt);
	});
	
	$("#refresh").click(function(){
		window.location.reload();		
	});
	
	$("#cetak").click(function() {
		var tgl_awal	= $("#t_tgl_awal").val();
		var tgl_akhir 	= $("#t_tgl_akhir").val();
		var kodesp   	= $("#t_kodesp").val();
		var namasp   	= $("#t_namasp").val();
		var kodegr   	= $("#t_kodegr").val();
		var namagr   	= $("#t_namagr").val();
		var kodecab     = $("#txt_kodecab").val();
		var urut      	= $("#x_urut").val();
		var user      	= $("#t_user").val();
		var kodedt      = $("#t_kodedt").val();
		var namadt      = $("#t_namadt").val();
		
		window.location.href='modul/laporan/rekap_pjl.php?tgl_awal='+tgl_awal+'&tgl_akhir='+tgl_akhir+'&kodesp='+kodesp+'&namasp='+namasp+'&kodegr='+kodegr+'&namagr='+namagr+'&kodecab='+kodecab+'&urut='+urut+'&user='+user+'&kodedt='+kodedt+'&namadt='+namadt;
	});
	
	$("#tutup").click(function(){
		document.location='?module=home';
	});
});
</script>
<style type="text/css">
#info {
	font-size:12px;
	font-weight:bold;
	color:#F00;
}
</style>

<?php	
echo "<div span='12' style='background-color:white'>";
echo "<div id='form' align='center'><h2>REKAP PENJUALAN BARANG DAGANGAN<h2></div>";
echo "<div id='filter' align='left'>
	<fieldset>
		<legend>Filter Data </legend>
		<table width='100%' style='font:14px Verdana'>
			<tr>
				<input type='text' id='t_user' class='input_header' hidden/>
				<input type='text' id='t_kodedt' size='20' hidden/>
				<td>Tanggal : <input type='date' id='t_tgl_awal' size='10'> sampai dengan <input type='date' id='t_tgl_akhir' size='10'></td>
				<td>Cabang : <select id='txt_kodecab'>";
				echo "<option value=''></option>";
				        $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>Kelompok : <input type='text' id='t_kodegr' size='3' maxlength='3' class='filter_ds'>
						<img src='images/view.png' width='18' height='18' title='Cari grup' id='cari_gr'>
						<input id='t_namagr' size='25' class='filter_ds' readonly/>
					</td>
				<tr>
				<td>Supplier : <input type='text' id='t_namasp' size='25' class='filter_ds'>
					<input type='text' id='t_kodesp' size='3' class='input_detail' class='filter_ds' readonly />
				</td>
				<td>Dokter : <input type='text' id='t_namadt' size='20'></td>
				<td>Diurutkan : <select id='x_urut'>
						<option value='kode'>Kode Barang</option>
						<option value='nominal'>Nominal</option>
						<option value='qty'>Unit Terjual</option>
					</select>
				</td>
				<td>
					<button id='cari'>Cari</button>
					<button id='cetak'>Cetak</button>
					<button id='refresh'>Refresh</button>
					<button id='tutup'>Tutup</button>
				</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_sup' title='Pencarian Data Supplier'>
		<table>
			<tr>
				<td>Cari Supplier : <input type='text' name='txt_carisup' id='txt_carisup' size='40'></td>
			</tr>
		</table>
		<div id='info_supplier' align='center' style='overflow-x: auto;height: 400px;scroll-behavior: smooth'></div>
	</div>";
	
	echo "<div id='form_cari_gr' title='Pencarian grup'>
		<table width='100%'>
			<td>
				<td>Cari Kelompok : <input type='text' id='txt_carigr' size='40'></td>
			</td>
		</table>
		<div id='info_gr' align='center' style='overflow-x: auto;height: 400px;scroll-behavior: smooth'></div>
	</div>";

echo "<div id='form_cari_dokter' title='Pencarian Data Dokter'>
		<table width='100%'>
			<tr>
				<td>Cari nama : <input type='text' id='txt_caridt' size='30'></td>
			</tr>
		</table>
		<div id='info_dokter' align='center'></div>
	</div>";
	
echo "</div>";
?>
