<?php

require_once('config.php');
require_once ('f_get_usg_wrk_change.php');
require_once('f_get_emp_ls5.php');
require_once ('f_logging.php');
$now = date("Ymdhisa");
$file_name = __DIR__ . "\mobile_log\_get_dropdown.log";

$error_message;
$valid = true;


/* Begin the transaction. */
if ( sqlsrv_begin_transaction( $conn ) === false ) {
     die( print_r( sqlsrv_errors(), true ));
}

 
$site_cd = $_REQUEST['site_cd'];
$type = $_REQUEST['type'];
$EmpID = $_REQUEST['EmpID'];
$LoginID = $_REQUEST['LoginID'];

$where_work_group = get_emp_ls5($site_cd, $EmpID, 'emp_ls5_work_group');

switch ($type) {
    case 'All':
	
			//CostCenter
			$sql= "SELECT 	cf_cost_center.costcenter,
							cf_cost_center.descs    
					FROM 	cf_cost_center (NOLOCK)  
					WHERE (	cf_cost_center.disable_flag = 0  ) 
					AND 	cf_cost_center.site_cd = '".$site_cd."' 
					AND 	disable_flag = '0'ORDER BY costcenter ASC";

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

			if ($stmt_CostCenter === false)
			{
				if (($errors = sqlsrv_errors()) != null)
				{
					foreach ($errors as $error)
					{

						file_put_contents($file_name, $now . "\r\n" . $sql . "\r\n" . "SQLSTATE: " . $error['SQLSTATE'] . "\r\n" . "code: " . $error['code'] . "\r\n" . "message: " . $error['message'] . "\r\n\r\n", FILE_APPEND);
					}
				}
				sqlsrv_rollback($conn);
				sqlsrv_close($conn);

				$error_message = "(".$now.") Error selecting table (cf_cost_center)";
				returnError($error_message);
			}

			$CostCenter = array();

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



			//Cf_Account
			$sql="SELECT 	cf_account.account, cf_account.descs        
					FROM 	cf_account (NOLOCK)     
					WHERE 	cf_account.site_cd = '".$site_cd."' 
					AND 	disable_flag = '0'ORDER BY cf_account.account ASC";
					
			$stmt_Cf_Account = sqlsrv_query( $conn, $sql);

			if ($stmt_Cf_Account === false)
			{
				if (($errors = sqlsrv_errors()) != null)
				{
					foreach ($errors as $error)
					{

						file_put_contents($file_name, $now . "\r\n" . $sql . "\r\n" . "SQLSTATE: " . $error['SQLSTATE'] . "\r\n" . "code: " . $error['code'] . "\r\n" . "message: " . $error['message'] . "\r\n\r\n", FILE_APPEND);
					}
				}
				sqlsrv_rollback($conn);
				sqlsrv_close($conn);

				$error_message = "(".$now.") Error selecting table (Cf_Account)";
				returnError($error_message);
			}

			$account = array();

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


			//FaultCode
			$sql= "SELECT 	wrk_flt.wrk_flt_fault_cd,wrk_flt.wrk_flt_desc  
					FROM 	wrk_flt (NOLOCK) 
					WHERE 	wrk_flt.site_cd = '".$site_cd."' 
					AND 	wrk_flt.wrk_flt_disable_flag = '0' ORDER BY wrk_flt_fault_cd ASC";
					
			$stmt_FaultCode = sqlsrv_query( $conn, $sql);

			if ($stmt_FaultCode === false)
			{
				if (($errors = sqlsrv_errors()) != null)
				{
					foreach ($errors as $error)
					{

						file_put_contents($file_name, $now . "\r\n" . $sql . "\r\n" . "SQLSTATE: " . $error['SQLSTATE'] . "\r\n" . "code: " . $error['code'] . "\r\n" . "message: " . $error['message'] . "\r\n\r\n", FILE_APPEND);
					}
				}
				sqlsrv_rollback($conn);
				sqlsrv_close($conn);

				$error_message = "(".$now.") Error selecting table (wrk_flt)";
				returnError($error_message);
			}

			$FaultCode = array();

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



			//Priority
			$sql= "	SELECT 	wrk_pri.wrk_pri_pri_cd,  
							wrk_pri.wrk_pri_desc,  
							wrk_pri.wrk_pri_due_date_count ,
							wrk_pri_due_type,
							wrk_pri_start_day							
					FROM 	wrk_pri   (NOLOCK)
					WHERE 	wrk_pri.site_cd = '".$site_cd."'
					AND 	wrk_pri.wrk_pri_disable_flag = '0'ORDER BY wrk_pri_pri_cd ASC";
					
			$stmt_Priority = sqlsrv_query( $conn, $sql);

			if ($stmt_Priority === false)
			{
				if (($errors = sqlsrv_errors()) != null)
				{
					foreach ($errors as $error)
					{

						file_put_contents($file_name, $now . "\r\n" . $sql . "\r\n" . "SQLSTATE: " . $error['SQLSTATE'] . "\r\n" . "code: " . $error['code'] . "\r\n" . "message: " . $error['message'] . "\r\n\r\n", FILE_APPEND);
					}
				}
				sqlsrv_rollback($conn);
				sqlsrv_close($conn);

				$error_message = "(".$now.") Error selecting table (wrk_pri)";
				returnError($error_message);
			}

			$Priority = array();

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



			//Work ActionCode
			$sql= "	SELECT 	wrk_act.wrk_act_action_cd, 
							wrk_act.wrk_act_desc        
					FROM 	wrk_act (NOLOCK)  
					WHERE 	wrk_act.site_cd = '".$site_cd."' 
					AND 	wrk_act.wrk_act_disable_flag ='0' ORDER BY wrk_act_action_cd ASC";
					
			$stmt_ActionCode = sqlsrv_query( $conn, $sql);

			if ($stmt_ActionCode === false)
			{
				if (($errors = sqlsrv_errors()) != null)
				{
					foreach ($errors as $error)
					{

						file_put_contents($file_name, $now . "\r\n" . $sql . "\r\n" . "SQLSTATE: " . $error['SQLSTATE'] . "\r\n" . "code: " . $error['code'] . "\r\n" . "message: " . $error['message'] . "\r\n\r\n", FILE_APPEND);
					}
				}
				sqlsrv_rollback($conn);
				sqlsrv_close($conn);

				$error_message = "(".$now.") Error selecting (wrk_act)";
				returnError($error_message);
			}

			$ActionCode = array();

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


			//WorkArea
			$sql= "SELECT mst_war.mst_war_work_area,mst_war.mst_war_desc 
					FROM mst_war (NOLOCK)
					WHERE (mst_war.mst_war_disable_flag = 0     ) 
					AND mst_war.site_cd = '".$site_cd."'ORDER BY mst_war_work_area ";


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

			if ($stmt_WorkArea === false)
			{
				if (($errors = sqlsrv_errors()) != null)
				{
					foreach ($errors as $error)
					{

						file_put_contents($file_name, $now . "\r\n" . $sql . "\r\n" . "SQLSTATE: " . $error['SQLSTATE'] . "\r\n" . "code: " . $error['code'] . "\r\n" . "message: " . $error['message'] . "\r\n\r\n", FILE_APPEND);
					}
				}
				sqlsrv_rollback($conn);
				sqlsrv_close($conn);

				$error_message = "(".$now.") Error selecting (mst_war)";
				returnError($error_message);
			}

			$WorkArea = array();

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



			//WorkCasuseCode
			$sql= "	SELECT 	wrk_ccd.wrk_ccd_cause_cd,
							wrk_ccd.wrk_ccd_desc      
					FROM 	wrk_ccd (NOLOCK)      
					WHERE 	wrk_ccd.site_cd = '".$site_cd."' 
					AND 	wrk_ccd.wrk_ccd_disable_flag ='0' ORDER BY wrk_ccd_cause_cd ASC";
					
			$stmt_CasuseCode = sqlsrv_query( $conn, $sql);

			if ($stmt_CasuseCode === false)
			{
				if (($errors = sqlsrv_errors()) != null)
				{
					foreach ($errors as $error)
					{

						file_put_contents($file_name, $now . "\r\n" . $sql . "\r\n" . "SQLSTATE: " . $error['SQLSTATE'] . "\r\n" . "code: " . $error['code'] . "\r\n" . "message: " . $error['message'] . "\r\n\r\n", FILE_APPEND);
					}
				}
				sqlsrv_rollback($conn);
				sqlsrv_close($conn);

				$error_message = "(".$now.") Error selecting (wrk_ccd)";
				returnError($error_message);
			}

			$CasuseCode = array();

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


			//WorkClass
			$sql= "	SELECT 	wrk_cls.wrk_cls_cls_cd,
							wrk_cls.wrk_cls_desc  
					FROM 	wrk_cls (NOLOCK)       
					WHERE 	wrk_cls.site_cd = '".$site_cd."' 
					AND 	wrk_cls.wrk_cls_disable_flag ='0' ORDER BY wrk_cls_cls_cd ASC";
					
			$stmt_WorkClass = sqlsrv_query( $conn, $sql);

			if ($stmt_WorkClass === false)
			{
				if (($errors = sqlsrv_errors()) != null)
				{
					foreach ($errors as $error)
					{

						file_put_contents($file_name, $now . "\r\n" . $sql . "\r\n" . "SQLSTATE: " . $error['SQLSTATE'] . "\r\n" . "code: " . $error['code'] . "\r\n" . "message: " . $error['message'] . "\r\n\r\n", FILE_APPEND);
					}
				}
				sqlsrv_rollback($conn);
				sqlsrv_close($conn);

				$error_message = "(".$now.") Error selecting (wrk_cls)";
				returnError($error_message);
			}


			$WorkClass = array();

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


			//wrk_group
			$sql="	SELECT 	wrk_grp_grp_cd,wrk_grp_desc 
					from 	wrk_grp (NOLOCK)
					where 	site_cd = '".$site_cd."'";
					
			$stmt_wrk_group = sqlsrv_query( $conn, $sql);

			if ($stmt_wrk_group === false)
			{
				if (($errors = sqlsrv_errors()) != null)
				{
					foreach ($errors as $error)
					{

						file_put_contents($file_name, $now . "\r\n" . $sql . "\r\n" . "SQLSTATE: " . $error['SQLSTATE'] . "\r\n" . "code: " . $error['code'] . "\r\n" . "message: " . $error['message'] . "\r\n\r\n", FILE_APPEND);
					}
				}
				sqlsrv_rollback($conn);
				sqlsrv_close($conn);

				$error_message = "(".$now.") Error selecting (wrk_grp)";
				returnError($error_message);
			}

			$wrk_group = array();

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


			$where_wrk_sts_change = get_usg_wrk_change($site_cd,$EmpID,'wrk_sts_status');

			//Workorder Status
			$sql= "	SELECT 	wrk_sts.wrk_sts_status,  wrk_sts.wrk_sts_typ_cd,    wrk_sts.wrk_sts_desc,  wrk_sts.wrk_sts_email_flag, wrk_sts.wrk_sts_tim_crd,wrk_sts.wrk_sts_cm_ack_req,wrk_sts.wrk_sts_pm_ack_req  
					FROM 	wrk_sts  (NOLOCK)
					WHERE  (wrk_sts.wrk_sts_disable_flag = 0  ) 
					AND 	wrk_sts.site_cd = '".$site_cd."'".$where_wrk_sts_change;
					
			$stmt_WorkorderStatus = sqlsrv_query( $conn, $sql);

			if ($stmt_WorkorderStatus === false)
			{
				if (($errors = sqlsrv_errors()) != null)
				{
					foreach ($errors as $error)
					{

						file_put_contents($file_name, $now . "\r\n" . $sql . "\r\n" . "SQLSTATE: " . $error['SQLSTATE'] . "\r\n" . "code: " . $error['code'] . "\r\n" . "message: " . $error['message'] . "\r\n\r\n", FILE_APPEND);
					}
				}
				sqlsrv_rollback($conn);
				sqlsrv_close($conn);

				$error_message = "(".$now.") Error selecting (wrk_sts)";
				returnError($error_message);
			}

			$WorkorderStatus = array();

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



			//WorkType
			$sql= "	SELECT  wrk_typ.wrk_typ_typ_cd ,
							wrk_typ.wrk_typ_desc, 
							wrk_typ_option,  
							wrk_typ_pm_option  
					FROM 	wrk_typ  (NOLOCK)     
					WHERE 	wrk_typ.site_cd = '".$site_cd."' 
					AND 	wrk_typ.wrk_typ_disable_flag ='0'ORDER BY wrk_typ_typ_cd ASC";
					
			$stmt_WorkType = sqlsrv_query( $conn, $sql);

			if ($stmt_WorkType === false)
			{
				if (($errors = sqlsrv_errors()) != null)
				{
					foreach ($errors as $error)
					{

						file_put_contents($file_name, $now . "\r\n" . $sql . "\r\n" . "SQLSTATE: " . $error['SQLSTATE'] . "\r\n" . "code: " . $error['code'] . "\r\n" . "message: " . $error['message'] . "\r\n\r\n", FILE_APPEND);
					}
				}
				sqlsrv_rollback($conn);
				sqlsrv_close($conn);

				$error_message = "(".$now.") Error selecting (wrk_typ)";
				returnError($error_message);
			}

			$WorkType = array();

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




			//AssetCode
			$sql= "	SELECT 	ast_cod.ast_cod_ast_cd, ast_cod.ast_cod_desc        
					FROM 	ast_cod  (NOLOCK)      
					WHERE (	ast_cod.ast_cod_disable_flag = 0  ) 
					AND 	ast_cod.site_cd = '".$site_cd."'ORDER BY ast_cod_ast_cd";


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

			if ($stmt_AssetCode === false)
			{
				if (($errors = sqlsrv_errors()) != null)
				{
					foreach ($errors as $error)
					{

						file_put_contents($file_name, $now . "\r\n" . $sql . "\r\n" . "SQLSTATE: " . $error['SQLSTATE'] . "\r\n" . "code: " . $error['code'] . "\r\n" . "message: " . $error['message'] . "\r\n\r\n", FILE_APPEND);
					}
				}
				sqlsrv_rollback($conn);
				sqlsrv_close($conn);

				$error_message = "(".$now.") Error selecting (ast_cod)";
				returnError($error_message);
			}


			$Assetcode = array();

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



			//CriticalFactor
			$sql= "SELECT 	ast_cri.ast_cri_cri_factor,ast_cri.ast_cri_desc    
					FROM 	ast_cri  (NOLOCK)
					WHERE (	ast_cri.ast_cri_disable_flag = 0  ) 
					AND ast_cri.site_cd = '".$site_cd."'ORDER BY ast_cri_cri_factor";


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

			if ($stmt_CriticalFactor === false)
			{
				if (($errors = sqlsrv_errors()) != null)
				{
					foreach ($errors as $error)
					{

						file_put_contents($file_name, $now . "\r\n" . $sql . "\r\n" . "SQLSTATE: " . $error['SQLSTATE'] . "\r\n" . "code: " . $error['code'] . "\r\n" . "message: " . $error['message'] . "\r\n\r\n", FILE_APPEND);
					}
				}
				sqlsrv_rollback($conn);
				sqlsrv_close($conn);

				$error_message = "(".$now.") Error selecting (ast_cri)";
				returnError($error_message);
			}

			$CriticalFactor = array();

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



			//AssetGroupCode
			$sql= "SELECT 	ast_grp.ast_grp_grp_cd, ast_grp.ast_grp_desc ,ast_grp_option
					FROM 	ast_grp  (NOLOCK)
					WHERE (	ast_grp.ast_grp_disable_flag =0  ) 
					AND ast_grp.site_cd = '".$site_cd."'ORDER BY ast_grp_grp_cd";


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

			if ($stmt_ast_grp === false)
			{
				if (($errors = sqlsrv_errors()) != null)
				{
					foreach ($errors as $error)
					{

						file_put_contents($file_name, $now . "\r\n" . $sql . "\r\n" . "SQLSTATE: " . $error['SQLSTATE'] . "\r\n" . "code: " . $error['code'] . "\r\n" . "message: " . $error['message'] . "\r\n\r\n", FILE_APPEND);
					}
				}
				sqlsrv_rollback($conn);
				sqlsrv_close($conn);

				$error_message = "(".$now.") Error selecting (ast_grp)";
				returnError($error_message);
			}

			$AssetGroupCode = array();

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


			//Level
			$sql= "SELECT 	ast_lvl.ast_lvl_ast_lvl, ast_lvl.ast_lvl_desc    
					FROM 	ast_lvl    (NOLOCK)
					WHERE (	ast_lvl.ast_lvl_disable_flag = 0)
					AND ast_lvl.site_cd = '".$site_cd."'ORDER BY ast_lvl_ast_lvl";


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

			if ($stmt_ast_lvl === false)
			{
				if (($errors = sqlsrv_errors()) != null)
				{
					foreach ($errors as $error)
					{

						file_put_contents($file_name, $now . "\r\n" . $sql . "\r\n" . "SQLSTATE: " . $error['SQLSTATE'] . "\r\n" . "code: " . $error['code'] . "\r\n" . "message: " . $error['message'] . "\r\n\r\n", FILE_APPEND);
					}
				}
				sqlsrv_rollback($conn);
				sqlsrv_close($conn);

				$error_message = "(".$now.") Error selecting (ast_lvl)";
				returnError($error_message);
			}


			$AssetLevel = array();

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



			//AssetLocation
			$sql= "SELECT 	ast_loc.ast_loc_ast_loc,ast_loc.ast_loc_desc,ast_loc.ast_loc_wr_option,ast_loc.ast_loc_wo_option, ast_loc.ast_loc_pm_option  
					FROM 	ast_loc     (NOLOCK)
					WHERE (	ast_loc.ast_loc_disable_flag = 0      ) 
					AND ast_loc.site_cd = '".$site_cd."'ORDER BY ast_loc_ast_loc";


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

			if ($stmt_ast_loc === false)
			{
				if (($errors = sqlsrv_errors()) != null)
				{
					foreach ($errors as $error)
					{

						file_put_contents($file_name, $now . "\r\n" . $sql . "\r\n" . "SQLSTATE: " . $error['SQLSTATE'] . "\r\n" . "code: " . $error['code'] . "\r\n" . "message: " . $error['message'] . "\r\n\r\n", FILE_APPEND);
					}
				}
				sqlsrv_rollback($conn);
				sqlsrv_close($conn);

				$error_message = "(".$now.") Error selecting (ast_loc)";
				returnError($error_message);
			}
			$AssetLocation = array();

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



			//AssetStatus
			$sql= "SELECT ast_sts_status,ast_sts_desc,ast_sts_typ_cd		
					FROM 	ast_sts (NOLOCK)
					WHERE	ast_sts.site_cd = '".$site_cd."'
					AND		ast_sts.ast_sts_typ_cd IN ( 'IN-SERVICE', 'OUT-OF-SERVICE') ORDER BY ast_sts_status";


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

			if ($stmt_ast_sts === false)
			{
				if (($errors = sqlsrv_errors()) != null)
				{
					foreach ($errors as $error)
					{

						file_put_contents($file_name, $now . "\r\n" . $sql . "\r\n" . "SQLSTATE: " . $error['SQLSTATE'] . "\r\n" . "code: " . $error['code'] . "\r\n" . "message: " . $error['message'] . "\r\n\r\n", FILE_APPEND);
					}
				}
				sqlsrv_rollback($conn);
				sqlsrv_close($conn);

				$error_message = "(".$now.") Error selecting (ast_sts)";
				returnError($error_message);
			}

			$AssetStatus = array();

			do {
				 while ($row = sqlsrv_fetch_array($stmt_ast_sts, SQLSRV_FETCH_ASSOC)) {		
					$AssetStatus[] = $row;	
				
				 }
			} while ( sqlsrv_next_result($stmt_ast_sts) );
			
			
			
			//AssetStatus_IN-SERVICE
			$sql= "	select ast_sts_status,ast_sts_desc from ast_sts (NOLOCK) 
					where site_cd ='".$site_cd."' 
					and ast_sts_count_dwn_time ='1' 
					and ast_sts_disable_flag ='0' 
					and ast_sts_typ_cd='IN-SERVICE'";


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

			if ($stmt_ast_sts_in_service === false)
			{
				if (($errors = sqlsrv_errors()) != null)
				{
					foreach ($errors as $error)
					{

						file_put_contents($file_name, $now . "\r\n" . $sql . "\r\n" . "SQLSTATE: " . $error['SQLSTATE'] . "\r\n" . "code: " . $error['code'] . "\r\n" . "message: " . $error['message'] . "\r\n\r\n", FILE_APPEND);
					}
				}
				sqlsrv_rollback($conn);
				sqlsrv_close($conn);

				$error_message = "(".$now.") Error selecting (ast_sts)";
				returnError($error_message);
			}


			$AssetStatus_In_service = array();

			do {
				 while ($row = sqlsrv_fetch_array($stmt_ast_sts_in_service, SQLSRV_FETCH_ASSOC)) {		
					$AssetStatus_In_service[] = $row;	
				
				 }
			} while ( sqlsrv_next_result($stmt_ast_sts_in_service) );
			
			
			//AssetStatus_OUT-OF-SERVICE
			$sql= "	select ast_sts_status,ast_sts_desc from ast_sts (NOLOCK) 
					where site_cd ='".$site_cd."' 
					and ast_sts_count_dwn_time ='1'
					and ast_sts_disable_flag ='0'
					and ast_sts_typ_cd='OUT-OF-SERVICE'";


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

			if ($stmt_ast_sts_out_of_service === false)
			{
				if (($errors = sqlsrv_errors()) != null)
				{
					foreach ($errors as $error)
					{

						file_put_contents($file_name, $now . "\r\n" . $sql . "\r\n" . "SQLSTATE: " . $error['SQLSTATE'] . "\r\n" . "code: " . $error['code'] . "\r\n" . "message: " . $error['message'] . "\r\n\r\n", FILE_APPEND);
					}
				}
				sqlsrv_rollback($conn);
				sqlsrv_close($conn);

				$error_message = "(".$now.") Error selecting (ast_sts)";
				returnError($error_message);
			}

			$AssetStatus_Out_of_service = array();

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



			//AssetType
			$sql= "SELECT ast_type.ast_type_cd, ast_type.ast_type_descs 
					FROM ast_type (NOLOCK)
					WHERE (ast_type.ast_type_disable_flag = 0  ) 
					AND ast_type.site_cd = '".$site_cd."'ORDER BY ast_type_cd";


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

			if ($stmt_ast_type === false)
			{
				if (($errors = sqlsrv_errors()) != null)
				{
					foreach ($errors as $error)
					{

						file_put_contents($file_name, $now . "\r\n" . $sql . "\r\n" . "SQLSTATE: " . $error['SQLSTATE'] . "\r\n" . "code: " . $error['code'] . "\r\n" . "message: " . $error['message'] . "\r\n\r\n", FILE_APPEND);
					}
				}
				sqlsrv_rollback($conn);
				sqlsrv_close($conn);

				$error_message = "(".$now.") Error selecting (ast_type)";
				returnError($error_message);
			}

			$AssetType = array();

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


			//Employee
			$sql= "SELECT Distinct emp_mst.emp_mst_empl_id,     		
					emp_mst_title = COALESCE(emp_mst_title,''), 
					emp_mst.emp_mst_name,emp_mst_emg_phone = COALESCE(emp_mst_emg_phone,''),
					emp_det_craft = COALESCE(emp_det_craft+':'+crf_mst_desc,''),
					emp_ls1_charge_rate = COALESCE(emp_ls1.emp_ls1_charge_rate,0),
					emp_det_supervisor,
					emp_det_foreman					
			From 	emp_mst (NOLOCK)

					LEFT 
					OUTER 
					JOIN	emp_sts (NOLOCK) 
					ON		emp_mst.site_cd = emp_sts.site_cd  
					and     emp_mst.emp_mst_status = emp_sts.emp_sts_status  	
					And		emp_sts.emp_sts_typ_cd = 'ACTIVE'

					LEFT 
					OUTER 
					JOIN	emp_det (NOLOCK) 
					ON		emp_mst.site_cd = emp_det.site_cd		
					And		emp_mst.rowid = emp_det.mst_rowid
					
					LEFT 
					OUTER 
					JOIN	emp_ls1 (NOLOCK) 
					ON		emp_det.mst_rowid = emp_ls1.mst_rowid	
					And		emp_det.site_cd = emp_ls1.site_cd	
					AND		emp_det.emp_det_craft = emp_ls1.emp_ls1_craft
					
					LEFT 
					OUTER 
					JOIN	crf_mst (NOLOCK) 
					ON		emp_det.site_cd = crf_mst.site_cd		
					AND		emp_det.emp_det_craft = crf_mst.crf_mst_crf_cd	
					
					LEFT OUTER JOIN emp_ls5 (NOLOCK) 
					ON emp_mst.site_cd = emp_ls5.site_cd 
					AND emp_mst.RowID = emp_ls5.mst_RowID
					
					
			WHERE	emp_mst.site_cd = '".$site_cd."' 
			AND 	emp_det.emp_det_foreman = '1'
			And emp_sts.emp_sts_typ_cd = 'ACTIVE' ".$where_work_group." ORDER BY emp_mst.emp_mst_empl_id ASC";


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


			if ($stmt_emp_mst === false)
			{
				if (($errors = sqlsrv_errors()) != null)
				{
					foreach ($errors as $error)
					{

						file_put_contents($file_name, $now . "\r\n" . $sql . "\r\n" . "SQLSTATE: " . $error['SQLSTATE'] . "\r\n" . "code: " . $error['code'] . "\r\n" . "message: " . $error['message'] . "\r\n\r\n", FILE_APPEND);
					}
				}
				sqlsrv_rollback($conn);
				sqlsrv_close($conn);

				$error_message = "(".$now.") Error selecting (emp_mst)";
				returnError($error_message);
			}

			$Employee = array();

			do {
				 while ($row = sqlsrv_fetch_array($stmt_emp_mst, SQLSRV_FETCH_ASSOC)) {
					//$row['emp_mst_name'] =  utf8_encode($row['emp_mst_name']);
					$row['emp_mst_name'] =  mb_convert_encoding($row['emp_mst_name'], 'UTF-8', 'ISO-8859-7');
					$Employee[] = $row;	
				
				 }
			} while ( sqlsrv_next_result($stmt_emp_mst) );
			
			
			
			//Assign_Employee
			$sql= "SELECT  Distinct
					emp_mst.emp_mst_empl_id,     		
					emp_mst_title 			= COALESCE(emp_mst_title,''), 
					emp_mst.emp_mst_name,
					emp_mst_emg_phone 		= COALESCE(emp_mst_emg_phone,''),
					emp_det_craft 			= COALESCE(emp_det_craft+':'+crf_mst_desc,''),
					emp_ls1_charge_rate 	= COALESCE(emp_ls1.emp_ls1_charge_rate,0),

					WOASSIGN = (SELECT count(*) FROM wko_mst(NOLOCK) , wko_det(NOLOCK), wrk_sts(NOLOCK)
							WHERE	wko_mst.site_cd = wko_det.site_cd
							AND		wko_mst.rowid = wko_det.mst_rowid
							AND		wko_mst.site_cd = wrk_sts.site_cd
							AND		wko_mst.wko_mst_status = wrk_sts.wrk_sts_status
							ANd		wko_det.site_cd = emp_mst.site_cd
							AND		wko_det.wko_det_assign_to = emp_mst.emp_mst_empl_id
							AND		wrk_sts.wrk_sts_typ_cd ='OPEN')		
							
			From 	emp_mst (NOLOCK)

					LEFT 
					OUTER 
					JOIN	emp_sts (NOLOCK) 
					ON		emp_mst.site_cd = emp_sts.site_cd  
					and     emp_mst.emp_mst_status = emp_sts.emp_sts_status  	
					And		emp_sts.emp_sts_typ_cd = 'ACTIVE'

					LEFT 
					OUTER 
					JOIN	emp_det (NOLOCK) 
					ON		emp_mst.site_cd = emp_det.site_cd		
					And		emp_mst.rowid = emp_det.mst_rowid
					
					LEFT 
					OUTER 
					JOIN	emp_ls1 (NOLOCK) 
					ON		emp_det.mst_rowid = emp_ls1.mst_rowid	
					And		emp_det.site_cd = emp_ls1.site_cd	
					AND		emp_det.emp_det_craft = emp_ls1.emp_ls1_craft
					
					LEFT 
					OUTER 
					JOIN	crf_mst (NOLOCK) 
					ON		emp_det.site_cd = crf_mst.site_cd		
					AND		emp_det.emp_det_craft = crf_mst.crf_mst_crf_cd	
					
					LEFT OUTER JOIN emp_ls5 (NOLOCK) ON emp_mst.site_cd = emp_ls5.site_cd AND emp_mst.RowID = emp_ls5.mst_RowID
					
					
			WHERE	emp_mst.site_cd = '".$site_cd."' 
			And 	emp_sts.emp_sts_typ_cd = 'ACTIVE' 
			AND 	emp_det.emp_det_foreman = '1' ".$where_work_group."
			ORDER BY emp_mst.emp_mst_empl_id ASC";


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


			if ($stmt_assign_emp_mst === false)
			{
				if (($errors = sqlsrv_errors()) != null)
				{
					foreach ($errors as $error)
					{

						file_put_contents($file_name, $now . "\r\n" . $sql . "\r\n" . "SQLSTATE: " . $error['SQLSTATE'] . "\r\n" . "code: " . $error['code'] . "\r\n" . "message: " . $error['message'] . "\r\n\r\n", FILE_APPEND);
					}
				}
				sqlsrv_rollback($conn);
				sqlsrv_close($conn);

				$error_message = "(".$now.") Error selecting (emp_mst)";
				returnError($error_message);
			}

			$Assign_Employee = array();

			do {
				 while ($row = sqlsrv_fetch_array($stmt_assign_emp_mst, SQLSRV_FETCH_ASSOC)) {
					$row['emp_mst_name'] =  mb_convert_encoding($row['emp_mst_name'], 'UTF-8', 'ISO-8859-7');
					$Assign_Employee[] = $row;	
				
				 }
			} while ( sqlsrv_next_result($stmt_assign_emp_mst) );


			//Asset_Auto_Numnering
			$sql="	SELECT 	cnt_mst_numbering , 
							cnt_mst_option ,
							cnt_mst_module_cd 
					FROM 	cnt_mst  (NOLOCK)
					WHERE  	cnt_mst.site_cd ='".$site_cd."'
					AND 	cnt_mst_module_cd =  'AST'";

			$stmt_cnt_mst = sqlsrv_query( $conn, $sql);
			 
			 
			if ($stmt_cnt_mst === false)
			{
				if (($errors = sqlsrv_errors()) != null)
				{
					foreach ($errors as $error)
					{

						file_put_contents($file_name, $now . "\r\n" . $sql . "\r\n" . "SQLSTATE: " . $error['SQLSTATE'] . "\r\n" . "code: " . $error['code'] . "\r\n" . "message: " . $error['message'] . "\r\n\r\n", FILE_APPEND);
					}
				}
				sqlsrv_rollback($conn);
				sqlsrv_close($conn);

				$error_message = "(".$now.") Error selecting (cnt_mst)";
				returnError($error_message);
			}

			$Auto_Numnering = array();

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




			//WorkOrder_Auto_Numnering
			$sql= "	Select 	cnt_mst_numbering ,
							cnt_mst_option ,
							cnt_mst_module_cd 
					From 	cnt_mst (NOLOCK) 
					Where 	site_cd ='".$site_cd."' 
					And cnt_mst_module_cd ='WKO'";

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

			if ($stmt_wko_cnt_mst === false)
			{
				if (($errors = sqlsrv_errors()) != null)
				{
					foreach ($errors as $error)
					{

						file_put_contents($file_name, $now . "\r\n" . $sql . "\r\n" . "SQLSTATE: " . $error['SQLSTATE'] . "\r\n" . "code: " . $error['code'] . "\r\n" . "message: " . $error['message'] . "\r\n\r\n", FILE_APPEND);
					}
				}
				sqlsrv_rollback($conn);
				sqlsrv_close($conn);

				$error_message = "(".$now.") Error selecting (cnt_mst)";
				returnError($error_message);
			}

			$Wko_Auto_numbering = array();

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


			//WorkRequest_Auto_Numnering
			$sql= "Select cnt_mst_numbering,cnt_mst_option ,cnt_mst_module_cd  From cnt_mst (NOLOCK) Where site_cd ='".$site_cd."' And cnt_mst_module_cd ='WKR'";
			$stmt_wkr_cnt_mst = sqlsrv_query( $conn, $sql);

			if ($stmt_wkr_cnt_mst === false)
			{
				if (($errors = sqlsrv_errors()) != null)
				{
					foreach ($errors as $error)
					{

						file_put_contents($file_name, $now . "\r\n" . $sql . "\r\n" . "SQLSTATE: " . $error['SQLSTATE'] . "\r\n" . "code: " . $error['code'] . "\r\n" . "message: " . $error['message'] . "\r\n\r\n", FILE_APPEND);
					}
				}
				sqlsrv_rollback($conn);
				sqlsrv_close($conn);

				$error_message = "(".$now.") Error selecting (cnt_mst)";
				returnError($error_message);
			}

			$Wkr_Auto_numbering = array();

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


			//RatingQuestion
			$sql="WITH LabelData AS (SELECT * FROM cf_label WHERE table_name = 'wko_det' 
			AND language_cd = 'DEFAULT' AND column_name IN ('wko_det_rating1','wko_det_rating2','wko_det_rating3')),
			NumberedLabels AS (SELECT ROW_NUMBER() OVER (ORDER BY CASE column_name WHEN 'wko_det_rating1' THEN 1 WHEN 'wko_det_rating2' THEN 2 WHEN 'wko_det_rating3' THEN 3 END ) AS column_no, * FROM LabelData )
			SELECT * FROM NumberedLabels";	
							
				//echo $sql;
				//$params = array($site_cd,$mst_RowID);					
									
				$stmt_RatingQuestion = sqlsrv_query( $conn, $sql);

				if ($stmt_RatingQuestion === false)
				{
					if (($errors = sqlsrv_errors()) != null)
					{
						foreach ($errors as $error)
						{

							file_put_contents($file_name, $now . "\r\n" . $sql . "\r\n" . "SQLSTATE: " . $error['SQLSTATE'] . "\r\n" . "code: " . $error['code'] . "\r\n" . "message: " . $error['message'] . "\r\n\r\n", FILE_APPEND);
						}
					}
					sqlsrv_rollback($conn);
					sqlsrv_close($conn);

					$error_message = "(".$now.") Error selecting (cf_label)";
					returnError($error_message);
				}

				$RatingQuestion= array();

				do {
					 while ($row = sqlsrv_fetch_array($stmt_RatingQuestion, SQLSRV_FETCH_ASSOC)) {	
					 
						$RatingQuestion[] = $row;		
					
					 }
				} while ( sqlsrv_next_result($stmt_RatingQuestion) );
				
						
						
			//MRStockno			
			$sql="SELECT	DISTINCT

			itm_mst.itm_mst_stockno,
			itm_mst.itm_mst_costcenter,
			itm_mst.itm_mst_account,
			itm_mst.itm_mst_mstr_locn,			
			itm_mst_desc = COALESCE(cast(itm_mst.itm_mst_desc as varchar (255)),''),	
			itm_mst.itm_mst_issue_uom,			
			itm_mst.itm_mst_issue_price,
			itm_mst.itm_mst_ttl_oh,
			itm_mst_ext_desc = COALESCE(cast(itm_mst.itm_mst_ext_desc as varchar (255)),''),	
			itm_det.itm_det_part_deac_status,
			itm_det.itm_det_order_pt,
			itm_mst_partno = COALESCE(itm_mst_partno,''),			
			itm_det_ttl_oh= COALESCE(itm_det_ttl_oh,0),
			
			category = CASE
			WHEN		((itm_loc_oh_qty - itm_loc_hard_resrv - itm_loc_short_qty + itm_loc_pr_due_in + itm_loc_due_in) < itm_loc_order_pt )
			AND         ((itm_loc_oh_qty - itm_loc_hard_resrv - itm_loc_short_qty + itm_loc_pr_due_in + itm_loc_due_in) < itm_loc_maximum )
			AND         ( itm_det_maximum  > 0 )
			AND         ( itm_det_order_pt  > 0 )
			AND         ( itm_mst_order_rule = 'L' ) THEN 'BELOW'

			WHEN		((itm_mst_ttl_oh - itm_det_ttl_hard_resrv - itm_det_ttl_short + itm_det_pr_due_in + itm_det_due_in) < itm_det_order_pt )
			AND         ((itm_mst_ttl_oh - itm_det_ttl_hard_resrv - itm_det_ttl_short + itm_det_pr_due_in + itm_det_due_in) < itm_det_maximum )
			AND         ( itm_det_maximum  > 0 )
			AND         ( itm_det_order_pt  > 0 )
			AND         ( itm_mst_order_rule = 'T' ) THEN 'BELOW'

			ELSE 'NORMAL' END,			
			
			itm_mst.RowID
			
			FROM		itm_mst (NOLOCK)

			INNER JOIN	itm_det (NOLOCK)            
			ON          itm_mst.site_cd = itm_det.site_cd
			AND         itm_mst.RowID = itm_det.mst_RowID

			INNER JOIN  itm_sts (NOLOCK)
			ON          itm_det.site_cd = itm_sts.site_cd 
			AND         itm_det.itm_det_part_deac_status = itm_sts.itm_sts_status

			INNER JOIN	itm_loc (NOLOCK)
			ON			itm_mst.site_cd = itm_loc.site_cd
			AND			itm_mst.RowID = itm_loc.mst_RowID

			WHERE		itm_mst.site_cd = '".$_REQUEST['site_cd']."'
			AND			itm_sts_typ_cd = 'ACTIVE'

			ORDER BY	itm_mst.itm_mst_stockno" ;
					
			$stmt_MRStockno = sqlsrv_query( $conn, $sql);

			if ($stmt_MRStockno === false)
			{
				if (($errors = sqlsrv_errors()) != null)
				{
					foreach ($errors as $error)
					{

						file_put_contents($file_name, $now . "\r\n" . $sql . "\r\n" . "SQLSTATE: " . $error['SQLSTATE'] . "\r\n" . "code: " . $error['code'] . "\r\n" . "message: " . $error['message'] . "\r\n\r\n", FILE_APPEND);
					}
				}
				sqlsrv_rollback($conn);
				sqlsrv_close($conn);

				$error_message = "(".$now.") Error selecting (itm_mst)";
				returnError($error_message);
			}

			$MRStockno = array();

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


			//Time card houres
			$sql="SELECT hours_type_cd = hours_type_cd+' : '+ hours_type_desc,  
						 hours_type.hours_type_multiplier, 
						 hours_type.hours_type_adder    
				FROM 	 hours_type (NOLOCK)   
				WHERE 	 hours_type.site_cd = ?";
					
			//echo $sql;
			$params = array($site_cd);		
			$stmt_hours_type = sqlsrv_query( $conn, $sql,$params);

			if ($stmt_hours_type === false)
			{
				if (($errors = sqlsrv_errors()) != null)
				{
					foreach ($errors as $error)
					{

						file_put_contents($file_name, $now . "\r\n" . $sql . "\r\n" . "SQLSTATE: " . $error['SQLSTATE'] . "\r\n" . "code: " . $error['code'] . "\r\n" . "message: " . $error['message'] . "\r\n\r\n", FILE_APPEND);
					}
				}
				sqlsrv_rollback($conn);
				sqlsrv_close($conn);

				$error_message = "(".$now.") Error selecting (hours_type)";
				returnError($error_message);
			}


			$HoursType= array();

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


			//Time craft
			$sql="	SELECT 	emp_ls1_craft = emp_ls1_craft+' : '+crf_mst_desc, emp_ls1.emp_ls1_charge_rate,emp_mst.emp_mst_empl_id       
					FROM 	crf_mst (NOLOCK) , 	emp_ls1(NOLOCK),  	emp_mst(NOLOCK)  
					WHERE 	(crf_mst.site_cd = emp_ls1.site_cd  
					AND		crf_mst.crf_mst_crf_cd = emp_ls1.emp_ls1_craft  
					AND		crf_mst.site_cd = emp_mst.site_cd  
					AND		emp_ls1.mst_rowid = emp_mst.rowid) 
					AND 	emp_mst.site_cd = ?";	
					
				//echo $sql;
				$params = array($site_cd);					
									
				$stmt_crf_mst = sqlsrv_query( $conn, $sql,$params);

				if ($stmt_crf_mst === false)
				{
					if (($errors = sqlsrv_errors()) != null)
					{
						foreach ($errors as $error)
						{

							file_put_contents($file_name, $now . "\r\n" . $sql . "\r\n" . "SQLSTATE: " . $error['SQLSTATE'] . "\r\n" . "code: " . $error['code'] . "\r\n" . "message: " . $error['message'] . "\r\n\r\n", FILE_APPEND);
						}
					}
					sqlsrv_rollback($conn);
					sqlsrv_close($conn);

					$error_message = "(".$now.") Error selecting (hours_type)";
					returnError($error_message);
				}

				$TimeCraft= array();

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

						
			//supplier			
			$sql= "SELECT 	sup_mst.sup_mst_supplier_cd,   
							sup_mst.sup_mst_desc,  
							sup_mst.sup_mst_status  
					FROM 	sup_mst (NOLOCK), sup_sts (NOLOCK)
					WHERE (sup_mst.site_cd = sup_sts.site_cd  
					AND			sup_mst.sup_mst_status = sup_sts.sup_sts_status  
					AND			sup_sts.sup_sts_typ_cd NOT IN ('DEACTIVATE')) 
					AND sup_mst.site_cd = '".$site_cd."' ORDER BY sup_mst_supplier_cd ASC";
			$stmt_supplier = sqlsrv_query( $conn, $sql);

			if ($stmt_supplier === false)
			{
				if (($errors = sqlsrv_errors()) != null)
				{
					foreach ($errors as $error)
					{

						file_put_contents($file_name, $now . "\r\n" . $sql . "\r\n" . "SQLSTATE: " . $error['SQLSTATE'] . "\r\n" . "code: " . $error['code'] . "\r\n" . "message: " . $error['message'] . "\r\n\r\n", FILE_APPEND);
					}
				}
				sqlsrv_rollback($conn);
				sqlsrv_close($conn);

				$error_message = "(".$now.") Error selecting (sup_mst)";
				returnError($error_message);
			}

			$supplier = array();

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



			//UOM
			$sql= "SELECT 	uom_mst.uom_mst_uom,  uom_mst.uom_mst_desc,uom_mst_type  FROM uom_mst(NOLOCK)  
					WHERE 	uom_mst.site_cd = '".$site_cd."' 
					AND 	uom_mst_type IN ('SERVICE','MATERIAL') 
					AND 	uom_mst_disable_flag = '0' ORDER BY uom_mst_uom ASC ";
			$stmt_uom = sqlsrv_query( $conn, $sql);

			if ($stmt_uom === false)
			{
				if (($errors = sqlsrv_errors()) != null)
				{
					foreach ($errors as $error)
					{

						file_put_contents($file_name, $now . "\r\n" . $sql . "\r\n" . "SQLSTATE: " . $error['SQLSTATE'] . "\r\n" . "code: " . $error['code'] . "\r\n" . "message: " . $error['message'] . "\r\n\r\n", FILE_APPEND);
					}
				}
				sqlsrv_rollback($conn);
				sqlsrv_close($conn);

				$error_message = "(".$now.") Error selecting (uom_mst)";
				returnError($error_message);
			}
			$uom = array();

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


			//Tax code
			$sql= "	SELECT 	tax_mst.tax_mst_tax_cd, 
							tax_mst.tax_mst_desc, 
							tax_mst.tax_mst_tax_rate  
					FROM 	tax_mst (NOLOCK)    
					WHERE (	tax_mst.tax_mst_disable_flag = '0') 
					AND tax_mst.site_cd = '".$site_cd."' 
					AND tax_mst_type IN ('A', 'P') 
					AND tax_mst_disable_flag = '0' ORDER BY tax_mst_tax_cd ASC";
			$stmt_tax_cd = sqlsrv_query( $conn, $sql);

			if ($stmt_tax_cd === false)
			{
				if (($errors = sqlsrv_errors()) != null)
				{
					foreach ($errors as $error)
					{

						file_put_contents($file_name, $now . "\r\n" . $sql . "\r\n" . "SQLSTATE: " . $error['SQLSTATE'] . "\r\n" . "code: " . $error['code'] . "\r\n" . "message: " . $error['message'] . "\r\n\r\n", FILE_APPEND);
					}
				}
				sqlsrv_rollback($conn);
				sqlsrv_close($conn);

				$error_message = "(".$now.") Error selecting (tax_mst)";
				returnError($error_message);
			}

			$tax_cd = array();

			do {
				 while ($row = sqlsrv_fetch_array($stmt_tax_cd, SQLSRV_FETCH_ASSOC)) {		
					$tax_cd[] = $row;	
				
				 }
			} while ( sqlsrv_next_result($stmt_tax_cd) );
			
			
			//emp_ls5
			$sql= "	select  emp_ls5_work_group =COALESCE(emp_ls5_work_group +' : '+wrk_grp_desc,'') 

					from emp_ls5(NOLOCK)

					LEFT 
					OUTER 
					JOIN	wrk_grp (NOLOCK) 
					ON		emp_ls5.site_cd = wrk_grp.site_cd		
					And		emp_ls5.emp_ls5_work_group = wrk_grp.wrk_grp_grp_cd

					LEFT 
					OUTER 
					JOIN	emp_mst (NOLOCK) 
					ON		emp_mst.site_cd = emp_ls5.site_cd		
					And		emp_mst.rowid = emp_ls5.mst_rowid

			Where 			emp_mst.site_cd = '".$site_cd."'
					And		emp_mst.emp_mst_empl_id = '".$EmpID."'";
					
			$stmt_emp_ls5 = sqlsrv_query( $conn, $sql);

			if ($stmt_emp_ls5 === false)
			{
				if (($errors = sqlsrv_errors()) != null)
				{
					foreach ($errors as $error)
					{

						file_put_contents($file_name, $now . "\r\n" . $sql . "\r\n" . "SQLSTATE: " . $error['SQLSTATE'] . "\r\n" . "code: " . $error['code'] . "\r\n" . "message: " . $error['message'] . "\r\n\r\n", FILE_APPEND);
					}
				}
				sqlsrv_rollback($conn);
				sqlsrv_close($conn);

				$error_message = "(".$now.") Error selecting (emp_mst)";
				returnError($error_message);
			}

			$emp_ls5 = array();

			do {
				 while ($row = sqlsrv_fetch_array($stmt_emp_ls5, SQLSRV_FETCH_ASSOC)) {		
					$emp_ls5[] = $row;	
				
				 }
			} while ( sqlsrv_next_result($stmt_emp_ls5) );
			
			
			//Approvel_WorkOrderStatus
			$sql_apwrks="SELECT 	wrk_sts.wrk_sts_status, wrk_sts.wrk_sts_typ_cd,  wrk_sts.wrk_sts_desc, wrk_sts.wrk_sts_email_flag  
					FROM 	wrk_sts  (NOLOCK)
					WHERE	wrk_sts.wrk_sts_disable_flag = 0  
					AND		wrk_sts.wrk_sts_typ_cd NOT IN ( 'COMPLETE', 'CLOSE', 'CANCEL', 'FORCE-CLOSE' ) 
					AND		wrk_sts.site_cd = ?";	
							
			//echo $sql;
			$params_apwrks = array($site_cd);					
								
			$stmt_apwrks = sqlsrv_query( $conn, $sql_apwrks,$params_apwrks);

			if ($stmt_apwrks === false)
			{
				if (($errors = sqlsrv_errors()) != null)
				{
					foreach ($errors as $error)
					{

						file_put_contents($file_name, $now . "\r\n" . $sql . "\r\n" . "SQLSTATE: " . $error['SQLSTATE'] . "\r\n" . "code: " . $error['code'] . "\r\n" . "message: " . $error['message'] . "\r\n\r\n", FILE_APPEND);
					}
				}
				sqlsrv_rollback($conn);
				sqlsrv_close($conn);

				$error_message = "(".$now.") Error selecting (wrk_sts)";
				returnError($error_message);
			}


			$Approvel_WorkOrderStatus= array();

			do {
				 while ($row = sqlsrv_fetch_array($stmt_apwrks, SQLSRV_FETCH_ASSOC)) {	
				 
					$Approvel_WorkOrderStatus[] = $row;		
				
				 }
			} while ( sqlsrv_next_result($stmt_apwrks) );
			
			
			
			//Dashbord_menu
			$sql_DBM="SELECT 			cf_menu.object_name,
										cf_menu.object_descs,			
										exe_flag,					
										new_flag,
										edit_flag,
										mobile_object_type,
										cf_menu_seq,
										cf_menu.column1
													

						FROM 				cf_menu (NOLOCK)
						
						INNER JOIN			cf_user_access (NOLOCK)
						ON					cf_user_access.menuid = cf_menu.rowid
						
						INNER JOIN			cf_module (NOLOCK)
						ON					cf_module.language_cd = cf_menu.language_cd
						AND					cf_module.cf_module_module_cd = cf_menu.program_category

						WHERE    			cf_user_access.site_cd = '".$site_cd."'
						AND      			cf_user_access.empl_id = '".$LoginID."'		
						AND					cf_menu.object_type = 'M'
						AND					cf_menu.mobile_object_type in ('o','m')

						AND					cf_menu.language_cd = 'DEFAULT' order by cf_menu_seq ";	
							
			
								
								
			$stmt_DBM = sqlsrv_query( $conn, $sql_DBM);

			if ($stmt_DBM === false)
			{
				if (($errors = sqlsrv_errors()) != null)
				{
					foreach ($errors as $error)
					{

						file_put_contents($file_name, $now . "\r\n" . $sql . "\r\n" . "SQLSTATE: " . $error['SQLSTATE'] . "\r\n" . "code: " . $error['code'] . "\r\n" . "message: " . $error['message'] . "\r\n\r\n", FILE_APPEND);
					}
				}
				sqlsrv_rollback($conn);
				sqlsrv_close($conn);

				$error_message = "(".$now.") Error selecting (cf_menu)";
				returnError($error_message);
			}

			$Dashbord_menu= array();

			do {
				 while ($row = sqlsrv_fetch_array($stmt_DBM, SQLSRV_FETCH_ASSOC)) {	
				 
					$Dashbord_menu[] = $row;		
				
				 }
			} while ( sqlsrv_next_result($stmt_DBM) );
			
			
			//WORK ORDER cf_label
			$sql_WO_cf_label="select * from cf_label (NOLOCK) where  
							column_name IN ('wko_mst_originator',				'wko_mst_phone',			'wko_mst_assetno',			'wko_mst_descs',
											'wko_mst_asset_group_code',			'wko_mst_asset_location',	'wko_mst_asset_level',		'wko_mst_chg_costcenter',
											'wko_mst_wo_no',					'wko_mst_orig_priority',	'wko_mst_plan_priority',	'wko_mst_org_date',
											'wko_mst_due_date',					'wko_mst_flt_code',			'wko_mst_status',			'wko_det_assign_to',
											'wko_det_lab_cost',					'wko_det_con_cost',			'wko_det_mtl_cost',			'wko_det_work_type',
											'wko_det_caccount',					'wko_det_maccount',			'wko_det_ack_name',			'wko_det_ack_id',
											'wko_det_ack_contact',				'wko_det_ack_date',			'wko_det_safety',			'wko_det_work_grp',
											'wko_det_numeric2',					'wko_det_numeric3',			'wko_det_work_grp',			'wko_det_cause_code',
											'wko_det_act_code',					'wko_det_corr_action' ,		'wko_det_note1',			'wko_ls4_pr_no',	
											'wko_ls4_supplier',					'wko_ls4_chg_costcenter',	'wko_ls4_descr',			'wko_ls4_svc_uom',	
											'wko_ls4_est_cost',					'wko_ls4_qty_needed',		'pur_ls1_desc',				'pur_ls1_supplier',	
											'pur_ls1_tax_code',					'pur_ls1_chg_costcenter',	'pur_ls1_chg_account',		'pur_ls1_ord_uom',	
											'pur_ls1_ord_qty',					'wko_ls3_pr_lineno',		'wko_ls3_rec_supplier',		'wko_ls3_chg_costcenter',	
											'wko_ls3_descr',					'wko_ls3_mtl_uom',			'wko_ls3_item_cost',		'wko_ls3_qty_needed',
											'wko_ls2_mr_lineno',				'mtr_mst_assetno',			'mtr_mst_requester',		'wko_ls2_mr_no',
											'wko_ls2_stockno',					'wko_ls2_chg_costcenter',	'wko_ls2_stk_locn',			'wko_ls2_desc',
											'wko_ls2_mtl_uom',					'wko_ls2_item_cost',		'mtr_ls1_stockno',			'mtr_ls1_stk_locn',
											'mtr_ls1_desc',						'mtr_ls1_chg_costcenter',	'mtr_ls1_chg_account',		'mtr_ls1_mtl_uom',
											'mtr_ls1_item_cost',				'wko_ls8_empl_id',			'wko_ls8_craft',			'wko_ls8_hours_type',	
											'wko_ls8_hrs',						'wko_ls8_multiplier',		'wko_ls8_rate',				'wko_ls8_act_cost',
											'wko_det_supv_id',					'ast_mst_asset_no',			'ast_mst_asset_group',		'ast_mst_asset_shortdesc',
											'ast_mst_asset_longdesc',			'ast_mst_asset_grpcode',	'ast_mst_perm_id',			'ast_det_cus_code',
											'ast_mst_asset_type',				'ast_mst_asset_code',		'mst_war_work_area',		'ast_mst_asset_locn',
											'ast_mst_ast_lvl',					'ast_mst_asset_status',		'ast_mst_cri_factor',		'ast_mst_cost_center',
											'ast_mst_create_by',				'ast_det_warranty_date',	'wkr_mst_wr_no',			'wko_mst_work_area',
											'wko_mst_pm_grp',					'wko_det_work_class',		'wko_det_from_date',		'wko_det_to_date',
											'wko_mst_org_time',					'wko_mst_due_time',			'ast_dwntime_asset_no',		'ast_dwntime_out_of_service_date',	
											'ast_dwntime_return_to_service_date','ast_dwntime_remark',		'ast_dwntime_sched_flag',	'ast_dwntime_repair_from',
											'ast_dwntime_repair_to',			'ast_dwntime_downtime',		'ast_dwntime_repairtime',	'wko_det_sched_date',
											'wko_det_cmpl_date',				'ast_dwntime_repair_down',	'wko_det_planner', 			'wko_det_clo_date',
											'wko_det_exc_date',					'ast_mst_work_area',		'ler_mst_department',		'ler_mst_ler_date',
											'ler_mst_requester',				'ler_mst_contact',			'ler_mst_status',           'ler_det_sign_by',
											'ler_det_sign_by_id',				'ler_det_sign_by_contact',	'ast_det_serial') 
							and language_cd = 'DEFAULT' order by customize_label";	
							
			$stmt_WO_cf_label = sqlsrv_query( $conn, $sql_WO_cf_label);

			if ($stmt_WO_cf_label === false)
			{
				if (($errors = sqlsrv_errors()) != null)
				{
					foreach ($errors as $error)
					{

						file_put_contents($file_name, $now . "\r\n" . $sql . "\r\n" . "SQLSTATE: " . $error['SQLSTATE'] . "\r\n" . "code: " . $error['code'] . "\r\n" . "message: " . $error['message'] . "\r\n\r\n", FILE_APPEND);
					}
				}
				sqlsrv_rollback($conn);
				sqlsrv_close($conn);

				$error_message = "(".$now.") Error selecting (cf_label)";
				returnError($error_message);
			}

			$WO_cf_label= array();

			do {
				 while ($row = sqlsrv_fetch_array($stmt_WO_cf_label, SQLSRV_FETCH_ASSOC)) {	
				 
					$WO_cf_label[] = $row;		
				
				 }
			} while ( sqlsrv_next_result($stmt_WO_cf_label) );
			
			
			
			//cur_mst
			$sql= "SELECT * FROM cur_mst (NOLOCK)";
			$stmt_cur_mst = sqlsrv_query( $conn, $sql);

			if ($stmt_cur_mst === false)
			{
				if (($errors = sqlsrv_errors()) != null)
				{
					foreach ($errors as $error)
					{

						file_put_contents($file_name, $now . "\r\n" . $sql . "\r\n" . "SQLSTATE: " . $error['SQLSTATE'] . "\r\n" . "code: " . $error['code'] . "\r\n" . "message: " . $error['message'] . "\r\n\r\n", FILE_APPEND);
					}
				}
				sqlsrv_rollback($conn);
				sqlsrv_close($conn);

				$error_message = "(".$now.") Error selecting (cur_mst)";
				returnError($error_message);
			}

			$cur_mst = array();

			do {
				 while ($row = sqlsrv_fetch_array($stmt_cur_mst, SQLSRV_FETCH_ASSOC)) {		
					$cur_mst[] = $row;	
				
				 }
			} while ( sqlsrv_next_result($stmt_cur_mst) );
			
			
			//PR_Status_Type
			$sql= "	select pur_sts_st_cat,pur_sts_status_type,pur_sts_status,pur_sts_description from pur_sts (NOLOCK) where site_cd ='".$site_cd."'";


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

			if ($stmt_PRStatus_Type === false)
			{
				if (($errors = sqlsrv_errors()) != null)
				{
					foreach ($errors as $error)
					{

						file_put_contents($file_name, $now . "\r\n" . $sql . "\r\n" . "SQLSTATE: " . $error['SQLSTATE'] . "\r\n" . "code: " . $error['code'] . "\r\n" . "message: " . $error['message'] . "\r\n\r\n", FILE_APPEND);
					}
				}
				sqlsrv_rollback($conn);
				sqlsrv_close($conn);

				$error_message = "(".$now.") Error selecting (pur_sts)";
				returnError($error_message);
			}

			$PRStatus_Type = array();

			do {
				 while ($row = sqlsrv_fetch_array($stmt_PRStatus_Type, SQLSRV_FETCH_ASSOC)) {		
					$PRStatus_Type[] = $row;	
				
				 }
			} while ( sqlsrv_next_result($stmt_PRStatus_Type) );
			
			
			//PM Group			
			$sql= "SELECT 	prm_grp.prm_grp_grp_cd,   
							prm_grp.prm_grp_desc
					FROM 	prm_grp (NOLOCK)
					WHERE  	prm_grp.site_cd = '".$site_cd."' 
					AND 	prm_grp.prm_grp_disable_flag = 0 
					AND 	prm_grp.prm_grp_disable_flag = '0' ORDER BY prm_grp_grp_cd ASC";
			$stmt_prm_grp = sqlsrv_query( $conn, $sql);

			if ($stmt_prm_grp === false)
			{
				if (($errors = sqlsrv_errors()) != null)
				{
					foreach ($errors as $error)
					{

						file_put_contents($file_name, $now . "\r\n" . $sql . "\r\n" . "SQLSTATE: " . $error['SQLSTATE'] . "\r\n" . "code: " . $error['code'] . "\r\n" . "message: " . $error['message'] . "\r\n\r\n", FILE_APPEND);
					}
				}
				sqlsrv_rollback($conn);
				sqlsrv_close($conn);

				$error_message = "(".$now.") Error selecting (prm_grp)";
				returnError($error_message);
			}

			$PMGroup = array();

			do {
				 while ($row = sqlsrv_fetch_array($stmt_prm_grp, SQLSRV_FETCH_ASSOC)) {		
					$PMGroup []= $row;	
				
				 }
			} while ( sqlsrv_next_result($stmt_prm_grp) );
			
			
			//Department
			$sql= "	SELECT 	dept_mst_dept_cod,
							dept_mst_description,
							dept_mst_email_id,
							dept_mst_linen							
					FROM 	dept_mst   (NOLOCK)
					WHERE 	dept_mst.site_cd = '".$site_cd."'
					AND 	dept_mst.dept_mst_disable_flag = '0'ORDER BY dept_mst_dept_cod ASC";
					
			$stmt_Department = sqlsrv_query( $conn, $sql);

			if ($stmt_Department === false)
			{
				if (($errors = sqlsrv_errors()) != null)
				{
					foreach ($errors as $error)
					{

						file_put_contents($file_name, $now . "\r\n" . $sql . "\r\n" . "SQLSTATE: " . $error['SQLSTATE'] . "\r\n" . "code: " . $error['code'] . "\r\n" . "message: " . $error['message'] . "\r\n\r\n", FILE_APPEND);
					}
				}
				sqlsrv_rollback($conn);
				sqlsrv_close($conn);

				$error_message = "(".$now.") Error selecting (dept_mst)";
				returnError($error_message);
			}


			$Department = array();

			do {
				 while ($row = sqlsrv_fetch_array($stmt_Department, SQLSRV_FETCH_ASSOC)) {		
				 
					$Department[] = $row;	
				
				 }
			} while ( sqlsrv_next_result($stmt_Department) );
			
			
			//Linen Status
			$sql= "	SELECT 	lri_sts_cat_cd, lri_sts_typ_cd, lri_sts_status, lri_sts_desc, lri_sts_disable_flag, scn_sts_email_flag  
					FROM 	lri_sts  (NOLOCK)
					WHERE  (lri_sts.lri_sts_disable_flag = 0  ) 
					AND  	lri_sts_typ_cd NOT IN ('CANCEL')
					AND 	lri_sts.site_cd = '".$site_cd."'";
					
			$stmt_Linen_Status = sqlsrv_query( $conn, $sql);

			if ($stmt_Linen_Status === false)
			{
				if (($errors = sqlsrv_errors()) != null)
				{
					foreach ($errors as $error)
					{

						file_put_contents($file_name, $now . "\r\n" . $sql . "\r\n" . "SQLSTATE: " . $error['SQLSTATE'] . "\r\n" . "code: " . $error['code'] . "\r\n" . "message: " . $error['message'] . "\r\n\r\n", FILE_APPEND);
					}
				}
				sqlsrv_rollback($conn);
				sqlsrv_close($conn);

				$error_message = "(".$now.") Error selecting (lri_sts)";
				returnError($error_message);
			}

			$LineStatus = array();

			do {
				 while ($row = sqlsrv_fetch_array($stmt_Linen_Status, SQLSRV_FETCH_ASSOC)) {		
					$LineStatus[] = $row;	
				
				 }
			} while ( sqlsrv_next_result($stmt_Linen_Status) );
			
			
			//Linen Request Status
			$sql= "	SELECT 	lrr_sts_cat_cd, lrr_sts_typ_cd, lrr_sts_status, lrr_sts_desc, lrr_sts_disable_flag, scn_sts_email_flag  
					FROM 	lrr_sts  (NOLOCK)
					WHERE  (lrr_sts.lrr_sts_disable_flag = 0  ) 
					AND  	lrr_sts_typ_cd NOT IN ('CANCEL')
					AND 	lrr_sts.site_cd = '".$site_cd."'";
					
			$stmt_Linen_Req_Status = sqlsrv_query( $conn, $sql);

			if ($stmt_Linen_Req_Status === false)
			{
				if (($errors = sqlsrv_errors()) != null)
				{
					foreach ($errors as $error)
					{

						file_put_contents($file_name, $now . "\r\n" . $sql . "\r\n" . "SQLSTATE: " . $error['SQLSTATE'] . "\r\n" . "code: " . $error['code'] . "\r\n" . "message: " . $error['message'] . "\r\n\r\n", FILE_APPEND);
					}
				}
				sqlsrv_rollback($conn);
				sqlsrv_close($conn);

				$error_message = "(".$now.") Error selecting (lrr_sts)";
				returnError($error_message);
			}

			$LinenRequestStatus = array();

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


			$json_All = array();
			if( $stmt_CostCenter && $stmt_Cf_Account && $stmt_FaultCode && $stmt_Priority && $stmt_ActionCode && $stmt_WorkArea && $stmt_CasuseCode && $stmt_WorkClass && $stmt_wrk_group &&
			$stmt_WorkorderStatus && $stmt_WorkType && $stmt_AssetCode && $stmt_CriticalFactor && $stmt_ast_grp && $stmt_ast_lvl && $stmt_ast_loc && $stmt_ast_sts && $stmt_ast_type && $stmt_emp_mst 
			&&$stmt_cnt_mst&& $stmt_wko_cnt_mst && $stmt_RatingQuestion && $stmt_MRStockno && $stmt_hours_type && $stmt_crf_mst && $stmt_supplier && $stmt_uom && $stmt_tax_cd && $stmt_ast_sts_in_service
			&& $stmt_ast_sts_out_of_service && $stmt_emp_ls5 && $stmt_apwrks && $stmt_assign_emp_mst && $stmt_wkr_cnt_mst && $stmt_DBM && $stmt_WO_cf_label && $stmt_cur_mst && $stmt_PRStatus_Type && $stmt_prm_grp && $stmt_Department && $stmt_Linen_Status && $stmt_Linen_Req_Status) {
				 sqlsrv_commit( $conn );
				 sqlsrv_close( $conn);	
				 $json_All['CostCenter'] = $CostCenter;				 
				 $json_All['account'] = $account;
				 $json_All['FaultCode'] = $FaultCode;
				 $json_All['Priority'] = $Priority;
				 $json_All['ActionCode'] = $ActionCode;
				 $json_All['WorkArea'] = $WorkArea;
				 $json_All['CasuseCode'] = $CasuseCode;
				 $json_All['WorkClass'] = $WorkClass;
				 $json_All['wrk_group'] = $wrk_group;
				 $json_All['WorkorderStatus'] = $WorkorderStatus;
				 $json_All['WorkType'] = $WorkType;
				 $json_All['Assetcode'] = $Assetcode;
				 $json_All['CriticalFactor'] = $CriticalFactor;
				 $json_All['AssetGroupCode'] = $AssetGroupCode;
				 $json_All['AssetLevel'] = $AssetLevel;
				 $json_All['AssetLocation'] = $AssetLocation;
				 $json_All['AssetStatus'] = $AssetStatus;
				 $json_All['AssetType'] = $AssetType;
				 $json_All['Employee'] = $Employee;
				 $json_All['Assign_Employee'] = $Assign_Employee;
				 $json_All['Auto_Numnering'] = $Auto_Numnering;
				 $json_All['Wko_Auto_numbering'] = $Wko_Auto_numbering;
				 $json_All['RatingQuestion'] = $RatingQuestion;
				 $json_All['MRStockno'] = $MRStockno;
				 $json_All['HoursType'] = $HoursType;
				 $json_All['TimeCraft'] = $TimeCraft;
				 $json_All['supplier'] = $supplier;
				 $json_All['uom'] = $uom;
				 $json_All['tax_cd'] = $tax_cd;		 
				 $json_All['AssetInService'] = $AssetStatus_In_service;	
				 $json_All['AssetOutOfService'] = $AssetStatus_Out_of_service;					 
				 $json_All['emp_ls5'] = $emp_ls5;
				 $json_All['Approvel_WorkOrderstatus'] = $Approvel_WorkOrderStatus;				 
				 $json_All['Wkr_Auto_numbering'] = $Wkr_Auto_numbering;				 
				 $json_All['Dashbord_menu'] = $Dashbord_menu;
				 $json_All['WorkOrder_cf_label'] = $WO_cf_label;						 
				 $json_All['cur_mst'] = $cur_mst;						 
				 $json_All['PRStatus_Type'] = $PRStatus_Type;						 
				 $json_All['PMGroup'] = $PMGroup;
				 $json_All['Department'] = $Department;		
				 $json_All['LinenStatus'] = $LineStatus;						 
				 $json_All['LinenRequestStatus'] = $LinenRequestStatus;						 
				
				returnData($json_All);		
			} else {
				 sqlsrv_rollback( $conn );
				 $error_message = "Transaction rolled back.<br />";
				 returnError($error_message);
			}
    break;
    case 'CostCenter':
	
			//CostCenter
			$sql= "	SELECT 	cf_cost_center.costcenter,
							cf_cost_center.descs    
					FROM 	cf_cost_center (NOLOCK)  
					WHERE (	cf_cost_center.disable_flag = 0  ) 
					AND 	cf_cost_center.site_cd = '".$site_cd."' 
					AND 	disable_flag = '0'ORDER BY costcenter ASC";

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

			if ($stmt_CostCenter === false)
			{
				if (($errors = sqlsrv_errors()) != null)
				{
					foreach ($errors as $error)
					{

						file_put_contents($file_name, $now . "\r\n" . $sql . "\r\n" . "SQLSTATE: " . $error['SQLSTATE'] . "\r\n" . "code: " . $error['code'] . "\r\n" . "message: " . $error['message'] . "\r\n\r\n", FILE_APPEND);
					}
				}
				sqlsrv_rollback($conn);
				sqlsrv_close($conn);

				$error_message = "(".$now.") Error selecting (cf_cost_center)";
				returnError($error_message);
			}

			$CostCenter = array();

			do {
				 while ($row = sqlsrv_fetch_array($stmt_CostCenter, SQLSRV_FETCH_ASSOC)) {		
					$CostCenter[] = $row;	
				 }
			} while ( sqlsrv_next_result($stmt_CostCenter) );
			
			if($stmt_CostCenter) {
				sqlsrv_commit( $conn );
				sqlsrv_close( $conn);	
				
				$json_All['CostCenter'] = $CostCenter;				 
				returnData($json_All);		
			} else {
				sqlsrv_rollback( $conn );
				$error_message = "Transaction rolled back.<br />";
				returnError($error_message);
			}
    break;
    case 'account':
	
		//Cf_Account
		$sql="	SELECT 	cf_account.account, cf_account.descs        
				FROM 	cf_account (NOLOCK)     
				WHERE 	cf_account.site_cd = '".$site_cd."' 
				AND 	disable_flag = '0'ORDER BY cf_account.account ASC";
				
		$stmt_Cf_Account = sqlsrv_query( $conn, $sql);

		if ($stmt_Cf_Account === false)
		{
			if (($errors = sqlsrv_errors()) != null)
			{
				foreach ($errors as $error)
				{

					file_put_contents($file_name, $now . "\r\n" . $sql . "\r\n" . "SQLSTATE: " . $error['SQLSTATE'] . "\r\n" . "code: " . $error['code'] . "\r\n" . "message: " . $error['message'] . "\r\n\r\n", FILE_APPEND);
				}
			}
			sqlsrv_rollback($conn);
			sqlsrv_close($conn);

			$error_message = "(".$now.") Error selecting (cf_account)";
			returnError($error_message);
		}


		$account = array();

		do {
			 while ($row = sqlsrv_fetch_array($stmt_Cf_Account, SQLSRV_FETCH_ASSOC)) {		
				$account[] = $row;	
			}
		} while ( sqlsrv_next_result($stmt_Cf_Account) );
		
		if( $stmt_Cf_Account ) {
			
			sqlsrv_commit( $conn );
			sqlsrv_close( $conn);		 
			$json_All['account'] = $account;
			returnData($json_All);	
			
		} else {
			
			sqlsrv_rollback( $conn );
			$error_message = "Transaction rolled back.<br />";
			returnError($error_message);
		}
    break;
	case 'FaultCode':
		//FaultCode
		$sql= "SELECT 	wrk_flt.wrk_flt_fault_cd,wrk_flt.wrk_flt_desc  
				FROM 	wrk_flt (NOLOCK) 
				WHERE 	wrk_flt.site_cd = '".$site_cd."' 
				AND 	wrk_flt.wrk_flt_disable_flag = '0' ORDER BY wrk_flt_fault_cd ASC";
		$stmt_FaultCode = sqlsrv_query( $conn, $sql);

		if ($stmt_FaultCode === false)
		{
			if (($errors = sqlsrv_errors()) != null)
			{
				foreach ($errors as $error)
				{

					file_put_contents($file_name, $now . "\r\n" . $sql . "\r\n" . "SQLSTATE: " . $error['SQLSTATE'] . "\r\n" . "code: " . $error['code'] . "\r\n" . "message: " . $error['message'] . "\r\n\r\n", FILE_APPEND);
				}
			}
			sqlsrv_rollback($conn);
			sqlsrv_close($conn);

			$error_message = "(".$now.") Error selecting (wrk_flt)";
			returnError($error_message);
		}

		$FaultCode = array();

		do {
			 while ($row = sqlsrv_fetch_array($stmt_FaultCode, SQLSRV_FETCH_ASSOC)) {		
				$FaultCode[] = $row;	
			
			 }
		} while ( sqlsrv_next_result($stmt_FaultCode) );
        if( $stmt_FaultCode ) {
				 sqlsrv_commit( $conn );
				 sqlsrv_close( $conn);	
				
				
				 $json_All['FaultCode'] = $FaultCode;
				 		 
				
				returnData($json_All);		
			} else {
				 sqlsrv_rollback( $conn );
				 $error_message = "Transaction rolled back.<br />";
				 returnError($error_message);
			}
    break;
	case 'Priority':
	
		//Priority
		$sql= "	SELECT 	wrk_pri.wrk_pri_pri_cd,  
						wrk_pri.wrk_pri_desc,  
						wrk_pri.wrk_pri_due_date_count,
						wrk_pri_due_type,
						wrk_pri_start_day							
				FROM 	wrk_pri   (NOLOCK)
				WHERE 	wrk_pri.site_cd = '".$site_cd."'
				AND 	wrk_pri.wrk_pri_disable_flag = '0'ORDER BY wrk_pri_pri_cd ASC";
		$stmt_Priority = sqlsrv_query( $conn, $sql);

		if ($stmt_Priority === false)
		{
			if (($errors = sqlsrv_errors()) != null)
			{
				foreach ($errors as $error)
				{

					file_put_contents($file_name, $now . "\r\n" . $sql . "\r\n" . "SQLSTATE: " . $error['SQLSTATE'] . "\r\n" . "code: " . $error['code'] . "\r\n" . "message: " . $error['message'] . "\r\n\r\n", FILE_APPEND);
				}
			}
			sqlsrv_rollback($conn);
			sqlsrv_close($conn);

			$error_message = "(".$now.") Error selecting (wrk_pri)";
			returnError($error_message);
		}


		$Priority = array();

		do {
			 while ($row = sqlsrv_fetch_array($stmt_Priority, SQLSRV_FETCH_ASSOC)) {		
				$Priority[] = $row;	
			
			 }
		} while ( sqlsrv_next_result($stmt_Priority) );
       if( $stmt_Priority ) {
			 sqlsrv_commit( $conn );
			 sqlsrv_close( $conn);	
			
			$json_All['Priority'] = $Priority;
			returnData($json_All);		
		} else {
			 sqlsrv_rollback( $conn );
			 $error_message = "Transaction rolled back.<br />";
			 returnError($error_message);
		}
    break;
	case 'ActionCode':
	
		//Work ActionCode
		$sql= "	SELECT 	wrk_act.wrk_act_action_cd, 
						wrk_act.wrk_act_desc        
				FROM 	wrk_act (NOLOCK)  
				WHERE 	wrk_act.site_cd = '".$site_cd."' 
				AND 	wrk_act.wrk_act_disable_flag ='0' ORDER BY wrk_act_action_cd ASC";
				
		$stmt_ActionCode = sqlsrv_query( $conn, $sql);

		if ($stmt_ActionCode === false)
		{
			if (($errors = sqlsrv_errors()) != null)
			{
				foreach ($errors as $error)
				{

					file_put_contents($file_name, $now . "\r\n" . $sql . "\r\n" . "SQLSTATE: " . $error['SQLSTATE'] . "\r\n" . "code: " . $error['code'] . "\r\n" . "message: " . $error['message'] . "\r\n\r\n", FILE_APPEND);
				}
			}
			sqlsrv_rollback($conn);
			sqlsrv_close($conn);

			$error_message = "(".$now.") Error selecting (wrk_act)";
			returnError($error_message);
		}


		$ActionCode = array();

		do {
			 while ($row = sqlsrv_fetch_array($stmt_ActionCode, SQLSRV_FETCH_ASSOC)) {		
				$ActionCode[] = $row;	
			
			 }
		} while ( sqlsrv_next_result($stmt_ActionCode) );
        if( $stmt_ActionCode ) {
				 sqlsrv_commit( $conn );
				 sqlsrv_close( $conn);	
				
				 
				 $json_All['ActionCode'] = $ActionCode;
						 
				
				returnData($json_All);		
			} else {
				 sqlsrv_rollback( $conn );
				 $error_message = "Transaction rolled back.<br />";
				 returnError($error_message);
			}
    break;
	case 'WorkArea':
	
		//WorkArea
		$sql= "SELECT mst_war.mst_war_work_area,mst_war.mst_war_desc 
				FROM mst_war (NOLOCK)
				WHERE (mst_war.mst_war_disable_flag = 0     ) 
				AND mst_war.site_cd = '".$site_cd."'ORDER BY mst_war_work_area ";


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

		if ($stmt_WorkArea === false)
		{
			if (($errors = sqlsrv_errors()) != null)
			{
				foreach ($errors as $error)
				{

					file_put_contents($file_name, $now . "\r\n" . $sql . "\r\n" . "SQLSTATE: " . $error['SQLSTATE'] . "\r\n" . "code: " . $error['code'] . "\r\n" . "message: " . $error['message'] . "\r\n\r\n", FILE_APPEND);
				}
			}
			sqlsrv_rollback($conn);
			sqlsrv_close($conn);

			$error_message = "(".$now.") Error selecting (mst_war)";
			returnError($error_message);
		}

		$WorkArea = array();

		do {
			 while ($row = sqlsrv_fetch_array($stmt_WorkArea, SQLSRV_FETCH_ASSOC)) {		
				$WorkArea[] = $row;	
			 }
		} while ( sqlsrv_next_result($stmt_WorkArea) );
		if( $stmt_WorkArea ) {
				 sqlsrv_commit( $conn );
				 sqlsrv_close( $conn);	
				
				 
				 $json_All['WorkArea'] = $WorkArea;
				 	 
				
				returnData($json_All);		
			} else {
				 sqlsrv_rollback( $conn );
				 $error_message = "Transaction rolled back.<br />";
				 returnError($error_message);
			}
    break;
	case 'CasuseCode':
	
	//WorkCasuseCode
		$sql= "	SELECT 	wrk_ccd.wrk_ccd_cause_cd,
						wrk_ccd.wrk_ccd_desc      
				FROM 	wrk_ccd (NOLOCK)      
				WHERE 	wrk_ccd.site_cd = '".$site_cd."' 
				AND 	wrk_ccd.wrk_ccd_disable_flag ='0' ORDER BY wrk_ccd_cause_cd ASC";
				
		$stmt_CasuseCode = sqlsrv_query( $conn, $sql);

		if ($stmt_CasuseCode === false)
		{
			if (($errors = sqlsrv_errors()) != null)
			{
				foreach ($errors as $error)
				{

					file_put_contents($file_name, $now . "\r\n" . $sql . "\r\n" . "SQLSTATE: " . $error['SQLSTATE'] . "\r\n" . "code: " . $error['code'] . "\r\n" . "message: " . $error['message'] . "\r\n\r\n", FILE_APPEND);
				}
			}
			sqlsrv_rollback($conn);
			sqlsrv_close($conn);

			$error_message = "(".$now.") Error selecting (wrk_ccd)";
			returnError($error_message);
		}

		$CasuseCode = array();

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

        if( $stmt_CasuseCode ) {
				 sqlsrv_commit( $conn );
				 sqlsrv_close( $conn);	
				
				 
				 $json_All['CasuseCode'] = $CasuseCode;
				 	 
				
				returnData($json_All);		
			} else {
				 sqlsrv_rollback( $conn );
				 $error_message = "Transaction rolled back.<br />";
				 returnError($error_message);
			}
    break;
	case 'WorkClass':
	
		//WorkClass
		$sql= "	SELECT 	wrk_cls.wrk_cls_cls_cd,
						wrk_cls.wrk_cls_desc  
				FROM 	wrk_cls (NOLOCK)       
				WHERE 	wrk_cls.site_cd = '".$site_cd."' 
				AND 	wrk_cls.wrk_cls_disable_flag ='0' ORDER BY wrk_cls_cls_cd ASC";
				
		$stmt_WorkClass = sqlsrv_query( $conn, $sql);

		if ($stmt_WorkClass === false)
		{
			if (($errors = sqlsrv_errors()) != null)
			{
				foreach ($errors as $error)
				{

					file_put_contents($file_name, $now . "\r\n" . $sql . "\r\n" . "SQLSTATE: " . $error['SQLSTATE'] . "\r\n" . "code: " . $error['code'] . "\r\n" . "message: " . $error['message'] . "\r\n\r\n", FILE_APPEND);
				}
			}
			sqlsrv_rollback($conn);
			sqlsrv_close($conn);

			$error_message = "(".$now.") Error selecting (wrk_ccd)";
			returnError($error_message);
		}


		$WorkClass = array();

		do {
			 while ($row = sqlsrv_fetch_array($stmt_WorkClass, SQLSRV_FETCH_ASSOC)) {		
				$WorkClass[] = $row;	
			
			 }
		} while ( sqlsrv_next_result($stmt_WorkClass) );
        if(  $stmt_WorkClass) {
				 sqlsrv_commit( $conn );
				 sqlsrv_close( $conn);	
				
				 
				 $json_All['WorkClass'] = $WorkClass;
				 		 
				
				returnData($json_All);		
			} else {
				 sqlsrv_rollback( $conn );
				 $error_message = "Transaction rolled back.<br />";
				 returnError($error_message);
			}
    break;
	case 'wrk_group':
	
	//wrk_group
		$sql="	SELECT 	wrk_grp_grp_cd,wrk_grp_desc 
				from 	wrk_grp (NOLOCK) 
				where 	site_cd = '".$site_cd."'";
				
		$stmt_wrk_group = sqlsrv_query( $conn, $sql);

		if ($stmt_wrk_group === false)
		{
			if (($errors = sqlsrv_errors()) != null)
			{
				foreach ($errors as $error)
				{

					file_put_contents($file_name, $now . "\r\n" . $sql . "\r\n" . "SQLSTATE: " . $error['SQLSTATE'] . "\r\n" . "code: " . $error['code'] . "\r\n" . "message: " . $error['message'] . "\r\n\r\n", FILE_APPEND);
				}
			}
			sqlsrv_rollback($conn);
			sqlsrv_close($conn);

			$error_message = "(".$now.") Error selecting (wrk_grp)";
			returnError($error_message);
		}
		$wrk_group = array();

		do {
			 while ($row = sqlsrv_fetch_array($stmt_wrk_group, SQLSRV_FETCH_ASSOC)) {		
				$wrk_group[] = $row;	
			
			 }
		} while ( sqlsrv_next_result($stmt_wrk_group) );
        if( $stmt_wrk_group) {
				 sqlsrv_commit( $conn );
				 sqlsrv_close( $conn);	
				
				 
				 $json_All['wrk_group'] = $wrk_group;
				 	 
				
				returnData($json_All);		
			} else {
				 sqlsrv_rollback( $conn );
				 $error_message = "Transaction rolled back.<br />";
				 returnError($error_message);
			}
    break;
	case 'WorkorderStatus':
	
		$where_wrk_sts_change = get_usg_wrk_change($site_cd,$EmpID,'wrk_sts_status');

			//Workorder Status
			$sql= "	SELECT 	wrk_sts.wrk_sts_status,  wrk_sts.wrk_sts_typ_cd,wrk_sts.wrk_sts_desc,  wrk_sts.wrk_sts_email_flag ,wrk_sts.wrk_sts_tim_crd,wrk_sts.wrk_sts_cm_ack_req,wrk_sts.wrk_sts_pm_ack_req
					FROM 	wrk_sts  (NOLOCK)
					WHERE  (wrk_sts.wrk_sts_disable_flag = 0  ) 
					AND 	wrk_sts.site_cd = '".$site_cd."'".$where_wrk_sts_change;
				
		$stmt_WorkorderStatus = sqlsrv_query( $conn, $sql);

		if ($stmt_WorkorderStatus === false)
		{
			if (($errors = sqlsrv_errors()) != null)
			{
				foreach ($errors as $error)
				{

					file_put_contents($file_name, $now . "\r\n" . $sql . "\r\n" . "SQLSTATE: " . $error['SQLSTATE'] . "\r\n" . "code: " . $error['code'] . "\r\n" . "message: " . $error['message'] . "\r\n\r\n", FILE_APPEND);
				}
			}
			sqlsrv_rollback($conn);
			sqlsrv_close($conn);

			$error_message = "(".$now.") Error selecting (wrk_sts)";
			returnError($error_message);
		}

		$WorkorderStatus = array();

		do {
			 while ($row = sqlsrv_fetch_array($stmt_WorkorderStatus, SQLSRV_FETCH_ASSOC)) {		
				$WorkorderStatus[] = $row;	
			
			 }
		} while ( sqlsrv_next_result($stmt_WorkorderStatus) );
        if( $stmt_WorkorderStatus) {
				 sqlsrv_commit( $conn );
				 sqlsrv_close( $conn);	
				
				
				 $json_All['WorkorderStatus'] = $WorkorderStatus;
					 
				
				returnData($json_All);		
			} else {
				 sqlsrv_rollback( $conn );
				 $error_message = "Transaction rolled back.<br />";
				 returnError($error_message);
			}
    break;
	case 'WorkType':
	
		//WorkType
		$sql= "	SELECT  wrk_typ.wrk_typ_typ_cd ,
						wrk_typ.wrk_typ_desc, 
						wrk_typ_option,  
						wrk_typ_pm_option  
				FROM 	wrk_typ  (NOLOCK)     
				WHERE 	wrk_typ.site_cd = '".$site_cd."' 
				AND 	wrk_typ.wrk_typ_disable_flag ='0'ORDER BY wrk_typ_typ_cd ASC";
				
		$stmt_WorkType = sqlsrv_query( $conn, $sql);

		if ($stmt_WorkType === false)
		{
			if (($errors = sqlsrv_errors()) != null)
			{
				foreach ($errors as $error)
				{

					file_put_contents($file_name, $now . "\r\n" . $sql . "\r\n" . "SQLSTATE: " . $error['SQLSTATE'] . "\r\n" . "code: " . $error['code'] . "\r\n" . "message: " . $error['message'] . "\r\n\r\n", FILE_APPEND);
				}
			}
			sqlsrv_rollback($conn);
			sqlsrv_close($conn);

			$error_message = "(".$now.") Error selecting (wrk_typ)";
			returnError($error_message);
		}

		$WorkType = array();

		do {
			 while ($row = sqlsrv_fetch_array($stmt_WorkType, SQLSRV_FETCH_ASSOC)) {		
				$WorkType[] = $row;	
			
			 }
		} while ( sqlsrv_next_result($stmt_WorkType) );
        if( $stmt_WorkType) {
				 sqlsrv_commit( $conn );
				 sqlsrv_close( $conn);	
				
				
				 $json_All['WorkType'] = $WorkType;
				 	 
				
				returnData($json_All);		
			} else {
				 sqlsrv_rollback( $conn );
				 $error_message = "Transaction rolled back.<br />";
				 returnError($error_message);
			}
    break;
	case 'Assetcode':
	
		//AssetCode
		$sql= "	SELECT 	ast_cod.ast_cod_ast_cd, ast_cod.ast_cod_desc        
				FROM 	ast_cod  (NOLOCK)      
				WHERE (	ast_cod.ast_cod_disable_flag = 0  ) 
				AND 	ast_cod.site_cd = '".$site_cd."'ORDER BY ast_cod_ast_cd";


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

		if ($stmt_AssetCode === false)
		{
			if (($errors = sqlsrv_errors()) != null)
			{
				foreach ($errors as $error)
				{

					file_put_contents($file_name, $now . "\r\n" . $sql . "\r\n" . "SQLSTATE: " . $error['SQLSTATE'] . "\r\n" . "code: " . $error['code'] . "\r\n" . "message: " . $error['message'] . "\r\n\r\n", FILE_APPEND);
				}
			}
			sqlsrv_rollback($conn);
			sqlsrv_close($conn);

			$error_message = "(".$now.") Error selecting (ast_cod)";
			returnError($error_message);
		}

		$Assetcode = array();

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

        if( $stmt_AssetCode) {
				 sqlsrv_commit( $conn );
				 sqlsrv_close( $conn);	
				
				 
				 $json_All['Assetcode'] = $Assetcode;
				 	 
				
				returnData($json_All);		
			} else {
				 sqlsrv_rollback( $conn );
				 $error_message = "Transaction rolled back.<br />";
				 returnError($error_message);
			}
    break;
	case 'CriticalFactor':
	
			//CriticalFactor
		$sql= "SELECT 	ast_cri.ast_cri_cri_factor,ast_cri.ast_cri_desc    
				FROM 	ast_cri  (NOLOCK)
				WHERE (	ast_cri.ast_cri_disable_flag = 0  ) 
				AND ast_cri.site_cd = '".$site_cd."'ORDER BY ast_cri_cri_factor";


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

		if ($stmt_CriticalFactor === false)
		{
			if (($errors = sqlsrv_errors()) != null)
			{
				foreach ($errors as $error)
				{

					file_put_contents($file_name, $now . "\r\n" . $sql . "\r\n" . "SQLSTATE: " . $error['SQLSTATE'] . "\r\n" . "code: " . $error['code'] . "\r\n" . "message: " . $error['message'] . "\r\n\r\n", FILE_APPEND);
				}
			}
			sqlsrv_rollback($conn);
			sqlsrv_close($conn);

			$error_message = "(".$now.") Error selecting (ast_cri)";
			returnError($error_message);
		}

		$CriticalFactor = array();

		do {
			 while ($row = sqlsrv_fetch_array($stmt_CriticalFactor, SQLSRV_FETCH_ASSOC)) {		
				$CriticalFactor[] = $row;	
			 }
		} while ( sqlsrv_next_result($stmt_CriticalFactor) );
       if( $stmt_CriticalFactor ) {
				 sqlsrv_commit( $conn );
				 sqlsrv_close( $conn);	
				
				 
				 $json_All['CriticalFactor'] = $CriticalFactor;
				 	 
				
				returnData($json_All);		
			} else {
				 sqlsrv_rollback( $conn );
				 $error_message = "Transaction rolled back.<br />";
				 returnError($error_message);
			}
    break;
	case 'AssetGroupCode':
	
		//AssetGroupCode
		$sql= "SELECT 	ast_grp.ast_grp_grp_cd, ast_grp.ast_grp_desc ,ast_grp_option
				FROM 	ast_grp  (NOLOCK)
				WHERE (	ast_grp.ast_grp_disable_flag =0  ) 
				AND ast_grp.site_cd = '".$site_cd."'ORDER BY ast_grp_grp_cd";


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

		if ($stmt_ast_grp === false)
		{
			if (($errors = sqlsrv_errors()) != null)
			{
				foreach ($errors as $error)
				{

					file_put_contents($file_name, $now . "\r\n" . $sql . "\r\n" . "SQLSTATE: " . $error['SQLSTATE'] . "\r\n" . "code: " . $error['code'] . "\r\n" . "message: " . $error['message'] . "\r\n\r\n", FILE_APPEND);
				}
			}
			sqlsrv_rollback($conn);
			sqlsrv_close($conn);

			$error_message = "(".$now.") Error selecting (ast_grp)";
			returnError($error_message);
		}

		$AssetGroupCode = array();

		do {
			 while ($row = sqlsrv_fetch_array($stmt_ast_grp, SQLSRV_FETCH_ASSOC)) {		
				$AssetGroupCode[] = $row;	
			
			 }
		} while ( sqlsrv_next_result($stmt_ast_grp) );
        if( $stmt_ast_grp ) {
				 sqlsrv_commit( $conn );
				 sqlsrv_close( $conn);	
				
				 
				 $json_All['AssetGroupCode'] = $AssetGroupCode;
				 	 
				
				returnData($json_All);		
			} else {
				 sqlsrv_rollback( $conn );
				 $error_message = "Transaction rolled back.<br />";
				 returnError($error_message);
			}
    break;
	case 'AssetLevel':
	
		//Level
		$sql= "SELECT 	ast_lvl.ast_lvl_ast_lvl, ast_lvl.ast_lvl_desc    
				FROM 	ast_lvl    (NOLOCK)
				WHERE (	ast_lvl.ast_lvl_disable_flag = 0)
				AND ast_lvl.site_cd = '".$site_cd."'ORDER BY ast_lvl_ast_lvl";


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

		if ($stmt_ast_lvl === false)
		{
			if (($errors = sqlsrv_errors()) != null)
			{
				foreach ($errors as $error)
				{

					file_put_contents($file_name, $now . "\r\n" . $sql . "\r\n" . "SQLSTATE: " . $error['SQLSTATE'] . "\r\n" . "code: " . $error['code'] . "\r\n" . "message: " . $error['message'] . "\r\n\r\n", FILE_APPEND);
				}
			}
			sqlsrv_rollback($conn);
			sqlsrv_close($conn);

			$error_message = "(".$now.") Error selecting (ast_lvl)";
			returnError($error_message);
		}

		$AssetLevel = array();

		do {
			 while ($row = sqlsrv_fetch_array($stmt_ast_lvl, SQLSRV_FETCH_ASSOC)) {		
				$AssetLevel[] = $row;	
			 }
		} while ( sqlsrv_next_result($stmt_ast_lvl) );
        if(  $stmt_ast_lvl) {
				 sqlsrv_commit( $conn );
				 sqlsrv_close( $conn);	
				
				 
				 $json_All['AssetLevel'] = $AssetLevel;
				 	 
				
				returnData($json_All);		
			} else {
				 sqlsrv_rollback( $conn );
				 $error_message = "Transaction rolled back.<br />";
				 returnError($error_message);
			}
    break;
	case 'AssetLocation':
	
		//AssetLocation
		$sql= "SELECT 	ast_loc.ast_loc_ast_loc,ast_loc.ast_loc_desc,ast_loc.ast_loc_wr_option,ast_loc.ast_loc_wo_option, ast_loc.ast_loc_pm_option  
				FROM 	ast_loc     (NOLOCK)
				WHERE (	ast_loc.ast_loc_disable_flag = 0      ) 
				AND ast_loc.site_cd = '".$site_cd."'ORDER BY ast_loc_ast_loc";


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

		if ($stmt_ast_loc === false)
		{
			if (($errors = sqlsrv_errors()) != null)
			{
				foreach ($errors as $error)
				{

					file_put_contents($file_name, $now . "\r\n" . $sql . "\r\n" . "SQLSTATE: " . $error['SQLSTATE'] . "\r\n" . "code: " . $error['code'] . "\r\n" . "message: " . $error['message'] . "\r\n\r\n", FILE_APPEND);
				}
			}
			sqlsrv_rollback($conn);
			sqlsrv_close($conn);

			$error_message = "(".$now.") Error selecting (ast_loc)";
			returnError($error_message);
		}

		$AssetLocation = array();

		do {
			 while ($row = sqlsrv_fetch_array($stmt_ast_loc, SQLSRV_FETCH_ASSOC)) {		
				$AssetLocation[] = $row;	
			 }
		} while ( sqlsrv_next_result($stmt_ast_loc) );
        if( $stmt_ast_loc ) {
				 sqlsrv_commit( $conn );
				 sqlsrv_close( $conn);	
				
				
				 $json_All['AssetLocation'] = $AssetLocation;
				 	 
				
				returnData($json_All);		
			} else {
				 sqlsrv_rollback( $conn );
				 $error_message = "Transaction rolled back.<br />";
				 returnError($error_message);
			}
    break;
	case 'AssetStatus':
		//AssetStatus
		$sql= "SELECT ast_sts_status,ast_sts_desc,ast_sts_typ_cd		
				FROM 	ast_sts (NOLOCK)
				WHERE	ast_sts.site_cd = '".$site_cd."'
				AND		ast_sts.ast_sts_typ_cd IN ( 'IN-SERVICE', 'OUT-OF-SERVICE') ORDER BY ast_sts_status";


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

		if ($stmt_ast_sts === false)
		{
			if (($errors = sqlsrv_errors()) != null)
			{
				foreach ($errors as $error)
				{

					file_put_contents($file_name, $now . "\r\n" . $sql . "\r\n" . "SQLSTATE: " . $error['SQLSTATE'] . "\r\n" . "code: " . $error['code'] . "\r\n" . "message: " . $error['message'] . "\r\n\r\n", FILE_APPEND);
				}
			}
			sqlsrv_rollback($conn);
			sqlsrv_close($conn);

			$error_message = "(".$now.") Error selecting (ast_sts)";
			returnError($error_message);
		}

		$AssetStatus = array();

		do {
			 while ($row = sqlsrv_fetch_array($stmt_ast_sts, SQLSRV_FETCH_ASSOC)) {		
				$AssetStatus[] = $row;	
			
			 }
		} while ( sqlsrv_next_result($stmt_ast_sts) );
        if(  $stmt_ast_sts) {
				 sqlsrv_commit( $conn );
				 sqlsrv_close( $conn);	
				
				 
				 $json_All['AssetStatus'] = $AssetStatus;
				 	 
				
				returnData($json_All);		
			} else {
				 sqlsrv_rollback( $conn );
				 $error_message = "Transaction rolled back.<br />";
				 returnError($error_message);
			}
    break;
	case 'AssetType':
	
		//AssetType
		$sql= "SELECT ast_type.ast_type_cd, ast_type.ast_type_descs 
				FROM ast_type (NOLOCK)
				WHERE (ast_type.ast_type_disable_flag = 0  ) 
				AND ast_type.site_cd = '".$site_cd."'ORDER BY ast_type_cd";


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

		if ($stmt_ast_type === false)
		{
			if (($errors = sqlsrv_errors()) != null)
			{
				foreach ($errors as $error)
				{

					file_put_contents($file_name, $now . "\r\n" . $sql . "\r\n" . "SQLSTATE: " . $error['SQLSTATE'] . "\r\n" . "code: " . $error['code'] . "\r\n" . "message: " . $error['message'] . "\r\n\r\n", FILE_APPEND);
				}
			}
			sqlsrv_rollback($conn);
			sqlsrv_close($conn);

			$error_message = "(".$now.") Error selecting (ast_sts)";
			returnError($error_message);
		}

		$AssetType = array();

		do {
			 while ($row = sqlsrv_fetch_array($stmt_ast_type, SQLSRV_FETCH_ASSOC)) {		
				$AssetType[] = $row;	
			
			 }
		} while ( sqlsrv_next_result($stmt_ast_type) );
		if( $stmt_ast_type) {
				 sqlsrv_commit( $conn );
				 sqlsrv_close( $conn);	
				
				 
				 $json_All['AssetType'] = $AssetType;
				 	 
				
				returnData($json_All);		
			} else {
				 sqlsrv_rollback( $conn );
				 $error_message = "Transaction rolled back.<br />";
				 returnError($error_message);
			}
    break;
	case 'Employee':
	
		//Employee
		$sql= "SELECT Distinct emp_mst.emp_mst_empl_id,     		
				emp_mst_title = COALESCE(emp_mst_title,''), 
				emp_mst.emp_mst_name,emp_mst_emg_phone = COALESCE(emp_mst_emg_phone,''),
				emp_det_craft = COALESCE(emp_det_craft+':'+crf_mst_desc,''),
				emp_ls1_charge_rate = COALESCE(emp_ls1.emp_ls1_charge_rate,0),
				emp_det_supervisor,
				emp_det_foreman				
		From 	emp_mst (NOLOCK)

				LEFT 
				OUTER 
				JOIN	emp_sts (NOLOCK) 
				ON		emp_mst.site_cd = emp_sts.site_cd  
				and     emp_mst.emp_mst_status = emp_sts.emp_sts_status  	
				And		emp_sts.emp_sts_typ_cd = 'ACTIVE'

				LEFT 
				OUTER 
				JOIN	emp_det (NOLOCK) 
				ON		emp_mst.site_cd = emp_det.site_cd		
				And		emp_mst.rowid = emp_det.mst_rowid
				
				LEFT 
				OUTER 
				JOIN	emp_ls1 (NOLOCK) 
				ON		emp_det.mst_rowid = emp_ls1.mst_rowid	
				And		emp_det.site_cd = emp_ls1.site_cd	
				AND		emp_det.emp_det_craft = emp_ls1.emp_ls1_craft
				
				LEFT 
				OUTER 
				JOIN	crf_mst (NOLOCK) 
				ON		emp_det.site_cd = crf_mst.site_cd		
				AND		emp_det.emp_det_craft = crf_mst.crf_mst_crf_cd	
				
				LEFT OUTER JOIN emp_ls5 (NOLOCK) 
				ON emp_mst.site_cd = emp_ls5.site_cd 
				AND emp_mst.RowID = emp_ls5.mst_RowID
				
				
		WHERE	emp_mst.site_cd = '".$site_cd."' 
		AND 	emp_det.emp_det_foreman = '1'
		And 	emp_sts.emp_sts_typ_cd = 'ACTIVE' ".$where_work_group." ORDER BY emp_mst.emp_mst_empl_id ASC";


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


		if ($stmt_emp_mst === false)
		{
			if (($errors = sqlsrv_errors()) != null)
			{
				foreach ($errors as $error)
				{

					file_put_contents($file_name, $now . "\r\n" . $sql . "\r\n" . "SQLSTATE: " . $error['SQLSTATE'] . "\r\n" . "code: " . $error['code'] . "\r\n" . "message: " . $error['message'] . "\r\n\r\n", FILE_APPEND);
				}
			}
			sqlsrv_rollback($conn);
			sqlsrv_close($conn);

			$error_message = "(".$now.") Error selecting (ast_sts)";
			returnError($error_message);
		}

		$Employee = array();

		do {
			 while ($row = sqlsrv_fetch_array($stmt_emp_mst, SQLSRV_FETCH_ASSOC)) {
				$row['emp_mst_name'] =  mb_convert_encoding($row['emp_mst_name'], 'UTF-8', 'ISO-8859-7');
				$Employee[] = $row;	
			
			 }
		} while ( sqlsrv_next_result($stmt_emp_mst) );
        if( $stmt_emp_mst ) {
				 sqlsrv_commit( $conn );
				 sqlsrv_close( $conn);	
				
				 
				 $json_All['Employee'] = $Employee;
				 		 
				
				returnData($json_All);		
			} else {
				 sqlsrv_rollback( $conn );
				 $error_message = "Transaction rolled back.<br />";
				 returnError($error_message);
			}
    break;
	case 'Assign_Employee':
	
		//Assign_Employee
		$sql= "SELECT  Distinct emp_mst.emp_mst_empl_id,     		
				emp_mst_title = COALESCE(emp_mst_title,''), 
				emp_mst_att_sts = COALESCE(emp_mst_att_sts,''), 
				emp_mst.emp_mst_name,emp_mst_emg_phone = COALESCE(emp_mst_emg_phone,''),
				emp_det_craft = COALESCE(emp_det_craft+':'+crf_mst_desc,''),
				emp_ls1_charge_rate = COALESCE(emp_ls1.emp_ls1_charge_rate,0),
				
				WOASSIGN = (SELECT count(*) FROM wko_mst (NOLOCK), wko_det (NOLOCK), wrk_sts (NOLOCK)
				WHERE	wko_mst.site_cd = wko_det.site_cd
				AND		wko_mst.rowid = wko_det.mst_rowid
				AND		wko_mst.site_cd = wrk_sts.site_cd
				AND		wko_mst.wko_mst_status = wrk_sts.wrk_sts_status
				ANd		wko_det.site_cd = emp_mst.site_cd
				AND		wko_det.wko_det_assign_to = emp_mst.emp_mst_empl_id
				AND		wrk_sts.wrk_sts_typ_cd ='OPEN')					
		From 	emp_mst (NOLOCK)

				LEFT 
				OUTER 
				JOIN	emp_sts (NOLOCK) 
				ON		emp_mst.site_cd = emp_sts.site_cd  
				and     emp_mst.emp_mst_status = emp_sts.emp_sts_status  	
				And		emp_sts.emp_sts_typ_cd = 'ACTIVE'

				LEFT 
				OUTER 
				JOIN	emp_det (NOLOCK) 
				ON		emp_mst.site_cd = emp_det.site_cd		
				And		emp_mst.rowid = emp_det.mst_rowid
				
				LEFT 
				OUTER 
				JOIN	emp_ls1 (NOLOCK) 
				ON		emp_det.mst_rowid = emp_ls1.mst_rowid	
				And		emp_det.site_cd = emp_ls1.site_cd	
				AND		emp_det.emp_det_craft = emp_ls1.emp_ls1_craft
				
				LEFT 
				OUTER 
				JOIN	crf_mst (NOLOCK) 
				ON		emp_det.site_cd = crf_mst.site_cd		
				AND		emp_det.emp_det_craft = crf_mst.crf_mst_crf_cd	
				
				LEFT 
				OUTER
				JOIN 	emp_ls5 (NOLOCK) 
				ON 		emp_mst.site_cd = emp_ls5.site_cd 
				AND 	emp_mst.RowID = emp_ls5.mst_RowID
				
				
				
		WHERE	emp_mst.site_cd = '".$site_cd."' 
		AND 	emp_det.emp_det_foreman = '1' 
		And 	emp_sts.emp_sts_typ_cd = 'ACTIVE' ".$where_work_group." ORDER BY emp_mst.emp_mst_empl_id ASC";


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


		if ($stmt_assign_emp_mst === false)
		{
			if (($errors = sqlsrv_errors()) != null)
			{
				foreach ($errors as $error)
				{

					file_put_contents($file_name, $now . "\r\n" . $sql . "\r\n" . "SQLSTATE: " . $error['SQLSTATE'] . "\r\n" . "code: " . $error['code'] . "\r\n" . "message: " . $error['message'] . "\r\n\r\n", FILE_APPEND);
				}
			}
			sqlsrv_rollback($conn);
			sqlsrv_close($conn);

			$error_message = "(".$now.") Error selecting (ast_sts)";
			returnError($error_message);
		}

		$Assing_Employee = array();

		do {
			 while ($row = sqlsrv_fetch_array($stmt_assign_emp_mst, SQLSRV_FETCH_ASSOC)) {
				$row['emp_mst_name'] =  mb_convert_encoding($row['emp_mst_name'], 'UTF-8', 'ISO-8859-7');
				$Assing_Employee[] = $row;	
			
			 }
		} while ( sqlsrv_next_result($stmt_assign_emp_mst) );
        if( $stmt_assign_emp_mst ) {
				 sqlsrv_commit( $conn );
				 sqlsrv_close( $conn);	
				
				 
				 $json_All['Assign_Employee'] = $Assing_Employee;
				 		 
				
				returnData($json_All);		
			} else {
				 sqlsrv_rollback( $conn );
				 $error_message = "Transaction rolled back.<br />";
				 returnError($error_message);
			}
    break;
	case 'Auto_Numnering':
	
			//Asset_Auto_Numnering
		$sql="	SELECT 	cnt_mst_numbering , 
						cnt_mst_option ,
						cnt_mst_module_cd 
				FROM 	cnt_mst  (NOLOCK)
				WHERE  	cnt_mst.site_cd ='".$site_cd."'
				AND 	cnt_mst_module_cd =  'AST'";

		$stmt_cnt_mst = sqlsrv_query( $conn, $sql);
		 
		 
		if ($stmt_cnt_mst === false)
		{
			if (($errors = sqlsrv_errors()) != null)
			{
				foreach ($errors as $error)
				{

					file_put_contents($file_name, $now . "\r\n" . $sql . "\r\n" . "SQLSTATE: " . $error['SQLSTATE'] . "\r\n" . "code: " . $error['code'] . "\r\n" . "message: " . $error['message'] . "\r\n\r\n", FILE_APPEND);
				}
			}
			sqlsrv_rollback($conn);
			sqlsrv_close($conn);

			$error_message = "(".$now.") Error selecting (ast_sts)";
			returnError($error_message);
		}
		$Auto_Numnering = array();

		do {
			 while ($row = sqlsrv_fetch_array($stmt_cnt_mst, SQLSRV_FETCH_ASSOC)) {		
				$Auto_Numnering[] = $row;	
			
			 }
		} while ( sqlsrv_next_result($stmt_cnt_mst) );
        if(  $stmt_cnt_mst) {
				 sqlsrv_commit( $conn );
				 sqlsrv_close( $conn);	
				
				
				 $json_All['Auto_Numnering'] = $Auto_Numnering;
				 		 
				
				returnData($json_All);		
			} else {
				 sqlsrv_rollback( $conn );
				 $error_message = "Transaction rolled back.<br />";
				 returnError($error_message);
			}
    break;
	case 'Wko_Auto_numbering':
	
			//WorkOrder_Auto_Numnering
		$sql= "	Select 	cnt_mst_numbering ,
						cnt_mst_option ,
						cnt_mst_module_cd 
				From 	cnt_mst (NOLOCK) 
				Where 	site_cd ='".$site_cd."' 
				And cnt_mst_module_cd ='WKO'";

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

		if ($stmt_wko_cnt_mst === false)
		{
			if (($errors = sqlsrv_errors()) != null)
			{
				foreach ($errors as $error)
				{

					file_put_contents($file_name, $now . "\r\n" . $sql . "\r\n" . "SQLSTATE: " . $error['SQLSTATE'] . "\r\n" . "code: " . $error['code'] . "\r\n" . "message: " . $error['message'] . "\r\n\r\n", FILE_APPEND);
				}
			}
			sqlsrv_rollback($conn);
			sqlsrv_close($conn);

			$error_message = "(".$now.") Error selecting (ast_sts)";
			returnError($error_message);
		}

		$Wko_Auto_numbering = array();

		do {
			 while ($row = sqlsrv_fetch_array($stmt_wko_cnt_mst, SQLSRV_FETCH_ASSOC)) {		
				$Wko_Auto_numbering[] = $row;	
			
			 }
		} while ( sqlsrv_next_result($stmt_wko_cnt_mst) );
        if(  $stmt_wko_cnt_mst ) {
				 sqlsrv_commit( $conn );
				 sqlsrv_close( $conn);	
				
				 
				 $json_All['Wko_Auto_numbering'] = $Wko_Auto_numbering;
				 		 
				
				returnData($json_All);		
			} else {
				 sqlsrv_rollback( $conn );
				 $error_message = "Transaction rolled back.<br />";
				 returnError($error_message);
			}
    break;
	case 'RatingQuestion':
	
	//RatingQuestion
			$sql="WITH LabelData AS (SELECT * FROM cf_label WHERE table_name = 'wko_det' AND language_cd = 'DEFAULT' AND column_name IN ('wko_det_rating1','wko_det_rating2','wko_det_rating3')),
