COMPILE FUNCTION obj_Order_Test(Method,Parms)
/*
	Methods for Order table
    
	08/15/2004 JCH - Initial Coding
     
    Properties:
     
    Methods:
    
    Find()			;* Lookup Order number
	
	
*/


DECLARE FUNCTION Get_Status, Msg, Utility, obj_Tables, Dialog_Box
DECLARE SUBROUTINE  Set_Status, Msg, obj_Tables, Send_Dyn

$INSERT MSG_EQUATES
$INSERT ORDER_EQU
$INSERT WO_LOG_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

ErrTitle = 'Error in Stored Procedure "obj_Order"'
ErrorMsg = ''

IF NOT(ASSIGNED(Method))	THEN ErrorMsg = 'Unassigned parameter "Method" passed to subroutine'
IF NOT(ASSIGNED(Parms))		THEN Parms = ''

IF ErrorMsg NE '' THEN
	Set_Status(-1,ErrTitle:@SVM:ErrorMsg)
	RETURN ''
END

Result = ''

BEGIN CASE
	CASE Method = 'Find'		; GOSUB Find
	CASE Method = 'Ord_WOLog'	; GOSUB Ord_WOLog
	CASE 1
		ErrorMsg = 'Unknown Method ':QUOTE(Method):' passed to routine.'

END CASE

IF ErrorMsg NE '' THEN
	Set_Status(-1,ErrTitle:@SVM:ErrorMsg)
	RETURN ''
END

RETURN Result


* * * * * * *
Find:
* * * * * * *

OrderKeys = Dialog_Box( 'DIALOG_ORDER_FIND', @WINDOW, '' )

Result = OrderKeys

RETURN


* * * * * * *
Ord_WOLog:
* * * * * * *

OrdNo	= Parms[1,@RM]
OrdRec	= Parms[COL2()+1,@RM]


IF NOT(ASSIGNED(OrdNo)) THEN ErrorMsg = 'Unassigned parameter "OrdNo" passed to routine. (':Method:')'
IF NOT(ASSIGNED(OrdRec)) THEN OrdRec = ''

IF ErrorMsg NE '' OR OrdNo = '' THEN RETURN

IF  OrdRec = '' THEN
	OrdRec = XLATE('ORDER',OrdNo,'','X')
END



SchedIDs	= OrdRec<ORDER_SCHEDULE_IDS$>		; SchedIDCnt	= COUNT(SchedIDs,@VM) + (SchedIDs NE '')
PartNos		= OrdRec<ORDER_PART_NUM$>			; PartNoCnt		= COUNT(PartNos,@VM) + (PartNos NE '')
LotNos		= OrdRec<ORDER_LOT_NUM$>			; LotNoCnt		= COUNT(LotNos,@VM) + (LotNos NE '')
Qtys		= OrdRec<ORDER_QUANTITY$>			; QtyCnt		= COUNT(Qtys,@VM) + (Qtys NE '')
Prices		= OrdRec<ORDER_PRICE$>				; PriceCnt		= COUNT(Prices,@VM) + (Prices NE '')
WONos		= OrdRec<ORDER_WO$>					; WOCnt			= COUNT(WONos,@VM) + (WONos NE '')
QuoteIDs	= OrdRec<ORDER_QUOTE_IDS$>			; QuoteCnt		= COUNT(QuoteIDs,@VM) + (QuoteIDs NE '')
SetupChgs	= OrdRec<ORDER_SETUP_CHARGE$>		; SetupChgCnt	= COUNT(SetupChgs,@VM) + (SetupChgs NE '')
SRPChgs		= OrdRec<ORDER_SRP_CHARGE$>			; SRPChgCnt		= COUNT(SRPChgs,@VM) + (SRPChgs NE '')
WafInvIDs	= OrdRec<ORDER_WAF_INV_IDS$>		; WafInvCnt		= COUNT(WafInvIDs,@VM) + (WafInvIDs NE '')
SubPartNos	= OrdRec<ORDER_SUB_PART_NUM$>		; SubPartCnt	= COUNT(SubPartNos,@VM) + (SubPartNos NE '')

	
MVCnt = SchedIDCnt
IF PartNoCnt > MVCnt	THEN MVCnt = PartNoCnt
IF LotNoCnt > MVCnt		THEN MVCnt = LotNoCnt
IF QtyCnt > MVCnt		THEN MVCnt = QtyCnt
IF PriceCnt > MVCnt		THEN MVCnt = PriceCnt
IF WOCnt > MVCnt		THEN MVCnt = WOCnt
IF QuoteCnt > MVCnt		THEN MVCnt = QuoteCnt
IF SetupChgCnt > MVCnt	THEN MVCnt = SetupChgCnt
IF SRPChgCnt > MVCnt	THEN MVCnt = SRPChgCnt
IF WafInvCnt > MVCnt	THEN MVCnt = WafInvCnt
IF SubPartCnt > MVCnt	THEN MVCnt = SubPartCnt



