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

/*
	Commuter module for WO_Mat_Inv window
	
	3/4/2013 - John C. Henry, J.C. Henry & Co., Inc.
*/

DECLARE SUBROUTINE Set_Property, End_Dialog, Send_Event, Set_Status, Center_Window, Post_Event, obj_WO_Mat, obj_WO_Log
DECLARE SUBROUTINE ErrMsg, Send_Message, Set_Property, Send_Event, Btree.Extract, obj_AppWindow, obj_WO_Mat_Log, obj_WM_Out
DECLARE SUBROUTINE obj_Notes, Security_Err_Msg, End_Window, Forward_Event, Start_Window, Create_Note, Print_SAP_Cass_Ship_Label

DECLARE FUNCTION Get_Property, Get_Status, Dialog_Box, Utility, Popup, Collect.Ixvals
DECLARE FUNCTION Send_Message, Msg, Security_Check, Select_Into, obj_WM_Out



$INSERT MSG_EQUATES
$INSERT APPCOLORS
$INSERT LSL_USERS_EQU
$INSERT SECURITY_RIGHTS_EQU
$INSERT WO_LOG_EQUATES
$INSERT WO_MAT_EQUATES
$INSERT REACT_RUN_EQUATES
$INSERT POPUP_EQUATES
$INSERT RTI_STYLE_EQUATES
$INSERT WM_OUT_EQUATES

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

EQU COL$TIME_STAMP		TO 1
EQU COL$WH_CD			TO 2
EQU COL$WAREHOUSE		TO 3
EQU COL$LOC_CD			TO 4
EQU COL$LOCATION		TO 5
EQU COL$ACTION			TO 6
EQU COL$USER_ID			TO 7
EQU COL$TAG				TO 8
EQU COL$TOOL_ID			TO 9
EQU COL$TIME_AT_STEP	TO 10


EQU COL$SIG_CODE		TO 1
EQU COL$SIGNATURE		TO 2
EQU COL$SIG_DTM			TO 3
EQU COL$SIG_VER			TO 4

ErrTitle = 'Error in WO_MAT_INV'
ErrorMsg = ''

Result = ''


BEGIN CASE
	CASE EntID = @WINDOW
		BEGIN CASE
			CASE Event = 'CLEAR'			; GOSUB Clear
			CASE Event = 'CREATE' 			; GOSUB Create
			CASE Event = 'CLOSE'			; GOSUB Close
			CASE Event = 'READ'				; GOSUB Read
			CASE Event = 'WRITE'			; GOSUB Write
			CASE Event[1,3] = 'QBF'			; GOSUB Refresh
		END CASE
		
	CASE EntID = @WINDOW:'.CASS_NO' AND EVENT = 'GOTFOCUS'			; GOSUB LUCassNo
	CASE EntID = @WINDOW:'.LOG_DTM' AND EVENT = 'GOTFOCUS'			; GOSUB CurrDTM
	CASE EntID = @WINDOW:'.LOG_ACTION' AND EVENT = 'GOTFOCUS'		; GOSUB ActionGF
	CASE EntID = @WINDOW:'.ADD_INV_TRANS' AND EVENT = 'CLICK'		; GOSUB AddInvTrans
	CASE EntID = @WINDOW:'.REMOVE_WM_OUT' AND EVENT = 'CLICK'		; GOSUB RemoveWMOut
	
	CASE EntID = @WINDOW:'.INV_WH' AND EVENT = 'DELETEROW'			; GOSUB InvDelRow
	
	CASE 1
		DEBUG
		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',@WINDOW)

* Set result table special styles (Dropdowns)


GOSUB Refresh

RETURN


* * * * * * *
Clear:
* * * * * * *


IF Get_Property(@WINDOW,'@READONLY') THEN
	obj_AppWindow('ReadOnly',@RM:1)			;* Reenables data bound controls
	Set_Property(@WINDOW,'@READONLY',0)		;* Clear flag on window
END


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

WMOKey = Get_Property(@WINDOW:'.WMO_KEY','TEXT')

Ctrls  = @WINDOW:'.WMO_KEY_LABEL':@RM		; Props  = 'VISIBLE':@RM
Ctrls := @WINDOW:'.WMO_KEY':@RM				; Props := 'VISIBLE':@RM
Ctrls := @WINDOW:'.REMOVE_WM_OUT'			; Props := 'VISIBLE'


IF WMOKey NE '' THEN
	Vals = '1':@RM:'1':@RM:'1'
	Set_Property(Ctrls,Props,Vals)
END ELSE
	Vals = '0':@RM:'0':@RM:'0'
END




