<script type="text/javascript">
$(document).ready(function() {
    $(function() {
        $("#theList.barang tr:even").addClass("stripe1");
        $("#theList.barang tr:odd").addClass("stripe2");

        $("#theList.barang tr").hover(
            function() {
                $(this).toggleClass("highlight");
            },
            function() {
                $(this).toggleClass("highlight");
            }
        );
    });	
});

	function pilih(ID){
		var kode = ID;
		var kwprs 	= $("#kwprs").val();
		var kwkar 	= $("#kwkar").val();
		var tkprs 	= $("#tkprs").val();
		var tkkar 	= $("#tkkar").val();
		var ptkpwp	= $("#ptkpwp").val();
		var ptkpis	= $("#ptkpis").val();
		var ptkpan	= $("#ptkpan").val();
		var maxanak = $("#maxanak").val();
		var nkwprs	= parseFloat(kwprs);
		var nkwkar	= parseFloat(kwkar);
		var ntkprs	= parseFloat(tkprs);
		var ntkkar	= parseFloat(tkkar);
		var nptkpwp	= parseInt(ptkpwp);
		var nptkpis	= parseInt(ptkpis);
		var nptkpan	= parseInt(ptkpan);
		var nmaxanak= parseInt(maxanak);
				
		$.ajax({
			type	: "POST",
			url		: "modul/gaji/cari_kar.php",
			data	: "kode="+kode,
			dataType: "json",
			success	: function(data){
				$("#txt_nik").val(kode);
				$("#txt_nama").val(data.nama);
				$("#txt_jabatan").val(data.jabatan);
				$("#sex").val(data.sex);
				$("#kawin").val(data.kawin);
				$("#anak").val(data.anak);
				$("#txt_gapok").val(data.gapok);
				$("#umak").val(data.umak);
				$("#txt_tunjab").val(data.tunjab);
				
				var sex		= $("#sex").val();
				var kawin	= $("#kawin").val();
				var anak 	= $("#anak").val();
				var gapok	= $("#txt_gapok").val();
				var tunjab	= $("#txt_tunjab").val();
				var janak	= parseInt(anak);
				var ngapok  = parseInt(gapok);
				var ntunjab = parseInt(tunjab);
				
				if(janak>nmaxanak){
					janak=nmaxanak;
				}
				if(sex=='LAKI-LAKI'){
					if(kawin=='KAWIN')
						var ptkp=nptkpwp+nptkpis;
					else
						var ptkp=nptkpwp;
					if(janak>0) ptkp=ptkp+(nptkpan*janak);
				}else{
					if(kawin=='KAWIN')
						var ptkp=nptkpwp;
					else
						var ptkp=nptkpwp+(nptkpan*janak);
				}
				$("#ptkp").val(ptkp);
				
				if(kawin=='TIDAK KAWIN'){
					var tunbpjs=(ntkprs*ngapok)/100;
					var potbpjs=((ntkprs+ntkkar)*ngapok)/100;
					var tht	   =(ntkkar*ngapok)/100;
				}else{
					var tunbpjs=(nkwprs*ngapok)/100;
					var potbpjs=((nkwprs+nkwkar)*ngapok)/100;
					var tht	   =(nkwkar*ngapok)/100;
				}
				var totgaji = ngapok+ntunjab+tunbpjs;
				var gaber	= totgaji-potbpjs;
				$("#txt_tunbpjs").val(tunbpjs);
				$("#txt_potbpjs").val(potbpjs);
				$("#txt_totgaji").val(totgaji);
				$("#txt_gaber").val(gaber);
				$("#tht").val(tht);
				$("#form_cari_kar").dialog('close');
				cari_nomor();		
			}
		});
	}
	
	function cari_nomor(){
		var bulan = $("#txt_bulan").val();
		var tahun = $("#txt_tahun").val();
		var nik   = $("#txt_nik").val();		
		
		$.ajax({
			type	: "POST",
			url		: "modul/gaji/cari_nomor.php",
			data	: "bulan="+bulan+
					"&tahun="+tahun+
					"&nik="+nik,
			dataType: "json",
			success	: function(data){
				$("#txt_kode").val(data.nomor);
				$("#txt_sakit").focus();
			}
		});
	}
</script>
<?php
include '../../inc/inc.koneksi.php';

$cari = $_POST['cari'];

echo "<table id='theList' class='barang' width='100%'>
	<tr>			
		<th>No.</th>
		<th>NIK</th>
		<th>Nama Karyawan</th>
		<th>Jabatan</th>
		<th>Gaji Pokok</th>
		<th>Uang Makan</th>
		<th>Tunj. Jabatan</th>
		<th>Ambil</th>
	</tr>";
	if (!empty($cari))
		$sql = "SELECT * FROM karyawan WHERE (nama LIKE '%$cari%' OR nik LIKE '%$cari%') ORDER BY nik";
	else
		$sql = "SELECT * FROM karyawan ORDER BY nik";

	$query = mysql_query($sql);		
	$no=1;
	while($r_data=mysql_fetch_array($query)){
		echo "<tr>
			<td align='center'>$no</td>
			<td>$r_data[nik]</td>
			<td>$r_data[nama]</td>
			<td>$r_data[jabatan]</td>
			<td>$r_data[gapok]</td>
			<td>$r_data[umak]</td>
			<td>$r_data[tunj_jab]</td>
			<td align='center'>
				<a href='javascript:void(0)' onClick=\"pilih('$r_data[nik]')\">
					<img src='icon/download.gif' border='0' id='tambah_data' title='Pilih' width='12' height='12' >
				</a>
			</td>
		</tr>";
		$no++;
	}
		
echo "</table>";
?>
