COMPILE FUNCTION Dialog_React_Item_Hist(EntID,Event,Parm1,Parm2,Parm3,Parm4,Parm5)

/*
	Commuter module for DIALOG_REACT_ITEM_HIST window
	
	01/19/2014 - John C. Henry, J.C. Henry & Co., Inc. cloned from Graphite
*/

DECLARE SUBROUTINE Set_Property, ErrMsg, obj_Appwindow, Btree.Extract, Send_Event, Send_Message
DECLARE FUNCTION Get_Property, Send_Message, NextKey, Popup, obj_Calendar, Printer_Select
DECLARE FUNCTION Set_Printer, obj_Install, Start_Window, obj_Popup, obj_React_Item_Hist, MemberOf

$INSERT APPCOLORS
$INSERT REACT_ITEM_EQUATES
$INSERT REACT_ITEM_HIST_EQUATES
$INSERT POPUP_EQUATES
$INSERT RTI_STYLE_EQUATES

EQU COL$REACT_NO			TO 1
EQU COL$RI_NO				TO 2
EQU COL$RI_TYPE				TO 3
EQU COL$SVC_HRS				TO 4
EQU COL$SVC_WFRS			TO 5

EQU COL$INST_DTM			TO 6
EQU COL$INST_REACT_HRS		TO 7
EQU COL$INST_REACT_WFRS		TO 8
EQU COL$INST_RL_ID			TO 9

EQU COL$REM_DTM				TO 10
EQU COL$REM_REACT_HRS		TO 11
EQU COL$REM_REACT_WFRS		TO 12
EQU COL$REM_RL_ID			TO 13
EQU COL$REM_REASON			TO 14

EQU SPECIAL_BLUE$	TO 227 + (253*256) + (248*65536)
EQU CRLF$			TO \0D0A\

EQU HIDDEN$		TO 32
EQU SKIPPED$	TO 4100

EQU PI$LEFT		TO	1
EQU PI$TOP		TO  2
EQU PI$RIGHT	TO	3
EQU PI$BOTTOM	TO	4
EQU PI$WIDTH	TO 	5
EQU PI$HEIGHT	TO	6
EQU PI$SIZE		TO	7



ErrTitle = 'Error in Dialog_React_Item_Hist'
ErrorMsg = ''

Result = ''

BEGIN CASE
	CASE EntID = @WINDOW
		BEGIN CASE
			CASE Event = 'CREATE' 			; GOSUB Create
			
		END CASE
	
	CASE EntID = @WINDOW:'.HISTORY' AND Event = 'DBLCLK'			; GOSUB HistoryDC
	CASE EntID = @WINDOW:'.LU_REACT_NO' AND Event = 'CLICK'			; GOSUB LUReactNo
	CASE EntID = @WINDOW:'.LU_RI_NO' AND Event = 'CLICK'	 		; GOSUB LUReactItem
	CASE EntID = @WINDOW:'.LU_ALL_RI_NO' AND Event = 'CLICK'		; GOSUB LUReactItem
	CASE EntID = @WINDOW:'.LU_RI_TYPE' AND Event = 'CLICK'			; GOSUB LURIType
	CASE EntID = @WINDOW:'.REACT_NO' AND Event = 'LOSTFOCUS'		; GOSUB Select
	CASE EntID = @WINDOW:'.RI_NO' AND Event = 'LOSTFOCUS'			; GOSUB Select
	CASE EntID = @WINDOW:'.RI_TYPE' AND Event = 'LOSTFOCUS'			; GOSUB Select
	CASE EntID = @WINDOW:'.CLEAR_BUTTON' AND Event = 'CLICK'		; GOSUB Clear
	CASE EntID = @WINDOW:'.CLOSE_OPEN' AND Event = 'CLICK'			; GOSUB CloseOpen
	
	CASE EntID = @WINDOW:'.PRINT_LABEL' AND Event = 'CLICK'			; GOSUB PrintLabel

	CASE 1
		
		ErrorMsg = 'Unknown Parameters ':EntID:' - ':Event:' passed to commuter'
		ErrMsg(ErrorMsg)
		
END CASE

IF ErrorMsg NE '' THEN
	ErrMsg(ErrTitle:@SVM:ErrorMsg)
END

RETURN Result


* * * * * * *
Create:
* * * * * * *

obj_Appwindow('Create',@WINDOW)


RETURN


* * * * * * *
LUReactNo:
* * * * * * *


ReactorNo = Popup(@WINDOW,'','REACTORS')

IF ReactorNo = '' THEN RETURN

IF ReactorNo NE '' THEN
	obj_AppWindow('LUValReturn',ReactorNo:@RM:@WINDOW:'.REACT_NO')
	GOSUB Refresh
END

RETURN

