<?php
include 'koneksi.php';
$bulans = array("Jan", "Feb", "Mar", "Apr", "Mei", "Jun", "Jul", "Agu", "Sep", "Okt", "Nov", "Des");
?>
<!DOCTYPE HTML>
<html>
<head>
  <title></title>
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <meta name="keywords" content="Modern Responsive web template, Bootstrap Web Templates, Flat Web Templates, Andriod Compatible web template,
  Smartphone Compatible web template, free webdesigns for Nokia, Samsung, LG, SonyErricsson, Motorola web design" />
  <script type="application/x-javascript"> addEventListener("load", function() { setTimeout(hideURLbar, 0); }, false); function hideURLbar(){ window.scrollTo(0,1); } </script>
  <link href="css/bootstrap.min.css" rel='stylesheet' type='text/css' />
</head>
<body>
  <div id="wrapper">
    <div id="page-wrapper">
      <div class="graphs" style="font-family:'Tahoma';">
        <?php
        $query = mysqli_query($koneksi, "SELECT * FROM produk WHERE id_produk='".$_GET['id_produk']."'");
        $result=mysqli_fetch_array($query);
        echo "<img src='../images/logo.png' style='width:100px;margin-left:20px;margin-bottom:10px;' />";
        echo "<div class=widget_head style='margin-left:20px;'>Laporan Opname Stok Produk : ".$result['nama_produk']."<br />Periode ".$bulans[$_GET['bulan']-1]." ".$_GET['tahun']."</div><hr>";
        ?>
        <div class="col-md-12">
          <table class="table table-bordered" style="background-color:white;text-color:black;;font-size:10px;">
            <thead>
              <tr>
                <th>ID Opname</th>
                <th>Tanggal</th>
                <th>Status</th>
                <th>Kuantiti</th>
                <th>Stok</th>
              </tr>
            </thead>
            <tbody>
              <?php
              $query2=mysqli_query($koneksi, "SELECT *, p.stok AS last_stok FROM opname_produk p, produk o WHERE p.id_produk=o.id_produk AND MONTH(p.tanggal)='".$_GET['bulan']."' AND YEAR(p.tanggal)='".$_GET['tahun']."'
              AND p.id_produk='".$_GET['id_produk']."' ORDER BY p.tanggal DESC, p.id_opname DESC");
              if(mysqli_num_rows($query2) > 0){
                while($result2=mysqli_fetch_array($query2)) {
                  echo "<tr>";
                  echo "<td style='vertical-align:middle'>#".$result2['id_opname']."</td>";
                  echo "<td style='vertical-align:middle'>".tanggalIndo($result2['tanggal'])."</td>";
                  echo "<td style='vertical-align:middle'>".$result2['status']."</td>";
                  if($result2['status']=="Stok Keluar Batal" || $result2['status']=="Produksi Batal"){
                    echo "<td style='vertical-align:middle'><center>0 ".$result2['satuan']."</center></td>";
                  } else if($result2['status']=="Produksi"){
                    echo "<td style='vertical-align:middle'><center>+".$result2['jumlah']." ".$result2['satuan']."</center></td>";
                  } else {
                    echo "<td style='vertical-align:middle'><center>-".$result2['jumlah']." ".$result2['satuan']."</center></td>";
                  }
                  echo "<td style='vertical-align:middle'><center><b>".$result2['last_stok']."</b></center></td>";
                  echo "<tr>";
                }
              } else {
                echo "<tr>";
                echo "<td colspan=5 style='vertical-align:middle'><center>Data Opname Stok Produk Kosong...</center></td>";
                echo "<tr>";
              }
              ?>
            </tbody>
          </table>
        </div>
        <div class="clearfix"></div>

      </div>
    </div>
  </div>
</body>
</html>
<script>
window.print();
</script>
