COMPILE FUNCTION Comm_Dialog_EpiPro_Export(Method, Parm1)

/*
	Commuter module for Dialog_EpiPro_Exportwindow.
	
	10/28/2005 - John C. Henry, J.C. Henry & Co., Inc.
*/

DECLARE SUBROUTINE Set_Property, End_Dialog, Send_Event, Set_Status, ErrMsg
DECLARE SUBROUTINE obj_Appwindow, Start_Window, Btree.Extract, Msg, Send_Info
DECLARE FUNCTION Get_Property, Get_Status, Dialog_Box, Utility, Send_Message, Popup, Collect.IXVals, Msg

EQU CRLF$	TO \0D0A\


EQU COL$CUST_NO		TO 1		;* Customer edit table column equates
EQU COL$CUST_NAME	TO 2


EQU LTGREY$		TO	229 + (229*256) + (229*65536)	;* JCH standard colors for edittable backgrounds
EQU GREY$		TO	192 + (192*256) + (192*65536)
EQU GREEN$		TO	192 + (220*256) + (192*65536)
EQU RED$		TO	255 + (128*256) + (128*65536)
EQU BLUE$		TO	128 + (255*256) + (255*65536)
EQU WHITE$		TO	255 + (255*256) + (255*65536)
EQU YELLOW$		TO	255 + (255*256) + (202*65536)
EQU LTBLUE$		TO	128 + (255*256) + (255*65536)
EQU PURPLE$		TO	225 + (181*256) + (255*65536)

EQU DTS_MULTIROW$	TO 512
EQU DTS_LARGEDATA$	TO 4096

$INSERT WM_OUT_EQUATES
$INSERT PS_EQUATES
$INSERT POPUP_EQUATES
$INSERT MSG_EQUATES

ErrTitle = 'Error in Comm_Dialog_Order_Find'
ErrorMsg = ''

Result = ''

BEGIN CASE
	CASE Method = 'Create'			; GOSUB Create
	CASE Method = 'CustChar'		; GOSUB CustChar
	CASE Method = 'CustPC'			; GOSUB CustPC
	CASE Method = 'CustDC'			; GOSUB CustDC
	CASE Method = 'CustPNDC'		; GOSUB CustPNDC
	CASE Method = 'SubPNDC'			; GOSUB SubPNDC
	CASE Method = 'LotNoDC'			; GOSUB LotNoDC
	CASE Method = 'PSNoDC'			; GOSUB PSNoDC
	CASE Method = 'WONoDC'			; GOSUB WONoDC
	CASE Method = 'LUDate'			; GOSUB LUDate
	CASE Method = 'Cancel'			; GOSUB Cancel
	CASE Method = 'Refresh'			; GOSUB Refresh
	CASE Method = 'PerformQuery'	; GOSUB PerformQuery
	CASE 1
		ErrMsg(ErrTitle:@SVM:'Unknown method ':QUOTE(Method):' passed to routine.')
		
END CASE

RETURN Result


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


obj_AppWindow('Create')

Set_Property(@WINDOW,'STATUSLINE',@WINDOW:'.STATUSLINE_FIX')

GOSUB Refresh

RETURN


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

* Turn edit table symbolic column backgrounds to green

stat = Send_Message(@WINDOW:'.CUST_INFO','COLOR_BY_POS',COL$CUST_NAME,0,GREEN$)	;* Turn names column all rows green

RETURN


* * * * * * *
CustChar:
* * * * * * *

CtrlName = @WINDOW:'.CUST_INFO'

CustArray	= Get_Property(CtrlName,'ARRAY')		;* Customer Information table
CurrPos		= Get_Property(CtrlName,'SELPOS')

CurrRow = CurrPos<2>

DataIn = CustArray<COL$CUST_NO,CurrRow>

IF LEN(DataIn) > 2 THEN

	ReturnToCtrl = CtrlName
	ReturnToPos  = CurrPos

	IF NOT(NUM(DataIn)) THEN 
		Set_Property(CtrlName,'CELLPOS','',CurrPos)	;* Clear characters input
		Start_Window('COMP_LOOKUP',@WINDOW,DataIn:@VM:'C':@FM:ReturnToCtrl:@FM:ReturnToPos,'','')
	END
