COMPILE FUNCTION obj_Quote(Method,Parms)

/*
	Methods for the Quote table
    
	12/05/2004 JCH - Initial Coding
     
    Properties:
     
    Methods:
    
    ProdSpecHistory(PSNNo)		;* Returns @VM's list of Quotes that use the specified PSN
	
*/


DECLARE FUNCTION Get_Status, Msg, Utility, obj_Tables, Dialog_Box
DECLARE SUBROUTINE  Set_Status, Msg, obj_Tables, Send_Dyn, Btree.Extract

$INSERT MSG_EQUATES
$INSERT QUOTE_EQUATES
$INSERT PROD_SPEC_EQU
$INSERT PROD_VER_EQUATES

ErrTitle = 'Error in Stored Procedure "obj_Quote"'
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 = 'ProdSpecHistory'		; GOSUB ProdSpecHistory
	CASE Method = 'CustPNDesc'			; GOSUB CustPNDesc
	CASE Method = 'CustPNInbound'		; GOSUB CustPNInbound
	CASE Method = 'PartNo'				; GOSUB PartNo
	CASE Method = 'GetQuoteProdVer'		; GOSUB GetQuoteProdVer
	
	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



* * * * * * *
ProdSpecHistory:
* * * * * * *

QuoteNo = Parms[1,@RM]

IF NOT(ASSIGNED(QuoteNo)) THEN QuoteNo = ''

IF QuoteNo = '' THEN RETURN

OPEN 'DICT.PROD_SPEC' TO DictVar ELSE
	ErrorMsg = 'Unable to Open DICT.PROD_SPEC table'
	RETURN
END

SearchString = 'QUOTE_KEYS':@VM:QuoteNo
Option = ''
Flag = ''

Btree.Extract(SearchString,'PROD_SPEC',DictVar,QuoteNos,Option,Flag)

Result = QuoteNos


RETURN



* * * * * * *
CustPNDesc:
* * * * * * *

RETURN

QuoteNo		= Parms[1,@RM]
CustPN		= Parms[COL2()+1,@RM]
QuoteRec	= Parms[COL2()+1,@RM]

IF QuoteNo	= '' THEN RETURN
IF CustPN	= '' THEN RETURN
IF QuoteRec = '' THEN QuoteRec = XLATE('QUOTE',QuoteNo,'','X')

StepPSNs		= QuoteRec<QUOTE_PROC_STEP_PSN$>
ShippingPSN		= StepPSNs[-1,'B':@VM]															;* Last process step PSN
SpecRec			= XLATE('PROD_SPEC',ShippingPSN,'','X')

SpecCustPartNos = SpecRec<PROD_SPEC_CUST_PART_NO$>

LOCATE CustPN IN SpecCustPartNos USING @VM SETTING Pos THEN
	Result = SpecRec<PROD_SPEC_PN_DESC$,Pos>
END

RETURN



* * * * * * *
CustPNInbound:
* * * * * * *

QuoteNo		= Parms[1,@RM]
CustPN		= Parms[COL2()+1,@RM]
QuoteRec	= Parms[COL2()+1,@RM]

RETURN

IF QuoteNo	= '' THEN RETURN
IF CustPN	= '' THEN RETURN
IF QuoteRec = '' THEN QuoteRec = XLATE('QUOTE',QuoteNo,'','X')

StepPSNs		= QuoteRec<QUOTE_PROC_STEP_PSN$>
ShippingPSN		= StepPSNs[-1,'B':@VM]															;* Last process step PSN
SpecRec			= XLATE('PROD_SPEC',ShippingPSN,'','X')

SpecCustPartNos = SpecRec<PROD_SPEC_CUST_PART_NO$>

LOCATE CustPN IN SpecCustPartNos USING @VM SETTING Pos THEN
	Result = SpecRec<PROD_SPEC_INBOUND_CUST_PN$,Pos>
END

RETURN


* * * * * * *
PartNo:
* * * * * * *

QuoteNo		= Parms[1,@RM]
QuoteRec	= Parms[COL2()+1,@RM]

IF QuoteNo = '' THEN RETURN

IF QuoteRec = '' THEN
	QuoteRec = XLATE('QUOTE',QuoteNo,'','X')
END

IF QuoteRec = '' THEN RETURN


PsnID = XLATE('QUOTE',QuoteNo,'PSN_ID','X')

CONVERT @VM TO '.' IN PsnID

EpiPartNos = QuoteRec<QUOTE_EPI_PART_NO$>

EpiPartNo = ''
EPCnt = COUNT(EpiPartNos,@VM) + (EpiPartNos NE '')

FOR I = 1 to EPCnt
	EPN = EpiPartNos<1,I>
	IF INDEX(EPN,'-',1) ELSE
		LOCATE EPN IN EpiPartNo BY 'AL' USING @VM SETTING Pos ELSE
			EpiPartNo = INSERT(EpiPartNo,1,Pos,0,EPN)
		END
	END	;* End of check for dash in EPN
NEXT I

Result = PsnID:' - ':EpiPartNo

RETURN


* * * * * * *
GetQuoteProdVer:
* * * * * * *

QuoteNo		= Parms[1,@RM]
QuoteRec	= Parms[COL2()+1,@RM]

IF QuoteNo = '' THEN RETURN

IF QuoteRec = '' THEN
	QuoteRec = XLATE('QUOTE',QuoteNo,'','X')
END

IF QuoteRec = '' THEN RETURN


IF QuoteRec<QUOTE_PROD_VER_NO$> = '' THEN
	Result = QuoteRec<QUOTE_PROC_STEP_PSN_ORG$>
	CONVERT @VM TO '.' IN Result
END ELSE
	ProdVerNos = QuoteRec<QUOTE_PROD_VER_NO$>
	
	PVCnt = COUNT(ProdVerNos,@VM) + (ProdVerNos NE '')
	
	QuoteProdVerNo = ''
	
	FOR I = 1 TO PVCnt
		ProdVerNo = ProdVerNos<1,I>
		
		IF QuoteProdVerNo = '' THEN
			QuoteProdVerNo = ProdVerNo
		END ELSE
			IF ProdVerNo NE QuoteProdVerNo THEN
				Result = '*Error*'
				RETURN
			END
		END
	NEXT I
	Result = QuoteProdVerNo
END


RETURN













