COMPILE FUNCTION WO_REPROCESS(EntID,Event,Parm1,Parm2,Parm3,Parm4,Parm5)

/*
	Commuter module for WO_REPROCESS (Receive Wafers for Reprocessing) window
	
	09/10/2009 - John C. Henry, J.C. Henry & Co., Inc.
*/

DECLARE SUBROUTINE Set_Property, End_Dialog, Send_Event, Set_Status, Center_Window, Post_Event
DECLARE SUBROUTINE ErrMsg, Send_Message, Set_Property, Send_Event, Btree.Extract, obj_AppWindow, 
DECLARE SUBROUTINE obj_Notes, Security_Err_Msg, End_Window, Forward_Event, Start_Window, Create_Note, obj_WO_Mat

DECLARE FUNCTION Get_Property, Get_Status, Dialog_Box, Utility, Popup, Collect.Ixvals
DECLARE FUNCTION Send_Message, Msg, Security_Check, obj_React_Run_CI, obj_WO_Mat


$INSERT MSG_EQUATES
$INSERT APPCOLORS
$INSERT LSL_USERS_EQU
$INSERT POPUP_EQUATES
$INSERT LOGICAL

$INSERT WO_LOG_EQUATES
$INSERT ORDER_EQU
$INSERT ORDER_DET_EQU
$INSERT COMPANY_EQU
$INSERT PROD_SPEC_EQU
$INSERT QUOTE_SPEC_EQU
$INSERT SECURITY_RIGHTS_EQU
$INSERT NOTIFICATION_EQU
$INSERT EPI_PART_EQUATES
$INSERT CUST_EPI_PART_EQUATES



EQU CRLF$	TO \0D0A\
EQU TAB$	TO \09\


EQU COL$CASS_NO				TO 1		;* Equates for CASS_NO edit table control (cassettes received)
EQU COL$CASS_LOT_NO			TO 2
EQU COL$CASS_QTY			TO 3
EQU COL$CASS_PART_NO		TO 4
EQU COL$CASS_SUB_PART_NO	TO 5
EQU COL$CASS_TIME_STAMP		TO 6
EQU COL$CASS_SCAN_BY		TO 7
EQU COL$CASS_ORDER_ITEM		TO 8

EQU COL$OD_ITEM_NO			TO 1		;* Equates for ORDER_DETAIL control (material ordered)
EQU COL$OD_CUST_PART_NO		TO 2
EQU COL$OD_CUST_PN_DESC		TO 3
EQU COL$OD_CUST_PN_INBOUND	TO 4
EQU COL$OD_SUB_PART_NO		TO 5
EQU COL$OD_PROMISE_DT		TO 6
EQU COL$OD_ITEM_QTY			TO 7
EQU COL$OD_WAFER_QTY		TO 8

EQU CA$ITEM_NO				TO 1			;* Equates for Checking Array passed to Scan routine
EQU CA$LOT_NO				TO 2
EQU CA$LOT_QTY				TO 3
EQU CA$CUST_PART_NO			TO 4
EQU CA$SUB_PART_NO			TO 5
EQU CA$SCANNED_LOT_QTY		TO 6
EQU CA$VERIFY_PART_NO		TO 7



ErrTitle = 'Error in WO_Reprocess commuter module'
ErrorMsg = ''

Result = ''

BEGIN CASE
	CASE EntID = @WINDOW
		BEGIN CASE
			CASE Event = 'CREATE' 			; GOSUB Create
			CASE Event = 'CLEAR'			; GOSUB Clear
			CASE Event = 'READ'				; GOSUB Read
			CASE Event = 'WRITE'			; GOSUB Write
			CASE Event = 'CLOSE'			; GOSUB Close
			CASE Event = 'PAGE'				; GOSUB Page

			
			CASE Event[1,3] = 'QBF'			; GOSUB Refresh
		END CASE
	
	CASE EntID = @WINDOW:'.SCAN_BUTTON' AND Event = 'CLICK'		; GOSUB Scan
	CASE EntID = @WINDOW:'.TABCONTROL_1' AND Event = 'CLICK'	; GOSUB Page
	
	
		
	CASE 1
		ErrorMsg = 'Unknown Parameters ':EntID:' - ':Event:' passed to commuter'
		ErrMsg(ErrorMsg)
		
