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

/*
	Commuter module for WO_MAT (Work Order Material) window
	
	10/18/2006 - John C. Henry, J.C. Henry & Co., Inc.
*/

DECLARE SUBROUTINE Set_Property,  Set_Status, ErrMsg, Set_Property, obj_AppWindow, Send_Message, Wo_Mat_Services 
DECLARE SUBROUTINE Btree.Extract, Send_Event, Security_Err_Msg, Forward_Event, End_Window, Start_Window
DECLARE SUBROUTINE EditCell, obj_NCR, obj_Notes, obj_WO_Mat, obj_Tables, SAP_Services, Hold_Services

DECLARE FUNCTION Get_Property, Get_Status, Popup, Send_Message, Msg, Security_Check, Dialog_Box, RowExists
DECLARE FUNCTION Dialog_Box, obj_WO_Log, obj_NCR, MemberOf, obj_Tables, Error_Services, Hold_Services, Database_Services


$INSERT POPUP_EQUATES
$INSERT LOGICAL
$INSERT MSG_EQUATES
$INSERT APPCOLORS
$INSERT WM_IN_EQUATES
$INSERT WO_LOG_EQU
$INSERT WO_STEP_EQU
$INSERT WO_MAT_EQUATES
$INSERT ORDER_EQU
$INSERT RDS_EQU
$INSERT PROD_SPEC_EQU
$INSERT NOTIFICATION_EQU
$INSERT LSL_USERS_EQU
$INSERT SECURITY_RIGHTS_EQU

EQU CRLF$	TO \0D0A\

EQU COL$PROC_STEP	TO 1
EQU COL$PSN			TO 2
EQU COL$PRE_CLEAN	TO 3
EQU COL$RDS_NO		TO 4
EQU COL$CURR_STATUS	TO 5
EQU COL$POST_CLEAN	TO 6
EQU COL$WFRS_OUT	TO 7

EQU COL$ON_HOLD_DTM		TO 1
EQU COL$ON_HOLD_USER	TO 2
EQU COL$ON_REASON		TO 3
EQU COL$OFF_HOLD_DTM	TO 4
EQU COL$OFF_HOLD_USER	TO 5
EQU COL$OFF_REASON		TO 6

EQU COL$INV_TAG			TO 8

EQU COL$CI_KEY			TO 1
EQU COL$CI_STEP			TO 2
EQU COL$CI_STAGE		TO 3
EQU COL$CI_CLEAN_TOOL	TO 4

EQU COL_WFR_SLOT_NO$	TO 1
EQU COL_WFR_ID$			TO 2
EQU COL_WFR_DISP$		TO 3

ErrTitle = 'Error in Comm_WO_MAT'
ErrorMsg = ''

Result = ''

BEGIN CASE
    CASE Instruction = 'Create' 			; GOSUB Create
    CASE Instruction = 'Refresh'			; GOSUB Refresh
    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 = 'WfrDC'				; GOSUB WfrDC
    CASE Instruction = 'Shipment'			; GOSUB Shipment
    CASE Instruction = 'NCRKeysDC'			; GOSUB NCRKeysDC
    CASE Instruction = 'TabClick'			; GOSUB TabClick
    CASE Instruction = 'HoldClick'			; GOSUB HoldClick
    CASE Instruction = 'FlagClick'			; GOSUB FlagClick
    CASE Instruction = 'MakeUpClick'		; GOSUB MakeUpClick
    CASE Instruction = 'CleanInspDC'		; GOSUB CleanInspDC
    CASE Instruction = 'ProdVerClick'		; GOSUB ProdVerClick
    CASE Instruction = 'SendGR'				; GOSUB SendGR
    CASE Instruction = 'BatchFixit'			; GOSUB BatchFixit
        
    CASE 1
        ErrorMsg = 'Unknown Instruction passed to routine'
END CASE

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

RETURN Result


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

    obj_Appwindow('Create',@WINDOW)
    
    * get the current style
    
    IF MemberOf(@USER4,'OI_SUPERUSER') THEN
        Set_Property(@WINDOW:'.VOID_CHECKBOX','VISIBLE',1)
    END ELSE
        Set_Property(@WINDOW:'.VOID_CHECKBOX','VISIBLE',0)
    END
    
    * Provides compatibility with the existing messaging attachment system
    
    IF Parm1 NE '' THEN
        PassedKeys = FIELD(Parm1,'*',1)
        obj_Appwindow('ViewRelated',@WINDOW:@RM:PassedKeys)
    END
    
    GOSUB Refresh
    
