COMPILE FUNCTION Prod_Ver_Select(EntID,Event,Parm1,Parm2,Parm3,Parm4,Parm5)

/*
	Commuter module for the Prod_Ver_Select collector window.
	
	06/08/2011 - John C. Henry, J.C. Henry & Co., Inc.
*/

DECLARE SUBROUTINE Set_Property, End_Dialog, Set_Status, ErrMsg
DECLARE SUBROUTINE obj_Appwindow, Start_Window, Msg, Send_Message,Btree.Extract
DECLARE FUNCTION Get_Property, Get_Status, Dialog_Box

$INSERT PROD_VER_EQUATES
$INSERT EPI_PART_EQUATES
$INSERT PROD_SPEC_EQUATES

EQU CRLF$	TO \0D0A\


ErrTitle = 'Error in Prod_Ver_Select'
ErrorMsg = ''

Result = ''

BEGIN CASE
	CASE EntID = @WINDOW
		BEGIN CASE
			CASE Event = 'CREATE'			; GOSUB Create
			CASE Event = 'CLOSE'			; GOSUB Close
		END CASE
		
	CASE EntID = @WINDOW:'.OK_BUTTON'		; GOSUB OK
	CASE EntID = @WINDOW:'.CANCEL_BUTTON'	; GOSUB Cancel
	
	CASE 1
		ErrorMsg = 'Unknown Parameters ':EntID:' - ':Event:' passed to commuter'
		ErrMsg(ErrorMsg)
			
END CASE

IF ErrorMsg NE '' THEN
	ErrMsg(ErrTitle:@SVM:ErrorMsg)
END

RETURN Result


* * * * * * *
Create:
* * * * * * *

obj_AppWindow('Create')

EpiPartNo	= Parm1<1,1>
PsnID		= Parm1<1,2>

OPEN 'DICT.PROD_VER' TO DictProdVer ELSE
	ErrMsg('Unable to Open DICT.PROD_VER table for BTREE.EXTRACT')
	GOTO Cancel
END

Search				= 'PSN_ID':@VM:PsnID:@FM		;*:'STATUS':@VM:'A':@FM
Table				= 'PROD_VER'
ActiveProdVerNos	= ''
Option				= ''
Flag				= ''

Btree.Extract(Search,Table,DictProdVer,ProdVerNos,Option,Flag)

IF ProdVerNos = '' THEN
	ErrMsg('No Prod Ver numbers on file for Epi Part No: ':QUOTE(EpiPartNo))
	RETURN
END

ProdVerCnt = COUNT(ProdVerNos,@VM) + (ProdVerNos NE '')

SortArray = ''
ProdVerArray = ''

FOR I = 1 TO ProdVerCnt
	ProdVerNo = ProdVerNos<1,I>

	ProdVerRec = XLATE('PROD_VER',ProdVerNo,'','X')
	
	PVStatus	= ProdVerRec<PROD_VER_STATUS$>
	IF PVStatus = 'A' THEN PVStatus = 'Active'
	IF PVStatus = 'I' THEN PVStatus = 'xx Inactive xx'
	
	CustNo		= ProdVerRec<PROD_VER_CUST_NO$>
	ReactType	= OCONV(ProdVerRec<PROD_VER_REACT_TYPE$>,'[REACT_TYPE_CONV,OPSREF]')
	SubPartNo	= ProdVerRec<PROD_VER_SUB_PART_NO$>
	
	SubPartKey = PVStatus:'*':ProdVerNo:'*':ReactType:'*':SubPartNo
	
	LOCATE SubPartKey IN SortArray BY 'AL' USING @FM SETTING Pos ELSE
		SortArray = INSERT(SortArray,Pos,0,0,SubPartKey)
		ProdVerArray = INSERT(ProdVerArray,Pos,0,0,ProdVerNo)
	END
NEXT I

PrevPVStatus = ''
PrevReactType = ''

FOR I = 1 TO ProdVerCnt

	SubPartKey	= SortArray<I>
	ProdVerNo	= ProdVerArray<I>
	
	PVStatus	= SubPartKey[1,'*']
	ProdVerNo	= SubPartKey[COL2()+1,'*']
	ReactType	= SubPartKey[COL2()+1,'*']
	SubPartNo	= SubPartKey[COL2()+1,'*']
	
	
	IF PVStatus NE PrevPVStatus THEN
		Result<-1> = '2-1:Status: ':PVStatus
		PrevPVStatus = PVStatus
	END
	
	IF ReactType NE PrevReactType THEN
		Result<-1> = '2-2:React Type: ':ReactType
		PrevReactType = ReactType
	END
	
	Result<-1> = '3-3: Prod_Ver_No: ':ProdVerNo:' - ':SubPartNo

NEXT I


Set_Property(@WINDOW:'.PROD_VER_LIST','LIST',Result)
Send_Message(@WINDOW:'.PROD_VER_LIST','EXPAND',2,1)


RETURN



* * * * * * *
Refresh:
* * * * * * *


RETURN



* * * * * * *
Close:
* * * * * * *


* * * * * * *
Cancel:
* * * * * * *

End_Dialog(@WINDOW,'Cancel')

RETURN



* * * * * * *
OK:
* * * * * * *

ProdVerString = TRIM(Get_Property(@WINDOW:'.PROD_VER_LIST','TEXT'))

ProdVerNo = FIELD(ProdVerString,' ',2)

End_Dialog(@WINDOW,ProdVerNo)

RETURN


