<?php
require_once('includes/load.php');

$conn = mysqli_connect("localhost", "robz3369_Rnanda", "Clemira123", "robz3369_gitar");
if (!$conn) {
    die("Koneksi database gagal: " . mysqli_connect_error());
}

$page_title = 'penjualan';

include_once('layouts/header.php');
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title><?php echo $page_title; ?></title>
</head>
<body>

    <h2>Form Penjualan</h2>

    <?php
    // Tampilkan pesan sukses atau error jika ada
    if (isset($_SESSION['success'])) {
        echo '<div style="color: green;">' . $_SESSION['success'] . '</div>';
        unset($_SESSION['success']);
    }

    if (isset($_SESSION['error'])) {
        echo '<div style="color: red;">' . $_SESSION['error'] . '</div>';
        unset($_SESSION['error']);
    }
    ?>

    <form method="post" action="proses_penjualan.php">
        <label for="no_po">Nomor PO:</label>
        <select name="no_po" required>
            <?php
            // Ambil nomor PO dari database
            // Gantilah dengan kode pengambilan nomor PO dari database Anda
            $query_no_po = "SELECT id, nomor_po FROM No_PO";
            $result_no_po = mysqli_query($conn, $query_no_po);

            while ($row_no_po = mysqli_fetch_assoc($result_no_po)) {
                echo '<option value="' . $row_no_po['id'] . '">' . $row_no_po['nomor_po'] . '</option>';
            }
            ?>
        </select>

        <br>

        <!-- Form detail_po -->
        <label for="product">Product:</label>
        <input type="text" name="product" required>

        <label for="qty">Quantity:</label>
        <input type="text" name="qty" required>

        <label for="harga">Harga:</label>
        <input type="text" name="harga" required>

        <label for="total">Total:</label>
        <input type="text" name="total" required>

        <br>

        <button type="submit" name="submit_penjualan">Simpan Penjualan</button>
    </form>

</body>
</html>

<?php include_once('layouts/footer.php'); ?>
