COMPILE FUNCTION Comm_WO_Step(Instruction, Parm1,Parm2)

/*
	Commuter module for WO_Step (Work Order Step) window
	
	11/11/2004 - John C. Henry, J.C. Henry & Co., Inc.
*/

DECLARE SUBROUTINE Set_Property,  Set_Status, ErrMsg, Set_Property, obj_AppWindow, obj_Notes, obj_RDS
DECLARE SUBROUTINE Btree.Extract, Send_Event, Security_Err_Msg, Forward_Event, End_Window, Start_Window
DECLARE SUBROUTINE obj_WO_Mat
DECLARE FUNCTION Get_Property, Get_Status, Popup, Send_Message, Msg, Security_Check, Dialog_Box, RowExists
DECLARE FUNCTION Dialog_Box, obj_WO_Log


$INSERT POPUP_EQUATES
$INSERT MSG_EQUATES
$INSERT APPCOLORS
$INSERT WO_LOG_EQU
$INSERT WO_STEP_EQU
$INSERT ORDER_EQU
$INSERT RDS_EQU
$INSERT LSL_USERS_EQU
$INSERT SECURITY_RIGHTS_EQU

EQU CRLF$	TO \0D0A\

EQU COL$QUOTE_DESC		TO 1
EQU COL$SETUP_CHG		TO 4
EQU COL$SRP_CHG			TO 5
EQU COL$WAFER_PRICE		TO 6

EQU COL$ADD_DESC		TO 1
EQU COL$ADD_AMT			TO 2



EQU COL$CASS_NO			TO 1
EQU COL$RDS_NO			TO 2
EQU COL$HOT_LOT			TO 3
EQU COL$STEP_COMMIT_DT	TO 4
EQU COL$HOLD			TO 5
EQU COL$MAKEUP_BOX		TO 6

EQU COL$RDS_STATUS		TO 13


ErrTitle = 'Error in Comm_WO_Step'
ErrorMsg = ''

Result = ''

BEGIN CASE
	CASE Instruction = 'Create' 		; GOSUB Create
	CASE Instruction = 'Refresh'		; GOSUB Refresh
	CASE Instruction = 'Page'			; GOSUB Page
	CASE Instruction = 'Read'			; GOSUB Read
	CASE Instruction = 'Write'			; GOSUB Write
	CASE Instruction = 'Clear'			; GOSUB Clear
	CASE Instruction = 'Delete'			; GOSUB Delete
	CASE Instruction = 'Close'			; GOSUB Close
	CASE Instruction = 'ViewProdSpec'	; GOSUB ViewProdSpec
	CASE Instruction = 'RdsDC'			; GOSUB RdsDC
	CASE Instruction = 'ChangeRDSVals'	; GOSUB ChangeRDSVals
	CASE Instruction = 'RefreshRDSSpec'	; GOSUB RefreshRDSSpec
	
	CASE 1
		ErrorMsg = 'Unknown Instruction passed to routine'
END CASE

RETURN Result


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

IF NOT(Security_Check('WO Log',READ$)) THEN
	Security_Err_Msg('WO Log',READ$)
	End_Window(@WINDOW)
	RETURN
END

obj_Appwindow('Create',@WINDOW)

* Provides compatibility with the existing messaging attachment system

IF Parm1 NE '' THEN
	PassedKeys = FIELD(Parm1,'*',1)
	obj_Appwindow('ViewRelated',@WINDOW:@RM:PassedKeys)
END

GOSUB Refresh

RETURN


* * * * * * *
Read:
* * * * * * *

WONo = Get_Property(@WINDOW:'.WO_NO','TEXT')

IF RowExists('WO_LOG',WONo) THEN
	IF NOT(Security_Check('Work Order',READ$)) THEN
		Send_Event(@WINDOW,'CLEAR')
		Security_Err_Msg('Work Order',READ$)
		RETURN
	END
END ELSE
	ErrMsg('Work Order Log entries may only be created from the ORDER window.')
	Send_Event(@WINDOW,'CLEAR')
	RETURN
END



GOSUB Refresh

RETURN


* * * * * * *
Write:
* * * * * * *

RETURN


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

Send_Event(@WINDOW,'PAGE',1)

GOTO Refresh

RETURN


* * * * * * *
Delete:
* * * * * * *

IF NOT(Security_Check('WO Log',DELETE$)) THEN
	Security_Err_Msg('WO Log',DELETE$)
	RETURN
END

Result = 0	;* OK to proceed with the delete

RETURN



* * * * * * *
Page:
* * * * * * *

obj_Appwindow('Page')

GOSUB Refresh

RETURN



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

