COMPILE FUNCTION Comm_Dialog_WO_Due_In(Method, Parm1)

/*
	Commuter module for Dialog_WO_Due_In window.
	
	05/18/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 WO_LOG_EQU
$INSERT ORDER_DET_EQU
$INSERT PS_EQUATES
$INSERT POPUP_EQUATES
$INSERT LOGICAL
$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 = 'LotNoDC'			; GOSUB LotNoDC
	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




* * * * * * *
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.ORDER_DET' TO DictVar THEN
	SearchString  = 'CUST_NO':@VM:CustNos:@VM:@FM
	SearchString := 'CUST_LOT_NO':@VM:'#':@FM
	
	Btree.Extract(SearchString, 'ORDER_DET', DictVar, OrdDetKeys, '', Flag)
	IF Get_Status(errCode) THEN
		Msg(@WINDOW,MsgUp)
		ErrMsg(errCode)
		RETURN
	END
	
	
	RETURN
	IF OrdDetKeys 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




* * * * * * *
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



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

RETURN



* * * * * * *
PerformQuery:
* * * * * * *


* Customer numbers *


SearchString = ''

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 := 'CUST_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_PN':@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

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

	* display the processing message and do the processing

	MsgUp = Msg(@window, Def)

	Btree.Extract(SearchString,'ORDER_DET',DictVar,OrderDetKeys,'',flag)
	IF Get_Status(errCode) THEN ErrMsg(errCode)
	
	Msg(@window, MsgUp)
	IF Get_Status(errCode) THEN
		ErrMsg(errCode)
		RETURN
	END
	
	IF OrderDetKeys NE '' THEN
		IF INDEX(OrderDetKeys,@VM,1) THEN
			TypeOver = ''
			TypeOver<PDISPLAY$> = OrderDetKeys
			TypeOver<PMODE$> = 'K'
			TypeOver<PSELECT$> = 2	;* Multiple selection allowed
			TypeOver<PTYPE$> = 'K'
			
			OrderDetKeys = Popup(@WINDOW,TypeOver,'ORDER_DETAIL')
			
			IF Get_Status(errCode) THEN ErrMsg(errCode)
			
			DisplayList = ''
			LineCnt = 1
			FOR I = 1 TO COUNT(OrderDetKeys,@VM) + (OrderDetKeys NE '')
				OrderDetKey 	= OrderDetKeys<1,I>
				OrderDetRec 	= XLATE('ORDER_DET',OrderDetKey,'','X')
				OrderNo			= OrderDetKey[1,'*']	;* Order No
				OrderItem		= FIELD(OrderDetKey,'*',2)
				OrderItemDesc	= OrderDetRec<ORDER_DET_ITEM_DESC$>
				CustPartNo		= OrderDetRec<ORDER_DET_CUST_PN$>
				WONo = OrderDetRec<ORDER_DET_WO_NO$>
				CustLotNos = OrderDetRec<ORDER_DET_CUST_LOT_NO$>
				FOR N = 1 TO COUNT(CustLotNos,@VM) + (CustLotNos NE '')
					DisplayList<LineCnt,1> = WONo
					DisplayList<LineCnt,2> = CustLotNos<1,N>
					DisplayList<LineCnt,3> = CustPartNo
					DisplayList<LineCnt,4> = OrderNo
					DisplayList<LineCnt,5> = OrderItem
					DisplayList<LineCnt,6> = OrderItemDesc
					LineCnt += 1
				NEXT N
			NEXT I
			IF DisplayList = '' THEN
				ErrMsg('Selected Order Items are missing Customer Lot information.')
				End_Dialog(@WINDOW,'')
			END
			CONVERT @VM:@FM TO @SVM:@VM IN DisplayList
			
			TypeOver = ''
			TypeOver<PDISPLAY$> = DisplayList
			WONo = PopUp(@WINDOW,TypeOver,'WO_LOTS_DUE_IN')
			IF Get_Status(errCode) THEN
				ErrMsg(errCode)
			END
		END ELSE
			WONo = XLATE('ORDER_DET',OrderDetKeys,ORDER_DET_WO_NO$,'X')
		END
		
	END ELSE
		ErrMsg('No Work Orders with Material Due In found for specified Orders')
		WONo = ''
	END

	End_Dialog(@WINDOW,WONo)

END ELSE
	ErrMsg('Unable to open DICT.ORDER_DET in routine COMM_DIALOG_WO_LOG_FIND')
	End_Dialog(@WINDOW,'')
END

RETURN




