COMPILE FUNCTION Comm_WO_Prod_EPI(Instruction, Parm1,Parm2)

/*
	Commuter module for WO_Prod_EPI, Read Only WO Step window for production use (Work Order Step) Work Order step table
	
	11/11/2004 - John C. Henry, J.C. Henry & Co., Inc.
	03/20/2019 - DJS - Updated "CreateRDS" subroutine to use Work_Order_Services instead of obj_WO_LOG to avoid
	                   locking WO_LOG database table unnecessarily.
*/

DECLARE SUBROUTINE Set_Property,  Set_Status, ErrMsg, Set_Property, obj_AppWindow, obj_Notes, obj_WM_Out
DECLARE SUBROUTINE Error_Services, obj_Post_Log, obj_SAP, Print_Control_Plan, Send_Info, ShowWindow
DECLARE SUBROUTINE Btree.Extract, Send_Event, Security_Err_Msg, Forward_Event, End_Window, Start_Window
DECLARE FUNCTION Get_Property, Get_Status, Popup, Send_Message, Msg, Security_Check, Dialog_Box, RowExists
DECLARE FUNCTION Dialog_Box, obj_WO_Log, obj_RDS, obj_WM_Out,obj_React_Run, Set_Property, MemberOf
DECLARE FUNCTION Work_Order_Services, Error_Services


$INSERT POPUP_EQUATES
$INSERT LOGICAL
$INSERT MSG_EQUATES
$INSERT APPCOLORS
$INSERT WO_LOG_EQUATES
$INSERT WO_STEP_EQU
$INSERT WO_MAT_EQUATES
$INSERT WM_OUT_EQUATES
$INSERT ORDER_EQU
$INSERT ORDER_DET_EQU
$INSERT QUOTE_SPEC_EQU
$INSERT PROD_SPEC_EQUATES
$INSERT PRS_STAGE_EQUATES
$INSERT EPI_PART_EQUATES
$INSERT LSL_USERS_EQU
$INSERT SECURITY_RIGHTS_EQU
$INSERT QUOTE_SIGS_EQU
$INSERT RTI_STYLE_EQUATES

Equ HIDE$ To 0
Equ NORMAL$ To 1
Equ MINIMIZE$ To 2
Equ MAXIMIZE$ To 3


EQU CRLF$	TO \0D0A\

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

EQU COL$WM_IN_CASS_NO	TO 1
EQU COL$WM_IN_BLANK		TO 2
EQU COL$WM_IN_QTY		TO 3
EQU COL$WM_IN_REJ		TO 4
EQU COL$WM_IN_REMAINING	TO 5
EQU COL$WM_IN_STATUS	TO 6

EQU COL$RUN_NO			TO 1
EQU COL$RDS_NO			TO 2
EQU COL$REACTOR			TO 3
EQU COL$ZONE1			TO 4
EQU COL$ZONE2			TO 5
EQU COL$SCHED			TO 6
EQU COL$PTEST			TO 7
EQU COL$UNLOAD			TO 8
EQU COL$RDS_STATUS		TO 9

EQU COL$WM_OUT_STATUS	TO 8

ErrTitle = 'Error in Comm_WO_Log'
ErrorMsg = ''

Result = ''

If Get_Property('NDW_MAIN', 'VISIBLE') then
    AppMain = 'NDW_MAIN'
end else
    AppMain = 'LSL_MAIN2'
end

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 = 'GotFocus'			; GOSUB GotFocus
    CASE Instruction = 'WONoLF'				; GOSUB WONoLF
    CASE Instruction = 'StepGF'				; GOSUB StepGF
    CASE Instruction = 'OpenWOS'			; GOSUB OpenWOS
    CASE Instruction = 'ViewProdSpec'		; GOSUB ViewProdSpec
    CASE Instruction = 'RdsDC'				; GOSUB RdsDC
    CASE Instruction = 'LUWONo'				; GOSUB LUWONo
    CASE Instruction = 'BrowseRDS'			; GOSUB BrowseRDS
    CASE Instruction = 'WMInDC'				; GOSUB WMInDC
    CASE Instruction = 'WMOutDC'			; GOSUB WMOutDC
    CASE Instruction = 'CreateRDS'			; GOSUB CreateRDS
    CASE Instruction = 'ViewPSN'			; GOSUB ViewPSN
    CASE Instruction = 'RemWMOut'			; GOSUB RemWMOut
    CASE Instruction = 'WaferTrace'			; GOSUB WaferTrace
    CASE Instruction = 'ControlPlanClick'	; GOSUB ControlPlanClick
    CASE 1
        ErrorMsg = 'Unknown Instruction passed to routine'
END CASE

RETURN Result


