<?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'];
$RowID = $_REQUEST['RowID'];
$partno = $_REQUEST['partno'];
$ext_desc = $_REQUEST['ext_desc'];
$mst_desc = $_REQUEST['mst_desc'];
$EMPID = $_REQUEST['EMPID'];




	$sql="UPDATE itm_mst SET							
				itm_mst_partno =?,		
				itm_mst_ext_desc=?,		
				itm_mst_desc =?,			
				audit_user=?,		
				audit_date=getdate()
				WHERE site_cd = ? 
				AND RowID = ?";	
				
	//echo $sql;
	$params = array($partno,$ext_desc,$mst_desc,$EMPID,$site_cd,$RowID);					
			//echo '<pre>'; print_r(array_merge_recursive($params)); echo '</pre>'	;		
	$stmt = sqlsrv_query( $conn, $sql,$params);

			if( !$stmt ) {
				$error_message = "Error SELECT Table (itm_mst)";
				returnError($error_message);
				die( print_r( sqlsrv_errors(), true));
			} while ( sqlsrv_next_result($stmt) );
			sqlsrv_free_stmt( $stmt);	


if( $stmt) {
	 sqlsrv_commit( $conn );
	 sqlsrv_close( $conn);	
	 returnData();		
} else {
	 sqlsrv_rollback( $conn );
	 $error_message = "Transaction rolled back.<br />";
	 returnError($error_message);
}

function returnData(){

	
	$returnData = array(
	'status' => 'SUCCESS',
	'message' => 'Update Successfully');

	echo json_encode($returnData);
}

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

 
?>