<?php 
require_once 'master_validation.php';
require_once 'config/connection.php';
require_once 'lib/nangkoelib.php';
require_once 'lib/zLib.php';
require_once 'lib/fpdf.php';
$proses = checkPostGet('proses', '');
$kdorg = checkPostGet('kdorg', '');
$thn = checkPostGet('thn', '');
$perlist = month_inbetween($thn . '-01', $thn . '-12');
$iProdr = "select * from " . $dbname . ".pabrik_produksi_vw where tahun='" . $thn . "' and kodeorg='" . $kdorg . "' ";
$nProdr = mysql_query($iProdr) or die(mysql_error($conn));
while ($dProdr = mysql_fetch_assoc($nProdr)) {
    $tbsr[$dProdr['periode']]['R'] = $dProdr['tbsdiolahton'];
    $cpor[$dProdr['periode']]['R'] = $dProdr['cpoton'];
    $pkr[$dProdr['periode']]['R'] = $dProdr['pkton'];
}
$olah = $kgcpo = $kgker = $rp = "";
for ($i = 1; $i <= 12; $i++) {
    if (strlen($i) < 2) {
        $i = '0' . $i;
    }
    if ($i == 12) {
        $olah .= 'sum(olah' . $i . ') as olah' . $i;
        $kgcpo .= 'sum(kgcpo' . $i . ') as kgcpo' . $i;
        $kgker .= 'sum(kgker' . $i . ') as kgker' . $i;
        $rp .= 'sum(rp' . $i . ') as rp' . $i;
    } else {
        $olah .= 'sum(olah' . $i . ') as olah' . $i . ',';
        $kgcpo .= 'sum(kgcpo' . $i . ') as kgcpo' . $i . ',';
        $kgker .= 'sum(kgker' . $i . ') as kgker' . $i . ',';
/*$noKom=$counterKar=$counterGaji="";
$iKom="select distinct idkomponen from ".$dbname.".sdm_gaji where kodeorg='".$kdorg."' "
        . " ".$komponen." ";
$nKom=mysql_query($iKom) or die (mysql_error($conn));
while($dKom=mysql_fetch_assoc($nKom))
{
    $noKom+=1;
    $idKomponen[$dKom['idkomponen']]=$dKom['idkomponen'];
}*/
$iKom = "select distinct (idkomponen) as idkomponen from " . $dbname . ".sdm_gaji_vw where 1=1 " . " " . $komponen . " order by idkomponen asc ";
$nKom = mysql_query($iKom) or die(mysql_error($conn));
while ($dKom = mysql_fetch_assoc($nKom)) {
    $noKom += 1;
    $idKomponen[$dKom['idkomponen']] = $dKom['idkomponen'];
}
$rangePer = month_inbetween($per1, $per2);
$colspanPer = count($rangePer);
$tglMasuk = $per1 . '-01';
$tglKeluar = $per2 . '-28';
//echo $tglMasuk;
#ambil list datakaryawannya #tolong buat validasi seperti proses gaji untuk filter karyawan aktif
$iKar = "select distinct(karyawanid) as karyawanid,namakaryawan,nik,kodejabatan,tipekaryawan" . " from " . $dbname . ".sdm_gaji_vw  where kodeorg='" . $kdorg . "' " . $sorttk . " " . " and periodegaji between '" . $per1 . "' and '" . $per2 . "' " . $komponen . " order by namakaryawan asc";
$nKar = mysql_query($iKar) or die(mysql_error($conn));
while ($dKar = mysql_fetch_assoc($nKar)) {
    $counterKar += 1;
    $kar[$dKar['karyawanid']] = $dKar['karyawanid'];
    $nm[$dKar['karyawanid']] = $dKar['namakaryawan'];
    $nik[$dKar['karyawanid']] = $dKar['nik'];
    $jabatan[$dKar['karyawanid']] = $dKar['kodejabatan'];
    $tipekaryawan[$dKar['karyawanid']] = $dKar['tipekaryawan'];
}
include 'master_mainMenu.php';
OPEN_BOX('', "<b>" . $_SESSION['lang']['tutup'] . " " . $_SESSION['lang']['arealstatement'] . "</b>");
?>
<link rel=stylesheet type=text/css href="style/zTable.css">
<script language="javascript" src="js/zMaster.js"></script>
<script type="application/javascript" src="js/kebun_3tutuparesta.js"></script>
<?php 
$lksi = substr($_SESSION['empl']['lokasitugas'], 0, 4);
$sKbn = "select namaorganisasi,kodeorganisasi from " . $dbname . ".organisasi where kodeorganisasi='" . $lksi . "'";
$qKbn = mysql_query($sKbn) or die(mysql_error());
$optKbn = "";
while ($rKbn = mysql_fetch_assoc($qKbn)) {
    $optKbn .= "<option value=" . $rKbn['kodeorganisasi'] . ">" . $rKbn['namaorganisasi'] . "</option>";
}
$tahun = date("Y");
$arrPeriod = month_inbetween(date("Y") - 1 . '-01', date("Y") + 1 . '-12');
$periode = date("Y") - 1 . '-01';
$perakhir = date("Y-m-d");
//echo $perakhir;
//$perakhir=(date("Y")+1).'-01';
#bentuk daftar periode sampai periode terakhir
$start = new DateTime($periode . '-01');
$end = new DateTime($perakhir . '-01');
$inc = DateInterval::createFromDateString('first day of next month');
$end->modify('+1 day');
$p = new DatePeriod($start, $inc, $end);
foreach ($p as $d) {
    $optPerList .= "<option value='" . $d->format('Y-m') . "'>" . $d->format('Y-m') . "</option>";
}
?>