END

RETURN


* * * * * * *
CustPC:
* * * * * * *

CtrlName = @WINDOW:'.CUST_INFO'

CustList = Get_Property(CtrlName,'LIST')		;* Customer Information table

CurrPos = Get_Property(CtrlName,'SELPOS')
CurrCol = CurrPos<1>
CurrRow = CurrPos<2>

CustNo = CustList<CurrRow,COL$CUST_NO>
IF CustNo NE '' THEN
	Set_Property(CtrlName,'CELLPOS',XLATE('COMPANY',CustNo,4,'X'),COL$CUST_NAME:@FM:CurrRow)
END

RETURN


* * * * * * *
CustDC:
* * * * * * *

CtrlName = @WINDOW:'.CUST_INFO'

CustList = Get_Property(CtrlName,'LIST')		;* Customer Information table

CurrPos = Get_Property(CtrlName,'SELPOS')
CurrCol = CurrPos<1>
CurrRow = CurrPos<2>

CustNo = CustList<CurrRow,COL$CUST_NO>
LineCnt = COUNT(CustList,@FM) + (CustList NE '')
IF CustNo = '' THEN
	CustNos = Popup(@WINDOW,'','CUSTOMER')
	CustCnt = COUNT(CustNos,@VM) + (CustNos NE '')
	IF CustCnt > LineCnt THEN
		FOR I = 1 TO CustCnt
			stat = Send_Message(CtrlName,'INSERT',-1,@VM:@FM)	; * Add blank lines
		NEXT I
	END
	
	FOR I = CurrRow TO CurrRow + CustCnt
		CustNo = CustNos<1,I>
		CustName = XLATE('COMPANY',CustNo,4,'X')
		Set_Property(CtrlName,'CELLPOS',CustNo,COL$CUST_NO:@FM:I)
		Set_Property(CtrlName,'CELLPOS',CustName,COL$CUST_NAME:@FM:I)
		Set_Property(CtrlName,'SELPOS',COL$CUST_NO:@FM:I+1)
	NEXT I
	
END ELSE
	ErrMsg('DoubleClick on the first empty Cust No field to view a popup of all Customers')
END
RETURN


* * * * * * *
SubPNDC:
* * * * * * *

CustArray = Get_Property(@WINDOW:'.CUST_INFO','ARRAY')<COL$CUST_NO>

CustNos = CustArray<COL$CUST_NO>

LOOP
	LastCustNo = CustNos[-1,'B':@VM]
UNTIL LastCustNo NE '' OR CustNos = ''
	CustNos[COL1(),99] = ''		;* Trim trailing blanks
REPEAT

IF CustNos = '' THEN RETURN

* display the processing message and do the processing

Def = ""
Def<MTEXT$> = "Selecting Substrate Part Numbers..."
Def<MTYPE$> = "U"

