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


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

$sql ="SELECT		dft_mst_mtr_approval_type,
					dft_mst_pur_approval,
					dft_mst_mtr_closed_loop,
					dft_mst_pur_closed_loop
		FROM		dft_mst (NOLOCK)
		WHERE		dft_mst.site_cd = '".$site_cd."'";



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

		if( !$stmt_1 ) {
			
			 $error_message = "Error selecting dft_mst";
			 returnError($error_message);
			 die( print_r( sqlsrv_errors(), true));
			 
		}

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




	$sql ="SELECT	emp_det_mr_approver,
					emp_det_mr_limit,
					emp_det_pr_approval_limit,
					emp_det_pr_approver
		FROM		emp_mst (NOLOCK),
					emp_det (NOLOCK)
		WHERE		emp_mst.site_cd = emp_det.site_cd
		AND			emp_mst.RowID = emp_det.mst_RowID
		AND			emp_mst.site_cd = '".$site_cd."'
		AND			emp_mst_login_id = '".$LOGINID."'";		



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

		if( !$stmt_1 ) {
			
			 $error_message = "Error selecting dft_mst";
			 returnError($error_message);
			 die( print_r( sqlsrv_errors(), true));
			 
		}		
		
		$json1 = array();

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


if ($valid) {

	returnData($json,$json1);	
	
}


function returnData($json,$json1){
	
	 
	$returnData = array(
		'status' => 'SUCCESS',
		'message' => 'Successfully',
		'data'=>$json,
		'data1'=>$json1);

	echo json_encode($returnData);
}

function returnError($error_message){
	$json = array();
	
	$returnData = array(
	'status' => 'ERROR',
	'message' => $error_message);
	
	echo json_encode($returnData);
		
}


 
?>