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

/*
	Commuter module for NCR (Non Conforming Report) window
	03/27/2006 - John C. Henry, J.C. Henry & Co., Inc.
*/

COMMON /Comm_NCR/ Module@, Routine@, RoutineParams@

DECLARE SUBROUTINE Set_Property,  Set_Status, ErrMsg, Set_Property, obj_AppWindow, obj_RDS2, Post_Event, obj_React_Run
DECLARE SUBROUTINE Btree.Extract, Send_Event, Security_Err_Msg, Forward_Event, End_Window, obj_WO_Mat, obj_WO_Wfr
DECLARE SUBROUTINE obj_Tables,Set_List_Box_Data, Send_Message, Print_NCR, obj_Notes, obj_WM_In, obj_WM_Out, RList
DECLARE SUBROUTINE Database_Services, SPC_Services, Logging_Services, Get_EventStatus, NCR_Services, Error_Services

DECLARE FUNCTION Get_Property, Get_Status, Popup, Send_Message, Msg, Security_Check, Dialog_Box, RowExists
DECLARE FUNCTION Dialog_Box, obj_RDS, obj_Tables, MemberOf, Check_Notes, Start_Window, obj_WO_Mat, Environment_Services
DECLARE FUNCTION Error_Services, Database_Services, Signature_Services, Logging_Services

$INSERT POPUP_EQUATES
$INSERT LOGICAL
$INSERT MSG_EQUATES
$INSERT APPCOLORS
$INSERT NCR_EQUATES
$INSERT RDS_EQU
$INSERT REACTOR_EQUATES
$INSERT LSL_USERS_EQU
$INSERT QUOTE_SIGS_EQU
$INSERT SECURITY_RIGHTS_EQU
$INSERT NOTIFICATION_EQU
$INSERT WM_OUT_EQUATES
$INSERT WO_MAT_EQUATES
$INSERT RLIST_EQUATES
$INSERT SPC_QUEUE_EQUATES
$INSERT WO_WFR_EQUATES
$INSERT WO_MAT_WFR_EQUATES
$INSERT REACT_RUN_EQUATES

EQU CRLF$	TO \0D0A\
EQU TAB$	TO CHAR(9)

EQU HIDDEN$		TO 32
EQU CHECKBOX$	TO 65536

EQU COL$SLOT		TO 1		;* Non-EpiPRO cassette slot checkboxes

EQU COL$OUT_CASS	TO 1		;* EpiPRO slot information
EQU COL$OUT_SLOT	TO 2
EQU COL$RDS			TO 3
EQU COL$POCKET		TO 4
EQU COL$ZONE		TO 5
EQU COL$IN_CASS		TO 6
EQU COL$IN_SLOT		TO 7
EQU COL$PREV_NCR	TO 8
EQU COL$MU_WO_NO	TO 9
EQU COL$MU_STEP		TO 10
EQU COL$MU_CASS		TO 11
EQU COL$MU_SLOT		TO 12

EQU WMOD_COL$OUT_SLOT		TO 1
EQU WMOD_COL$RDS			TO 2
EQU WMOD_COL$POCKET			TO 3
EQU WMOD_COL$ZONE			TO 4
EQU WMOD_COL$IN_CASS		TO 5
EQU WMOD_COL$IN_SLOT		TO 6
EQU WMOD_COL$SLOT_NCR		TO 7
EQU WMOD_COL$MU_WO_NO		TO 8
EQU WMOD_COL$MU_STEP		TO 9
EQU WMOD_COL$MU_CASS		TO 10
EQU WMOD_COL$MU_SLOT		TO 11
EQU WMOD_COL$UM_CASS_ID		TO 12
EQU WMOD_COL$UM_SLO			TO 13

EQU COL$RDS_NO		TO 1
EQU COL$REACTOR		TO 2
EQU COL$REJ_CNT		TO 3

EQU WFR_COL$SLOT			TO 1
EQU WFR_COL$WAFER_ID		TO 2
EQU WFR_COL$SLOT_NCR		TO 3
EQU WFR_COL$MET_NO			TO 4
EQU WFR_COL$MOVED_TO_SLOT	TO 5
EQU WFR_COL$REPLACED_BY		TO 6

EQU WFR_SLOT$WFR_ID			TO 1
EQU WFR_SLOT$CASS_SLOT_ID	TO 2
EQU WFR_SLOT$CARR_SLOT_ID	TO 3
EQU WFR_SLOT$SUSC_RPZ		TO 4

ErrTitle = 'Error in Comm_NCR'
ErrorMsg = ''

LogDate           = Oconv(Date(), 'D4/')
LogTime           = Oconv(Time(), 'MTS')
RemNCRLogPath     = Environment_Services('GetApplicationRootPath') : '\LogFiles\NCR'
RemNCRLogFileName = LogDate[7, 4] : '-' : LogDate[1, 2] : '-' : LogDate[4, 2] : ' REM_NCR.csv'
RemNCRHeaders     = 'Logging DTM':@FM:'WONo':@FM:'CassNo':@FM:'NCRNo':@FM:'SlotNos':@FM:'RejWaferIDs':@FM:'PrevNCRNos':@FM:'Notes':@FM:'User'
RemNCRObjLog      = Logging_Services('NewLog', RemNCRLogPath, RemNCRLogFileName, CRLF$, Comma$, RemNCRHeaders, '', False$, False$)
LoggingDTM        = LogDate : ' ' : LogTime

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 = 'CalcRejQty'			; GOSUB CalcRejQty
	CASE Instruction = 'LUNcrNo'			; GOSUB LUNcrNo
	CASE Instruction = 'LUTeam'				; GOSUB LUTeam
	CASE Instruction = 'LULossCd'			; GOSUB LULossCd
	CASE Instruction = 'LUACCd'				; GOSUB LUACCd
	CASE Instruction = 'ViewRDS'			; GOSUB ViewRDS
	CASE Instruction = 'PrintNCR'			; GOSUB PrintNCR
	CASE Instruction = 'DeptMgrSig'			; GOSUB DeptMgrSig
	CASE Instruction = 'DeviationSig'		; GOSUB DeviationSig
	CASE Instruction = 'RejectSig'			; GOSUB RejectSig
	CASE Instruction = 'ShipSig'			; GOSUB ShipSig
	CASE Instruction = 'SetAllSlots'		; GOSUB SetAllSlots
	CASE Instruction = 'ClearAllSlots'		; GOSUB ClearAllSlots
	CASE Instruction = 'RdsDC'				; GOSUB RdsDC
	CASE Instruction = 'CorrectSlots'		; GOSUB CorrectSlots
	CASE Instruction = 'CorrectEpiSlots'	; GOSUB CorrectEpiSlots
	CASE Instruction = 'DeptRespLF'			; GOSUB DeptRespLF
	CASE Instruction = 'LossByClick'		; GOSUB LossByClick
	CASE 1
		ErrorMsg = 'Unknown Instruction ':QUOTE(Instruction):' passed to routine'
		
END CASE

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

RETURN Result


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

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

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

IF Security_Check( 'NCR', EDIT$ ) ELSE
   Security_Err_Msg( 'NCR', EDIT$ )
END

obj_Appwindow('Create',@WINDOW)

IOOptions     = Get_Property(@WINDOW,'IOOPTIONS')
IOOptions<10> = 1	;* Check required fields on write only
* IOOptions<2>  = 2   ;* Do not lock

Set_Property(@WINDOW,'IOOPTIONS',IOOptions)

Set_List_Box_Data( @WINDOW )

* Provides compatibility with the existing messaging attachment system

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

SlotStyles = Send_Message( @WINDOW:'.CASSETTE_SLOT', "COLSTYLE", 0, '' )

SlotStyles<1> = BitOr( SlotStyles<1>, CHECKBOX$ )

Send_Message( @WINDOW:'.CASSETTE_SLOT', "COLSTYLE", 0, SlotStyles )

IOOptions = Get_Property(@WINDOW,'IOOPTIONS')
IOOptions<11> = 1	;* Generate READ event on QBFLoad

Set_Property(@WINDOW,'IOOPTIONS',IOOptions)


IF MemberOf( @USER4, 'SUPERVISOR' ) OR MemberOf( @USER4, 'ENGINEERING' ) OR MemberOf( @USER4,'LEAD') OR MemberOf( @USER4,'FINAL_QA') Then;*Added Final_QA usergroup  dkk 7/20/16
	Set_Property(@WINDOW:'.ROOT_CAUSE_GROUP','ENABLED',1)
	Set_Property(@WINDOW:'.SEND_SPC','ENABLED',1)
END ELSE
	Set_Property(@WINDOW:'.ROOT_CAUSE_GROUP','ENABLED',0)
	Set_Property(@WINDOW:'.SEND_SPC','ENABLED',0)
END

GOSUB Page
GOSUB Refresh

RETURN


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

NCRId = Get_Property(@WINDOW,'ID')

IF RowExists('NCR',NCRId) THEN
	IF NOT(Security_Check('NCR',READ$)) THEN
		Send_Event(@WINDOW,'CLEAR')
		Security_Err_Msg('NCR',READ$)
		RETURN
	END
	
	IF NOT(Security_Check('NCR',EDIT$)) THEN
		obj_Appwindow('ReadOnly',@WINDOW)					;*Set to Read Only
	END
	
END ELSE
	ErrMsg('NCR entries may only be created from the RDS window.')
	Send_Event(@WINDOW,'CLEAR')
	RETURN
END

IF Get_Property(@WINDOW,'QBFLIST') = '' THEN
	GOSUB CalcRejQty
	WONo = Get_Property(@WINDOW:'.WO_NO','DEFPROP')
	CassNo = Get_Property(@WINDOW:',WO_MAT_CASS_NO','DEFPROP')
END

GOSUB Refresh

RETURN


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

IOOptions    = Get_Property(@Window, "IOOPTIONS")
IOOptions<6> = True$ ; // Do not clear the form after writing
Set_Property(@Window, "IOOPTIONS", IOOptions)

