<?
include"../plg/kon.php";
$loka = $_GET['loka'];
?>
<div class="w3-border">
<i class="fa fa-window-close w3-xxlarge" aria-hidden="true" style="color:red;cursor:pointer;" onclick="location.href='index.php'"></i>
<table class="w3-small w3-border w3-striped w3-table-all w3-hoverable" onclick="tutup()">
  <tr class="w3-blue-gray">
    <th class="w3-border w3-center">NO</th>
    <th class="w3-border w3-center">NAMA</th>
    <th class="w3-border w3-center">NIP</th>
    <th class="w3-border w3-center">JABATAN</th>
    <th class="w3-border w3-center">UNIT</th>
    <th class="w3-border w3-center">SMT  I</th>
    <th class="w3-border w3-center">SMT II</th>
  </tr>
<?
$i = 1;
$sql1 = "select * from karyawan where lokasi like'%$loka%' or unit like'%$loka%' and del='0' order by unit asc";
$res1 = $conn->query($sql1);
while($b = $res1->fetch_assoc()){
  $nipnya = $b['nip'];
  ?>
    <tr>
      <td class="w3-border"><?=$i++?></td>
      <td class="w3-border"><?=$b['nama']?></td>
      <td class="w3-border"><?=$b['nip']?></td>
      <td class="w3-border"><?=$b['jab']?></td>
      <td class="w3-border"><?=$b['unit']?><br/><?=$b['lokasi']?></td>
      <td class="w3-border w3-center">
        <?
        $sqlkpi = "select * from kpikar where nip='$nipnya' and idkar like'I - 2024%'";
        $reskpi = $conn->query($sqlkpi);
        while ($k = $reskpi->fetch_assoc()){
          $tandakpi = $k['idkar'];
          $sitem = "select count(id)as totitem from kpiuser where idkar='$tandakpi' and del='0'";
          $ritem = $conn->query($sitem);
          while($ti = $ritem->fetch_assoc()){
            $totitem = $ti['totitem'];
          }
          $sitem2 = "select count(id)as totinput from kpiuser where idkar='$tandakpi' and del='0' and hpkuan<>'0'";
          $ritem2 = $conn->query($sitem2);
          while($ti = $ritem2->fetch_assoc()){
            $totinput = $ti['totinput'];
          }
          if($tandakpi !== ''){
            echo"<a href='../userkpi/formuserkpiver2.php?idkar=$tandakpi' class='w3-card-4'>
            <i class='fa fa-check w3-card-2 w3-large w3-green' style=''>".$totinput." / ".$totitem."&nbsp;</i></a>";
          }
        }
        ?>
      </td>
      <td class="w3-border">
        <?
        $sqlkpi2 = "select * from kpikar where nip='$nipnya' and idkar like'II - 2024%'";
        $reskpi2 = $conn->query($sqlkpi2);
        while ($k2 = $reskpi2->fetch_assoc()){
          $tandakpi2 = $k2['idkar'];
          $sitemb = "select count(id)as totitem from kpiuser where idkar='$tandakpi2' and del='0'";
          $ritemb = $conn->query($sitemb);
          while($ti = $ritemb->fetch_assoc()){
            $totitemb = $ti['totitem'];
          }
          $sitem2b = "select count(id)as totinput from kpiuser where idkar='$tandakpi2' and del='0' and hpkuan<>'0'";
          $ritem2b = $conn->query($sitem2b);
          while($ti = $ritem2b->fetch_assoc()){
            $totinputb = $ti['totinput'];
          }
          if($tandakpi2 !== ''){
            echo"<a href='../userkpi/formuserkpiver2.php?idkar=$tandakpi2' class='w3-card-4'>
            <i class='fa fa-check w3-card-2 w3-large w3-green' style=''>".$totinputb." / ".$totitemb."&nbsp;</i></a>";
          }
        }
        ?>
      </td>
    </tr>
    <?
}
?>
</table>
</div>