* Turn edit table symbolic column backgrounds to green **************************************************

ETSymbolics = Get_Property(@WINDOW,'@ET_SYMBOLICS')		;* Loaded during 'Create' in obj_Appwindow

ETCtrls	= ETSymbolics<1>
ETCols	= ETSymbolics<2>

FOR I = 1 TO COUNT(ETCtrls,@VM) + (ETCtrls NE '')
	ETCtrl	= ETCtrls<1,I>
	ETList = Get_Property(ETCtrl,'LIST')
	FOR Line = 1 TO COUNT(ETList,@FM) + (ETList NE '')
		IF ETList<Line,1> NE '' THEN
			FOR N = 1 TO COUNT(ETCols<1,I>,@SVM) + (ETCols<1,I> NE '')
				stat = Send_Message(ETCtrl,'COLOR_BY_POS',ETCols<1,I,N>,Line,GREEN$)
			NEXT N
		END
	NEXT I
NEXT I

RETURN





* * * * * * *
LUCassNo:
* * * * * * *

WONo = Get_Property(@WINDOW:'.WO_NO','DEFPROP')
CassNo = Get_Property(@WINDOW:'.CASS_NO','DEFPROP')

IF WONo NE '' AND CassNo = '' THEN

	TypeOver = ''
	TypeOver<PDISPLAY$> = 'WITH WO_NO = ':WONo:' BY CASS_NO'
	TypeOver<PFIELD$>	= 2		;* Cass No(s)
	PopupLines = POPUP(@WINDOW,TypeOver,'WO_MAT_FIXIT')
	
	IF PopupLines = '' THEN RETURN
	
	
	IF INDEX(PopupLines,@FM,1) THEN
		LineCnt = COUNT(PopupLines,@FM) + (PopupLines NE '')
		
		WOMatKeys = ''
		
		FOR I = 1 TO LineCnt
			WOMatKeys<1,-1> = WONo:'*':PopupLines<I,2>
		NEXT I
		
		Send_Event(@WINDOW,'QBFINIT')
		Set_Property(@WINDOW,'QBFLIST',WOMatKeys)
		GOSUB Refresh
		Send_Event(@WINDOW,'QBFIRST')
	END ELSE
		CassNo = PopupLines<1,2>
		Set_Property(@WINDOW:'.CASS_NO','DEFPROP',CassNo)
		Send_Event(@WINDOW:'.CASS_NO','LOSTFOCUS')
	END
END

RETURN




* * * * * * *
Read:
* * * * * * *

GOSUB Refresh

RETURN


* * * * * * *
Write:
* * * * * * *
	
ParentWindow = Get_Property(@WINDOW,'PARENT')

IF ParentWindow = 'WO_MAT' THEN 

	ParentWindow = Get_Property(@WINDOW,'PARENT')
	ParentKey = Get_Property(@WINDOW,'@RETURNKEY')

	obj_AppWindow('LoadFormKeys',ParentWindow:@RM:ParentKey)

	Post_Event(@WINDOW,'CLOSE')
END

RETURN



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


RETURN


* * * * * * *
CurrDTM:
* * * * * * *

CurrDtm = OCONV(Date(),'D4/'):' ':OCONV(Time(),'MTS')

Set_Property(@WINDOW:'.LOG_DTM','DEFPROP',CurrDTM)
Set_Property(@WINDOW:'.LOG_DTM','SELECTION',1:@FM:Len(CurrDTM))

RETURN


* * * * * * * 
InvDelRow:
* * * * * * *

CtrlEntID = Get_Property(@WINDOW,'FOCUS')

DelRowNo	= Parm1
DelRowData	= Parm2

Action = DelRowData<1,COL$ACTION>

IF NUM(Action[1,1]) THEN

	MsgHead	= 'Signature Removal'
	MsgText	= 'Do you wish to remove the signature for the ':Action:' step in the signature profile.'

	OK = Msg(@WINDOW,'','YESNO','',MsgHead:@FM:MsgText)

	IF OK = 1 THEN
		SigProfileArray = Get_Property(@WINDOW:'.SIG_PROFILE','ARRAY')
	
		LOCATE Action IN SigProfileArray<COL$SIG_CODE> USING @VM SETTING Pos THEN
			SigProfileArray<COL$SIGNATURE,Pos>	= ''
			SigProfileArray<COL$SIG_DTM,Pos>	= ''
			SigProfileArray<COL$SIG_VER,Pos>	= ''
			
			Set_Property(@WINDOW:'.SIG_PROFILE','DEFPROP',SigProfileArray)
		END
	END
END
	

RETURN


