COMPILE FUNCTION Comm_WO_log(Instruction, Parm1,Parm2)
#pragma precomp SRP_PreCompiler

/*
	Commuter module for WO_Log2 (Work Order Log) window
	
	08/16/2004 - John C. Henry, J.C. Henry & Co., Inc.
*/

DECLARE SUBROUTINE Set_Property,  Set_Status, ErrMsg, Set_Property, obj_AppWindow, obj_Notes, Print_WO_Release, Create_Note
DECLARE SUBROUTINE Btree.Extract, Send_Event, Security_Err_Msg, Forward_Event, End_Window, obj_WO_Log,Print_CleanRoom_Labels_Thermal
DECLARE SUBROUTINE obj_Tables, obj_Vision, Print_Shelf_Label, Print_Cass_Labels, Print_WMI_Labels, Print_WMO_Labels, Print_WO_Mat_In_Labels
DECLARE SUBROUTINE obj_WM_In, obj_WM_Out, Send_Info, Post_Event, Print_WO, obj_WO_Mat, Utility
DECLARE SUBROUTINE SRP_Stopwatch, Database_Services, Print_WO_Mat_Out_Labels, Logging_Services
DECLARE FUNCTION Get_Property, Get_Status, Popup, Send_Message, Msg, Security_Check, Dialog_Box, RowExists, MemberOf
DECLARE FUNCTION Dialog_Box, obj_WO_Log, obj_RDS, obj_Tables, obj_WO_Step, obj_WM_In, obj_WM_Out, obj_WO_Mat, obj_MUWafers
DECLARE FUNCTION WO_Purge, Set_Property, NextKey, Start_Window, Database_Services, Gan_Services, Environment_Services
DECLARE FUNCTION Logging_Services, Datetime

$INSERT APPCOLORS
$INSERT COMPANY_EQUATES
$INSERT CUST_EPI_PART_EQUATES
$INSERT EPI_PART_EQUATES
$INSERT LSL_USERS_EQU
$INSERT MSG_EQUATES
$INSERT NOTIFICATION_EQU
$INSERT POPUP_EQUATES
$INSERT LOGICAL
$INSERT LOGICAL
$INSERT PROD_SPEC_EQU
$INSERT PROD_VER_EQUATES
$INSERT QUOTE_EQU
$INSERT QUOTE_DET_EQU
$INSERT QUOTE_SIGS_EQU
$INSERT REACT_RUN_EQUATES
$INSERT SECURITY_RIGHTS_EQU
$INSERT WM_IN_EQUATES
$INSERT WM_OUT_EQUATES
$INSERT WO_LOG_EQUATES
$INSERT WO_STEP_EQU
$INSERT WO_MAT_EQUATES
$INSERT ORDER_EQU
$INSERT ORDER_DET_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$CASS_LOT_NO			TO 2
EQU COL$CASS_QTY			TO 3
EQU COL$CASS_SUB_PART_NO	TO 4
EQU COL$CASS_SUB_VEND_CD	TO 5
EQU COL$CASS_EPI_PART_NO	TO 6
EQU COL$CASS_RX_DTM			TO 7
EQU COL$CASS_REL_DTM		TO 8
EQU COL$CASS_CURR_STATUS	TO 9
EQU COL$CASS_SAP_TX_DTM		TO 10
EQU COL$CASS_BATCH_NO		TO 11
EQU COL$CASS_CASS_ID_SAP	TO 12
EQU COL$CASS_SAP_YIELD		TO 13
EQU COL$CASS_SAP_SCRAP		TO 14
EQU COL$CASS_SAP_GR			TO 15
EQU COL$CASS_RAW_SCRAP		TO 16
EQU COL$CASS_PROD_TEST		TO 17
EQU COL$CASS_AVAIL_MU		TO 18

EQU COL$WO_STEP_PSN			TO 2

EQU COL$PART_STEP_PSN		TO 2
EQU COL$PART_STEP_PSN_TYPE	TO 3

EQU COL$ITEM_PROMISE_DT		TO 4

LogPath       = Environment_Services('GetApplicationRootPath') : '\LogFiles\WO_LOG'
LogDate       = Oconv(Date(), 'D4/')
LogTime       = Oconv(Time(), 'MTS')
LogFileName   = LogDate[7, 4] : '-' : LogDate[1, 2] : '-' : LogDate[4, 2] : ' Release Performance Log.csv'
Headers       = 'Logging DTM':@FM:'WO':@FM:'User':@FM:'Cassettes (Qty)':@FM:'Release (Secs)':@FM:'Form Refresh (Secs)':@FM:'Total Duration (Secs)':@FM:'Seconds/Cassette'
objReleaseLog = Logging_Services('NewLog', LogPath, LogFileName, CRLF$, COMMA$, Headers, '', False$, False$)

LoggingDTM    = LogDate : ' ' : LogTime   ; // Logging DTM

ErrTitle	= 'Error in Comm_WO_Log'
ErrorMsg	= ''
ErrCode		= ''
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 = 'LUWONo'				; GOSUB LUWONo
    CASE Instruction = 'LUPriority'			; GOSUB LUPriority
    CASE Instruction = 'WONoLF'				; GOSUB WONoLF
    CASE Instruction = 'OpenWOS'			; GOSUB OpenWOS
    CASE Instruction = 'Unrouted'			; GOSUB Unrouted
    CASE Instruction = 'QuoteGF'			; GOSUB QuoteGF
    CASE Instruction = 'ViewQuote'			; GOSUB ViewQuote
    CASE Instruction = 'LUQuote'			; GOSUB LUQuote
    CASE Instruction = 'LUProdVer'			; GOSUB LUProdVer
    CASE Instruction = 'ProdVerLF'			; GOSUB ProdVerLF
    CASE Instruction = 'UnrouteWO'			; GOSUB UnrouteWO
    CASE Instruction = 'ViewProdVer'		; GOSUB ViewProdVer
    CASE Instruction = 'ViewCust'			; GOSUB ViewCust
    CASE Instruction = 'ViewOrder'			; GOSUB ViewOrder
    CASE Instruction = 'ViewProdSpec'		; GOSUB ViewProdSpec
    CASE Instruction = 'ViewCustEpiPart'	; GOSUB ViewCustEpiPart
    CASE Instruction = 'CommDtGF'			; GOSUB CommDtGF
    CASE Instruction = 'CycleTimeClick'		; GOSUB CycleTimeClick
    CASE Instruction = 'Release'			; GOSUB Release
    CASE Instruction = 'Recall'				; GOSUB Recall
    CASE Instruction = 'PrintLabels'		; GOSUB PrintLabels
    CASE Instruction = 'PrintReleaseTicket'	; GOSUB PrintReleaseTicket
    CASE Instruction = 'PrintShelfLabels'	; GOSUB PrintShelfLabels
    CASE Instruction = 'RxWafers'			; GOSUB RxWafers
    CASE Instruction = 'RxReprocess'		; GOSUB RxReprocess
    CASE Instruction = 'ChangeLotNo'		; GOSUB ChangeLotNo
    CASE Instruction = 'ChangeCassQty'		; GOSUB ChangeCassQty
    CASE Instruction = 'ChangeCustPartNo'	; GOSUB ChangeCustPartNo
    CASE Instruction = 'ChangePONo'			; GOSUB ChangePONo
    CASE Instruction = 'RemCassettes'		; GOSUB RemCassettes
    CASE Instruction = 'RemWMOut'			; GOSUB RemWMOut
    CASE Instruction = 'RefreshSigProfile'	; GOSUB RefreshSigProfile
    CASE Instruction = 'MUWaferDetail'		; GOSUB MUWaferDetail
    CASE Instruction = 'StartStopDtClick'	; GOSUB StartStopDtClick
    CASE Instruction = 'LUCustPartNo'		; GOSUB LUCustPartNo
    CASE Instruction = 'LUCustSubNo'		; GOSUB LUCustSubNo
    CASE Instruction = 'Purge'				; GOSUB Purge
    CASE Instruction = 'ShipDC'				; GOSUB ShipDC
    CASE Instruction = 'PrintWO'			; GOSUB PrintWO
    Case Instruction = 'NewGaN'				; Gosub NewGaN
        
    CASE 1
        ErrorMsg = 'Unknown Instruction ':QUOTE(Instruction):' passed to routine'
END CASE

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

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)
    
    IF Parm1 NE '' THEN
        PassedKeys = FIELD(Parm1,'*',1)
        obj_Appwindow('ViewRelated',@WINDOW:@RM:PassedKeys)
    END
    
    Ctrls  = @WINDOW:'.PROD_ORD_NO':@RM			; Props  = 'ENABLED':@RM
    Ctrls := @WINDOW:'.CUST_PO_NO':@RM			; Props := 'ENABLED':@RM
    Ctrls := @WINDOW:'.EPI_PART_NO':@RM			; Props := 'ENABLED':@RM
    Ctrls := @WINDOW:'.ORD_SUB_PART_NO':@RM		; Props := 'ENABLED':@RM
    Ctrls := @WINDOW:'.ORD_SUB_PART_REV':@RM	; Props := 'ENABLED':@RM
    Ctrls := @WINDOW:'.RECALL_BUTTON':@RM		; Props := 'ENABLED':@RM
    Ctrls := @WINDOW:'.WO_QTY'					; Props := 'ENABLED'
    
    IF MemberOf(@USER4,'MASTER_SCHED') OR MemberOf(@USER4, 'OI_SUPERUSER') THEN Vals = 1 ELSE Vals = 0
    
    Set_Property(Ctrls,Props,Vals)
    
    IF MemberOf(@USER4,'CONFIG_LIMITED') THEN
        Set_Property(@WINDOW:'.CUST_PO_NO','ENABLED',1)
    END ELSE
        Set_Property(@WINDOW:'.CUST_PO_NO','ENABLED',0)
    END
    
    GOSUB Refresh
    
RETURN


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

    WONo = Get_Property(@WINDOW:'.WO_NO','TEXT')
    
    IF RowExists('WO_LOG',WONo) THEN
        IF NOT(Security_Check('WO Log',READ$)) THEN
            Send_Event(@WINDOW,'CLEAR')
            Security_Err_Msg('Work Order',READ$)
            RETURN
        END
        
        IF NOT(Security_Check('WO Log',EDIT$)) THEN
            obj_Appwindow('ReadOnly',@WINDOW)					;*Set to Read Only
        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:
