<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);
			}
		});
	}
	
	$('#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_gr.php?");
		$("#txt_carigr").focus();
	});
	
	$('#txt_carigr').keyup(function(){		
		var cari	= $("#txt_carigr").val();
		
		$.ajax({
			type	: "GET",
			url	    : "modul/inventory/tampil_data_gr.php",
			data	: "cari="+cari,			
			timeout	: 2000,
			beforeSend	: function(){		
				$("#info_gr").html("<img src='loading.gif' />");
			},				  
			success	: function(data){
				$("#info_gr").html(data);				
			}
		});
	});
		
	$("#txt_kodegr").keyup(function(){
		var kode= $("#txt_kodegr").val();
		
		if(kode.length==3){
		$.ajax({
			type	: "POST",
			url	    : "modul/inventory/cari_grup.php",
			data	: "kode="+kode,
			dataType: "json",
			success	: function(data){
				$("#txt_kodegr").val(kode);
				$("#txt_namagr").val(data.namagr);
				var nagr = $("#txt_namagr").val();
				
				if(nagr.length==0){
					alert('Kode kelompok '+kode+' tidak ditemukan.');
					return (false);
				}
				tampil_data_detail();
			}
		});
		}
	});
	
	$('#form_cari_sup').dialog({
		autoOpen: false,
		modal	: true,
		width: 700,
	});
		
	$('#txt_namasp').keyup(function(){
		$('#form_cari_sup').dialog('open');
		$("#info_supplier").load('modul/inventory/tampil_data_sup.php');
		$("#txt_carisup").focus();
	});
	
	$('#txt_namasp').click(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	: "GET",
			url	    : "modul/inventory/tampil_data_sup.php",
			data	: "cari="+cari,
			success	: function(data){
				$("#info_supplier").html(data);
			}
		});
	});
	
	$("#refresh").click(function(){
		window.location.reload();
	});
	
	$("#cari").click(function(){
		var bulanaw = $("#t_bulanaw").val();
		var bulanak = $("#t_bulanak").val();
		var tahun   = $("#t_tahun").val();
		var kodesp  = $("#txt_kodesp").val();
		var kodegr  = $("#txt_kodegr").val();
		var cari    = $("#cari_brg").val();
		
		if(bulanaw.length==''){
			alert('Maaf, kolom Bulan awal masih kosong, silahkan pilih terlebih dahulu.');
			$("#t_bulanaw").focus();
			return false;
		}
		if(bulanak.length==''){
			alert('Maaf, kolom Bulan akhir masih kosong, silahkan pilih terlebih dahulu.');
			$("#t_bulanak").focus();
			return false;
		}

		$.ajax({
			type    : "GET",
			url	    : "modul/report/tampil_anal_pbpj.php",
			data	: "bulanaw="+bulanaw+
			    "&bulanak="+bulanak+
			    "&tahun="+tahun+
			    "&kodesp="+kodesp+
			    "&kodegr="+kodegr+
			    "&cari="+cari,
			success	: function(data){
				$("#data_pbpj").show();
				$("#data_pbpj").html(data);
			}
		});
	});
	
	$("#refresh").click(function(){
		$(".input_sup").val('');
	});
	
	$("#cetak").click(function() {
		var bulanaw = $("#t_bulanaw").val();
		var bulanak = $("#t_bulanak").val();
		var tahun   = $("#t_tahun").val();
		var kodesp  = $("#txt_kodesp").val();
		var namasp  = $("#txt_namasp").val();
		var kodegr  = $("#txt_kodegr").val();
		var namagr  = $("#txt_namagr").val();
		var cari    = $("#cari_brg").val();
		
		if(bulanaw.length==''){
			alert('Maaf, kolom Bulan awal masih kosong, silahkan pilih terlebih dahulu.');
			$("#t_bulanaw").focus();
			return false;
		}
		if(bulanak.length==''){
			alert('Maaf, kolom Bulan akhir masih kosong, silahkan pilih terlebih dahulu.');
			$("#t_bulanak").focus();
			return false;
		}
		window.location.href='modul/laporan/analisa_pbpj.php?bulanaw='+bulanaw+'&bulanak='+bulanak+'&tahun'+tahun+'&kodesp='+kodesp+'&namasp='+namasp+'&kodegr='+kodegr+'&namagr='+namagr+'&cari='+cari;
	});

	$("#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';

$tanggal=date('Y-m-d');
$tahun=substr($tanggal,0,4);

echo "<div span='12' style='background-color:white'>";
echo "<div id='form' align='center'><h2>ANALISA PEMBELIAN DAN PENJUALAN<h2></div>";
echo "<div id='filter' align='left'>
	<fieldset>
		<legend>Filter Data </legend>
		<table width='100%' style='font:14px Verdana'>
			<tr>
				<td width='7%'>Bulan</td>
				<td>: <select id='t_bulanaw' >
    					<option value='' selected>-Pilih-</option>
	    				<option value='01'> 1 - JANUARI</option>
		    			<option value='02'> 2 - FEBRUARI</option>
			    		<option value='03'> 3 - MARET</option>
				    	<option value='04'> 4 - APRIL</option>
					    <option value='05'> 5 - MEI</option>
    					<option value='06'> 6 - JUNI</option>
	    				<option value='07'> 7 - JULI</option>
		    			<option value='08'> 8 - AGUSTUS</option>
			    		<option value='09'> 9 - SEPTEMBER</option>
				    	<option value='10'>10 - OKTOBER</option>
					    <option value='11'>11 - NOVEMBER</option>
    					<option value='12'>12 - DESEMBER</option>
	    			</select>
				</td>
				<td width='10%'>Sampai Dengan</td>
				<td><select id='t_bulanak' >
    					<option value='' selected>-Pilih-</option>
	    				<option value='01'> 1 - JANUARI</option>
		    			<option value='02'> 2 - FEBRUARI</option>
			    		<option value='03'> 3 - MARET</option>
				    	<option value='04'> 4 - APRIL</option>
					    <option value='05'> 5 - MEI</option>
    					<option value='06'> 6 - JUNI</option>
	    				<option value='07'> 7 - JULI</option>
		    			<option value='08'> 8 - AGUSTUS</option>
			    		<option value='09'> 9 - SEPTEMBER</option>
				    	<option value='10'>10 - OKTOBER</option>
					    <option value='11'>11 - NOVEMBER</option>
    					<option value='12'>12 - DESEMBER</option>
	    			</select>
				    Tahun : <input type='number' id='t_tahun' value='$tahun'>
				</td>
				<td>Cari barang : <input type='text' id='cari_brg' size='30'></td>
			</tr>
			<tr>
				<td>Kelompok</td>
		        <td>: <input type='text' id='txt_kodegr' size='2' maxlength='3'>
		            <img src='images/view.png' width='18' height='18' title='Cari grup' id='cari_gr'>
		            <input type='id='txt_namagr' size='25' readonly/>
		        </td>
            	<td>Supplier</td>
				<td>: <input type='text' id='txt_namasp' size='30' class='input_detail'> <input type='text' id='txt_kodesp' size='3' class='input_detail' readonly /></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='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' name='txt_carigr' id='txt_carigr' size='40'</td>
			</td>
		</table>
		<div id='tampil_data_gr' align='center' ></div>
		<div id='info_gr' align='center' style='overflow-x: auto;height: 400px;scroll-behavior: smooth'></div>
	</div>";
	
echo "<div id='data_pbpj' align='center' style='overflow-x: auto;height: 400px;scroll-behavior: smooth'></div>";

echo "</div>";
?>