obj_Notes('Inbox',@User4)

obj_Appwindow('DetailReturn')

RETURN 


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

* All cassette detail background colors

CtrlName = @WINDOW:'.CASSETTES'
CassArray = Get_Property(CtrlName,'INVALUE')
RdsStatuses = CassArray<COL$RDS_STATUS>	
FOR I = 1 TO COUNT(RdsStatuses,@VM) + (RdsStatuses NE '')
	RdsStatus	= RdsStatuses<1,I>
	RdsHold		= CassArray<COL$HOLD,I>
	RdsHotLot	= CassArray<COL$HOT_LOT,I>
	
	IF RdsHold OR RdsHotLot THEN
		IF RdsHold THEN LineColor = YELLOW$
		IF RdsHotLot THEN LineColor = RED$
	END ELSE
		BEGIN CASE
			CASE RdsStatus[1,3] = 'Rec'	; LineColor = RCV_BLUE$
			CASE RdsStatus[1,3] = 'Pre'	; LineColor = PRE_BLUE$
			CASE RdsStatus[1,3] = 'In '	; LineColor = INP_BLUE$
			CASE RdsStatus[1,3] = 'Pos'	; LineColor = POS_BLUE$
			CASE RdsStatus[1,3] = 'Rea' ; LineColor = GREEN$
			CASE RdsStatus[1,3] = 'Shi'	; LineColor = LTGREY$
			CASE RdsStatus[1,3] = 'Pro'	; LineColor = LTGREY$
			CASE RdsStatus[1,3] = 'Cas' ; LineColor = ORANGE$
			CASE RdsStatus[1,3] = 'Out'	; LineColor = RED$
			CASE RdsStatus[1,3] = 'Non'	; LineColor = RED$
			CASE RdsStatus[1,3] = 'Ope'	; LineColor = RED$
			CASE 1	; LineColor = WHITE$
		END CASE
	END
	stat = Send_Message(CtrlName,'COLOR_BY_POS',0,I,LineColor)
NEXT I




* QBF buttons

Ctrls  = @WINDOW:'.QBF_FIRST_FIX':@RM		; Props  = 'ENABLED':@RM
Ctrls := @WINDOW:'.QBF_PREV_FIX':@RM		; Props := 'ENABLED':@RM
Ctrls := @WINDOW:'.QBF_ABS_FIX':@RM			; Props := 'ENABLED':@RM
Ctrls := @WINDOW:'.QBF_NEXT_FIX':@RM		; Props := 'ENABLED':@RM
Ctrls := @WINDOW:'.QBF_LAST_FIX':@RM		; Props := 'ENABLED':@RM
Ctrls := @WINDOW:'.QBF_STOP_FIX'			; Props := 'ENABLED'

IF Get_Property(@WINDOW,'QBFLIST') = '' THEN
	Vals = 0:@RM:0:@RM:0:@RM:0:@RM:0:@RM:0
END ELSE
	Vals = 1:@RM:1:@RM:1:@RM:1:@RM:1:@RM:1
END

Set_Property(Ctrls,Props,Vals)

* Turn edit table symbolic column backgrounds to green

ETSymbolics = Get_Property(@WINDOW,'@ET_SYMBOLICS')		;* Loaded during 'Create' in obj_Appwindow

ETCtrls	= ETSymbolics<1>
ETCols	= ETSymbolics<2>

FOR I = 1 TO COUNT(ETCtrls,@VM) + (ETCtrls NE '')
	ETCtrl	= ETCtrls<1,I>
	IF ETCtrl NE @WINDOW:'.CASSETTES' THEN
		ETList = Get_Property(ETCtrl,'LIST')
		FOR Line = 1 TO COUNT(ETList,@FM) + (ETList NE '')
			IF ETList<Line,1> NE '' THEN
				FOR N = 1 TO COUNT(ETCols<1,I>,@SVM) + (ETCols<1,I> NE '')
					stat = Send_Message(ETCtrl,'COLOR_BY_POS',ETCols<1,I,N>,Line,GREEN$)
				NEXT N
			END
		NEXT Line
	END
NEXT I


RETURN



* * * * * * *
ViewProdSpec:
* * * * * * *

PSNo = Get_Property(@WINDOW:'.PS_NO','TEXT')

IF PSNo = '' THEN RETURN

obj_AppWindow('ViewRelated','PROD_SPEC':@RM:PSNo)

Send_Event(@WINDOW:'.PS_NO','LOSTFOCUS')	;* Kicks the symbolics

RETURN



* * * * * * *
RdsDC:
* * * * * * *

WOStepKey = Get_Property(@WINDOW,'ID')

