<?php
require 'koneksi.php';

$barcode = $_GET['barcode'];
$stmt = $conn->prepare("SELECT * FROM barang WHERE barcode = ?");
$stmt->bind_param("s", $barcode);
$stmt->execute();
$result = $stmt->get_result();

if ($result->num_rows > 0) {
    $barang = $result->fetch_assoc();
    echo json_encode([
        'id_barang' => $barang['id_barang'],
        'nama_barang' => $barang['nama_barang'],
        'part_number' => $barang['part_number'],
        'satuan' => $barang['satuan']
    ]);
} else {
    echo json_encode(['error' => 'Barang tidak ditemukan']);
}
