<?php
include 'db.php';

$code = $_GET['code'] ?? '';
$stmt = $conn->prepare("SELECT 
  i.id, i.name, i.cost_price, 
  COALESCE(tr.rate, 0) as tax_rate 
  FROM items i 
  LEFT JOIN tax_rates tr ON i.tax_rate_id = tr.id 
  WHERE i.item_code = ? OR i.sku_number = ?");
$stmt->bind_param("ss", $code, $code);
$stmt->execute();
$result = $stmt->get_result();
echo json_encode($result->fetch_assoc() ?: []);