* * * * * * *
LURIType:
* * * * * * *

RetVal = Popup(@WINDOW,'','REACT_ITEM_TYPE')

IF RetVal NE '' THEN
	oaParms = RetVal:@RM:@WINDOW:'.RI_TYPE'
	obj_Appwindow('LUValReturn',oaParms)
	GOSUB Refresh
END

RETURN



* * * * * * *
LUReactItem:
* * * * * * *

TypeOver = ''
TypeOver<PSELECT$> = 1

IF EntID = @WINDOW:'.LU_RI_NO' THEN
	TypeOver<PDISPLAY$> = 'WITH RETIRE_DT = "" BY RI_TYPE BY RI_NO'		;* Active Records only
END ELSE
	TypeOver<PDISPLAY$> = 'BY RI_TYPE BY RI_NO'							;* All Records
END

RetVal = Popup(@WINDOW,TypeOver,'REACT_ITEM')

IF RetVal NE '' THEN
	obj_AppWindow('LUValReturn',RetVal:@RM:@WINDOW:'.RI_NO')
	GOSUB Refresh
END

RETURN


* * * * * * *
Refresh:
* * * * * * *

Ctrls  = @WINDOW:'.REACT_NO':@RM		; Props  = 'TEXT':@RM
Ctrls := @WINDOW:'.RI_NO':@RM			; Props := 'TEXT':@RM
Ctrls := @WINDOW:'.RI_TYPE'				; Props := 'TEXT'

Vals = Get_Property(Ctrls,Props)

ReactNo	= Vals[1,@RM]
RINo	= Vals[COL2()+1,@RM]
RIType	= Vals[COL2()+1,@RM]


IF ReactNo = '' THEN
	ToolDesc = ''
END ELSE
	ToolDesc = XLATE('TOOL','R':ReactNo,1,'X'):'   ':XLATE('TOOL','R':ReactNo,'TOOL_LOC_DESC','X')
END

Set_Property(@WINDOW:'.REACT_DESC','TEXT',ToolDesc)


IF RINo = '' THEN
	RIDesc = ''
END ELSE
	RIDesc = XLATE('REACT_ITEM',RINo,'DESC_CALC','X')
END

Set_Property(@WINDOW:'.RI_DESC','TEXT',RIDesc)


IF RIType = '' THEN
	ItemTypDesc = ''
END ELSE
	ItemTypeDesc = obj_Popup('CodeDesc','REACT_ITEM_TYPE':@RM:RIType)
END

Set_Property(@WINDOW:'.RI_TYPE_DESC','TEXT',ItemTypeDesc)

IF MemberOf(@USER4, 'OI_SUPERUSER') THEN

	IF ( ReactNo NE '' AND RIType NE '' AND RINo = '' ) THEN
		Set_Property(@WINDOW:'.CLOSE_OPEN','VISIBLE',1)
	END ELSE
		Set_Property(@WINDOW:'.CLOSE_OPEN','VISIBLE',0)
	END
END

ETCtrl = @WINDOW:'.HISTORY'
ETList = Get_Property(ETCtrl,'LIST')
ListCnt = COUNT(ETList,@FM) + (ETList NE '')


FOR Line = 1 TO ListCnt
	
	IF MOD(Line,2) THEN
		stat = Send_Message(ETCtrl,'COLOR_BY_POS',COL$REACT_NO,Line,SPECIAL_BLUE$)
		stat = Send_Message(ETCtrl,'COLOR_BY_POS',COL$RI_NO,Line,SPECIAL_BLUE$)
		stat = Send_Message(ETCtrl,'COLOR_BY_POS',COL$RI_TYPE,Line,SPECIAL_BLUE$)
		stat = Send_Message(ETCtrl,'COLOR_BY_POS',COL$SVC_HRS,Line,VL_YELLOW$)
		stat = Send_Message(ETCtrl,'COLOR_BY_POS',COL$SVC_WFRS,Line,VL_YELLOW$)
		stat = Send_Message(ETCtrl,'COLOR_BY_POS',COL$INST_DTM,Line,SPECIAL_BLUE$)
		stat = Send_Message(ETCtrl,'COLOR_BY_POS',COL$INST_REACT_HRS,Line,SPECIAL_BLUE$)
		stat = Send_Message(ETCtrl,'COLOR_BY_POS',COL$INST_REACT_WFRS,Line,SPECIAL_BLUE$)
		stat = Send_Message(ETCtrl,'COLOR_BY_POS',COL$INST_RL_ID,Line,SPECIAL_BLUE$)
		stat = Send_Message(ETCtrl,'COLOR_BY_POS',COL$REM_DTM,Line,RCV_BLUE$)
		stat = Send_Message(ETCtrl,'COLOR_BY_POS',COL$REM_REACT_HRS,Line,RCV_BLUE$)
		stat = Send_Message(ETCtrl,'COLOR_BY_POS',COL$REM_REACT_WFRS,Line,RCV_BLUE$)
		stat = Send_Message(ETCtrl,'COLOR_BY_POS',COL$REM_RL_ID,Line,RCV_BLUE$)
		stat = Send_Message(ETCtrl,'COLOR_BY_POS',COL$REM_REASON,Line,RCV_BLUE$)
		
	END ELSE
		FOR N = 1 TO 11
			stat = Send_Message(ETCtrl,'COLOR_BY_POS',N,Line,WHITE$)
		NEXT N
	END
