COMPILE FUNCTION obj_Part(Method,Parms)

/*
	Methods for PART table
    
	9/1/2010 JCH - Initial Coding
     
    Properties:
     
    Methods:
    
   * Convert(OrderDetKey)				;* Create Part Record from Data in ORDER_DET records on ORDER_DET window write event
	
	
*/

DECLARE SUBROUTINE  Set_Status, Msg, obj_Tables, Send_Dyn, ErrMsg
DECLARE FUNCTION Get_Status, Msg, Utility, obj_Tables, NextKey

$INSERT PROD_SPEC_EQUATES
$INSERT ORDER_DET_EQU
$INSERT QUOTE_SPEC_EQU
$INSERT PART_EQUATES
$INSERT CUST_PART_EQUATES


ErrTitle = 'Error in Stored Procedure "obj_Part"'
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 = 'Convert'			; GOSUB Convert
	CASE Method = 'SAPSubPartNos'	; GOSUB SAPSubPartNos
	CASE Method = 'CustPartSpec'	; GOSUB CustPartSpec
	
	CASE 1
		ErrorMsg = 'Unknown Method ':Method:' passed to object routine.'

END CASE

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

RETURN Result


* * * * * * *
CustPartSpec:
* * * * * * *
debug
PartNo	= Parms[1,@RM]
PartRec = Parms[COL2()+1,@RM]

IF PartNo = '' THEN RETURN

IF PartRec = '' THEN
	PartRec = XLATE('PART',PartNo,'','X')
	IF PartRec = '' THEN RETURN
END

CustNo		= PartRec<PART_CUST_NO$>
CustPartNo	= PartRec<PART_CUST_PART_NO$>

CustPartRec = XLATE('CUST_PART',CustNo:'*':CustPartNo,'','X')
IF CustPartRec = '' THEN RETURN

SpecDescs = CustPartRec<CUST_PART_SPEC_DESC$>

CONVERT @LOWER_CASE TO @UPPER_CASE IN SpecDescs

LOCATE 'TARGET' IN SpecDescs USING @VM SETTING Pos THEN
	SpecNo	= CustPartRec<CUST_PART_SPEC_NO$,Pos>
	RevNo	= CustPartRec<CUST_PART_SPEC_REV$,Pos>
	Result = SpecNo:'*':RevNo
END ELSE
	SpecNo = SpecNo[-1,'B':@VM]
	DEBUG
END


RETURN


* * * * * * *
Convert:
* * * * * * *

RETURN






* * * * * * * 
SAPSubPartNos:
* * * * * * *

PartNo 	= Parms[1,@RM]
PartRec = Parms[COL2()+1,@RM]


IF PartNo = '' THEN RETURN

IF PartRec = '' THEN
	PartRec = XLATE('PART',PartNo,'','X')
END
	
CurrSubPartNo	= PartRec<PART_SUB_PART_NO$>

Ans = CurrSubPartNo

SPCnt = COUNT(SubPartNos,@VM) + (SubPartNos NE '')
FOR I = 1 TO SPCnt
	SubPartNo = SubPartNos<1,I>
	IF SubPartNo MATCHES "6N'-'1A'-'2A" THEN
		LOCATE SubPartNo IN Ans BY 'AL' USING @VM  SETTING Pos ELSE
			Ans = INSERT(Ans,1,Pos,0,SubPartNo)
		END
	END
NEXT I

Result = Ans
RETURN