NCRId      = Get_Property(@WINDOW:'.NCR_NO','DEFPROP')
RejCnt     = Get_Property(@WINDOW:'.TOT_REJ','DEFPROP')
SAPBatchNo = Get_Property(@WINDOW:'.SAP_BATCH_NO','DEFPROP')
PartNoID   = Get_Property(@WINDOW:'.WO_MAT_PART_NO','DEFPROP')		;* Added
MUFlag     = OCONV(Get_Property(@WINDOW:'.MU_FLAG','DEFPROP'),'BYes,') 			;* Added - dkk 11/18/14

// Validate that the user has entered data in the required fields.
Error     = False$

ReqFields = 'SHIFT,DEPT,DEPT_RESP,LOSS_CODE,LOSS_COMMENTS,CONTAIN_ACTIONS,LOSS_STAGE,LOSS_BY'
ReqCtrls  = 'SHIFT,DEPARTMENT,DEPARTMENTRESP,LOSS_CODE,LOSS_COMMENTS,CONTAIN_ACTIONS,LOSS_STAGE,LOSS_BY'
For each ReqField in ReqFields using ',' setting cPos
    Ctrl = Field(ReqCtrls, ',', cPos)
    Val  = Get_Property(@Window:'.':Ctrl, 'DEFPROP')
    If Val EQ '' then
        Error     = True$
        Result    = 0
        ErrorDesc = ReqField:' is a required field.'
        ErrMsg(ErrorDesc)
        Set_Property(@Window, '@WRITE_ERROR', ErrorDesc)
        Set_Property(@Window:'.':Ctrl, 'FOCUS', True$)
    end
Until Error
Next ReqField

If Error EQ False$ then
    // Continue with pre-existing validation logic
    SkipChecks = Get_Property(@WINDOW,'@SKIP_WRITE_CHECKS')

    IF SkipChecks = 1 THEN
        Result = 1
        Set_Property(@WINDOW,'@SKIP_WRITE_CHECKS','')
        RETURN
    END

    DeptResp = Get_Property(@WINDOW:'.DEPARTMENTRESP','TEXT')

    OrgDeptResp = XLATE('NCR',NcrId,NCR_DEPT_RESP$,'X')

    IF DeptResp NE OrgDeptResp THEN 

        DeptManager = ''
        QSRec = XLATE( 'CONFIG', 'QUOTE_SIGS', '', 'X' )

        IF DeptResp <> 'Customer' THEN
            IF OrgDeptResp = '' THEN
                BEGIN CASE
                   CASE DeptResp = 'Production'
                      *DeptManager = QSRec<ProdMgr$>
                      
                   CASE DeptResp = 'Engineering'
                      *DeptManager = QSRec<EngMgr$>
                      
                   CASE DeptResp = 'Maintenance'
                      DeptManager = QSRec<MaintMgr$>
                      
                   CASE DeptResp = 'Facilities'
                      *DeptManager = QSRec<FacilMgr$>
                      
                   CASE DeptResp = 'Shipping'
                      DeptManager = QSRec<ShipMgr$>
                      
                   CASE DeptResp = 'Metrology'
                      DeptManager = QSRec<MetMgr$>
                      
                END CASE
                
                IF DeptManager NE '' THEN
                    Recipients		= DeptManager
                    SentFrom		= @USER4
                    Subject			= 'NCR Created'
                    Message			= "NCR ":NCRId:" created."
                    AttachWindow	= 'NCR'
                    AttachKey		= NCRId
                    SendToGroup		= ''

                    Parms = Recipients:@RM:SentFrom:@RM:Subject:@RM:Message:@RM:AttachWindow:@RM:AttachKey:@RM:SendToGroup
                    obj_Notes('Create',Parms)
                END
            END
            
            IF DeptResp = 'Maintenance' THEN
            
                IF OrgDeptResp = '' THEN
                    Message	= "NCR ":NCRId:" with Maintenance as Department Responsible created."
                END ELSE
                    Message = "NCR ":NCRId:" Department Responsible was changed to Maintenance."
                END
                
                Recipients 		= XLATE('NOTIFICATION','MAINT_NCR',NOTIFICATION_USER_ID$,'X')
                SentFrom		= @USER4
                Subject			= 'Maintenance NCR Created'
                AttachWindow	= 'NCR'
                AttachKey		= NCRId
                SendToGroup		= ''

                Parms = Recipients:@RM:SentFrom:@RM:Subject:@RM:Message:@RM:AttachWindow:@RM:AttachKey:@RM:SendToGroup
                obj_Notes('Create',Parms)
            END

        END
    END

*    LossBy = Get_Property(@WINDOW:'.LOSS_BY','VALUE')
*    IF LossBy = '' THEN
*        ErrMsg('Caused By is a required field.')
*        Set_Property(@WINDOW:'.LOSS_BY','FOCUS',1)
*        Result = 0
*        RETURN
*    END
*        
*        
*    LossStage = Get_Property(@WINDOW:'.LOSS_STAGE','VALUE')
* 
*    IF LossStage = '' THEN
*        ErrMsg('Stage is a required field.')
*        Set_Property(@WINDOW:'.LOSS_STAGE','FOCUS',1)
*        Result = 0
*        RETURN
*    END

    Result = 1
    
    QBFList      = Get_Property(@WINDOW,'QBFLIST')
    CloseOnWrite = Get_Property(@Window, '@CLOSE_ON_WRITE')

    GOSUB Refresh
end

RETURN


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

Send_Event(@WINDOW,'PAGE',1)

obj_AppWindow('ReadOnly',@WINDOW:@RM:1)		;* Clear Read Only

GOTO Refresh

RETURN


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

LogData    = ''
LogData<1> = LoggingDTM
LogData<8> = 'Begin COMM_NCR("Delete")'
LogData<9> = @User4
Logging_Services('AppendLog', RemNCRObjLog, LogData, @RM, @FM)

SAPBatchNo = Get_Property(@Window:'.SAP_BATCH_NO', 'TEXT')