* * * * * * *
    
    Ctrls  = @WINDOW:'.COMMIT_DT':@RM			; Props  = 'DEFPROP':@RM
    Ctrls := @WINDOW:'.WO_NO':@RM				; Props := 'DEFPROP':@RM
    Ctrls := @WINDOW:'.ORDER_NO':@RM			; Props := 'DEFPROP':@RM
    Ctrls := @WINDOW:'.PROD_ORD_NO':@RM			; Props := 'DEFPROP':@RM
    Ctrls := @WINDOW:'.CUST_PART_NO':@RM		; Props := 'DEFPROP':@RM
    Ctrls := @WINDOW:'.CUST_CAPTIVE':@RM		; Props := 'CHECK':@RM
    Ctrls := @WINDOW:'.CLOSE_DT':@RM			; Props := 'DEFPROP':@RM
    Ctrls := @WINDOW:'.WO_STOP_DTM':@RM			; Props := 'DEFPROP':@RM
    Ctrls := @WINDOW:'.PROD_VER_NO'				; Props := 'DEFPROP'
    
    Vals = Get_Property(Ctrls,Props)
    
    PromiseDt	= Vals[1,@RM]
    WONo		= Vals[COL2()+1,@RM]
    OrderNo		= Vals[COL2()+1,@RM]
    ProdOrdNo	= Vals[COL2()+1,@RM]
    CustPartNo	= Vals[COL2()+1,@RM]
    CustCaptive	= Vals[COL2()+1,@RM]
    CloseDt		= Vals[COL2()+1,@RM]
    WOStopDTM	= Vals[COL2()+1,@RM]
    ProdVerNo	= Vals[COL2()+1,@RM]
    
    IF WOStopDTM = '' AND CloseDt NE '' THEN
        CurrDTM = OCONV(Date(),'D4/'):' ':OCONV(Time(),'MTH')
        Set_Property(@WINDOW:'.WO_STOP_DTM','TEXT',CurrDTM)
    END
    
    IF ProdOrdNo[1,1] NE 'M' AND CustPartNo = '' AND ProdVerNo NE '' THEN
        ErrMsg('Part No in Non SAP Group is required.')
        Set_Property(@WINDOW:'.CUST_PART_NO','BACKCOLOR',RED$)
        Result = 0
        RETURN
    END
    
    IF PromiseDt NE '' AND WONo NE '' AND OrderNo NE ''	AND ProdOrdNo = '' THEN 
        
        VisionOrderNo = XLATE('ORDER',OrderNo,ORDER_VISION_ORDER_NO$,'X')
        IF VisionOrderNo = '' THEN
            Result = 1
            RETURN
        END
        OrgWOLogRec = XLATE('WO_LOG',WONo,'','X')
        
        PrevPromiseDt = OCONV(OrgWOLogRec<WO_LOG_COMMIT_DATE$>,'D4/')
        PrevCycleTime = OrgWOLogRec<WO_LOG_CYCLE_TIME$>
        
        IF PromiseDt NE PrevPromiseDt THEN
            
            Reason = Msg(@WINDOW,'','PROMISE_DT_REASON')
            
            IF Reason = CHAR(27) THEN
                Set_Property(@WINDOW:'.COMMIT_DT','DEFPROP',PrevPromiseDt)
                Set_Property(@WINDOW:'.CYCLE_TIME','VALUE',PrevCycleTime)
                Msg('Promise Date will not be changed.')
            END ELSE
                
                VisionOrderNo = XLATE('ORDER',OrderNo,ORDER_VISION_ORDER_NO$,'X')
                
                OrderItems = Get_Property(@WINDOW:'.ORDER_ITEMS','DEFPROP')<1>
                
                LOOP
                    TestLine = OrderItems[-1,'B':@VM]
                UNTIL TestLine NE '' OR OrderItems = ''
                    OrderItems[COL1(),COL2()] = ''
                REPEAT
                
                Def = ""
                Def<MTEXT$> = "Updating Promise Ship Date on RDS records..."
                Def<MTYPE$> = "U"
                
                MsgUp = Msg(@window, Def)
                
                obj_WO_Log('SetPromiseDt',OrderNo:@RM:OrderItems:@RM:WONo:@RM:PromiseDt:@RM:Reason)
                
                Msg(@window, MsgUp)
            END ;* End of prompt for change reason
            
        END	;* End of check for changed Promise Date
        
    END	;* End of check for fields required to update Promise Date
    
    
    Result = 1
    
RETURN


* * * * * * *
Clear:
* * * * * * *
    
    Set_Property(@WINDOW:'.CUST_PART_NO','BACKCOLOR',WHITE$)
    
    Set_Property(@WINDOW:'.TAB_MAIN','VALUE',1)
    
    Send_Event(@WINDOW,'PAGE',1)
    
    obj_AppWindow('ReadOnly',@WINDOW:@RM:1)		;* Clear Read Only
    
    GOTO Refresh
    
RETURN


* * * * * * *
Delete:
* * * * * * *
    
    IF NOT(Security_Check('WO Log',Delete$)) THEN
        Security_Err_Msg('WO Log',Delete$)
        RETURN
    END
    
    WONo = Get_Property(@WINDOW:'.WO_NO','TEXT')
    IF WONo NE '' THEN
        
        obj_WO_Log('Delete',WONo)						;* Removes WO_LOG record from system
        IF Get_Status(errCode) THEN
            ErrMsg(errCode)
            RETURN
        END
    END
    
    Send_Event(@WINDOW,'CLEAR')
    
    obj_AppWindow('ReadOnly',@WINDOW:@RM:1)		;* Clear Read Only
    
    Result = 0
    
RETURN


* * * * * * *
Page:
* * * * * * *
    
    Page = Parm1
    
    IF Page = '' THEN
        Page = Get_Property(@WINDOW:'.TAB_MAIN','VALUE')
    END ELSE
        Set_Property(@WINDOW:'.TAB_MAIN','VALUE',Page)
    END
    
    Set_Property(@WINDOW,'VPOSITION', Page)
    
    GOSUB Refresh
    
RETURN



* * * * * * *
Close:
* * * * * * *
    
    obj_Notes('Inbox',@USER4)
    
    obj_Appwindow('DetailReturn')
    
Return


* * * * * * *
NewGaN:
* * * * * * *
    
    IF NOT(MemberOf( @USER4, 'CONFIG_LIMITED' )) THEN RETURN
    
    WONo = Get_Property(@WINDOW:'.WO_NO','DEFPROP')
    
    IF WONo = '' THEN
        WONo = NextKey('WO_LOG')
    END ELSE
        Send_Event(@WINDOW,'WRITE')
    END
    
    void = Start_Window('WO_LOG_GAN',@WINDOW,WONo)
    
RETURN