RETURN


* * * * * * *
Read:
* * * * * * *
    
    WONo = Get_Property(@WINDOW:'.WO_NO','DEFPROP')
    CassNo = Get_Property(@WINDOW:'.CASS_NO','DEFPROP')
    
    IF RowExists('WO_MAT',WONo:'*':CassNo) ELSE
        ErrMsg('Incorrect Work Order Mat Key entered.')
        Send_Event(@WINDOW,'CLEAR')
        RETURN
    END
    
    GOSUB Refresh
    
RETURN


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


* * * * * * *
Clear:
* * * * * * *
    
    GOTO Refresh
    
RETURN


* * * * * * *
Delete:
* * * * * * *
    
    IF NOT(Security_Check('WO Material',DELETE$)) THEN
        Security_Err_Msg('WO Material',DELETE$)
        RETURN
    END
    
    WONo = Get_Property(@WINDOW:'.WO_NO','TEXT')
    CassNo = Get_Property(@WINDOW:'.CASS_NO','TEXT')
    
    IF WONo NE '' AND CassNo NE '' THEN
        
        obj_WO_Mat('Delete',WONo:@RM:CassNo)
        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

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


* * * * * * * *
WfrDC:
* * * * * * * * 
    
    WMId		= Get_Property(@WINDOW,'ID')
    CtrlEntID	= Get_Property(@WINDOW,'FOCUS')
    
    CurrPos = Get_Property(CtrlEntID,'SELPOS')
    CurrCol = CurrPos<1>
    CurrRow = CurrPos<2>
    
    WfrID = Get_Property(CtrlEntID,'CELLPOS',COL_WFR_ID$:@FM:CurrRow)
    
    CONVERT '.' TO '*' IN WfrID
    
    DetWindow	= 'WO_WFR'
    DetKeys		= WfrID
    DefaultRec	= ''
    RetKey		= WMId
    RetWin		= @WINDOW
    RetPage		= 1
    RetCtrl		= CtrlEntID
    RetPos		= CurrPos
    
    obj_Appwindow('ViewNewDetail',DetWindow:@RM:DetKeys:@RM:DefaultRec:@RM:RetKey:@RM:RetPage:@RM:RetCtrl:@RM:RetPos)
    