END CASE

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

RETURN Result



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

obj_Appwindow('Create',@WINDOW)

GOSUB Refresh


RETURN

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



Set_Property(@WINDOW,'VPOSITION',1)
Set_Property(@WINDOW:'.TABCONTROL_1','VALUE',1)

GOSUB Refresh

RETURN


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

GOSUB Refresh

RETURN


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

RETURN


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

* 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


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

RETURN


* * * * * * *
Page:
* * * * * * *

Page = Get_Property(@WINDOW:'.TABCONTROL_1', 'VALUE')

Set_Property(@WINDOW,'VPOSITION', Page)

RETURN


* * * * * * *
Scan:
* * * * * * *

WONo = Get_Property(@WINDOW:'.WO_NO','TEXT')

CtrlEntID = @WINDOW:'.CASS_NO'

CassList = Get_Property(CtrlEntID,'LIST')
CassArray = Get_Property(CtrlEntID,'DEFPROP')

CassListCnt = COUNT(CassList,@FM)
ExistLotNos = ''

CassPointer = 1
LOOP
	IF CassList<CassPointer,COL$CASS_NO> NE '' THEN
		ExistLotNos<1,-1> = CassList<CassPointer,COL$CASS_LOT_NO>
		CassPointer += 1
	END ELSE
		CassList = DELETE(CassList,CassPointer,0,0)
	END
UNTIL CassList<CassPointer> = ''
	
REPEAT

ExistCassCnt = COUNT(CassList,@FM) + (CassList NE '')

OrderNo = Get_Property(@WINDOW:'.ORDER_NO','TEXT')
IF OrderNo = '' THEN RETURN

OrderDetailList = Get_Property(@WINDOW:'.ORDER_ITEMS','LIST')	;* Get Order Items from the control on the 2nd page

ORDCnt = COUNT(OrderDetailList,@FM) + (OrderDetailList NE '')

FOR I = OrdCnt TO 1 STEP -1
WHILE OrderDetailList<I,COL$OD_ITEM_NO> = ''
	OrderDetailList = DELETE(OrderDetailList,I,0,0)				;* Strip blank lines from control data
NEXT I