* * * * * * *
ActionGF:
* * * * * * *

MUBox		= Get_Property(@WINDOW:'.MAKEUP_BOX','CHECK')
EpoMUBox	= Get_Property(@WINDOW:'.EPO_MAKEUP_BOX','CHECK')

PopupID = @APPID<1>:'**':'WO_MAT_INV_ACTION'

PopupLiteral = XLATE('SYSREPOSPOPUPS',PopupID,PDISPLAY$,'X')

plCnt = COUNT(PopupLiteral,@VM) + (PopupLiteral NE '')

TypeOver = ''

FOR I = 1 TO plCnt
	IF MUBox OR EpoMUBox THEN
		IF PopupLiteral<1,I,1> = 'EMPTY' OR PopupLiteral<1,I,1> = 'REJ' OR PopupLiteral<1,I,1> = 'RTU' OR PopupLiteral<1,I,1> = 'MU_USE' OR PopupLiteral<1,I,1> = 'DELETE' THEN
			TypeOver<PDISPLAY$,-1> = PopupLiteral<1,I>
		END
	END ELSE
		IF PopupLiteral<1,I,1> = 'SHIP' OR PopupLiteral<1,I,1> = 'REJ'  OR PopupLiteral<1,I,1> = 'PLACE' OR PopupLiteral<1,I,1> = 'LOAD' OR PopupLiteral<1,I,1> = 'UNLOAD' OR PopupLiteral<1,I,1> = 'VER' OR PopupLiteral<1,I,1> = 'PSTS' OR PopupLiteral<1,I,1> = 'DELETE' OR PopupLiteral<1,I,1>[1,4] = 'HOLD' THEN
			TypeOver<PDISPLAY$,-1> = PopupLiteral<1,I>
		END
	END
	
NEXT I

TypeOver := @VM:'HOLD_ON':@SVM:'Hold On':@VM:'HOLD_OFF':@SVM:'Hold Off'

Action = Popup(@WINDOW,TypeOver,'WO_MAT_INV_ACTION')

BEGIN CASE

	CASE Action = 'DELETE'
		WHCd	= 'CR'
		LocCd	= 'QA'
		CurrDtm = OCONV(Date(),'D4/'):' ':OCONV(Time(),'MTS')	;* Add 1800 seconds (1 Hour) to the timestamp for reporting system. - OCONV(Time() + 1800 ,'MTS') Per Dave Klotz 6/20/2014
		
		Set_Property(@WINDOW:'.LOG_DTM','DEFPROP',CurrDTM)
		
	*CASE Action = '1QA'		;*IF EpiPro - use 1MO_QA  -dkk 10/21/14
		*WHCd = 'CR'
		*LocCd = 'QA'		
	
	CASE Action = 'REJ'
		WHCd = 'CR'
		LocCd = 'QA'
		
	CASE Action = 'SHIP'
		WHCd = 'SR'
		LocCd = 'SB'
		
		Tags = Get_Property(@WINDOW:'.INV_WH','ARRAY')<8>

		LOOP
			Tag = Tags<1,1>
		UNTIL Tag NE '' OR Tags = ''
			Tags = Delete(Tags,1,1,0)
		REPEAT
		
		Set_Property(@WINDOW:'.LOG_TAG','TEXT',Tag)
		
		
	CASE Action = 'EMPTY'
		WHCd = 'CR'
		LocCd = 'MU'
		
	CASE Action = 'RTU'
		WHCd = 'CR'
		LocCd = 'MU'
		
	CASE Action = 'MU_USE'
		WHCd = 'CR'
		LocCd = 'MU'
		
	CASE Action = 'PLACE'
	
		Tags = Get_Property(@WINDOW:'.INV_WH','ARRAY')<8>
		TagCnt = COUNT(Tags,@VM) + (Tags NE '')
		
		FOR I = TagCnt TO 1 STEP -1
			Tag = Tags<1,I>
		UNTIL Tag NE ''
			
		NEXT I
		
		Set_Property(@WINDOW:'.LOG_TAG','TEXT',Tag)
		
	CASE 1
		WHCd = ''
		LocCd = ''
		
END CASE

Set_Property(@WINDOW:'.LOG_WH_CD','TEXT',WHCd)
Set_Property(@WINDOW:'.WH_CD_DESC','TEXT',XLATE('WAREHOUSE',WHCd,1,'X'))

Set_Property(@WINDOW:'.LOG_LOC_CD','TEXT',LocCd)
Set_Property(@WINDOW:'.LOC_CD_DESC','TEXT',XLATE('LOCATION',WHCd:'*':LocCd,1,'X'))

