<?php
include 'config.php';

if(isset($_GET['barcode'])) {
    $barcode = $_GET['barcode'];
    
    // Look for product by barcode
    $query = mysqli_query($conn, "SELECT * FROM produk WHERE kode_produk = '$barcode'");
    
    if($row = mysqli_fetch_assoc($query)) {
        echo json_encode([
            'success' => true,
            'idproduk' => $row['idproduk'],
            'nama_produk' => $row['nama_produk'],
            'harga_jual' => $row['harga_jual'],
            'stock' => $row['stock']
        ]);
    } else {
        echo json_encode([
            'success' => false
        ]);
    }
} else {
    echo json_encode([
        'success' => false,
        'message' => 'No barcode provided'
    ]);
}
?>