CheckArray = ''
CALine = 1		
FOR I = 1 TO COUNT(OrderDetailList,@FM) + (OrderDetailList NE '')
	OrdItem = OrderDetailList<I,COL$OD_ITEM_NO>
	
	IF OrderDetailList<I,COL$OD_CUST_PN_INBOUND> NE '' THEN
		VerifyPartNo = OrderDetailList<I,COL$OD_CUST_PN_INBOUND>
	END ELSE
		VerifyPartNo = OrderDetailList<I,COL$OD_CUST_PART_NO>
	END
	
	ItemLotNos = XLATE('ORDER_DET',OrderNo:'*':OrdItem,ORDER_DET_CUST_LOT_NO$,'X')		;* Get the list of expected lot numbers on that item
	ItemLotQtys = XLATE('ORDER_DET',OrderNo:'*':OrdItem,ORDER_DET_CUST_LOT_QTY$,'X')	;* Get the list of expected lot qtys for associated item
	
	IF ItemLotNos = '' THEN
		IF OrderDetailList<I,COL$OD_WAFER_QTY> NE '' THEN
		
			CheckArray<CA$ITEM_NO,CALine>			= OrderDetailList<I,COL$OD_ITEM_NO>
			CheckArray<CA$LOT_NO,CALine>			= ''
			CheckArray<CA$LOT_QTY,CALine>			= ICONV(OrderDetailList<I,COL$OD_WAFER_QTY>,'MD0')
			CheckArray<CA$CUST_PART_NO,CALine>		= OrderDetailList<I,COL$OD_CUST_PART_NO>
			CheckArray<CA$SUB_PART_NO,CALine>		= OrderDetailList<I,COL$OD_SUB_PART_NO>
			CheckArray<CA$VERIFY_PART_NO,CALine>	= VerifyPartNo
			
		END
	
	END ELSE
	
		FOR N = 1 TO COUNT(ItemLotNos,@VM) + (ItemLotNos NE '')
			ItemLotNo = ItemLotNos<1,N>
			
			LOCATE ItemLotNo IN ExistLotNos USING @VM Setting Dummy ELSE
		
				LOCATE ItemLotNo IN CheckArray<CA$LOT_NO> USING @VM SETTING Pos THEN
					CheckArray<CA$LOT_QTY,Pos> = CheckArray<CA$LOT_QTY,Pos> + ItemLotQtys<1,N>
				END ELSE
					CheckArray = INSERT(CheckArray,CA$ITEM_NO,Pos,0,OrderDetailList<I,COL$OD_ITEM_NO>)
					CheckArray = INSERT(CheckArray,CA$LOT_NO,Pos,0,ItemLotNo)
					CheckArray = INSERT(CheckArray,CA$LOT_QTY,Pos,0,ItemLotQtys<1,N>)
					CheckArray = INSERT(CheckArray,CA$CUST_PART_NO,Pos,0,OrderDetailList<I,COL$OD_CUST_PART_NO>)
					CheckArray = INSERT(CheckArray,CA$SUB_PART_NO,Pos,0,OrderDetailList<I,COL$OD_SUB_PART_NO>)
					CheckArray = INSERT(CheckArray,CA$VERIFY_PART_NO,Pos,0,VerifyPartNo)
				END
			END
			
		NEXT N
	END
	
NEXT I

CheckArray = OrderNo:@FM:CheckArray

ScanResults = Dialog_Box('DIALOG_WO_REP_SCAN',@WINDOW,CheckArray)	;* Returns a line for each cassette scanned, checked, filled in or override data


WONo		= Get_Property(@WINDOW:'.WO_NO','TEXT')

WORec		= XLATE('WO_LOG',WONo,'','X')

ProdVerNo	= WORec<WO_LOG_PROD_VER_NO$>
CustNo		= WORec<WO_LOG_CUST_NO$>
EpiPartNo 	= WORec<WO_LOG_EPI_PART_NO$>

SubSupplyBy = XLATE('EPI_PART',EpiPartNo,EPI_PART_SUB_SUPP_BY$,'X')

CustEpiPartRec = XLATE('CUST_EPI_PART',CustNo:'*':EpiPartNo,'','X')


RetRejects		= CustEpiPartRec<CUST_EPI_PART_RET_REJECTS$>
CassShipQty		= CustEpiPartRec<CUST_EPI_PART_CASS_SHIP_QTY$>
MUWaferFlag		= CustEpiPartRec<CUST_EPI_PART_MAKEUP_WAFERS$>
MinCassShipQty	= CustEpiPartRec<CUST_EPI_PART_MIN_CASS_SHIP_QTY$>


WOStepKeys		= WORec<WO_LOG_WO_STEP_KEY$>
LastWOStepKey	= WOStepKeys[-1,'B':@VM]

LastPSNo 	= XLATE('WO_STEP',LastWOStepKey,1,'X')


PSNo = XLATE('WO_STEP',WONo:'*1',1,'X')
PSRec = XLATE('PROD_SPEC',PSNo,'','X')


ReactType = XLATE( 'PROD_SPEC',PSNo,PROD_SPEC_REACTOR_TYPE$,'X' )	;* Type 'EPP' (EpiPRO) don't get slot no's 

RelStamps = Get_Property(@WINDOW:'.REL_STAMP','ARRAY')