obj_AppWindow('LUValReturn',Action:@RM:@WINDOW:'.LOG_ACTION')


RETURN

* * * * * * *
AddInvTrans:
* * * * * * *

InvDTM	= Get_Property(@WINDOW:'.LOG_DTM','TEXT')
Action	= Get_Property(@WINDOW:'.LOG_ACTION','TEXT')
WhCd	= Get_Property(@WINDOW:'.LOG_WH_CD','TEXT')
LocCd	= Get_Property(@WINDOW:'.LOG_LOC_CD','TEXT')
WONo	= Get_Property(@WINDOW:'.WO_NO','TEXT')
CassNo	= Get_Property(@WINDOW:'.CASS_NO','TEXT')
UserID	= @USER4
Tag		= Get_Property(@WINDOW:'.LOG_TAG','TEXT')



Send_Event(@WINDOW,'WRITE')

CheckWOMat = XLATE('WO_MAT',WONo:'*':CassNo,'','X')

CONVERT @FM:@VM TO '' IN CheckWOMat

IF CheckWOMat = '' OR CheckWOMat<WO_MAT_WMO_KEY$> = WONo:'*1*':CassNo THEN

	LastSlotUsed = 25
	obj_WO_Mat('CreateWMO',WONo:@RM:CassNo:@RM:LastSlotUsed)		;* Creates "shell" WO_MAT record with the signature profile in it.
	errCode      = ''
	IF Get_Status(errCode) THEN DEBUG
END

obj_WO_Log('AddCassNo',WONo:@RM:CassNo)
	
IF Get_Status(errCode) THEN DEBUG


ScanToolID = ''
Set_Status(0)
aiParms	= 'WO_MAT':@RM:WONo:@RM:CassNo:@RM:WhCd:'*':LocCd:@RM:Action:@RM:InvDTM:@RM:UserID:@RM:Tag:@RM:ScanToolID
obj_WO_Mat('AddInvTrans',aiParms)

IF Get_Status(errCode) THEN
	ErrMsg(errCode)
	RETURN
END

obj_Appwindow('LoadFormKeys',@WINDOW:@RM:WONo:'*':CassNo)

RETURN




* * * * * * *
RemoveWMOut:
* * * * * * *

WONo = Get_Property(@WINDOW:'.WO_NO','DEFPROP')
CassNo = Get_Property(@WINDOW:'.CASS_NO','DEFPROP')

IF WONo = '' THEN RETURN
IF CassNo = '' THEN RETURN

* Check for the last WMO_OUT key

WORec		= XLATE('WO_LOG',WONo,'','X')
WOMatKeys	= WORec<WO_LOG_WO_MAT_KEY$>

WMOutKeys = XLATE('WO_MAT',WOMatKeys,WO_MAT_WMO_KEY$,'X')	;* Get all WM_OUT keys in work order

LastWMOKey = WMOutKeys[-1,'B':@VM]

LastCassNo = LastWMOKey[-1,'B*']

IF CassNo NE LastCassNo THEN
	ErrMsg('This is not the last WM_OUT cassette on this work order.':CRLF$:'Last WM_OUT Key is: ':LastWMOKey)
	RETURN
END

CurrWMOutKey = WONo:'*1*':CassNo

WMORec = XLATE('WM_OUT',CurrWMOutKey,'','X')
WMO_RdsNos		= WMORec<WM_OUT_RDS$>
WMO_NCRNos		= WMORec<WM_OUT_SLOT_NCR$>
WMO_UMWCassIDs	= WMORec<WM_OUT_UMW_CASS_ID$>
CONVERT @VM TO '' IN WMO_RdsNos
CONVERT @VM TO '' IN WMO_NCRNos
CONVERT @VM TO '' IN WMO_UMWCassIDs
		
IF WMO_RdsNos = '' AND WMO_NCRNos = '' AND WMO_UMWCassIDs = '' ELSE
	ErrMsg('This cassette has started processing.')
	RETURN
END


MsgHead	= 'WM_OUT Record Removal'
MsgText	= 'Do you wish to remove WM_OUT record ':CurrWMOutKey:' attached to this WO_MAT record?.'

OK = Msg(@WINDOW,'','YESNO','',MsgHead:@FM:MsgText)


IF OK = 1 THEN

	Send_Event(@WINDOW,'WRITE')
	
	Set_Status(0)
	obj_WM_Out('Delete',CurrWMOutKey)

	IF Get_Status(errCode) THEN
		ErrMsg(errCode)
	END
	
	obj_Appwindow('LoadFormKeys',@WINDOW:@RM:WONo:'*':CassNo)
	
END

RETURN




