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

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

	function edit_data(ID){
		var kode = ID;
				
		$.ajax({
			type	: "POST",
			url		: "modul/gaji/edit.php",
			data	: "kode="+kode,
			dataType: "json",
			success	: function(data){
				$("#txt_kode").val(kode);
				$("#txt_nik").val(data.nik);				
				$("#txt_nama").val(data.nama);
				$("#txt_sakit").val(data.sakit);
				$("#txt_ijin").val(data.ijin);
				$("#txt_alpa").val(data.alpa);
				$("#txt_jabatan").val(data.jabatan);
				$("#txt_gapok").val(data.gapok);
				$("#txt_tunmak").val(data.tunmak);
				$("#txt_tunbpjs").val(data.tunbpjs);
				$("#txt_tunjab").val(data.tunjab);
				$("#txt_namatl").val(data.namatl);
				$("#txt_jumlahtl").val(data.jumlahtl);				
				$("#txt_totgaji").val(data.totgaji);
				$("#txt_potabsen").val(data.potabsen);
				$("#txt_umgaji").val(data.umgaji);
				$("#txt_angsuran").val(data.angsuran);
				$("#txt_potbpjs").val(data.potbpjs);
				$("#txt_potpph").val(data.potpph);
				$("#txt_namapl").val(data.namapl);
				$("#txt_jumlahpl").val(data.jumlahpl);
				$("#txt_gaber").val(data.gaber);				
			}
		});
	}
	
	function hapus_data(ID){
		var pilih = confirm('Hapus data karyawan kode '+ID+' ?');
		
		if (pilih==true) {
		var kode = ID;
		
		$.ajax({
			type	: "POST",
			url		: "modul/gaji/hapus.php",
			data	: "kode="+kode,
			success	: function(data){				
				$("#info").html(data);
				tampil_data_detail();
			}			
		});
		}
	}
	
	function tampil_data_detail(kode){		
		var bulan = $("#txt_bulan").val();
		var tahun = $("#txt_tahun").val();
		
		$("#data_detail").show();
		$("#data_detail").load('modul/gaji/tampil_data_detail.php?bulan='+bulan+'&tahun='+tahun);
		$("#txt_harief").focus();
	}
</script>

<?php
include '../../inc/inc.koneksi.php';

$bulan= $_GET[bulan];
$tahun= $_GET[tahun];