If SAPBatchNo EQ '' then 

    Modules       = ''
    Routines      = ''
    RoutineParams = ''

    GoSub FQAVerify

    If Not(Authorized) then Return 0

    NCRNo = Get_Property(@WINDOW:'.NCR_NO','DEFPROP')
    RejCnt = Get_Property(@WINDOW:'.TOT_REJ','TEXT')

    IF RejCnt > 5 THEN
       IF MemberOf( @USER4, 'ENGINEERING' ) OR (MemberOf(@USER4,'SUPERVISOR') OR (MemberOf( @USER4, 'LEAD'))) ELSE
          MsgInfo = ''
          MsgInfo<micon$> = '!'
          MsgInfo<mtext$> = 'There are more than 5 rejects, therefor an engineer must Remove NCR.'
          Void = msg( '', MsgInfo )      
          RETURN
       END
    END ELSE
       IF MemberOf( @USER4, 'ENGINEERING' ) OR MemberOf( @USER4, 'SUPERVISOR' ) OR  MemberOf( @USER4, 'LEAD' ) OR  MemberOf( @USER4, 'FINAL_QA' ) ELSE
          MsgInfo = ''
          MsgInfo<micon$> = '!'
          MsgInfo<mtext$> = 'You must be a Supervisor, Lead or Engineer to Remove NCR.'
          Void = Msg( '', MsgInfo )
          RETURN
       END
    END

    NCRNo		= Get_Property(@WINDOW:'.NCR_NO','DEFPROP')
    LossStage	= Get_Property(@WINDOW:'.LOSS_STAGE','DEFPROP')

    IF Get_Property(@WINDOW:'.SLOT_REJECT','VISIBLE') THEN
        
        * Non-EpiPro
        
        WONo		= Get_Property(@WINDOW:'.WO_NO','DEFPROP')
        WOMatCassNo = Get_Property(@WINDOW:'.WO_MAT_CASS_NO','DEFPROP')
        WOMatKey    = WONo:'*':WOMatCassNo
        SlotList    = Get_Property(@WINDOW:'.SLOT_REJECT','LIST')
        SlotCnt     = COUNT(SlotList,@FM) + (SlotList NE '')
        
        SlotNos = ''
        RejWaferIDs = ''
        PrevNCRNos = ''
        
        FOR I = 1 TO SlotCnt
            IF SlotList<I,1> NE '' THEN
                SlotNos<1,-1>		= SlotList<I,1>
                RejWaferIDs<1,-1> 	= SlotList<I,2>
                PrevNCRNos<1,-1>	= SlotList<I,3>
            END
        NEXT I
        
        LogData<2> = WONo
        LogData<3> = WOMatCassNo
        LogData<4> = NCRNo
        LogData<5> = SlotNos
        LogData<6> = RejWaferIDs
        LogData<7> = PrevNCRNos
        LogData<8> = 'COMM_NCR("Delete") - Line 430'
        Logging_Services('AppendLog', RemNCRObjLog, LogData, @RM, @FM)

        IF RejWaferIDs NE '' THEN
            
            * Need to check if makeup wafers are in the cassette associated with
            * the NCR that the user is attempting to delete. If so, do not allow NCR to be removed/deleted.
            WOMatNCRs   = Xlate('WO_MAT', WOMatKey, 'SLOT_NCR', 'X')
            WOMatMUWfrs = Xlate('WO_MAT', WOMatKey, 'SLOT_REP_WAFER_ID', 'X')
            
            MUWfrFound  = False$
            For each NCR in WOMatNCRs using @VM setting vPos
                If (NCR EQ NCRNo) and (WOMatMUWfrs<1, vPos> NE '') then
                    MUWfrFound = True$
                end
            Until MUWfrFound EQ True$
            Next NCR
            
            If MUWfrFound EQ True$ then
                ErrMsg('Makeup wafers must be returned before an NCR can be deleted.')
                // Stop the event handler from progressing to system event handler.
                return 0
            end else
            
                LogData<8> = 'COMM_NCR("Delete") - Line 454'
                Logging_Services('AppendLog', RemNCRObjLog, LogData, @RM, @FM)
                
                // Subroutine call moved to the end of this event after the user confirms the delete prompt.
                Modules       = 'OBJ_WO_MAT' : @RM
                Routines      = 'RemNCR' : @RM
                RoutineParams = WONo:@FM:WOMatCassNo:@FM:NCRNo:@FM:SlotNos:@FM:RejWaferIDs:@FM:PrevNCRNos:@RM
                
    *            obj_WO_Mat('RemNCR',WONo:@RM:WOMatCassNo:@RM:NCRNo:@RM:SlotNos:@RM:RejWaferIDs:@RM:PrevNCRNos)
                
                IF Get_Status(errCode) THEN
                    ErrMsg(errCode)
                    RETURN
                END
            END
        END
    END


    * * * GaN added 8/14/2016 JCH  * * *


    ReactType = Get_Property(@WINDOW:'.REACTOR_TYPE','DEFPROP')

    IF ReactType = 'GAN' THEN
        
        * GaN
        
        NCRRec    = Database_Services('ReadDataRow', 'NCR', NCRNo)                  
        RejWfrIDs = NCRRec<NCR_WFR_ID$>
        For each WfrID in RejWfrIDs using @VM setting WfrIndex
            // Determine NCR type (i.e. WMI, RDS, or WMO)
            WOWfrRec  = Database_Services('ReadDataRow', 'WO_WFR', WfrID)
            WmiNCRNo = WOWfrRec<WO_WFR_WMI_NCR_NO$>
            RdsNCRNo = WOWfrRec<WO_WFR_RDS_NCR_NO$>
            WmoNCRNo = WOWfrRec<WO_WFR_WMO_NCR_NO$>
            // Remove NCR_NO from the WO_WFR record
            Begin Case
                
                Case WmiNCRNo NE ''
                    
                    // Remove WMI NCR Key
                    WOWfrRec<WO_WFR_WMI_NCR_NO$>    = ''               
                     // Update WO_MAT_WFR wafer IDs (i.e. GaN Inbound Material)
                    WONo         = Field(WfrID, '*', 1)
                    CassNo       = Field(WfrID, '*', 2)
                    SlotIndex    = Field(WfrID, '*', 3)
                    WOMatWfrKey  = WONo:'*':CassNo
                    WOMatWfrRec  = Database_Services('ReadDataRow', 'WO_MAT_WFR', WOMatWfrKey)
                    AvailWfrs    = WOMatWfrRec<WO_MAT_WFR_IN_WFR_ID$>
                    ConsumedWfrs = WOMatWfrRec<WO_MAT_WFR_IN_PREV_WFR_ID$>
                    AvailWfrs<0, SlotIndex>     = WfrID
                    ConsumedWfrs<0, SlotIndex>  = ''
                    WOMatWfrRec<WO_MAT_WFR_IN_WFR_ID$>      = AvailWfrs
                    WOMatWfrRec<WO_MAT_WFR_IN_PREV_WFR_ID$> = ConsumedWfrs
                    Database_Services('WriteDataRow', 'WO_MAT_WFR', WOMatWfrKey, WOMatWfrRec, True$, False$, True$)
                    
                Case RdsNCRNo NE ''
                    
                    // Remove RDS NCR Key
                    WOWfrRec<WO_WFR_RDS_NCR_NO$>    = ''               
                    // Remove Grade from the REACT_RUN (RDS) record
                    ! RDS NCRs no longer stored in the RDS for GaN
                    RDSNo = Xlate('WO_WFR', WfrID, 'RDS_NO', 'X')
                    If RDSNo NE '' then
                        ReactRunRec = Database_Services('ReadDataRow', 'REACT_RUN', RDSNo)
                        InWfrIDs    = ReactRunRec<REACT_RUN_IN_WFR_ID$>
                        Locate WfrID in InWfrIDs using @VM setting vPos then
                             ReactRunRec<REACT_RUN_CARR_WFR_GRADE$, vPos> = ''
                             Database_Services('WriteDataRow', 'REACT_RUN', RDSNo, ReactRunRec, True$, False$, True$)
                        end
                    end
                    
                Case WmoNCRNo NE ''
                    
                    // WMO NCR Key
                    WOWfrRec<WO_WFR_WMO_NCR_NO$>    = ''
                    // Update WO_MAT_WFR wafer IDs (i.e. GaN Inbound Outbound Wafers)
                    WONo          = Field(WfrID, '*', 1)
                    CassNo        = Field(WfrID, '*', 2)
                    SlotIndex     = Field(WfrID, '*', 3)
                    WOMatWfrKey   = WONo:'*':CassNo
                    WOMatWfrRec   = Database_Services('ReadDataRow', 'WO_MAT_WFR', WOMatWfrKey)
                    OutWfrIDs     = WOMatWfrRec<WO_MAT_WFR_OUT_WFR_ID$>
                    PrevOutWfrIDs = WOMatWfrRec<WO_MAT_WFR_OUT_PREV_WFR_ID$>
                    OutWfrIDs<0, SlotIndex>     = ''
                    PrevOutWfrIDs<0, SlotIndex> = WfrID
                    WOMatWfrRec<WO_MAT_WFR_OUT_WFR_ID$>      = OutWfrIDs
                    WOMatWfrRec<WO_MAT_WFR_OUT_PREV_WFR_ID$> = PrevOutWfrIDs
                    Database_Services('WriteDataRow', 'WO_MAT_WFR', WOMatWfrKey, WOMatWfrRec, True$, False$, True$)
                    
            End Case

            Database_Services('WriteDataRow', 'WO_WFR', WfrID, WOWfrRec, True$, False$, True$)

        Next WfrID

        GaNProdVis = Get_Property('WO_PROD_GAN', 'VISIBLE')
        If GaNProdVis EQ True$ then Send_Event('WO_PROD_GAN', 'READ')
               
        InboundMatVis = Get_Property('NDW_GAN_INBOUND_MATERIAL', 'VISIBLE')
        If InboundMatVis EQ True$ then Send_Event('NDW_GAN_INBOUND_MATERIAL', 'OMNIEVENT')

        IF Get_Status(errCode) THEN
            ErrMsg('Unable to Remove NCR from GaN RDS ':QUOTE(RDSNo):'.')
        END
    END

    IF Get_Property(@WINDOW:'.CASS_NO','VISIBLE') THEN

        * EpiPro
        CassList	= Get_Property(@WINDOW:'.CASS_NO','LIST')
        InCassNos	= ''
        InSlotNos	= ''
        RDSNos		= ''
        PocketNos	= ''
        Zones		= ''
        OutCassNos	= ''
        OutSlotNos	= ''
        PrevNCRs	= ''
        MUWONos		= ''
        MUSteps		= ''
        MUCassIDs	= ''
        MUSlots		= ''	
        
        FOR I = 1 TO COUNT(CassList,@FM) + (CassList NE '')
            IF CassList<I,1> NE '' THEN
                InCassNos<1,-1>		= CassList<I,COL$IN_CASS>
                InSlotNos<1,-1>		= CassList<I,COL$IN_SLOT>
                RDSNos<1,-1>		= CassList<I,COL$RDS>
                PocketNos<1,-1> 	= CassList<I,COL$POCKET>
                Zones<1,-1>			= CassList<I,COL$ZONE>
                OutCassNos<1,-1>	= CassList<I,COL$OUT_CASS>
                OutSlotNos<1,-1>	= CassList<I,COL$OUT_SLOT>
                PrevNCRs<1,-1>		= CassList<I,COL$PREV_NCR>
                MUWONos<1,-1>		= CassList<I,COL$MU_WO_NO>
                MUSteps<1,-1>		= CassList<I,COL$MU_STEP>
                MUCassIDs<1,-1>		= CassList<I,COL$MU_CASS>
                MUSlots<1,-1>		= CassList<I,COL$MU_SLOT>
                
                
            END
        NEXT I

        IF InCassNos NE '' THEN

            RDSNo	= Get_Property(@WINDOW:'.RDS_ID','DEFPROP')
            
            IF LossStage = 'PRE' THEN

                WONo		= Get_Property(@WINDOW:'.WO_NO','DEFPROP')
                WOStep		= Get_Property(@WINDOW:'.WO_STEP','DEFPROP')
                EventDTM 	= OCONV(Date(),'D4/'):' ':OCONV(Time(),'MTS')
                
                FOR N = 1 TO COUNT(InCassNos,@VM) + (InCassNos NE '')
                    obj_WM_In('AddWafer',WONo:@RM:WOStep:@RM:InCassNos<1,N>:@RM:InSlotNos<1,N>)
                    IF Get_Status(errCode) THEN
                        ErrMsg(errCode)
                        RETURN
                    End
                    
                    * * * *   Added 3/23/2016  JCH - wafer history   * * * *
                    
                    EventWfrID = WONo:'*':InCassNos<1,N>:'*':InSlotNos<1,N>
                    
                    Parms  = EventWfrID:@RM				;* WfrID
                    Parms := 'NCR':@RM					;* Event to remove
                    Parms := NCRNo						;* NCR No for locate

                    obj_WO_Wfr('RemEvent',Parms)
                
                NEXT N
            END
            IF LossStage = 'POST' THEN
            
                WONo		= Get_Property(@WINDOW:'.WO_NO','DEFPROP')
                WOStep		= Get_Property(@WINDOW:'.WO_STEP','DEFPROP')
                EventDTM 	= OCONV(Date(),'D4/'):' ':OCONV(Time(),'MTS')
                
                IF OutCassNos<1,1> = '' THEN
                
                    * This is material rejected from the reactor during EpiPRO Unload (This should be dead************)
                    
                    obj_RDS2('RemovePocketNCR',RDSNo:@RM:NCRNo)
                    IF Get_Status(errCode) THEN
                        ErrMsg(errCode)
                        RETURN
                    END
                    
                END ELSE
                
                    * This is material rejected from the WM_OUT box
                    
                    WMOutKey = WONo:'*':WOStep:'*':OutCassNos<1,1>
                    WMOutRec = XLATE('WM_OUT',WMOutKey,'','X')
                    
                    osCnt = COUNT(OutSlotNos,@VM) + (OutSlotNos NE '')
                    
                    FOR N = 1 TO osCnt
                        OutSlotNo = OutSlotNos<1,N>
                        IF WMOutRec<WM_OUT_RDS$,OutSlotNo> NE '' AND WMOutRec<WM_OUT_POCKET$,OutSlotNo> NE '' THEN
                            * Make Up Wafers already in the box
                            ErrorMsg  = 'Makeup Wafers have already been placed in the cassette.':CRLF$:CRLF$
                            ErrorMsg := 'This NCR cannot be canceled until they are removed.'
                            
                            ErrMsg(ErrorMsg)
                            
                            RETURN
                        END
                    NEXT N
                    
                    
                    
                    FOR N = 1 TO COUNT(OutSlotNos,@VM) + (OutSlotNos NE '')
                        
                        wmoParms  = WONo:@RM
                        wmoParms := WOStep:@RM
                        wmoParms := OutCassNos<1,1>:@RM		;* These are all the same for this material
                        wmoParms := OutSlotNos<1,N>:@RM
                        wmoParms := RDSNos<1,N>:@RM
                        wmoParms := PocketNos<1,N>:@RM
                        wmoParms := Zones<1,N>:@RM
                        wmoParms := InCassNos<1,N>:@RM
                        wmoParms := InSlotNos<1,N>:@RM
                        wmoParms := PrevNCRs<1,N>:@RM
                        wmoParms := MUWONos<1,N>:@RM
                        wmoParms := MUSteps<1,N>:@RM
                        wmoParms := MUCassIDs<1,N>:@RM
                        wmoParms := MUSlots<1,N>:@RM
                        
                        // Add wafer data back to WM_OUT record
                        Modules       := 'obj_WM_Out' : @RM
                        Routines      := 'AddWafer' : @RM
                        Swap @RM with @FM in wmoParms
                        RoutineParams :=  wmoParms : @RM
                        
                        * * * *   Added 3/23/2016  JCH - wafer history   * * * *
                        // Remove NCR event from WO_WFR record
                        EventWfrID = WONo:'*':InCassNos<1,N>:'*':InSlotNos<1,N>
                                            
                        Parms  = EventWfrID:@RM				;* WfrID
                        Parms := 'NCR':@RM					;* Event to remove
                        Parms := NCRNo

                        Modules       := 'obj_WO_Wfr' : @RM
                        Routines      := 'RemEvent' : @RM
                        Swap @RM with @FM in Parms
                        RoutineParams := Parms : @RM
                        
                        // Remove NCR data from RDS record
                        RDSNo          = RDSNos<1, N>
                        Modules       := 'obj_RDS2' : @RM
                        Routines      := 'RemovePocketNCR' : @RM
                        RoutineParams := RDSNo : @FM : NCRNo : @RM
                        
                    NEXT N
                END
            END
                
        END
    END	;* End of check for EpiPRO rejects

    Forward_Event()
    EventCode  = ''
    Get_EventStatus(EventCode)

    If EventCode<0, 1> NE 'EV107' then
        // User pressed ok on delete prompt
        // Commit related delete events
        If Assigned(Modules) and Assigned(Routines) and Assigned(RoutineParams) then
            Swap @RM with '~' in Modules
            Swap @RM with '~' in Routines
            Swap @RM with '~' in RoutineParams
            For each Row in Modules using '~' setting Pos
                ServiceModule = Field(Modules, '~', Pos)
                Service       = Field(Routines, '~', Pos)
                ServiceParams = Field(RoutineParams, '~', Pos)
                Swap @FM with @RM in ServiceParams
                If ( (ServiceModule NE '') and (Service NE '') and (ServiceParams NE '') ) then
                    Convert @Lower.Case to @Upper.Case in ServiceModule
                    Ans     = Function(@ServiceModule(Service, ServiceParams))
                    IF Get_Status(errCode) THEN
                        ErrMsg(errCode)
                    END
                end
            Next Row

        end
    end
    obj_AppWindow('ReadOnly',@WINDOW:@RM:1)		;* Clear Read Only

    GOSUB Refresh
    
