<?php 
include 'header.php';
?>

<!DOCTYPE html>
<html lang="id">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Dashboard - UMKM Galeri 3D</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.2/css/all.min.css">
<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" style="padding-bottom: 300px;">
    <h2 style="width: 100%; border-bottom: 2px solid #000; padding-bottom: 10px;">
        <b><i class="fas fa-shopping-cart"></i> Pesanan Saya</b>
    </h2>

<?php 
if(!isset($_SESSION['kd_cs'])){
    echo "<div class='text-center alert alert-danger' style='color: #333; font-weight: bold;'>
        SILAHKAN LOGIN TERLEBIH DAHULU UNTUK MELIHAT PESANAN
      </div>";
} else {
    $kode_cs = $_SESSION['kd_cs'];

    $sql = "SELECT kode_produk, nama_produk, qty, status, tanggal 
            FROM produksi 
            WHERE kode_customer = '$kode_cs' 
            ORDER BY tanggal ASC";

    $result = mysqli_query($conn, $sql) or die("Query error: " . mysqli_error($conn));

    echo '<table class="table table-striped">
            <thead>
                <tr>
                    <th>No</th>
                    <th>Kode Produk</th>
                    <th>Nama Produk</th>
                    <th>Qty</th>
                    <th>Status</th>
                    <th>Tanggal</th>
                    <th>Action</th>
                </tr>
            </thead>
            <tbody>';

    if(mysqli_num_rows($result) > 0){
        $no = 1;
        while($row = mysqli_fetch_assoc($result)){
            echo '<tr>
                    <td>'.$no++.'</td>
                    <td>'.$row['kode_produk'].'</td>
                    <td>'.$row['nama_produk'].'</td>
                    <td>'.$row['qty'].'</td>
                    <td>'.$row['status'].'</td>
                    <td>'.date('Y-m-d H:i:s', strtotime($row['tanggal'])).'</td>
                    <td>
                        <a href="proses/add.php?produk='.$row['kode_produk'].'&kd_cs='.$kode_cs.'&hal=1" 
                           class="btn btn-success  btn-sm" role="button">
                           <i class="glyphicon glyphicon-plus"></i>
                        </a>
                    </td>
                  </tr>';
        }
    } else {
        echo "<tr><td colspan='7' class='text-center bg-warning'>
                <h5><b>Belum ada pesanan.</b></h5>
              </td></tr>";
    }

    echo '</tbody></table>';
}
?>

</div>
</body>
</html>