MsgUp = Msg(@window, Def)
OPEN 'DICT.WO_LOG' TO DictVar THEN
	SearchString  = 'CUST_NO':@VM:CustNos:@VM:@FM
	SearchString := 'SUB_PART_NO':@VM:'#':@FM
	
	Btree.Extract(SearchString, 'WO_LOG', DictVar, WOKeys, '', Flag)
	IF Get_Status(errCode) THEN
		Msg(@WINDOW,MsgUp)
		ErrMsg(errCode)
		RETURN
	END

	IF WOKeys NE '' THEN
		RawPartNos = XLATE('WO_LOG',WOKeys,'SUB_PART_NO','X')	;* Calculated field
		IF Get_Status(errCode) THEN DEBUG
		PartNos = ''
		FOR I = 1 TO COUNT(RawPartNos,@VM) + (RawPartNos NE '')
			RawPartNo = RawPartNos<1,I>
			LOCATE RawPartNo IN PartNos BY 'AL' USING @VM SETTING Pos ELSE
				PartNos = INSERT(PartNos,1,Pos,0,RawPartNo)
			END
		NEXT I
		
	END ELSE
		PartNos = ''
	END
	
	Msg(@WINDOW,MsgUp)
		
	IF PartNos = '' THEN
		ErrMsg('No Substrate Part Numbers on file for specified customer.')
		RETURN
	END
	
	PartNos := @VM
	CONVERT @VM TO @RM IN PartNos
	CALL V119('S','','D','R',PartNos,'')
	IF Get_Status(errCode) THEN DEBUG
	CONVERT @RM TO @VM IN PartNos
	PartNos[-1,1] = ''					;* Strip trailing delimiter	
	
	
	TypeOver = ''
	TypeOver<PDISPLAY$> = PartNos
	PartNos = Popup(@WINDow,TypeOver,'CUST_PO')	;****** Need a popup
	IF Get_Status(errCode) THEN DEBUG
	
	IF PartNos NE '' THEN
		Set_Property(@WINDOW:'.SUB_PART_NO','DEFPROP',PartNos)
	END
	
	
END ELSE
	ErrMsg('Unable to open DICT.WO_LOG in COMM_DIALOG_WO_LOG_FIND.')
END

RETURN


* * * * * * *
LotNoDC:
* * * * * * *


CustNos = Get_Property(@WINDOW:'.CUST_INFO','ARRAY')<COL$CUST_NO>

LOOP
	LastCustNo = CustNos[-1,'B':@VM]
UNTIL LastCustNo NE '' OR CustNos = ''
	CustNos[COL1(),99] = ''		;* Trim trailing blanks
REPEAT

IF CustNos = '' THEN RETURN

* display the processing message and do the processing

Def = ""
Def<MTEXT$> = "Selecting Lot Numbers..."
Def<MTYPE$> = "U"

MsgUp = Msg(@window, Def)
OPEN 'DICT.WO_LOG' TO DictVar THEN
	SearchString  = 'CUST_NO':@VM:CustNos:@VM:@FM
	SearchString := 'LOT_NO':@VM:'#':@FM
	
	Btree.Extract(SearchString, 'WO_LOG', DictVar, WOKeys, '', Flag)
	IF Get_Status(errCode) THEN
		Msg(@WINDOW,MsgUp)
		ErrMsg(errCode)
		RETURN
	END

	IF WOKeys NE '' THEN
		RawLotNos = XLATE('WO_LOG',WOKeys,'LOT_NO','X')	;* Calculated field
		IF Get_Status(errCode) THEN DEBUG
		LotNos = ''
		FOR I = 1 TO COUNT(RawLotNos,@VM) + (RawLotNos NE '')
			RawLotNo = RawLotNos<1,I>
			LOCATE RawLotNo IN LotNos BY 'AL' USING @VM SETTING Pos ELSE
				LotNos = INSERT(LotNos,1,Pos,0,RawLotNo)
			END
		NEXT I
		
	END ELSE
		LotNos = ''
	END
	
	Msg(@WINDOW,MsgUp)
		
	IF LotNos = '' THEN
		ErrMsg('No Lot Numbers on file for specified customer.')
		RETURN
	END
	
	LotNos := @VM
	CONVERT @VM TO @RM IN LotNos
	CALL V119('S','','D','R',LotNos,'')
	IF Get_Status(errCode) THEN DEBUG
	CONVERT @RM TO @VM IN LotNos
	LotNos[-1,1] = ''					;* Strip trailing delimiter	
	
	
	TypeOver = ''
	TypeOver<PDISPLAY$> = LotNos
	LotNos = Popup(@WINDow,TypeOver,'CUST_PO')	;****** Need a popup
	IF Get_Status(errCode) THEN DEBUG
	
	IF LotNos NE '' THEN
		Set_Property(@WINDOW:'.LOT_NO','DEFPROP',LotNos)
	END
	
	
END ELSE
	ErrMsg('Unable to open DICT.WO_LOG in COMM_DIALOG_WO_LOG_FIND.')