end else
    ErrMsg('NCR cannot be deleted because an SAP batch number has been assigned. Contact FI for further assistance.')
end

LogData<8> = 'End COMM_NCR("Delete")'
Logging_Services('AppendLog', RemNCRObjLog, LogData, @RM, @FM)

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)

RETURN


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

obj_Appwindow('DetailReturn')

*Void = Check_Notes()

RETURN 


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

Stage		= Get_Property(@WINDOW:'.LOSS_STAGE','DEFPROP')
ReactorType	= Get_Property(@WINDOW:'.REACTOR_TYPE','DEFPROP')		;* This is a hidden field on the window
SRArray		= Get_Property(@WINDOW:'.SLOT_REJECT','ARRAY')
SlotNos		= SRArray<WFR_COL$SLOT>
RejWaferIDs = SRArray<WFR_COL$WAFER_ID>


CONVERT @VM TO '' IN SlotNos
CONVERT @VM TO '' IN RejWaferIDS

CassNoStyles = Send_Message( @WINDOW:'.CASS_NO', "COLSTYLE", 0, '' )


BEGIN CASE
	CASE ReactorType = 'P' OR ReactorType = 'EPP'
	
		Set_Property(@WINDOW:'.CASSETTE_SLOT','VISIBLE',0)
		Set_Property(@WINDOW:'.SLOT_REJECT','VISIBLE',0)
		Set_Property(@WINDOW:'.CASS_NO','VISIBLE',1)
		Set_Property(@WINDOW:'.CORRECT_EPI_SLOTS','VISIBLE',1)
		Set_Property(@WINDOW:'.CORRECT_SLOTS','VISIBLE',0)
		Set_Property(@WINDOW:'.WFR_SLOTS','VISIBLE',0)			;* WFR_SLOTS is used with wafer traceability
		Set_Property(@WINDOW:'.SET_ALL','VISIBLE',0)
		Set_Property(@WINDOW:'.CLEAR_ALL','VISIBLE',0)
		
		
	CASE SlotNos NE '' AND RejWaferIDs = '' 
		
		Set_Property(@WINDOW:'.CASSETTE_SLOT','VISIBLE',1)
		Set_Property(@WINDOW:'.SLOT_REJECT','VISIBLE',0)
		Set_Property(@WINDOW:'.CASS_NO','VISIBLE',0)
		Set_Property(@WINDOW:'.WFR_SLOTS','VISIBLE',0)			;* WFR_SLOTS is used with wafer traceability
		Set_Property(@WINDOW:'.SET_ALL','VISIBLE',1)
		Set_Property(@WINDOW:'.CLEAR_ALL','VISIBLE',1)
		
	CASE ReactorType = 'GAN'
		Set_Property(@WINDOW:'.CASSETTE_SLOT','VISIBLE',0)
		Set_Property(@WINDOW:'.SLOT_REJECT','VISIBLE',0)
		Set_Property(@WINDOW:'.CASS_NO','VISIBLE',0)
		Set_Property(@WINDOW:'.WFR_SLOTS','VISIBLE',1)			;* WFR_SLOTS is used with wafer traceability
		
	
	CASE 1

		Set_Property(@WINDOW:'.CASSETTE_SLOT','VISIBLE',0)
		Set_Property(@WINDOW:'.SLOT_REJECT','VISIBLE',1)
		Set_Property(@WINDOW:'.CASS_NO','VISIBLE',0)
		Set_Property(@WINDOW:'.WFR_SLOTS','VISIBLE',0)			;* WFR_SLOTS is used with wafer traceability
		Set_Property(@WINDOW:'.SET_ALL','VISIBLE',0)
		Set_Property(@WINDOW:'.CLEAR_ALL','VISIBLE',0)
		Set_Property(@WINDOW:'.CORRECT_SLOTS','VISIBLE',1)
		Set_Property(@WINDOW:'.CORRECT_EPI_SLOTS','VISIBLE',0)
		
END CASE


IF Get_Property(@WINDOW:'.SPC_DTM','DEFPROP') = '' THEN
	Set_Property(@WINDOW:'.SEND_SPC','ENABLED',1)
	Set_Property(@WINDOW:'.SEND_SPC','TEXT','Send to SPC')
END ELSE
	Set_Property(@WINDOW:'.SEND_SPC','ENABLED',0)				;* Resends disabled per Chad 8/9/2011 JCH
	Set_Property(@WINDOW:'.SEND_SPC','TEXT','Resend to SPC')
END


* 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:'.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

RETURN


* * * * * * *
CalcRejQty:
* * * * * * *

RETURN			;***********************************************************   JCH 7/8/2016   *************************************


* This entire routine is just to update the Rej_Qty and Total Rej Qty fields in the window during data entry.

EpiSlots	= Get_Property(@WINDOW:'.CASSETTE_SLOT','DEFPROP')<COL$SLOT>
EpiCassNos	= Get_Property(@WINDOW:'.CASS_NO','DEFPROP')<COL$IN_CASS>
EpiRDSNos	= Get_Property(@WINDOW:'.CASS_NO','DEFPROP')<COL$RDS>
TRejQty		= Get_Property(@WINDOW:'.TREJ_QTY','DEFPROP')
WfrIDs		= Get_Property(@WINDOW:'.WFR_SLOTS','DEFPROP')<WFR_SLOT$WFR_ID>

RDSNos = Get_Property(@WINDOW:'.RDS_ID','DEFPROP')<COL$RDS_NO>

RejQtys = ''

TestEpiCassNos = EpiCassNos
CONVERT @VM TO '' IN TestEpiCassNos

* * * * * *   JCH Change to a CASE Statement   * * * * * and add case for WfrIDs<1,1> NE ''  -> wafer traceability

IF TestEpiCassNos = '' THEN

	* This is a nonEpi NCR

	FOR I = 1 TO COUNT(EpiSlots,@VM) + (EpiSlots NE '')
		IF EpiSlots<1,I> > 0 THEN RejQtys += 1
	NEXT I

END ELSE

	FOR I = 1 TO COUNT(EpiCassNos,@VM) + (EpiCassNos NE '')
		
		EpiRDSNo = EpiRDSNos<1,I>
		IF EpiRDSNo NE '' THEN
			LOCATE EpiRDSNo IN RDSNos BY 'AR' USING @VM SETTING RPos THEN
				RejQtys<1,RPos> = RejQtys<1,RPos> + 1
			END 
		END ELSE
			IF EpiCassNos<1,I> NE '' THEN
				RejQtys<1,1> = RejQtys<1,1> + 1
			END
		END
		
	NEXT I
END


IF RejQtys = '' THEN
	IF TRejQty NE '' THEN
		RejQtys = TRejQty
	END