NEXT Line

RETURN


* * * * * * *
Select:
* * * * * * *

Ctrls  = @WINDOW:'.REACT_NO':@RM		; Props  = 'TEXT':@RM
Ctrls := @WINDOW:'.RI_NO':@RM			; Props := 'TEXT':@RM
Ctrls := @WINDOW:'.RI_TYPE'				; Props := 'TEXT'

Vals = Get_Property(Ctrls,Props)

ReactNo	= Vals[1,@RM]
RINo	= Vals[COL2()+1,@RM]
RIType	= Vals[COL2()+1,@RM]

HistoryStyles = Send_Message(@WINDOW:'.HISTORY','COLSTYLE',0,'')


/*
IF ReactNo '' THEN 
	HistoryStyles<COL$REACT_NO> = BitAnd(HistoryStyles<COL$REACT_NO>,BitNot(HIDDEN$))
END ELSE
	HistoryStyles<COL$REACT_NO> = BitOr(HistoryStyles<COL$REACT_NO>,HIDDEN$)
END

IF RINo = '' THEN 
	HistoryStyles<COL$RI_NO> = BitAnd(HistoryStyles<COL$RI_NO>,BitNot(HIDDEN$))
END ELSE
	HistoryStyles<COL$RI_NO> = BitOr(HistoryStyles<COL$RI_NO>,HIDDEN$)
END

IF RIType = '' THEN 
	HistoryStyles<COL$RI_TYPE> = BitAnd(HistoryStyles<COL$RI_TYPE>,BitNot(HIDDEN$))
END ELSE
	HistoryStyles<COL$RI_TYPE> = BitOr(HistoryStyles<COL$RI_TYPE>,HIDDEN$)
END

Send_Message(@WINDOW:'.HISTORY','COLSTYLE',0,HistoryStyles)
*/

HistoryKeys = obj_React_Item_Hist('GetHistory',Vals)

HistoryList = ''

hlCnt = COUNT(HistoryKeys,@VM) + (HistoryKeys NE '')

FOR I = 1 TO hlCnt
	HistoryKey = HistoryKeys<1,I>
	
	HistoryRec = XLATE('REACT_ITEM_HIST',HistoryKey,'','X')
	
	ReactNo		= HistoryKey[1,'*']
	RINo		= HistoryKey[COL2()+1,'*']
	InstDTM		= HistoryKey[COL2()+1,'*']
	RIType		= XLATE('REACT_ITEM',RINo,REACT_ITEM_RI_TYPE$,'X')
	
	HistoryList<I,COL$REACT_NO>			= ReactNo
	HistoryList<I,COL$RI_NO>			= RINo
	HistoryList<I,COL$INST_DTM>			= OCONV(InstDTM,'DT4/^S')
	
	HistoryList<I,COL$RI_TYPE>			= obj_Popup('CodeDesc','REACT_ITEM_TYPE':@RM:RIType)
	HistoryList<I,COL$SVC_HRS>			= ''
	HistoryList<I,COL$SVC_WFRS>			= ''
	
	HistoryList<I,COL$INST_REACT_HRS>	= HistoryRec<REACT_ITEM_HIST_INST_REACT_HRS$>
	HistoryList<I,COL$INST_REACT_WFRS>	= HistoryRec<REACT_ITEM_HIST_INST_REACT_WFR_CNT$>
	HistoryList<I,COL$INST_RL_ID>		= HistoryRec<REACT_ITEM_HIST_INST_RL_ID$>
	HistoryList<I,COL$REM_DTM>			= OCONV(HistoryRec<REACT_ITEM_HIST_REM_DTM$>,'DT4/^S')
	HistoryList<I,COL$REM_REACT_HRS>	= HistoryRec<REACT_ITEM_HIST_REM_REACT_HRS$>
	HistoryList<I,COL$REM_REACT_WFRS>	= HistoryRec<REACT_ITEM_HIST_REM_REACT_WFR_CNT$>
	HistoryList<I,COL$REM_RL_ID>		= HistoryRec<REACT_ITEM_HIST_REM_RL_ID$>
	HistoryList<I,COL$REM_REASON>		= HistoryRec<REACT_ITEM_HIST_REM_REASON$>

