<?
session_start();
include"../plg/ses.php";
?>
<!DOCTYPE html>
<?
$idkar = $_GET['idkar'];
$smt = substr($idkar,0,9);
if($prof=='admin'){
  $menu = "../menu.php";
}else{
  $menu = "../menu2.php";
}
?>
<html>
<title></title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="../plg/w3.css">
<link rel="stylesheet" href="../plg/hijaucss.css">
<body>
<?include"$menu";?>
<hr/>
<div class="w3-container">
  <h4>SEMESTER <?=$smt?></h4>

  <table class="w3-table w3-card-2" id="myTable" style="">
    <tr>
      <th style="width:300px" class="w3-small w3-border w3-blue-gray w3-center">NAMA</th>
      <th style="width:150px" class="w3-small w3-border w3-blue-gray w3-center">NIP</th>
      <th style="width:200px" class="w3-small w3-border w3-blue-gray w3-center">UNIT</th>
      <th style="width:400px" class="w3-small w3-border w3-blue-gray w3-center">JABATAN</th>
      <th style="width:200px" class="w3-small w3-border w3-blue-gray w3-center">LOKASI</th>
      <th style="width:80px" class="w3-small w3-border w3-blue-gray w3-center"></th>
    </tr>
    <?
    include"../plg/kon.php";
    $sql = "select * from kpikar where idkar='$idkar'";
    $res = $conn->query($sql);
    while($b = $res->fetch_assoc()){

      $kuncicetak = $b['lok'];
      if($kuncicetak == 'Kantor Pusat'){
        $viscetak = "display:none";
        $viscetakpus = "display:";
      }
      if($kuncicetak !== 'Kantor Pusat'){
        $viscetak = "display:";
        $viscetakpus = "display:none";
      }


      $lokk = $b['lok'];
      $kunci = $b['kunci'];
      if($kunci == 'Selesai'){
        $kuncimati = "xx";
        $kuncidis = "Disabled";
        $kuncipesan = "alert('KPI SUDAH CLOSING !...')";
      }
    ?>
    <tr style="font-weight:bold" class="w3-light-gray">
      <td class="w3-small w3-border"><?=$b['nama']?></td>
      <td class="w3-small w3-border w3-center"><?=$b['nip']?></td>
      <td class="w3-small w3-border"><?=$b['unit']?></td>
      <td class="w3-small w3-border"><?=$b['jab']?></td>
      <td class="w3-small w3-border"><?=$lokk?></td>
      <td class="w3-small w3-border">
        <div class="w3-btn w3-green w3-small w3-round-large" onclick="bukakpi<?=$kuncimati?>('<?=$idkar?>')">Tambah KPI</div>
      </td>
    </tr>
    <?}?>
  </table>
