<?php
include 'koneksi.php';

if (isset($_POST['hapus'])) {
    $id_supplier = $_POST['id_supplier'];

    // Cek apakah supplier digunakan di transaksi lain (optional, sesuaikan dengan sistem Anda)
    // Contoh: cek di tabel pembelian
    // $cek_pembelian = "SELECT * FROM pembelian WHERE id_supplier = '$id_supplier'";
    // $result_pembelian = mysqli_query($conn, $cek_pembelian);
    
    // if (mysqli_num_rows($result_pembelian) > 0) {
    //     echo "<script>alert('Supplier tidak dapat dihapus karena sudah digunakan dalam transaksi pembelian!'); window.location='supplier.php';</script>";
    // } else {
        $query = "DELETE FROM supplier WHERE id_supplier = '$id_supplier'";
        
        if (mysqli_query($conn, $query)) {
            echo "<script>alert('Supplier berhasil dihapus!'); window.location='supplier.php';</script>";
        } else {
            echo "<script>alert('Gagal menghapus supplier.'); window.location='supplier.php';</script>";
        }
    // }
}
?>