* * * * * * * 
Create:
* * * * * * *
    
    obj_Appwindow('Create',@WINDOW)
    
    QuoteSigs = XLATE( 'CONFIG', 'QUOTE_SIGS','', 'X' )
    
    IF @USER4 = QuoteSigs<ProdCtrlMgr$> OR MemberOf(@USER4, 'OI_SUPERUSER') THEN
        Set_Property(@WINDOW:'.REM_CASSETTES','VISIBLE',1)
        Set_Property(@WINDOW:'.REM_WM_OUT','VISIBLE',1)
    END ELSE
        Set_Property(@WINDOW:'.REM_CASSETTES','VISIBLE',0)
        Set_Property(@WINDOW:'.REM_WM_OUT','VISIBLE',0)
    END
    
    GOSUB Refresh
    
RETURN


* * * * * * *
Read:
* * * * * * *
    
    WONo = Get_Property(@WINDOW:'.WO_NO','TEXT')
    
    IF RowExists('WO_LOG',WONo) ELSE
        ErrMsg('Incorrect Work Order Number entered.')
        Send_Event(@WINDOW,'CLEAR')
        RETURN
    END
    
    GOSUB Refresh
    
RETURN


* * * * * * *
Write:
* * * * * * *
    
RETURN


* * * * * * *
Clear:
* * * * * * *
    
    Send_Event(@WINDOW,'PAGE',1)
    
    GOTO Refresh
    
RETURN


* * * * * * *
Delete:
* * * * * * *
    
RETURN



* * * * * * *
Page:
* * * * * * *
    
    obj_Appwindow('Page')
    
    GOSUB Refresh
    
RETURN



* * * * * * *
Close:
* * * * * * *
    
    obj_Appwindow('DetailReturn')
    
RETURN 



* * * * * * *
GotFocus:
* * * * * * *
    
    WOStepKey = Get_Property(@WINDOW,'@RETURN_FROM_RDS')
    
    IF WOStepKey NE '' THEN
        Set_Property(@WINDOW,'@RETURN_FROM_RDS','')
        Send_Event(@WINDOW,'READ')
    END
    
RETURN


* * * * * * *
WONoLF:
* * * * * * *
    
    DataValue = Get_Property(@WINDOW:'.WO_NO','TEXT')
    
    If DataValue = '' Then RETURN
    
    IF INDEX(DataValue,'.',1)  THEN
        * Try a BTREE lookup on PROD_ORD_NO
        
        OPEN 'DICT.WO_LOG' TO DictVar ELSE
            ErrMsg('Unable to open "DICT.WO_LOG" for index lookup in COMM_SHIPMENT routine.')
            RETURN
        END
        
        SearchString  = 'PROD_ORD_NO':@VM:DataValue:@FM
        WONos = ''
        Flag = ''
        Btree.Extract(SearchString, 'WO_LOG', DictVar, WONos, '', Flag)
        errCode = ''
        IF Get_Status(errCode) THEN
            ErrMsg(errCode)
            RETURN
        END
        
        IF WONos = '' THEN 
            ErrMsg('Value Entered "':DataValue:'" is not found.')
            Result = 0
            RETURN
        END
        
        IF INDEX(WONos,@VM,1) THEN
            * This is an error
            ErrMsg('Multiple Work Orders ':QUOTE(DataValue):' for Prod Order entered.')
            Result = 0
            RETURN
            
        END ELSE
            Set_Property(@WINDOW:'.WO_NO','DEFPROP',WONos)
        END
        
        Result = 1
        
    END ELSE
        IF RowExists('WO_LOG', DataValue) THEN
            Result = 1
        END ELSE
            Message = QUOTE(DataValue):' is not a valid WO No'
            ErrMsg(Message)
            
            Set_Property(@WINDOW:'.WO_NO','DEFPROP','')
            
            Result = 0
        END
    END
    
RETURN



