<?php
include 'db.php';

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

echo json_encode([
    'account_code' => $next_code
]);
?>
