<?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' />
  <link href="css/style.css" rel='stylesheet' type='text/css' />
</head>
<body>
  <div id="wrapper">
    <div id="page-wrapper">
      <div class="graphs" style="font-family:'Tahoma';font-size:13px;">
        <?php
        echo "<div class=widget_head style='margin-left:20px;'><img src='../images/logo.png' style='width:100px;' /> &nbsp;&nbsp;Laporan Pembelian</div><hr>";
        $query = mysqli_query($koneksi, "SELECT * FROM produk");
        while($result=mysqli_fetch_array($query)){
          echo "<div class=widget_head style='margin-left:20px;font-size:15px;'>Pembelian Bahan Baku Produk ".$result['nama_produk']."</div>";
        ?>
        <div class="col-md-12">
          <table class="table table-bordered" style="background-color:white;text-color:black;">
            <thead>
              <tr>
                <th>Nama Bahan</th>
                <th>Bulan</th>
                <th>Tahun</th>
                <th>Jumlah Pembelian</th>
              </tr>
            </thead>
            <tbody>
              <?php
              $query2 = mysqli_query($koneksi, "SELECT * FROM beli bl, bahan b WHERE b.id_bahan=bl.id_bahan AND
                b.id_produk='".$result['id_produk']."' ORDER BY bl.tahun ASC, bl.bulan ASC, b.nama_bahan");
              if(mysqli_num_rows($query2) > 0){
                while($result2=mysqli_fetch_array($query2)) {
                  echo "<tr>";
                  echo "<td style='vertical-align:middle'>".$result2['nama_bahan']."</td>";
                  echo "<td style='vertical-align:middle'><center>".$bulans[($result2['bulan']-1)]."</center></td>";
                  echo "<td style='vertical-align:middle'><center>".$result2['tahun']."</center></td>";
                  echo "<td style='vertical-align:middle'><center><b>".numberFormat($result2['jumlah'])."</b></center></td>";
                  echo "<tr>";
                }
              } else {
                echo "<tr>";
                echo "<td colspan=4 style='vertical-align:middle'><center>Data Pembelian Kosong...</center></td>";
                echo "<tr>";
              }
              ?>
            </tbody>
          </table>
        </div>
        <div class="clearfix"></div>
        <?php
        }
        ?>
      </div>
    </div>
  </div>
</body>
</html>
<script>
window.print();
</script>
