COMPILE ROUTINE FIX_WM_OUT(Dummy)
ROWDEF(CHARSTR)

DECLARE SUBROUTINE obj_Schedule,Send_Dyn,Send_Infom, obj_Order, obj_WO_Log, RList, RList, ErrMsg
DECLARE SUBROUTIne obj_WO_Step, Set_Status, Send_Info, obj_WM_In, obj_WM_Out
DECLARE FUNCTION Get_Status, Set_Printer,Get_Status

$INSERT ORDER_DET_EQU
$INSERT ORDER_EQU
$INSERT QUOTE_EQU
$INSERT COMPANY_EQU
$INSERT WM_OUT_EQUATES
$INSERT WM_IN_EQUATES
$INSERT WO_MAT_EQUATES
$INSERT RDS_EQU



OPEN 'WM_OUT' TO WMOTable ELSE
	GOTO Bail
END


WMOutKeys = ''
FOR CassNo = 7 TO 14
	WMOutKeys<1,-1> = '155723*1*':CassNo
NEXT CassNo

debug

*obj_WM_Out('Delete',WMOutKeys)


GOTO Bail

******************************

SelectSent = 'SELECT WM_OUT WITH WO_NO "153998" '

RList(SelectSent,5)

IF Get_Status(errCode) THEN DEBUG

Done = 0
TempRec = ''
LOOP
	READNEXT WMOKey ELSE Done = 1
UNTIl Done
	READ WMOutRec FROM WMOTable,WMOKey THEN
		SlotNos = WMOutRec<WM_OUT_SLOT_NO$>	
				
		WMOutRec<WM_OUT_SLOT_NO$>	 = FIELD(SlotNos,@VM,1,24)
		WRITE WMOutRec ON WMOTable,WMOKey THEN
			Send_Dyn(WMOKey:' ':WMOutRec<WM_OUT_SLOT_NO$>)
		END

	END
REPEAT




GOTO Bail

SELECT WMOTable



Done = 0
RecCnt = 0

LOOP
	READNEXT WMOKey ELSE Done = 1
UNTIL Done
	READ WMORec FROM WMOTable,WMOKey THEN
		WRITE WMORec ON WMOTable,WMOKey THEN
			RecCnt += 1
			Send_Info(RecCnt)
		END
	END

REPEAT




GOTO Bail

Done = 0
RecCnt = 0

LOOP
	READNEXT WMOKey ELSE Done = 1
UNTIL Done
	READ WMoRec FROM WMoTable,WMoKey THEN
		WONo = WMOKey[1,'*']
		CassNo = WMOKey[-1,'B*']
		
		WOMatRec = XLATE('WO_MAT',WONo:'*':CassNo,'','X')
		
		LocCnt = COUNT(WOMatRec<WO_MAT_INV_LOCATION$>,@VM) + (WOMatRec<WO_MAT_INV_LOCATION$> NE '')

		LastIn = ''
		LastOut = ''

		FOR I = LocCnt TO 1 STEP -1
			IF WOMatRec<WO_MAT_INV_LOCATION$,I> = 'PTI' AND LastIn = '' THEN
				LastIn = WOMatRec<WO_MAT_INV_DTM$,I>
			END
			
			IF WOMatRec<WO_MAT_INV_LOCATION$,I> = 'PTO' AND LastOut = '' THEN
				LastOut = WOMatRec<WO_MAT_INV_DTM$,I>
			END
		UNTIL LastIn NE '' AND LastOut NE ''
		NEXT I
			
		BEGIN CASE
			CASE LastIn = '' AND LastOut = ''	; InCleanRoom = 0
			CASE LastIn = ''					; InCleanRoom = 0
			CASE LastOut = ''					; InCleanRoom = 1
			CASE LastOut > LastIn				; InCleanRoom = 0
			CASE LastIn > LastOut				; InCleanRoom = 1
		END CASE


		WMORec<WM_OUT_IN_CLEANROOM$> = InCleanRoom
		
		IF InCleanRoom THEN Send_Dyn(WMOKey)
		
		*WRITE WMORec ON WMOTable,WMOKey THEN
			RecCnt += 1
			Send_Info(RecCnt)
		*END
	END

REPEAT






GOTO Bail


WMOutKEy = '139020*1*18'

obj_WM_OUT('RebuildLoad',WMOutKey)

WMOutKEy = '139020*1*19'

obj_WM_OUT('RebuildLoad',WMOutKey)

WMOutKEy = '139020*1*20'

obj_WM_OUT('RebuildLoad',WMOutKey)

GOTO Bail

SelectSent = 'SELECT WM_OUT WITH HOLD_START_DTM NE ""'

RList(SelectSent,5,'','','')

IF Get_Status(errCode) THEN DEBUG

OPEN 'WM_OUT' TO FileVar ELSE
	DEBUG
	GOTO Bail
END

debug

Done = 0
LOOP
	READNEXT WMOKey ELSE Done = 1
UNTIL Done
	READ WMOutRec FROM FileVar,WMOKey THEN
		IF WMOutRec<WM_OUT_HOLD_START_DTM$> NE '' THEN
			WMOutRec<WM_OUT_HOLD$>				= ''		
			WMOutRec<WM_OUT_HOLD_START_DTM$>	= ''
			WMOutRec<WM_OUT_HOLD_START_USER$>	= ''
			WMOutRec<WM_OUT_HOLD_START_REASON$>	= ''
			WMOutRec<WM_OUT_HOLD_STOP_DTM$>		= ''
			WMOutRec<WM_OUT_HOLD_STOP_USER$>	= ''
			WMOutRec<WM_OUT_HOLD_STOP_REASON$>	= ''
			
			
			WRITE WMOutRec ON FileVar,WMOKey THEN
				Send_Dyn(WMOKey)
			END
		END
	END
REPEAT


* * * * * *
Bail:
* * * * * *

END