NumberedLabels AS (SELECT ROW_NUMBER() OVER (ORDER BY CASE column_name WHEN 'wko_det_rating1' THEN 1 WHEN 'wko_det_rating2' THEN 2 WHEN 'wko_det_rating3' THEN 3 END ) AS column_no, * FROM LabelData )
SELECT * FROM NumberedLabels";	
				
	//echo $sql;
	//$params = array($site_cd,$mst_RowID);					
						
		$stmt_RatingQuestion = sqlsrv_query( $conn, $sql);

			if ($stmt_RatingQuestion === false)
			{
				if (($errors = sqlsrv_errors()) != null)
				{
					foreach ($errors as $error)
					{

						file_put_contents($file_name, $now . "\r\n" . $sql . "\r\n" . "SQLSTATE: " . $error['SQLSTATE'] . "\r\n" . "code: " . $error['code'] . "\r\n" . "message: " . $error['message'] . "\r\n\r\n", FILE_APPEND);
					}
				}
				sqlsrv_rollback($conn);
				sqlsrv_close($conn);

				$error_message = "(".$now.") Error selecting (ast_sts)";
				returnError($error_message);
			}

			$RatingQuestion= array();

			do {
				 while ($row = sqlsrv_fetch_array($stmt_RatingQuestion, SQLSRV_FETCH_ASSOC)) {	
				 
					$RatingQuestion[] = $row;		
				
				 }
			} while ( sqlsrv_next_result($stmt_RatingQuestion) );
        if( $stmt_RatingQuestion ) {
				 sqlsrv_commit( $conn );
				 sqlsrv_close( $conn);	
				
				 
				 $json_All['RatingQuestion'] = $RatingQuestion;
				 		 
				
				returnData($json_All);		
			} else {
				 sqlsrv_rollback( $conn );
				 $error_message = "Transaction rolled back.<br />";
				 returnError($error_message);
			}
    break;
	case 'MRStockno':
	
		//MRStockno			
		$sql="SELECT	DISTINCT

			itm_mst.itm_mst_stockno,
			itm_mst.itm_mst_costcenter,
			itm_mst.itm_mst_account,
			itm_mst.itm_mst_mstr_locn,			
			itm_mst_desc = COALESCE(cast(itm_mst.itm_mst_desc as varchar (255)),''),	
			itm_mst.itm_mst_issue_uom,			
			itm_mst.itm_mst_issue_price,
			itm_mst.itm_mst_ttl_oh,
			itm_mst_ext_desc = COALESCE(cast(itm_mst.itm_mst_ext_desc as varchar (255)),''),	
			itm_det.itm_det_part_deac_status,
			itm_det.itm_det_order_pt,	
			itm_mst_partno = COALESCE(itm_mst_partno,''),			
			itm_det_ttl_oh= COALESCE(itm_det_ttl_oh,0),
			
			category = CASE
			WHEN		((itm_loc_oh_qty - itm_loc_hard_resrv - itm_loc_short_qty + itm_loc_pr_due_in + itm_loc_due_in) < itm_loc_order_pt )
			AND         ((itm_loc_oh_qty - itm_loc_hard_resrv - itm_loc_short_qty + itm_loc_pr_due_in + itm_loc_due_in) < itm_loc_maximum )
			AND         ( itm_det_maximum  > 0 )
			AND         ( itm_det_order_pt  > 0 )
			AND         ( itm_mst_order_rule = 'L' ) THEN 'BELOW'

			WHEN		((itm_mst_ttl_oh - itm_det_ttl_hard_resrv - itm_det_ttl_short + itm_det_pr_due_in + itm_det_due_in) < itm_det_order_pt )
			AND         ((itm_mst_ttl_oh - itm_det_ttl_hard_resrv - itm_det_ttl_short + itm_det_pr_due_in + itm_det_due_in) < itm_det_maximum )
			AND         ( itm_det_maximum  > 0 )
			AND         ( itm_det_order_pt  > 0 )
			AND         ( itm_mst_order_rule = 'T' ) THEN 'BELOW'

			ELSE 'NORMAL' END,			
			
			itm_mst.RowID
			
			FROM		itm_mst (NOLOCK)

			INNER JOIN	itm_det (NOLOCK)            
			ON          itm_mst.site_cd = itm_det.site_cd
			AND         itm_mst.RowID = itm_det.mst_RowID

			INNER JOIN  itm_sts (NOLOCK)
			ON          itm_det.site_cd = itm_sts.site_cd 
			AND         itm_det.itm_det_part_deac_status = itm_sts.itm_sts_status

			INNER JOIN	itm_loc (NOLOCK)
			ON			itm_mst.site_cd = itm_loc.site_cd
			AND			itm_mst.RowID = itm_loc.mst_RowID

			WHERE		itm_mst.site_cd = '".$_REQUEST['site_cd']."'
			AND			itm_sts_typ_cd = 'ACTIVE'

			ORDER BY	itm_mst.itm_mst_stockno" ;
						
		$stmt_MRStockno = sqlsrv_query( $conn, $sql);

		if ($stmt_MRStockno === false)
		{
			if (($errors = sqlsrv_errors()) != null)
			{
				foreach ($errors as $error)
				{

					file_put_contents($file_name, $now . "\r\n" . $sql . "\r\n" . "SQLSTATE: " . $error['SQLSTATE'] . "\r\n" . "code: " . $error['code'] . "\r\n" . "message: " . $error['message'] . "\r\n\r\n", FILE_APPEND);
				}
			}
			sqlsrv_rollback($conn);
			sqlsrv_close($conn);

			$error_message = "(".$now.") Error selecting (ast_sts)";
			returnError($error_message);
		}

		$json = array();

		do {
			 while ($row = sqlsrv_fetch_array($stmt_MRStockno, SQLSRV_FETCH_ASSOC)) {		
				$MRStockno[] = $row;	
			
			 }
		} while ( sqlsrv_next_result($stmt_MRStockno) );
        if( $stmt_MRStockno ) {
				 sqlsrv_commit( $conn );
				 sqlsrv_close( $conn);	
				
				 
				 $json_All['MRStockno'] = $MRStockno;
				
				returnData($json_All);		
			} else {
				 sqlsrv_rollback( $conn );
				 $error_message = "Transaction rolled back.<br />";
				 returnError($error_message);
			}
    break;
	case 'HoursType':
	
		//Time card houres
		$sql="SELECT hours_type_cd = hours_type_cd+' : '+ hours_type_desc,  hours_type.hours_type_multiplier, hours_type.hours_type_adder    FROM hours_type (NOLOCK)   
				WHERE hours_type.site_cd = ?";			
		
		$params = array($site_cd);		
		$stmt_hours_type = sqlsrv_query( $conn, $sql,$params);

		if ($stmt_hours_type === false)
		{
			if (($errors = sqlsrv_errors()) != null)
			{
				foreach ($errors as $error)
				{

					file_put_contents($file_name, $now . "\r\n" . $sql . "\r\n" . "SQLSTATE: " . $error['SQLSTATE'] . "\r\n" . "code: " . $error['code'] . "\r\n" . "message: " . $error['message'] . "\r\n\r\n", FILE_APPEND);
				}
			}
			sqlsrv_rollback($conn);
			sqlsrv_close($conn);

			$error_message = "(".$now.") Error selecting (ast_sts)";
			returnError($error_message);
		}
		$HoursType= array();

		do {
			while ($row = sqlsrv_fetch_array($stmt_hours_type, SQLSRV_FETCH_ASSOC)) {	
					 
			$HoursType[] = $row;		
					
			}
		}
		while ( sqlsrv_next_result($stmt_hours_type) );																					
        if( $stmt_hours_type ) {
				 sqlsrv_commit( $conn );
				 sqlsrv_close( $conn);	
				
				
				 $json_All['HoursType'] = $HoursType;
				 	 
				
				returnData($json_All);		
			} else {
				 sqlsrv_rollback( $conn );
				 $error_message = "Transaction rolled back.<br />";
				 returnError($error_message);
			}
    break;
	case 'TimeCraft':
	
		//Time craft
		$sql="	SELECT 	emp_ls1_craft = emp_ls1_craft+' : '+crf_mst_desc, emp_ls1.emp_ls1_charge_rate,emp_mst.emp_mst_empl_id       
				FROM 	crf_mst (NOLOCK) , 	emp_ls1(NOLOCK),  	emp_mst(NOLOCK)  
				WHERE 	(crf_mst.site_cd = emp_ls1.site_cd  
				AND		crf_mst.crf_mst_crf_cd = emp_ls1.emp_ls1_craft  
				AND		crf_mst.site_cd = emp_mst.site_cd  
				AND		emp_ls1.mst_rowid = emp_mst.rowid) 
				AND 	emp_mst.site_cd = ?";	
				
		//echo $sql;
		$params = array($site_cd);					
							
		$stmt_crf_mst = sqlsrv_query( $conn, $sql,$params);

		if ($stmt_crf_mst === false)
		{
			if (($errors = sqlsrv_errors()) != null)
			{
				foreach ($errors as $error)
				{

					file_put_contents($file_name, $now . "\r\n" . $sql . "\r\n" . "SQLSTATE: " . $error['SQLSTATE'] . "\r\n" . "code: " . $error['code'] . "\r\n" . "message: " . $error['message'] . "\r\n\r\n", FILE_APPEND);
				}
			}
			sqlsrv_rollback($conn);
			sqlsrv_close($conn);

			$error_message = "(".$now.") Error selecting (ast_sts)";
			returnError($error_message);
		}

		$TimeCraft= array();

		do {
			 while ($row = sqlsrv_fetch_array($stmt_crf_mst, SQLSRV_FETCH_ASSOC)) {	
			 
				$TimeCraft[] = $row;		
			
			 }
		} while ( sqlsrv_next_result($stmt_crf_mst) );
		if( $stmt_crf_mst) {
			sqlsrv_commit( $conn );
			sqlsrv_close( $conn);	
			
			$json_All['TimeCraft'] = $TimeCraft;
			returnData($json_All);		
		} else {
			sqlsrv_rollback( $conn );
			$error_message = "Transaction rolled back.<br />";
			returnError($error_message);
		}
    break;
	case 'supplier':
	
		//supplier			
		$sql= "SELECT 	sup_mst.sup_mst_supplier_cd,   
						sup_mst.sup_mst_desc,  
						sup_mst.sup_mst_status  
				FROM 	sup_mst (NOLOCK), sup_sts (NOLOCK)
				WHERE (sup_mst.site_cd = sup_sts.site_cd  
				AND			sup_mst.sup_mst_status = sup_sts.sup_sts_status  
				AND			sup_sts.sup_sts_typ_cd NOT IN ('DEACTIVATE')) 
				AND sup_mst.site_cd = '".$site_cd."' ORDER BY sup_mst_supplier_cd ASC";
		$stmt_supplier = sqlsrv_query( $conn, $sql);

		if ($stmt_supplier === false)
		{
			if (($errors = sqlsrv_errors()) != null)
			{
				foreach ($errors as $error)
				{

					file_put_contents($file_name, $now . "\r\n" . $sql . "\r\n" . "SQLSTATE: " . $error['SQLSTATE'] . "\r\n" . "code: " . $error['code'] . "\r\n" . "message: " . $error['message'] . "\r\n\r\n", FILE_APPEND);
				}
			}
			sqlsrv_rollback($conn);
			sqlsrv_close($conn);

			$error_message = "(".$now.") Error selecting (ast_sts)";
			returnError($error_message);
		}

		$supplier = array();

		do {
			 while ($row = sqlsrv_fetch_array($stmt_supplier, SQLSRV_FETCH_ASSOC)) {		
				$supplier []= $row;	
			
			 }
		} while ( sqlsrv_next_result($stmt_supplier) );
		if( $stmt_supplier ) {
				 sqlsrv_commit( $conn );
				 sqlsrv_close( $conn);
				 $json_All['supplier'] = $supplier;
				 returnData($json_All);		
			} else {
				 sqlsrv_rollback( $conn );
				 $error_message = "Transaction rolled back.<br />";
				 returnError($error_message);
			}				
    break;
	case 'uom':
	
		//UOM
		$sql= "SELECT 	uom_mst.uom_mst_uom,  uom_mst.uom_mst_desc ,uom_mst_type FROM uom_mst(NOLOCK)  
				WHERE 	uom_mst.site_cd = '".$site_cd."' 
				AND 	uom_mst_type IN ('SERVICE','MATERIAL') 
				AND 	uom_mst_disable_flag = '0' ORDER BY uom_mst_uom ASC ";
		$stmt_uom = sqlsrv_query( $conn, $sql);

		if ($stmt_uom === false)
		{
			if (($errors = sqlsrv_errors()) != null)
			{
				foreach ($errors as $error)
				{

					file_put_contents($file_name, $now . "\r\n" . $sql . "\r\n" . "SQLSTATE: " . $error['SQLSTATE'] . "\r\n" . "code: " . $error['code'] . "\r\n" . "message: " . $error['message'] . "\r\n\r\n", FILE_APPEND);
				}
			}
			sqlsrv_rollback($conn);
			sqlsrv_close($conn);

			$error_message = "(".$now.") Error selecting (ast_sts)";
			returnError($error_message);
		}


		$uom = array();

		do {
			 while ($row = sqlsrv_fetch_array($stmt_uom, SQLSRV_FETCH_ASSOC)) {		
				$uom[] = $row;	
			
			 }
		} while ( sqlsrv_next_result($stmt_uom) );
		if( $stmt_uom ) {
			
				 sqlsrv_commit( $conn );
				 sqlsrv_close( $conn);
				 $json_All['uom'] = $uom;
				 returnData($json_All);	
				 
			} else {
				 sqlsrv_rollback( $conn );
				 $error_message = "Transaction rolled back.<br />";
				 returnError($error_message);
			}
			
    break;		
	case 'tax_cd':
	
		//Tax code
		$sql= "	SELECT 	tax_mst.tax_mst_tax_cd, 
						tax_mst.tax_mst_desc, 
						tax_mst.tax_mst_tax_rate  
				FROM 	tax_mst (NOLOCK)    
				WHERE (	tax_mst.tax_mst_disable_flag = '0') 
				AND tax_mst.site_cd = '".$site_cd."' 
				AND tax_mst_type IN ('A', 'P') 
				AND tax_mst_disable_flag = '0' ORDER BY tax_mst_tax_cd ASC";
		$stmt_tax_cd = sqlsrv_query( $conn, $sql);

		if ($stmt_tax_cd === false)
		{
			if (($errors = sqlsrv_errors()) != null)
			{
				foreach ($errors as $error)
				{

					file_put_contents($file_name, $now . "\r\n" . $sql . "\r\n" . "SQLSTATE: " . $error['SQLSTATE'] . "\r\n" . "code: " . $error['code'] . "\r\n" . "message: " . $error['message'] . "\r\n\r\n", FILE_APPEND);
				}
			}
			sqlsrv_rollback($conn);
			sqlsrv_close($conn);

			$error_message = "(".$now.") Error selecting (ast_sts)";
			returnError($error_message);
		}

		$tax_cd = array();

		do {
			 while ($row = sqlsrv_fetch_array($stmt_tax_cd, SQLSRV_FETCH_ASSOC)) {		
				$tax_cd[] = $row;	
			
			 }
		} while ( sqlsrv_next_result($stmt_tax_cd) );
			
		if($stmt_tax_cd) {
				 sqlsrv_commit( $conn );
				 sqlsrv_close( $conn);	
				 
				 $json_All['tax_cd'] = $tax_cd;
				 returnData($json_All);	
				 
			} else {
				
				 sqlsrv_rollback( $conn );
				 $error_message = "Transaction rolled back.<br />";
				 returnError($error_message);
			}
				
	break;	
	case	'emp_ls5':

			//emp_ls5
			$sql= "	select  emp_ls5_work_group =COALESCE(emp_ls5_work_group +' : '+wrk_grp_desc,'') 

					from emp_ls5(NOLOCK)

					LEFT 
					OUTER 
					JOIN	wrk_grp (NOLOCK) 
					ON		emp_ls5.site_cd = wrk_grp.site_cd		
					And		emp_ls5.emp_ls5_work_group = wrk_grp.wrk_grp_grp_cd

					LEFT 
					OUTER 
					JOIN	emp_mst (NOLOCK) 
					ON		emp_mst.site_cd = emp_ls5.site_cd		
					And		emp_mst.rowid = emp_ls5.mst_rowid

			Where 			emp_mst.site_cd = '".$site_cd."'
					And		emp_mst.emp_mst_empl_id = '".$EmpID."'";
					
			$stmt_emp_ls5 = sqlsrv_query( $conn, $sql);

			if ($stmt_emp_ls5 === false)
			{
				if (($errors = sqlsrv_errors()) != null)
				{
					foreach ($errors as $error)
					{

						file_put_contents($file_name, $now . "\r\n" . $sql . "\r\n" . "SQLSTATE: " . $error['SQLSTATE'] . "\r\n" . "code: " . $error['code'] . "\r\n" . "message: " . $error['message'] . "\r\n\r\n", FILE_APPEND);
					}
				}
				sqlsrv_rollback($conn);
				sqlsrv_close($conn);

				$error_message = "(".$now.") Error selecting (ast_sts)";
				returnError($error_message);
			}

			$emp_ls5 = array();

			do {
				 while ($row = sqlsrv_fetch_array($stmt_emp_ls5, SQLSRV_FETCH_ASSOC)) {		
					$emp_ls5[] = $row;	
				
				 }
			} while ( sqlsrv_next_result($stmt_emp_ls5) );	
			
			if($stmt_emp_ls5) {
				 sqlsrv_commit( $conn );
				 sqlsrv_close( $conn);	
				 
				 $json_All['emp_ls5'] = $emp_ls5;
				 returnData($json_All);	
				 
			} else {
				
				 sqlsrv_rollback( $conn );
				 $error_message = "Transaction rolled back.<br />";
				 returnError($error_message);
			}
			
	break;	
	case	'AssetInService':

			//AssetStatus_IN-SERVICE
			$sql= "select ast_sts_status,ast_sts_desc from ast_sts (NOLOCK) where site_cd ='".$site_cd."' and ast_sts_count_dwn_time ='1' and ast_sts_disable_flag ='0' and ast_sts_typ_cd='IN-SERVICE'";


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

			if ($stmt_ast_sts_in_service === false)
			{
				if (($errors = sqlsrv_errors()) != null)
				{
					foreach ($errors as $error)
					{

						file_put_contents($file_name, $now . "\r\n" . $sql . "\r\n" . "SQLSTATE: " . $error['SQLSTATE'] . "\r\n" . "code: " . $error['code'] . "\r\n" . "message: " . $error['message'] . "\r\n\r\n", FILE_APPEND);
					}
				}
				sqlsrv_rollback($conn);
				sqlsrv_close($conn);

				$error_message = "(".$now.") Error selecting (ast_sts)";
				returnError($error_message);
			}

			$AssetStatus_In_service = array();

			do {
				 while ($row = sqlsrv_fetch_array($stmt_ast_sts_in_service, SQLSRV_FETCH_ASSOC)) {		
					$AssetStatus_In_service[] = $row;	
				
				 }
			} while ( sqlsrv_next_result($stmt_ast_sts_in_service) );	
			
			if($stmt_ast_sts_in_service) {
				 sqlsrv_commit( $conn );
				 sqlsrv_close( $conn);	
				 
				 $json_All['AssetInService'] = $AssetStatus_In_service;
				 returnData($json_All);	
				 
			} else {
				
				 sqlsrv_rollback( $conn );
				 $error_message = "Transaction rolled back.<br />";
				 returnError($error_message);
			}
		break;
		case	'AssetOutOfService':

			//AssetStatus_OUT-OF-SERVICE
			$sql= "select ast_sts_status,ast_sts_desc from ast_sts (NOLOCK) where site_cd ='".$site_cd."' and ast_sts_count_dwn_time ='1' and ast_sts_disable_flag ='0'and ast_sts_typ_cd='OUT-OF-SERVICE'";


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

			if ($stmt_ast_sts_out_of_service === false)
			{
				if (($errors = sqlsrv_errors()) != null)
				{
					foreach ($errors as $error)
					{

						file_put_contents($file_name, $now . "\r\n" . $sql . "\r\n" . "SQLSTATE: " . $error['SQLSTATE'] . "\r\n" . "code: " . $error['code'] . "\r\n" . "message: " . $error['message'] . "\r\n\r\n", FILE_APPEND);
					}
				}
				sqlsrv_rollback($conn);
				sqlsrv_close($conn);

				$error_message = "(".$now.") Error selecting (ast_sts)";
				returnError($error_message);
			}


			$AssetStatus_Out_of_service = array();

			do {
				 while ($row = sqlsrv_fetch_array($stmt_ast_sts_out_of_service, SQLSRV_FETCH_ASSOC)) {		
					$AssetStatus_Out_of_service[] = $row;	
				
				 }
			} while ( sqlsrv_next_result($stmt_ast_sts_out_of_service) );	
			
			if($stmt_ast_sts_out_of_service) {
				 sqlsrv_commit( $conn );
				 sqlsrv_close( $conn);	
				 
				 $json_All['AssetOutOfService'] = $AssetStatus_Out_of_service;
				 returnData($json_All);	
				 
			} else {
				
				 sqlsrv_rollback( $conn );
				 $error_message = "Transaction rolled back.<br />";
				 returnError($error_message);
			}
		break;