<hr/>
  <table class="w3-table-all w3-hoverable">
    <thead>
      <tr class="w3-blue-gray w3-center">
        <th class="w3-small w3-center w3-border" rowspan="2">NO</th>
        <th class="w3-small w3-center w3-border" rowspan="2" style="width:120px;">KODE</th>
        <th class="w3-small w3-center w3-border" rowspan="2" style="width:80px;">KPI</th>
        <th class="w3-small w3-center w3-border" rowspan="2" style="width:100px;">POLARISASI</th>
        <th class="w3-small w3-center w3-border" rowspan="2">KEY PERFORMANCE INDICATOR<br/>(SASARAN KINERJA)</th>
        <th class="w3-small w3-center w3-border" rowspan="2">SATUAN</th>
        <th class="w3-small w3-center w3-border" rowspan="2">VOLUME</th>
        <th class="w3-small w3-center w3-border" rowspan="2">KUALITAS</th>
        <th class="w3-small w3-center w3-border w3-pale-yellow" colspan="3">PENCAPAIAN KINERJA</th>
        <th class="w3-small w3-center w3-border w3-pale-blue" colspan="2">HASIL PENILAIAN</th>
      </tr>
      <tr>
        <th class="w3-small w3-center w3-border w3-pale-yellow" colspan="">VOLUME</th>
        <th class="w3-small w3-center w3-border w3-pale-yellow" colspan="">KUALITAS</th>
        <th class="w3-small w3-center w3-border w3-pale-yellow" colspan="">CATATAN</th>
        <th class="w3-small w3-center w3-border w3-pale-blue" colspan="">KUANTITAS</th>
        <th class="w3-small w3-center w3-border w3-pale-blue" colspan="">KUALITAS</th>
      </tr>
    </thead>
    <form action="editkpiuserver2.php" method="post" id="form">
      <input type="hidden" name="idkar" value="<?=$idkar?>"/>
    <?
    include"../plg/kon.php";
    $i = 1;
    $x = 1;
    $v = 1;
    $a1 = 1;
    $a2 = 1;
    $a1 = 1;
    $a2 = 1;
    $a3 = 1;
    $a4 = 1;
    $a5 = 1;
    $sql = "select * from kpiuser where idkar='$idkar' and del='0' order by kpi asc";
    $res = $conn->query($sql);
    while($a = $res->fetch_assoc()){
      $idx = $a['id'];
      $uang = $a['foktan'];
      $pkvoll = number_format($a['pkvol']);
      $hpkuanx = $a['hpkuan'];
      if($uang == '1'){
        $warna = "w3-light-blue";$ket = $a['fok'];
      }elseif($uang == "2"){
        $warna = "w3-cyan";$ket = $a['fok'];
      }elseif($uang == "3"){
        $warna = "w3-aqua";$ket = $a['fok'];
      }elseif($uang == "4"){
        $warna = "w3-teal";$ket = $a['fok'];
      }elseif($uang == "5"){
        $warna = "w3-green";$ket = $a['fok'];
      }elseif($uang == "6"){
        $warna = "w3-light-green";$ket = $a['fok'];
      }elseif($uang == "7"){
        $warna = "w3-amber";$ket = $a['fok'];
      }
      if($hpkuanx !== '0'){
        $ro = "readonly";
        $psn = "alert('USER SUDAH INPUT VOLUME PENCAPAIAN')";
        $wd = "w3-pale-yellow";
        $wd2 = "w3-pale-blue";
      }else{
        $ro = "";
        $psn = "";
        $wd = "";
        $wd2 = "";
      }
      ?>
      <tr class="<?=$warna?>" title="<?=strtoupper($ket)?>" onclick="<?=$kuncipesan?>">
        <td class="w3-small w3-center w3-border ">
          <div class="w3-btn w3-red w3-small w3-round-xlarge"
          onclick="delkpi<?=$kuncimati?>('<?=$a['id']?>','<?=$a['kode']?>','<?=$a['idkar']?>')"><?=$i++?></div>
        </td>
        <td class="w3-small w3-border "><?=$a['kode']?></td>
        <td class="w3-small w3-border "><?=$a['kpi']?></td>
        <td class="w3-small w3-center w3-border "><?=$a['pola']?></td>
        <td class="w3-small w3-border "><?=$a['des']?></td>
        <td class="w3-small w3-center w3-border "><?=$a['sat']?></td>
        <td class="w3-small w3-center w3-border ">
          <input type="hidden" value="<?=$a['id']?>" name="id<?=$x++?>"/>
          <i id="nf<?=$a1++?>" class="w3-small"><?=number_format($a['vol'],2)?></i><br/>
          <input type="number" name="vol<?=$v++?>" class="w3-border w3-small w3-input <?=$wd?>" value="<?=$a['vol']?>"
          style="width:130px" <?=$ro?> onclick="<?=$psn?>" id="isi<?=$a2++?>" onkeyup="nih('<?=$a3++?>')" <?=$kuncidis?>/>
        </td>
        <td class="w3-small w3-center w3-border "><?=$a['kua']?> %</td>
        <td class="w3-small w3-center w3-border <?=$wd?>"><?=$a['pkvol']?></td>
        <td class="w3-small w3-center w3-border <?=$wd?>"><?=$a['pkkua']?></td>
        <td class="w3-small w3-center w3-border <?=$wd?>"><?=$a['pkcat']?></td>
        <td class="w3-small w3-center w3-border <?=$wd2?>"><?=$a['hpkuan']?> %</td>
        <td class="w3-small w3-center w3-border <?=$wd2?>"><?=$a['hpkua']?> %</td>
      </tr>
      <?
    }
    include"rumus.php";
    ?>
    </form>
    <tr>
      <td class="w3-small w3-center w3-border" colspan="10"></td>

      <td class="w3-small w3-center w3-border" colspan="1"><b>TOTAL</b></td>
      <td class="w3-small w3-center w3-border" colspan="1"><b><?=$hasilkuantab?> %</b></td>
      <td class="w3-small w3-center w3-border" colspan="1"><b><?=$hasilkuatab?> %</b></td>
    </tr>
    <tr>
      <td class="w3-small w3-center w3-border" colspan="10"></td>
      <td class="w3-small w3-center w3-border" colspan="1"><b>KATEGORI</b></td>
      <td class="w3-small w3-center w3-border" colspan="1"><b><?=$kategori?></b></td>
      <td class="w3-small w3-center w3-border" colspan="1"><b><?=$hasilnya?></b></td>
    </tr>
  </table>