NEXT I

Set_Property(@WINDOW:'.HISTORY','LIST',HistoryList)

GOSUB Refresh


RETURN


* * * * * * *
Clear:
* * * * * * *


Ctrls  = @WINDOW:'.REACT_NO':@RM		; Props  = 'TEXT':@RM
Ctrls := @WINDOW:'.RI_NO':@RM			; Props := 'TEXT':@RM
Ctrls := @WINDOW:'.RI_TYPE'				; Props := 'TEXT'

Vals = '':@RM:'':@RM:''

Set_Property(Ctrls,Props,Vals)

Vals = STR(@FM,36)

Set_Property(@WINDOW:'.HISTORY','LIST',Vals)

GOSUB Refresh

RETURN



* * * * * * *
CloseOpen:
* * * * * * *

ReactNo = Get_Property(@WINDOW:'.REACT_NO','DEFPROP')
RIType	= Get_Property(@WINDOW:'.RI_TYPE','DEFPROP')

HistKeys = obj_React_Item_Hist('GetHistory',ReactNo:@RM:@RM:RIType)
HistCnt = COUNT(HistKeys,@VM) + (HistKeys NE '')
	
IF HistCnt > 1 THEN


	OPEN 'REACT_ITEM_HIST' TO ReactItemHistTable ELSE
		ErrorMsg = 'Unable to OPEN "REACT_ITEM_HIST" for updates.'
		RETURN
	END
	
	FOR N = 2 TO HistCnt
		HistKey		= HistKeys<1,N>
		PrevHistKey = HistKeys<1,N-1>
		
		READ HistRec FROM ReactItemHistTable,HistKey THEN
			
			READ PrevHistRec FROM ReactItemHistTable,PrevHistKey THEN
				
				*IF HistRec<REACT_ITEM_HIST_REM_DTM$> = '' THEN
					HistRec<REACT_ITEM_HIST_REM_DTM$>			= FIELD(PrevHistKey,'*',3)
					HistRec<REACT_ITEM_HIST_REM_RL_ID$>			= PrevHistRec<REACT_ITEM_HIST_INST_RL_ID$>
					HistRec<REACT_ITEM_HIST_REM_REACT_WFR_CNT$>	= PrevHistRec<REACT_ITEM_HIST_INST_REACT_WFR_CNT$>
					HistRec<REACT_ITEM_HIST_REM_REACT_HRS$>		= PrevHistRec<REACT_ITEM_HIST_INST_REACT_HRS$>
					HistRec<REACT_ITEM_HIST_REM_REASON$>		= ''
				
					
					WRITE HistRec ON ReactItemHistTable,HistKey THEN
						NULL
						*Send_Dyn('Closed: ':HistKey:' ':HistRec)
					END
				*END
				
			END	;* End of Closing History Record
		END	;* End of History Record Read
	
	NEXT N	;* End of loop through History keys
END	;* End of check for HistCnt > 1

GOSUB Select

RETURN


* * * * * * *
HistoryDC:
* * * * * * * 

CurrPos = Get_Property(EntID,'SELPOS')
CurrCol = CurrPos<1>
CurrRow = CurrPos<2>

CurrList = Get_Property(EntID,'LIST')

BEGIN CASE
	CASE CurrCol = COL$RI_NO
		RINo = CurrList<CurrRow,COL$RI_NO>
		IF RINo NE '' THEN
			obj_AppWindow('ViewRelated','REACT_ITEM':@RM:RINo)
		END
		
	CASE CurrCol = COL$INST_RL_ID
		RLId = CurrList<CurrRow,COL$INST_RL_ID>
		IF RLId NE '' THEN
			Dummy = Start_Window( 'REACTOR_LOG', @WINDOW, RLId:'*CENTER', '', '' )
		END
		
	CASE CurrCol = COL$REM_RL_ID
		RLId = CurrList<CurrRow,COL$REM_RL_ID>
		IF RLId NE '' THEN
			Dummy = Start_Window( 'REACTOR_LOG', @WINDOW, RLId:'*CENTER', '', '' )
		END
		
	CASE 1
	
		ReactNo = CurrList<CurrRow,COL$REACT_NO>
		RINo	= CurrList<CurrRow,COL$RI_NO>
		InstDTM	= ICONV(CurrList<CurrRow,COL$INST_DTM>,'DT')
		
		IF ReactNo NE '' THEN
			RIHistKey = ReactNo:'*':RINo:'*':InstDTM
			obj_AppWindow('ViewRelated','REACT_ITEM_HIST':@RM:RIHistKey)
		END
		
END CASE

RETURN


* * * * * * * 
PrintLabel:
* * * * * * *

RETURN



