<?php
// get these values from your DB.
require_once('config.php');
$error_message;
$valid = true;


/* Begin the transaction. */
if ( sqlsrv_begin_transaction( $conn ) === false ) {
     die( print_r( sqlsrv_errors(), true ));
}

$json = file_get_contents('php://input');
$data = json_decode($json, true);

$site_cd = $data['site_cd'];
$mfg_mdl_mfg_cd = $data['mfg_mdl_mfg_cd'];

if (!empty($mfg_mdl_mfg_cd)){	
	$where_mfg_mdl_mfg_cd = " AND mfg_mdl.mfg_mdl_mfg_cd = '".$mfg_mdl_mfg_cd."' ";	
}else{	
	$where_mfg_mdl_mfg_cd = "";	
}



		$sql="	SELECT	mfg_mdl.mfg_mdl_modelno,              	
						mfg_mdl.mfg_mdl_desc  
				FROM 	mfg_mdl 
				WHERE (mfg_mdl.site_cd = '".$site_cd."')".
				$where_mfg_mdl_mfg_cd."";		

				$stmt_mfg_mdl = sqlsrv_query( $conn, $sql);

				if( !$stmt_mfg_mdl ) {
					 $error_message = "Error selecting table (emp_mst)";
					 returnError($error_message);
					 die( print_r( sqlsrv_errors(), true));
					 
				}

				$json = array();

				do {
					 while ($row = sqlsrv_fetch_array($stmt_mfg_mdl, SQLSRV_FETCH_ASSOC)) {		
						$json[] = $row;	
					
					 }
				} while ( sqlsrv_next_result($stmt_mfg_mdl) );




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

function returnData($json){
	//echo $json;
	$returnData = array(												
	'status' => 'SUCCESS',
	'message' => 'Successfully',	
	'data'=>$json);
	
	echo json_encode($returnData);
}

function returnError($error_message){
	$json = array();
	
	$returnData = array(


	'status' => 'ERROR',
	'message' => $error_message,
	'data' => $json);
	
	echo json_encode($returnData);
	exit();
		
}
	

 
?>