* * * * * * *
Refresh:
* * * * * * *
        
    Set_Property(@Window, 'REDRAW', False$)
    
    IF MemberOf(@USER4,'MASTER_SCHED') OR MemberOf(@USER4,'OI_ADMIN') THEN
        Set_Property(@WINDOW:'.NEW_GAN','ENABLED',1)
    END ELSE
        Set_Property(@WINDOW:'.NEW_GAN','ENABLED',0)
    ENd
    
    IF MemberOf(@USER4,'CONFIG_LIMITED') OR MemberOf(@USER4,'OI_ADMIN') THEN
        *Set_Property(@WINDOW:'.LU_PROD_VER_NO','ENABLED',1)
        Set_Property(@WINDOW:'.UNROUTE_WO','ENABLED',1)
    END ELSE
        *Set_Property(@WINDOW:'.LU_PROD_VER_NO','ENABLED',0)
        Set_Property(@WINDOW:'.UNROUTE_WO','ENABLED',0)
    END
    
    
    IF MemberOf(@USER4,'OI_ADMIN') OR MemberOf(@USER4, 'OI_SUPERUSER') THEN
        
        Ctrls = @WINDOW:'.WO_START_DTM':@RM:@WINDOW:'.WO_STOP_DTM'
        Props = 'DEFPROP':@RM:'DEFPROP'
        
        Vals		= Get_Property(Ctrls,Props)
        WOStartDTM	= Vals[1,@RM]
        WOStopDTM	= Vals[COL2()+1,@RM]
        
        Vals = ''
        IF WOStartDTM	= '' THEN Vals<1> = 'Set Start Dt'	ELSE Vals<1> = 'Clear Start Dt'
        IF WOStopDTM	= '' THEN Vals<2> = 'Set Stop Dt'	ELSE Vals<2> = 'Clear Stop Dt'
        
        Vals<3> = 1
        Vals<4> = 1
        
        CONVERT @FM TO @RM IN Vals
        
        Ctrls = @WINDOW:'.WO_START_DT':@RM:@WINDOW:'.WO_STOP_DT':@RM:@WINDOW:'.WO_START_DT':@RM:@WINDOW:'.WO_STOP_DT'
        
        Props = 'TEXT':@RM:'TEXT':@RM:'VISIBLE':@RM:'VISIBLE'
        
        Set_Property(Ctrls,Props,Vals)
        
    END	;* End of SAP development code
    
    * * * * * * Changes for SAP generated Order * * * * * *
    
    Priority = Get_Property(@WINDOW:'.PRIORITY','DEFPROP')
    
    BEGIN CASE
        CASE Priority = 'P1'	; Color = RED$
        CASE Priority = 'P2'	; Color = YELLOW$
        CASE 1					; Color = GREEN$
    END CASE
    
    Set_Property(@WINDOW:'.PRIORITY','BACKCOLOR',Color)
    Set_Property(@WINDOW:'.PRI_DESC','BACKCOLOR',Color)
    
    IF MemberOf(@USER4,'OI_ADMIN') THEN
        Set_Property(@WINDOW:'.PURGE','VISIBLE',1)
    END ELSE
        Set_Property(@WINDOW:'.PURGE','VISIBLE',0)
    END
    
    Ctrls  = @WINDOW:'.CUST_CAPTIVE':@RM		; Props  = 'CHECK':@RM
    Ctrls := @WINDOW:'.PROD_VER_NO':@RM			; Props := 'DEFPROP':@RM
    Ctrls := @WINDOW:'.CUST_PO_NO':@RM			; Props := 'DEFPROP':@RM
    Ctrls := @WINDOW:'.CUST_PART_NO':@RM		; Props := 'DEFPROP':@RM
    Ctrls := @WINDOW:'.PROD_ORD_NO':@RM			; Props := 'DEFPROP':@RM
    Ctrls := @WINDOW:'.PART_STEP_NO'			; Props := 'ARRAY'
    
    Vals = Get_Property(Ctrls,Props)
    
    CustCaptive 	= Vals[1,@RM]
    ProdVerNo		= Vals[COL2()+1,@RM]
    CustPONo		= Vals[COL2()+1,@RM]
    CustPartNo		= Vals[COL2()+1,@RM]
    ProdOrdNo		= Vals[COL2()+1,@RM]
    PartStepArray	= Vals[COL2()+1,@RM]
    
    StepPSNs		= PartStepArray<COL$WO_STEP_PSN>
    
    LOOP
        StepPSN = StepPSNs[-1,1]
    UNTIL StepPSN NE @VM OR StepPSNs = ''
        StepPSNs[-1,1] = ''
    REPEAT
    
    ShipPSN			= StepPSNs[-1,'B':@VM]
    ShipSpecType	= XLATE('PROD_SPEC',ShipPSN,'SPEC_TYPE','X')		;* Added 2/9/2016 JCH
    
    DefBack			= Get_Property(@WINDOW,'BACKCOLOR')
    
    IF CustCaptive = 1 OR ShipSpecType = 'U' OR ShipSpecType = 'Q' THEN
        Set_Property(@WINDOW:'.NON_SAP_GROUP','ENABLED',0)
        Set_Property(@WINDOW:'.NON_SAP_GROUP','BACKCOLOR',DefBack)
        Set_Property(@WINDOW:'.CUST_PART_NO_LABEL','BACKCOLOR',DefBack)
        Set_Property(@WINDOW:'.CUST_PART_INBOUND_LABEL','BACKCOLOR',DefBack)
        Set_Property(@WINDOW:'.CUST_SUB_PART_NO_LABEL','BACKCOLOR',DefBack)
        Set_Property(@WINDOW:'.CUST_SUB_MFR_LABEL','BACKCOLOR',DefBack)
    END ELSE
        Set_Property(@WINDOW:'.NON_SAP_GROUP','ENABLED',1)
        Set_Property(@WINDOW:'.NON_SAP_GROUP','BACKCOLOR',CI_GROUP_BLUE$)
        Set_Property(@WINDOW:'.CUST_PART_NO_LABEL','BACKCOLOR',CI_GROUP_BLUE$)
        Set_Property(@WINDOW:'.CUST_PART_INBOUND_LABEL','BACKCOLOR',CI_GROUP_BLUE$)
        Set_Property(@WINDOW:'.CUST_SUB_PART_NO_LABEL','BACKCOLOR',CI_GROUP_BLUE$)
        Set_Property(@WINDOW:'.CUST_SUB_MFR_LABEL','BACKCOLOR',CI_GROUP_BLUE$)
    END
    
    IF Get_Property(@WINDOW:'.PROD_VER_NO','DEFPROP') = '' THEN
        Set_Property(@WINDOW:'.RX_BUTTON','ENABLED',0)
    END ELSE
        Set_Property(@WINDOW:'.RX_BUTTON','ENABLED',1)
    END
    
    * * * * * * End of Changes for SAP generated Order * * * * * *
    
    WOQty = Get_Property(@WINDOW:'.WO_QTY','DEFPROP')
    CustLotTotal = Get_Property(@WINDOW:'.CUST_LOT_TOTAL','DEFPROP')
    
    IF WOQty NE '' THEN
        
        IF CustLotTotal NE WOQty THEN
            Set_Property(@WINDOW:'.CUST_LOT_TOTAL','BACKCOLOR',RED$)
            Set_Property(@WINDOW:'.CUST_LOT_NO','BACKCOLOR',YELLOW$)
        END ELSE
            Set_Property(@WINDOW:'.CUST_LOT_TOTAL','BACKCOLOR',GREEN$)
            Set_Property(@WINDOW:'.CUST_LOT_NO','BACKCOLOR',GREEN$)
        END
    END ELSE
        Set_Property(@WINDOW:'.CUST_LOT_NO','BACKCOLOR',WHITE$)
    END
    
    * Added by DKK 12/11/14	- set background light orange if less than full box 
    
    OutLoadQty = Get_Property(@WINDOW:'.CUST_EPI_PART_SHIP_QTY','DEFPROP')	
    
    IF OutLoadQty <25 THEN														
        Set_Property(@WINDOW:'.CUST_EPI_PART_SHIP_QTY','BACKCOLOR',LTORANGE$)
    END ELSE
        Set_Property(@WINDOW:'.CUST_EPI_PART_SHIP_QTY','BACKCOLOR',DefBack)
    END
    
    Ctrls  = @WINDOW:'.ENTER_BY':@RM	; Props  = 'TEXT':@RM
    Ctrls := @WINDOW:'.ENTER_DTM'		; Props := 'TEXT'
    
    Vals = Get_Property(Ctrls,Props)
    
    EnterBy		= Vals[1,@RM]
    EnterDTM	= Vals[COL2()+1,@RM]
    
    IF EnterBy	= '' THEN Vals  = 1:@RM ELSE Vals  = 0:@RM
    IF EnterDTM = '' THEN Vals := 1		ELSE Vals := 0
    
    Props = 'ENABLED':@RM:'ENABLED'
    
    Set_Property(Ctrls,Props,Vals)
    
    CassNos 	= Get_Property(@WINDOW:'.CASS_NO','DEFPROP')<1>
    CommitDt	= Get_Property(@WINDOW:'.COMMIT_DT','DEFPROP')
    RelStamp	= Get_Property(@WINDOW:'.REL_STAMP','DEFPROP')
    
    IF CassNos<1,1> = '' THEN
        
        Set_Property(@WINDOW:'.RELEASE_GROUP','ENABLED',0)
        Set_Property(@WINDOW:'.RELEASE_BUTTON','VISIBLE',0)
        Set_Property(@WINDOW:'.PRINT_RELEASE_BUTTON','ENABLED',0)
        Set_Property(@WINDOW:'.LABELS_BUTTON','ENABLED',0)
        
    END ELSE
        
        Set_Property(@WINDOW:'.RELEASE_GROUP','ENABLED',1)
        
        IF CommitDt = '' THEN
            ItemPromiseDt = Get_Property(@WINDOW:'.ORDER_ITEMS','ARRAY')<COL$ITEM_PROMISE_DT,1>	;* Changed 2/4/2010 JCH
            Set_Property(@WINDOW:'.COMMIT_DT','DEFPROP',ItemPromiseDt)
        END
        
        Set_Property(@WINDOW:'.RELEASE_BUTTON','VISIBLE',1)
        
        CassList = Get_Property(@WINDOW:'.CASS_NO','LIST')		;* Get all of the 
        
        LOOP
            LastLine = CassList[-1,'B':@FM]
            IF LastLine<1,COL$CASS_RX_DTM> NE '' AND LastLine<1,COL$CASS_REL_DTM> = '' THEN OpenLine = 1 ELSE OpenLine = 0
        UNTIL OpenLine = 1 OR LastLine = ''
            CassList[COL1(),COL2()] = ''
        REPEAT
        
        * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 
        
        IF OpenLine OR MemberOf(@USER4,'OI_ADMIN') THEN
            Set_Property(@WINDOW:'.RELEASE_BUTTON','ENABLED',1)
        END ELSE
            Set_Property(@WINDOW:'.RELEASE_BUTTON','ENABLED',0)
        END
        
        IF RelStamp NE '' THEN
            Set_Property(@WINDOW:'.PRINT_RELEASE_BUTTON','ENABLED',1)
            Set_Property(@WINDOW:'.LABELS_BUTTON','ENABLED',1)
        END ELSE
            Set_Property(@WINDOW:'.PRINT_RELEASE_BUTTON','ENABLED',0)
            Set_Property(@WINDOW:'.LABELS_BUTTON','ENABLED',0)
        END
        
        CycleTimeCode = Get_Property(@WINDOW:'.CYCLE_TIME','VALUE')
        
        BEGIN CASE
            CASE CycleTimeCode = 'P'	; Set_Property(@WINDOW:'.COMMIT_DT','BACKCOLOR',RED$)	
            CASE CycleTimeCode = 'E'	; Set_Property(@WINDOW:'.COMMIT_DT','BACKCOLOR',YELLOW$)
            CASE 1						; Set_Property(@WINDOW:'.COMMIT_DT','BACKCOLOR',WHITE$)
        END CASE
        
    END
    
    RefreshWOMatSigUsers = XLATE('CONFIG','QUOTE_SIGS',RefreshWOMatSigProf$,'X')
    
    LOCATE @USER4 IN RefreshWOMatSigUsers USING @VM SETTING Pos THEN
        Set_Property(@WINDOW:'.REFRESH_SIG_PROFILE','ENABLED',1)
    END ELSE
        Set_Property(@WINDOW:'.REFRESH_SIG_PROFILE','ENABLED',0)
    END
    
    IF	MemberOf(@USER4,'CONFIG_LIMITED') OR MemberOf(@USER4,'OI_SUPERUSER') THEN
        Set_Property(@WINDOW:'.CHANGE_LOT_NO',  	 'ENABLED', 1)
        Set_Property(@WINDOW:'.CHANGE_CASS_QTY',	 'ENABLED', 1)
        Set_Property(@WINDOW:'.CHANGE_CUST_PART_NO', 'ENABLED', 1)
        Set_Property(@WINDOW:'.CHANGE_PO_NO',   	 'ENABLED', 1)
        Set_Property(@WINDOW:'.REM_CASS_BUTTON',	 'ENABLED', 1)
        Set_Property(@WINDOW:'.REM_WM_OUT', 		 'ENABLED', 1)
        
    END ELSE
        Set_Property(@WINDOW:'.CHANGE_LOT_NO',  	 'ENABLED', 0)
        Set_Property(@WINDOW:'.CHANGE_CASS_QTY',	 'ENABLED', 0)
        Set_Property(@WINDOW:'.CHANGE_CUST_PART_NO', 'ENABLED', 0)
        Set_Property(@WINDOW:'.CHANGE_PO_NO',   	 'ENABLED', 0)
        Set_Property(@WINDOW:'.REM_CASS_BUTTON',	 'ENABLED', 0)
        Set_Property(@WINDOW:'.REM_WM_OUT', 		 'ENABLED', 0)
    END
    
    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:'.ALL_RDS_KEYS' 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
    
    PartStepArray = Get_Property(@WINDOW:'.PART_STEP_NO','ARRAY')
    
    PartStepCnt = COUNT(PartStepArray,@FM) + (PartStepArray NE '')
    
    FOR I = 1 TO PartStepCnt
        IF PartStepArray<COL$PART_STEP_PSN_TYPE,I>[1,1] = 'Q' THEN
            stat = Send_Message(@WINDOW:'.PART_STEP_NO','COLOR_BY_POS',COL$PART_STEP_PSN,I,YELLOW$)
            stat = Send_Message(@WINDOW:'.PART_STEP_NO','COLOR_BY_POS',COL$PART_STEP_PSN_TYPE,I,YELLOW$)
        end
    NEXT I
    
    WOStepArray = Get_Property(@WINDOW:'.WO_STEP','ARRAY')
    PSNos = WOStepArray<COL$WO_STEP_PSN>
    
    LOOP
        PSNo = PSNos[-1,1]
    UNTIL PSNo NE @VM OR PSNos = ''
        PSNos[-1,1] = ''
    REPEAT
    
    PSStatuses = XLATE('PROD_SPEC',PSNos,9,'X')
    PSNCnt = COUNT(PSNos,@VM) + (PSNos NE '')
    
    FOR I = 1 TO PSNCnt
        PSStatus = PSStatuses<1,I>
        IF PSStatus = 'I' THEN
            stat = Send_Message(@WINDOW:'.WO_STEP','COLOR_BY_POS',COL$WO_STEP_PSN,I,RED$)
        END
        
    NEXT I
    
    *********** Fill Conf Yield & Conf Scrap Edit Boxes ************
    WONo = Get_Property(@WINDOW:'.WO_NO', 'TEXT')
    If WONo NE '' then 
        Database_Services('ActivateRecord', 'WO_LOG', WONo)
        WOYield       = 0
        TotalScrapQty = 0
        ReactorType   = {REACT_TYPE}
        WOStepKey     = {WO_STEP_KEY}
        Begin Case
            Case ReactorType EQ 'GAN'
                WOStepRec = Database_Services('ReadDataRow', 'WO_STEP', WOStepKey)            
                RDSKeys = WOStepRec<WO_STEP_RDS_KEY$>
                For each RDSKey in RDSKeys using @VM
                    RDSYieldInfo = GaN_Services('GetYieldInfo', RDSKey)
                    GRWfrQty   = RDSYieldInfo<1>
                    ScrapQty   = RDSYieldInfo<2>
                    ProdTWQty  = RDSYieldInfo<3>
                    DummyQty   = RDSYieldInfo<4>
                    RDSYield   = GRWfrQty - ScrapQty - ProdTWQty - DummyQty
                    WOYield   += RDSYield
                    TotalScrapQty += ScrapQty
                Next RDSKey
            Case ( (ReactorType EQ 'EPP') or (ReactorType EQ 'P') )
                WOYield       = SUM({WO_MAT_SAP_YIELD})
                TotalScrapQty = Xlate('WO_STEP', WOStepKey, 'TOT_REJ_TOTAL', 'X')
            Case Otherwise$
                WOYield       = SUM({WO_MAT_SAP_YIELD})
                TotalScrapQty = SUM({WO_MAT_SAP_CONFIRM_SCRAP})
        End Case

        Set_Property(@Window:'.SAP_CONFIRM_SCRAP', 'TEXT', TotalScrapQty)
        Set_Property(@Window:'.SAP_YIELD_QTY', 'TEXT', WOYield)
    end
    
    ReactType = Get_Property(@Window:'.REACTOR_TYPE', 'TEXT')
    If ReactType EQ 'GAN' then ReactType = 'GaN'
    Set_Property(@Window:'.REACT_TYPE_GROUP', 'TEXT', ReactType)

    RxQty         = Get_Property(@Window:'.RX_QTY', 'TEXT')
    RelQty        = Get_Property(@Window:'.REL_QTY', 'TEXT')
    Swap ',' with '' in RxQty
    Swap ',' with '' in RelQty
    If Num(RxQty) and Num(RelQty) then
        AvailToRel    = RxQty - RelQty
        RelBtnEnabled = (AvailToRel GT 0)
        Set_Property(@Window:'.RELEASE_BUTTON', 'ENABLED', RelBtnEnabled)
    end

    Set_Property(@Window, 'REDRAW', True$)

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'
        
        WOKeys = Popup(@WINDOW,TypeOver,'WO_LOG_QUERY')
        IF Get_Status(errCode) THEN
            ErrMsg(errCode)
        END
        
        IF WOKeys NE '' THEN obj_Appwindow('ViewRelated',@WINDOW:@RM:WOKeys)		;* Loads form key or QBFList as required
    END