END

FOR I = 1 TO COUNT(RejQtys,@VM) + (RejQtys NE '')

	Set_Property(@WINDOW:'.RDS_ID','CELLPOS',RejQtys<1,I>,COL$REJ_CNT:@FM:I)

NEXT I

Set_Property(@WINDOW:'.TOT_REJ','DEFPROP',SUM(RejQtys))

	
RETURN


* * * * * * *
LUNcrNo:
* * * * * * *

ReturnCtrl = Parm1

IF ReturnCtrl = '' THEN RETURN

IF INDEX(ReturnCtrl,'.',1) ELSE
	ReturnCtrl = @WINDOW:'.':ReturnCtrl
END

NcrKeys = Dialog_Box('NCR_QUERY',@WINDOW,'')

IF INDEX(NcrKeys,@VM,1) THEN

	TypeOver = ''
	TypeOver<PMODE$>	= 'K'
	TypeOver<PDISPLAY$> = NcrKeys
	
	NcrKeys = Popup(@WINDOW,TypeOver,'NCR_QUERY')
	errCode = ''
	IF Get_Status(errCode) THEN DEBUG
	
	Set_Property(@WINDOW,'QBFLIST',NcrKeys)
END ELSE
	obj_AppWindow('LUValReturn',NcrKeys:@RM:ReturnCtrl)
END

RETURN


* * * * * * *
LUTeam:
* * * * * * *

ReturnCtrl = Parm1

IF ReturnCtrl = '' THEN RETURN

IF INDEX(ReturnCtrl,'.',1) ELSE
	ReturnCtrl = @WINDOW:'.':ReturnCtrl
END

Team = Popup(@WINDOW,'','TEAMS')

IF Team = '' THEN
	RETURN
END ELSE
	obj_AppWindow('LUValReturn',Team:@RM:ReturnCtrl)
END

RETURN


* * * * * * *
LULossCd:
* * * * * * *

ReturnCtrl = Parm1

IF ReturnCtrl = '' THEN RETURN

IF INDEX(ReturnCtrl,'.',1) ELSE
	ReturnCtrl = @WINDOW:'.':ReturnCtrl
END

ReactType = Get_Property(@WINDOW:'.REACTOR_TYPE','DEFPROP')

IF ReactType = 'GAN' THEN
	RList('SELECT LOSS_CODES WITH DESC  "GaN]"',TARGET_ACTIVELIST$,'','','')
	
	IF Get_Status(errCode) THEN
		ErrMsg(errCode)
	END
END ELSE
	RList('SELECT LOSS_CODES WITH DESC NE "GaN]"',TARGET_ACTIVELIST$,'','','')
	
	IF Get_Status(errCode) THEN
		ErrMsg(errCode)
	END
	
END

LossCd = Popup(@WINDOW,'','SHOW_LOSS_CODES')

IF LossCd = '' THEN
	RETURN
END ELSE
	obj_AppWindow('LUValReturn',LossCd:@RM:ReturnCtrl)
END

RETURN


* * * * * * *
LUACCd:
* * * * * * *

ReturnCtrl = Parm1

IF ReturnCtrl = '' THEN Return


IF INDEX(ReturnCtrl,'.',1) ELSE
	ReturnCtrl = @WINDOW:'.':ReturnCtrl
END

IF MemberOf( @USER4, 'SUPERVISOR' ) OR MemberOf( @USER4, 'LEAD' ) OR MemberOf( @USER4, 'FINAL_QA' ) OR MemberOf( @USER4, 'ENGINEERING')  THEN

	ReactType = Get_Property(@WINDOW:'.REACTOR_TYPE','DEFPROP')

	IF ReactType = 'GAN' THEN
		RList('SELECT ASSIGN_CAUSE WITH DESIG_ERR_GRP "55"',TARGET_ACTIVELIST$,'','','')
		
		IF Get_Status(errCode) THEN
			ErrMsg(errCode)
		END
	END ELSE
		RList('SELECT ASSIGN_CAUSE WITH DESIG_ERR_GRP NE "55"',TARGET_ACTIVELIST$,'','','')
		
		IF Get_Status(errCode) THEN
			ErrMsg(errCode)
		END
		
	END

	AccCd = Popup(@WINDOW,'','SHOW_ASSIGN_CAUSE')
	IF AccCd = '' THEN
		RETURN
	END ELSE
		obj_AppWindow('LUValReturn',AccCd:@RM:ReturnCtrl)
	END
	
END
	
RETURN


* * * * * * *
ViewRDS:
* * * * * * *

QuoteNo = Get_Property(@WINDOW:'.QUOTE_NO','TEXT')

IF QuoteNo = '' THEN RETURN

obj_AppWindow('ViewRelated','QUOTE2':@RM:QuoteNo)

RETURN


* * * * * * *
PrintNCR:
* * * * * * * 

NCRNo = Get_Property(@WINDOW,'ID')

IF Security_Check( 'NCR', PRINT$ ) THEN
	Send_Event(@WINDOW,'WRITE')

	Print_NCR(NCRNo, '', '' )
	
	obj_AppWindow('LoadFormKeys',@WINDOW:@RM:NCRNo)
	
END ELSE
    Security_Err_Msg( 'NCR', Print$ )
END

RETURN


* * * * * * * 
DeptMgrSig:
* * * * * * *

NCRId		= Get_Property(@WINDOW:'.NCR_NO','TEXT')
DeptResp	= Get_Property(@WINDOW:'.DEPARTMENTRESP','TEXT')
QSRec		= XLATE( 'CONFIG', 'QUOTE_SIGS', '', 'X' )
DeptManager	= ''


BEGIN CASE
	CASE DeptResp = 'Production'
		DeptManager = QSRec<ProdMgr$>
	CASE DeptResp = 'Engineering'
		DeptManager = QSRec<EngMgr$>
	CASE DeptResp = 'Maintenance'
		DeptManager = QSRec<MaintMgr$>
	CASE DeptResp = 'Facilities'
		DeptManager = QSRec<FacilMgr$>
	CASE DeptResp = 'Shipping'
		DeptManager = QSRec<ShipMgr$>
END CASE

* Need to get the department manager's name

IF ( @USER4 = DeptManager ) OR ( DeptResp = 'Customer' ) OR ( DeptResp = 'Research' ) THEN
	DeptMgrSig		= Get_Property(@WINDOW:'.DEPT_MGR_SIG','TEXT')
	DeptMgrSigName	= Get_Property(@WINDOW:'.DEPT_MGR_SIG_NAME','TEXT')
	
	IF DeptMgrSig <> '' THEN
	    MsgInfo = ''
	    MsgInfo<mtext$> = 'This NCR has already been signed by the manager.'
	    MsgInfo<micon$> = '!'
	    Msg( '', MsgInfo )
	END ELSE
	    Valid = Dialog_Box('NDW_VERIFY_USER', @Window, @User4)
        Valid = Valid<1>
	    
		IF Valid THEN
	        Set_Property(@WINDOW:'.DEPT_MGR_SIG','TEXT', @USER4 )
	        Set_Property(@WINDOW:'.DEPT_MGR_SIG_NAME','TEXT',XLATE( 'LSL_USERS', @USER4, 'FIRST_LAST', 'X' ))
	        
            VpMfg = XLATE( 'CONFIG', 'QUOTE_SIGS', VipMfg$, 'X' )		
	           
			Recipients		= VpMfg
			SentFrom		= @USER4
			Subject			= 'NCR Created'
			Message			= "NCR ":NCRId:" was signed by department manager."
			AttachWindow	= 'NCR'
			AttachKey		= NCRId
			SendToGroup		= ''

			Parms = Recipients:@RM:SentFrom:@RM:Subject:@RM:Message:@RM:AttachWindow:@RM:AttachKey:@RM:SendToGroup
			obj_Notes('Create',Parms)

	    END
	END
END ELSE
    MsgInfo = ''
    MsgInfo<mtext$> = 'You are not the ':DeptResp:' manager.'
    MsgInfo<micon$> = '!'
    Msg( '', MsgInfo )
END
RETURN


* * * * * * *
DeviationSig:
* * * * * * *

IF NOT( MemberOf( @USER4, 'SUPERVISOR' ) OR MemberOf( @USER4, 'ENGINEERING' )) THEN
   Mesg = 'You must be a Supervisor or Engineer to sign for acceptance under deviation.'
   ErrMsg(Mesg)
   RETURN
END

ACData = Get_Property(@WINDOW:'.AC_CODE':@RM:@WINDOW:'.AC_COMMENTS','TEXT':@RM:'TEXT')

ACCode		= ACData[1,@RM]
ACComments	= ACData[COL2()+1,@RM]

IF ACCode = ''  THEN
	ErrMsg('Root Cause Code must be entered prior to sign off.')
	Set_Property(@WINDOW:'.AC_CODE','FOCUS',1)
	RETURN
END
	
IF ACComments = ''  THEN
	ErrMsg('Root Cause Comments must be entered prior to sign off.')
	Set_Property(@WINDOW:'.AC_COMMENTS','FOCUS',1)
	RETURN
END

AuthDevSig		= Get_Property(@WINDOW:'.AUTH_DEV_SIG','TEXT')
AuthDevSigName	= Get_Property(@WINDOW:'.AUTH_DEV_SIG_NAME','TEXT')

CurStatus = Get_Property(@WINDOW:'.STATUS','VALUE')
IF CurStatus = 'O' THEN
    IF AuthDevSigName <> '' THEN
        MsgInfo = ''
        MsgInfo<mtext$> = 'This NCR has already been signed for accept under deviation.'
        MsgInfo<micon$> = '!'
        Void = Msg( '', MsgInfo )
    END ELSE
        IF Get_Property(@WINDOW:'.AUTH_REJ_SIG','TEXT') <> '' THEN
		    Valid = Dialog_Box('NDW_VERIFY_USER', @Window, @User4)
            Valid = Valid<1>
			IF Valid THEN
		        Set_Property(@WINDOW:'.AUTH_DEV_SIG','TEXT', @USER4 )
		        Set_Property(@WINDOW:'.AUTH_DEV_SIG_NAME','TEXT', XLATE( 'LSL_USERS', @USER4, 'FIRST_LAST', 'X' ) )
		        Set_Property(@WINDOW,'SAVEWARN',1)
		    END
	    END ELSE
	        MsgInfo = ''
	        MsgInfo<mtext$> = 'This NCR must be signed for rejected material before accepting under deviation.'
	        MsgInfo<micon$> = '!'
	        Void = Msg( '', MsgInfo )
	    END
    END
