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

/*
	Commuter module for MASTER_CALIB_LIST (Calibration List) dialog window
	
	02/9/2010 - John C. Henry, J.C. Henry & Co., Inc.
*/

DECLARE SUBROUTINE Set_Property, End_Dialog, Send_Event, Set_Status, Center_Window, Post_Event, RList
DECLARE SUBROUTINE ErrMsg, Send_Message, Set_Property, Send_Event, Btree.Extract, obj_AppWindow
DECLARE SUBROUTINE obj_Notes, Security_Err_Msg, End_Window, Forward_Event, Start_Window, Create_Note

DECLARE FUNCTION Get_Property, Get_Status, Dialog_Box, Utility, Popup, Collect.Ixvals, Admin_User, Printer_Select
DECLARE FUNCTION Send_Message, Msg, Security_Check, obj_React_Run_CI, MemberOf, Get_Printer, obj_Install,Set_Printer

$INSERT MSG_EQUATES
$INSERT APPCOLORS
$INSERT LSL_USERS_EQU
$INSERT SECURITY_RIGHTS_EQU
$INSERT CALIB_LIST_EQUATES
$INSERT POPUP_EQUATES
$INSERT LOGICAL
$INSERT QUOTE_SIGS_EQU
$INSERT RLIST_EQUATES
$INSERT OIPRINT_EQUATES

EQU HIDDEN$	TO 32

EQU COL$CL_NO			TO 1
EQU COL$DEPT			TO 2
EQU COL$EQ_INSTRUMENT	TO 3
EQU COL$EQ_SN			TO 4
EQU COL$EQ_LOC			TO 5
EQU COL$EQ_CLASS		TO 6 
EQU COL$EQ_CAL_CLASS	TO 7
EQU COL$EQ_CAL_INT		TO 8
EQU COL$EQ_INT_EXT		TO 9
EQU COL$EQ_LAST_CAL		TO 10
EQU COL$EQ_NEXT_CAL		TO 11

EQU COL$NIST_STANDARD	TO 3
EQU COL$NIST_TSN		TO 4
EQU COL$NIST_LOC		TO 5
EQU COL$NIST_CAL_INT	TO 6
EQU COL$NIST_INT_EXT	TO 7
EQU COL$NIST_LAST_CAL	TO 8
EQU COL$NIST_NEXT_CAL	TO 9


ErrTitle = 'Error in Master_Calib_List routine'
ErrorMsg = ''

Result = ''


BEGIN CASE
	CASE EntID = @WINDOW
		BEGIN CASE
			CASE Event = 'CREATE' 			; GOSUB Create
			CASE Event = 'CLOSE'			; GOSUB Close
			
		END CASE
	
	CASE EntID = @WINDOW:'.PRINT_EQUIP_LIST' AND Event = 'CLICK'	; GOSUB PrintEquipment
	CASE EntID = @WINDOW:'.PRINT_NIST_LIST' AND Event = 'CLICK'		; GOSUB PrintNIST
	
	CASE EntID = @WINDOW:'.NEW_EQUIPMENT' AND Event = 'CLICK'		; GOSUB NewEquipment
	CASE EntID = @WINDOW:'.NEW_NIST' AND Event = 'CLICK'			; GOSUB NewNIST
	
	CASE EntID = @WINDOW:'.EQUIPMENT' AND Event = 'DBLCLK'			; GOSUB EquipDC
	CASE EntID = @WINDOW:'.NIST' AND Event = 'DBLCLK'				; GOSUB NISTDC
	
	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)

IF MemberOf (@USER4, 'CALIBRATION') ELSE 
	Message = 'You do not have the proper security to enter the Master Calibration List...' 
	Message<MICON$> = 'H'
	Void = Msg( '', Message )
	GOTO Close
END


CalEngSigners = XLATE( 'CONFIG', 'QUOTE_SIGS', PSNPreProdSigs$, 'X' )

LOCATE @USER4 IN CalEngSigners USING @VM SETTING DUM THEN 
   IsCalEng = TRUE$
END ELSE
   Set_Property(@WINDOW:'.PRINT)','VISIBLE',FALSE$)
   IsCalEng = FALSE$
END

GOSUB Refresh

RETURN


* * * * * * *
Close:
* * * * * * *


End_Dialog(@WINDOW,'')

RETURN


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

OPEN 'CALIB_LIST' TO TableIn ELSE
	ErrorMsg = 'Unable to open "CALIB_LIST" table.'
	RETURN
END
 
SELECT TableIn