END



RETURN




* * * * * * *
PSNoDC:
* * * * * * *


CustArray = Get_Property(@WINDOW:'.CUST_INFO','ARRAY')

CustNos = CustArray<COL$CUST_NO>

LOOP
	LastCustNo = CustNos[-1,'B':@VM]
UNTIL LastCustNo NE '' OR CustNos = ''
	CustNos[COL1(),99] = ''		;* Trim trailing blanks
REPEAT

IF CustNos = '' THEN RETURN

* display the processing message and do the processing

Def = ""
Def<MTEXT$> = "Selecting Product Specifications..."
Def<MTYPE$> = "U"

MsgUp = Msg(@window, Def)
OPEN 'DICT.WO_LOG' TO DictVar THEN
	SearchString  = 'CUST_NO':@VM:CustNos:@VM:@FM
	SearchString := 'PS_NO':@VM:'#':@FM
	
	Btree.Extract(SearchString, 'WO_LOG', DictVar, WOKeys, '', Flag)
	IF Get_Status(errCode) THEN
		Msg(@WINDOW,MsgUp)
		ErrMsg(errCode)
		
		RETURN
	END

	IF WOKeys NE '' THEN
		PSNs = ''

		FOR N = 1 TO COUNT(WOKeys,@VM) + (WOKeys NE '')
			WOKey = WOKeys<1,N>
			RawPSNs = XLATE('WO_LOG',WOKey,'PS_NO','X')
		
			FOR I = 1 TO COUNT(RawPSNs,@VM) + (RawPSNs NE '')
				RawPSN = RawPSNs<1,I>
				
				LOCATE RawPSN IN PSNs BY 'AL' USING @VM SETTING Pos ELSE
					PSNs = INSERT(PSNs,1,Pos,0,RawPSN)
				END
				
			NEXT I

		NEXT N
	END ELSE
		PSNs = ''
	END
	
	Msg(@WINDOW,MsgUp)
		
	IF PSNs = '' THEN
		ErrMsg('No Product Specifications on file for specified customer.')
		RETURN
	END
	
	PSNs := @VM
	CONVERT @VM TO @RM IN PSNs
	CALL V119('S','','D','R',PSNs,'')
	IF Get_Status(errCode) THEN DEBUG
	CONVERT @RM TO @VM IN PSNs
	PSNs[-1,1] = ''					;* Strip trailing delimiter	
	
	
	TypeOver = ''
	TypeOver<PDISPLAY$> = PSNs
	PSNs = Popup(@WINDow,TypeOver,'CUST_PO')
	IF Get_Status(errCode) THEN DEBUG
	
	IF PSNs NE '' THEN
		CONVERT @VM TO @FM IN PSNs
		Set_Property(@WINDOW:'.PS_NO','LIST',PSNs)
	END
	
	
END ELSE
	ErrMsg('Unable to open DICT.WO_LOG in COMM_DIALOG_WO_LOG_FIND.')
END

RETURN


* * * * * * *
WONoDC:
* * * * * * *

WOKeys = Collect.IXVals('WM_OUT', 'WO_NO')

CONVERT @FM TO @VM IN WOKeys

IF Get_Status(errCode) THEN ErrMsg(ErrCode)

IF WOKeys NE '' THEN
	TypeOver = ''
	TypeOver<PDISPLAY$> = WOKeys
	TypeOver<PMODE$> = 'K'

	WOKeys = Popup(@WINDOW,TypeOver,'WO_LOG_QUERY')
	IF Get_Status(errCode) THEN
		ErrMsg(errCode)
	END
	
	IF WOKeys NE '' THEN
		CONVERT @VM TO @FM IN WOKeys
		Set_Property(@WINDOW:'.WO_NO','LIST',WOKeys)
	END
END
RETURN



* * * * * * *
CustPNDC:
* * * * * * *

CustArray = Get_Property(@WINDOW:'.CUST_INFO','ARRAY')

CustNos = CustArray<COL$CUST_NO>

