<?php
	include '../../inc/inc.koneksi.php';
	
	$bulan= $_GET['bulan'];
	$tahun= $_GET['tahun'];
	$thn  = $tahun-2000;
	$bln  = sprintf("%02s",$bulan);
	
	$sql2 = mysql_query("SELECT nama1 FROM company");
	$r2	  = mysql_fetch_assoc($sql2);
	$kop1 = $r2[nama1];

	if($bulan==1) $nbulan='JANUARI';
	else if($bulan==2) $nbulan='FEBRUARI';
	else if($bulan==3) $nbulan='MARET';
	else if($bulan==4) $nbulan='APRILI';
	else if($bulan==5) $nbulan='MEI';
	else if($bulan==6) $nbulan='JUNI';
	else if($bulan==7) $nbulan='JULI';
	else if($bulan==8) $nbulan='AGUSTUS';
	else if($bulan==9) $nbulan='SEPTEMBER';
	else if($bulan==10) $nbulan='OKTOBER';
	else if($bulan==11) $nbulan='NOVEMBER';
	else if($bulan==12) $nbulan='DESEMBER';
	else{
		$sql = "SELECT * FROM gaji WHERE bulan='$bulan' AND tahun='$tahun' ORDER BY kode_gj";
		$query = mysql_query($sql);
		$r=mysql_fetch_assoc($query);
		$bulan1=substr($r[tanggal],5,2);
		
		if($bulan1==1) $nbulan='JANUARI';
		else if($bulan1==2) $nbulan='FEBRUARI';
		else if($bulan1==3) $nbulan='MARET';
		else if($bulan1==4) $nbulan='APRILI';
		else if($bulan1==5) $nbulan='MEI';
		else if($bulan1==6) $nbulan='JUNI';
		else if($bulan1==7) $nbulan='JULI';
		else if($bulan1==8) $nbulan='AGUSTUS';
		else if($bulan1==9) $nbulan='SEPTEMBER';
		else if($bulan1==10) $nbulan='OKTOBER';
		else if($bulan1==11) $nbulan='NOVEMBER';		
		else $nbulan='DESEMBER';
	}
		
	if($bulan==13) $judul='DAFTAR PENERIMAAN THR';
	else $judul='DAFTAR GAJI KARYAWAN';
		
	$content = "<b><h3>$kop1</h3></b>
	<b><li>$judul</li></b>
	<b><li>BULAN $nbulan $tahun</li></b>
	<br>
	
	<table width='390' border='1' style='border-collapse:collapse'>
		<tr>
			<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);

		$no=1;
		$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)){
			$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];
		
		$content .="<tr>
					<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++;
		}
		
		$content .= "<tr>
			<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>";
				
		header("Content-type: application/x-msdownload");
		header("Content-Disposition: attachment; filename=gaji$thn$bln.xls");
		header("Pragma: no-cache");
		header("Expires: 0");
		echo $content;
?>