<br/>
<center>
<div class="w3-btn w3-blue w3-small w3-round-large" onclick="edit<?=$kuncimati?>()">UPDATE</div>
&nbsp;&nbsp;
<div class="w3-btn w3-red w3-small w3-round-large" onclick="window.close()">CANCEL</div>
&nbsp;&nbsp;
<div class="w3-btn w3-black w3-small w3-round-large" onclick="cetakcabang('<?=$idkar?>')" style="<?=$viscetak?>">CETAK</div>
<div class="w3-btn w3-black w3-small w3-round-large" onclick="cetakpusat('<?=$idkar?>')" style="<?=$viscetakpus?>">CETAK PUSAT</div>
&nbsp;&nbsp;
<div class="w3-btn w3-blue w3-small w3-round-large" onclick="xlspusat('<?=$idkar?>')" style="<?=$viscetakpus?>">EXCEL PUSAT</div>
<div class="w3-btn w3-blue w3-small w3-round-large" onclick="xlscabang('<?=$idkar?>')" style="<?=$viscetak?>">EXCEL CABANG</div>
</center>
  <br/><br/><hr/>
</div>
<div id="id01" class="w3-modal">
  <div class="w3-modal-content" style="width:95%;">
    <div class="w3-container" style="">
        <span onclick="batal()"
        class="w3-button w3-display-topright w3-red">&times;</b></span>
        <br/><hr/>
        <iframe style="border:1px solid white;width:100%;height:400px;" id="rangka">

        </iframe>
    </div>
  </div>
</body>
<script>
function cetakcabang(x){
  window.open("cetakkpiuser.php?idkar="+x,"_blank");
}
function cetakpusat(x){
  window.open("cetakpusat.php?idkar="+x,"_blank");
}
function xlspusat(x){
  window.open("xlspusat.php?idkar="+x,"_blank");
}
function xlscabang(x){
  window.open("xlscabang.php?idkar="+x,"_blank");
}

function nih(id){
  txt = "isi";
  txt2 = "nf";
  isi = document.getElementById(txt+id).value;
  const number = parseFloat(isi);
  const formattedNumberDefault = number.toLocaleString();
  const formattedNumberUS = number.toLocaleString('en-US');
  //console.log(formattedNumberUS); // Output: "1,234,567.89"
  const options = {
    style: 'decimal',  // Other options: 'currency', 'percent', etc.
    minimumFractionDigits: 2,
    maximumFractionDigits: 2,
  };
  const formattedWithOptions = number.toLocaleString('en-US', options);
  //console.log(formattedWithOptions); // Output: "1,234,567.89"
  document.getElementById(txt2+id).innerHTML = formattedWithOptions;
}

function bukakpi(a){
  location.href="../addkpi/index.php?idkar="+a;
}
function delkpi(a,b,c){
  var r = confirm("APAKAH KOLOM KODE "+b+ "AKAN DI HAPUS ?...");
  if(r==true){
    location.href="delkpi.php?id="+a+"&idkar="+c;
  }
}
function edit(){
  var r = confirm("APAKAH KPI AKAN DI UPDATE ?...");
  if(r == true){
    document.getElementById('form').submit();
  }
}
function editkan(a){
  document.getElementById('id01').style.display='block';
  document.getElementById('rangka').src="perkpi.php?kode="+a;
}
function batal(){
  document.getElementById('id01').style.display='none';
}
function isiulang(){
  location.reload();
}
</script>
</html>