LOOP
	LastCustNo = CustNos[-1,'B':@VM]
UNTIL LastCustNo NE '' OR CustNos = ''
	CustNos[COL1(),99] = ''		;* Trim trailing blanks
REPEAT

IF CustNos = '' THEN RETURN

* display the processing message and do the processing

Def = ""
Def<MTEXT$> = "Selecting Part Numbers..."
Def<MTYPE$> = "U"

MsgUp = Msg(@window, Def)
OPEN 'DICT.WO_LOG' TO DictVar THEN
	SearchString  = 'CUST_NO':@VM:CustNos:@VM:@FM
	SearchString := 'CUST_PART_NO':@VM:'#':@FM
	
	Btree.Extract(SearchString, 'WO_LOG', DictVar, WOKeys, '', Flag)
	IF Get_Status(errCode) THEN
		Msg(@WINDOW,MsgUp)
		ErrMsg(errCode)
		RETURN
	END

	IF WOKeys NE '' THEN
		PartNos = ''
		FOR N = 1 TO COUNT(WOKeys,@VM) + (WOKeys NE '')
			WOKey = WOKeys<1,N>
				RawPartNos = XLATE('WO_LOG',WOKey,'PART_NO','X')
				FOR I = 1 TO COUNT(RawPartNos,@VM) + (RawPartNos NE '')
					RawPartNo = RawPartNos<1,I>
					
					LOCATE RawPartNo IN PartNos BY 'AL' USING @VM SETTING Pos ELSE
						PartNos = INSERT(PartNos,1,Pos,0,RawPartNo)
					END
				NEXT I

		NEXT N
	END ELSE
		PartNos = ''
	END
	
	Msg(@WINDOW,MsgUp)
		
	IF PartNos = '' THEN
		ErrMsg('No Customer Part Numbers on file for specified customer.')
		RETURN
	END
	
	PartNos := @VM
	CONVERT @VM TO @RM IN PartNos
	CALL V119('S','','D','R',PartNos,'')
	IF Get_Status(errCode) THEN DEBUG
	CONVERT @RM TO @VM IN PartNos
	PartNos[-1,1] = ''					;* Strip trailing delimiter	
	
	
	TypeOver = ''
	TypeOver<PDISPLAY$> = PartNos
	PartNos = Popup(@WINDow,TypeOver,'CUST_PO')		;* Needs a popup
	IF Get_Status(errCode) THEN DEBUG
	
	IF PartNos NE '' THEN
		Set_Property(@WINDOW:'.CUST_PART_NO','DEFPROP',PartNos)
	END
	
END ELSE
	ErrMsg('Unable to open DICT.WO_LOG in COMM_DIALOG_WO_LOG_FIND.')
END

RETURN



* * * * * * *
LUDate:
* * * * * * *

ReturnCtrl = Parm1[1,@RM]

IF ReturnCtrl = '' THEN ReturnCtrl = Get_Property(@WINDOW,'FOCUS')

DateSelected =  Dialog_Box('POPUP_YEAR',@WINDOW)

RetVal = OCONV(DateSelected, 'D4/')

IF RetVal NE '' THEN
	obj_Appwindow('LUValReturn',RetVal:@RM:ReturnCtrl)
END

RETURN


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

RETURN



* * * * * * *
PerformQuery:
* * * * * * *
If @USER4 EQ 'DANIEL_ST' then debug
* Customer numbers *

SearchString = 'MAKEUP_BOX':@VM:'0':@FM

CustNos = Get_Property(@WINDOW:'.CUST_INFO','ARRAY')<COL$CUST_NO>

LOOP
	LastVar = CustNos[-1,'B':@VM]
UNTIL LastVar NE '' OR CustNos = ''
	CustNos[COL1(),99] = ''		;* Trim trailing blanks
REPEAT

IF CustNos NE '' THEN SearchString := 'CUST_NO':@VM:CustNos:@FM			

* LotNumbers *

LotNos = Get_Property(@WINDOW:'.LOT_NO','ARRAY')<1>