RETURN


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

    WONo       = Get_Property(@WINDOW:'.WO_NO','DEFPROP')
    CassNo     = Get_Property(@WINDOW:'.CASS_NO','DEFPROP')
    WOMatKey   = WONo:'*':CassNo
    sapBatchId = Get_Property(@WINDOW:'.SAP_BATCH_NO', 'TEXT')
    SAPTXDtm = Xlate('WO_MAT', WOMatKey, WO_MAT_SAP_TX_DTM$, 'X')
    * Disabled until further notice! - DJS / JRO - 2023/09/18
    * Re-enabled SAP Batch Fixit for material handlers - JRO - 2023/10/10
    IF MemberOf(@USER4,'MATERIAL HANDLER') THEN	
        Set_Property(@WINDOW:'.SAP_FIXIT','ENABLED',1)
    END ELSE
        Set_Property(@WINDOW:'.SAP_FIXIT','ENABLED',0)
    END
    
    IF MemberOf(@USER4,'OI_SUPERUSER') THEN
        Set_Property(@WINDOW:'.VOID_CHECKBOX','VISIBLE',1)
        Set_Property(@WINDOW:'.FIX_ORDER_ITEM','VISIBLE',1)
    END ELSE
        Set_Property(@WINDOW:'.VOID_CHECKBOX','VISIBLE',0)
        Set_Property(@WINDOW:'.FIX_ORDER_ITEM','VISIBLE',0)
    END
    
    Ctrls  = @WINDOW:'.WMO_KEY':@RM		; Props  = 'DEFPROP':@RM
    Ctrls := @WINDOW:'.WMI_KEY':@RM		; Props := 'DEFPROP':@RM
    Ctrls := @WINDOW:'.PS_REACTOR_TYPE'	; Props := 'DEFPROP'
    
    Props = Get_Property(Ctrls,Props)
    
    WMOKey		= Props[1,@RM]
    WMIKey		= Props[COL2()+1,@RM]
    ReactorType	= Props[COL2()+1,@RM]
    
    IF ReactorType = 'P' OR ReactorType = 'EPP' THEN
        IF WMIKey NE '' THEN
            Set_Property(@WINDOW:'.EPI_GROUP','ENABLED',1)
        END ELSE
            Set_Property(@WINDOW:'.EPI_GROUP','ENABLED',0)
        END
        
        IF WMOKey NE '' THEN
            Set_Property(@WINDOW:'.EPO_GROUP','ENABLED',1)
        END ELSE
            Set_Property(@WINDOW:'.EPO_GROUP','ENABLED',0)
        END
        
        Set_Property(@WINDOW:'.ASM_GROUP','ENABLED',0)
    END ELSE
        Set_Property(@WINDOW:'.ASM_GROUP','ENABLED',1)	
        Set_Property(@WINDOW:'.EPO_GROUP','ENABLED',0)
        Set_Property(@WINDOW:'.EPI_GROUP','ENABLED',0)
    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:'.CASSETTES' AND ETCtrl NE @WINDOW:'.INV_WH' 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
    
    CtrlName = @WINDOW:'.INV_WH'
    InvArray = Get_Property(CtrlName,'INVALUE')
    TagIDs = InvArray<COL$INV_TAG>
    
    TagCnt = COUNT(TagIDs,@VM) + (TagIDs NE '')
    FOR I = 1 TO TagCnt
        InvTag = InvArray<COL$INV_TAG,I>
        BEGIN CASE
            CASE InvTag[1,1] = 'I'	; LineColor = PRE_BLUE$
            CASE InvTag[1,1] = 'O'	; LineColor = YELLOW$
            CASE 1					; LineColor = GREEN$
        END CASE
        stat = Send_Message(CtrlName,'COLOR_BY_POS',0,I,LineColor)
    NEXT I
    
    CtrlName = @WINDOW:'.NCR_KEYS'
    NCRList = Get_Property(CtrlName,'LIST')
    
    ColCount = COUNT(NCRList<1>,@VM) + (NCRList<1> NE '')
    FOR Line = 1 TO COUNT(NCRList,@FM) + (NCRList NE '')
        
        Status = NCRList<Line,2>
        
        BEGIN CASE
            CASE Status = ''			; Color = WHITE$
            CASE Status = 'Closed'		; Color = GREEN$
            CASE Status = 'Open'		; Color = RED$
            CASE Status = 'Verified'	; Color = YELLOW$
                
            CASE 1				; Color = WHITE$
                
        END CASE
        FOR Col = 1 TO ColCount
            stat = Send_Message(CtrlName,'COLOR_BY_POS',Col,Line,Color)
        NEXT Col
        
    NEXT Line
    
RETURN


* * * * * * *
Shipment:
* * * * * * *
    
    ShipNo = Get_Property(@WINDOW:'.SHIP_NO','DEFPROP')
    
    
    IF ShipNo NE '' THEN
        obj_AppWindow('ViewRelated','SHIPMENT':@RM:ShipNo)
    END
    
RETURN


