<script type="text/javascript">	
$(document).ready(function() {	
	$("#tabs").tabs({selected:0});	
	$("#form").load('spv/order_pb/form.php');
	$("#info_sopb").hide();

	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){				
				$("#tgl_awal").val(data.tanggal);
				$("#tgl_akhir").val(data.tanggal);
				$("#d_tglawal").val(data.tanggal);
				$("#d_tglakhir").val(data.tanggal);
			}
		});
	}
	
	$('#form_cari_sup').dialog({
		autoOpen: false,
		modal	: true,
		width: 700,
	});

	$('#d_namasp').keyup(function(){
		var cari= $("#d_carisp").val();
		$('#form_cari_sup').dialog('open');
		$("#info_sup").load('spv/order_pb/tampil_data_sup.php?cari='+cari);
		$("#d_carisp").focus();
	});
	
	$("#d_carisp").keyup(function(){
		$("#info_sup").show();
		var cari= $("#d_carisp").val();
		
		$.ajax({
			type	: "POST",
			url	    : "spv/order_pb/tampil_data_sup.php",
			data	: "cari="+cari,
			success	: function(data){
				$("#info_sup").html(data);
			}
		});
	});
	
	$("#cari_daf").click(function(){
		var tgl_awal	= $("#d_tglawal").val();
		var tgl_akhir	= $("#d_tglakhir").val();
		var kodesp   	= $("#d_kodesp").val();
		var kodecab  	= $("#d_kodecab").val();
        
		$("#tampil_data").load('spv/order_pb/tampil_data.php?tgl_awal='+tgl_awal+'&tgl_akhir='+tgl_akhir+'&kodesp='+kodesp+'&kodecab='+kodecab);
	});
	
	$("#cetak_daf").click(function(){
		var tgl_awal	= $("#d_tglawal").val();
		var tgl_akhir	= $("#d_tglakhir").val();
		var kodesp  	= $("#d_kodesp").val();
		var namasp  	= $("#d_namasp").val();
		var kodecab  	= $("#d_kodecab").val();
		
		window.location.href='modul/laporan/daftar_sopb.php?tgl_awal='+tgl_awal+'&tgl_akhir='+tgl_akhir+'&kodesp='+kodesp+'&namasp='+namasp+'&kodecab='+kodecab;
	});
	
	$("#tutup_daf").click(function(){
		document.location='?module=home';
	});
	
	$('#os_namasp').keyup(function(){
		var cari= $("#d_carisp").val();
		$('#form_cari_sup').dialog('open');
		$("#info_sup").load('spv/order_pb/tampil_data_sup.php?cari='+cari);
		$("#d_carisp").focus();
	});
	
	$("#cari_osp").click(function(){
		var kodesp = $("#os_kodesp").val();

		$("#tampil_data_osp").load('spv/order_pb/tampil_data_osp.php?kodesp='+kodesp);
	});
	
	$("#cetak_osp").click(function(){
		var kodesp = $("#d_kodesp").val();
		var namasp = $("#d_namasp").val();
		
		window.location.href='modul/laporan/daftar_osp.php?kodesp='+kodesp+'&namasp='+namasp;
	});
	
	$("#tutup_daf").click(function(){
		document.location='?module=home';
	});
	
	$("#tutup_osp").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 id='tabs'>";
echo "<ul >
        <li><a href='#form'>Input Pesanan Pembelian</a></li>
	    <li><a href='#daftar'>Daftar Pesanan Pembelian</a></li>
	    <li><a href='#outst_ps'>Outstanding Pesanan</a></li>
    </ul>";
	  
echo "<div id='form'></div>";

echo "<div id='daftar'>
		<div id='pencarian_daf'>
			<table width='100%'>
				<tr>
					<td>Tanggal order : <input type='date' id='d_tglawal' size='10'> Sampai dengan <input type='date' id='d_tglakhir' size='10'></td>
					<td>Supplier : <input type='text' id='d_namasp' size='25' class='input' >
						<input type='text' id='d_kodesp' size='3' class='input' class='filter_ds' readonly />
					</td>
					<td>Apotek : <select id='d_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>
						<button id='cari_daf'>Cari</button>
						<button id='cetak_daf'>Cetak</button>
						<button id='tutup_daf'>Tutup</button>
					</td>
				</tr>
			</table>
		</div>
			
		<div id='tampil_data' align='center' style='overflow-x: auto;height: 450px;scroll-behavior: smooth'></div>
	</div>";
	
echo "<div id='outst_ps'>
		<div id='pencarian_daf'>
			<table width='100%'>
				<tr>
					<td>Supplier : <input type='text' id='os_namasp' size='25' class='input'>
						<input type='text' id='os_kodesp' size='3' class='input' class='filter_ds' readonly />
					</td>
					<td>
						<button id='cari_osp'>Cari</button>
						<button id='cetak_osp'>Cetak</button>
						<button id='tutup_osp'>Tutup</button>
					</td>
				</tr>
			</table>
		</div>
			
		<div id='tampil_data_osp' align='center' style='overflow-x: auto;height: 450px;scroll-behavior: smooth'></div>
	</div>";

echo "<div id='form_cari_sup' title='Pencarian Data Supplier'>
		<table width='100%'>
			<tr>
				<td>Cari Supplier : <input type='text' id='d_carisp' size='40'></td>
			</tr>
		</table>
		<div id='info_sup' align='center'></div>
	</div>";
	
echo "<div id='info' align='center'></div>";

echo "</div>";
?>