<?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'];
$ast_mst_assigned_to = $data['ast_mst_assigned_to'];






		$sql="	SELECT 		DISTINCT ast_lvl.ast_lvl_ast_lvl,   ast_lvl.ast_lvl_desc    
				FROM 		ast_mst, ast_lvl     
				WHERE		(ast_lvl.site_cd = '".$site_cd."') 
				AND		(	ast_mst.ast_mst_ast_lvl = ast_lvl.ast_lvl_ast_lvl  
				AND			ast_mst.site_cd = ast_lvl.site_cd  
				AND			ast_lvl.ast_lvl_disable_flag = 0  
				AND 		ast_lvl.ast_lvl_ast_lvl <> '-' ) 
				AND			ast_lvl_ast_lvl <> '-'					
				AND ast_mst.ast_mst_assigned_to = '".$ast_mst_assigned_to."' order by ast_lvl_ast_lvl";

				$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();
		
}
	

 
?>