WOList = ''
WOStructs = ''

FOR I = 1 TO MVCnt
	WONo = WONos<1,I>
	LOCATE WONo IN WOList USING @FM SETTING WOPos  ELSE
		WOList = INSERT(WOList,WOPos,0,0,WONo)
	END
	
	WOStruct = FIELD(WOStructs,@RM,WOPos,1)
	
	IF WOStruct<ST$WO>			= '' THEN WOStruct<ST$WO> = WONo
	IF WOStruct<ST$ORD_NO>		= '' AND OrdNo NE ''			THEN WOStruct<ST$ORD_NO> = OrdNo
	IF WOStruct<ST$QUOTE_NO>	= '' AND QuoteIDs<1,I> NE ''	THEN WOStruct<ST$QUOTE_NO> = QuoteIDs<1,I>
	IF WOStruct<ST$PRICE>		= '' AND Prices<1,I> NE ''		THEN WOStruct<ST$PRICE> = Prices<1,I>
	
	
	IF LotNos<1,I> = '' OR (SetupChgs<1,I> NE '' OR SRPChgs<1,I> NE '') THEN
		AddChgDesc = PartNos<1,I>
		IF SubPartNos<1,I> NE '' THEN AddChgDesc := ' ':SubPartNos<1,I>
		
		AddChgAmt = ''
		IF SetupChgs<1,I> NE '' THEN AddChgAmt = SetupChgs<1,I>
		IF SRPChgs<1,I> NE '' THEN AddChgAmt = SRPChgs<1,I>
		IF AddChgAmt = '' THEN AddChgAmt = 0
		
		LOCATE AddChgDesc IN WOStruct<ST$ADD_CHG_DESCS> USING @VM SETTING ACPos  ELSE
			WOStruct = INSERT(WOStruct,ST$ADD_CHG_DESCS,ACPos,0,AddChgDesc)
			WOStruct = INSERT(WOStruct,ST$ADD_CHG_AMTS,ACPos,0,AddChgAmt)
		END
	END ELSE
		SchedID = SchedIDs<1,I>
		
		SchedRec = XLATE('SCHEDULE',SchedID,'','X')
		CassCnt = SchedRec<30>
		
		LotQty = Qtys<1,I>
		IF LotQty <= 25 THEN
			CassCnt = 1
			CassQty = LotQty
		END ELSE
		
		
			BEGIN CASE
				CASE MOD(LotQty,25) = 0
					CassCnt = LotQty/25
					CassQty = 25
					
				CASE MOD(LotQty,24) = 0
					CassCnt = LotQty/24
					CassQty = 24
					
				CASE MOD(LotQty,15) = 0
					CassCnt = LotQty/15
					CassQty = 15
					 
				CASE MOD(LotQty,12) = 0
					CassCnt = LotQty/12
					CassQty = 12
					
				CASE MOD(LotQty,10) = 0
					CassCnt = LotQty/10
					CassQty = 10
					
				CASE 1
					CassCnt = ''
					CassQty = ''
					
			END CASE
		END	;* End of small lot check		
		
		LOCATE SchedID IN WOStruct<ST$SCHED_IDS> USING @VM SETTING SchedPos ELSE
			WOStruct = INSERT(WOStruct,ST$SCHED_IDS,SchedPos,0,SchedID)
			WOStruct = INSERT(WOStruct,ST$LOT_NOS,SchedPos,0,LotNos<1,I>)
			WOStruct = INSERT(WOStruct,ST$LOT_QTYS,SchedPos,0,Qtys<1,I>)
			WOStruct = INSERT(WOStruct,ST$PART_NOS,SchedPos,0,PartNos<1,I>)
			WOStruct = INSERT(WOStruct,ST$SUB_PART_NOS,SchedPos,0,SubPartNos<1,I>)
			WOStruct = INSERT(WOStruct,ST$WAF_INV_IDS,SchedPos,0,WafInvIDs<1,I>)
			WOStruct = INSERT(WOStruct,ST$CASS_CNT,SchedPos,0,CassCnt)
			WOStruct = INSERT(WOStruct,ST$CASS_QTY,SchedPos,0,CassQty)
		END	;* End of Locate Sched Pos
		
	END	;* End of check for lot number

	WOStructs = FIELDSTORE(WOStructs,@RM,WOPos,-1,WOStruct)


NEXT I

Result = WOStructs

RETURN





