<?php

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

//Asset Code:



$sql="select * from cf_label (NOLOCK) where  
		column_name IN ('ast_mst_asset_no',
						'ast_ls2_meter_id',
						'ast_ls2_meter_point',
						'ast_ls2_usage_uom',
						'ast_ls2_meter_install_date',
						'ast_ls2_incr_usage_flag',
						'ast_ls2_ltd_usage',
						'ast_ls2_meter_desc',
						'ast_ls2_meter_maximum',
						'ast_ls2_max_avg_usage',
						'ast_ls2_usage_date',
						'ast_ls2_usage_reading',
						'itm_det_minimum',
						'ast_mst_asset_status',
						'ast_mst_asset_locn') 
		and language_cd = 'DEFAULT' order by customize_label";


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

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

$json = array();

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



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



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

 
?>