EquipList	= ''
NISTList 	= ''
EquipDescs	= ''
StdDescs	= ''
EquipColors = ''
NISTColors 	= ''
EQ_LOC = ''
Done = 0
Today = Date() 

LOOP 

READNEXT CLNo ELSE Done = 1 

UNTIL Done
	READ CalRec FROM TableIn,CLNo THEN
	
		NextCalDt = XLATE('CALIB_LIST',CLNo,'NEXT_CAL_DT','X')
		
		BEGIN CASE
			CASE CalRec<CALIB_LIST_EQ_LOC$>[1,14] = 'Out of Service'		; LineColor = LTGREY$
			CASE NextCalDt = ''												; LineColor = WHITE$
			CASE CalRec<CALIB_LIST_EQ_LOC$>[1,19] = 'Out for Calibration' 	; LineColor = ORANGE$		;* Added dkk 10/6/14
			CASE (Today GT NextCalDt)										; LineColor = RED$
			CASE (NextCalDt - Today) LE 15									; LineColor = YELLOW$
			CASE 1															; LineColor = GREEN$
		
		END CASE
		
		IF CalRec<CALIB_LIST_CL_TYPE$> = 'E' THEN
	
			EquipDesc	= CalRec<CALIB_LIST_EQ_DESC$>
			Dept		= CalRec<CALIB_LIST_DEPT$>
			
			IF EquipDesc NE '' THEN
			
				SortKey = Dept:'*':EquipDesc:'*':CLNo
				
				LOCATE SortKey IN EquipDescs BY 'AL' SETTING Pos ELSE
				
					EquipDescs = INSERT(EquipDescs,1,Pos,0,SortKey)
					
					EquipLine = CLNo
					EquipLine<1,COL$DEPT>			= Dept
					EquipLine<1,COL$EQ_INSTRUMENT>	= CalRec<CALIB_LIST_EQ_DESC$>
					EquipLine<1,COL$EQ_SN>			= CalRec<CALIB_LIST_EQ_SN$>
					EquipLine<1,COL$EQ_LOC>			= CalRec<CALIB_LIST_EQ_LOC$>
					//EquipLine<1,COL$EQ_CLASS>		= CalRec<CALIB_LIST_EQ_LEVEL$>
					//EquipLine<1,COL$EQ_CAL_CLASS>	= CalRec<CALIB_LIST_EQ_CAL_CLASS$>
					EquipLine<1,COL$EQ_CAL_INT>		= CalRec<CALIB_LIST_CAL_INTERVAL$> 
					EquipLine<1,COL$EQ_INT_EXT>		= CalRec<CALIB_LIST_CAL_LOC$> 
					EquipLine<1,COL$EQ_LAST_CAL>	= OCONV(XLATE('CALIB_LIST',CLNo,'LAST_CAL_DT','X'),'D4/')
					EquipLine<1,COL$EQ_NEXT_CAL>	= OCONV(NextCalDt,'D4/')
					
					EquipList	= INSERT(EquipList,Pos,0,0,EquipLine)
					EquipColors	= INSERT(EquipColors,Pos,0,0,LineColor)
					
				END	;* End of LOCATE SortKey
				
			END	;* End of check for Null EquipDesc
			
		END;* End of check for CL_TYPE = 'E'
		
		IF CalRec<CALIB_LIST_CL_TYPE$> = 'S' THEN
			StdDesc = CalRec<CALIB_LIST_STD_DESC$>
			Dept	= CalRec<CALIB_LIST_DEPT$>
			
			IF StdDesc NE '' THEN
		
				SortKey = Dept:'*':StdDesc:'*':CLNo
				
				LOCATE SortKey IN StdDescs BY 'AL' SETTING Pos ELSE
				
					StdDescs = INSERT(StdDescs,1,Pos,0,SortKey)
					
					NISTLine = CLNo
					NISTLine<1,COL$DEPT>			= CalRec<CALIB_LIST_DEPT$>
					NISTLine<1,COL$NIST_STANDARD>	= CalRec<CALIB_LIST_STD_DESC$>
					NISTLine<1,COL$NIST_TSN>		= CalRec<CALIB_LIST_STD_SN$>
					NISTLine<1,COL$NIST_LOC>		= CalRec<CALIB_LIST_STD_LOC$>
					NISTLine<1,COL$NIST_CAL_INT>	= CalRec<CALIB_LIST_CAL_INTERVAL$>
					NISTLine<1,COL$NIST_INT_EXT>	= CalRec<CALIB_LIST_CAL_LOC$>
					NISTLine<1,COL$NIST_LAST_CAL>	= OCONV(XLATE('CALIB_LIST',CLNo,'LAST_CAL_DT','X'),'D4/') 
					NISTLine<1,COL$NIST_NEXT_CAL>	= OCONV(NextCalDt,'D4/') 
					
					NISTList = INSERT(NISTList,Pos,0,0,NISTLine)
					NISTColors = INSERT(NISTColors,Pos,0,0,LineColor)
					
				END	;* End of LOCATE SortKey
				
			END	;* End of check for Null StdDesc
		
		END	;* End of check for CL_TYPE = 'S'
	END	;* End of CalRec read