* * * * * * *
RdsDC:
* * * * * * *
    
    WOStepKey = Get_Property(@WINDOW,'ID')
    
    IF WOStepKey = '' THEN RETURN
    
    CtrlEntID = @WINDOW:'.CASSETTES'
    
    CurrPos = Get_Property(CtrlEntID,'NOTIFYPOS')	;* Undocumented property that gives cell location when multi select is enabled.
    CurrCol = CurrPos<1>
    CurrRow = CurrPos<2>
    
    RDSNo = Get_Property(CtrlEntID,'CELLPOS',2:@FM:CurrRow)
    
    IF RDSNo NE '' THEN
        
        Set_Property(@WINDOW,'@RETURN_FROM_RDS',WOStepKey)		;* Bullshit lashup to work with multiple RDS windows
        
        thisFormName = 'RDS'
        
        thisFormWindowUp = Get_Property(thisFormName,'VISIBLE')	;* Returns 0 = hidden, 1 = visible, 2 = minimized, 3 = maximized 
        
        IF thisFormWindowUp = ''	THEN
            If Get_Property('NDW_MAIN', 'VISIBLE') then
                AppMain = 'NDW_MAIN'
            end else
                AppMain = 'LSL_MAIN2'
            end
            Start_Window(thisFormName,AppMain,RDSNo:'*CENTER', '', '')	;* Put up the card window
            
            RETURN
        END
        
        IF thisFormWindowUp = 2		THEN Set_Property(thisFormName,'VISIBLE',9)	;* Restore the window if minimized
        
        IF Get_Property(thisFormName,'SAVEWARN') THEN
            Send_Event(thisFormName,'CLEAR')					;* Clear anything existing (prompts for save first)
        END
        
    END
    
RETURN


* * * * * * *
NCRKeysDC:
* * * * * * *
    
    WMId = Get_Property(@WINDOW,'ID')
    
    CtrlEntID = @WINDOW:'.NCR_KEYS'
    
    CurrPos = Get_Property(CtrlEntID,'SELPOS')
    CurrCol = CurrPos<1>
    CurrRow = CurrPos<2>
    
    NCRKey = Get_Property(CtrlEntID,'CELLPOS',1:@FM:CurrRow)
    
    Send_Event(@WINDOW,'WRITE')
    
    DetWindow	= 'NCR'
    DetKeys		= NCRKey
    DefaultRec	= ''
    RetKey		= WMId
    RetWin		= @WINDOW
    RetPage		= 1
    RetCtrl		= CtrlEntID
    RetPos		= CurrPos
    
    obj_Appwindow('ViewNewDetail',DetWindow:@RM:DetKeys:@RM:DefaultRec:@RM:RetKey:@RM:RetPage:@RM:RetCtrl:@RM:RetPos)
    
RETURN


* * * * * * *
TabClick:
* * * * * * *
    
    IF Parm1 NE '' THEN
        Page = Parm1
    END ELSE
        Page = Get_Property(@WINDOW:'.TAB_CONTROL','VALUE')
    END
    
    Set_Property(@WINDOW,'VPOSITION',Page)
    
RETURN


* * * * * * *
HoldClick:
* * * * * * *
    
    WONo = Get_Property(@WINDOW:'.WO_NO','DEFPROP')
    CassNo = Get_Property(@WINDOW:'.CASS_NO','DEFPROP')
    CtrlEnt = Get_Property(@WINDOW,'FOCUS')
    
    IF WONo = '' OR CassNo = '' THEN RETURN
    
    WOMatKey		= WONo:'*':CassNo
    HoldEntity		= 'WO_MAT'
    HoldEntityID	= WOMatKey
    
    Send_Event(CtrlEnt,'GOTFOCUS')
    Set_Property(@WINDOW,'SAVEWARN',0)
    Send_Event(@WINDOW,'CLEAR')
    
*    obj_WO_Mat('ToggleHold',WOMatKey:@RM:HoldEntity:@RM:HoldEntityID:@RM:CtrlEnt)
*    
*    IF Get_Status(errCode) THEN ErrMsg(errCode)
    
    Transition = Hold_Services('CheckForHold', WOMatKey, CtrlEnt)
    HoldType   = 'HOLD'
    HoldData   = ''
    HoldData   = Dialog_Box('DIALOG_HOLD',@WINDOW,Transition:@FM:@FM:HoldType)
    If HoldData NE 'Cancel' then
		Hold_Services('ToggleHold', WOMatKey, HoldEntity, HoldEntityID, CtrlEnt, '', HoldData, '')
		IF Error_Services("HasError") THEN
			ErrCode = Error_Services("GetMessage")
			ErrMsg(errCode)
		end
	end
    
    obj_AppWindow('LoadFormKeys',@WINDOW:@RM:WOMatKey)
    
RETURN