* * * * * * *
Refresh:
* * * * * * *
    
    PSStatus = Get_Property(@WINDOW:'.PS_STATUS','TEXT')
    IF PSStatus = 'Active' THEN
        Set_Property(@WINDOW:'.PS_STATUS','BACKCOLOR',GREEN$)
    END ELSE
        Set_Property(@WINDOW:'.PS_STATUS','BACKCOLOR',RED$)
    END
    
    * WM_IN background colors
    
    CtrlName = @WINDOW:'.WM_IN'
    WMInArray = Get_Property(CtrlName,'INVALUE')
    
    WMInStatuses = WMInArray<COL$WM_IN_STATUS>	
    FOR I = 1 TO COUNT(WMInStatuses,@VM) + (WMInStatuses NE '') 
        WMInStatus	= WMInStatuses<1,I>
        
        BEGIN CASE
            CASE WMInStatus = 'Ready to Build'			; LineColor = RCV_BLUE$
            CASE WMInStatus = 'Building'				; LineColor = PRE_BLUE$
            CASE WMInStatus = 'Cond Post Clean' 		; LineColor = INP_BLUE$
            CASE WMInStatus = 'Ready to Post Clean' 	; LineColor = INP_BLUE$
            CASE WMInStatus = 'Ready for QA'			; LineColor = POS_BLUE$
            CASE WMInStatus = 'Ready to Use'			; LineColor = GREEN$
            CASE WMInStatus = 'Ready to Ship'			; LineColor = GREEN$
            CASE WMInStatus = 'Shipped'					; LineColor = LTGREY$
            CASE WMInStatus = 'Empty' 					; LineColor = LTGREY$
            CASE WMInStatus = 'On Hold'					; LineColor = RED$
            CASE WMInStatus = 'Open NCR' 				; LineColor = RED$
            CASE WMInStatus = 'Cassette Rejected'		; LineColor = ORANGE$
            CASE 1	; LineColor = WHITE$
        END CASE
        
        stat = Send_Message(CtrlName,'COLOR_BY_POS',0,I,LineColor)
    NEXT I
    
    * All cassette detail background colors
    
    
    CtrlName = @WINDOW:'.RUNS'
    CassArray = Get_Property(CtrlName,'ARRAY')
    RdsStatuses = CassArray<COL$RDS_STATUS>	
    FOR I = 1 TO COUNT(RdsStatuses,@VM) + (RdsStatuses NE '')
        RdsStatus	= RdsStatuses<1,I>
        a = RdsStatus[-1,8]
        a1 = RdsStatus[-1,9]
        BEGIN CASE
            CASE RdsStatus[-3,3] 		= 'Run'									; LineColor = RCV_BLUE$		;* Ready to Run
            CASE RdsStatus[10,3]	= 'Pre'									; LineColor = PRE_BLUE$		;* xxx Pre Clean, Pre SurfaceInspect, Pre Surf Scan
            CASE RdsStatus[10,4]	= 'Load'								; LineColor = INP_BLUE$		;* xxx Load
            CASE RdsStatus[1,6]		= 'Loaded'								; LineColor = GREEN$		;* Loaded
            CASE RdsStatus[-8,8]	= 'Met Comp'							; LineColor = LTGREY$		;* EpiPRO Unloaded
            CASE RdsStatus[-9,9]    = 'Needs Met'							; LineColor = YELLOW$		;* EpiPro Unloaded Nees Metrology
                
            CASE RdsStatus[1,7]		= 'Post'								; LineColor = POS_BLUE$
                
            CASE RdsStatus[1,3]	= 'Epi'	and RdsStatus[-6,6] = 'Loaded'		; LineColor = ORANGE$		;* EpiPRO Test
            CASE RdsStatus[1,3]	= 'Epi'	and RdsStatus[-8,8] = 'Unloaded'	; LineColor = LTORANGE$		;* EpiPRO Test
            CASE RdsStatus[10,2]	= 'QA'									; LineColor = YELLOW$		;* xxx QA
            CASE RdsStatus[1,2]		= 'QA'									; LineColor = LTGREY$		;* QA Complete
            CASE RdsStatus[1,4]		= 'Canc' 								; LineColor = LTGREY$
            CASE RdsStatus[1,3]		= 'Void'								; LineColor = LTGREY$
            CASE RdsStatus[1,3] 	= 'Out'									; LineColor = RED$
            CASE 1	; LineColor = WHITE$
        END CASE
        
        stat = Send_Message(CtrlName,'COLOR_BY_POS',0,I,LineColor)
    NEXT I
    
    * WM_OUT background colors
    
    CtrlName = @WINDOW:'.WM_OUT'
    WMOutArray = Get_Property(CtrlName,'INVALUE')
    
    WMOutStatuses = WMOutArray<COL$WM_OUT_STATUS>	
    FOR I = 1 TO COUNT(WMOutStatuses,@VM) + (WMOutStatuses NE '')
        WMOutStatus	= WMOutStatuses<1,I>
        
        BEGIN CASE
            CASE WMOutStatus = 'Ready to Build'			; LineColor = RCV_BLUE$
            CASE WMOutStatus = 'Building'				; LineColor = PRE_BLUE$
            CASE WMOutStatus = 'PostEpi Clean'	 		; LineColor = INP_BLUE$
            CASE WMOutStatus = 'PostEpi Surfscan' 		; LineColor = INP_BLUE$
            CASE WMOutStatus = 'PostEpi Inspection'		; LineColor = POS_BLUE$
            CASE WMOutStatus = 'Ready for QA'			; LineColor = POS_BLUE$
            CASE WMOutStatus = 'Ready to Use'			; LineColor = MU_GREEN$
            CASE WMOutStatus = 'QA Complete'			; LineColor = YELLOW$
            CASE WMOutStatus = 'Ready to Ship'			; LineColor = GREEN$
            CASE WMOutStatus = 'Shipped'				; LineColor = LTGREY$
            CASE WMOutStatus = 'Empty' 					; LineColor = LTGREY$
            CASE WMOutStatus = 'Void'					; LineColor = GREY$
            CASE WMOutStatus = 'On Hold'				; LineColor = RED$
            CASE WMOutStatus = 'Open NCR' 				; LineColor = RED$
            CASE WMOutStatus = 'Cassette Rejected'		; LineColor = ORANGE$
            CASE 1	; LineColor = WHITE$
        END CASE
        
        stat = Send_Message(CtrlName,'COLOR_BY_POS',0,I,LineColor)
    NEXT I
    
    
    Ctrls  = @WINDOW:'.TOT_ORD_ITEM_QTY':@RM		; Props  = 'INVALUE':@RM
    Ctrls := @WINDOW:'.TOT_PRE_EPI_REJ':@RM			; Props := 'INVALUE':@RM
    Ctrls := @WINDOW:'.TOT_RDS_PROD_TEST':@RM		; Props := 'INVALUE':@RM
    Ctrls := @WINDOW:'.TOT_WFRS_OUT':@RM			; Props := 'INVALUE':@RM
    Ctrls := @WINDOW:'.TOT_MU_WFRS_OUT':@RM			; Props := 'INVALUE':@RM
    Ctrls := @WINDOW:'.TOT_POST_EPI_REJ'			; Props := 'INVALUE'
    
    Vals = Get_Property(Ctrls,Props)
    
    OrdQty		= Vals[1,@RM]
    PreEpiRej	= Vals[COL2()+1,@RM]
    ProdTest	= Vals[COL2()+1,@RM]
    WfrsOut		= Vals[COL2()+1,@RM]
    MUWfrsOut	= Vals[COL2()+1,@RM]
    PostEpiRej	= Vals[COL2()+1,@RM]
    
    * This section re-written 11/22/2011 JCH
    
    WONo 	= Get_Property(@WINDOW:'.WO_NO','DEFPROP')
    StepNo	= Get_Property(@WINDOW:'.PROC_STEP_NO','DEFPROP')
    
    WOLogRec = XLATE('WO_LOG',WONo,'','X')
    WOMatKeys = WOLogRec<WO_LOG_WO_MAT_KEY$>
    
    WOWfrQty	= SUM(XLATE('WO_MAT',WOMatKeys,WO_MAT_WAFER_QTY$,'X'))
    WOOrderQty	= XLATE('WO_LOG',WONo,'TOT_ORD_ITEM_QTY','X')
    
    IF WOOrderQty = 0 THEN
        WOOrderQty = XLATE('WO_LOG',WONo,'WO_QTY','X')
    END
    
    WOLoadCnt	= SUM(XLATE('WO_MAT',WOMatKeys,'WMI_RDS_LOAD_CNT','X'))
    WOPreEpiRej	= SUM(XLATE('WO_MAT',WOMatKeys,'WM_IN_REJ_WFRS','X'))
    
    RRunNos	= XLATE('WO_STEP',WONo:'*':StepNo,6,'X')
    WOUnloadCnt	= SUM(XLATE('REACT_RUN',RRunNos,'EPI_PRO_UNLD_CNT','X'))
    WOPTCnt		= SUM(XLATE('REACT_RUN',RRunNos,'EPI_PRO_PT_CNT','X'))
    
    IF WOLoadCnt > 0 THEN
        OrdPcntComp = ICONV(((WOPreEpiRej + WOUnloadCnt + WOPTCnt)/WOOrderQty)*100,'MD0')
        WipPcntComp = ICONV(((WOPreEpiRej + WOUnloadCnt + WOPTCnt)/WOWfrQty)*100,'MD0')
        
    END ELSE
        OrdPcntComp = 0
        WipPcntComp = 0
    END
    
    
    OrdPcntComp = 'Order - ':OCONV(OrdPcntComp,'MD0S%')
    WipPcntComp = 'WIP   - ':OCONV(WipPcntComp,'MD0S%')
    
    Set_Property(@WINDOW:'.ORDER_PCNT','DEFPROP',OrdPcntComp)
    Set_Property(@WINDOW:'.WIP_PCNT','DEFPROP',WipPcntComp)
    
    * SAP interface update
    
    IF WONo NE '' THEN
        
        IF WOLogRec<WO_LOG_WO_START_DTM$> = '' OR WOLogRec<WO_LOG_WO_STOP_DTM$> = '' THEN
            
            CurrDTM		= ICONV(OCONV(Date(),'D4/'):' ':OCONV(Time(),'MTH') ,'DT')
            ProdOrderNo	= WOLogRec<WO_LOG_PROD_ORD_NO$>
            
            IF ProdOrderNo NE '' THEN
                IF WOLoadCnt >= 1 AND WOLogRec<WO_LOG_WO_START_DTM$> = '' THEN
                    obj_Post_Log('Create','WO_LOG':@RM:WONo:@RM:WO_LOG_WO_START_DTM$:@RM:CurrDTM)
                END	
                
                IF (WOPreEpiRej + WOUnloadCnt + WOPTCnt) >= WOOrderQty AND WOLogRec<WO_LOG_WO_STOP_DTM$> = '' THEN
                    obj_Post_Log('Create','WO_LOG':@RM:WONo:@RM:WO_LOG_WO_STOP_DTM$:@RM:CurrDTM)
                END
            END
            
        END	;* End of check for WO_START and WO_STOP DTM's in WO Log record	
    END
    
    
    * End of rewrite JCH
    
    
    
    * 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:'.RUNS' AND ETCtrl NE @WINDOW:'.WM_OUT' AND ETCtrl NE @WINDOW:'.WM_IN' 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
    
    hWnd = Get_Property(@WINDOW, "HANDLE")
    ShowWindow(hWnd, NORMAL$)
    
