<?php
include 'db.php';

// Get highest existing numeric item code
$result = $conn->query("SELECT MAX(CAST(item_code AS UNSIGNED)) AS max_code FROM items");
$row = $result->fetch_assoc();
$next_code = $row['max_code'] ? $row['max_code'] + 1 : 10010;

// Same for SKU (or reuse item_code)
$result2 = $conn->query("SELECT MAX(CAST(sku_number AS UNSIGNED)) AS max_sku FROM items");
$row2 = $result2->fetch_assoc();
$next_sku = $row2['max_sku'] ? $row2['max_sku'] + 1 : 10010;

echo json_encode([
    'item_code' => $next_code,
    'sku_number' => $next_sku
]);
?>
