COMPILE ROUTINE SPLIT_ORDER(Dummy)
ROWDEF(CHARSTR)

DECLARE SUBROUTINE Send_Dyn,Send_Info, Set_Status
DECLARE FUNCTION Get_Status, Test_Convert_PO, obj_Order

$INSERT WO_LOG_EQU
$INSERT ORDER_EQU

EQU ST$WO				TO 1		;* Equates used with obj_Order
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

* This routine moves detail information in the ORDER table to the WO_LOG table where it belongs.
* JCHenry 8/14/2004

OPEN 'ORDER' TO OrderTable ELSE
	Send_Dyn('Unable to open "ORDER" table for conversion')
	GOTO Bail
END

OPEN 'WO_LOG' TO WOLogTable ELSE
	Send_Dyn('Unable to open "WO_LOG" table for conversion')
	GOTO Bail
END	

SELECT OrderTable

RecCnt = 0

Done = 0
LOOP
	READNEXT OrdNo ELSE Done = 1
UNTIL Done
	READ OrderRec FROM OrderTable,OrdNo THEN
		RecCnt += 1	
		GOTO Skip
		
		Set_Status(0)
		WOUpdates = obj_Order('Ord_WOLog',OrdNo:@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
				
				WOLogRec<WO_LOG_ORDER_NO$>		= WOUpdate<ST$ORD_NO>
				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>
				WOLogRec<WO_LOG_CASS_CNT$>		= WOUpdate<ST$CASS_CNT>
				WOLogRec<WO_LOG_CASS_QTY$>		= WOUPdate<ST$CASS_QTY>
				
				WRITE WOLogRec ON WOLogTable,WONo THEN
					Send_Info(RecCnt)
				END
								
			END	ELSE
				Send_Dyn('Missing WO_LOG Record: ':WONo)
				GOTO Skip
			END ;* End of WOLOgRec READ


		NEXT I
		
SKIP:
		PO = OrderRec<ORDER_PO$>
		CompNo = OrderRec<ORDER_CUST_NO$>
		
		POStuff = Test_Convert_PO(PO,CompNo)
		OrderRec<ORDER_PO_NO$>		= POStuff<1,1>
		OrderRec<ORDER_PO_LINE$>	= POStuff<1,2>
		OrderRec<ORDER_PO_REL$>		= POStuff<1,3>
		
		
		
		WRITE OrderRec ON OrderTable,OrdNo THEN
			Send_Info(RecCnt)
		END
		

	END	;* End of ORDER record read

REPEAT

IF Get_Status(errCode) THEN DEBUG

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

END