RETURN


* * * * * * *
LUWONo:
* * * * * * *
    
    Set_Status(0)
    
    WOKeys = obj_WO_Log('Find')	
    
    IF Get_Status(errCode) THEN ErrMsg(ErrCode)
    
    IF WOKeys NE '' THEN
        TypeOver = ''
        TypeOver<PDISPLAY$> = WOKeys
        TypeOver<PMODE$> = 'K'
        TypeOver<PSELECT$> = 1
        
        WOKey = Popup(@WINDOW,TypeOver,'WO_LOG_QUERY')
        IF Get_Status(errCode) THEN
            ErrMsg(errCode)
        END
        
        IF WOKey NE '' THEN obj_Appwindow('LUValReturn',WOKey:@RM:@WINDOW:'.WO_NO':@RM:'')		;* Loads form key or QBFList as required
    END
RETURN



* * * * * * *
StepGF:
* * * * * * *
    
    WONo = Get_Property(@WINDOW:'.WO_NO','TEXT')
    WOStep = Get_Property(@WINDOW:'.PROC_STEP_NO','TEXT')
    
    IF WONo NE '' AND WOStep = '' THEN
        WOStepKeys = XLATE('WO_LOG',WONo,WO_LOG_WO_STEP_KEY$,'X')
        
        IF INDEX(WOStepKeys,@VM,1) THEN
            LastStep = WOStepKeys[-1,'B':@VM]
            WOStep = FIELD(LastStep,'*',2)
            
        END ELSE
            WOStep = FIELD(WOStepKeys,'*',2)
        END
        CurrControl = @WINDOW:'.PROC_STEP_NO'
        CurrPos	= ''
        obj_Appwindow('LUValReturn',WOStep:@RM:CurrControl:@RM:CurrPos)
    END
    
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