RETURN


* * * * * * *
LUPriority:
* * * * * * *
    
    Set_Status(0)
    
    Priority = Popup(@WINDOW,'','WO_PRIORITY')
    
    IF Priority NE '' THEN
        obj_Appwindow('LUValReturn',Priority:@RM:@WINDOW:'.':Parm1)
    END
    
RETURN


* * * * * * *
WONoLF:
* * * * * * *
    DataValue = Get_Property(@WINDOW:'.WO_NO','DEFPROP')
    
    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
        
    END
    
    Result = 1
    
RETURN


* * * * * * *
LUProdVer:
* * * * * * *
    
    WONo 		= Get_Property(@WINDOW:'.WO_NO','DEFPROP')
    EpiPartNo	= Get_Property(@WINDOW:'.EPI_PART_NO','DEFPROP')
    SubPartNo	= Get_Property(@WINDOW:'.ORD_SUB_PART_NO','DEFPROP')
    ProdVerNo	= Get_Property(@WINDOW:'.PROD_VER_NO','DEFPROP')
    
    IF ProdVerNo NE '' THEN
        ErrMsg('ProdVer Numbers may not be changed.')
        RETURN
    END
    
    AllProdVerNos = XLATE('EPI_PART',EpiPartNo,EPI_PART_PROD_VER_NO$,'X')
    SubPartNos = XLATE('PROD_VER',AllProdVerNos,PROD_VER_SUB_PART_NO$,'X')
    
    ProdVerCnt = COUNT(AllProdVerNos,@VM) + (AllProdVerNos NE '')
    
    DisplayKeys = ''
    
    FOR I = 1 TO ProdVerCnt
        IF SubPartNos<1,I> = SubPartNo THEN
            DisplayKeys<1,-1> = AllProdVerNos<1,I>
        END
    NEXT I
    
    IF DisplayKeys = '' THEN
        DisplayKeys = AllProdVerNos
    END
    
    TypeOver = ''
    TypeOver<PDISPLAY$> = DisplayKeys
    TypeOver<PSELECT$> = 1
    TypeOver<PMODE$> = 'K'
    
    ProdVerNo = Popup(@WINDOW,TypeOver,'PROD_VER')
    IF ProdVerNo = '' THEN RETURN
    
    IF NOT(MemberOf(@USER4,'RELEASE_ALL')) THEN
        IF MemberOf(@USER4,'RELEASE') THEN
            
            ProdVerRec 	= XLATE('PROD_VER',ProdVerNo,'','X')
            Captive		= XLATE('COMPANY', ProdVerRec<PROD_VER_CUST_NO$>,COMPANY_CAPTIVE$,'X')
            SpecType	= XLATE('PROD_SPEC', ProdVerRec<PROD_VER_PROC_STEP_PSN$,1> ,'SPEC_TYPE', 'X')
            
            IF NOT(Captive) THEN
                ErrMsg('This is a merchant order')
                RETURN
            END
            
            If SpecType = 'Q' Then								;* Added to prevent routing by S&R for qual runs. -dkk 4/14/14
                ErrMsg('The Prod Spec for this Captive order is Engineeing.')
                RETURN
            END
            
        END	ELSE
            RETURN
        END
    END
    
    Send_Event(@WINDOW,'WRITE')
    
    obj_WO_Log('Route',WONo:@RM:ProdVerNo)
    
    IF Get_Status(errCode) THEN
        ErrMsg(errCode)
    END
    
    obj_AppWindow('LoadFormKeys',@WINDOW:@RM:WONo)
    
RETURN


* * * * * * *
ProdVerLF:
* * * * * * *
    
    WONo		= Get_Property(@WINDOW:'.WO_NO','DEFPROP')
    ProdVerNo	= Get_Property(@WINDOW:'.PROD_VER_NO','DEFPROP')
    
    ChkProdVer = XLATE('WO_LOG',WONo,WO_LOG_PROD_VER_NO$,'X')
    
    IF ProdVerNo NE '' AND ProdVerNo NE ChkProdVer THEN
        Recipients		= XLATE('NOTIFICATION','WO_ENTRY',NOTIFICATION_USER_ID$,'X')
        SentFrom		= @USER4
        Subject			= 'Work Order Routed ':WONo
        Message			= 'Work Order Routed.'
        
        NewForm = Xlate('APP_INFO', 'NEW_WO_FORM', '', 'X')
        If NewForm then
            AttachWindow	= 'NDW_WO_LOG'
        end else
            AttachWindow	= 'WO_LOG2'
        end
        
        AttachKey		= WONo
        SendToGroup		= ''   
        
        Parms = Recipients:@RM:SentFrom:@RM:Subject:@RM:Message:@RM:AttachWindow:@RM:AttachKey:@RM:SendToGroup
        obj_Notes('Create',Parms)
        
        IF Get_Status(errCode) THEN
            ErrMsg(errCode)
        END
    END
    
RETURN


* * * * * * *
UnrouteWO:
* * * * * * *
    
    WONo = Get_Property(@WINDOW:'.WO_NO','DEFPROP')
    ProdVerNo = Get_Property(@WINDOW:'.PROD_VER_NO','DEFPROP')
    
    IF WONo = '' OR ProdVerNo = '' THEN RETURN
    
    Send_Event(@WINDOW,'WRITE')
    
    obj_WO_Log('Unroute',WONo)
    
    IF Get_Status(errCode) THEN
        ErrMsg(errCode)
    END
    
    obj_AppWindow('LoadFormKeys',@WINDOW:@RM:WONo)
    
RETURN


* * * * * * *
ViewProdVer:
* * * * * * *
    
    ProdVerNo = Get_Property(@WINDOW:'.PROD_VER_NO','DEFPROP')
    
    IF ProdVerNo NE '' THEN
        obj_AppWindow('ViewRelated','PROD_VER':@RM:ProdVerNo)
    END
    
RETURN

* * * * * * *
ViewCust:
* * * * * * *
    
    CustNo = Get_Property(@WINDOW:'.CUST_NO','TEXT')
    
    IF CustNo NE '' THEN
        obj_Appwindow('ViewRelated','CUSTOMER_EPI':@RM:CustNo)
    END
    
RETURN


* * * * * * *
CommDtGF:
* * * * * * *
    
RETURN	;* Replaced by logic in Refresh method

CommitDt	= Get_Property(@WINDOW:'.COMMIT_DT','TEXT')
RxStamp		= Get_Property(@WINDOW:'.RX_STAMP','TEXT')

IF RxStamp = '' THEN RETURN

RxDt = RxStamp[1,' ']

IF RxDt NE '' AND CommitDt = '' THEN
    
    thisRxDt = ICONV(RxDt,'D')
    
    CycleTimeCode = Get_Property(@WINDOW:'.CYCLE_TIME','VALUE')
    IF CycleTimeCode = '' THEN CycleTimeCode  = 'E'
    
    BEGIN CASE
        CASE CycleTimeCode = 'P'
            CommitDt = OCONV(thisRxDT + 2,'D4/')
            
        CASE CycleTimeCode = 'E'
            CommitDt = OCONV(thisRxDt + 7,'D4/')
            
        CASE CycleTimeCode = 'F'
            CommitDt = OCONV(thisRxDt + 14,'D4/')
            
        CASE 1
            CommitDt = OCONV(thisRxDt + 14,'D4/')
            
    END CASE
    
    Set_Property(@WINDOW:'.COMMIT_DT','TEXT',CommitDt)
    Set_Property(@WINDOW:'.COMMIT_DT','SELECTION',1:@FM:65534)
END

GOSUB Refresh

RETURN


* * * * * * *
ShipDtGF:
* * * * * * *
    
    CommitDt = Get_Property(@WINDOW:'.COMMIT_DT','TEXT')
    
    ShipDt = Get_Property(@WINDOW:'.CUST_SHIP_DT','TEXT')
    
    IF CommitDt NE '' AND ShipDt = '' THEN
        
        Set_Property(@WINDOW:'.CUST_SHIP_DT','TEXT',CommitDt)
        Set_Property(@WINDOW:'.CUST_SHIP_DT','SELECTION',1:@FM:65534)
    END
    
    GOSUB Refresh
    
RETURN


* * * * * * *
CycleTimeClick:
* * * * * * *
    
RETURN		;* Replaced by code in Refresh 2/4/2010 JCH

CycleTimeCode = Get_Property(@WINDOW:'.CYCLE_TIME','VALUE')

RxStamp = Get_Property(@WINDOW:'.RX_STAMP','TEXT')

IF RxStamp = '' THEN RETURN

RxDt = RxStamp[1,' ']

thisRxDt = ICONV(RxDt,'D')

BEGIN CASE
    CASE CycleTimeCode = 'P'
        CommitDt = OCONV(thisRxDt + 2,'D4/')
        
    CASE CycleTimeCode = 'E'
        CommitDt = OCONV(thisRxDt + 7,'D4/')
        
    CASE CycleTimeCode = 'F'
        CommitDt = OCONV(thisRxDt + 14,'D4/')
        
    CASE 1
        CommitDt = OCONV(thisRxDt + 14,'D4/')
        
END CASE

Set_Property(@WINDOW:'.COMMIT_DT','DEFPROP',CommitDt)

GOSUB Refresh

RETURN


* * * * * * *
ViewQuote:
* * * * * * *
    
    QuoteNo = Get_Property(@WINDOW:'.QUOTE_NO','TEXT')
    
    IF QuoteNo = '' THEN RETURN
    
    obj_AppWindow('ViewRelated','QUOTE2':@RM:QuoteNo)
    