REPEAT

EquipList<-1> = STR(@VM,9)
NISTList<-1> = STR(@VM,7)

Set_Property(@WINDOW:'.EQUIPMENT','LIST',EquipList)
Set_Property(@WINDOW:'.NIST','LIST',NISTList)


EquipCnt = COUNT(EquipList,@FM) + (EquipList NE '')

FOR I = 1 TO EquipCnt
	stat = Send_Message(@WINDOW:'.EQUIPMENT','COLOR_BY_POS',0,I,EquipColors<I>)
NEXT I

NISTCnt = COUNT(NISTList,@FM) + (NISTList NE '')

FOR I = 1 TO NISTCnt
	stat = Send_Message(@WINDOW:'.NIST','COLOR_BY_POS',0,I,NISTColors<I>)
NEXT I

// Hide Cal/PM Class and Class column
ColumnStyles	= Send_Message( @WINDOW:'.EQUIPMENT', "COLSTYLE", 0, '' )
ColumnStyles<COL$EQ_CAL_CLASS>	= BitOr( ColumnStyles<COL$EQ_CAL_CLASS>, HIDDEN$ )	;* Column not used -> Hide
ColumnStyles<COL$EQ_CLASS>	= BitOr( ColumnStyles<COL$EQ_CLASS>, HIDDEN$ )	;* Column not used -> Hide
ColumnStyles	= Send_Message( @WINDOW:'.EQUIPMENT', "COLSTYLE", 0, ColumnStyles)

RETURN


* * * * * * *
EquipDC:
* * * * * * *

CtrlEntId = @WINDOW:'.EQUIPMENT'
RowData = Get_Property(CtrlEntId,'ROWDATA')
CLNo = RowData<COL$CL_NO>

obj_AppWindow('ViewRelated','CALIB_LIST':@RM:CLNo)

GOSUB Refresh

RETURN


* * * * * * *
NISTDC:
* * * * * * *

CtrlEntId = @WINDOW:'.NIST'

RowData = Get_Property(CtrlEntId,'ROWDATA')

CLNo = RowData<COL$CL_NO>


obj_AppWindow('ViewRelated','CALIB_LIST':@RM:CLNo)

GOSUB Refresh

RETURN


* * * * * * *
NewEquipment:
* * * * * * *

* * * * * * *
NewNIST:
* * * * * * *

thisFormWindowUp = Get_Property('CALIB_LIST','VISIBLE')	;* Returns 0 = hidden, 1 = visible, 2 = minimized, 3 = maximized 

IF thisFormWindowUp = ''	THEN Start_Window('CALIB_LIST',@WINDOW,thisFormParms)	;* Put up the card window - added thisFormParms 3/22/2010 JCH
IF thisFormWindowUp = 2		THEN Set_Property('CALIB_LIST','VISIBLE',9)				;* Restore the window if minimized

IF Get_Property('CALIB_LIST','SAVEWARN') THEN
	Set_Property('CALIB_LIST','@SKIP_CARD_RETURN',1)	;* This stops the Return behavior
	Send_Event('CALIB_LIST','CLEAR')					;* Clear anything existing (prompts for save first)
END

Send_Event('CALIB_LIST.NEW_ITEM','CLICK')


RETURN



* * * * * * *
PrintEquipment:
* * * * * * *


Title		= '':@VM:''
PageInfo	= .25:@FM:1.5:@FM:.25:@FM:0.6
PageSetup	= 1								;* Landscape
										
PrintSetup	= ''
PrintSetup<1,1>	= '2'	;* Preview Normal
PrintSetup<1,2> = '5'	;* Show Print and PDF, hide Print Setup
PrintSetup<1,3>	= '0'	;* Show the printing window
PDFParms = 'Printing PDF Document':@FM: '' :@FM:'':@FM: ''


PrintPath	= Printer_Select('')						;* Select printer without changing default printer

stat = Set_Printer("INIT",PDFParms,Title,PageInfo,PageSetup,PrintSetup,PrintPath)


