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

require_once('config.php');

$error_message;
$valid = true;

$site_cd = $_REQUEST['site_cd'];
$mst_RowID = $_REQUEST['mst_RowID'];



$sql= "select wko_ls7.site_cd,
				mst_RowID,
				wko_ls7_emp_id = COALESCE(emp_mst_name,''), 
				wko_ls7_wo_org_date = COALESCE(wko_ls7_wo_org_date,''),
				wko_ls7_due_date = COALESCE(wko_ls7_due_date,''),
				audit_date = COALESCE(wko_ls7.audit_date,''),
				column1= COALESCE(wko_ls7.column1,''),
				wko_ls7.RowID ,
				wko_ls7_date3 = COALESCE(wko_ls7_date3,'')

				from wko_ls7  (NOLOCK) 

				LEFT 
				OUTER 
				JOIN		emp_mst emp_mst(NOLOCK)						
				ON			wko_ls7.site_cd = emp_mst.site_cd
				AND			wko_ls7.wko_ls7_emp_id = emp_mst.emp_mst_empl_id

				where wko_ls7.site_cd = '".$site_cd."' 
				and mst_RowID = '".$mst_RowID."' order by RowID";

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

if( !$stmt ) {
     $error_message = "Error selecting table (wko_ls7)";
	 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) {
	sqlsrv_free_stmt( $stmt);
	sqlsrv_close( $conn);	
	
	returnData($json);	
}

function returnData($json){
	
	$json1 = json_encode($json);
		
	if(empty(json_decode($json1,1))) {
		
		$returnData = array(
		'status' => 'SUCCESS',
		'message' => 'No Records found',
		'data' => $json);
			
	}else{
		
		$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();
}

 
?>