Compile function COMM_OVERRIDE_REPORT(Method)

#pragma precomp SRP_PreCompiler
Declare function Get_Property, SRP_DateTime, Datetime, RList, SRP_SORT_ARRAY	
Declare Subroutine Errmsg, Btree.Extract, RList, Set_Property

$Insert OVERRIDE_LOG_EQUATES

ErrTitle = 'Error in Comm_RDS'
ErrorMsg = ''

Result = ''

BEGIN CASE
	CASE Method = 'Search'							; GOSUB Search
	CASE Method = 'SearchTypeControls'				; GOSUB SearchTypeControls
		
	CASE 1
		ErrMsg(ErrTitle:@SVM:'Unknown method ':QUOTE(Method):' passed to routine.')
		
END CASE

Return Result


* * * * * * * *
Search: 
* * * * * * * *
	
	SearchType = Get_Property(@WINDOW:'.REPORT_BY','DEFPROP')
	Filter = Get_Property(@WINDOW:'.ITEM_FILTER','DEFPROP')
	DateFrom = Get_Property(@WINDOW:'.DATE_FROM','DEFPROP')
	DateFrom = ICONV(DateFrom,'DT')
	DateTo = Get_Property(@WINDOW:'.DATE_TO','DEFPROP')
	DateTo = ICONV(DateTo,'DT')
	
	IF DateTo EQ '' then
		DateTo = DateTime()
	end
	IF DateFrom EQ '' then
		DateFrom = SRP_DateTime('AddDays', DateTo, -7)
	end
	
	dataarray = ''
	open "OVERRIDE_LOG" To OverRideTable else
		Status = Set_FSError()
		return
		
	end
	
	select OverRideTable
	Begin Case
		
		Case SearchType = 'ALL'
			Done = 0
			Loop
				ReadNext @ID else Done = 1
			Until Done Do
				read @Record from OverRideTable, @ID else
					status = Set_FSError()
					
					return
				end
				RecordTime = @RECORD<OVERRIDE_LOG_DTM$>
				IF RecordTime GE DateFrom AND RecordTime LE DateTo Then
					RecToWrite = @Record
					
					User = @Record<OVERRIDE_LOG_USER$>
					Comment = @Record<OVERRIDE_LOG_COMMENT$>
					LogTime = OCONV(@Record<OVERRIDE_LOG_DTM$>,'DT4/HS')
					Category = @Record<OVERRIDE_LOG_CATEGORY$>
					DynamicValues = @Record<OVERRIDE_LOG_KEY$>
					dataarray:= User :@VM:Comment:@VM:LogTime:@VM:Category :@VM:DynamicValues :@FM
					
				end
			Repeat
			
			DynamicFields = @RECORD<OVERRIDE_LOG_TABLE$>
			swap @VM with @FM in DynamicFields
			HeaderText = Get_Property(@WINDOW:'.OVERRIDE_TABLE','LABEL')
			HeaderText<5> = DynamicFields
			Set_Property(@WINDOW:'.OVERRIDE_TABLE','LABEL',HeaderText)
			//////////////////////			
		Case SearchType = 'RDS' Or SearchType = 'REACTOR'
			Done = 0
			Loop
				ReadNext @ID else Done = 1
			Until Done Do
				read @Record from OverRideTable, @ID else
					status = Set_FSError()
					
					return
				end
				RecordTables = @RECORD<OVERRIDE_LOG_TABLE$>
				RecordKeys = @RECORD<OVERRIDE_LOG_KEY$>
				Locate SearchType in RecordTables using @VM setting tPos then
					
					RecordTime = @RECORD<OVERRIDE_LOG_DTM$>
					IF RecordTime GE DateFrom AND RecordTime LE DateTo AND RecordKeys<1,tPos> EQ Filter Then
						RecToWrite = @Record
						
						User = @Record<OVERRIDE_LOG_USER$>
						Comment = @Record<OVERRIDE_LOG_COMMENT$>
						LogTime = OCONV(@Record<OVERRIDE_LOG_DTM$>,'DT4/HS')
						Category = @Record<OVERRIDE_LOG_CATEGORY$>
						DynamicValues = @Record<OVERRIDE_LOG_KEY$>
						dataarray:=  User :@VM:Comment:@VM:LogTime:@VM:Category :@VM:DynamicValues :@FM
					end
				end
				
			Repeat
			////////////////////
		Case SearchType = 'OVERRIDE'
			debug
			OverrideFilter = Get_Property(@WINDOW:'.OVERRIDE_TYPE','DEFPROP')
			Done = 0
			Loop
				ReadNext @ID else Done = 1
			Until Done Do
				read @Record from OverRideTable, @ID else
					status = Set_FSError()
					
					return
				end
				
				RecordTime = @RECORD<OVERRIDE_LOG_DTM$>
				IF RecordTime GE DateFrom AND RecordTime LE DateTo AND @RECORD<OVERRIDE_LOG_CATEGORY$> EQ OverrideFilter Then
					RecToWrite = @Record
					
					User = @Record<OVERRIDE_LOG_USER$>
					Comment = @Record<OVERRIDE_LOG_COMMENT$>
					LogTime = OCONV(@Record<OVERRIDE_LOG_DTM$>,'DT4/HS')
					Category = @Record<OVERRIDE_LOG_CATEGORY$>
					DynamicValues = @Record<OVERRIDE_LOG_KEY$>
					dataarray:=  User :@VM:Comment:@VM:LogTime:@VM:Category :@VM:DynamicValues :@FM
				end
				
				
			Repeat
			
		Case SearchType = 'USER'
			debug
			
			Done = 0
			Loop
				ReadNext @ID else Done = 1
			Until Done Do
				read @Record from OverRideTable, @ID else
					status = Set_FSError()
					
					return
				end
				
				RecordTime = @RECORD<OVERRIDE_LOG_DTM$>
				IF RecordTime GE DateFrom AND RecordTime LE DateTo AND @RECORD<OVERRIDE_LOG_USER$> EQ Filter Then
					RecToWrite = @Record
					
					User = @Record<OVERRIDE_LOG_USER$>
					Comment = @Record<OVERRIDE_LOG_COMMENT$>
					LogTime = OCONV(@Record<OVERRIDE_LOG_DTM$>,'DT4/HS')
					Category = @Record<OVERRIDE_LOG_CATEGORY$>
					DynamicValues = @Record<OVERRIDE_LOG_KEY$>
					dataarray:=  User :@VM:Comment:@VM:LogTime:@VM:Category :@VM:DynamicValues :@FM
				end
				
				
			Repeat
	End Case
	
	dataarray =  SRP_SORT_Array(dataarray, "DR3", 1)
	
	Set_Property(@WINDOW:'.OVERRIDE_TABLE','LIST',dataarray)
	HeaderText = Get_Property(@WINDOW:'.OVERRIDE_TABLE','LABEL')
	
	* HeaderText<COL$REC_NO> = HeaderText<COL$REC_NO>:CHAR(13):'<dc>'
	* HeaderText<COL$THK_UNITS> = HeaderText<COL$THK_UNITS>:CHAR(13):'<dc>'
	* HeaderText<COL$RES_UNITS> = HeaderText<COL$RES_UNITS>:CHAR(13):'<dc>'
	* HeaderText<COL$CON_UNITS> = HeaderText<COL$CON_UNITS>:CHAR(13):'<dc>'
	* HeaderText<COL$CRES_UNITS> = HeaderText<COL$CRES_UNITS>:CHAR(13):'<dc>'
	* 
	* Set_Property(@WINDOW:'.LS_TABLE','LABEL',HeaderText)
	//NewList = SRP_Sort_Array(List, "AL2", 1)
	//Set_Property(@Window:".EDT_TEST", "LIST", NewList)
	
	
	
return
//Set the correct filter label and enable field
* * * * * * * *
SearchTypeControls: 
* * * * * * * *
	Selection = Get_Property(@WINDOW:'.REPORT_BY','DEFPROP')
	//Set the correct filter label and enable field
	IF Selection EQ 'ALL' then
		Set_Property(@Window:'.ITEM_FILTER', 'ENABLED', -1)
		Set_Property(@WINDOW:'.LABEL_FILTER','TEXT','')
		
	end else
		IF Selection EQ 'OVERRIDE' THEN
			Set_Property(@Window:'.OVERRIDE_TYPE', 'ENABLED', 1)
			Set_Property(@Window:'.ITEM_FILTER', 'ENABLED', -1)
			Set_Property(@WINDOW:'.LABEL_FILTER','TEXT','')
		end else
			Set_Property(@Window:'.ITEM_FILTER', 'ENABLED', 1)
			Set_Property(@WINDOW:'.LABEL_FILTER','TEXT',Selection : '#:')
			Set_Property(@Window:'.OVERRIDE_TYPE', 'ENABLED', 0)
		end
		
	end
return

* * * * * * * *
ExportCSV: 
* * * * * * * *