LOOP
	LastVal = LotNos[-1,'B':@VM]
UNTIL LastVal NE '' OR LotNos = ''
	LotNos[COL1(),99] = ''		;* Trim trailing blanks
REPEAT

IF LotNos NE '' THEN SearchString := 'LOT_NO':@VM:LotNos:@FM


* Cust Part Number *

CustPNs = Get_Property(@WINDOW:'.CUST_PART_NO','ARRAY')<1>

LOOP
	LastVal = CustPNs[-1,'B':@VM]
UNTIL LastVal NE '' OR CustPNs = ''
	CustPNS[COL1(),99] = ''		;* Trim trailing blanks
REPEAT

IF CustPNs NE '' THEN SearchString := 'CUST_PART_NO':@VM:CustPNs:@FM

* Substrate Part Numbers *

SubPartNos = Get_Property(@WINDOW:'.SUB_PART_NO','ARRAY')<1>

LOOP
	LastVal = SubPartNos[-1,'B':@VM]
UNTIL LastVal NE '' OR SubPartNos = ''
	SubPartNos[COL1(),99] = ''		;* Trim trailing blanks
REPEAT

IF SubPartNos NE '' THEN SearchString := 'SUB_PART_NO':@VM:SubPartNos:@FM

* PSN Nos *

PS_NOs = Get_Property(@WINDOW:'.PS_NO','ARRAY')<1>

LOOP
	LastVal = PS_NOs[-1,'B':@VM]
UNTIL LastVal NE '' OR PS_NOs = ''
	PS_NOs[COL1(),99] = ''		;* Trim trailing blanks
REPEAT

IF PS_NOs NE '' THEN SearchString := 'PS_NO':@VM:PS_NOs:@FM


* WO Nos *

WO_NOs = Get_Property(@WINDOW:'.WO_NO','ARRAY')<1>

LOOP
	LastVal = WO_NOs[-1,'B':@VM]
UNTIL LastVal NE '' OR WO_NOs = ''
	WO_NOs[COL1(),99] = ''		;* Trim trailing blanks
REPEAT

IF WO_NOs NE '' THEN SearchString := 'WO_NO':@VM:WO_NOs:@FM

* Entry Dates *

StartDt = ICONV(Get_Property(@WINDOW:'.START_DT','TEXT'),'D')
EndDt	= ICONV(Get_Property(@WINDOW:'.END_DT','TEXT'),'D')

BEGIN CASE
	CASE StartDt NE '' AND EndDt = ''
		SearchString := 'SUP_VER_SIG_DT':@VM:'>=':OConv(StartDt, 'D4/'):@FM
	
	CASE StartDt = '' AND EndDt NE ''
		SearchString := 'SUP_VER_SIG_DT':@VM:'<=':OConv(EndDt, 'D4/'):@FM
	
	CASE StartDt NE '' AND EndDt NE ''
		* Fudge the dates - '~' is not inclusive of the end dates
		StartDt -= 1
		EndDt += 1
		SearchString := 'SUP_VER_SIG_DT':@VM:OConv(StartDt, 'D4/'):'~':OConv(EndDt, 'D4/'):@FM
		
	CASE 1
		NULL
END CASE


OPEN 'DICT.WM_OUT' TO DictVar THEN
	Def = ""
	Def<MTEXT$> = "Selecting WM_OUT Recrods..."
	Def<MTYPE$> = "U"

	* display the processing message and do the processing

	MsgUp = Msg(@window, Def)
	
	Btree.Extract(SearchString,'WM_OUT',DictVar,WMOKeys,'',flag)
	IF Get_Status(errCode) THEN ErrMsg(errCode)
	
	Msg(@window, MsgUp)
	IF Get_Status(errCode) THEN
		ErrMsg(errCode)
		RETURN
	END
	
	End_Dialog(@WINDOW,WMOKeys)

END ELSE
	ErrMsg('Unable to open DICT.WM_OUT in routine COMM_DIALOG_EPIPRO_EXPORT')
END

RETURN



