<?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_ls3.site_cd,   
				wko_ls3.wko_ls3_assetno,      
				wko_ls3.wko_ls3_activity_code,   
				wko_ls3.wko_ls3_stockno,    
				wko_ls3.wko_ls3_descr,    
				wko_ls3.wko_ls3_qty_needed,   
				wko_ls3.wko_ls3_item_cost,   
				wko_ls3.wko_ls3_mr_no,   
				wko_ls3.wko_ls3_rec_supplier,   
				wko_ls3.wko_ls3_act_qty,   
				wko_ls3.wko_ls3_act_cost,   
				wko_ls3.wko_ls3_mtl_uom,   
				wko_ls3.wko_ls3_pr_no,   
				wko_ls3.wko_ls3_pr_lineno,   
				wko_ls3.wko_ls3_po_no,    
				wko_ls3.wko_ls3_po_lineno,   
				wko_ls3.wko_ls3_craft,   
				wko_ls3.wko_ls3_nonrefpono,   
				wko_ls3.wko_ls3_com_code,   
				wko_ls3.wko_ls3_taxable,   
				wko_ls3.wko_ls3_chg_costcenter,   
				wko_ls3.wko_ls3_chg_account,   
				wko_ls3.wko_ls3_info_src,   
				wko_ls3.wko_ls3_stk_locn,   
				wko_ls3.wko_ls3_inv_no, 
				wko_ls3.wko_ls3_inv_lineno, 
				wko_ls3.wko_ls3_varchar1,   
				wko_ls3.wko_ls3_varchar2,   
				wko_ls3.wko_ls3_varchar3,   
				wko_ls3.wko_ls3_varchar4,   
				wko_ls3.wko_ls3_varchar5,   
				wko_ls3.wko_ls3_numeric1,   
				wko_ls3.wko_ls3_numeric2,   
				wko_ls3.wko_ls3_numeric3,   
				wko_ls3.wko_ls3_numeric4,   
				wko_ls3.wko_ls3_numeric5,   
				wko_ls3.wko_ls3_datetime1,   
				wko_ls3.wko_ls3_datetime2,   
				wko_ls3.wko_ls3_datetime3,   
				wko_ls3.wko_ls3_datetime4,   
				wko_ls3.wko_ls3_datetime5,   
				wko_ls3.wko_ls3_tax_cd,   
				wko_ls3.wko_ls3_tax_rate,   
				wko_ls3.wko_ls3_tax_value,   
				pur_mst.pur_mst_purq_approve,
				pur_ls1.pur_ls1_po_no,
				pur_ls1.pur_ls1_po_lineno,
				wko_ls3.audit_user,   
				wko_ls3.audit_date,   
				wko_ls3.column1,   
				wko_ls3.column2,   
				wko_ls3.column3,   
				wko_ls3.column4,   
				wko_ls3.column5,   
				wko_ls3.mst_RowID,
				wko_ls3.RowID
	FROM 		wko_ls3

	LEFT OUTER JOIN pur_mst
	ON				pur_mst.site_cd = wko_ls3.site_cd
	AND			pur_mst.pur_mst_porqnnum =  wko_ls3.wko_ls3_pr_no

	LEFT OUTER JOIN pur_ls1
	ON				pur_mst.site_cd = pur_ls1.site_cd
	AND			pur_mst.RowID =  pur_ls1.mst_RowID
	AND			pur_ls1.pur_ls1_pr_lineno =  wko_ls3.wko_ls3_pr_lineno


			WHERE 	wko_ls3.site_cd = '".$site_cd."'
			AND 	wko_ls3.mst_RowID = '".$mst_RowID."'";
 
 


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

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



if ($valid) {
	
	
	returnData($json);	
}
 
function returnData($json){
	$returnData = array(
	'status' => 'SUCCESS',	
	'message' => 'Successfully',
	'data' => $json);

	echo json_encode($returnData);
}

function returnError($error_message){	
	
	$returnData = array(
	'status' => 'ERROR',
	'message' => $error_message);	
	echo json_encode($returnData);
	exit();
}
	sqlsrv_free_stmt( $stmt);
	sqlsrv_close( $conn);	

 
?>