<?php 
include 'header.php';
$kode = $_GET['kode'];
$pr = mysqli_query($conn, "SELECT * FROM produk WHERE kode_produk = '$kode'");
$tam = mysqli_fetch_assoc($pr);
?>

<!DOCTYPE html>
<html lang="id">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Master Produk - UMKM Galeri 3D</title>
<style>
body {
    background: #f3f4f6;
    font-family: 'Poppins', sans-serif;
    margin: 0;
    padding: 0;
}
.container {
  	max-width: 1200px;
    margin: 5px auto;
    padding: 0 30px;
}
</style>
</head>
<body>
<div class="container">
    <h2 style=" width: 100%; border-bottom: 4px solid gray"><b>Master Produk</b></h2>
    <table class="table table-striped">
        <thead>
            <tr>
                <th>No</th>
                <th>Kode & Nama Produk</th>
                <th>Image</th>
                <th>Harga</th>
                <th>Action</th>
            </tr>
        </thead>
        <tbody>
            <?php 
            $result = mysqli_query($conn, "SELECT * FROM produk");
            $no = 1;
            while ($row = mysqli_fetch_assoc($result)) {
            ?>
            <tr>
                <td><?= $no; ?></td>
                <td>
                    <?= $row['kode_produk']; ?><br>
                    <small><?= $row['nama']; ?></small>
                </td>
                <td><img src="../image/produk/<?= $row['image']; ?>" width="65"></td>
                <td>Rp <?= number_format($row['harga'],0,',','.'); ?></td>
                <td>
                    <a href="edit_produk.php?kode=<?= $row['kode_produk']; ?>" class="btn btn-warning btn-sm">
                        <i class="glyphicon glyphicon-edit"></i>
                    </a>
                    <a href="proses/del_produk.php?kode=<?= $row['kode_produk']; ?>" class="btn btn-danger btn-sm" 
                        onclick="return confirm('Yakin ingin menghapus data ini?')">
                        <i class="glyphicon glyphicon-trash"></i>
                    </a>
                    <a href="#" class="btn btn-primary btn-sm" data-toggle="modal" data-target="#myModal">
                        <i class="glyphicon glyphicon-eye-open"></i>
                    </a>
                </td>
            </tr>
            <?php $no++; } ?>
        </tbody>
    </table>

    <a href="tm_produk.php" class="btn btn-success">
        <i class="glyphicon glyphicon-plus-sign"></i> Tambah Produk
    </a>
</div>

<!-- Modal BOM Produk -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog modal-lg" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h4 class="modal-title">BOM PRODUK <?= strtoupper($tam['nama']); ?></h4>
            </div>
            <div class="modal-body table-responsive">
                <table class="table table-striped">
                    <thead>
                        <tr>
                            <th>No</th>
                            <th>Nama Material</th>
                            <th>Kebutuhan Material</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php 
                        $result1 = mysqli_query($conn, "SELECT i.nama as nama, b.kebutuhan as jml, i.satuan as satu FROM bom_produk b JOIN inventory i ON b.kode_bk=i.kode_bk WHERE b.kode_produk='$kode'");
                        $no = 1;
                        while ($row1 = mysqli_fetch_assoc($result1)) {
                        ?>
                        <tr>
                            <td><?= $no; ?></td>
                            <td><?= $row1['nama']; ?></td>
                            <td><?= $row1['jml'] . " " . $row1['satu']; ?></td>
                        </tr>
                        <?php $no++; } ?>
                    </tbody>
                </table>
            </div>
            <div class="modal-footer">
                <a href="m_produk.php" class="btn btn-default">Close</a>
            </div>
        </div>
    </div>
</div>
</body>
</html>
<!-- Auto trigger modal -->
<script type="text/javascript">
    $(document).ready(function() {
        $('#myModal').modal('show');
    });
</script>