echo "<table id='theList' class='detail' width='100%'>
		<tr>
			<th>Action</th>
			<th>NIK</th>
			<th>Nama Karyawan</th>
			<th>Jabatan</th>
			<th>Sakit</th>
			<th>Ijin</th>
			<th>Alpa</th>
			<th>Gaji Pokok</th>
			<th>Uang Makan</th>
			<th>Tunj. BPJS</th>
			<th>Tunj. Jabatan</th>
			<th>Tunj. Lain</th>
			<th>Jumlah TL</th>
			<th>Total Gaji</th>
			<th>Potong. Absen</th>
			<th>UM Gaji</th>
			<th>Angsuran</th>
			<th>Potong. BPJS</th>
			<th>Potong. PPh 21</th>
			<th>Potong. Lain</th>
			<th>Jumlah PL</th>
			<th>Gaji Bersih</th>
		</tr>";
		
		$sql = "SELECT * FROM gaji WHERE bulan='$bulan' AND tahun='$tahun' ORDER BY kode_gj";
				
		$query = mysql_query($sql);
		$jml_data = mysql_num_rows($query);
		$no=0;
		$t_gapok  = 0;
		$t_tunmak = 0;
		$t_tunjab = 0;
		$t_tunbpjs= 0;
		$t_tunpph = 0;
		$t_tunlain= 0;		
		$t_totgaji= 0;
				
		$t_potabs = 0;
		$t_umgaji = 0;
		$t_angsur = 0;
		$t_potbpjs= 0;
		$t_potpph = 0;
		$t_potlain= 0;
		$t_gaber  = 0;
		
		while($r_data=mysql_fetch_array($query)){			
			
			echo "<tr>
					<td align='center'>						
						<a href='javascript:void(0)' onClick=\"edit_data('$r_data[kode_gj]')\">
							<img src='icon/thumb_up.png' border='0' id='edit' title='Edit' width='12' height='12' >
						</a>
						<a href='javascript:void(0)' onClick=\"hapus_data('$r_data[kode_gj]')\">
							<img src='icon/thumb_down.png' border='0' id='hapus' title='Hapus' width='12' height='12' >
						</a>
					</td>
					<td>$r_data[nik]</td>
					<td>$r_data[nama]</td>
					<td>$r_data[jabatan]</td>
					<td align='center'>$r_data[sakit]</td>
					<td align='center'>$r_data[ijin]</td>
					<td align='center'>$r_data[alpa]</td>
					<td align='right'>".number_format($r_data[gapok],0)."</td>
					<td align='right'>".number_format($r_data[tunj_mak],0)."</td>
					<td align='right'>".number_format($r_data[tunj_bpjs],0)."</td>
					<td align='right'>".number_format($r_data[tunj_jab],0)."</td>
					<td>$r_data[nama_tl]</td>
					<td align='right'>".number_format($r_data[jumlah_tl],0)."</td>
					<td align='right'>".number_format($r_data[tot_gaji],0)."</td>
					<td align='right'>".number_format($r_data[pot_absen],0)."</td>
					<td align='right'>".number_format($r_data[um_gaji],0)."</td>
					<td align='right'>".number_format($r_data[angsuran],0)."</td>
					<td align='right'>".number_format($r_data[pot_bpjs],0)."</td>
					<td align='right'>".number_format($r_data[pot_pph21],0)."</td>
					<td>$r_data[nama_pl]</td>
					<td align='right'>".number_format($r_data[jumlah_pl],0)."</td>
					<td align='right'>".number_format($r_data[gaber],0)."</td>					
				</tr>";
			$no++;
			$t_gapok  =$t_gapok+$r_data[gapok];
			$t_tunmak =$t_tunmak+$r_data[tunj_mak];
			$t_tunbpjs=$t_tunbpjs+$r_data[tunj_bpjs];
			$t_tunjab =$t_tunjab+$r_data[tunj_jab];
			$t_tunlain=$t_tunlain+$r_data[jumlah_tl];
			$t_totgaji=$t_totgaji+$r_data[tot_gaji];
			$t_potabs =$t_potabs+$r_data[pot_absen];
			$t_umgaji =$t_umgaji+$r_data[um_gaji];
			$t_angsur =$t_angsur+$r_data[angsuran];
			$t_potbpjs=$t_potbpjs+$r_data[pot_bpjs];
			$t_potpph =$t_potpph+$r_data[pot_pph21];
			$t_potlain=$t_potlain+$r_data[jumlah_pl];
			$t_gaber  =$t_gaber+$r_data[gaber];
		}
		echo "<tr>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td align='right'>Total</td>
			<td aligh='right'>".number_format($t_gapok,0)."</td>
			<td align='right'>".number_format($t_tunmak,0)."</td>
			<td align='right'>".number_format($t_tunbpjs,0)."</td>
			<td align='right'>".number_format($t_tunjab,0)."</td>
			<td></td>
			<td align='right'>".number_format($t_tunlain,0)."</td>
			<td align='right'>".number_format($t_totgaji,0)."</td>
			<td align='right'>".number_format($t_potabs,0)."</td>
			<td align='right'>".number_format($t_umgaji,0)."</td>
			<td align='right'>".number_format($t_angsur,0)."</td>
			<td align='right'>".number_format($t_potbpjs,0)."</td>
			<td align='right'>".number_format($t_potpph,0)."</td>
			<td></td>
			<td align='right'>".number_format($t_potlain,0)."</td>
			<td align='right'>".number_format($t_gaber,0)."</td>
		</tr>
		</table>";
		
	echo "<table width='100%'>
		<tr>
			<td>Jumlah Data : $no</td>
		</tr>
		</table>";
?>