COMPILE FUNCTION Comm_WO_Prod_GaN(EntID,Event,Parm1,Parm2,Parm3,Parm4,Parm5)
#pragma precomp SRP_PreCompiler

/*
	Commuter module for WO_Prod_GaN, Read Only WO Step window for production use (Work Order Step) Work Order step table
	
	05/13/2016 - John C. Henry, J.C. Henry & Co., Inc.
	11/23/2020 - djs - Added PUB_ADD_OUT_CASS.CLICK event
*/

DECLARE SUBROUTINE Set_Property,  Set_Status, ErrMsg, Set_Property, obj_AppWindow, obj_Notes, obj_WM_Out, obj_Post_Log
DECLARE SUBROUTINE obj_SAP, obj_Run_Stage, Print_Control_Plan, Send_Info, obj_Tables, End_Window, Start_Window
DECLARE SUBROUTINE Btree.Extract, Send_Event, Security_Err_Msg, Forward_Event, Post_Event, Error_Services
DECLARE SUBROUTINE Work_Order_Services
DECLARE FUNCTION Get_Property, Get_Status, Popup, Send_Message, Msg, Security_Check, Dialog_Box, RowExists, obj_Tables
DECLARE FUNCTION Dialog_Box, obj_WO_Log, obj_RDS, obj_WM_Out,obj_React_Run, Set_Property, obj_Prod_Spec, MemberOf
DECLARE FUNCTION GaN_Services, 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 REACT_RUN_EQUATES
$INSERT LSL_USERS_EQU
$INSERT SECURITY_RIGHTS_EQU
$INSERT QUOTE_SIGS_EQU
$INSERT RTI_STYLE_EQUATES

EQU CRLF$	TO \0D0A\

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

EQU COL$RUNS_RUN_NO		    TO 1
EQU COL$RUNS_CHAR_STATUS    TO 2
EQU COL$RUNS_RDS_NO		    TO 3
EQU COL$RUNS_GAN_RUN        TO 4

EQU COL$WM_IN_CASS_NO	TO 1
EQU COL$WM_IN_QTY		TO 2
EQU COL$WM_IN_REJ		TO 3
EQU COL$WM_IN_REMAINING	TO 4

ErrCode	 = ''
ErrorMsg = ''
ErrTitle = 'Error in Comm_WO_Prod_GaN'


Result = ''

BEGIN CASE
    CASE EntID = @WINDOW
        
        BEGIN CASE
            CASE Event      = 'CLEAR'		; GOSUB Clear
            CASE Event      = 'CREATE' 		; GOSUB Create
            CASE Event      = 'CLOSE'		; GOSUB Close
            CASE Event      = 'WRITE'		; GOSUB Write
            CASE Event      = 'READ'		; GOSUB Read
            CASE Event      = 'CLOSE'		; GOSUB Close
            CASE Event      = 'GOTFOCUS'	; GOSUB GotFocus                
            CASE Event[1,3] = 'QBF'			; GOSUB Refresh
        END CASE
        
        
    CASE EntID = @WINDOW:'.WO_NO'				AND Event = 'LOSTFOCUS'	 	; GOSUB WONoLF
    CASE EntID = @WINDOW:'.PROC_STEP_NO'		AND Event = 'GOTFOCUS'	 	; GOSUB StepGF
    CASE EntID = @WINDOW:'.CONTROL_PLAN'		AND Event = 'CLICK'			; GOSUB ControlPlan
    CASE EntID = @WINDOW:'.VIEW_PSN_BUTTON'		AND Event = 'CLICK'			; GOSUB ViewProdSpec
    CASE EntID = @WINDOW:'.NEW_RDS'				AND Event = 'CLICK'			; GOSUB CreateRDS
    CASE EntID = @WINDOW:'.LU_WO_NO'			AND Event = 'CLICK'			; GOSUB LUWONo
    CASE EntID = @WINDOW:'.PUB_VIEW_WO'			AND Event = 'CLICK'			; GOSUB ViewWorkOrder          
    CASE EntID = @WINDOW:'.RUNS'				AND Event = 'DBLCLK'		; GOSUB RdsDC
    CASE EntID = @WINDOW:'.OUT_WFRS'			AND Event = 'DBLCLK'		; GOSUB OutCassDC
    CASE EntID = @WINDOW:'.WO_MAT_KEYS'         AND Event = 'DBLCLK'        ; GOSUB InCassDC
    CASE EntID = @WINDOW:'.PUB_ADD_OUT_CASS'    AND Event = 'CLICK'         ; GOSUB AddOutboundCass
      
    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)
    
    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:
