<?php
session_start(); 
require("includes/dbconnect.php");
require("includes/config.php");
require("includes/function.php");

ini_set('display_errors', 1);
error_reporting(E_ERROR);


$zdb = $_SESSION["zdbyear"];
$accode = $_SESSION["customer_code"];

mysqli_select_db($conn, $zdb);

// Get shipment ID from POST
$shipId = isset($_POST['id']) ? $_POST['id'] : '';

$shipmentId = str_replace("GL-", "", strtoupper($shipId));

if (!$shipmentId) {
    echo json_encode(["error" => "No shipment ID provided"]);
    exit;
}

$getdata = mysqli_query($conn, "SELECT status FROM `shipment` WHERE `vouchno`='$shipmentId' AND customer = '$accode'  ") or die(mysqli_error($conn));

if (mysqli_num_rows($getdata) > 0) {
    $row = mysqli_fetch_assoc($getdata);
    // Return as JSON
    echo json_encode(["status" => intval($row['status'])]);
} else {
    echo json_encode(["error" => "Shipment not found"]);
}


?>