<?php
// get these values from your DB.

require_once('config.php');

$error_message;
$valid = true;

$site_cd = $_REQUEST['site_cd'];
$prm_mst_assetno = $_REQUEST['prm_mst_assetno'];
	
$sql= "select prm_mst_pm_no,prm_mst_freq_code,prm_mst_desc,prm_mst_lpm_date,prm_mst_next_due,prm_fcd.prm_fcd_desc 

		from prm_mst (NOLOCK) 
		
		LEFT 
		OUTER 
		JOIN		ast_mst (NOLOCK)
		ON			prm_mst.site_cd = ast_mst.site_cd
		AND			prm_mst.prm_mst_assetno = ast_mst.ast_mst_asset_no
		
		LEFT 
		OUTER 
		JOIN		prm_fcd (NOLOCK)
		ON			prm_mst.site_cd = prm_fcd.site_cd
		AND			prm_mst.prm_mst_freq_code = prm_fcd.prm_fcd_freq_code
		
		where prm_mst.site_cd ='".$site_cd ."' 
		and prm_mst.prm_mst_assetno ='".$prm_mst_assetno ."'";

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

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

$json = array();

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

if ($valid) {
			
	returnData($json);	
	sqlsrv_free_stmt( $stmt);
	sqlsrv_close( $conn);
}

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

 
?>