END ELSE
	IF CurStatus = 'C' THEN
		CurStatus = 'Closed'
	END ELSE
		CurStatus = 'Verified'    
	END
	MsgExtension = ''
	IF AuthDevSig <> '' THEN
		MsgExtension = ' and has already been signed for accept under deviation.'
	END
	MsgInfo = ''
	MsgInfo<mtext$> = 'This NCR is ':CurStatus:MsgExtension
	MsgInfo<micon$> = '!'
	Void = msg( '', MsgInfo )
END

RETURN


* * * * * * *
RejectSig:
* * * * * * *

RejCnt = Get_Property(@WINDOW:'.TOT_REJ','TEXT')

IF RejCnt > 5 THEN
   IF MemberOf( @USER4, 'ENGINEERING' ) OR (MemberOf(@USER4,'SUPERVISOR') OR (MemberOf( @USER4, 'LEAD'))) ELSE
      MsgInfo = ''
      MsgInfo<micon$> = '!'
      MsgInfo<mtext$> = 'There are more than 5 rejects, so an engineer must sign.'
      Void = msg( '', MsgInfo )      
      RETURN
   END
END ELSE
   IF MemberOf( @USER4, 'ENGINEERING' ) OR MemberOf( @USER4, 'SUPERVISOR' ) OR  MemberOf( @USER4, 'LEAD' ) OR  MemberOf( @USER4, 'FINAL_QA' ) ELSE
      MsgInfo = ''
      MsgInfo<micon$> = '!'
      MsgInfo<mtext$> = 'You must be a Supervisor, Engineer, Lead, or Final QA verifier to sign for shipping material.'
      Void = Msg( '', MsgInfo )
      RETURN
   END
END


AuthRejSig		= Get_Property(@WINDOW:'.AUTH_REJ_SIG','TEXT')
AuthRejSigName	= Get_Property(@WINDOW:'.AUTH_REJ_SIG_NAME','TEXT')

IF AuthRejSig <> '' THEN
    MsgInfo = ''
    MsgInfo<mtext$> = 'This NCR has already been signed for rejecting material.'
    MsgInfo<micon$> = '!'
    Void = msg( '', MsgInfo )
END ELSE
    Valid = Dialog_Box('NDW_VERIFY_USER', @Window, @User4)
    Valid = Valid<1>
	IF Valid THEN
        Set_Property(@WINDOW:'.AUTH_REJ_SIG','DEFPROP', @USER4 )
        Set_Property(@WINDOW:'.AUTH_REJ_SIG_NAME','DEFPROP', XLATE( 'LSL_USERS', @USER4, 'FIRST_LAST', 'X' ) )
    END
END

RETURN


* * * * * * *
ShipSig:
* * * * * * *

RejCnt = Get_Property(@WINDOW:'.TOT_REJ','DEFPROP')

IF RejCnt > 5 THEN
   IF MemberOf(@USER4,'ENGINEERING') OR MemberOf(@USER4,'SUPERVISOR') OR MemberOf( @USER4, 'LEAD') Else   ;* substituted AND NOT with OR to allow Leads to sign >5 rejects. -dkk 10/16/15 Ok per Mark C.
	  MsgInfo = ''
	  MsgInfo<micon$> = '!'
	  MsgInfo<mtext$> = 'There are more than 5 rejects, therefore an authorized user must sign.'
	  Void = msg( '', MsgInfo )      
	  RETURN
   END
END ELSE
   IF MemberOf( @USER4, 'ENGINEERING' ) OR MemberOf( @USER4, 'SUPERVISOR' ) OR  MemberOf( @USER4, 'LEAD' ) OR MemberOf( @USER4, 'FINAL_QA' ) ELSE
	  MsgInfo = ''
	  MsgInfo<micon$> = '!'
	  MsgInfo<mtext$> = 'You are not authorized to sign for shipping materisl. See Supervisor or Lead'
	  Void = Msg( '', MsgInfo )
	  RETURN
   END
END

SAPBatchNo	= Get_Property(@WINDOW:'.SAP_BATCH_NO','DEFPROP')
NCRId		= Get_Property(@WINDOW:'.NCR_NO','DEFPROP')
PartNoID	= Get_Property(@WINDOW:'.WO_MAT_PART_NO','DEFPROP')		;* Added
MUFlag		= OCONV(Get_Property(@WINDOW:'.MU_FLAG','DEFPROP'),'BYes,') 			;* Added - dkk 11/18/14


* IF SAPBatchNo NE '' THEN
* 
* 	IF SAPBatchNo[-1,1] NE 'R' THEN
* 
*		Recipients		= XLATE('NOTIFICATION','POST_GR_SCRAP',NOTIFICATION_USER_ID$,'X')
*		SentFrom		= @USER4
*		Subject			= 'SAP Post - GR Scrap Qty - NCR Reported'																					;* Modified subject line - dkk 7/17/14
*		Message			= "NCR: ":NCRId:CRLF$:"Batch_No: ":SAPBatchNo:CRLF$:"MU Box: ":MUFlag:CRLF$:"Epi PN: ":PartNoID:CRLF$:"Qty: ":RejCnt		;* Added Epi PN on the end - dkk 7/17/14
*		AttachWindow	= 'NCR'
*		AttachKey		= NCRId
*		SendToGroup		= ''
* 
*		Parms = Recipients:@RM:SentFrom:@RM:Subject:@RM:Message:@RM:AttachWindow:@RM:AttachKey:@RM:SendToGroup
*		obj_Notes('Create',Parms)
* 	END
* 	
* END	;* End of check for SAPBatch number on Cassette

ACData = Get_Property(@WINDOW:'.AC_CODE':@RM:@WINDOW:'.AC_COMMENTS','TEXT':@RM:'TEXT')
ACCode		= ACData[1,@RM]
ACComments	= ACData[COL2()+1,@RM]

IF ACCode = ''  THEN
	ErrMsg('Root Cause Code must be entered prior to sign off.')
	Set_Property(@WINDOW:'.AC_CODE','FOCUS',1)
	RETURN
END
	
IF ACComments = ''  THEN
	ErrMsg('Root Cause Comments must be entered prior to sign off.')
	Set_Property(@WINDOW:'.AC_COMMENTS','FOCUS',1)
	RETURN
END


DeptMgrSig		= Get_Property( @WINDOW:'.DEPT_MGR_SIG', 'TEXT' )
AuthRejSig		= Get_property( @WINDOW:'.AUTH_REJ_SIG', 'TEXT' )
AuthShipSig		= Get_Property(@WINDOW:'.AUTH_SHIP_SIG','TEXT')
AuthShipSigName	= Get_Property(@WINDOW:'.AUTH_SHIP_SIG_NAME','TEXT')
AuthDevSig		= Get_Property(@WINDOW:'.AUTH_DEV_SIG','TEXT')
CurStatus		= Get_Property(@WINDOW:'.STATUS','VALUE')
WONo			= Get_Property(@WINDOW:'.WO_NO','DEFPROP')
CassNo			= Get_Property(@WINDOW:'.WO_MAT_CASS_NO','DEFPROP')
NCRNo			= Get_Property(@WINDOW:'.NCR_NO','DEFPROP')

IF CurStatus = 'O' THEN
    IF AuthShipSigName <> '' THEN
        MsgInfo = ''
        MsgInfo<mtext$> = 'This NCR has already been signed for ship material.'
        MsgInfo<micon$> = '!'
        Void = Msg( '', MsgInfo )
    END ELSE
        IF ( Get_Property(@WINDOW:'.AUTH_REJ_SIG','TEXT' ) <> '' ) THEN
		    Valid = Dialog_Box('NDW_VERIFY_USER', @Window, @User4)
            Valid = Valid<1>
		    
			IF Valid THEN
			
			    // This code has been moved to the NCR_ACTIONS routine invoked by BASE_MFS
*				IF CassNo NE '' THEN
*					* EpiPRO NCR's don't have the cassette number - neither does GaN
*					oWOMParms  = WONo:@RM
*					oWOMParms := CassNo:@RM
*					oWOMParms := NCRNo:@RM
*					oWOMParms := @USER4:@RM
*					oWOMParms := ICONV(OCONV(Date(),'D4/'):' ':OCONV(Time(),'MTS'),'DT')
*					
*					If @User4 NE 'DANIEL_ST' then obj_WO_Mat('SignNCR',oWOMParms)												;* Added 4/2/2008 JCH J.C. Henry & Co., Inc.
*					
*					IF Get_Status(errCode) THEN
*						* Problem encountered putting final sig date on WO_MAT record so abort the signature.
*						ErrMsg(errCode)
*						RETURN
*					END
*				END
				
				CurrDTM = OCONV(Date(),'D4/'):' ':OCONV(Time(),'MTS')
				
		        Set_Property(@WINDOW:'.AUTH_SHIP_SIG','DEFPROP', @USER4 )
		        Set_Property(@WINDOW:'.AUTH_SHIP_SIG_NAME','DEFPROP', XLATE( 'LSL_USERS', @USER4, 'FIRST_LAST', 'X' ))
		        Set_Property(@WINDOW:'.AUTH_SHIP_SIG_DTM','DEFPROP',CurrDTM)
		        Set_Property(@WINDOW:'.STATUS','VALUE','C')
				
		    END
	    END ELSE
	        MsgInfo = ''
	        MsgInfo<mtext$> = 'This NCR must be signed for rejected material before shipping material.'
	        MsgInfo<micon$> = '!'
	        Void = msg( '', MsgInfo )
	    END
    END
END ELSE
    IF CurStatus = 'C' THEN
    
       CurStatus = 'Closed'
       
       // This code has been moved to the NCR_ACTIONS routine invoked by BASE_MFS
