<?php

require_once('config.php');
require_once ('f_get_usg_wrk_change.php');
$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'];


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 ) {
				 $error_message = "Error selecting table (Cost Center)";
				 returnError($error_message);
				 die( print_r( sqlsrv_errors(), true));
				 
			}

			$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 ) {
				 $error_message = "Error selecting table (Account list)";
				 returnError($error_message);
				 die( print_r( sqlsrv_errors(), true));
				 
			}

			$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 ) {
				 $error_message = "Error selecting table (Fault Code)";
				 returnError($error_message);
				 die( print_r( sqlsrv_errors(), true));
				 
			}

			$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  
					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 ) {
				 $error_message = "Error selecting table (Priority)";
				 returnError($error_message);
				 die( print_r( sqlsrv_errors(), true));
				 
			}

			$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 ) {
				 $error_message = "Error selecting table (wrk_act)";
				 returnError($error_message);
				 die( print_r( sqlsrv_errors(), true));
				 
			}

			$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 ) {
				 $error_message = "Error selecting table (Work Area)";
				 returnError($error_message);
				 die( print_r( sqlsrv_errors(), true));	 
			}

			$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 ) {
				 $error_message = "Error selecting table (wrk_ccd)";
				 returnError($error_message);
				 die( print_r( sqlsrv_errors(), true));
				 
			}

			$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 ) {
				 $error_message = "Error selecting table (wrk_cls)";
				 returnError($error_message);
				 die( print_r( sqlsrv_errors(), true));
				 
			}

			$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 ) {
				 $error_message = "Error selecting table (Account list)";
				 returnError($error_message);
				 die( print_r( sqlsrv_errors(), true));
				 
			}

			$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  
					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 ) {
				 $error_message = "Error selecting table (Workorder Status)";
				 returnError($error_message);
				 die( print_r( sqlsrv_errors(), true));
				 
			}

			$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 ) {
				 $error_message = "Error selecting table (wrk_typ)";
				 returnError($error_message);
				 die( print_r( sqlsrv_errors(), true));
				 
			}

			$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 ) {
				 $error_message = "Error selecting table (Asset Code)";
				 returnError($error_message);
				 die( print_r( sqlsrv_errors(), true));
				 
			}

			$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 ) {
				 $error_message = "Error selecting table (Critical Factor)";
				 returnError($error_message);
				 die( print_r( sqlsrv_errors(), true));	 
			}

			$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 ) {
				 $error_message = "Error selecting table (Asset Group Code)";
				 returnError($error_message);
				 die( print_r( sqlsrv_errors(), true));
				 
			}

			$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 ) {
				 $error_message = "Error selecting table (Level)";
				 returnError($error_message);
				 die( print_r( sqlsrv_errors(), true));	 
			}

			$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 ) {
				 $error_message = "Error selecting table (Asset Location)";
				 returnError($error_message);
				 die( print_r( sqlsrv_errors(), true));	 
			}

			$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 ) {
				 $error_message = "Error selecting table (Asset Status)";
				 returnError($error_message);
				 die( print_r( sqlsrv_errors(), true));
				 
			}

			$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 ) {
				 $error_message = "Error selecting table (Asset Status In Service)";
				 returnError($error_message);
				 die( print_r( sqlsrv_errors(), true));
				 
			}

			$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 ) {
				 $error_message = "Error selecting table (Asset Status Out of Service)";
				 returnError($error_message);
				 die( print_r( sqlsrv_errors(), true));
				 
			}

			$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 ) {
				 $error_message = "Error selecting table (Asset Type)";
				 returnError($error_message);
				 die( print_r( sqlsrv_errors(), true));
				 
			}

			$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  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)		
			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	
					
					
			WHERE	emp_mst.site_cd = '".$site_cd."' And emp_sts.emp_sts_typ_cd = 'ACTIVE' ORDER BY emp_mst.emp_mst_empl_id ASC";


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


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

			$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  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, wko_det, wrk_sts
							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	
					
					
			WHERE	emp_mst.site_cd = '".$site_cd."' And emp_sts.emp_sts_typ_cd = 'ACTIVE' ORDER BY emp_mst.emp_mst_empl_id ASC";


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


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

			$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 ) {
				
				 $error_message = "Error selecting table (cnt_mst)";
				 returnError($error_message);
				 die( print_r( sqlsrv_errors(), true));
				 
			}
			$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 ) {
				 $error_message = "Error selecting table (cnt_mst)";
				 returnError($error_message);
				 die( print_r( sqlsrv_errors(), true));
				 
			}

			$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 ) {
				 $error_message = "Error selecting table (WorkRequest_Auto_Numnering)";
				 returnError($error_message);
				 die( print_r( sqlsrv_errors(), true));
				 
			}

			$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="select column_name = CASE WHEN column_name =  'wko_det_rating1' Then '1'
						WHEN column_name =  'wko_det_rating2' Then '2'
						WHEN column_name =  'wko_det_rating3' Then '3' End
						, * from cf_label(NOLOCK) where table_name = 'wko_det' and language_cd = 'DEFAULT' and column_name IN ('wko_det_rating1','wko_det_rating2','wko_det_rating3')";	
							
				//echo $sql;
				//$params = array($site_cd,$mst_RowID);					
									
				$stmt_RatingQuestion = sqlsrv_query( $conn, $sql);

						if( !$stmt_RatingQuestion ) {
							$error_message = "Error SELECT Table (wko_ls8)";
							returnError($error_message);
							die( print_r( sqlsrv_errors(), true));
						}

						$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.itm_mst_desc,	
			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
			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 ) {
					 $error_message = "Error selecting table (MR Stockno)";
					 returnError($error_message);
					 die( print_r( sqlsrv_errors(), true));
					 
				}

				$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 ) {
					$error_message = "Error selecting table (Hours Type)";
					returnError($error_message);
					die( print_r( sqlsrv_errors(), true));
							 
				}

				$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 ) {
							$error_message = "Error SELECT Table (crf_mst)";
							returnError($error_message);
							die( print_r( sqlsrv_errors(), true));
						}

						$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 ) {
				 $error_message = "Error selecting table (sup_mst)";
				 returnError($error_message);
				 die( print_r( sqlsrv_errors(), true));
				 
			}

			$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  FROM uom_mst(NOLOCK)  
					WHERE 	uom_mst.site_cd = '".$site_cd."' 
					AND 	uom_mst_type = 'SERVICE' 
					AND 	uom_mst_disable_flag = '0' ORDER BY uom_mst_uom ASC ";
			$stmt_uom = sqlsrv_query( $conn, $sql);

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

			$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 ) {
				 $error_message = "Error selecting table (Priority)";
				 returnError($error_message);
				 die( print_r( sqlsrv_errors(), true));
				 
			}

			$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 ) {
				 $error_message = "Error selecting table (emp_ls5)";
				 returnError($error_message);
				 die( print_r( sqlsrv_errors(), true));
				 
			}

			$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 ) {
				$error_message = "Error SELECT Table (Approvel wrk_sts)";
				returnError($error_message);
				die( print_r( sqlsrv_errors(), true));
			}

			$Approvel_WorkOrderStatus= array();

			do {
				 while ($row = sqlsrv_fetch_array($stmt_apwrks, SQLSRV_FETCH_ASSOC)) {	
				 
					$Approvel_WorkOrderStatus[] = $row;		
				
				 }
			} while ( sqlsrv_next_result($stmt_apwrks) );
			
			
			//ProjectID
			$sql_projectid="SELECT prj_mst_prj_cd,prj_mst_desc 	FROM 	prj_mst  (NOLOCK) WHERE	prj_mst.site_cd = ?";	
							
			//echo $sql;
			$params_apwrks = array($site_cd);					
								
			$stmt_projectid = sqlsrv_query( $conn, $sql_projectid,$params_apwrks);

			if( !$stmt_projectid ) {
				$error_message = "Error SELECT Table (project_id)";
				returnError($error_message);
				die( print_r( sqlsrv_errors(), true));
			}

			$project_id= array();

			do {
				 while ($row = sqlsrv_fetch_array($stmt_projectid, SQLSRV_FETCH_ASSOC)) {	
				 
					$project_id[] = $row;		
				
				 }
			} while ( sqlsrv_next_result($stmt_projectid) );
			
			
			
			//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 ) {
				$error_message = "Error SELECT Table (Approvel Dashbord_menu)";
				returnError($error_message);
				die( print_r( sqlsrv_errors(), true));
			}

			$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 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_down',
											'ast_dwntime_repair_to',			'ast_dwntime_downtime',		'ast_dwntime_repairtime',	'wko_mst_project_id','wko_det_numeric1') 
							and language_cd = 'DEFAULT' order by customize_label";	
							
			$stmt_WO_cf_label = sqlsrv_query( $conn, $sql_WO_cf_label);

			if( !$stmt_WO_cf_label ) {
				$error_message = "Error SELECT Table (WO_cf_label)";
				returnError($error_message);
				die( print_r( sqlsrv_errors(), true));
			}

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


			$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_projectid) {
				 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['project_id'] = $project_id;				 
				
				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 ) {
				 $error_message = "Error selecting table (Cost Center)";
				 returnError($error_message);
				 die( print_r( sqlsrv_errors(), true));
				 
			}

			$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 ) {
			 $error_message = "Error selecting table (Account list)";
			 returnError($error_message);
			 die( print_r( sqlsrv_errors(), true));
			 
		}

		$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 ) {
			 $error_message = "Error selecting table (Fault Code)";
			 returnError($error_message);
			 die( print_r( sqlsrv_errors(), true));
			 
		}

		$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  
				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 ) {
			 $error_message = "Error selecting table (Priority)";
			 returnError($error_message);
			 die( print_r( sqlsrv_errors(), true));
			 
		}

		$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 ) {
			 $error_message = "Error selecting table (wrk_act)";
			 returnError($error_message);
			 die( print_r( sqlsrv_errors(), true));
			 
		}

		$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 ) {
			 $error_message = "Error selecting table (Work Area)";
			 returnError($error_message);
			 die( print_r( sqlsrv_errors(), true));	 
		}

		$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 ) {
			 $error_message = "Error selecting table (wrk_ccd)";
			 returnError($error_message);
			 die( print_r( sqlsrv_errors(), true));
			 
		}

		$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 ) {
			 $error_message = "Error selecting table (wrk_cls)";
			 returnError($error_message);
			 die( print_r( sqlsrv_errors(), true));
			 
		}

		$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 
				where 	site_cd = '".$site_cd."'";
				
		$stmt_wrk_group = sqlsrv_query( $conn, $sql);

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

		$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  
					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 ) {
			 $error_message = "Error selecting table (Workorder Status)";
			 returnError($error_message);
			 die( print_r( sqlsrv_errors(), true));
			 
		}

		$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 ) {
			 $error_message = "Error selecting table (wrk_typ)";
			 returnError($error_message);
			 die( print_r( sqlsrv_errors(), true));
			 
		}

		$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 ) {
			 $error_message = "Error selecting table (Asset Code)";
			 returnError($error_message);
			 die( print_r( sqlsrv_errors(), true));
			 
		}

		$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 ) {
			 $error_message = "Error selecting table (Critical Factor)";
			 returnError($error_message);
			 die( print_r( sqlsrv_errors(), true));	 
		}

		$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 ) {
			 $error_message = "Error selecting table (Asset Group Code)";
			 returnError($error_message);
			 die( print_r( sqlsrv_errors(), true));
			 
		}

		$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 ) {
			 $error_message = "Error selecting table (Level)";
			 returnError($error_message);
			 die( print_r( sqlsrv_errors(), true));	 
		}

		$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 ) {
			 $error_message = "Error selecting table (Asset Location)";
			 returnError($error_message);
			 die( print_r( sqlsrv_errors(), true));	 
		}

		$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 ) {
			 $error_message = "Error selecting table (Asset Status)";
			 returnError($error_message);
			 die( print_r( sqlsrv_errors(), true));
			 
		}

		$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 ) {
			 $error_message = "Error selecting table (Asset Type)";
			 returnError($error_message);
			 die( print_r( sqlsrv_errors(), true));
			 
		}

		$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  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)		
		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	
				
				
		WHERE	emp_mst.site_cd = '".$site_cd."' And emp_sts.emp_sts_typ_cd = 'ACTIVE' ORDER BY emp_mst.emp_mst_empl_id ASC";


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


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

		$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  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, wko_det, wrk_sts
				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	
				
				
		WHERE	emp_mst.site_cd = '".$site_cd."' And emp_sts.emp_sts_typ_cd = 'ACTIVE' ORDER BY emp_mst.emp_mst_empl_id ASC";


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


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

		$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 ) {
			
			 $error_message = "Error selecting table (cnt_mst)";
			 returnError($error_message);
			 die( print_r( sqlsrv_errors(), true));
			 
		}
		$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 ) {
			 $error_message = "Error selecting table (cnt_mst)";
			 returnError($error_message);
			 die( print_r( sqlsrv_errors(), true));
			 
		}

		$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="select column_name = CASE WHEN column_name =  'wko_det_rating1' Then '1'
			WHEN column_name =  'wko_det_rating2' Then '2'
			WHEN column_name =  'wko_det_rating3' Then '3' End
			, * from cf_label(NOLOCK) where table_name = 'wko_det' and language_cd = 'DEFAULT' and column_name IN ('wko_det_rating1','wko_det_rating2','wko_det_rating3')";	
				
	//echo $sql;
	//$params = array($site_cd,$mst_RowID);					
						
		$stmt_RatingQuestion = sqlsrv_query( $conn, $sql);

			if( !$stmt_RatingQuestion ) {
				$error_message = "Error SELECT Table (wko_ls8)";
				returnError($error_message);
				die( print_r( sqlsrv_errors(), true));
			}

			$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.itm_mst_desc,	
			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
			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 ) {
			 $error_message = "Error selecting table (MR Stockno)";
			 returnError($error_message);
			 die( print_r( sqlsrv_errors(), true));
			 
		}

		$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 ) {
			$error_message = "Error selecting table (Hours Type)";
			returnError($error_message);
			die( print_r( sqlsrv_errors(), true));
					 
		}

		$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 ) {
					$error_message = "Error SELECT Table (crf_mst)";
					returnError($error_message);
					die( print_r( sqlsrv_errors(), true));
				}

				$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 ) {
			 $error_message = "Error selecting table (sup_mst)";
			 returnError($error_message);
			 die( print_r( sqlsrv_errors(), true));
			 
		}

		$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  FROM uom_mst(NOLOCK)  
				WHERE 	uom_mst.site_cd = '".$site_cd."' 
				AND 	uom_mst_type = 'SERVICE' 
				AND 	uom_mst_disable_flag = '0' ORDER BY uom_mst_uom ASC ";
		$stmt_uom = sqlsrv_query( $conn, $sql);

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

		$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 ) {
			 $error_message = "Error selecting table (Priority)";
			 returnError($error_message);
			 die( print_r( sqlsrv_errors(), true));
			 
		}

		$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 ) {
				 $error_message = "Error selecting table (emp_ls5)";
				 returnError($error_message);
				 die( print_r( sqlsrv_errors(), true));
				 
			}

			$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 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 ) {
				 $error_message = "Error selecting table (Asset Status In Service)";
				 returnError($error_message);
				 die( print_r( sqlsrv_errors(), true));
				 
			}

			$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 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 ) {
				 $error_message = "Error selecting table (Asset Status Out of Service)";
				 returnError($error_message);
				 die( print_r( sqlsrv_errors(), true));
				 
			}

			$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 ) {
				$error_message = "Error SELECT Table (Approvel wrk_sts)";
				returnError($error_message);
				die( print_r( sqlsrv_errors(), true));
			}

			$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 ) {
				 $error_message = "Error selecting table (WorkRequest_Auto_Numnering)";
				 returnError($error_message);
				 die( print_r( sqlsrv_errors(), true));
				 
			}

			$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	'project_id':
		
		
			//ProjectID
			$sql_projectid="SELECT prj_mst_prj_cd,prj_mst_desc 	FROM 	prj_mst  (NOLOCK) WHERE	prj_mst.site_cd = ?";	
							
			//echo $sql;
			$params_apwrks = array($site_cd);					
								
			$stmt_projectid = sqlsrv_query( $conn, $sql_projectid,$params_apwrks);

			if( !$stmt_projectid ) {
				$error_message = "Error SELECT Table (project_id)";
				returnError($error_message);
				die( print_r( sqlsrv_errors(), true));
			}

			$project_id= array();

			do {
				 while ($row = sqlsrv_fetch_array($stmt_projectid, SQLSRV_FETCH_ASSOC)) {	
				 
					$project_id[] = $row;		
				
				 }
			} while ( sqlsrv_next_result($stmt_projectid) );	
			
			if($stmt_projectid) {
				 sqlsrv_commit( $conn );
				 sqlsrv_close( $conn);	
				 
				 $json_All['project_id'] = $project_id;
				 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);
		
}
	

 
?>