<?php
require_once('config.php');
$error_message;
$valid = true;


/* Begin the transaction. */
if ( sqlsrv_begin_transaction( $conn ) === false ) {
     die( print_r( sqlsrv_errors(), true ));
}
 
$site_cd = $_REQUEST['site_cd'];
$itm_mst_stockno = $_REQUEST['itm_mst_stockno'];


$sql = "select   itm_mst_stockno,itm_mst_ttl_oh,itm_mst_issue_price,itm_mst_mstr_locn 
			from itm_mst (NOLOCK)
			where site_cd = '".$site_cd."'
			and itm_mst_stockno = '".$itm_mst_stockno."'";			
			
			
			$stmt = sqlsrv_query( $conn, $sql);			
			if( !$stmt ) {
				$error_message = "Error update table (itm_mst)";
				returnError($error_message);
				die( print_r( sqlsrv_errors(), true));
			}
			
			$stock = array();
			
			
			do {
				while ($row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC)) {	
				
				$itm_mst_stockno = $row['itm_mst_stockno'];
				$itm_mst_ttl_oh = $row['itm_mst_ttl_oh'];
				$itm_mst_issue_price = $row['itm_mst_issue_price'];
				$itm_mst_mstr_locn = $row['itm_mst_mstr_locn'];
				
				
				
					 	 
			}
		} while ( sqlsrv_next_result($stmt));
		
		
		


returnData($itm_mst_stockno,$itm_mst_ttl_oh,$itm_mst_issue_price,$itm_mst_mstr_locn);
//sqlsrv_free_stmt( $stmt);

sqlsrv_close($conn);


function returnData($itm_mst_stockno,$itm_mst_ttl_oh,$itm_mst_issue_price,$itm_mst_mstr_locn){
	
	$returnData = array(
	'status' => 'SUCCESS',
	'itm_mst_stockno' => $itm_mst_stockno,	
	'itm_mst_ttl_oh' => $itm_mst_ttl_oh,
	'itm_mst_issue_price' => $itm_mst_issue_price,
	'itm_mst_mstr_locn' => $itm_mst_mstr_locn);
	
	echo json_encode($returnData);
}

function returnError($error_message){
	$json = array();
	
	$returnData = array(
	'status' => 'ERROR',
	'message' => $error_message,
	'data' => $json);	
	
	echo json_encode($returnData);
		
	exit();
}
 
?>