RETURN


* * * * * * *
QuoteGF:
* * * * * * *
    
    QuoteNo = Get_Property(@WINDOW:'.QUOTE_NO','TEXT')
    
    IF QuoteNo NE '' THEN RETURN
    
    
    * * * * * * *
LUQuote:
* * * * * * *
    
    CustNo = Get_Property(@WINDOW:'.CUST_NO','DEFPROP')
    ProdVerNo = Get_Property(@WINDOW:'.PROD_VER_NO','DEFPROP')
    
    OPEN 'DICT.QUOTE' TO DictVar THEN
        SearchString  = 'CUST_NO':@VM:CustNo:@FM
        SearchString := 'STATUS':@VM:'=O':@FM
        SearchString := 'PROD_VER_NO':@VM:ProdVerNo:@FM
        
        Btree.Extract(SearchString, 'QUOTE', DictVar, QuoteKeys, '', Flag)
        IF Get_Status(errCode) THEN
            Msg(@window, MsgUp)
            ErrMsg(errCode)
            RETURN
        END
        
        IF QuoteKeys = '' THEN
            ErrMsg('No Quotes on file for customer ':CustNo)
            RETURN
        END
        
        IF INDEX(QuoteKeys,@VM,1) THEN
            
            QuoteKeys := @VM
            CONVERT @VM TO @RM IN QuoteKeys
            CALL V119('S','','D','R',QuoteKeys,'')
            CONVERT @RM TO @VM IN QuoteKeys
            QuoteKeys[-1,1] = ''					;* Strip trailing delimiter	
            
            TypeOver = ''
            TypeOver<PDISPLAY$> = QuoteKeys
            TypeOver<PSELECT$>	= 1				;* Single value select
            TypeOver<PTITLE$>	= 'Open Quotes for ':OCONV(CustNo,'[XLATE_CONV,COMPANY*CO_NAME]')
            
            QuoteKey = Popup(@WINDOW,TypeOver,'QUOTE')
            
        END ELSE
            QuoteKey = QuoteKeys
        END
        
        QuoteRec = XLATE('QUOTE',QuoteKey,'','X')
        PSNo = QuoteRec<7>
        
        QuoteNo = QuoteKey
        
    END	;* End of DICT.QUOTE open
    
    IF QuoteNo NE '' THEN
        obj_Appwindow('LUValReturn',QuoteNo:@RM:@WINDOW:'.QUOTE_NO')
        
    END
    
    
RETURN


* * * * * * *
ViewOrder:
* * * * * * *
    
    OrderNo = Get_Property(@WINDOW:'.ORDER_NO','TEXT')
    
    IF OrderNo = '' THEN RETURN
    
    obj_AppWindow('ViewRelated','ORDER2':@RM:OrderNo)
    
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


* * * * * * *
ViewCustEpiPart:
* * * * * * *
    
    CustEpiPartKey = Get_Property(@WINDOW:'.CUST_EPI_PART_KEY','DEFPROP')
    
    IF CustEpiPartKey = '' THEN RETURN
    
    WONo = Get_Property(@WINDOW:'.WO_NO','DEFPROP')
    
    IF WONo = '' THEN RETURN
    
    Send_Event(@WINDOW,'WRITE')
    
    
    DetWindow	= 'CUST_EPI_PART'
    DetKeys		= CustEpiPartKey
    DefaultRec	= ''
    RetKey		= WONo
    RetPage		= 1
    RetCtrl		= @WINDOW:'.CUST_EPI_PART_BUTTON'
    RetPos		= ''
    
    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
    
RETURN


* * * * * * * 
OpenWOS:
* * * * * * *
    
    OpenWONo = obj_WO_Log('OpenWONos','')
    
    IF OpenWONo NE '' THEN
        obj_AppWindow('LoadFormKeys',@WINDOW:@RM:OpenWONo)
    END
    
RETURN


* * * * * * *
Unrouted:
* * * * * * *
    
    UnroutedWONos = Popup(@WINDOW,'','WO_LOG_UNROUTED')
    
    IF UnroutedWONos = '' THEN
        ErrMsg('No Unrouted Work Orders on file.')
        RETURN
    END
    
    IF INDEX(UnroutedWONos,@VM,1) THEN
        Set_Property(@WINDOW,'QBFLIST',UnroutedWONos)
    END ELSE
        obj_AppWindow('LUValReturn',UnroutedWONos:@RM:@WINDOW:'.WO_NO')
    END
    
    GOSUB Refresh
    
    
RETURN


* * * * * * *
Release:
* * * * * * *
 
    AppShutdown = Database_Services('ReadDataRow', 'APP_INFO', 'APP_SHUTDOWN')
    If AppShutDown then
        
        Message = 'Unable to release cassettes at this time because OpenInsight is shutting down.'
        Msg(@Window, '', 'OK', '', 'App Shutting Down':@FM:Message)
        
    end else
        
        ReleaseStartDTM = Datetime()
    
        WONo = Get_Property(@WINDOW:'.WO_NO','TEXT')
        IF WONo = '' THEN RETURN
        
        PSNo = Get_Property(@WINDOW:'.WO_STEP','DEFPROP')<2,1>
        
        PSMode = XLATE('PROD_SPEC',PSNo,'SPEC_TYPE','X')
        
        IF PSMode = 'Q' OR PSMode = 'U' THEN
            
            ReactType = Get_Property(@WINDOW:'.REACTOR_TYPE','INVALUE')
            
            IF ReactType = 'EPP' OR ReactType = 'EpiPro' THEN
                
                OutLoadQty = Get_Property(@WINDOW:'.CUST_EPI_PART_WMO_LOAD_CNT','DEFPROP')
                IF OutLoadQty = '' THEN
                    Set_Property(@WINDOW:'.CUST_EPI_PART_WMO_LOAD_CNT','BACKCOLOR',RED$)
                    ErrMsg('Process Error':@SVM:'Outbound Load Cnt is required for ':OCONV(PSMode,'[PROD_SPEC_MODE_CONV]'):' Work Orders.')
                    RETURN
                END
                
            END ELSE
                
                OutLoadQty = Get_Property(@WINDOW:'.CUST_EPI_PART_SHIP_QTY','DEFPROP')
                IF OutLoadQty = '' THEN
                    ErrMsg('Process Error':@SVM:'Cass Ship Qty is required for ':OCONV(PSMode,'[PROD_SPEC_MODE_CONV]'):' Work Orders.')
                    Set_Property(@WINDOW:'.CUST_EPI_PART_SHIP_QTY','FOCUS',1)
                    RETURN
                END
            END
            
        END ;* End of check for PreQual or Qual PSN's
        
        CassList = Get_Property(@WINDOW:'.CASS_NO','LIST')
        
        LOOP
            LastLine = CassList[-1,'B':@FM]
        UNTIL LastLine<1,1> NE '' OR LastLine = ''
            CassList[COL1(),COL2()] = ''
        REPEAT
        
        CassCnt = COUNT(CassList,@FM) + (CassList NE '')
        
        UnReleasedCassNos = ''
        FOR I = 1 TO CassCnt
            IF ( (CassList<I,COL$CASS_REL_DTM> = '') and (CassList<I,COL$CASS_CASS_ID_SAP> = '') and (CassList<I,COL$CASS_CURR_STATUS> = 'Received') )  THEN
                UnReleasedCassNos<1,-1> = CassList<I,1>
            END
        NEXT I
        
        Send_Event(@WINDOW,'WRITE')
        
        TempWONo = WONo
        Set_Status(0)

        obj_WO_Log('ReleaseCassettes',TempWONo:@RM:UnReleasedCassNos)		;* This variable gets changed down the line
        
        ReleaseStopDTM = Datetime()
        
        IF Get_Status(errCode) THEN
            ErrMsg(errCode)
            RETURN
        END
        
        RefreshStartDTM = Datetime()
        obj_AppWindow('LoadFormKeys',@WINDOW:@RM:WONo)
        RefreshStopDTM = Datetime()
        
        OrderNo = Get_Property(@WINDOW:'.ORD_NO','TEXT')
        
        Recipients		= XLATE('NOTIFICATION','WO_ENTRY',NOTIFICATION_USER_ID$,'X')
        SentFrom		= @USER4
        Subject			= 'Work Order Released ':WONo
        Message			= 'Work Order Released to Production.'
        
        NewForm = Xlate('APP_INFO', 'NEW_WO_FORM', '', 'X')
        If NewForm then
            AttachWindow	= 'NDW_WO_LOG'
        end else
            AttachWindow	= 'WO_LOG2'
        end
        
        AttachKey   = WONo
        SendToGroup = ''   
        
        Parms = Recipients:@RM:SentFrom:@RM:Subject:@RM:Message:@RM:AttachWindow:@RM:AttachKey:@RM:SendToGroup
        obj_Notes('Create',Parms)
        
        IF Get_Status(errCode) THEN
            ErrMsg(errCode)
        END

        // Calculate duration in seconds
        ReleaseDuration = (ReleaseStopDTM - ReleaseStartDTM) * 60 * 60 * 24
        RefreshDuration = (RefreshStopDTM - RefreshStartDTM) * 60 * 60 * 24
        TotalDuration   = ReleaseDuration + RefreshDuration

        NumCass       = DCount(UnReleasedCassNos,@VM)
        LogData       = ''
        LogData<1>    = Oconv(Date(), 'D4/') : ' ' : Oconv(Time(), 'MTS')
        LogData<2>    = WONo
        LogData<3>    = @User4
        LogData<4>    = NumCass
        LogData<5>    = ReleaseDuration
        LogData<6>    = RefreshDuration
        LogData<7>    = TotalDuration
        If NumCass GT 0 then
            LogData<8>    = TotalDuration / NumCass
        end else
            LogData<8>    = 'N/A'
        end
        Logging_Services('AppendLog', objReleaseLog, LogData, @RM, @FM)
        
    end
    
RETURN