* * * * * * *
HoldDC:
* * * * * * *
    
    WONo = Get_Property(@WINDOW:'.WO_NO','DEFPROP')
    CassNo = Get_Property(@WINDOW:'.CASS_NO','DEFPROP')
    
    IF WONo = '' OR CassNo = '' THEN RETURN
    
    WOMatKey = WONo:'*':CassNo
    
    CtrlEntID = @WINDOW:'.HOLD_HISTORY'
    
    HoldHistory = Get_Property(CtrlEntID,'LIST')
    
    CurrPos = Get_Property(CtrlEntID,'SELPOS')
    CurrCol = CurrPos<1>
    CurrRow = CurrPos<2>
    
    HistoryCols	= Get_Property(CtrlEntID, "COLUMN")
    ColName		= HistoryCols<1,1,CurrCol>
    
    Set_Property(@WINDOW,'SAVEWARN',0)
    WOMatRec = Database_Services("ReadDataRow", "WO_MAT", WOMatKey, "", "", FALSE$)

	IF INDEX(ColName,'START',1)  THEN
		HoldStartReason = WOMatRec<WO_MAT_HOLD_START_REASON$,CurrRow>
		UpdatedText     = Dialog_Box('DIALOG_TEXT',@WINDOW,'Hold Start Reason':@FM:HoldStartReason)
	END ELSE
		IF INDEX(ColName,'STOP',1)  THEN
			HoldStopReason = WOMatRec<WO_MAT_HOLD_STOP_REASON$,CurrRow>
			UpdatedText    = Dialog_Box('DIALOG_TEXT',@WINDOW,'Hold Stop Reason':@FM:HoldStopReason)
		END
	END
    
    If UpdatedText NE 'Cancel' then 
		Hold_Services("EditHoldReason",WOMatKey, ColName, CurrRow, UpdatedText)
	End
    IF Error_Services("NoError") NE TRUE$ THEN
    	ErrMsg(Error_Services("GetMessage"))
    end
    
    obj_AppWindow('LoadFormKeys',@WINDOW:@RM:WOMatKey)
    
RETURN


* * * * * * *
FlagClick:
* * * * * * *
    
    WONo	= Get_Property(@WINDOW:'.WO_NO','DEFPROP')
    CassNo	= Get_Property(@WINDOW:'.CASS_NO','DEFPROP')
    CtrlEnt = Get_Property(@WINDOW,'FOCUS')
    FieldNo = Get_Property(CtrlEnt,'POS')
    
    IF WONo = '' OR CassNo = '' THEN RETURN
    
    WOMatKey = WONo:'*':CassNo
    
    IF NOT(MemberOf(@USER4,'MASTER_SCHED')) AND NOT(MemberOf(@USER4,'OI_ADMIN')) THEN
        ErrMsg('This function is limited to Material Control.')
        RETURN
    END
    
    Send_Event(CtrlEnt,'GOTFOCUS')
    CheckValue = Get_Property(CtrlEnt,'DEFPROP')
    
    Set_Property(@WINDOW,'SAVEWARN','0')
    Send_Event(@WINDOW,'CLEAR')
    
    obj_WO_Mat('ChangeFlag',WOMatKey:@RM:FieldNo:@RM:CheckValue)
    
    IF Get_Status(errCode) THEN ErrMsg(errCode)
    
    obj_AppWindow('LoadFormKeys',@WINDOW:@RM:WOMatKey)
    
    
RETURN


