<?php
require_once("dbconn.php");
require_once("phpFunctions.php");

$response = array(); 

$result = executeQuery($conn, "SELECT MAX(BatchCode) AS maxBatchCode FROM batch_details");

if ($result === false) { 
	throw new Exception("Error executing query: " . $conn->error);
} 

if ($result->num_rows > 0) {
	while($row = $result->fetch_assoc()) 
	{
		$maxBatchCode = $row["maxBatchCode"];
		// Add 100 to the maxBatchCode
		$newBatchCode = $maxBatchCode + 100;
		
		$response["newBatchCode"] = $newBatchCode;
	}
} 

if (empty($response)) {
	echo json_encode(["status" => "error", "message" => "BatchCode_Generator - An error occurred while processing your request."]);
} else {
    echo json_encode($response);
}
?>