* * * * * * *
Recall:
* * * * * * *
    
    WONo = Get_Property(@WINDOW:'.WO_NO','TEXT')
    IF WONo = '' THEN RETURN
    
    Response = Msg(@WINDOW,'','WO_PURGE')
    
    IF Response = CHAR(27) THEN RETURN
    
    Send_Event(@WINDOW,'WRITE')
    
    TempWONo = WONo
    Set_Status(0)
    
    WORec			= XLATE('WO_LOG',WONo,'','X')
    WOMatKeys		= WORec<WO_LOG_WO_MAT_KEY$>
    WMInKeys		= XLATE('WO_MAT',WOMatKeys,WO_MAT_WMI_KEY$,'X')
    WMInTestSTring	= WMInKeys
    
    CONVERT @VM TO '' IN WMInTestString
    
    RDSNos = ''
    CassNos = ''
    
    IF WMInTestString NE '' THEN
        
        * EpiPRO material inbound
        
        EpiRDSNos = XLATE('WM_IN',WMInKeys,WM_IN_RDS_NO$,'X')
        EpiNCRNos = XLATE('WM_IN',WMInKeys,WM_IN_SLOT_NCR$,'X')
        
        CONVERT @VM TO '' IN EpiRDSNos
        CONVERT @VM TO '' IN EpiNCRNos
        
        IF EpiRDSNos NE '' OR EpiNCRNos NE '' THEN
            
            ErrMsg('Processing has started. Work Order cannot be recalled.')
            obj_AppWindow('LoadFormKeys',@WINDOW:@RM:WONo)
            RETURN
            
        END
        
    END ELSE
        
        WOMatSigs = XLATE('WO_MAT',WOMatKeys,WO_MAT_SIGNATURE$,'X')
        
        CONVERT @VM TO '' IN WOMatSigs
        
        IF WOMatSigs NE '' THEN
            ErrMsg('Processing has started. Work Order cannot be recalled.')
            obj_AppWindow('LoadFormKeys',@WINDOW:@RM:WONo)
            RETURN
        END
        
    END
    
    obj_WO_Log('RecallWO',TempWONo)		;* This variable gets changed down the line
    
    IF Get_Status(errCode) THEN
        
        Def = ''
        Def<MTEXT$>		= errCode[-1,'B':@SVM]			;* Error handling system puts a title in front of the @SVM, strip it off here
        Def<MICON$>		= '!'
        Def<MTYPE$>		= 'BO'
        Def<MCAPTION$>	= 'Work Order Recall'
        Def<MJUST$>		= 'C'
        
        Msg(@WINDOW,Def,'')
        Set_Status(0)
        
        obj_AppWindow('LoadFormKeys',@WINDOW:@RM:WONo)
        Send_Event(@WINDOW,'PAGE',2)
        
        RETURN
    END
    
    obj_AppWindow('LoadFormKeys',@WINDOW:@RM:WONo)
    
    Recipients = XLATE('NOTIFICATION','WO_ENTRY',NOTIFICATION_USER_ID$,'X')
    SentFrom   = @USER4
    Subject    = 'Work Order Recalled ':WONo
    Message    = 'Work Order Recalled from Production.'
    NewForm    = Xlate('APP_INFO', 'NEW_WO_FORM', '', 'X')
    If NewForm then
        AttachWindow	= 'NDW_WO_LOG'
    end else
        AttachWindow	= 'WO_LOG2'
    end
    AttachKey		= WONo
    SendToGroup		= ''   
    
    Parms = Recipients:@RM:SentFrom:@RM:Subject:@RM:Message:@RM:AttachWindow:@RM:AttachKey:@RM:SendToGroup
    obj_Notes('Create',Parms)
    
    IF Get_Status(errCode) THEN
        ErrMsg(errCode)
    END
    
RETURN



* * * * * * *
PrintLabels:
* * * * * * *

    WONo = Get_Property(@WINDOW:'.WO_NO','DEFPROP')
    
    IF WONo = '' THEN RETURN
    
    Send_Event(@WINDOW,'WRITE')
    
    
    WOSteps = XLATE('WO_LOG',WONo,WO_LOG_WO_STEP_KEY$,'X')
    
    IF INDEX(WOSteps,@VM,1) THEN
        Buttons = ''
        FOR I = 1 TO COUNT(WOSteps,@VM) + (WOSteps NE '')
            Buttons<I> = 'Step ':I
        NEXT I
        SWAP @FM WITH ',' IN Buttons
        Buttons = 'B':Buttons
        
        TypeOver = ''
        TypeOver<MTEXT$> 	= 'Which Work Order step do you wish to print labels for?'
        TypeOver<MTYPE$> 	= Buttons
        TypeOver<MICON$> 	= '?'
        TypeOver<MCAPTION$>	= 'MultiStep WorkOrder Selection'
        WOStep = Msg(@window, TypeOver)
        MultiStepFlag = WOStep
    END ELSE
        WOStep = 1
        MultiStepFlag = 0
    END
    
    IF WOStep = 1 THEN
        PSNo = XLATE('WO_STEP',WONo:'*1',WO_STEP_PROD_SPEC_ID$,'X')
        ReactorType = XLATE('PROD_SPEC',PSNo,PROD_SPEC_REACTOR_TYPE$,'X')
        
        IF ReactorType = 'GAN' THEN
            Print_WO_Mat_In_Labels(WONo,'')
            Print_WO_Mat_Out_Labels(WONo,'')
            RETURN
        END
        
        IF ReactorType = 'EPP' OR ReactorType = 'P' THEN
            Print_WMI_Labels(WONo,1)
            Print_WMO_Labels(WONo,1)
            RETURN
        END
    END
    
    IF WOStep > 1 THEN
        
        Def = ""
        Def<MTEXT$> = "Adjusting Step ":WOStep:" Scheduled Quantities..."
        Def<MTYPE$> = "U"
        
        MsgUp = Msg(@window, Def)
        
        RDSNos = obj_WO_Step('AdjStepRDSQtys', WOStep:@RM:WOSteps)
        
        IF Get_Status(errCode) THEN
            
            ErrMsg(errCode)											;* Display error from the update
            Msg(@WINDOW,MsgUp)										;* Take down the processing message
            obj_AppWindow('LoadFormKeys',@WINDOW:@RM:WONo)			;* Reload the data in the form
            
            RETURN
        END
        Msg(@WINDOW,MsgUp)
        
    END ELSE
        RDSNos = XLATE('WO_STEP',WOSteps<1,1>,WO_STEP_RDS_KEY$,'X')
    END
    
    IF MemberOf(@USER4,'OI_ADMIN') THEN
        WOMatKeys = XLATE('WO_LOG',WONo,WO_LOG_WO_MAT_KEY$,'X')
        CONVERT @VM TO @FM IN WOMatKeys
        AllRDSNos = XLATE('WO_MAT',WOMatKeys,WO_MAT_RDS_NO$,'X')
        
        RDSNos = ''
        
        LOOP
            CassRDSNos = AllRDSNos[1,@FM]
            AllRDSNos[1,COL2()] = ''
        UNTIL CassRdsNos = ''
            RDSNos := CassRdsNos<1,WOStep>:@VM
        REPEAT
        
        RDSNos[-1,1] = ''
        
    END
    
    IF INDEX(RDSNos,@VM,1) THEN
        TypeOver = ''
        TypeOver<PDISPLAY$> = RDSNos
        TypeOver<PFIELD$>	= 2
        TypeOver<PTYPE$>	= 'K'
        
        RDSKeys = Popup(@WINDOW,TypeOver,'WO_LOG_RTS')
        
    END ELSE
        RDSKeys = RDSNos
    END
    
    IF RDSKeys = '' THEN 
        ErrMsg('No RDS Numbers Selected or Work Order Not Yet Released to Production.')
    END ELSE
        CONVERT @VM TO @FM IN RDSKeys
        
        Print_Cass_Labels(RDSKeys,MultiStepFlag)				;* Updated labels with Akrion Bar Codes
        
    END
    
    obj_AppWindow('LoadFormKeys',@WINDOW:@RM:WONo)
    
RETURN


* * * * * * * 
PrintReleaseTicket:
* * * * * * *
    
    WONo = Get_Property(@WINDOW:'.WO_NO','TEXT')
    IF WONo = '' THEN RETURN
    
    Send_Event(@WINDOW,'WRITE')
    
    Set_Status(0)
    
    Print_WO_Release(WONo)
    
    IF Get_Status(errCode) THEN ErrMsg(errCode)
    
    obj_AppWindow('LoadFormKeys',@WINDOW:@RM:WONo)
    
    Set_Property('SYSTEM','FOCUS','VSPRINTER')
    
RETURN


* * * * * * * 
PrintShelfLabels:
* * * * * * *
    
    WONo = Get_Property(@WINDOW:'.WO_NO','TEXT')
    IF WONo = '' THEN RETURN
    
    Send_Event(@WINDOW,'WRITE')
    
    Set_Status(0)
    
    Print_Shelf_Label(WONo)
    
    IF Get_Status(errCode) THEN ErrMsg(errCode)
    
    obj_AppWindow('LoadFormKeys',@WINDOW:@RM:WONo)
    
RETURN


* * * * * * *
RxWafers:
* * * * * * *
    
    WONo = Get_Property(@WINDOW:'.WO_NO','TEXT')
    IF WONo = '' THEN RETURN
    
    Send_Event(@WINDOW,'WRITE')
    
    DetWindow	= 'WO_REC'
    DetKeys		= WONo
    DefaultRec	= ''
    RetKey		= WONo
    RetPage		= 1
    RetCtrl		= @WINDOW:'.RX_BUTTON'
    RetPos		= ''
    
    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
    
RETURN


* * * * * * *
RxReprocess:
* * * * * * *
    
    WONo = Get_Property(@WINDOW:'.WO_NO','TEXT')
    IF WONo = '' THEN RETURN
    
    Send_Event(@WINDOW,'WRITE')
    
    CheckArray = WONo
    
    DetWindow	= 'WO_REPROCESS'
    DetKeys		= WONo
    DefaultRec	= ''
    RetKey		= WONo
    RetPage		= 1
    RetCtrl		= @WINDOW:'.REPROCESS_BUTTON'
    RetPos		= ''
    
    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
    
    
RETURN


* * * * * * *
ChangeLotNo:
* * * * * * *
    
    WONo	= Get_Property(@WINDOW:'.WO_NO','TEXT')
    IF WONo = '' THEN RETURN
    
    Send_Event(@WINDOW,'WRITE')
    
    Result = Dialog_Box('DIALOG_LOT_NO_CHANGE',@WINDOW,WONo)
    
    IF Result = 'Cancel' THEN RETURN
    
    OrgLotNo	= Result<1>
    NewLotNo	= Result<2>
    Reason		= Result<3>
    CassNos		= Result<4>
    
    obj_WO_Log('ChangeLotNo',WONo:@RM:OrgLotNo:@RM:NewLotNo:@RM:Reason:@RM:CassNos)
    
    IF Get_Status(errCode) THEN
        ErrMsg(errCode)
    END ELSE
        
        Recipients = XLATE('NOTIFICATION','WO_ENTRY',NOTIFICATION_USER_ID$,'X')
        SentFrom   = @USER4
        Subject    = 'Lot No Changed in WO ':WONo
        Message    = 'Lot No Change in WO.'
        NewForm    = Xlate('APP_INFO', 'NEW_WO_FORM', '', 'X')
        If NewForm then
            AttachWindow	= 'NDW_WO_LOG'
        end else
            AttachWindow	= 'WO_LOG2'
        end
        AttachKey		= WONo
        SendToGroup		= ''   
        
        Parms = Recipients:@RM:SentFrom:@RM:Subject:@RM:Message:@RM:AttachWindow:@RM:AttachKey:@RM:SendToGroup
        obj_Notes('Create',Parms)
    END
    
    IF Get_Status(errCode) THEN
        ErrMsg(errCode)
    END
    
    obj_AppWindow('LoadFormKeys',@WINDOW:@RM:WONo)
    
    
RETURN