* * * * * * *
    
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)
        
        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
    // Doesn't apply to this form
*    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')
    CharStatuses = CassArray<COL$RUNS_CHAR_STATUS>
    NumRows      = DCount(CharStatuses, @VM)
    FOR RowIndex = 1 TO NumRows
        CharStatus = CharStatuses<0, RowIndex>
        
        BEGIN CASE
            CASE CharStatus EQ 'Sched-Done' ; LineColor = LTBLUE$
            CASE CharStatus	EQ 'Done'	    ; LineColor = GREEN$
            CASE CharStatus EQ 'Sched'		; LineColor = YELLOW$
            CASE CharStatus EQ 'Skipped'    ; LineColor = RED$
            CASE Otherwise$	                ; LineColor = WHITE$
        END CASE
        
        stat = Send_Message(CtrlName, 'COLOR_BY_POS', COL$RUNS_CHAR_STATUS, RowIndex, 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
    
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:
* * * * * * *
    
    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
    
*    TechType = Xlate('PROD_SPEC', PSNo, 'TECH_TYPE', 'X')
*        Begin Case
*            Case TechType EQ 'P'
                Start_Window('DBW_PROD_SPEC_GAN', '', PSNo)
*            Case TechType EQ 'E'
*                Start_Window('PROD_SPEC', '', PSNo)
*            Case Otherwise$
*                Start_Window('PROD_SPEC', '', PSNo)
*        End Case
    
*    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$RUNS_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
        
        PSNo     = Get_Property(@Window:'.PROD_SPEC_ID', 'TEXT')
        TechType = Xlate('PROD_SPEC', PSNo, 'TECH_TYPE', 'X')
        Begin Case
            Case TechType EQ 'P'
                Start_Window('DBW_GAN_RDS_PROD', '', RDSNo)
            Case TechType EQ 'E'
                Start_Window('REACT_RUN', '', RDSNo)
            Case Otherwise$
                Start_Window('REACT_RUN', '', RDSNo)
        End Case
        
    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
        If Get_Property('NDW_MAIN', 'VISIBLE') then
            AppMain = 'NDW_MAIN'
        end else
            AppMain = 'LSL_MAIN2'
        end
        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


* * * * * * *
OutCassDC:
* * * * * * *
    
    CtrlEntID = @WINDOW:'.OUT_WFRS'
    
    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
        
        Send_Event(@WINDOW,'CLEAR')
        
        DetWindow	= 'WO_MAT_GAN'
        DetKeys		= WONo:'*':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


* * * * * * *
InCassDC:
* * * * * * *

    If MemberOf(@USER4, 'OI_SUPERUSER') then

        CtrlEntID = @WINDOW:'.WO_MAT_KEYS'        
        CurrPos = Get_Property(CtrlEntID,'SELPOS')
        CurrCol = CurrPos<1>
        CurrRow = CurrPos<2>       
        WONo	= Get_Property(@WINDOW:'.WO_NO','DEFPROP')
        CassNo	= Get_Property(CtrlEntID,'CELLPOS',1:@FM:CurrRow)       
        IF ( (WONo NE '') AND (CassNo NE '') ) THEN
            Start_Window('NDW_GAN_INBOUND_MATERIAL', @Window, WONo:'*':CassNo)
        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
    
    WOStepKey = WONo:'*':WOStep
    
    IF @WINDOW = 'WO_PROD_EPI' THEN					
        
        WMInRem	= Get_Property(@WINDOW:'.WO_MAT_KEYS','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
    END
    
    IF @WINDOW = 'WO_PROD_GAN' THEN
        
        WMInRem	= Get_Property(@WINDOW:'.WO_MAT_KEYS','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
        
    END

    Error_Services('Clear')
    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
    
    WOMatKey = WONo:'*':NextCassNo
    
    WOMatRec = XLATE('WO_MAT',WOMatKey,'','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$>				
       
    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 NextCassNo 
    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
    
    RDSNo         = obj_RDS('Create',Parms)
    PSRec         = XLATE('PROD_SPEC',PSN,'','X')
    RunStages     = GaN_Services('GetCassStages', RDSNo) ; // Cassette Stages
    WfrStages     = GaN_Services('GetWfrStages', RDSNo)  ; // Wafer Stages
    
    rsCnt		  = COUNT(RunStages,@VM) + (RunStages NE '')
    
    RunStageKeys  = ''
    
    FOR R = 1 TO rsCnt
        
        Stage = RunStages<1,R>
        RunStageKeys<1,R> = RDSNO:'*':Stage 	
        obj_Run_Stage('Create',RDSNo:@RM:Stage:@RM:PSN)			;* Create new RUN_STAGE records for each stage 
        
    NEXT R
    
    otParms = 'REACT_RUN':@RM:RDSNo
    RRunRec = obj_Tables('ReadRec',otParms)
    
    IF Get_Status(errCode) THEN
        
        ErrMsg(errCode)
        
    END ELSE
        RRunRec<REACT_RUN_RUN_STAGE_KEY$>	= RunStageKeys
        RRunRec<REACT_RUN_WFR_STAGE$>		= WfrStages        
        otParms = FieldStore(otParms,@RM,4,0,RRunRec)
        obj_Tables('WriteRec',otParms)        
        IF Get_Status(errCode) THEN
            ErrMsg(errCode)
        END
        
    END
    
    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
        
        PSNo     = Get_Property(@Window:'.PROD_SPEC_ID', 'TEXT')
        TechType = Xlate('PROD_SPEC', PSNo, 'TECH_TYPE', 'X')
        Begin Case
            Case TechType EQ 'P'
                Start_Window('DBW_GAN_RDS_PROD', '', RDSNo)
            Case TechType EQ 'E'
                Start_Window('REACT_RUN', '', RDSNo)
            Case Otherwise$
                Start_Window('REACT_RUN', '', RDSNo)
        End Case
        
        
    END    
    Post_Event('WO_PROD_GAN', 'READ')
    
RETURN


* * * * * * *
RemWMOut:
* * * * * * *
    
RETURN

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


* * * * * * *
ControlPlan:
* * * * * * *
    
    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


* * * * * * *
ViewWorkOrder:
* * * * * * *

    WONo = Get_Property(@WINDOW:'.WO_NO','TEXT')
    If WONo NE '' then
        NewForm = Xlate('APP_INFO', 'NEW_WO_FORM', '', 'X')
        If NewForm then
            Form = 'NDW_WO_LOG'
        end else
            Form = 'WO_LOG2'
        end
        Parent = Get_Property(@Window, 'PARENT')
        Start_Window(Form, Parent, WONo)
    end
    
return


* * * * * * *
AddOutboundCass:

    WONo = Get_Property(@WINDOW:'.WO_NO','TEXT')
    If WONo NE '' then
        Def = ""
        Def<MTEXT$> = "Creating outbound cassettee..."
        Def<MTYPE$> = "U"
        MsgUp = Msg(@window, Def)   ;* display the processing message
        Work_Order_Services('CreateOutbound', WONo)
        Post_Event('WO_PROD_GAN', 'READ')
        Msg(@window, MsgUp)         ;* take down the processing message
    end
 
return
* * * * * * *