case	'Approvel_WorkOrderstatus':

			//Approvel_WorkOrderStatus
			$sql_apwrks="SELECT 	wrk_sts.wrk_sts_status, wrk_sts.wrk_sts_typ_cd,  wrk_sts.wrk_sts_desc, wrk_sts.wrk_sts_email_flag  
					FROM 	wrk_sts  (NOLOCK)
					WHERE	wrk_sts.wrk_sts_disable_flag = 0  
					AND		wrk_sts.wrk_sts_typ_cd NOT IN ( 'COMPLETE', 'CLOSE', 'CANCEL', 'FORCE-CLOSE' ) 
					AND		wrk_sts.site_cd = ?";	
							
			//echo $sql;
			$params_apwrks = array($site_cd);					
								
			$stmt_apwrks = sqlsrv_query( $conn, $sql_apwrks,$params_apwrks);

			if ($stmt_apwrks === false)
			{
				if (($errors = sqlsrv_errors()) != null)
				{
					foreach ($errors as $error)
					{

						file_put_contents($file_name, $now . "\r\n" . $sql . "\r\n" . "SQLSTATE: " . $error['SQLSTATE'] . "\r\n" . "code: " . $error['code'] . "\r\n" . "message: " . $error['message'] . "\r\n\r\n", FILE_APPEND);
					}
				}
				sqlsrv_rollback($conn);
				sqlsrv_close($conn);

				$error_message = "(".$now.") Error selecting (ast_sts)";
				returnError($error_message);
			}

			$Approvel_WorkOrderStatus= array();

			do {
				 while ($row = sqlsrv_fetch_array($stmt_apwrks, SQLSRV_FETCH_ASSOC)) {	
				 
					$Approvel_WorkOrderStatus[] = $row;		
				
				 }
			} while ( sqlsrv_next_result($stmt_apwrks) );	
			
			if($stmt_apwrks) {
				 sqlsrv_commit( $conn );
				 sqlsrv_close( $conn);	
				 
				 $json_All['Approvel_WorkOrderstatus'] = $Approvel_WorkOrderStatus;
				 returnData($json_All);	
				 
			} else {
				
				 sqlsrv_rollback( $conn );
				 $error_message = "Transaction rolled back.<br />";
				 returnError($error_message);
			}
		break;		
		
		case	'Wkr_Auto_numbering':

			//WorkRequest_Auto_Numnering
			$sql= "Select cnt_mst_numbering,cnt_mst_option ,cnt_mst_module_cd  From cnt_mst (NOLOCK) Where site_cd ='".$site_cd."' And cnt_mst_module_cd ='WKR'";
			$stmt = sqlsrv_query( $conn, $sql);

			if ($stmt === false)
			{
				if (($errors = sqlsrv_errors()) != null)
				{
					foreach ($errors as $error)
					{

						file_put_contents($file_name, $now . "\r\n" . $sql . "\r\n" . "SQLSTATE: " . $error['SQLSTATE'] . "\r\n" . "code: " . $error['code'] . "\r\n" . "message: " . $error['message'] . "\r\n\r\n", FILE_APPEND);
					}
				}
				sqlsrv_rollback($conn);
				sqlsrv_close($conn);

				$error_message = "(".$now.") Error selecting (ast_sts)";
				returnError($error_message);
			}

			$Wkr_Auto_numbering = array();

			do {
				 while ($row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC)) {		
					$Wkr_Auto_numbering[] = $row;	
				
				 }
			} while ( sqlsrv_next_result($stmt) );	
			
			if($stmt) {
				 sqlsrv_commit( $conn );
				 sqlsrv_close( $conn);	
				 
				 $json_All['Wkr_Auto_numbering'] = $Wkr_Auto_numbering;
				 returnData($json_All);	
				 
			} else {
				
				 sqlsrv_rollback( $conn );
				 $error_message = "Transaction rolled back.<br />";
				 returnError($error_message);
			}
		break;
		
		case	'PRStatus_Type':
		
			//PRStatus_Type
			$sql= "	select pur_sts_st_cat,pur_sts_status_type,pur_sts_status,pur_sts_description from pur_sts (NOLOCK) where site_cd ='".$site_cd."'";


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

			if ($stmt_PRStatus_Type === false)
			{
				if (($errors = sqlsrv_errors()) != null)
				{
					foreach ($errors as $error)
					{

						file_put_contents($file_name, $now . "\r\n" . $sql . "\r\n" . "SQLSTATE: " . $error['SQLSTATE'] . "\r\n" . "code: " . $error['code'] . "\r\n" . "message: " . $error['message'] . "\r\n\r\n", FILE_APPEND);
					}
				}
				sqlsrv_rollback($conn);
				sqlsrv_close($conn);

				$error_message = "(".$now.") Error selecting (ast_sts)";
				returnError($error_message);
			}

			$PRStatus_Type = array();

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

			
			if($stmt_PRStatus_Type) {
				 sqlsrv_commit( $conn );
				 sqlsrv_close( $conn);	
				 
				 $json_All['PRStatus_Type'] = $PRStatus_Type;
				 returnData($json_All);	
				 
			} else {
				
				 sqlsrv_rollback( $conn );
				 $error_message = "Transaction rolled back.<br />";
				 returnError($error_message);
			}
		break;
		
		case	'Dashbord_menu':

			//Dashbord_menu
			$sql_DBM="SELECT 			cf_menu.object_name,
										cf_menu.object_descs,			
										exe_flag,					
										new_flag,
										edit_flag,
										mobile_object_type,
										cf_menu_seq,
										cf_menu.column1
													

						FROM 				cf_menu (NOLOCK)
						
						INNER JOIN			cf_user_access (NOLOCK)
						ON					cf_user_access.menuid = cf_menu.rowid
						
						INNER JOIN			cf_module (NOLOCK)
						ON					cf_module.language_cd = cf_menu.language_cd
						AND					cf_module.cf_module_module_cd = cf_menu.program_category

						WHERE    			cf_user_access.site_cd = '".$site_cd."'
						AND      			cf_user_access.empl_id = '".$LoginID."'		
						AND					cf_menu.object_type = 'M'
						AND					cf_menu.mobile_object_type in ('o','m')

						AND					cf_menu.language_cd = 'DEFAULT' order by cf_menu_seq ";	
							
			
								
								
			$stmt_DBM = sqlsrv_query( $conn, $sql_DBM);

			if ($stmt_DBM === false)
			{
				if (($errors = sqlsrv_errors()) != null)
				{
					foreach ($errors as $error)
					{

						file_put_contents($file_name, $now . "\r\n" . $sql . "\r\n" . "SQLSTATE: " . $error['SQLSTATE'] . "\r\n" . "code: " . $error['code'] . "\r\n" . "message: " . $error['message'] . "\r\n\r\n", FILE_APPEND);
					}
				}
				sqlsrv_rollback($conn);
				sqlsrv_close($conn);

				$error_message = "(".$now.") Error selecting (ast_sts)";
				returnError($error_message);
			}

			$Dashbord_menu= array();

			do {
				 while ($row = sqlsrv_fetch_array($stmt_DBM, SQLSRV_FETCH_ASSOC)) {	
				 
					$Dashbord_menu[] = $row;		
				
				 }
			} while ( sqlsrv_next_result($stmt_DBM) );
			
			if($stmt_DBM) {
				 sqlsrv_commit( $conn );
				 sqlsrv_close( $conn);	
				 
				 $json_All['Dashbord_menu'] = $Dashbord_menu;
				 returnData($json_All);	
				 
			} else {
				
				 sqlsrv_rollback( $conn );
				 $error_message = "Transaction rolled back.<br />";
				 returnError($error_message);
			}
		break;
		
		case 'PMGroup':
		
			//PM Group			
			$sql= "SELECT 	prm_grp.prm_grp_grp_cd,   
							prm_grp.prm_grp_desc
					FROM 	prm_grp (NOLOCK)
					WHERE  	prm_grp.site_cd = '".$site_cd."' 
					AND 	prm_grp.prm_grp_disable_flag = 0 
					AND 	prm_grp.prm_grp_disable_flag = '0' ORDER BY prm_grp_grp_cd ASC";
			$stmt_prm_grp = sqlsrv_query( $conn, $sql);

			if ($stmt_prm_grp === false)
			{
				if (($errors = sqlsrv_errors()) != null)
				{
					foreach ($errors as $error)
					{

						file_put_contents($file_name, $now . "\r\n" . $sql . "\r\n" . "SQLSTATE: " . $error['SQLSTATE'] . "\r\n" . "code: " . $error['code'] . "\r\n" . "message: " . $error['message'] . "\r\n\r\n", FILE_APPEND);
					}
				}
				sqlsrv_rollback($conn);
				sqlsrv_close($conn);

				$error_message = "(".$now.") Error selecting (ast_sts)";
				returnError($error_message);
			}


			$PMGroup = array();

			do {
				 while ($row = sqlsrv_fetch_array($stmt_prm_grp, SQLSRV_FETCH_ASSOC)) {		
					$PMGroup []= $row;	
				
				 }
			} while ( sqlsrv_next_result($stmt_prm_grp) );
			
			if($stmt_prm_grp) {
				 sqlsrv_commit( $conn );
				 sqlsrv_close( $conn);	
				 
				 $json_All['PMGroup'] = $PMGroup;
				 returnData($json_All);	
				 
			} else {
				
				 sqlsrv_rollback( $conn );
				 $error_message = "Transaction rolled back.<br />";
				 returnError($error_message);
			}
			
		break;
		
		case 'Department':
		
			//PM Group			
			$sql= "SELECT 	dept_mst_dept_cod,   
							dept_mst_description,
							dept_mst_email_id,
							dept_mst_linen	
					FROM 	dept_mst (NOLOCK)
					WHERE  	dept_mst.site_cd = '".$site_cd."' 
					AND 	dept_mst.dept_mst_disable_flag = 0 ORDER BY dept_mst_dept_cod ASC";
			$stmt_Department = sqlsrv_query( $conn, $sql);

			if ($stmt_Department === false)
			{
				if (($errors = sqlsrv_errors()) != null)
				{
					foreach ($errors as $error)
					{

						file_put_contents($file_name, $now . "\r\n" . $sql . "\r\n" . "SQLSTATE: " . $error['SQLSTATE'] . "\r\n" . "code: " . $error['code'] . "\r\n" . "message: " . $error['message'] . "\r\n\r\n", FILE_APPEND);
					}
				}
				sqlsrv_rollback($conn);
				sqlsrv_close($conn);

				$error_message = "(".$now.") Error selecting (ast_sts)";
				returnError($error_message);
			}


			$Department = array();

			do {
				 while ($row = sqlsrv_fetch_array($stmt_Department, SQLSRV_FETCH_ASSOC)) {		
					$Department []= $row;	
				
				 }
			} while ( sqlsrv_next_result($stmt_Department) );
			
			if($stmt_Department) {
				 sqlsrv_commit( $conn );
				 sqlsrv_close( $conn);	
				 
				 $json_All['Department'] = $Department;
				 returnData($json_All);	
				 
			} else {
				
				 sqlsrv_rollback( $conn );
				 $error_message = "Transaction rolled back.<br />";
				 returnError($error_message);
			}
			
		break;
		
		//Linen Status
		case 'LinenStatus':
			
			$sql= "	SELECT 	lri_sts_cat_cd, lri_sts_typ_cd, lri_sts_status, lri_sts_desc, lri_sts_disable_flag, scn_sts_email_flag  
					FROM 	lri_sts  (NOLOCK)
					WHERE   lri_sts.lri_sts_disable_flag = 0 
					AND  	lri_sts_typ_cd NOT IN ('CANCEL')
					AND 	lri_sts.site_cd = '".$site_cd."'";
					
			$stmt_Linen_Status = sqlsrv_query( $conn, $sql);

			if ($stmt_Linen_Status === false)
			{
				if (($errors = sqlsrv_errors()) != null)
				{
					foreach ($errors as $error)
					{

						file_put_contents($file_name, $now . "\r\n" . $sql . "\r\n" . "SQLSTATE: " . $error['SQLSTATE'] . "\r\n" . "code: " . $error['code'] . "\r\n" . "message: " . $error['message'] . "\r\n\r\n", FILE_APPEND);
					}
				}
				sqlsrv_rollback($conn);
				sqlsrv_close($conn);

				$error_message = "(".$now.") Error selecting (lri_sts)";
				returnError($error_message);
			}

			$LineStatus = array();

			do {
				 while ($row = sqlsrv_fetch_array($stmt_Linen_Status, SQLSRV_FETCH_ASSOC)) {		
					$LineStatus[] = $row;	
				
				 }
			} while ( sqlsrv_next_result($stmt_Linen_Status) );
			if($stmt_Linen_Status) {
				 sqlsrv_commit( $conn );
				 sqlsrv_close( $conn);	
				 
				 $json_All['LinenStatus'] = $LineStatus;
				 returnData($json_All);	
				 
			} else {
				
				 sqlsrv_rollback( $conn );
				 $error_message = "Transaction rolled back.<br />";
				 returnError($error_message);
			}
			
		break;
		
		//Linen Request Status
		case 'LinenRequestStatus':
			
			$sql= "	SELECT 	lrr_sts_cat_cd, lrr_sts_typ_cd, lrr_sts_status, lrr_sts_desc, lrr_sts_disable_flag, scn_sts_email_flag  
					FROM 	lrr_sts  (NOLOCK)
					WHERE  	lrr_sts.lrr_sts_disable_flag = 0  
					AND  	lrr_sts_typ_cd NOT IN ('CANCEL')
					AND 	lrr_sts.site_cd = '".$site_cd."'";
					
			$stmt_Linen_Req_Status = sqlsrv_query( $conn, $sql);

			if ($stmt_Linen_Req_Status === false)
			{
				if (($errors = sqlsrv_errors()) != null)
				{
					foreach ($errors as $error)
					{

						file_put_contents($file_name, $now . "\r\n" . $sql . "\r\n" . "SQLSTATE: " . $error['SQLSTATE'] . "\r\n" . "code: " . $error['code'] . "\r\n" . "message: " . $error['message'] . "\r\n\r\n", FILE_APPEND);
					}
				}
				sqlsrv_rollback($conn);
				sqlsrv_close($conn);

				$error_message = "(".$now.") Error selecting (lrr_sts)";
				returnError($error_message);
			}

			$LinenRequestStatus = array();

			do {
				 while ($row = sqlsrv_fetch_array($stmt_Linen_Req_Status, SQLSRV_FETCH_ASSOC)) {		
					$LinenRequestStatus[] = $row;	
				
				 }
			} while ( sqlsrv_next_result($stmt_Linen_Req_Status) );
			if($stmt_Linen_Req_Status) {
				 sqlsrv_commit( $conn );
				 sqlsrv_close( $conn);	
				 
				 $json_All['LinenRequestStatus'] = $LinenRequestStatus;
				 returnData($json_All);	
				 
			} else {
				
				 sqlsrv_rollback( $conn );
				 $error_message = "Transaction rolled back.<br />";
				 returnError($error_message);
			}
			
		break;
}



function returnData($json_return){
	//echo $json;
	$returnData = array(												
	'status' => 'SUCCESS',
	'message' => 'Successfully',
	'data'=>$json_return);
	
	echo json_encode($returnData);
}

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

 
?>