* * * * * * *
ChangeCassQty:
* * * * * * *
    
    
    WONo = Get_Property(@WINDOW:'.WO_NO','TEXT')
    IF WONo = '' THEN RETURN
    
    CassList = Get_Property(@WINDOW:'.CASS_NO','LIST')
    
    LOOP
        LastLine = CassList[-1,'B':@FM]
    UNTIL LastLine<1,1> NE '' OR LastLine = ''
        CassList[COL1(),COL2()] = ''
    REPEAT
    
    Send_Event(@WINDOW,'WRITE')
    
    CassettesList = XLATE('WO_LOG',WONo,WO_LOG_WO_MAT_KEY$,'X')
    
    CassCnt = COUNT(CassList,@VM) + (CassList NE '')
    
    Result = Dialog_Box('DIALOG_CASS_QTY_CHANGE',@WINDOW,WONo:@FM:CassettesList)
    
    IF Result = 'Cancel' THEN RETURN
    
    CassNo		= Result[1,@FM]
    Reason		= Result[COL2()+1,@FM]
    OrgCassQty	= Result[COL2()+1,@FM]
    NewCassQty	= Result[COL2()+1,@FM]
    
    obj_WO_Log('ChangeCassQty',WONo:@RM:CassNo:@RM:NewCassQty:@RM:Reason)
    
    IF Get_Status(errCode) THEN
        ErrMsg(errCode)
    END ELSE
        
        Recipients		= XLATE('NOTIFICATION','WO_ENTRY',NOTIFICATION_USER_ID$,'X')
        SentFrom		= @USER4
        Subject			= 'Cassette Quantity Change ':WONo:'*':CassNo
        Message			= 'Cassette Quantity Change. WOMatNo: ':WONo:'*':CassNo
        AttachWindow	= 'WO_MAT'
        AttachKey		= WONo:'*':CassNo
        SendToGroup		= ''   
        Parms = Recipients:@RM:SentFrom:@RM:Subject:@RM:Message:@RM:AttachWindow:@RM:AttachKey:@RM:SendToGroup
        obj_Notes('Create',Parms)
    END
    
    IF Get_Status(errCode) THEN
        ErrMsg(errCode)
    END
    
    obj_AppWindow('LoadFormKeys',@WINDOW:@RM:WONo)
    
RETURN


* * * * * * *
ChangeCustPartNo:
* * * * * * *
    
    Ctrls  = @WINDOW:'.WO_NO':@RM			; Props  = 'DEFPROP':@RM
    Ctrls := @WINDOW:'.CUST_PART_NO':@RM	; Props := 'DEFPROP':@RM
    Ctrls := @WINDOW:'.WO_MAT_KEY'			; Props := 'DEFPROP'
    
    Vals = Get_Property(Ctrls,Props)
    
    WONo 		= Vals[1,@RM]
    CustPartNo	= Vals[COL2()+1,@RM]
    WOMatKeys	= Vals[COL2()+1,@RM]
    
    LOOP
        TestChar = WOMatKeys[-1,1]
    UNTIL TestChar NE @VM OR WOMatKeys = ''
        WOMatKeys[-1,1] = ''
    REPEAT
    
    IF WONo			= '' THEN RETURN
    IF CustPartNo	= '' THEN RETURN
    IF WOMatKeys 	= '' THEN RETURN
    
    obj_WO_Mat('SetPartNo',WOMatKeys:@RM:CustPartNo)
    
    IF Get_Status(errCode) THEN
        ErrMsg(errCode)
    END ELSE
        
        Recipients		= XLATE('NOTIFICATION','WO_ENTRY',NOTIFICATION_USER_ID$,'X')
        SentFrom		= @USER4
        Subject			= 'Customer Part No Changed ':WONo
        Message			= 'Customer Part No Changed on WONo ':WONo
        AttachWindow	= 'WO_No'
        AttachKey		= WONo
        SendToGroup		= ''   
        
        Parms = Recipients:@RM:SentFrom:@RM:Subject:@RM:Message:@RM:AttachWindow:@RM:AttachKey:@RM:SendToGroup
        obj_Notes('Create',Parms)
    END
    
    IF Get_Status(errCode) THEN
        ErrMsg(errCode)
    END
    
    Send_Event(@WINDOW,'READ')
    
RETURN


* * * * * * *
ChangePONo:
* * * * * * *
    
    WONo = Get_Property(@WINDOW:'.WO_NO','TEXT')
    IF WONo = '' THEN
        /* Missing the Work Order parameter */
        RETURN
    END
    
    Send_Event(@WINDOW,'WRITE')
    
    Parent = @window
    Result = Dialog_Box('DIALOG_PO_NO_CHANGE', Parent, WONo)
    
    IF Get_Status(errCode) THEN
        ErrMsg(errCode)
        
    END ELSE
        IF (Result = 'PO Number Changed') THEN
            Recipients = XLATE('NOTIFICATION','WO_ENTRY',NOTIFICATION_USER_ID$,'X')
            SentFrom   = @USER4
            Subject    = 'PO Number Changed in WO ':WONo
            Message    = 'PO Number Change in WO.'
            NewForm    = Xlate('APP_INFO', 'NEW_WO_FORM', '', 'X')
            If NewForm then
                AttachWindow	= 'NDW_WO_LOG'
            end else
                AttachWindow	= 'WO_LOG2'
            end
            AttachKey		= WONo
            SendToGroup		= ''   
            Parms = Recipients:@RM:SentFrom:@RM:Subject:@RM:Message:@RM:AttachWindow:@RM:AttachKey:@RM:SendToGroup
            obj_Notes('Create',Parms)
        END
    END
    
    IF Get_Status(errCode) THEN
        ErrMsg(errCode)
    END
    
    obj_AppWindow('LoadFormKeys',@WINDOW:@RM:WONo)
    
RETURN


* * * * * * *
RemCassettes:
* * * * * * *

    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$>
    WMInKeys	= XLATE('WO_MAT',WOMatKeys,WO_MAT_WMI_KEY$,'X')
    
    WMInKeys		= XLATE('WO_MAT',WOMatKeys,WO_MAT_WMI_KEY$,'X')
    WMInTestSTring	= WMInKeys
    
    CONVERT @VM TO '' IN WMInTestString
    
    WMInCnt = COUNT(WMInKeys,@VM) + (WMinKeys NE '')
    
    RDSNos = ''
    CassNos = ''
    
    WMIData = ''
    RDSData = ''
    
    Display = ''
    DispLine = 1
    
    IF WMInTestString NE '' THEN
        
        FOR I = WMInCnt TO 1 STEP -1
            WMIRec = XLATE('WM_IN',WMInKeys<1,I>,'','X')
            WMIRdsNos = WMIRec<WM_IN_RDS_NO$>
            WMINCRNos = WMIRec<WM_IN_SLOT_NCR$>
            CONVERT @VM TO '' IN WMIRdsNos
            CONVERT @VM TO '' IN WMINCRNos
        UNTIL WMIRdsNos NE '' OR WMINCRNos NE ''
            Display<1,DispLine,1> = FIELD(WOMatKeys<1,I>,'*',2)
            Display<1,DispLine,2> = XLATE('WO_MAT',WOMatKeys<1,I>,WO_MAT_LOT_NO$,'X')
            Display<1,DispLine,3> = XLATE('WO_MAT',WOMatKeys<1,I>,WO_MAT_WAFER_QTY$,'X')
            Display<1,DispLine,4> = WMInKeys<1,I>
            Display<1,DispLine,5> = OCONV(XLATE('WM_IN',WMInKeys<1,I>,'CURR_STATUS','X'),'[WM_IN_CURR_STATUS_CONV]')
            DispLine += 1
        NEXT I
        
        IF Display NE '' THEN
            TypeOver = ''
            TypeOver<PDISPLAY$> = Display
            WMIData = Popup(@WINDOW,TypeOver,'UNUSED_WM_IN')
            
            WMIDCnt = COUNT(WMIData,@FM) + (WMIData NE '')
            FOR N = 1 TO WMIDCnt
                IF WMIData<N,1> NE Display<1,N,1> THEN
                    ErrMsg('You must pick cassettes from the top line downward in sequence.')
                    obj_AppWindow('LoadFormKeys',@WINDOW:@RM:WONo)
                    RETURN
                END
            NEXT N
            
            IF WMIData = '' OR WMIData = CHAR(27) THEN
                obj_AppWindow('LoadFormKeys',@WINDOW:@RM:WONo)
                RETURN	;* Cancelled out
            END
        END ELSE
            ErrMsg('All cassettes on this Work Order have started processing.')
            obj_AppWindow('LoadFormKeys',@WINDOW:@RM:WONo)
            RETURN
        END
        
        DelWMInKeys = ''
        FOR I = 1 TO COUNT(WMIData,@FM) + (WMIData NE '')
            CassNos<1,I> = WMIData<I,1>
            DelWMInKeys<1,I> = WMIData<I,4>
        NEXT I
        
        TestWMInKeys = DelWMInKeys
        CONVERT @VM TO '' IN TestWMInKeys
        
        IF TestWMInKeys NE '' THEN
            Set_Status(0)
            obj_WM_In('Delete',DelWMInKeys)					;* Removes WMI records from system
            
            IF Get_Status(errCode) THEN
                ErrMsg(errCode)
            END
        END
        
        Set_Status(0)
        obj_WO_Log('RemoveCassettes',WONo:@RM:CassNos)
        
        IF Get_Status(errCode) THEN
            ErrMsg(errCode)
        END
        
    END ELSE
        
        CassCnt = COUNT(WOMatKeys,@VM) + (WOMatKeys NE '')
        
        FOR I = CassCnt TO 1 STEP -1
            
            WOMatKey = WOMatKeys<1,I>
            WOMatRec = XLATE('WO_MAT',WOMatKey,'','X')
            
            WOMatCurrStatus = obj_WO_Mat('CurrStatus',WOMatKey:@RM:WOMatRec)
            
            WOMatSigs = WOMatRec<WO_MAT_SIGNATURE$>
            CONVERT @VM TO '' IN WOMatSigs
            
        UNTIL WOMatSigs NE ''
            Display<1,DispLine,1> = WOMatKeys<1,I>[-1,'B*']
            Display<1,DispLine,2> = WOMatRec<WO_MAT_LOT_NO$>
            Display<1,DispLine,3> = WOMatRec<WO_MAT_WAFER_QTY$>
            Display<1,DispLine,4> = WOMatRec<WO_MAT_RDS_NO$>
            Display<1,DispLine,5> = OCONV(WOMatCurrStatus,'[WO_MAT_CURR_STATUS_CONV]')
            DispLine += 1
        NEXT I
        
        IF Display NE '' THEN
            TypeOver = ''
            TypeOver<PDISPLAY$> = Display
            UnusedData = Popup(@WINDOW,TypeOver,'UNUSED_RDS')
        END ELSE
            ErrMsg('All cassettes on this Work Order have started processing.')
            obj_AppWindow('LoadFormKeys',@WINDOW:@RM:WONo)
            RETURN
        END
        
        IF UnusedData = '' OR UnusedData = CHAR(27) THEN
            obj_AppWindow('LoadFormKeys',@WINDOW:@RM:WONo)
            RETURN	;* Cancelled out
        END
        
        UnusedCnt = COUNT(UnusedData,@FM) + (UnusedData NE '')
        
        FOR I = 1 TO UnusedCnt
            IF Display<1,I,1> = UnusedData<I,1> THEN
                CassNos<1,I> = UnusedData<I,1>
                RDSNos<1,I> = UnusedData<I,4>
            END ELSE
                Msg(@WINDOW,'','WO_MAT_REMOVAL')
                obj_AppWindow('LoadFormKeys',@WINDOW:@RM:WONo)
                RETURN
            END
        NEXT I
        
        TestRDSNos = RDSNos
        CONVERT @VM TO '' IN TestRDSNos
        IF TestRDSNos NE '' THEN
            Set_Status(0)
            InProcessRDSNos = obj_RDS('Delete',RDSNos)			;* Removes RDS records from system
            
            IF Get_Status(errCode) THEN
                ErrMsg(errCode)
            END
        END
        
        Set_Status(0)
        obj_WO_Log('RemoveCassettes',WONo:@RM:CassNos)
        
        IF Get_Status(errCode) THEN
            ErrMsg(errCode)
        END
    END
    
    IF Display = '' THEN
        ErrMsg('All cassettes on this Work Order have started processing.')
        RETURN
    END
    
    Recipients = XLATE('NOTIFICATION','WO_ENTRY',NOTIFICATION_USER_ID$,'X')
    SentFrom   = @USER4
    Subject    = 'Unprocessed Cassettes removed from WO ':WONo
    Message    = 'Cassettes removed from WO.'
    NewForm    = Xlate('APP_INFO', 'NEW_WO_FORM', '', 'X')
    If NewForm then
        AttachWindow	= 'NDW_WO_LOG'
    end else
        AttachWindow	= 'WO_LOG2'
    end
    AttachKey		= WONo
    SendToGroup		= ''   
    
    Parms = Recipients:@RM:SentFrom:@RM:Subject:@RM:Message:@RM:AttachWindow:@RM:AttachKey:@RM:SendToGroup
    obj_Notes('Create',Parms)
    
    IF Get_Status(errCode) THEN
        ErrMsg(errCode)
    END
    
    obj_AppWindow('LoadFormKeys',@WINDOW:@RM:WONo)
    
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)								;* Removes WMO records from system
            
            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)
    