*       IF CassNo NE '' THEN
*			* EpiPRO NCR's don't have the cassette number
*			oWOMParms  = WONo:@RM
*			oWOMParms := CassNo:@RM
*			oWOMParms := NCRNo:@RM
*			oWOMParms := @USER4:@RM
*			oWOMParms := ICONV(OCONV(Date(),'D4/'):' ':OCONV(Time(),'MTS'),'DT')
*			
*			If @User4 NE 'DANIEL_ST' then obj_WO_Mat('SignNCR',oWOMParms)												;* Added 3/17/2010 JCH J.C. Henry & Co., Inc. Updates signature if it's missing
*			
*			IF Get_Status(errCode) THEN
*				* Problem encountered putting final sig date on WO_MAT record so abort the signature.
*				ErrMsg(errCode)
*				RETURN
*			END
*		END
       
    END ELSE
       CurStatus = 'Verified'    
    END
    MsgExtension = ''
    IF AuthDevSig <> '' THEN
       MsgExtension = ' and has already been signed for accept under deviation.'
    END
    MsgInfo = ''
    MsgInfo<mtext$> = 'This NCR is ':CurStatus:MsgExtension
    MsgInfo<micon$> = '!'
    Void = msg( '', MsgInfo )
END

Send_Event(@Window, 'WRITE')

If Error_Services('HasError') then
	Error_Services('DisplayError')
end

RETURN


* * * * * * *
SetAllSlots:
* * * * * * *

CtrlName = @WINDOW:'.CASSETTE_SLOT'

IF Get_Property(CtrlName,'VISIBLE') THEN
	TableArray = Get_Property(CtrlName,'DEFPROP')
END ELSE
	RETURN
END

SlotNos = TableArray<1>

taCnt = COUNT(SlotNos,@VM) + (SlotNos NE '')

SlotNos = STR('1':@VM,taCnt)
SlotNos[-1,1] = ''

TableArray<1> = SlotNos
Set_Property( CtrlName , 'DEFPROP'  , TableArray)

GOSUB CalcRejQty

RETURN


* * * * * * *
ClearAllSlots:
* * * * * * *

CtrlName = @WINDOW:'.CASSETTE_SLOT'

IF Get_Property(CtrlName,'VISIBLE') THEN
	TableArray = Get_Property(CtrlName,'DEFPROP')
END ELSE
	RETURN
END

SAPBatchNo = Get_Property(@Window:'.SAP_BATCH_NO', 'TEXT')

If SAPBatchNo EQ '' then 
    SlotNos = TableArray<1>

    taCnt = COUNT(SlotNos,@VM) + (SlotNos NE '')

    SlotNos = STR('0':@VM,taCnt)
    SlotNos[-1,1] = ''

    TableArray<1> = SlotNos
    Set_Property( CtrlName , 'DEFPROP' , TableArray)

    GOSUB CalcRejQty
end else
    ErrMsg('Slots cannot be cleared because an SAP batch number has been assigned. Contact FI for further assistance.')
end

RETURN


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

CtrlEntID = @WINDOW:'.RDS_ID'

CurrPos = Get_Property(CtrlEntID,'SELPOS')
CurrCol = CurrPos<1>
CurrRow = CurrPos<2>

NCRNo	= Get_Property(@WINDOW:'.NCR_NO','DEFPROP')

IF NCRNo NE '' THEN

	RDSNo	= Get_Property(CtrlEntID,'CELLPOS',1:@FM:CurrRow)
	IF RDSNo NE '' THEN
		Dummy = Start_Window( 'RDS_UNLOAD', @WINDOW, RDSNo:'*CENTER', '', '' )
	END

END

RETURN


* * * * * * *
CorrectSlots:
* * * * * * *

Error     = False$
ReqFields = 'SHIFT,DEPT,DEPT_RESP,LOSS_CODE,LOSS_COMMENTS,CONTAIN_ACTIONS,LOSS_STAGE,LOSS_BY'
ReqCtrls  = 'SHIFT,DEPARTMENT,DEPARTMENTRESP,LOSS_CODE,LOSS_COMMENTS,CONTAIN_ACTIONS,LOSS_STAGE,LOSS_BY'
For each ReqField in ReqFields using ',' setting cPos
    Ctrl = Field(ReqCtrls, ',', cPos)
    Val  = Get_Property(@Window:'.':Ctrl, 'DEFPROP')
    If Val EQ '' then
        Error     = True$
        Result    = 0
        ErrorDesc = ReqField:' is a required field.'
        ErrMsg(ErrorDesc:' You must complete the required NCR fields before correcting slot information.')
        Set_Property(@Window:'.':Ctrl, 'FOCUS', True$)
    end
Until Error
Next ReqField

RawRejList = Get_Property(@WINDOW:'.SLOT_REJECT','LIST')

RejList = ''
LOOP
	RejLine = RawRejList<1>
UNTIL RejLine<1,1> = ''
	RejList<-1> = RawRejList<1>
	RawRejList = DELETE(RawRejList,1,0,0)
REPEAT

WONo = Get_Property(@WINDOW:'.WO_NO','DEFPROP')
CassNo = Get_Property(@WINDOW:'.WO_MAT_CASS_NO','DEFPROP')
NCRNo = Get_Property(@WINDOW:'.NCR_NO','DEFPROP')

IF WONo = '' OR CassNo = '' THEN RETURN

WMParms  = 'WO_MAT':@RM:WONo:'*':CassNo
WOMatKey = WONo:'*':CassNo
* WMRec    = obj_Tables('ReadRec',WMParms)
WMRec    = Database_Services('ReadDataRow', 'WO_MAT', WOMatKey)
IF Get_Status(errCode) THEN
	ErrMsg(errCode)
	RETURN
END

SlotNos 	= WMRec<WO_MAT_SLOT_NO$>
WMWaferIDs	= obj_WO_Mat('SlotWaferIDs',WONo:'*':CassNo:@RM:WMRec)
NCRNos		= WMRec<WO_MAT_SLOT_NCR$>
MetNos		= WMRec<WO_MAT_SLOT_MET_NO$>
MovedTos	= WMRec<WO_MAT_SLOT_MOVED_TO$>
RepWaferIDs	= WMRec<WO_MAT_SLOT_REP_WAFER_ID$>

WMList = ''

OpenSlotFlag = 0
MUWaferInPlace = 0

SlotCnt = COUNT(SlotNos,@VM) + (SlotNos NE '')

FOR I = 1 TO SlotCnt

	WMWaferID = WMWaferIDs<1,I>
	LineNCRNo = NCRnos<1,I>
	IF WMWaferID = '' AND LineNCRNo = NCRNo THEN OpenSlotFlag = 1
	IF WMWaferID NE '' AND LineNCRNo = NCRNo THEN MUWaferInPlace = 1
	
	WMList<I,1> = SlotNos<1,I>
	WMList<I,2> = WMWaferIDs<1,I>
	WMList<I,3> = NCRNos<1,I>
	WMList<I,4> = MetNos<1,I>
	WMList<I,5> = MovedTos<1,I>
	WMList<I,6> = RepWaferIDs<1,I>
NEXT I

IF MUWaferInPlace THEN
	ErrMsg('Slot(s) have makeup wafers in them.')
	WMRec = obj_Tables('UnlockRec',WMParms)
	RETURN
END

UpdatedParms = Dialog_Box('DIALOG_NCR_SLOT_REJ', @WINDOW, WMList:'/':RejList:'/':WONo:'/':CassNo:'/':NCRNo)

IF UpdatedParms = '' THEN 
	obj_Tables('UnlockRec',WMParms)
	RETURN
END

WOMatData	= UpdatedParms[1,@RM]
NCRSlotData = UpdatedParms[COL2()+1,@RM]

WOMatCnt = COUNT(WOMatData<1>,@VM) + (WOMatData<1> NE '')

FOR I = 1 TO WOMatCnt
	WaferID = WOMatData<2,I>
	IF WaferID NE '' THEN
		IF FIELD(WaferID,'.',1,2) = WONo:'.':CassNo THEN
			* This wafer is from this box
		END ELSE
			* This wafer is a makeup wafer
			WMRec<WO_MAT_SLOT_REP_WAFER_ID$,I> = WaferID
		END
	END
	WMRec<WO_MAT_SLOT_NO$,I>			= WOMatData<WFR_COL$SLOT,I>
	WMRec<WO_MAT_SLOT_NCR$,I>			= WOMatData<WFR_COL$SLOT_NCR,I>
	WMRec<WO_MAT_SLOT_REP_WAFER_ID$,I>	= WOMatData<WFR_COL$REPLACED_BY,I>
	WMRec<WO_MAT_SLOT_MET_NO$,I>		= WOMatData<WFR_COL$MET_NO,I>
	
NEXT I

* WMParms = FIELDSTORE(WMParms,@RM,4,0,WMRec)
* obj_Tables('WriteRec',WMParms)

OrigNCRSlotData = Get_Property(@Window:'.SLOT_REJECT', 'LIST')

Set_Property(@WINDOW:'.SLOT_REJECT','LIST',NCRSlotData)
Set_Property(@WINDOW,'@SKIP_WRITE_CHECKS',1)
Send_Event(@WINDOW,'WRITE')	;* Do the write without any data checking

WriteError = Get_Property(@Window, '@WRITE_ERROR')
// Check for WRITE event error. If no error, then commit changes to WO_MAT record.
If WriteError NE '' then
    // Error caught, do not commit write to WO_MAT record.
    ErrorTitle = 'Error!'
    ErrorDesc  = 'An error occurred when saving the NCR record. ':WriteError:' Data changes aborted.'
    Msg(@Window, '', 'OK', '', ErrorTitle:@FM:ErrorDesc) 
    Set_Property(@Window:'.SLOT_REJECT', 'LIST', OrigNCRSlotData)
end else
    // No error, so commit WO_MAT record changes.
    Database_Services('WriteDataRow', 'WO_MAT', WOMatKey, WMRec, True$, False$, True$)
end

obj_Appwindow('LoadFormKeys',@WINDOW:@RM:NCRNo)

RETURN


* * * * * * *
CorrectEpiSlots:
* * * * * * *

