COMPILE FUNCTION obj_Pend_Ship_Labels(Method,Parms)
/*
	Methods for the Pending Shipping Label (PEND_SHIP_LABELS) table.
    
	5/15/2015 JCH - Initial Coding
     
	Properties:
	
	Methods:
	
	SetCassNo									;* Create new WO Material entry
	PrintAll(null)								;* Pass null - Prints all 
	
*/


DECLARE FUNCTION Get_Status, Msg, Utility, obj_Tables,
DECLARE SUBROUTINE  Set_Status, Msg, obj_Tables, ErrMsg, obj_WO_Mat, RList, Print_SAP_Cass_Ship_Label

$INSERT PEND_SHIP_LABELS_EQUATES
$INSERT WO_LOG_EQUATES
$INSERT WO_MAT_EQUATES

EQU CRLF$	TO \0D0A\
EQU TAB$	TO \09\

EQU TARGET_ACTIVELIST$ TO 5

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

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

Result = ''

BEGIN CASE
	CASE Method = 'SetCassNo'		; GOSUB SetCassNo
	CASE Method = 'PrintAll'		; GOSUB PrintAll
	
	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


* * * * * * *
SetCassNo:
* * * * * * *

WONo		= Parms[1,@RM]
CassNo		= Parms[COL2()+1,@RM]

IF WONo = ''		THEN ErrorMsg = 'Null parameter "WONo" passed to routine. (':Method:')'
IF CassNo = ''		THEN ErrorMsg = 'Null parameter "CassNo" passed to routine. (':Method:')'


IF ErrorMsg NE '' THEN
	RETURN
END

OtParms = 'PEND_SHIP_LABELS':@RM:WONo
PendLabelsRec = obj_Tables('ReadRec',OtParms)

LOCATE CassNo IN PendLabelsRec<PEND_SHIP_LABELS_CASS_NO$> BY 'AR' USING @VM SETTING Pos ELSE

	PendLabelsRec = INSERT(PendLabelsRec,PEND_SHIP_LABELS_CASS_NO$,Pos,0,CassNo)
	
	OtParms = FieldStore(OtParms, @RM, 4, 1, PendLabelsRec)
	obj_Tables('WriteRec',OtParms)
	
END

RETURN



* * * * * * *
PrintAll:
* * * * * * *


OPEN 'PEND_SHIP_LABELS' TO PSLTable ELSE
	RETURN
END

SelectString = 'SELECT PEND_SHIP_LABELS BY WO_NO '

RList(SelectString,TARGET_ACTIVELIST$,'','','')


Done = 0

LOOP
	READNEXT WONo ELSE Done = 1
UNTIL Done
	READ PSLRec FROM PSLTable,WONo THEN
		WOStepKey	= XLATE('WO_LOG',WONo,WO_LOG_WO_STEP_KEY$,'X')[-1,'B':@VM]  ;* Last step only
		WOStepNo	= WOStepKey[-1,'B*'] 
		
		
		CassNos = PSLRec<PEND_SHIP_LABELS_CASS_NO$>
		cCnt = COUNT(CassNos,@VM) + (CassNos NE '')
		
		ShipRDSNos = ''
		
		FOR I = 1 TO cCnt
			CassNo = CassNos<1,I>
		
			ShipRDSNos<1,I> = XLATE('WO_MAT',WONo:'*':CassNo , WO_MAT_RDS_NO$ , 'X' )<1,WOStepNo>
			
		NEXT I
	
		Print_SAP_Cass_Ship_Label( WONo ,WOStepNo, CassNos, ShipRDSNos )
		
		
		DELETE PSLTable,WONo THEN NULL
		
	
	END	;* End of PSLRec Read
REPEAT


RETURN