RETURN


* * * * * * *
RefreshSigProfile:
* * * * * * * 
    
    WONo = Get_Property(@WINDOW:'.WO_NO','TEXT')
    IF WONo = '' THEN RETURN
    
    Send_Event(@WINDOW,'WRITE')
    
    Set_Status(0)
    
    obj_WO_Log('RefreshSigProfile',WONo)
    
    IF Get_Status(errCode) THEN ErrMsg(errCode)
    
    obj_AppWindow('LoadFormKeys',@WINDOW:@RM:WONo)
    
RETURN


* * * * * * *
MUWaferDetail:
* * * * * * * 
    
    WONo = Get_Property(@WINDOW:'.WO_NO','DEFPROP')
    
    IF WONo = '' THEN Return
    
    Utility('CURSOR', 'H')
    Response    = Dialog_Box('NDW_MAKEUP_WAFERS', @Window, WONo)
    
RETURN


* * * * * * *
StartStopDtClick:
* * * * * * *
    
    Ctrls  = @WINDOW:@RM					; Props  = 'FOCUS':@RM
    Ctrls := @WINDOW:'.WO_NO':@RM			; Props := 'DEFPROP':@RM
    Ctrls := @WINDOW:'.PROD_VER_NO':@RM		; Props := 'DEFPROP':@RM
    Ctrls := @WINDOW:'.WO_MAT_KEY'			; Props := 'DEFPROP'
    
    Vals = Get_Property(Ctrls,Props)
    
    CtrlEntID	= Vals[1,@RM]
    WONo		= Vals[COL2()+1,@RM]
    ProdVerNo	= Vals[COL2()+1,@RM]
    WOMatKeys	= Vals[COL2()+1,@RM]
    
    IF WONo = '' THEN RETURN
    
    CtrlName = FIELD(CtrlEntID,'.',2)
    
    ReactType = XLATE('PROD_VER',ProdVerNo,PROD_VER_REACT_TYPE$,'X')
    
    IF ReactType = 'EPP' THEN RETURN		;* EpiPro is working don't mess with it.
    
    IF CtrlName = 'WO_START_DT' THEN
        CurrText = Get_Property(CtrlEntID,'TEXT')
        IF CurrText[1,' ']= 'Clear' THEN
            Set_Property(@WINDOW:'.WO_START_DTM','TEXT','')
        END ELSE
            RelStamp = Get_Property(@WINDOW:'.REL_STAMP','DEFPROP')<1,1>
            TimeStamp = FIELD(RelStamp,' ',1,2)
            Set_Property(@WINDOW:'.WO_START_DTM','TEXT',TimeStamp)
        END
    END
    
    IF CtrlName = 'WO_STOP_DT' THEN
        CurrText = Get_Property(CtrlEntID,'TEXT')
        IF CurrText[1,' ']= 'Clear' THEN
            Set_Property(@WINDOW:'.WO_STOP_DTM','TEXT','')
        END ELSE
            TimeStamp = OCONV(Date(),'D4/'):' ':OCONV(Time(),'MTH')
            Set_Property(@WINDOW:'.WO_STOP_DTM','TEXT',TimeStamp)
        END
    END
    
RETURN


* * * * * * *
LUCustPartNo:
* * * * * * *
    EpiPN = Get_Property(@WINDOW:'.EPI_PART_NO','DEFPROP')
    CustNo = Get_Property(@WINDOW:'.CUST_NO','DEFPROP')
    
    IF EpiPN = '' THEN
        ErrMsg('Missing Epi Part No.')
        RETURN
    END
    
    IF CustNo = '' THEN
        ErrMsg('Missing Cust No.')
        RETURN
    END
    
    CustEPRec = XLATE('CUST_EPI_PART',CustNo:'*':EpiPN,'','X')
    
    CustPNs			= CustEPRec<CUST_EPI_PART_CUST_PART_NO$>
    CustPNRevs 		= CustEPRec<CUST_EPI_PART_CUST_PART_REV$>
    CustPNInbounds	= CustEPRec<CUST_EPI_PART_CUST_PART_NO_INBOUND$>
    CustPNDescs		= CustEPRec<CUST_EPI_PART_CUST_PART_DESC$>
    
    CustPNCnt = COUNT(CustPNs,@VM) + (CustPNs NE '')
    
    IF CustPNCnt = 1 THEN
        CustPN			= CustPNs
        CustPNInbound	= CustPNInbounds
    END ELSE
        
        Display = ''
        
        FOR I = 1 TO CustPNCnt
            Display<1,I,1> = CustPNs<1,I>
            Display<1,I,2> = CustPNRevs<1,I>
            Display<1,I,3> = CustPNDescs<1,I>
            Display<1,I,4> = CustPNInbounds<1,I>
        NEXT I
        
        TypeOver = ''
        TypeOver<PDISPLAY$>	= Display
        
        CustPNLine = Popup(@WINDOW,TypeOver,'CUST_EPI_PART_PART_NOS')
        CustPN 			= CustPNLine<1,1>
        CustPNInbound	= CustPNLine<1,3>
        
    END
    
    IF CustPN NE '' THEN
        Set_Property(@WINDOW:'.CUST_PART_NO','DEFPROP',CustPN)
        Set_Property(@WINDOW:'.CUST_PART_INBOUND','DEFPROP',CustPNInbound)
    END
    
RETURN


* * * * * * *
LUCustSubNo:
* * * * * * *
    
    EpiPN = Get_Property(@WINDOW:'.EPI_PART_NO','DEFPROP')
    CustNo = Get_Property(@WINDOW:'.CUST_NO','DEFPROP')
    
    IF EpiPN = '' THEN
        ErrMsg('Missing Epi Part No.')
        RETURN
    END
    
    IF CustNo = '' THEN
        ErrMsg('Missing Cust No.')
        RETURN
    END
    
    CustEPIRec = XLATE('CUST_EPI_PART',CustNo:'*':EpiPN,'','X')
    
    SubPartNos = CustEPIRec<CUST_EPI_PART_SUBSTRATE_PART_NO$>
    SubPartMfrs = CustEPIRec<CUST_EPI_PART_SUBSTRATE_MFR$>
    
    SubPartCnt = COUNT(SubPartNos,@VM) + (SubPartNos NE '')
    
    IF SubPartCnt = 1 THEN
        SubPartNo = SubPartNos
        SubPartMfr = SubPartMfrs
    END ELSE
        
        Display = ''
        
        FOR I = 1 TO SubPartCnt
            Display<1,I,1> = SubPartNos<1,I>
            Display<1,I,2> = SubPartMfrs<1,I>
        NEXT I
        
        TypeOver = ''
        TypeOver<PDISPLAY$> = Display
        
        SubPNLine = Popup(@WINDOW,TypeOver,'CUST_EPI_SUB_PART_NOS')
        
        SubPartNo = SubPNLine<1,1>
        SubPartMfr = SubPNLine<1,2>
    END
    
    IF SubPartNo NE '' THEN
        Set_Property(@WINDOW:'.CUST_SUB_PART_NO','DEFPROP',SubPartNo)
        Set_Property(@WINDOW:'.CUST_SUB_MFR','DEFPROP',SubPartMfr)
    END
    
RETURN


* * * * * * * *
Purge:
* * * * * * * *
    
    WONo = Get_Property(@WINDOW:'.WO_NO','DEFPROP')
    
    MsgHead	= 'Purge Work Order from System'
    MsgText	= 'Are you sure you wish to purge WO':WONo:' and all associated data from the system?'
    
    OK = Msg(@WINDOW,'','YESNO','',MsgHead:@FM:MsgText)
    
    IF OK = 1 THEN
        Send_Event(@WINDOW,'CLEAR')
        
        OrgColor = Set_Property('WO_LOG2.STATUSLINE_FIX','BACKCOLOR',YELLOW$)	;* //////// Messaging
        
        Log = WO_Purge(WONo)
        
        
        Typeover = ''
        Typeover<PDISPLAY$>	= Log
        
        Dummy = Popup(@WINDOW,TypeOver,'WO_PURGE_LOG')
        
        Send_Info(STR(' ',60))															;** - Messaging - **
        Dummy = Set_Property('WO_LOG2.STATUS_LINE_FIX','BACKCOLOR',OrgColor)			;** - Messaging - **
        
    END
    
RETURN


* * * * * * *
ShipDC:
* * * * * * *
    
    CtrlEntID = @WINDOW:'.SHIP_NO'
    
    ProdOrdNo = Get_Property(@WINDOW:'.PROD_ORD_NO','DEFPROP')
    
    
    CurrPos = Get_Property(CtrlEntID,'SELPOS')
    CurrCol = CurrPos<1>
    CurrRow = CurrPos<2>
    
    ShipNo = Get_Property(CtrlEntID,'CELLPOS',1:@FM:CurrRow)	;* Ship No is in column 1
    
    IF ShipNo NE '' THEN
        IF ProdOrdNo = '' THEN
            obj_AppWindow('ViewRelated','SHIPMENT':@RM:ShipNo)
        END ELSE
            obj_AppWindow('ViewRelated','SAP_SHIPMENT':@RM:ShipNo)
        END
    END
    
RETURN


* * * * * * *
PrintWO:
* * * * * * *
    
    WONo = Get_Property(@WINDOW:'.WO_NO','DEFPROP')
    
    IF WONo = '' THEN RETURN
    
    Send_Event(@WINDOW,'WRITE')
    
    Confirmation = Parm1
    
    Print_WO(WONo,Confirmation)
    
    obj_AppWindow('LoadFormKeys',@WINDOW:@RM:WONo)
    
    Set_Property('SYSTEM','FOCUS','VSPRINTER')
    
RETURN