IF WOStepKey = '' THEN RETURN

CtrlEntID = @WINDOW:'.CASSETTES'

CurrPos = Get_Property(CtrlEntID,'NOTIFYPOS')	;* Undocumented property that gives cell location when multi select is enabled.
CurrCol = CurrPos<1>
CurrRow = CurrPos<2>

RDSNo = Get_Property(CtrlEntID,'CELLPOS',2:@FM:CurrRow)

IF RDSNo NE '' THEN

	Set_Property(@WINDOW,'@RETURN_FROM_RDS',WOStepKey)		;* Bullshit lashup to work with multiple RDS windows

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

	IF thisFormWindowUp = ''	THEN
        If Get_Property('NDW_MAIN', 'VISIBLE') then
            AppMain = 'NDW_MAIN'
        end else
            AppMain = 'LSL_MAIN2'
        end
		Start_Window(thisFormName,AppMain,RDSNo:'*CENTER', '', '')	;* Put up the card window
		
		RETURN
	END
	
	IF thisFormWindowUp = 2		THEN Set_Property(thisFormName,'VISIBLE',9)	;* Restore the window if minimized

	IF Get_Property(thisFormName,'SAVEWARN') THEN
		Send_Event(thisFormName,'CLEAR')					;* Clear anything existing (prompts for save first)
	END
	
END

RETURN


* * * * * * * 
ChangeRDSVals:
* * * * * * *

WOStepKey = Get_Property(@WINDOW,'ID')

IF WOStepKey = '' THEN RETURN

CassList = Get_Property(@WINDOW:'.CASSETTES','LIST')

Send_Event(@WINDOW,'WRITE')

LOOP
	LastLine = CassList[-1,'B':@FM]
UNTIL LastLine<1,1> NE '' OR LastLine = ''
	CassList[COL1(),COL2()] = ''
REPEAT

CassCnt = COUNT(CassList,@FM) + (CassList NE '')

WONo = WOStepKey[1,'*']

CassetteList	= ''
WOMatKeys		= ''
FOR I = 1 TO CassCnt
	CassetteList<I> = FIELD(CassList<I>,@VM,1,6)
	WOMatKeys<1,I> = WONo:'*':CassList<I,1>
NEXT I

Result = Dialog_Box('DIALOG_RDS_VAL_CHANGE',@WINDOW,CassetteList)

IF Result = 'Cancel' THEN RETURN

RDSNos		= Result[1,@FM]
CommitDts	= Result[COL2()+1,@FM]
HotLots		= Result[COL2()+1,@FM]
MUBoxes		= Result[COL2()+1,@FM]
CassNos		= Result[COL2()+1,@FM]

obj_RDS('ChangeWOStepProps',RDSNos:@RM:CommitDts:@RM:HotLots:@RM:MUBoxes)

CassCnt = COUNT(CassNos,@VM) + (CassNos NE '')
WOMatKeys = ''
FOR I = 1 TO CassCnt
	WOMatKeys<1,I> = WONo:'*':CassNos<1,I>
NEXT I


obj_WO_Mat('ChangeCassProps',WOMatKeys:@RM:HotLots:@RM:MUBoxes)

IF Get_Status(errCode) THEN ErrMsg(errCode)

obj_AppWindow('LoadFormKeys',@WINDOW:@RM:WOStepKey)


RETURN



* * * * * * *
RefreshRDSSpec:
* * * * * * *

WOStepKey = Get_Property(@WINDOW,'ID')

IF WOStepKey = '' THEN RETURN

Send_Event(@WINDOW,'WRITE')

RDSNos = XLATE('WO_STEP',WOStepKey,WO_STEP_RDS_KEY$,'X')

OperatorIns = XLATE('RDS',RDSNos,RDS_OPERATOR_IN$,'X')

DispRDSNos = ''
FOR I = 1 TO COUNT(RDSNos,@VM) + (RDSNos NE '')
	IF OperatorIns<1,I> = '' THEN
		DispRdsNos<1,-1> = RdsNos<1,I>
	END
NEXT I

TypeOver = ''
TypeOver<PDISPLAY$> = DispRdsNos
TypeOver<PTITLE$>	= 'Refresh RDS Product Specification Information - Cassettes Awaiting Processing'

RdsNos = Popup(@WINDOW,TypeOver,'RDS_PRINT_CLEANROOM_LABELS')

IF RdsNos NE '' THEN

	obj_RDS('RefreshRDSSpec',RdsNos)

	IF Get_Status(errCode) THEN
		ErrMsg(errCode)
	END
END

obj_AppWindow('LoadFormKeys',@WINDOW:@RM:WOStepKey)

RETURN

