font	= 'Arial'
font<2>	= '12'
font<3>	= 'L'
font<4> = '1'	;* Bold

stat = Set_Printer( 'FONT', font ); *send the Font to the printer

stat  = set_Printer('FONTHEADFOOT',font)


Header    = @VM:'MASTER CALIBRATION LIST'
Header<2> = @VM:"for Equipment as of 'D'"
Header<3> = ''
Header<4> = @VM:'All items must be calibrated by approved calibration suppliers.'
Header<5> = ' '
Header<6> = ' '

stat = Set_Printer( 'HEADER', header )

Location = -0.15:@FM:-1.150:@FM:1.57:@FM:1
stat = Set_Printer('BMP',obj_Install('Get_Prop','ColorBMP'),Location, 0,1)


colData = Get_Property(@WINDOW:'.EQUIPMENT','LIST')
colHead = Get_Property(@WINDOW:'.EQUIPMENT','LABEL')

CONVERT @FM TO @VM IN colHead

colFmt = '^+720'
colFmt<1,2> = '+720'
colFmt<1,3>  = '^+1800'
colFmt<1,4>  = '^+2160'
colFmt<1,5>  = '^+1440'
colFmt<1,6>  = '^+1440'
colFmt<1,7>  = '^+1080'
colFmt<1,8>  = '^+1440'
colFmt<1,9>  = '^+1440'
colFmt<1,10> = '^+1440'
colFmt<1,11> =  '^+1440'


font<2> = 10
font<4> = 1		;* Bold
stat = Set_Printer('FONT',font,'100')

stat = Set_Printer('ADDTABLE',colFmt,colHead,'',LTGREY$,'',0,TB_ALL)

font<4> = 0
stat = Set_Printer('FONT',font,fontSpacing)

stat = Set_Printer('ADDTABLE',colFmt,'',colData,LTGREY$,'',0,7)

stat = Set_Printer('TERM',1 )       
RETURN



* * * * * * *
PrintNIST:
* * * * * * *

FileName	= ''
Title		= '':@VM:''
PageInfo	= .25:@FM:1.5:@FM:.25:@FM:0.6
PageSetup	= 1											;* Landscape

PrintSetup	= ''
PrintSetup<1,1>	= '2'	;* Preview Normal
PrintSetup<1,2> = '5'	;* Show Print and PDF, hide Print Setup
PrintSetup<1,3>	= '0'	;* Show the printing window
PDFParms = 'Printing PDF Document':@FM: '' :@FM: 6 :@FM: ''


PrintPath	= Printer_Select('')						;* Select printer without changing default printer

stat = Set_Printer("INIT",PDFParms,Title,PageInfo,PageSetup,PrintSetup,PrintPath)


font	= 'Arial'
font<2>	= '12'
font<3>	= 'L'
font<4> = '1'	;* Bold

stat = Set_Printer( 'FONT', font ); *send the Font to the printer

stat  = set_Printer('FONTHEADFOOT',font)


Header    = @VM:'MASTER CALIBRATION LIST'
Header<2> = @VM:"for NIST / Primary Standards as of 'D'"
Header<3> = ''
Header<4> = @VM:'All items must be calibrated by approved'
Header<5> = @VM:'calibration suppliers as outlined in the Critical Materials List'
Header<6> = ' '

stat = Set_Printer( 'HEADER', header )

Location = -0.15:@FM:-1.150:@FM:1.57:@FM:1
stat = Set_Printer('BMP',obj_Install('Get_Prop','ColorBMP'),Location, 0,1)


colData = Get_Property(@WINDOW:'.NIST','LIST')
colHead = Get_Property(@WINDOW:'.NIST','LABEL')

CONVERT @FM TO @VM IN colHead

colFmt = '^+720'
colFmt<1,2> = '+1440'
colFmt<1,3>  = '^+1800'
colFmt<1,4>  = '^+2160'
colFmt<1,5>  = '^+2160'
colFmt<1,6>  = '^+1440'
colFmt<1,7>  = '^+1440'
colFmt<1,8>  = '^+1440'
colFmt<1,9>  = '^+1440'


font<2> = 10
font<4> = 1		;* Bold
stat = Set_Printer('FONT',font,'100')

stat = Set_Printer('ADDTABLE',colFmt,colHead,'',LTGREY$,'',0,TB_ALL)

font<4> = 0
stat = Set_Printer('FONT',font,fontSpacing)

stat = Set_Printer('ADDTABLE',colFmt,'',colData,LTGREY$,'',0,7)

stat = Set_Printer('TERM',1 )       

RETURN



