<?php

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

$site_cd = $_REQUEST['site_cd'];

$sql = "SELECT 		ast_mst.ast_mst_asset_no,		ast_mst.ast_mst_cost_center,		ast_mst.ast_mst_asset_type,		ast_mst.ast_mst_asset_grpcode,
  			ast_mst.ast_mst_asset_status,   ast_mst.ast_mst_asset_shortdesc,    ast_mst.ast_mst_asset_longdesc,  ast_mst.ast_mst_work_area,      				
  			ast_mst.ast_mst_asset_locn,     ast_mst.ast_mst_perm_id,  			ast_det.ast_det_cus_code,		ast_mst.ast_mst_ast_lvl
 FROM 		ast_mst (NOLOCK),  				ast_det (NOLOCK),  				ast_sts (NOLOCK)  
 WHERE (	ast_mst.site_cd = ast_det.site_cd  
 AND			ast_mst.RowID = ast_det.mst_RowID  
 AND			ast_mst.site_cd = ast_sts.site_cd  
 AND			ast_mst.ast_mst_asset_status = ast_sts.ast_sts_status  
 AND			ast_sts.ast_sts_typ_cd NOT IN ('AWA-DISPOSED', 'DISPOSED', 'OUT-OF-SERVICE')) 
 AND ast_mst.site_cd = '".$site_cd."' AND  ast_mst.ast_mst_asset_status  IN ( 'ACT','AWD','DEA','DIS','ISF','ISL') "
 
 $stmt = sqlsrv_query( $conn, $sql);
 
 if( !$stmt ) {
     $error_message = "Error selecting table (emp_mst)";
	 returnError($error_message);
     die( print_r( sqlsrv_errors(), true));
	 
}

$json = array();


if ($valid) {

	//echo $sql;
	returnData($json);	
	
}

function returnData($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);
		
}
	sqlsrv_free_stmt( $stmt);
	sqlsrv_close( $conn);	

 
?>