************
MakeUpClick:
************
    
    WONo	= Get_Property(@WINDOW:'.WO_NO','DEFPROP')
    CassNo	= Get_Property(@WINDOW:'.CASS_NO','DEFPROP')
    CtrlEnt = Get_Property(@WINDOW,'FOCUS')
    FieldNo = Get_Property(CtrlEnt,'POS')
    
    Send_Event(CtrlEnt,'GOTFOCUS')
    CheckValue     = Get_Property(CtrlEnt,'DEFPROP')
    InvalidRequest = False$
    
    IF ((WONo NE '') AND (CassNo NE '')) THEN
        
        WOMatKey = WONo:'*':CassNo
        OnHold   = Xlate('WO_MAT', WOMatKey, 'HOLD', 'X')
        IF OnHold NE True$ then
            IF	   (MemberOf(@USER4,'MASTER_SCHED')) |
            OR (MemberOf(@USER4,'SUPERVISOR'))   |
            OR (MemberOf(@USER4,'ENGINEERING'))	 |
            OR (MemberOf(@USER4,'LEAD'))		 |
            OR (MemberOf(@USER4,'OI_ADMIN')) THEN
            	
            	WOMatRec  = Database_Services("ReadDataRow", 'WO_MAT', WOMatKey)
            	If Error_Services('NoError') then 
					SAPBatchNo      = WOMatRec<WO_MAT_SAP_BATCH_NO$>
					SAPTXDtm        = WOMatRec<WO_MAT_SAP_TX_DTM$>
					AwaitingBatchNo = ( (SAPTXDtm NE '') and (SAPBatchNo EQ '') )
					FullBoxReject   = (SAPBatchNo[-1, 1] = 'R')
					Begin Case
						Case AwaitingBatchNo
							InvalidRequest = True$
							ErrMsg('WARNING: Cassette ineligible to be converted as it is awaiting a batch number from SAP.')
						Case FullBoxReject
							InvalidRequest = True$
							ErrMsg('WARNING: Cassette ineligible to be converted as it is a full box reject.')
						Case Otherwise$
							Null
					End Case            	
					
					If Not(InvalidRequest) then
						ReactorType = Xlate('WO_MAT', WOMatKey, 'REACTOR_TYPE_NO_CONV', 'X')
						EpiPro      = (ReactorType EQ 'EPP')
						If EpiPro then
							LotId = Xlate('WO_MAT', WOMatKey, 'WMO_KEY', 'X')
						end else
							LotId = Xlate('WO_MAT', WOMatKey, 'RDS_NO', 'X')
							RDSNo = LotID
						end
						
						If LotId NE '' then
							Parms    = ''
							Parms<1> = LotId ; // Cassette to verify wafer count of.
							Parms<2> = 0     ; // Wafer count adjustment - 0 because converting box.
							Parms<3> = 'MU'  ; // Wafer counter tool location
							Proceed  = Dialog_Box('NDW_WAFER_COUNTER', @Window, Parms)
							If Proceed EQ True$ then
						        obj_WO_Mat('ChangeFlag',WOMatKey:@RM:FieldNo:@RM:CheckValue)
								If EpiPro EQ False$ then
                                    IF Get_Status(errCode) THEN
                                        ErrMsg('Unable to set makeup flag until Unload stage is signed.')
                                        InvalidRequest = True$
                                    END else
                                        Set_Property(@WINDOW,'SAVEWARN', False$)
                                        Send_Event(@WINDOW,'CLEAR')
                                        If (CheckValue EQ True$) then
                                            Wo_Mat_Services('MakeupFlagOn', WOMatKey)
                                        end
                                    end
								end else
								    Set_Property(@WINDOW,'SAVEWARN', False$)
								    Send_Event(@WINDOW,'CLEAR')
								end
							end else
								InvalidRequest = True$
							end
						end else
							InvalidRequest = True$
							ErrMsg('WARNING: Error starting wafer counter check. RDS No is missing.')
						end
					end
				end else
					InvalidRequest = True$
					ErrMsg('ERROR: Error reading WO_MAT record.')
				end            	

            END ELSE
                InvalidRequest = True$
                ErrMsg('INFO: This function is limited to authorized users only.')
            END
        end else
           InvalidRequest = True$
           ErrMsg('INFO: You cannot make changes to the lot while it is on hold.')
        end
        
    END ELSE
        InvalidRequest = True$
        ErrMsg('WARNING: Work Order and Cassette information is missing.')
    END
    
    IF (InvalidRequest EQ True$) then
        /* Toggle back the checkbox flag */
        IF (CheckValue EQ False$) THEN
            Set_Property(CtrlEnt, 'DEFPROP', True$)
        END ELSE
            Set_Property(CtrlEnt, 'DEFPROP', False$)
        END
    END
    
    obj_AppWindow('LoadFormKeys',@WINDOW:@RM:WOMatKey)
    
RETURN


