<?php
ob_start();
require("includes/check_auth_user.php");
require("includes/dbconnect.php");
include ('includes/function.php');

$admin = $_SESSION["admin_" . $dbname];
$zdb = $_SESSION["zdbyear_" . $dbname];
$myyear = $_SESSION[$myyear];
mysqli_select_db($conn, $zdb);

$zroot = $_SESSION["zdbroot"];

if (isset($_REQUEST["item"])) {
    $item    = $_REQUEST["item"];
    $vouchdt = $_REQUEST["vouchdt"];

    $getitemstk = mysqli_query($conn, "SELECT * FROM stkenttran WHERE item = '$item' AND  vouchdt < '$vouchdt' order by vouchdt desc ") or die(mysqli_error($conn));
    $item = mysqli_fetch_object($getitemstk);

    $stkqty = $item->qty; 
    $unit = $item->unit; 

    // Check if boat number exists
    $stkqtyExists = !empty($stkqty); // Check if boat number is not empty
    
    echo json_encode([
        'stkqty' => $stkqty,
        'unit' => $unit,
        'stkqtyExists' =>  $stkqtyExists
    ]);
   
}
?>