IF RelStamps[-1,'B*'] = '' THEN Released = 0 ELSE Released = 1


IF ExistCassCnt >= 1 THEN

	IF Released THEN
		Resp = 1													;* 12/13/20007 - JCH added to limit replace function to unreleased WO's
	END ELSE

		TypeOver = ''
		TypeOver<MCAPTION$> = 'Add or Replace Work Order Cassette Information'
		TypeOver<MTEXT$> = 'Do you wish to Add To or Replace the existing cassette information?'
		TypeOver<MTYPE$> = 'B&Add,&Replace,&Cancel'
		Resp = Msg(@WINDOW,TypeOver)
		
	END
	
	IF Resp = 3 THEN RETURN	;* Canceled
	IF Resp = 1 THEN
	
		* Add to Existing
		
		NewCassetteCnt = COUNT(ScanResults<COL$CASS_NO>,@VM) + (ScanResults<COL$CASS_NO> NE '')
		
		Def = ''
		Def<MCAPTION$>		= 'Receiving Cassettes...'
		Def<MTYPE$>			= 'G'
		Def<MEXTENT$>		= NewCassetteCnt
		Def<MTEXTWIDTH$>	= 600
		MsgUp = Msg(@WINDOW,Def)
		
		FOR I = 1 TO NewCassetteCnt
		
			Msg(@WINDOW, MsgUp, I, MSGINSTUPDATE$)
		
			ScanLotNo	= ScanResults<COL$CASS_LOT_NO,I>
			ScanQty		= ScanResults<COL$CASS_QTY,I>
			ScanPartNo	= ScanResults<COL$CASS_PART_NO,I>
			ScanOrdItem	= ScanResults<COL$CASS_ORDER_ITEM,I>
			
			IF ScanLotNo NE '' AND ScanQty NE '' AND ScanPartNo NE '' AND ScanOrdItem NE '' THEN
			
				CassNo = ExistCassCnt + 1
				
				
				Parms  = WONo:@RM
				Parms := CassNo:@RM
				Parms := ProdVerNo:@RM
				Parms := ScanResults<COL$CASS_LOT_NO,I>:@RM
				Parms := ScanResults<COL$CASS_QTY,I>:@RM
				Parms := ScanResults<COL$CASS_PART_NO,I>:@RM
				Parms := ScanResults<COL$CASS_ORDER_ITEM,I>:@RM
				Parms := ReactType:@RM
				Parms := ScanResults<COL$CASS_SUB_PART_NO,I>:@RM
				Parms := 'SR':@RM									;* Warehouse = 'SR' - Shipping/Receiving Area
				Parms := 'RB':@RM									;* Location = 'RB' - Receiving Bench
				Parms := ScanResults<COL$CASS_TIME_STAMP,I>:@RM
				Parms := ScanResults<COL$CASS_SCAN_BY,I>:@RM
				Parms := SubSupplyBy:@RM
				Parms := MUWaferFlag:@RM
				Parms := RetRejects:@RM								;* Added 8/18/2009 JCH
				Parms := 1:@RM										;* Reprocessed Material Flag
				Parms := CassShipQty:@RM						    ;* Added 11/4/2009
				Parms := @RM
				Parms := @RM
				Parms := MinCassShipQty                             ; // Added 02/01/2018 dmb

				obj_WO_Mat('Create',Parms)		;* Added 10/18/2006 JCH - New Work Order material subsystem.
				
				ExistCassCnt += 1
			END
			
		NEXT I
		
		Msg(@WINDOW,MsgUp)
		
		ScanResults = CassArray
		
		Scheduled = XLATE('WO_LOG',WONo,'SCHEDULED','X')
		
		IF Scheduled THEN
			
			* Message to production about change in Work Order Size
			   	
			Recipients 		= XLATE('NOTIFICATION','MAST_SCHED_BEG',NOTIFICATION_USER_ID$,'X')		;* Added 10/03/2005 JCH - J.C. Henry & Co., Inc
			OtherRecipients	= XLATE('NOTIFICATION','MAST_SCHED_END',NOTIFICATION_USER_ID$,'X')		;* Added 10/03/2005 JCH - J.C. Henry & Co., Inc
			
			FOR N = 1 TO COUNT(OtherRecipients,@VM) + (OtherRecipients NE '')
				OtherRecip = OtherRecipients<1,N>
				LOCATE OtherRecip IN Recipients USING @VM SETTING Pos ELSE
					Recipients = INSERT(Recipients,1,Pos,0,OtherRecip)
				END
			NEXT N
			
			SentFrom		= @USER4
			Subject			= 'Cassettes Added to Work Order'
			Message			= NewCassetteCnt:" Cassettes have been added to Scheduled Work Order ":WONo
			AttachWindow	= 'WO_PROD'
			AttachKey		= WONo
			SendToGroup		= ''

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

	* Loop through ScanResults and call obj_WO_Mat('Create')
	
	NewCassetteCnt = COUNT(ScanResults<COL$CASS_NO>,@VM) + (ScanResults<COL$CASS_NO> NE '')
		
	Def = ''
	Def<MCAPTION$>		= 'Receiving Cassettes...'
	Def<MTYPE$>			= 'G'
	Def<MEXTENT$>		= NewCassetteCnt
	Def<MTEXTWIDTH$>	= 600
	MsgUp = Msg(@WINDOW,Def)	
			
	FOR I = 1 TO NewCassetteCnt
	
		Msg(@WINDOW, MsgUp, I, MSGINSTUPDATE$)
		
		CassNo = I
		
		Parms  = WONo:@RM
		Parms := CassNo:@RM
		Parms := ProdVerNo:@RM
		Parms := ScanResults<COL$CASS_LOT_NO,I>:@RM
		Parms := ScanResults<COL$CASS_QTY,I>:@RM
		Parms := ScanResults<COL$CASS_PART_NO,I>:@RM
		Parms := ScanResults<COL$CASS_ORDER_ITEM,I>:@RM
		Parms := ReactType:@RM
		Parms := ScanResults<COL$CASS_SUB_PART_NO,I>:@RM
		Parms := 'SR':@RM									;* Warehouse = 'SR' - Shipping/Receiving Area
		Parms := 'RB':@RM									;* Location = 'RB' - Receiving Bench
		Parms := ScanResults<COL$CASS_TIME_STAMP,I>:@RM
		Parms := ScanResults<COL$CASS_SCAN_BY,I>:@RM
		Parms := SubSupplyBy:@RM
		Parms := MUWaferFlag:@RM
		Parms := RetRejects:@RM									;* Added 8/18/2009 JCH
		Parms := 1											;* Reprocessed Material Flag
		
		obj_WO_Mat('Create',Parms)		;* Added 10/18/2006 JCH - New Work Order material subsystem.
		
		ExistCassCnt += 1
		
	NEXT I
	
	Msg(@WINDOW,MsgUp)
END


IF ScanResults NE '' THEN
	Recipients = XLATE('NOTIFICATION','MATERIAL_RECEIPT',NOTIFICATION_USER_ID$,'X')		;* Added 10/04/2005 JCH - J.C. Henry & Co., Inc
	SentFrom   = @USER4
	Subject    = 'Cassettes Received for Work Order'
	Message    = "Cassettes have been received for Work Order ":WONo
    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

Set_Property(@WINDOW:'.RX_BY','DEFPROP',OCONV(@USER4,'[XLATE_CONV,LSL_USERS*FIRST_LAST]'))		;* Current user
Set_Property(@WINDOW:'.RX_DTM','DEFPROP',OCONV(Date(),'D4/'):' ':OCONV(Time(),'MTH') )			;* Current timestamp

Send_Event(@WINDOW,'WRITE')

obj_AppWindow('LoadFormKeys','WO_REPROCESS':@RM:WONo)

RETURN