* * * * * * *
CleanInspDC:
* * * * * * * 
    
    CtrlEntID = @WINDOW:'.CLEAN_INSP'
    
    CurrPos		= Get_Property(CtrlEntID,"SELPOS")
    CurrCol 	= CurrPos<1>
    CurrRow 	= CurrPos<2>
    
    CIKey	= Get_Property(CtrlEntID,'CELLPOS',COL$CI_KEY:@FM:CurrRow)
    WONo	= Get_Property(@WINDOW:'.WO_NO','DEFPROP')
    CassNo	= Get_Property(@WINDOW:'.CASS_NO','DEFPROP')
    
    IF CIKey NE '' AND WONo NE '' AND CassNo NE '' THEN
        
        Send_Event(@WINDOW,'CLEAR')
        
        DetWindow	= 'CLEAN_INSP'
        DetKeys		= CIKey
        DefaultRec	= ''
        RetKey		= WONo:'*':CassNo
        RetWin		= @WINDOW
        RetPage		= 1
        RetCtrl		= CtrlEntID
        RetPos		= CurrPos
        
        obj_Appwindow('ViewNewDetail',DetWindow:@RM:DetKeys:@RM:DefaultRec:@RM:RetKey:@RM:RetPage:@RM:RetCtrl:@RM:RetPos)
        
        IF Get_Status(errCode) THEN
            ErrMsg(errCode)
        END	
    END	
    
    
RETURN


* * * * * * *
ProdVerClick:
* * * * * * *
    
    Ctrls  = @WINDOW:'.WO_NO':@RM			; Props  = 'DEFPROP':@RM
    Ctrls := @WINDOW:'.CASS_NO':@RM			; Props := 'DEFPROP':@RM
    Ctrls := @WINDOW:'.PROD_VER_NO'			; Props := 'DEFPROP'
    
    Vals = Get_Property(Ctrls,Props)
    
    WONo		= Vals[1,@RM]
    CassNo		= Vals[COL2()+1,@RM]
    ProdVerNo	= Vals[COL2()+1,@RM]
    
    IF WONo NE '' AND CassNo NE '' THEN
        
        DetWindow	= 'PROD_VER'
        DetKeys		= ProdVerNo
        DefaultRec	= ''
        RetKey		= WONo:'*':CassNo
        RetPage		= 1
        RetCtrl		= ''
        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
    END
    
RETURN


* * * * * * *
SendGR:
* * * * * * *
    WONo = Get_Property(@WINDOW:'.WO_NO','DEFPROP')
    CassNo = Get_Property(@WINDOW:'.CASS_NO','DEFPROP')
    If WONo NE '' and CassNo NE '' then
        WOMatKey = WONo:'*':CassNo
        WOMATRec = xlate('WO_MAT', WOMatKey, '', 'X')
        MUBox    = Xlate('WO_MAT', WOMatKey, 'MAKEUP_BOX', 'X')
		Locate 'PACK' In WOMATRec<7> Using @VM Setting packLoc Then
			myVal = WOMATRec<31, packLoc>
			packComplete = (WOMATRec<31, packLoc> _EQC 'packaging complete')
		end else
			packComplete = FALSE$
		end
		If ( (packComplete EQ '1') or (MUBox EQ True$) ) Then
	        Sap_Services('RetransmitCassComp', WOMatKey)
			obj_AppWindow('LoadFormKeys',@WINDOW:@RM:WOMatKey)
			ErrMsg('SAP Transaction for ':WOMatKey:' succesfully resent.')
        end else
        	ErrMsg('Packaging Step not complete - cannot send to SAP.':CRLF$:'Please return cassette to FAB for packaging.')
        end
    end else
        ErrorMessage = 'Process Error: Either Work Order number or Cassette number are null.'
        ErrMsg(ErrorMessage)
    end
    
RETURN


* * * * * * *
BatchFixit:
* * * * * * *
    
    WONo = Get_Property(@WINDOW:'.WO_NO','DEFPROP')
    CassNo = Get_Property(@WINDOW:'.CASS_NO','DEFPROP')
    
    WOMatKey = WONo:'*':CassNo
    
    IF WONo NE '' AND CassNo NE '' THEN
        Send_Event(@WINDOW,'CLEAR')
        obj_Appwindow('ViewRelated','WO_MAT_BATCH':@RM:WOMatKey)
        Set_Property('WO_MAT_BATCH','@RETURNKEY',WOMatKey)
    END
    
    
RETURN


