<?php 
    include 'header.php'; 

    $level=$_SESSION['level'];
    $thn = date('Y');
    $bln = date('m');   
?>

<div class="container">

 <div class="my-4 border-bottom">
   <h2 class="fw-semibold fs-3">KARYAWAN & PENGURUS</h2>
 </div>

  <div class="row justify-content-center">
    <div class="col-lg-12">
       <div class="card">

    <div class="card-header d-flex justify-content-between">
      <span class="card-title fw-semibold align-self-start mb">Data Semua Karyawan & Pengurus (oleh : <?php echo $level; ?>)  </span>
    <div>
      <button type="button" class="btn btn-danger btn-sm align-self-end" data-bs-toggle="modal" data-bs-target="#exampleModal111">
        <a href="b_karyawan_print.php?bln=<?php echo $bln; ?>&thn=<?php echo $thn; ?>" target="_blank" class="btn btn-warning btn-sm"><i class="bi bi-printer-fill"></i> &nbsp Cetak ke Printer</a>   
      </button>
    </div>    

    <div>
      <button type="button" class="btn btn-primary btn-sm align-self-end" data-bs-toggle="modal" data-bs-target="#exampleModal222">
        <a href="javascript:history.go(-1)" class="btn btn-primary btn-sm"><i class="bi bi-reply-all-fill"></i> &nbsp Balik ae</a>   
      </button>
    </div>
    
    </div>
    <div class="card-body">
      <div class="table-responsive">
        <table class="table table-bordered table-striped" id="table-datatable">
          <thead>
            <tr>
              <th width="1%" class="text-center">No</th>
              <th width="20%" class="text-center">NAMA</th>
              <th width="30%" class="text-center">ALAMAT</th>
              <th width="1%" class="text-center">PK</th>
              <th width="20%" class="text-center">JABATAN</th>
              <th width="1%" class="text-center">Gaji</th>
              <th width="1%" class="text-center">Transport</th>
              <th width="1%" class="text-center">P.rawat</th>
              <th width="1%" class="text-center">Total</th>
              <th width="2%" class="text-center">Bon</th>
            </tr>
          </thead>
          <tbody>
            <?php 
            $no=1;
            $data = mysqli_query($koneksi,"SELECT * FROM karyawan WHERE hapus<>'HAPUS' ORDER BY id ASC");
            while($d = mysqli_fetch_array($data)){
                $tkdr=$d['id'];
                  $sql2 = mysqli_query($koneksi, "SELECT sum(jumlah) AS t_bon FROM bon WHERE id_kary='$tkdr'");
                      list($t_bon) = mysqli_fetch_array($sql2); 
                  $sql3 = mysqli_query($koneksi, "SELECT sum(jumlah) AS t_gaji FROM gaji WHERE id_kary='$tkdr' and month(tgl)='$bln' and year(tgl)='$thn' ");
                      list($t_gaji) = mysqli_fetch_array($sql3);                       
                  $sql4 = mysqli_query($koneksi, "SELECT sum(jumlah) AS t_tran FROM transport WHERE kdr='$tkdr' and month(tgl)='$bln' and year(tgl)='$thn' ");
                      list($t_tran) = mysqli_fetch_array($sql4);                       
                  $sql5 = mysqli_query($koneksi, "SELECT sum(jumlah) AS t_rawat FROM perawatan WHERE kdr='$tkdr' and month(tgl)='$bln' and year(tgl)='$thn' ");
                      list($t_rawat) = mysqli_fetch_array($sql5);  
                  $total=($t_gaji+$t_tran+$t_rawat)  
              ?>
              <tr>
                <td><?php echo $no++; ?></td>
                <td><?php echo $d['nama']; ?></td>
                <td align='left'><?php echo $d['alamat']; ?></td>
                <td align='center'><?php echo $d['grup']; ?></td>
                <td align='left'><?php echo $d['jabatan']; ?></td>
                <td align='right'><?php echo "" . number_format("$t_gaji", 0, ",", "."); ?></td>
                <td align='right'><?php echo "" . number_format("$t_tran", 0, ",", "."); ?></td>
                <td align='right'><?php echo "" . number_format("$t_rawat", 0, ",", "."); ?></td>
                <td align='right'><?php echo "" . number_format("$total", 0, ",", "."); ?></td>
                <td align='right'><?php echo "" . number_format("$t_bon", 0, ",", "."); ?></td>
              </tr>
              <?php 
            }
            ?>
          </tbody>
                        <?php 
                  $sql2 = mysqli_query($koneksi, "SELECT sum(jumlah) AS t_bon2 FROM bon ");
                      list($t_bon2) = mysqli_fetch_array($sql2); 
                  $sql3 = mysqli_query($koneksi, "SELECT sum(jumlah) AS t_gaji2 FROM gaji WHERE month(tgl)='$bln' and year(tgl)='$thn' ");
                      list($t_gaji2) = mysqli_fetch_array($sql3);                       
                  $sql4 = mysqli_query($koneksi, "SELECT sum(jumlah) AS t_tran2 FROM transport WHERE month(tgl)='$bln' and year(tgl)='$thn' ");
                      list($t_tran2) = mysqli_fetch_array($sql4);                       
                  $sql5 = mysqli_query($koneksi, "SELECT sum(jumlah) AS t_rawat2 FROM perawatan WHERE month(tgl)='$bln' and year(tgl)='$thn' ");
                      list($t_rawat2) = mysqli_fetch_array($sql5);  
                  $total22=($t_gaji2+$t_tran2+$t_rawat2)  
            	        ?>						
							<tr>
						    	<td colspan="5" style="font-weight: bold;text-align: center;">Total Biaya & Sisa Bon</td>																																									
		                        <td align='right'><style="font-weight: bold;"><?php echo "" . number_format("$t_gaji2", 0, ",", "."); ?> </td>
								<td align='right'><style="font-weight: bold;"><?php echo "" . number_format("$t_tran2", 0, ",", "."); ?> </td>
		                        <td align='right'><style="font-weight: bold;"><?php echo "" . number_format("$t_rawat2", 0, ",", "."); ?> </td>
								<td align='right'><style="font-weight: bold;"><?php echo "" . number_format("$total22", 0, ",", "."); ?> </td>	
								<td align='right'><style="font-weight: bold;"><?php echo "" . number_format("$t_bon2", 0, ",", "."); ?> </td>	
								
							</tr> 
							<tr>
						    	<td colspan="11" style="font-weight: bold;text-align: center;"><i>Total Biaya hanya terbatas yg dibayar Koperasi pada Bulan <?php echo $bln; ?>-<?php echo $thn; ?> ini, sedang SISA BON berjalan sesuai pembayaran.</i></td>
							</tr>							
        </table>
      </div>
    </div>

  </div>
    </div>
  </div>

</div>
<?php include 'footer.php'; ?>