
<?php

if (isset($_SERVER['HTTP_ORIGIN'])) {
    header("Access-Control-Allow-Origin: {$_SERVER['HTTP_ORIGIN']}");
    header('Access-Control-Allow-Credentials: true');
    header('Access-Control-Max-Age: 86400'); // cache for 1 day
}

//$link = mssql_connect('192.168.1.30', 'sa', 'sap123');
$link = mssql_connect('10.0.0.50', 'sa', 'sap123');
$_SESSION['itemcode'] = $_GET['itemcode'];
$_SESSION['dep'] = $_GET['dep'];
$_SESSION['database'] = $_GET['database'];
$_SESSION['flag'] = $_GET['flag'];

if (!$link) {
    die('Unable to connect!');
}

if (!mssql_select_db('SBO_CALZASHOES_INC', $link)) {
    die('Unable to select database!');
}

$resultcodigo = mssql_query("select top(1) itemcode,onhand from oitw where itemcode='" . $_SESSION['itemcode'] . "'  and whscode='" . $_SESSION['dep'] . "'  ");

$msg = array("pr_id" => $SESSION['itemcode'], "cant" => "0", "succes" => "false");

while ($row = mssql_fetch_array($resultcodigo)) {

    $_SESSION['pr_id'] = $row['itemcode'];

    $_SESSION['cant'] = $row['onhand'];

    $msg = array("pr_id" => $row['itemcode'], "cant" => $row['onhand'], "succes" => "true");

}

$jsonData = $msg;

// header('content-type: application/json');
echo json_encode($jsonData);
//echo $json;
mssql_free_result($result);

?>
