COMPILE Subroutine Move_Order_Detail(Dummy)

DECLARE SUBROUTINE SEND_INFO, Utility, Msg, RList, ErrMsg, Set_Status, obj_WO_Log, Send_Info
DECLARE FUNCTION Printer_Select, Get_Printer, Set_Printer, obj_Install,Get_Status, obj_Order

$INSERT ORDER_EQU
$INSERT WO_LOG_EQU
$INSERT PROD_SPEC_EQU
$INSERT WO_STEP_EQU
$INSERT SCHEDULE_EQU
$INSERT RLIST_EQUATES
$INSERT APPCOLORS
$INSERT RDS_EQU


EQU ST$WO				TO 1
EQU ST$ORD_NO			TO 2
EQU ST$QUOTE_NO			TO 3
EQU ST$PRICE			TO 4
EQU ST$LOT_NOS			TO 5
EQU ST$LOT_QTYS			TO 6
EQU ST$PART_NOS			TO 7
EQU ST$SUB_PART_NOS		TO 8
EQU ST$WAF_INV_IDS		TO 9
EQU ST$SCHED_IDS		TO 10
EQU ST$ADD_CHG_DESCS	TO 11
EQU ST$ADD_CHG_AMTS		TO 12
EQU ST$CASS_CNT			TO 13
EQU ST$CASS_QTY			TO 14

ErrorTitle = 'Error in Stored Procedure Move_Order_Detail'
ErrorMsg = ''

OPEN 'ORDER' TO OrderTable ELSE
	ErrorMsg = 'Unable to open "ORDER" table.'
	ErrMsg(ErrorTitle:@SVM:ErrorMsg)
	RETURN
END

OPEN 'DICT.ORDER' TO @DICT ELSE
	ErrorMsg = 'Unable to open "DICT.ORDER" table.'
	ErrMsg(ErrorTitle:@SVM:ErrorMsg)
	RETURN
END


OPEN 'WO_LOG' TO WOLogTable ELSE
	ErrorMsg = 'Unable to open "WO_LOG" table.'
	ErrMsg(ErrorTitle:@SVM:ErrorMsg)
	RETURN
END

OPEN 'WO_STEP' TO WOStepTable ELSE
	ErrorMsg = 'Unable to open "WO_STEP" table.'
	ErrMsg(ErrorTitle:@SVM:ErrorMsg)
	RETURN
END

OPEN 'SCHEDULE' TO SchedTable ELSE
	ErrorMsg = 'Unable to open "SCHEDULE" table.'
	ErrMsg(ErrorTitle:@SVM:ErrorMsg)
	RETURN
END	

OPEN 'RDS' TO RDSTable ELSE
	ErrorMsg = 'Unable to open "RDS" table.'
	ErrMsg(ErrorTitle:@SVM:ErrorMsg)
	RETURN
END	


SelectSent  =  'SELECT ORDER WITH ENTRY_DATE > =  "1 10 2005"'

RList(SelectSent,TARGET_ACTIVELIST$,'','','')


Done = 0
LOOP
	READNEXT OrderNo ELSE Done = 1
UNTIL Done
	
	READ OrderRec FROM OrderTable,OrderNo THEN
		Set_Status(0)
		WOUpdates = obj_Order('Ord_WOLog',OrderNo:@RM:OrderRec)
		
		IF Get_Status(errCode) THEN DEBUG
		
		FOR I = 1 TO COUNT(WOUpdates,@RM) + (WOUpdates NE '')
			WOUpdate = FIELD(WOUpdates,@RM,I,1)
			
			WONo = WOUpdate<ST$WO>
			
			READ WOLogRec FROM WOLogTable,WONo THEN
				QuoteNo = WOUpdate<ST$QUOTE_NO>
				QuoteDetKeys = XLATE('QUOTE',QuoteNo,35,'X')
				IF INDEX(QuoteDetKeys,@VM,1) ELSE
				
					WOLogRec<WO_LOG_ORDER_NO$>		= OrderNo
					WOLogRec<WO_LOG_QUOTE_NO$>		= WOUpdate<ST$QUOTE_NO>
					WOLogRec<WO_LOG_UNIT_PRICE$>	= WOUpdate<ST$PRICE>
					
					WOLogRec<WO_LOG_LOT_NO$>		= WOUpdate<ST$LOT_NOS>
					WOLogRec<WO_LOG_LOT_QTY$>		= WOUpdate<ST$LOT_QTYS>
					WOLogRec<WO_LOG_PART_NO$>		= WOUpdate<ST$PART_NOS>
					WOLogRec<WO_LOG_SUB_PART_NO$>	= WOUpdate<ST$SUB_PART_NOS>
					WOLogRec<WO_LOG_WAF_INV_ID$>	= WOUpdate<ST$WAF_INV_IDS>
					WOLogRec<WO_LOG_SCHED_ID$>		= WOUpdate<ST$SCHED_IDS>
					WOLogRec<WO_LOG_ADD_CHG_DESC$>	= WOUpdate<ST$ADD_CHG_DESCS>
					WOLogRec<WO_LOG_ADD_CHG_AMT$>	= WOUpdate<ST$ADD_CHG_AMTS>
				
					
					WRITE WOLogRec ON WOLogTable,WONo THEN
						Send_Info('WONo ':WONo)
					END ELSE
						ErrMsg('Unable to write WO_Log Record ':WONo:' in Write event of ORDER Window')
					END
					
				END	;* End of check for
			END	ELSE
				GOTO Skip
			END ;* End of WOLOgRec READ
		NEXT I
SKIP:
	END	;* End of ORDER record read

REPEAT



* * * * * * *
JumpHere:
* * * * * * *

SelectSent  =  'SELECT WO_LOG WITH ENTRY_DATE >= "1/10/2005"'

RList(SelectSent,TARGET_ACTIVELIST$,'','','')

RecCnt = 0
Done = 0
LOOP
	READNEXT WONo ELSE Done = 1
UNTIL Done
	
	READ WORec FROM WOLogTable,WoNo THEN
		RecCnt += 1
		Send_Info(RecCnt)
		WOStepKeys = WORec<WO_LOG_WO_STEP_KEY$>
		
		FOR I = 1 TO COUNT(WOStepKeys,@VM) + (WOStepKeys NE '')
			WOStepKey = WOStepKeys<1,I>
			WOStepRec = XLATE('WO_STEP',WOStepKey,'','X')
			
			SchedIDs = WOStepRec<WO_STEP_SCHED_ID$>
			SchedCnt = COUNT(SchedIDs,@VM) + (SchedIDs NE '')
			Send_Info('SchedCnt: ':SchedCnt)
						
			FOR N = 1 TO SchedCnt
				SchedID = SchedIDs<1,N>
				Set_Status(0)
				obj_WO_Log('AddSchedDetail',WoNo:@RM:SchedID)
				IF Get_Status(errCode) THEN DEBUG
				
				RDSKeys = XLATE('SCHEDULE',SchedID,SCHEDULE_RDS_IDS$,'X')
				
				FOR M = 1 TO COUNT(RDSKeys,@VM) + (RDSKeys NE '')
					RDSKey = RDSKeys<1,M>
					READ RDSRec FROM RDSTable,RDSKey THEN
						RDSRec<RDS_WO_STEP_KEY$> = WOStepKey
						WRITE RDSRec ON RDSTable,RDSKey THEN Send_Info('RDS: ':RDSKey)
					END
				NEXT M
			NEXT N

		NEXT I

		
		
	END	;* end of WORec read
REPEAT
	
	
return
		
		
		
		
