<style type="text/css">
#tampil_slip{
	font-size:12px;
	font-weight:bold;
	color:#F00;
}
</style>

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

$sql2 = mysql_query("SELECT nama1 FROM company");
$r2	  = mysql_fetch_assoc($sql2);
$kop1 = $r2[nama1];

$bulan= $_GET['bulan'];
$tahun= $_GET['tahun'];
$nik1 = $_GET['nik1'];
$nik2 = $_GET['nik2'];

mysql_query("DELETE FROM slip_gaji");

if(!($nik2==''))
	$sql = "SELECT * FROM gaji WHERE bulan='$bulan' AND tahun='$tahun' AND nik BETWEEN '$nik1' AND '$nik2' ORDER BY kode_gj";
else
	$sql = "SELECT * FROM gaji WHERE bulan='$bulan' AND tahun='$tahun' ORDER BY kode_gj";
$query = mysql_query($sql);

$no=0;
while($r=mysql_fetch_array($query)){
	$no=$no+1;
	$nik=$r[nik];
	$nama=$r[nama];
	$jabatan=$r[jabatan];
	$bulan=$r[bulan];
	$alpa=$r[alpa];
	$gapok=$r[gapok];
	$tunmak=$r[tunj_mak];
	$tunjab=$r[tunj_jab];
	$tunbpjs=$r[tunj_bpjs];
	$namatl=$r[nama_tl];
	$jumlahtl=$r[jumlah_tl];
	$totgaji=$r[tot_gaji];
	$potabsen=$r[pot_absen];
	$umgaji=$r[um_gaji];
	$angsuran=$r[angsuran];
	$potbpjs=$r[pot_bpjs];
	$potpph=$r[pot_pph21];
	$namapl=$r[nama_pl];
	$jumlahpl=$r[jumlah_pl];
	$gaber=$r[gaber];
	
	if($bulan==1)
		$cbulan='Januari';
	else if($bulan==2)
		$cbulan='Februari';
	else if($bulan==3)
		$cbulan='Maret';
	else if($bulan==4)
		$cbulan='April';
	else if($bulan==5)
		$cbulan='Mei';
	else if($bulan==6)
		$cbulan='Juni';
	else if($bulan==7)
		$cbulan='Juli';
	else if($bulan==8)
		$cbulan='Agustus';
	else if($bulan==9)
		$cbulan='September';
	else if($bulan==10)
		$cbulan='Oktober';
	else if($bulan==11)
		$cbulan='November';
	else $cbulan='Desember';
	
	if($no==1){
		$urut=1;
		$nik1=$nik;
		mysql_query("INSERT INTO slip_gaji (nik1,urut,keter1) VALUES('$nik','$urut','$kop1')");
		$urut=$urut+1;
		mysql_query("INSERT INTO slip_gaji (nik1,urut,keter1) VALUES('$nik','$urut','')");
		$urut=$urut+1;
		mysql_query("INSERT INTO slip_gaji (nik1,urut,keter1) VALUES('$nik','$urut','TANDA TERIMA GAJI')");
		$urut=$urut+1;
		mysql_query("INSERT INTO slip_gaji (nik1,urut,keter1) VALUES('$nik','$urut','')");
		$urut=$urut+1;
		mysql_query("INSERT INTO slip_gaji (nik1,urut,keter1) VALUES('$nik','$urut','Nama  : $nama')");
		$urut=$urut+1;
		mysql_query("INSERT INTO slip_gaji (nik1,urut,keter1) VALUES('$nik','$urut','Bulan : $cbulan $tahun')");
		$urut=$urut+1;
		mysql_query("INSERT INTO slip_gaji (nik1,urut,keter1) VALUES('$nik','$urut','PENERIMAAN :')");
		$urut=$urut+1;
		mysql_query("INSERT INTO slip_gaji (nik1,urut,keter1,rp1,jumlah1) VALUES('$nik','$urut','1. Gaji Pokok','Rp','$gapok')");
		$urut=$urut+1;
		mysql_query("INSERT INTO slip_gaji (nik1,urut,keter1,rp1,jumlah1) VALUES('$nik','$urut','2. Tunjangan Makan','Rp','$tunmak')");
		$urut=$urut+1;
		mysql_query("INSERT INTO slip_gaji (nik1,urut,keter1,rp1,jumlah1) VALUES('$nik','$urut','3. Tunjangan BPJS','Rp','$tunbpjs')");
		$urut=$urut+1;
		mysql_query("INSERT INTO slip_gaji (nik1,urut,keter1,rp1,jumlah1) VALUES('$nik','$urut','4. Tunjangan Jabatan','Rp','$tunjab')");
		$urut=$urut+1;
		mysql_query("INSERT INTO slip_gaji (nik1,urut,keter1,rp1,jumlah1) VALUES('$nik','$urut','5. Tunjangan $namatl','Rp','$jumlahtl')");
		$urut=$urut+1;
		mysql_query("INSERT INTO slip_gaji (nik1,urut,keter1,rp1,jumlah1) VALUES('$nik','$urut','   Total Penerimaan','Rp','$totgaji')");
		$urut=$urut+1;
		mysql_query("INSERT INTO slip_gaji (nik1,urut,keter1) VALUES('$nik','$urut','')");
		$urut=$urut+1;
		mysql_query("INSERT INTO slip_gaji (nik1,urut,keter1) VALUES('$nik','$urut','POTONGAN :')");
		$urut=$urut+1;
		mysql_query("INSERT INTO slip_gaji (nik1,urut,keter1,rp1,jumlah1) VALUES('$nik','$urut','1. Potongan BPJS','Rp','$potbpjs')");
		$urut=$urut+1;
		mysql_query("INSERT INTO slip_gaji (nik1,urut,keter1,rp1,jumlah1) VALUES('$nik','$urut','2. Uang Muka Gaji','Rp','$umgaji')");
		$urut=$urut+1;
		mysql_query("INSERT INTO slip_gaji (nik1,urut,keter1,rp1,jumlah1) VALUES('$nik','$urut','3. Angsuran Pinjaman','Rp','$angsuran')");
		$urut=$urut+1;
		mysql_query("INSERT INTO slip_gaji (nik1,urut,keter1,rp1,jumlah1) VALUES('$nik','$urut','4. Absen $alpa hari','Rp','$potabsen')");
		$urut=$urut+1;
		mysql_query("INSERT INTO slip_gaji (nik1,urut,keter1,rp1,jumlah1) VALUES('$nik','$urut','5. PPh Pasal 21','Rp','$potpph')");
		$urut=$urut+1;
		mysql_query("INSERT INTO slip_gaji (nik1,urut,keter1,rp1,jumlah1) VALUES('$nik','$urut','6. Potongan $namapl','Rp','$jumlahpl')");
		$urut=$urut+1;
		mysql_query("INSERT INTO slip_gaji (nik1,urut,keter1,rp1,jumlah1) VALUES('$nik','$urut','Gaji Bersih','Rp','$gaber')");
		$urut=$urut+1;
		mysql_query("INSERT INTO slip_gaji (nik1,urut,keter1) VALUES('$nik','$urut','')");
		$urut=$urut+1;
		mysql_query("INSERT INTO slip_gaji (nik1,urut,keter1) VALUES('$nik','$urut','')");
		
	}else{
		$urut=1;		
		mysql_query("UPDATE slip_gaji SET nik2='$nik',keter2='$kop1' WHERE nik1='$nik1' AND urut='$urut'");
		$urut=$urut+1;
		mysql_query("UPDATE slip_gaji SET nik2='$nik' WHERE nik1='$nik1' AND urut='$urut'");
		$urut=$urut+1;
		mysql_query("UPDATE slip_gaji SET nik2='$nik',keter2='TANDA TERIMA GAJI' WHERE nik1='$nik1' AND urut='$urut'");
		$urut=$urut+1;
		mysql_query("UPDATE slip_gaji SET nik2='$nik' WHERE nik1='$nik1' AND urut='$urut'");
		$urut=$urut+1;
		mysql_query("UPDATE slip_gaji SET nik2='$nik',keter2='Nama  : $nama' WHERE nik1='$nik1' AND urut='$urut'");
		$urut=$urut+1;
		mysql_query("UPDATE slip_gaji SET nik2='$nik',keter2='Bulan : $cbulan $tahun' WHERE nik1='$nik1' AND urut='$urut'");
		$urut=$urut+1;
		mysql_query("UPDATE slip_gaji SET nik2='$nik',keter2='PENERIMAAN :' WHERE nik1='$nik1' AND urut='$urut'");
		$urut=$urut+1;
		mysql_query("UPDATE slip_gaji SET nik2='$nik',keter2='1. Gaji Pokok',rp2='Rp',jumlah2='$gapok' WHERE nik1='$nik1' AND urut='$urut'");
		$urut=$urut+1;
		mysql_query("UPDATE slip_gaji SET nik2='$nik',keter2='2. Tunjangan Makan',rp2='Rp',jumlah2='$tunmak' WHERE nik1='$nik1' AND urut='$urut'");
		$urut=$urut+1;
		mysql_query("UPDATE slip_gaji SET nik2='$nik',keter2='3. Tunjangan BPJS',rp2='Rp',jumlah2='$tunbpjs' WHERE nik1='$nik1' AND urut='$urut'");
		$urut=$urut+1;
		mysql_query("UPDATE slip_gaji SET nik2='$nik',keter2='4. Tunjangan Jabatan',rp2='Rp',jumlah2='$tunjab' WHERE nik1='$nik1' AND urut='$urut'");
		$urut=$urut+1;
		mysql_query("UPDATE slip_gaji SET nik2='$nik',keter2='5. Tunjangan $namatl',rp2='Rp',jumlah2='$jumlahtl' WHERE nik1='$nik1' AND urut='$urut'");
		$urut=$urut+1;
		mysql_query("UPDATE slip_gaji SET nik2='$nik',keter2='   Total Penerimaan',rp2='Rp',jumlah2='$totgaji' WHERE nik1='$nik1' AND urut='$urut'");
		$urut=$urut+1;
		mysql_query("UPDATE slip_gaji SET nik2='$nik' WHERE nik1='$nik1' AND urut='$urut'");
		$urut=$urut+1;
		mysql_query("UPDATE slip_gaji SET nik2='$nik',keter2='POTONGAN :' WHERE nik1='$nik1' AND urut='$urut'");
		$urut=$urut+1;
		mysql_query("UPDATE slip_gaji SET nik2='$nik',keter2='1. Potongan BPJS',rp2='Rp',jumlah2='$potbpjs' WHERE nik1='$nik1' AND urut='$urut'");
		$urut=$urut+1;
		mysql_query("UPDATE slip_gaji SET nik2='$nik',keter2='2. Uang Muka Gaji',rp2='Rp',jumlah2='$umgaji' WHERE nik1='$nik1' AND urut='$urut'");
		$urut=$urut+1;
		mysql_query("UPDATE slip_gaji SET nik2='$nik',keter2='3. Angsuran Pinjaman',rp2='Rp',jumlah2='$angsuran' WHERE nik1='$nik1' AND urut='$urut'");
		$urut=$urut+1;
		mysql_query("UPDATE slip_gaji SET nik2='$nik',keter2='4. Absen $alpa hari',rp2='Rp',jumlah2='$potabsen' WHERE nik1='$nik1' AND urut='$urut'");
		$urut=$urut+1;
		mysql_query("UPDATE slip_gaji SET nik2='$nik',keter2='5. PPh Pasal 21',rp2='Rp',jumlah2='$potpph' WHERE nik1='$nik1' AND urut='$urut'");
		$urut=$urut+1;
		mysql_query("UPDATE slip_gaji SET nik2='$nik',keter2='6. Potongan $namapl',rp2='Rp',jumlah2='$jumlahpl' WHERE nik1='$nik1' AND urut='$urut'");
		$urut=$urut+1;
		mysql_query("UPDATE slip_gaji SET nik2='$nik',keter2='Gaji Bersih',rp2='Rp',jumlah2='$gaber' WHERE nik1='$nik1' AND urut='$urut'");
		$urut=$urut+1;
		mysql_query("UPDATE slip_gaji SET nik2='$nik' WHERE nik1='$nik1' AND urut='$urut'");
		$urut=$urut+1;
		mysql_query("UPDATE slip_gaji SET nik2='$nik' WHERE nik1='$nik1' AND urut='$urut'");
		$no=0;
	}
}
	
	$query = "SELECT * FROM slip_gaji ";
	$sql	= mysql_query($query);
	while($r=mysql_fetch_array($sql)){
		$ket1	=$r[keter1];
		$jumlah1=$r[jumlah1];
		$jumlah2=$r[jumlah2];
		$ktr1	=substr($r[keter1],0,5);
		$ket2	=$r[keter2];
		
		if($jumlah1==0)
			$tjumlah1='';
		else
			$tjumlah1=number_format($r[jumlah1],0);
		
		if($jumlah2==0)
			$tjumlah2='';
		else
			$tjumlah2=number_format($r[jumlah2],0);
		
		echo "<table width='100%'>
			<tr>";
				if($ket2==''){
					if($ket1==$kop1){
						echo "<td width='31%' style='border-bottom:double 2px'>$r[keter1]</td>
							<td style='border-bottom:double 2px'>$r[rp1]</td>
							<td width='12%' style='border-bottom:double 2px'></td>
							<td width='3.5%'></td>
							<td width='31%'>$r[keter2]</td>
							<td>$r[rp2]</td>
							<td width='12%'></td>";
					}else if($ktr1=='Nama '){
						echo "<td>$r[keter1]</td>
							<td>$r[rp1]</td>
							<td>$tjumlah1</td>
							<td width='4%'></td>
							<td>$r[keter2]</td>
							<td>$r[rp2]</td>
							<td></td>";
					}else if($ktr1=='Bulan'){
						echo "<td width='31%' style='border-bottom:double 2px'>$r[keter1]</td>
							<td style='border-bottom:double 2px'>$r[rp1]</td>
							<td width='12%' style='border-bottom:double 2px'></td>
							<td width='3.5%'></td>
							<td width='31%'>$r[keter2]</td>
							<td>$r[rp2]</td>
							<td width='12%'></td>";
					}else if($ktr1=='Gaji '){
						echo "<td width='31%' style='border-bottom:double 2px'>$r[keter1]</td>
							<td style='border-bottom:double 2px'>$r[rp1]</td>
							<td width='12%' style='border-bottom:double 2px' align='right'>$tjumlah1</td><td width='4%'></td>
							<td width='3.5%'></td>
							<td width='31%'>$r[keter2]</td>
							<td>$r[rp2]</td>
							<td width='12%' align='right'>$tjumlah2</td>";
					}else if($ktr1=='TANDA'){
						echo "<td>$r[keter1]</td>
							<td>$r[rp1]</td>
							<td>$tjumlah1</td><td width='4%'></td>
							<td>$r[keter2]</td>
							<td>$r[rp2]</td>
							<td></td>";
					}else if($ktr1=='PENER'){
						echo "<td>$r[keter1]</td>
							<td>$r[rp1]</td>
							<td>$tjumlah1</td><td width='4%'></td>
							<td>$r[keter2]</td>
							<td>$r[rp2]</td>
							<td></td>";
					}else if($ktr1=='POTON'){
						echo "<td>$r[keter1]</td>
							<td>$r[rp1]</td>
							<td>$tjumlah1</td><td width='4%'></td>
							<td>$r[keter2]</td>
							<td>$r[rp2]</td>
							<td></td>";
					}else{
						echo "<td width='31%'>$r[keter1]</td>
							<td>$r[rp1]</td>
							<td width='12%' align='right'>$tjumlah1</td><td width='4%'></td>
							<td width='3.5%'></td>
							<td width='31%'>$r[keter2]</td>
							<td>$r[rp2]</td>
							<td width='12%' align='right'>$tjumlah2</td>";
					}
				}else{
					if($ket1==$kop1){
						echo "<td width='31%' style='border-bottom:double 2px'>$r[keter1]</td>
							<td style='border-bottom:double 2px'>$r[rp1]</td>
							<td width='12%' style='border-bottom:double 2px'></td>
							<td width='3.5%'></td>
							<td width='31%' style='border-bottom:double 2px'>$r[keter2]</td>
							<td style='border-bottom:double 2px'>$r[rp2]</td>
							<td width='12%' style='border-bottom:double 2px'></td>";
						
					}else if($ktr1=='Nama '){
						echo "<td>$r[keter1]</td>
							<td>$r[rp1]</td>
							<td>$tjumlah1</td>
							<td></td>
							<td>$r[keter2]</td>7
							<td>$r[rp2]</td>
							<td>$tjumlah2</td>
							<td width='20.7%'></td>";
					}else if($ktr1=='Bulan'){
						echo "<td width='31%' style='border-bottom:double 2px'>$r[keter1]</td>
							<td style='border-bottom:double 2px'>$r[rp1]</td>
							<td width='12%' style='border-bottom:double 2px'></td>
							<td width='3.5%'></td>
							<td width='31%' style='border-bottom:double 2px'>$r[keter2]</td>
							<td style='border-bottom:double 2px'>$r[rp2]</td>
							<td width='12%' style='border-bottom:double 2px'></td>";
					}else if($ktr1=='Gaji '){
						echo "<td width='31%' style='border-bottom:double 2px'>$r[keter1]</td>
							<td style='border-bottom:double 2px'>$r[rp1]</td>
							<td width='12%' style='border-bottom:double 2px' align='right'>$tjumlah1</td>
							<td width='3.5%'></td>
							<td width='31%' style='border-bottom:double 2px'>$r[keter2]</td>
							<td style='border-bottom:double 2px'>$r[rp2]</td>
							<td width='12%' style='border-bottom:double 2px' align='right'>$tjumlah2</td>
							</tr>
							<tr><td></td></tr>
							<tr><td></td></tr>
							<tr><td></td>";
					}else if($ktr1=='TANDA'){
						echo "<td>$r[keter1]</td>
							<td>$r[rp1]</td>
							<td>$tjumlah1</td>
							<td width='4%'></td>
							<td>$r[keter2]</td>
							<td>$r[rp2]</td>
							<td>$tjumlah2</td>";
					}else if($ktr1=='PENER'){
						echo "<td>$r[keter1]</td>
							<td>$r[rp1]</td>
							<td>$tjumlah1</td>
							<td width='4%'></td>
							<td>$r[keter2]</td>
							<td>$r[rp2]</td>
							<td>$tjumlah2</td>";
					}else if($ktr1=='POTON'){
						echo "<td>$r[keter1]</td>
							<td>$r[rp1]</td>
							<td>$tjumlah1</td>
							<td width='4%'></td>
							<td>$r[keter2]</td>
							<td>$r[rp2]</td>
							<td>$tjumlah2</td>";
					}else{
						echo "<td width='31%'>$r[keter1]</td>
							<td>$r[rp1]</td>
							<td width='12%' align='right'>$tjumlah1</td>
							<td width='3.5%'></td>
							<td width='31%'>$r[keter2]</td>
							<td>$r[rp2]</td>
							<td width='12%' align='right'>$tjumlah2</td>";
					}
				}
		echo "</tr>
		</table>";
	}
?>