Error     = False$
ReqFields = 'SHIFT,DEPT,DEPT_RESP,LOSS_CODE,LOSS_COMMENTS,CONTAIN_ACTIONS,LOSS_STAGE,LOSS_BY'
ReqCtrls  = 'SHIFT,DEPARTMENT,DEPARTMENTRESP,LOSS_CODE,LOSS_COMMENTS,CONTAIN_ACTIONS,LOSS_STAGE,LOSS_BY'
For each ReqField in ReqFields using ',' setting cPos
    Ctrl = Field(ReqCtrls, ',', cPos)
    Val  = Get_Property(@Window:'.':Ctrl, 'DEFPROP')
    If Val EQ '' then
        Error     = True$
        Result    = 0
        ErrorDesc = ReqField:' is a required field.'
        ErrMsg(ErrorDesc:' You must complete the required NCR fields before correcting slot information.')
        Set_Property(@Window:'.':Ctrl, 'FOCUS', True$)
    end
Until Error
Next ReqField

RawRejList = Get_Property(@WINDOW:'.CASS_NO','LIST')

SlotCnt = 0
RejList = ''
LOOP
	RejLine = RawRejList<1>
UNTIL RejLine<1,1> = ''
	RejList<-1> = RawRejList<1>
	RawRejList = DELETE(RawRejList,1,0,0)
	SlotCnt += 1
REPEAT


WONo	= Get_Property(@WINDOW:'.WO_NO','DEFPROP')
WOStep	= Get_Property(@WINDOW:'.WO_STEP','DEFPROP')
NCRNo	= Get_Property(@WINDOW:'.NCR_NO','DEFPROP')

CassNo	= RejList<1,COL$OUT_CASS>

IF WONo = '' OR CassNo = '' OR WOStep = '' THEN RETURN


WMOParms = 'WM_OUT':@RM:WONo:'*':WOStep:'*':CassNo
* WMORec   = obj_Tables('ReadRec',WMOParms)
WMOKey   = WONo:'*':WOStep:'*':CassNo
WMORec   = Database_Services('ReadDataRow', 'WM_OUT', WMOKey)
IF Get_Status(errCode) THEN
	ErrMsg(errCode)
	RETURN
END

OutCassNos	= STR(CassNo:@VM,SlotCnt)
OutCassNos[-1,1] = ''

SlotNos 	= WMORec<WM_OUT_SLOT_NO$>
RDSNos		= WMORec<WM_OUT_RDS$>
Pockets		= WMORec<WM_OUT_POCKET$>
Zones		= WMORec<WM_OUT_ZONE$>
InCassNos	= WMORec<WM_OUT_IN_CASS_NO$>
InSlotNos	= WMORec<WM_OUT_IN_SLOT_NO$>
NCRNos		= WMORec<WM_OUT_SLOT_NCR$>
MUWONos		= WMORec<WM_OUT_MU_WO_NO$>
MUSteps		= WMORec<WM_OUT_MU_WO_STEP$>
MUCassNos	= WMORec<WM_OUT_MU_CASS_NO$>
MUSlotNos	= WMORec<WM_OUT_MU_SLOT_NO$>
UMWCassIDs	= WMORec<WM_OUT_UMW_CASS_ID$>
UMWSlots	= WMORec<WM_OUT_UMW_SLOT_NO$>

WMOList = ''

OpenSlotFlag = 0

SlotCnt = COUNT(SlotNos,@VM) + (SlotNos NE '')

FOR I = 1 TO SlotCnt
	WMOList<I,1> = SlotNos<1,I>
	WMOList<I,2> = RDSNos<1,I>
	WMOList<I,3> = Pockets<1,I>
	WMOList<I,4> = Zones<1,I>
	WMOList<I,5> = InCassNos<1,I>
	WMOList<I,6> = InSlotNos<1,I>
	WMOList<I,7> = NCRNos<1,I>
	WMOList<I,8> = MUWONos<1,I>
	WMOList<I,9> = MUSteps<1,I>
	WMOList<I,10> = MUCassNos<1,I>
	WMOList<I,11> = MUSlotNos<1,I>
	WMOList<I,12> = UMWCassIDs<1,I>
	WMOList<I,13> = UMWSlots<1,I>
	
NEXT I

UpdatedParms = Dialog_Box('DIALOG_NCR_SRJ_EPI', @WINDOW, WMOList:'/':RejList:'/':WONo:'/':WOStep:'/':CassNo:'/':NCRNo)

IF UpdatedParms = '' THEN 
	obj_Tables('UnlockRec',WMOParms)
	RETURN
END

OrgWMOrec = WMORec

WMOData	= UpdatedParms[1,@RM]
NCRSlotData = UpdatedParms[COL2()+1,@RM]

WOMatCnt = COUNT(WMOData<1>,@VM) + (WMOData<1> NE '')

FOR I = 1 TO WOMatCnt
	WMORec<WM_OUT_RDS$,I>			= WMOData<WMOD_COL$RDS,I>	
	WMORec<WM_OUT_POCKET$,I>		= WMOData<WMOD_COL$POCKET,I>
	WMORec<WM_OUT_ZONE$,I>			= WMOData<WMOD_COL$ZONE,I>
	WMORec<WM_OUT_IN_CASS_NO$,I>	= WMOData<WMOD_COL$IN_CASS,I>
	WMORec<WM_OUT_IN_SLOT_NO$,I>	= WMOData<WMOD_COL$IN_SLOT,I>
	WMORec<WM_OUT_SLOT_NCR$,I>		= WMOData<WMOD_COL$SLOT_NCR,I>
	WMORec<WM_OUT_MU_WO_NO$,I>		= WMOData<WMOD_COL$MU_WO_NO,I>
	WMORec<WM_OUT_MU_WO_STEP$,I>	= WMOData<WMOD_COL$MU_STEP,I>

NEXT I

////////// Deprecated code - 11/15/2021 ///////////////
*    WMOParms = FIELDSTORE(WMOParms,@RM,4,0,WMORec)
*    obj_Tables('WriteRec',WMOParms)
///////////////////////////////////////////////////////

OrigNCRSlotData = Get_Property(@Window:'.CASS_NO', 'LIST')
Set_Property(@WINDOW:'.CASS_NO','LIST',NCRSlotData)
Set_Property(@WINDOW,'@SKIP_WRITE_CHECKS',1)
Send_Event(@WINDOW,'WRITE')	;* Do the write without any data checking

WriteError = Get_Property(@Window, '@WRITE_ERROR')
// Check for WRITE event error. If no error, then commit changes to WM_OUT record.
If WriteError NE '' then
    // Error caught, do not commit write to WM_OUT record.
    ErrorTitle = 'Error!'
    ErrorDesc  = 'An error occurred when saving the NCR record. ':WriteError:' Data changes aborted.'
    Msg(@Window, '', 'OK', '', ErrorTitle:@FM:ErrorDesc) 
    Set_Property(@Window:'.CASS_NO', 'LIST', OrigNCRSlotData)
end else
    // No error, so commit WM_OUT record changes.
    Database_Services('WriteDataRow', 'WM_OUT', WMOKey, WMORec, True$, False$, True$)
end

obj_Appwindow('LoadFormKeys',@WINDOW:@RM:NCRNo)

RETURN


* * * * * * *
LossByClick:
* * * * * * *
* Same logic both events


* * * * * * *
DeptRespLF:
* * * * * * *

DeptResp = Get_Property(@WINDOW:'.DEPARTMENTRESP','DEFPROP')
LossBy 	= Get_Property(@WINDOW:'.LOSS_BY','DEFPROP')

IF (DeptResp _EQC 'SUPPLIER' OR DeptResp _EQC 'CUSTOMER' OR DeptResp _EQC 'EPISIL' OR DeptResp _EQC 'OI ADMIN') AND LossBy NE 'C' Then	; * Added OR DeptResp _EQC 'OI ADMIN' - dkk 9/29/14
	Set_Property(@WINDOW:'.LOSS_BY','DEFPROP','C')
	IF Instruction = 'LossByClick' THEN
		ErrMsg('Loss By code changed to Cust/Supplier to match Department Responsible.')
	END
END ELSE
	Set_Property(@WINDOW:'.LOSS_BY','DEFPROP','M')
END

RETURN


* * * * * *
FQAVerify:
* * * * * *
    
    // Check if FQA'd. If so, prompt for override.
    Authorized  = False$
    WorkOrdNo   = Get_Property(@Window : '.WO_NO', 'TEXT')
    CassNo      = Get_Property(@Window : '.WO_MAT_CASS_NO', 'TEXT')
    WoMatKey    = WorkOrdNo:'*':CassNo
    WoMatRec    = Database_Services('ReadDataRow', 'WO_MAT', WoMatKey)
    FQASig  = ''
    FQADate = ''    
    ReactorType = XLATE('WO_LOG', WorkOrdNo, 'REACT_TYPE', 'X')
    SigArray    = Signature_Services('GetSigProfile', WOMatKey)
    SigProfile  = SigArray<1>
    Signatures  = SigArray<2>
    SigDTMS     = SigArray<3>
    
    IF (ReactorType = 'EPP') OR (ReactorType = 'EpiPro') THEN
        StatusStage = 'MO_QA'               
    END ELSE
        StatusStage = 'QA'      
    END
    
    LOCATE StatusStage IN SigProfile USING @VM SETTING Pos THEN
        FQASig    = Signatures<1, Pos>
        FQADate   = SigDTMS<1, Pos>
    end

    If (FQASig NE '') or (FQADate NE '') then
        // Cassette FQA'd
        OverrideMsg = "Cassette already FQA'd. Supervisor, Lead OR Eng. Tech must override."
        Response = Msg(@Window, '', 'OVERRIDE', '', OverrideMsg)

        Begin Case
            Case Response EQ 1
                Response = True$        ; // User Clicked Override
            Case Response EQ 2
                Response = False$       ; // User Clicked Cancel
            Case Response EQ char(27)
                Response = False$       ; // User Pressed Escape Key
        End Case            
        
        If Response EQ True$ then
            Response    = Dialog_Box('NDW_VERIFY_USER', @WINDOW, @USER4:@FM:'LEAD':@VM:'SUPERVISOR':@VM:'ENG_TECH')
            Authorized  = Response<1>
        end else
            Authorized  = False$
        end

    end else
        Authorized = True$
    end
    
return