* * * * * * * 
OpenWOS:
* * * * * * *
    
    IF Get_Property(@WINDOW:'.WO_NO','TEXT') NE '' THEN
        Send_Event(@WINDOW,'CLEAR')
    END
    
    OpenWONo = obj_WO_Log('OpenWONos','')
    
    IF OpenWONo NE '' THEN
        obj_AppWindow('LoadFormKeys',@WINDOW:@RM:OpenWONo)
    END
    
RETURN


* * * * * * *
RdsDC:
* * * * * * *
    
    CtrlEntID = @WINDOW:'.RUNS'
    
    CurrPos = Get_Property(CtrlEntID,'SELPOS')
    CurrCol = CurrPos<1>
    CurrRow = CurrPos<2>
    
    RDSNo = Get_Property(CtrlEntID,'CELLPOS',COL$RDS_NO:@FM:CurrRow)
    
    WONo = Get_Property(@WINDOW:'.WO_NO','DEFPROP')
    WOStep = Get_Property(@WINDOW:'.PROC_STEP_NO','DEFPROP')
    
    IF WONo = '' OR WOStep = '' THEN RETURN
    
    WOStepKey = WONo:'*':WOStep
    
    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
            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


* * * * * * *
BrowseRDS:
* * * * * * *
    
    WONo = Get_Property(@WINDOW:'.WO_NO','TEXT')
    StepNo = Get_Property(@WINDOW:'.PROC_STEP_NO','TEXT')
    
    IF WONo NE '' AND StepNo NE '' THEN
        WOStepKey = WONo:'*':StepNo
    END ELSE
        RETURN
    END
    
    CtrlEntID = @WINDOW:'.RUNS'
    
    CurrPos = Get_Property(CtrlEntID,'SELPOS')
    CurrCol = CurrPos<1>
    CurrRow = CurrPos<2>
    
    RDSNos = Get_Property(CtrlEntID,'ARRAY')<2>	;* Multivalue list of RDS Nos
    
    LOOP
        TestChar = RDSNos[-1,1]
    UNTIL TestChar NE @VM OR RDSNos = ''
        RDSNos[-1,1] = ''
    REPEAT
    
    IF RDSNos = '' THEN RETURN
    
    WONo    = Get_Property(@Window:'.WO_NO', 'TEXT')
    RDSKeys = Dialog_Box('NDW_RDS_QUERY', @Window, WONo)
    
    IF RDSKeys = '' THEN RETURN
    
    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
        Start_Window(thisFormName,AppMain,RDSKeys:'*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
    
RETURN



* * * * * * *
WMInDC:
* * * * * * *
    
    CtrlEntID = @WINDOW:'.WM_IN'
    
    CurrPos = Get_Property(CtrlEntID,'SELPOS')
    CurrCol = CurrPos<1>
    CurrRow = CurrPos<2>
    
    WONo	= Get_Property(@WINDOW:'.WO_NO','DEFPROP')
    StepNo	= Get_Property(@WINDOW:'.PROC_STEP_NO','DEFPROP')
    CassNo	= Get_Property(CtrlEntID,'CELLPOS',1:@FM:CurrRow)
    
    IF WONo NE '' AND StepNo NE '' AND CassNo NE '' THEN
        
        DetWindow	= 'WM_IN'
        DetKeys		= WONo:'*':StepNo:'*':CassNo
        DefaultRec	= ''
        RetKey		= WONo:'*':StepNo
        RetPage		= 1
        RetCtrl		= CtrlEntID
        RetPos		= CurrPos
        
        oAParms = DetWindow:@RM:DetKeys:@RM:DefaultRec:@RM:RetKey:@RM:RetPage:@RM:RetCtrl:@RM:RetPos
        
        obj_AppWindow('ViewNewDetail',oAParms)
        
        IF Get_Status(errCode) THEN
            ErrMsg(errCode)
        END
        
    END
    
RETURN


* * * * * * *
WMOutDC:
* * * * * * *
    
    CtrlEntID = @WINDOW:'.WM_OUT'
    
    CurrPos = Get_Property(CtrlEntID,'SELPOS')
    CurrCol = CurrPos<1>
    CurrRow = CurrPos<2>
    
    WONo	= Get_Property(@WINDOW:'.WO_NO','DEFPROP')
    StepNo	= Get_Property(@WINDOW:'.PROC_STEP_NO','DEFPROP')
    CassNo	= Get_Property(CtrlEntID,'CELLPOS',1:@FM:CurrRow)
    
    IF WONo NE '' AND StepNo NE '' AND CassNo NE '' THEN
        
        DetWindow	= 'WM_OUT'
        DetKeys		= WONo:'*':StepNo:'*':CassNo
        DefaultRec	= ''
        RetKey		= WONo:'*':StepNo
        RetPage		= 1
        RetCtrl		= CtrlEntID
        RetPos		= CurrPos
        
        oAParms = DetWindow:@RM:DetKeys:@RM:DefaultRec:@RM:RetKey:@RM:RetPage:@RM:RetCtrl:@RM:RetPos
        
        obj_AppWindow('ViewNewDetail',oAParms)
        IF Get_Status(errCode) THEN
            ErrMsg(errCode)
        END
        
    END
    
RETURN


* * * * * * *
CreateRDS:
* * * * * * *
    
    CtrlEntID = @WINDOW:'.RUNS'
    
    WONo	= Get_Property(@WINDOW:'.WO_NO','DEFPROP')
    WOStep	= Get_Property(@WINDOW:'.PROC_STEP_NO','DEFPROP')
    
    IF WONo = '' OR WOStep = '' THEN RETURN
    
    WMInRem	= Get_Property(@WINDOW:'.WM_IN','ARRAY')<COL$WM_IN_REMAINING>		;* Just need remaining wafers column
    
    FOR NextCassNo = 1 TO COUNT(WMInRem,@VM) + (WMInRem NE '')
    UNTIL WMInRem<1,NextCassNo> > 0 
    NEXT NextCassNo
    
    // 3/20/2019 - DJS - Deprecated to avoid locking WO_LOG table unnecessarily.
    * RunNo = obj_WO_Log('NextWORun',WONo:@RM:WOStep)							;* New RDS Run order number
    * IF Get_Status(errCode) THEN
    * 	ErrMsg(errCode)
    * 	RETURN
    * END
    
    RunNo = Work_Order_Services('GetNextRunNo', WONo, WOStep)
    If Error_Services('HasError') then
        ErrorMsg = Error_Services('GetMessage')
        ErrMsg('An error occurred creating an RDS. Please contact FI Support. ':ErrorMsg)
        Return
    end
    
    IF RunNo = '' THEN RETURN
    
    WOMatRec = XLATE('WO_MAT',WONo:'*':NextCassNo,'','X')
    
    CassLotNo 		= WOMatRec<WO_MAT_LOT_NO$>					
    CassWaferQty	= '0'										
    CassPartNo		= WOMatRec<WO_MAT_CUST_PART_NO$>					
    CassSubPartNo	= WOMatRec<WO_MAT_SUB_PART_NO$>				
    CassSubInvID	= ''										;* This isn't being used
    CassOrderItem	= WOMatRec<WO_MAT_ORDER_ITEM$>				
    CassSubVendCode = WOMatRec<WO_MAT_SUB_VEND_CD$>
    
    WORec = XLATE('WO_LOG',WONo,'','X')
    
    OrderNo 		= WORec<WO_LOG_ORDER_NO$>
    CustNo			= WORec<WO_LOG_CUST_NO$>
    PromiseDt		= WORec<WO_LOG_PROMISE_SHIP_DT$>
    
    PONo			= XLATE('ORDER',OrderNo,ORDER_PO_NO$,'X')
    
    QuoteNo	= XLATE('ORDER_DET',OrderNo:'*':CassOrderItem,ORDER_DET_QUOTE_NO$,'X')			
    
    WOStepCnt = COUNT(WORec<WO_LOG_WO_STEP_KEY$>,@VM) + (WORec<WO_LOG_WO_STEP_KEY$> NE '')
    WOStepKey = WONo:'*':WOStep
    
    IF WOStepKey = WORec<WO_LOG_WO_STEP_KEY$>[-1,'B':@VM] THEN
        LastStep = 1
    END ELSE
        LastStep = 0
    END
    
    PSN = XLATE('WO_STEP',WOStepKey,WO_STEP_PROD_SPEC_ID$,'X')
    
    *SubstrateSpec	= XLATE('PROD_SPEC',PSN,PROD_SPEC_SPEC_SUBSTRATE$,'X')
    ReactorType 	= XLATE('PROD_SPEC',PSN,PROD_SPEC_REACTOR_TYPE$,'X')		;* Not used in program JCH 8/28/2014
    
    EpiPN = XLATE('WO_LOG',WONo,WO_LOG_EPI_PART_NO$,'X')
    
    SubSupplyBy		= XLATE('EPI_PART',EpiPN,EPI_PART_SUB_SUPP_BY$,'X')			;*SubstrateSpec<1,QSSubWafersSupBy$>
    SubPreClean		= XLATE('PRS_STAGE',PSN:'*PRE',PRS_STAGE_CLEAN_TOOL$,'X')	;*SubstrateSpec<1,QSSubPreClean$>
    SubPostClean	= XLATE('PRS_STAGE',PSN:'*POST',PRS_STAGE_CLEAN_TOOL$,'X')	;*SubstrateSpec<1,QSSubPostClean$>
    
    OrgColor = Set_Property(@WINDOW:'.STATUS_LINE','BACKCOLOR',YELLOW$)
    
    Parms  = WONo:@RM
    Parms := WOStep:@RM
    Parms := LastStep:@RM
    Parms := RunNo:@RM						; * Was CassNo -> Verify what happens in obj_RDS('Create'...) with this number
    Parms := QuoteNo:@RM
    Parms := OrderNo:@RM
    Parms := CassOrderItem:@RM
    Parms := CustNo:@RM
    Parms := PONo:@RM 
    Parms := PSN:@RM
    Parms := SubSupplyBy:@RM
    Parms := SubPreClean:@RM
    Parms := SubPostClean:@RM
    Parms := PromiseDt:@RM 
    Parms := CassLotNo:@RM
    Parms := CassPartNo:@RM
    Parms := CassWaferQty:@RM
    Parms := CassSubPartNo:@RM
    Parms := '':@RM				; // QXJ flag
    Parms := CassSubVendCode
    
    RDSNo = obj_RDS('Create',Parms)
    
    IF Get_Status(errCode) THEN
        ErrMsg(errCode)
        obj_Appwindow('LoadFormKeys',@WINDOW:@RM:WOStepKey)
        RETURN
    END
    
    Send_Info(STR(' ',100))	
    
    Dummy = Set_Property(@WINDOW:'.STATUS_LINE','BACKCOLOR',OrgColor)
    
    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
            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

* * * * * * *
ViewPSN:
* * * * * * *
    
    IF Security_Check( 'Prod Spec', Read$ ) THEN
        PSNo = Get_Property(@WINDOW:'.PROD_SPEC_ID','DEFPROP')
        IF PSNo = '' THEN RETURN
    END ELSE
        Security_Err_Msg( 'Prod Spec', Read$ )
        RETURN
    END
    
    Start_Window ( 'PROD_SPEC', @WINDOW, PSNo:'*CENTER', '', '' )		;* This is an old style window so call with the old style code
    
RETURN



* * * * * * *
RemWMOut:
* * * * * * *
    
    WONo = Get_Property(@WINDOW:'.WO_NO','TEXT')
    IF WONo = '' THEN RETURN
    
    *Send_Event(@WINDOW,'WRITE')
    
    WORec		= XLATE('WO_LOG',WONo,'','X')
    WOMatKeys	= WORec<WO_LOG_WO_MAT_KEY$>
    
    WMOutKeys = XLATE('WO_MAT',WOMatKeys,WO_MAT_WMO_KEY$,'X')
    WMOutCnt = COUNT(WMOutKeys,@VM) + (WMOutKeys NE '')
    
    Display = ''
    DispLine = 1
    
    IF WMOutCnt > 0 THEN
        
        FOR I = WMOutCnt TO 1 STEP -1
            WMORec = XLATE('WM_OUT',WMOutKeys<1,I>,'','X')
            WMO_RdsNos		= WMORec<WM_OUT_RDS$>
            WMO_NCRNos		= WMORec<WM_OUT_SLOT_NCR$>
            WMO_UMWCassIDs	= WMORec<WM_OUT_UMW_CASS_ID$>
            CONVERT @VM TO '' IN WMO_RdsNos
            CONVERT @VM TO '' IN WMO_NCRNos
            CONVERT @VM TO '' IN WMO_UMWCassIDs
            
        UNTIL WMO_RdsNos NE '' OR WMO_NCRNos NE '' OR WMO_UMWCassIDs NE ''
            Display<1,DispLine,1> = FIELD(WOMatKeys<1,I>,'*',2)
            Display<1,DispLine,2> = OCONV(obj_WM_Out('CurrStatus',WOMatKeys<1,I>:@RM:WMORec),'[WO_MAT_CURR_STATUS_CONV]')
            Display<1,DispLine,3> = WMOutKeys<1,I>
            DispLine += 1
        NEXT I
        
        IF Display NE '' THEN
            TypeOver = ''
            TypeOver<PDISPLAY$> = Display
            TypeOver<PTITLE$> = 'Unused WM_OUT Cassettes'
            WMOData = Popup(@WINDOW,TypeOver,'UNUSED_WM_OUT')
            IF WMOData = '' OR WMOData = CHAR(27) THEN RETURN	;* Cancelled out
        END ELSE
            ErrMsg('All cassettes on this Work Order have started processing.')
            obj_AppWindow('LoadFormKeys',@WINDOW:@RM:WONo)
            RETURN
        END
        
        DelWMOutKeys = ''
        FOR I = 1 TO COUNT(WMOData,@FM) + (WMOData NE '')
            DelWMOutKeys<1,I> = WMOData<I,3>
        NEXT I
        
        TestWMOutKeys = DelWMOutKeys
        CONVERT @VM TO '' IN TestWMOutKeys
        
        IF TestWMOutKeys NE '' THEN
            Set_Status(0)
            obj_WM_Out('Delete',DelWMOutKeys)
            
            IF Get_Status(errCode) THEN
                ErrMsg(errCode)
            END
        END
        
        IF Get_Status(errCode) THEN
            ErrMsg(errCode)
        END
        
    END
    
    IF Display = '' THEN
        ErrMsg('All cassettes on this Work Order have had wafers placed in them.')
        RETURN
    END
    
    
    IF Get_Status(errCode) THEN
        ErrMsg(errCode)
    END
    
    *obj_AppWindow('LoadFormKeys',@WINDOW:@RM:WONo)
    
    Send_Event(@WINDOW,'READ')
    
RETURN


* * * * * * * 
WaferTrace:
* * * * * * *
    
    WONo = Get_Property(@WINDOW:'.WO_NO','TEXT')
    IF WONo = '' THEN RETURN
    
    CALL Reconcile_EPI_Wo(WONo)
    
RETURN


* * * * * * *
ControlPlanClick:
* * * * * * *
    
    WONo = Get_Property(@WINDOW:'.WO_NO','DEFPROP')
    PSNo = Get_Property(@WINDOW:'.PROD_SPEC_ID','DEFPROP')
    
    IF PSNo NE '' AND WONo NE '' THEN
        Print_Control_Plan(PSNo,WONo)
    END
    
RETURN




