<?php
// get/get_item_by_code.php
require_once '../config/config.php';
header('Content-Type: application/json');

 $code = $_GET['code'] ?? '';

// Query harus mengambil unit DAN price
 $stmt = $pdo->prepare("SELECT part_number as code, name, unit, price FROM spareparts WHERE part_number = ? OR id = ?");
 $stmt->execute([$code, $code]);
 $item = $stmt->fetch(PDO::FETCH_ASSOC);

if($item) {
    echo json_encode(['status' => 'success', 'data' => $item]);
} else {
    echo json_encode(['status' => 'error', 'msg' => 'Item not found']);
}
?>