COMPILE ROUTINE FIX_Order_Det(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_Vision
DECLARE FUNCTION Get_Status, Set_Printer

$INSERT ORDER_DET_EQU
$INSERT ORDER_EQU
$INSERT QUOTE_EQU


OPEN 'ORDER_DET' TO OrderDetTable  ELSE
	DEBUG
	GOTO Bail
END

DEBUG

FOR I = 1 TO 28
	OrdDetKey = 53182:'*':148745:'*':I
	READ JunkRec FROM OrderDetTable,OrdDetKey THEN
		DELETE OrderDetTable,OrdDetKey THEN
			Send_Dyn(LEN(JunkRec):' ':OrdDetKey)
		END
	END

NEXT I



GOTO Bail
*********************

OPEN 'QUOTE' TO QuoteTable ELSE
	DEBUG
	GOTO Bail
END

SELECT OrderDetTable


CheckDt = ICONV('7/17/2004','D')
RecCnt = 0
Done = 0
LOOP
	READNEXT OrderDetKey ELSE Done = 1
UNTIL Done
	
	READ OrderDetRec FROM OrderDetTable,OrderDetKey THEN
		RecCnt += 1
		
		Send_Info(RecCnt)
		
		QuoteNo = OrderDetRec<ORDER_DET_QUOTE_NO$>
	
		Captive = XLATE('ORDER',OrderDetKey[1,'*'],ORDER_CAPTIVE$,'X')
		OrderEntDt = XLATE('ORDER',OrderDetKey[1,'*'],ORDER_ENTRY_DATE$,'X')
		
		IF Captive AND OrderEntDt >= CheckDt THEN
			IF OrderDetRec<ORDER_DET_CUST_PN$> = '' THEN
				QCustPartNos = XLATE('QUOTE',QuoteNo,QUOTE_QUOTE_PART_NO$,'X')
				QCPNCnt = COUNT(QCustPartNos,@VM) + (QCustPartNos NE '')
				IF QCPNCnt = 1 THEN
					PartNo = QCustPartNos
					OrderDetRec<ORDER_DET_CUST_PN$> = PartNo
				END
			END ELSE
				PartNo = OrderDetRec<ORDER_DET_CUST_PN$>
			END
				
			CustNo = XLATE('ORDER',OrderDetKey[1,'*'],ORDER_CUST_NO$,'X')
			IF CustNo NE '6874' THEN
				Test = PartNo[1,6]
				IF NUM(Test) THEN
					PartNo = PartNo[1,6]
				END
			END ELSE
				IF NUM(PartNo[-3,3]) THEN PartNo := 'IRE'
				IF PartNo[1,1] NE 'W' THEN PartNo = 'W':PartNo
			END
			
			IF ( PartNo MATCHES "'W'6N'IRE'" OR NUM(PartNo) ) ELSE
				
				PartNo = 'EPI':FMT(QuoteNo,"R(0)#5")
			END		
		
			
			READ QuoteRec FROM QuoteTable,QuoteNo THEN
				IF QuoteRec<QUOTE_EPI_PART_NO$> NE PartNo THEN
					QuoteRec<QUOTE_EPI_PART_NO$> = PartNo
	
					WRITE QuoteRec ON QuoteTable,QuoteNo THEN
						Send_Dyn(QuoteNo:'  -  ':PartNo)
					END
				END
			END
		END
		
	END
REPEAT


goto Bail

/*
		IF Captive AND OrderDetRec<ORDER_DET_EPI_PN$> = '' THEN
		
			IF OrderDetRec<ORDER_DET_CUST_PN$> = '' THEN
				QCustPartNos = XLATE('QUOTE',QuoteNo,QUOTE_QUOTE_PART_NO$,'X')
				QCPNCnt = COUNT(QCustPartNos,@VM) + (QCustPartNos NE '')
				IF QCPNCnt = 1 THEN
					PartNo = QCustPartNos
					OrderDetRec<ORDER_DET_CUST_PN$> = PartNo
				END
			END ELSE
				PartNo = OrderDetRec<ORDER_DET_CUST_PN$>
			END
				
			CustNo = XLATE('ORDER',OrderDetKey[1,'*'],ORDER_CUST_NO$,'X')
			IF CustNo NE '6874' THEN
				Test = PartNo[1,6]
				IF NUM(Test) THEN
					PartNo = PartNo[1,6]
				END
			END ELSE
				IF NUM(PartNo[-3,3]) THEN PartNo := 'IRE'
				IF PartNo[1,1] NE 'W' THEN PartNo = 'W':PartNo
			END
			
			IF ( PartNo MATCHES "'W'6N'IRE'" OR NUM(PartNo) ) ELSE
				
				PartNo = 'EPI':FMT(QuoteNo,"R(0)#5")
			END
*/





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

END

