COMPILE FUNCTION COMM_SAP_Shipment(Instruction, Parm1,Parm2)
#pragma precomp SRP_PreCompiler

/*
	Commuter module for SAP_Shipment (COC) window
	
	09/09/2011 - John C. Henry, J.C. Henry & Co., Inc.
*/

DECLARE SUBROUTINE Set_Property, End_Dialog, Send_Event, Set_Status, Center_Window, Post_Event, Set_List_Box_Data, Print_Shipment, Print_Carton_Labels
DECLARE SUBROUTINE ErrMsg, Send_Message, Set_Property, Send_Event, Btree.Extract, obj_AppWindow, obj_Shipment, Print_Ship_CheckList,Print_Pallet_Labels
DECLARE SUBROUTINE obj_Notes, Security_Err_Msg, End_Window, Forward_Event, Start_Window,Print_SAP_Cass_Ship_Label, Print_COC_Back, Print_Packing_Slip, Print_CoC_Invoice
DECLARE SUBROUTINE obj_Invoice, obj_Export, Print_Comm_Invoice
DECLARE FUNCTION Get_Property, Get_Status, Dialog_Box, Utility, Center_Window, Popup, Collect.Ixvals, obj_RDS, ETMethod, Export_Tower_Met, Export_IR
DECLARE FUNCTION Send_Message, Msg, Security_Check, RowExists, NextKey, obj_Shipment, obj_WO_Log, Set_Printer, obj_Install, MemberOf

$INSERT POPUP_EQUATES
$INSERT LOGICAL
$INSERT MSG_EQUATES
$INSERT APPCOLORS
$INSERT COC_EQUATES
$INSERT LSL_USERS_EQU
$INSERT SECURITY_RIGHTS_EQU
$INSERT WO_LOG_EQU
$INSERT WO_STEP_EQU
$INSERT COMPANY_EQU
$INSERT ORDER_EQU
$INSERT OIPRINT_EQUATES

EQU COL$WO_STEP			TO 1
EQU COL$CASS_NO			TO 2
EQU COL$RDS_NO			TO 3
EQU COL$SAP_BATCH_NO	TO 4
EQU COL$RDS_LOT_NO		TO 5
EQU COL$RDS_PART_NO		TO 6
EQU COL$RDS_SCHED		TO 7
EQU COL$RDS_PTEST		TO 8
EQU COL$RDS_REJECT		TO 9
EQU COL$RDS_OUT			TO 10
EQU COL$RDS_HOT_LOT		TO 11
EQU COL$RDS_CURR_STATUS	TO 12	;* OCONV'd status
EQU COL$RDS_STAT_CD		TO 13	;* Internal status

EQU PI$LEFT		TO 1		;* Page info stuff until I can get the printing routines cleaned up
EQU PI$TOP		TO 2
EQU PI$RIGHT	TO 3
EQU PI$BOTTOM	TO 4
EQU PI$WIDTH	TO 5
EQU PI$HEIGHT	TO 6
EQU PI$SIZE		TO 7

ErrTitle = 'Error in Comm_Shipment'
ErrorMsg = ''

Result = ''

BEGIN CASE
	CASE Instruction = 'Create' 			; GOSUB Create
	CASE Instruction = 'Refresh'			; GOSUB Refresh
	CASE Instruction = 'Read'				; GOSUB Read
	CASE Instruction = 'Write'				; GOSUB Write
	CASE Instruction = 'Clear'				; GOSUB Clear
	CASE Instruction = 'Delete'				; GOSUB Delete
	CASE Instruction = 'Page'				; GOSUB Page
	CASE Instruction = 'Close'				; GOSUB Close
	CASE Instruction = 'LUShipNo'			; GOSUB LUShipNo
	CASE Instruction = 'ShipNoLF'			; GOSUB ShipNoLF
	CASE Instruction = 'ShippingWOS'		; GOSUB ShippingWOS
	CASE Instruction = 'NewShipment'		; GOSUB NewShipment
	CASE Instruction = 'TodaysShipments'	; GOSUB TodaysShipments
	CASE Instruction = 'ActiveShipments'	; GOSUB ActiveShipments
	
	CASE Instruction = 'LUShipVia'			; GOSUB LUShipVia
	CASE Instruction = 'ShipViaGF'			; GOSUB ShipViaGF
	CASE Instruction = 'WONoLF'				; GOSUB WONoLF
	CASE Instruction = 'RDSDetailDC'		; GOSUB RDSDetailDC
	CASE Instruction = 'SelectCassettes'	; GOSUB SelectCassettes
	CASE Instruction = 'ScanCassettes'		; GOSUB ScanCassettes
	CASE Instruction = 'Pick'				; GOSUB Pick
	CASE Instruction = 'Unpick'				; GOSUB Unpick
	CASE Instruction = 'ViewCustomer'		; GOSUB ViewCustomer
	
	CASE Instruction = 'ViewWO'	;			; GOSUB ViewWO
	CASE Instruction = 'PrintCassLabel'		; GOSUB PrintCassLabel
	CASE Instruction = 'PrintCheck'			; GOSUB PrintCheck
	CASE Instruction = 'PrintPackingList'	; GOSUB PrintPackingList
	CASE Instruction = 'PrintDocuments'		; GOSUB PrintDocuments
	
	CASE Instruction = 'PrintCoCInvoice'	; GOSUB PrintCoCInvoice
	CASE Instruction = 'PrintCommInvoice'	; GOSUB PrintcommInvoice
	
	CASE Instruction = 'TxTechData'			; GOSUB TxTechData
	
	CASE Instruction = 'Repost'				; GOSUB Repost
	
	CASE 1
		ErrorMsg = 'Unknown Instruction ':QUOTE(Instruction):' passed to routine.'
		ErrMsg(ErrorMsg)
END CASE

RETURN Result



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

IF NOT(Security_Check('COC',READ$)) THEN
	Security_Err_Msg('COC',READ$)
	End_Window(@WINDOW)
	RETURN
END

obj_Appwindow('Create',@WINDOW)

*Set_List_Box_Data(@WINDOW)

* Provides compatibility with the existing messaging attachment system

IF Parm1 NE '' THEN
	PassedKeys = FIELD(Parm1,'*',1)
	obj_Appwindow('ViewRelated',@WINDOW:@RM:PassedKeys)
END

GOSUB Refresh

RETURN


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

Send_Event(@WINDOW,'PAGE',1)


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


IF MemberOf(@USER4, 'SAP_ADMIN') THEN
	Set_Property(@WINDOW:'.REPOST_BUTTON','VISIBLE',1)
END ELSE
	Set_Property(@WINDOW:'.REPOST_BUTTON','VISIBLE',0)
END

IF Security_Check('COC',EDIT$) AND (Get_Property(@WINDOW:'.PICK_BUTTON','TEXT') = 'Pick') THEN
	Set_Property(@WINDOW:'.RDS_DETAIL','ENABLED',1)
END ELSE
	Set_Property(@WINDOW:'.RDS_DETAIL','ENABLED',0)
END


WindowTitle = Get_Property(@WINDOW,'TEXT')
ShipNo		= Get_Property(@WINDOW:'.SHIP_NO','TEXT')

IF INDEX(WindowTitle,'New',1) OR ShipNo = '' OR MemberOf(@USER4, 'SAP_ADMIN') THEN
	Set_Property(@WINDOW:'.WO_NO','ENABLED',1)
	Set_Property(@WINDOW:'.WO_NO','BACKCOLOR',WHITE$)
END ELSE
	Set_Property(@WINDOW:'.WO_NO','ENABLED',0)
	Set_Property(@WINDOW:'.WO_NO','BACKCOLOR',GREEN$)
END



Ctrls  = @WINDOW:'.PICK_BUTTON':@RM			; Props  = 'TEXT':@RM
Ctrls := @WINDOW:'.PICK_BUTTON':@RM			; Props := 'ENABLED':@RM
Ctrls := @WINDOW:'.PICKED_FIX':@RM			; Props := 'VISIBLE':@RM
Ctrls := @WINDOW:'.UNPICK_BUTTON':@RM		; Props := 'ENABLED':@RM
Ctrls := @WINDOW:'.SELECT_RDS':@RM			; Props := 'ENABLED':@RM
Ctrls := @WINDOW:'.SCAN_CASS_BUTTON'		; Props := 'ENABLED'

PrintCtrls  = @WINDOW:'.PRINT_PACKINGLIST':@RM			; PrintProps  = 'ENABLED':@RM
PrintCtrls := @WINDOW:'.PRINT_DOCUMENTS':@RM			; PrintProps := 'ENABLED':@RM
PrintCtrls := @WINDOW:'.PRINT_LABELS'					; PrintProps := 'ENABLED'


Vals = ''

IF Get_Property(@WINDOW:'.PICK_DTM','TEXT') NE '' THEN
	
	Vals<1> = 'Picked'		;* PickButton text
	Vals<2> = 0				;* PickButton Disabled
	Vals<3> = 1				;* Picked Text Visisble
	Vals<4> = 1				;* Unpick button Enabled
	Vals<5> = 0				;* Select RDS button Disabled
	Vals<6> = 0				;* Scan Cassettes button Disabled
	
	PrintVals = '1':@RM:'1':@RM:'1':@RM:'1':@RM:'1'
	
END ELSE

	Vals<1> = 'Pick'	;* PickButton text
	
	IF Get_Property(@WINDOW,'QBFLIST') = '' THEN
		Vals<2> = 1			;* PickButton Enabled
		Vals<3> = 0			;* Picked Text invisible
		Vals<4> = 0			;* Unpick button Disabled
		Vals<5> = 1			;* Select RDS button Enabled
		Vals<6> = 1			;* Scan Cassettes button Enabled
		
	END ELSE
		Vals<2> = 0			;* PickButton Enabled
		Vals<3> = 0			;* Picked Text invisible
		Vals<4> = 0			;* Unpick button Disabled
		Vals<5> = 0			;* Select RDS button Disabled
		Vals<6> = 0			;* Scan Cassettes button Disabled
	END
	
	IF MemberOf(@USER4, 'SAP_ADMIN') THEN
		PrintVals = '1':@RM:'1':@RM:'1'
	END ELSE
		PrintVals = '0':@RM:'0':@RM:'0'
	END

END

Set_Property(PrintCtrls,PrintProps,PrintVals)

Ctrls  = @WINDOW:'.ENTER_BY':@RM		; Props  = 'TEXT':@RM
Ctrls := @WINDOW:'.ENTER_DTM'			; Props := 'TEXT'

Vals = Get_Property(Ctrls,Props)

EnterBy		= Vals[1,@RM]
EnterDTM	= Vals[COL2()+1,@RM]

IF EnterBy	= '' THEN Vals  = 1:@RM ELSE Vals  = 0:@RM
IF EnterDTM = '' THEN Vals := 1		ELSE Vals := 0

Props = 'ENABLED':@RM:'ENABLED'

Set_Property(Ctrls,Props,Vals)

NextNumber = XLATE('DICT.COC','%SK%',1,'X')

Set_Property(@WINDOW:'.NEW_BUTTON','TEXT',NextNumber)

* QBF buttons

Ctrls  = @WINDOW:'.QBF_FIRST_FIX':@RM		; Props  = 'ENABLED':@RM
Ctrls := @WINDOW:'.QBF_PREV_FIX':@RM		; Props := 'ENABLED':@RM
Ctrls := @WINDOW:'.QBF_ABS_FIX':@RM			; Props := 'ENABLED':@RM
Ctrls := @WINDOW:'.QBF_NEXT_FIX':@RM		; Props := 'ENABLED':@RM
Ctrls := @WINDOW:'.QBF_LAST_FIX':@RM		; Props := 'ENABLED':@RM
Ctrls := @WINDOW:'.QBF_STOP_FIX'			; Props := 'ENABLED'

IF Get_Property(@WINDOW,'QBFLIST') = '' THEN
	Vals = 0:@RM:0:@RM:0:@RM:0:@RM:0:@RM:0
END ELSE
	Vals = 1:@RM:1:@RM:1:@RM:1:@RM:1:@RM:1
END

Set_Property(Ctrls,Props,Vals)

* All cassette detail background colors

CtrlName = @WINDOW:'.RDS_DETAIL'
RDSArray = Get_Property(CtrlName,'INVALUE')

RdsStatuses = RDSArray<COL$RDS_CURR_STATUS>	
FOR I = 1 TO COUNT(RdsStatuses,@VM) + (RdsStatuses NE '')
	RdsStatus	= RdsStatuses<1,I>
	
	* RdsStatus has been broken for some time 4/17/2014 JCH * * * * * * * * * * * * * 
	
	RdsHotLot	= RDSArray<COL$RDS_HOT_LOT,I>
	
	IF  RdsHotLot THEN
		IF RdsHotLot THEN LineColor = RED$
	END ELSE
		BEGIN CASE
			CASE RdsStatus[1,3] = 'Rec'	; LineColor = RCV_BLUE$
			CASE RdsStatus[1,3] = 'Pre'	; LineColor = PRE_BLUE$
			CASE RdsStatus[1,3] = 'In '	; LineColor = INP_BLUE$
			CASE RdsStatus[1,3] = 'Pos'	; LineColor = POS_BLUE$
			CASE RdsStatus[1,3] = 'Rea' ; LineColor = GREEN$
			CASE RdsStatus[1,3] = 'Shi'	; LineColor = LTGREY$
			CASE RdsStatus[1,3] = 'Pro'	; LineColor = RED$
			CASE 1	; LineColor = WHITE$
		END CASE
	END
	stat = Send_Message(CtrlName,'COLOR_BY_POS',0,I,LineColor)
NEXT I

* 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>
	*IF ETCtrl NE @WINDOW:'.RDS_DETAIL' THEN
		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
	*END
NEXT I

RETURN


* * * * * * *
Page:
* * * * * * *

Page = Get_Property(@WINDOW:'.TABCONTROL', 'VALUE')

Set_Property(@WINDOW,'VPOSITION', Page)

GOSUB Refresh

RETURN


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

ShipNo = Get_Property(@WINDOW:'SHIP_NO','TEXT')



IF RowExists('COC',ShipNo) ELSE
	IF NOT(Security_Check('COC',WRITE$)) THEN
		Send_Event(@WINDOW,'CLEAR')
		Security_Err_Msg('COC',WRITE$)
		RETURN
	END
END

EnterBy = Get_Property(@WINDOW:'.ENTER_BY','TEXT')

IF EnterBy = '' THEN
	CurrDate = OCONV(Date(),'D4/')
	CurrTime = OCONV(Time(),'MTH')
	
	IF @USER4 = '' THEN @USER4 = 'TESTING'
	Set_Property(@WINDOW:'.ENTER_BY','TEXT',OCONV(@USER4,'[XLATE_CONV,LSL_USERS*FIRST_LAST]'))
	Set_Property(@WINDOW:'.ENTER_DT','TEXT',CurrDate)
END

GOSUB Refresh

RETURN


* * * * * * *
Write:
* * * * * * *


ShipNo = Get_Property(@WINDOW:'.SHIP_NO','DEFPROP')
TxTransArray = Get_Property(@WINDOW:'.VISION_LOG','DEFPROP')


Forward_Event()			;* This does the Write

IF TxTransArray<1,1> = '' THEN

	obj_Shipment('SendTechnical',ShipNo)

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

Result = 0

RETURN


* * * * * * *
Delete:
* * * * * * *

IF Security_Check('COC',Delete$) THEN
	Result = 0
	
	IF Get_Property(@WINDOW:'.PICK_BY','TEXT') = ''  THEN
		Result = 1
	END ELSE
		ErrMsg('Record has material picked against it and may not be deleted.')
		Result = 0
	END
	
	
	IF Get_Property(@WINDOW:'.RDS_DETAIL','ARRAY')<COL$CASS_NO,1> = '' THEN
		Result = 1
	END ELSE
		ErrMsg('Record has material picked against it and may not be deleted.')
		Result = 0
	END
	
	
END ELSE
	Security_Err_Msg('COC',Delete$)
	Result = 0		;* Stop event chain
END

RETURN


* * * * * * *
LUShipNo:
* * * * * * * 

IF NOT(ASSIGNED(Parm1)) THEN FocusControl = ''	ELSE FocusControl = Parm1
IF NOT(ASSIGNED(Parm2)) THEN FocusPos = ''		ELSE FocusPos = Parm2

Set_Status(0)

ShipKeys = obj_Shipment('Find')	

IF Get_Status(errCode) THEN ErrMsg(ErrCode)

IF INDEX(ShipKeys,@VM,1) THEN
	TypeOver = ''
	TypeOver<PMODE$> = 'K'
	TypeOver<PDISPLAY$> = ShipKeys
	ShipKeys = Popup(@WINDOW,TypeOver,'COC_QUERY')
	IF Get_Status(errCode) THEN
		ErrMsg(errCode) 
		RETURN
	END
END

CONVERT @VM TO @FM IN ShipKeys

IF INDEX(ShipKeys,@FM,1) THEN
	Send_Event(@WINDOW,'QBFINIT')
	Set_Property(@WINDOW,'QBFLIST',ShipKeys)
	GOSUB Refresh
	Send_Event(@WINDOW,'QBFIRST')
END ELSE
	obj_Appwindow('LoadFormKeys',@WINDOW:@RM:ShipKeys)
END

RETURN


* * * * * * *
ShipNoLF:
* * * * * * *

RETURN


* * * * * * *
NewShipment:
* * * * * * *

ShipNo = Get_Property(@WINDOW,'ID')

IF NOT(Security_Check('COC',WRITE$)) THEN
	Security_Err_Msg('COC',WRITE$)
	RETURN
END

IF ShipNo = '' THEN
	NextShipNo = NextKey('COC')
	obj_Appwindow('LoadFormKeys',@WINDOW:@RM:NextShipNo)
END

RETURN


* * * * * * *
TodaysShipments:
* * * * * * *

ShipNo = Get_Property(@WINDOW,'ID')

IF ShipNo NE '' THEN
	Send_Event(@WINDOW,'WRITE')
END

OpenShipKeys = obj_Shipment('TodaysShipments')

IF INDEX(OpenShipKeys,@VM,1) THEN

	SortData = ''
	osCnt = COUNT(OpenShipKeys,@VM) + (OpenShipKeys NE '')
	
	FOR I = 1 TO osCnt
		OpenShipKey = OpenShipKeys<1,I>
		SortData<I> = XLATE('COC',OpenShipKey,COC_SAP_DEL_NO$,'X'):@VM:OpenShipKey
	NEXT I
	SortData := @FM
	CONVERT @FM:@VM TO @RM:@FM IN SortData
	
	CALL V119('S','','DD','RR',SortData,'')
	
	IF Get_Status(errCode) THEN DEBUG
	
	CONVERT @FM:@RM TO @VM:@FM IN SortData
	
	FOR I = 1 TO osCnt
		OpenShipKeys<1,I> = SortData<I,2>
	NEXT I
	
	TypeOver = ''
	TypeOver<PMODE$> = 'K'
	TypeOver<PDISPLAY$> = OpenShipKeys
	TypeOver<PSELECT$>	= 2							;* Single Select
	ShipKeys = Popup(@WINDOW,TypeOver,'COC_QUERY')
	IF Get_Status(errCode) THEN
		ErrMsg(errCode) 
		RETURN
	END
	
END ELSE
	ShipKeys = OpenShipKeys
END

IF INDEX(ShipKeys,@VM,1) THEN
	Send_Event(@WINDOW,'QBFINIT')
	Set_Property(@WINDOW,'QBFLIST',ShipKeys)
	Send_Event(@WINDOW,'QBFFIRST')
END ELSE
	obj_Appwindow('LoadFormKeys',@WINDOW:@RM:ShipKeys)
END

RETURN


* * * * * * *
ActiveShipments:
* * * * * * *

ShipNo = Get_Property(@WINDOW,'ID')

IF ShipNo NE '' THEN
	Send_Event(@WINDOW,'WRITE')
END

OpenShipKeys = obj_Shipment('OpenShipments')

IF INDEX(OpenShipKeys,@VM,1) THEN
			
	OpenShipKeys := @VM
	CONVERT @VM TO @RM IN OpenShipKeys
	CALL V119('S','','D','R',OpenShipKeys,'')
	IF Get_Status(errCode) THEN DEBUG
	CONVERT @RM TO @VM IN OpenShipKeys
	OpenShipKeys[-1,1] = ''					;* Strip trailing delimiter	
	
	TypeOver = ''
	TypeOver<PMODE$> = 'K'
	TypeOver<PDISPLAY$> = OpenShipKeys
	TypeOver<PSELECT$>	= 2							;* Single Select
	ShipKeys = Popup(@WINDOW,TypeOver,'COC_QUERY')
	IF Get_Status(errCode) THEN
		ErrMsg(errCode) 
		RETURN
	END
	
END ELSE
	ShipKeys = OpenShipKeys
END


IF INDEX(ShipKeys,@VM,1) THEN
	Send_Event(@WINDOW,'QBFINIT')
	Set_Property(@WINDOW,'QBFLIST',ShipKeys)
	Send_Event(@WINDOW,'QBFFIRST')
END ELSE
	obj_Appwindow('LoadFormKeys',@WINDOW:@RM:ShipKeys)
END

RETURN


* * * * * * *
ShipViaGF:
* * * * * * *

WONo = Get_Property(@WINDOW:'.WO_NO','TEXT')
ShipVia = Get_Property(@WINDOW:'.SHIP_VIA','TEXT')

IF WONo NE '' AND ShipVia = '' THEN
	OrderNo = XLATE('WO_LOG',WONo,WO_LOG_ORDER_NO$,'X')
	ShipVia = XLATE('ORDER',OrderNo,ORDER_SHIP_VIA$,'X')
	AcctNo	= XLATE('ORDER',OrderNo,ORDER_ACCOUNT_NO$,'X')
	Set_Property(@WINDOW:'.SHIP_VIA','TEXT',ShipVia)
	Set_Property(@WINDOW:'.SHIP_VIA_ACCT_NO','TEXT',AcctNo)
END

RETURN


* * * * * * *
LUShipVia:
* * * * * * *

CustNo = Get_Property(@WINDOW:'.CUST_NO','TEXT')
ShipVia = Get_Property(@WINDOW:'.SHIP_VIA','TEXT')

IF CustNo NE '' AND ShipVia = '' THEN
	CustRec = XLATE('COMPANY',CustNo,'','X')
	ShipVias = CustRec<COMPANY_SHIPPER_INFO$>
	IF INDEX(ShipVias,@VM,1) THEN
		Display = ''
		FOR I = 1 TO COUNT(ShipVias,@VM) + (ShipVias NE '')
			Display<1,I> = ShipVias<1,I>:@SVM:CustRec<COMPANY_ACCOUNT_NO$,I>
		NEXT I
		TypeOver = ''
		TypeOver<PDISPLAY$> = Display
		SelectedItems = Popup(@WINDOW,TypeOver,'ORDER_SHIPPER_INFO')
		IF SelectedItems = '' THEN RETURN
		ShipVia		= SelectedItems<1,1>
		AcctNo		= SelectedItems<1,2>
	END ELSE
		ShipVia		= ShipVias
		AcctNo		= CustRec<COMPANY_ACCOUNT_NO$>
	END
	Set_Property(@WINDOW:'.SHIP_VIA','TEXT',ShipVia)
	Set_Property(@WINDOW:'.SHIP_VIA_ACCT_NO','TEXT',AcctNo)
	
END

RETURN


* * * * * * *
WONoLF:
* * * * * * *

WONo = Get_Property(@WINDOW:'.WO_NO','DEFPROP')
ReactType = Get_Property(@WINDOW:'.REACTOR_TYPE','DEFPROP')

IF WONo NE '' AND ReactType = '' THEN
	WOStepKeys = XLATE('WO_LOG',WONo,WO_LOG_WO_STEP_KEY$,'X')
	ShipWOStepKey = WOStepKeys[-1,'B':@VM]
	ShipPSN = XLATE('WO_STEP',ShipWOStepKey,1,'X')
	ReactType = XLATE('PROD_SPEC',ShipPSN,80,'X')
	Set_Property(@WINDOW:'.REACTOR_TYPE','DEFPROP',ReactType)
END

GOSUB Refresh

RETURN


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

obj_Notes('Inbox',@USER4)	;* Checks for any new messages

obj_Appwindow('CardReturn',@WINDOW)

RETURN


* * * * * * *
LUWONo:
* * * * * * *

Set_Status(0)

WOKeys = obj_WO_Log('Find')	

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 obj_Appwindow('ViewRelated',@WINDOW:@RM:WOKeys)		;* Loads form key or QBFList as required
END
RETURN


* * * * * * * 
ShippingWOS:
* * * * * * *

OpenWONo = obj_WO_Log('ShipWONos','')

ShipNo	= Get_Property(@WINDOW:'.SHIP_NO','TEXT')
WONo	= Get_Property(@WINDOW:'.WO_NO','TEXT')

IF OpenWONo NE '' AND ShipNo NE '' AND WONo = '' THEN
	obj_AppWindow('LUValReturn',OpenWONo:@RM:@WINDOW:'.WO_NO')
END

RETURN


* * * * * * *
ViewCustomer:
* * * * * * *

CustNo = Get_Property(@WINDOW:'.CUST_NO','TEXT')

IF CustNo NE '' THEN
	obj_Appwindow('ViewRelated','COMPANY':@RM:CustNo)
END

RETURN




* * * * * * *
RDSDetailDC:
* * * * * * *
ShipNo = Get_Property(@WINDOW,'ID')

CtrlEntID = @WINDOW:'.RDS_DETAIL'

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

IF CurrCol = 1 THEN
	RdsNo = Get_Property(CtrlEntID,'CELLPOS',1:@FM:CurrRow)

	IF RdsNo NE '' THEN
		
		thisFormName = 'RDS_UNLOAD'
		
		thisFormWindowUp = Get_Property(thisFormName,'VISIBLE')	;* Returns 0 = hidden, 1 = visible, 2 = minimized, 3 = maximized 

		IF thisFormWindowUp = ''	THEN
		    If Get_Property('NDW_MAIN', 'VISIBLE') then
		        AppMain = 'NDW_MAIN'
		    end else
		        AppMain = 'LSL_MAIN2'
		    end
			Start_Window(thisFormName,AppMain,RDSNo:'*CENTER', '', '')	;* Put up the card window
			RETURN
		END
		
		IF thisFormWindowUp = 2		THEN Set_Property(thisFormName,'VISIBLE',9)	;* Restore the window if minimized

		IF Get_Property(thisFormName,'SAVEWARN') THEN
			Send_Event(thisFormName,'CLEAR')					;* Clear anything existing (prompts for save first)
		END

	END
END	;* End of ItemNo column

RETURN


* * * * * * *
SelectCassettes:
* * * * * * *

WONo = Get_Property(@WINDOW:'.WO_NO','TEXT')

IF WONo = '' THEN RETURN

ReactorType = XLATE('WO_STEP',WONo:'*1','PS_REACTOR_TYPE','X')

IF ReactorType = 'P' OR ReactorType = 'EPP' THEN
	* EpiPRO process
	OPEN 'DICT.WM_OUT' TO DictVar ELSE
		ErrMsg('Unable to open "DICT.WM_OUT" for index lookup in COMM_SHIPMENT routine.')
		RETURN
	END
	
	SearchString  = 'WO_NO':@VM:WONo:@FM
	WMOutKeys = ''
	Flag = ''
	Btree.Extract(SearchString, 'WM_OUT', DictVar, WMOutKeys, '', Flag)
	
	IF Get_Status(errCode) THEN
		ErrMsg(errCode)
		RETURN
	END
	
	IF WMOutKeys = '' THEN
		ErrMsg('Work Order has no WM_OUT cassettes.')
		RETURN
	END
	
	PopupData = ''
	PLineCnt = 0
	FOR I = 1 TO COUNT(WMOutKeys,@VM) + (WMOutKEys NE '')
		CurrStatus	= XLATE('WM_OUT',WMOutKeys<1,I>,'CURR_STATUS','X')
		WfrQty		= XLATE('WM_OUT',WMOutKeys<1,I>,'WFRS_OUT','X')
		IF CurrStatus = 'RTS' THEN
			PLineCnt += 1
			PopupData<1,PLineCnt,1> = FIELD(WMOutKeys<1,I>,'*',2)
			PopupData<1,PLineCnt,2> = FIELD(WMOutKeys<1,I>,'*',3)
			PopupData<1,PLineCnt,3> = ''
			PopupData<1,PLineCnt,4> = WfrQty
			
		END
	NEXT I
	
	IF PopupData = '' THEN
		ErrMsg('Work Order has no Ready To Ship cassettes.')
		RETURN
	END

	TypeOver = ''
	TypeOver<PDISPLAY$> = PopupData

	NewRows = Popup(@WINDOW,TypeOver,'SHIP_RTS_CASSETTES')
	
END ELSE

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

	IF WOMatKeys = '' THEN
		ErrMsg('Work Order has no Material (WO_MAT) records.')
		RETURN
	END

	PopupData = ''
	PLineCnt = 0
	FOR I = 1 TO COUNT(WOMatKeys,@VM) + (WOMatKeys NE '')
		WOMatKey = WOMatKeys<1,I>
		CurrStatus	= XLATE('WO_MAT',WOMatKey,'CURR_STATUS','X')
		WfrQty		= XLATE('WO_MAT',WOMatKey,'CURR_WFR_CNT','X')
		ShipRDS		= XLATE('WO_MAT',WOMatKey,'SHIP_RDS','X')
		ShipStep	= XLATE('WO_MAT',WOMatKey,'SHIP_WO_STEP','X')
		IF CurrStatus = 'RTS' THEN
			PLineCnt += 1
			PopupData<1,PLineCnt,1> = ShipStep
			PopupData<1,PLineCnt,2> = FIELD(WOMatKeys<1,I>,'*',2)
			PopupData<1,PLineCnt,3> = ShipRDS
			PopupData<1,PLineCnt,4> = WfrQty
			
		END
	NEXT I

	IF PopupData = '' THEN
		ErrMsg('Work Order has no Ready To Ship cassettes.')
		RETURN
	END

	TypeOver = ''
	TypeOver<PDISPLAY$> = PopupData

	NewRows = Popup(@WINDOW,TypeOver,'SHIP_RTS_CASSETTES')


END

IF NewRows NE '' THEN
	OrgArray = Get_Property(@WINDOW:'.RDS_DETAIL','DEFPROP')
	OrgCassNos = OrgArray<COL$CASS_NO>
	
	OrgLineCnt = COUNT(OrgArray,@FM) + (OrgCassNos NE '')		;* Number of lines in edit table (including blank lines)
	
	CurrStepNos = ''
	CurrCassNos = ''
	CurrRDSNos  = ''
	
	FOR I = 1 TO OrgLineCnt
		IF OrgCassNos<1,I> NE '' THEN
			CurrStepNos<1,-1> = OrgArray<1,I>
			CurrCassNos<1,-1> = OrgArray<2,I>
			CurrRDSNos<1,-1> = OrgArray<3,I>
		END
	NEXT I
	
	FOR I = 1 TO COUNT(NewRows,@FM) + (NewRows NE '')
		NewStepNo	= NewRows<I,1>
		NewCassNo	= NewRows<I,2>
		NewRdsNo	= NewRows<I,3>
		
		LOCATE NewCassNo IN CurrCassNos BY 'AR' USING @VM  SETTING Pos ELSE
			CurrStepNos	= INSERT(CurrStepNos,1,Pos,0,NewStepNo)
			CurrCassNos	= INSERT(CurrCassNos,1,Pos,0,NewCassNo)
			CurrRdsNos	= INSERT(CurrRdsNos,1,Pos,0,NewRdsNo)
		END
	NEXT I
	
	CurrLineCnt = COUNT(CurrRdsNos,@VM) + (CurrRdsNos NE '')
	
	IF CurrLineCnt < OrgLineCnt THEN
		CurrStepNos := Str(@VM,OrgLineCnt - CurrLineCnt)		;* Pad with blank lines to fill edit table control
		CurrCassNos := Str(@VM,OrgLineCnt - CurrLineCnt)
		CurrRdsNos	:= Str(@VM,OrgLineCnt - CurrLineCnt)
	END ELSE
		CurrStepNos	:= @VM
		CurrCassNos	:= @VM		
		CurrRdsNos 	:= @VM									;* Pad with single blank line at end of edit table
	END
	
	Set_Property(@WINDOW:'.RDS_DETAIL','DEFPROP',CurrStepNos:@FM:CurrCassNos:@FM:CurrRdsNos)
	
	FOR I = COL$RDS_LOT_NO TO COL$RDS_STAT_CD
		Send_Event(@WINDOW:'.RDS_DETAIL','CALCULATE',I)
	NEXT I
	
	GOSUB Refresh
	
END

RETURN


* * * * * * *
ScanCassettes:
* * * * * * *

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

NewRows = Dialog_Box("DIALOG_MAT_SCAN", @window, 'Ship':@VM:'Scan Cassettes for WO ':WONo)

IF NewRows = 'Cancel' THEN RETURN

IF NewRows NE '' THEN
	OrgArray = Get_Property(@WINDOW:'.RDS_DETAIL','DEFPROP')
	OrgCassNos = OrgArray<COL$CASS_NO>
	
	OrgLineCnt = COUNT(OrgArray,@FM) + (OrgCassNos NE '')		;* Number of lines in edit table (including blank lines)
	
	CurrStepNos = ''
	CurrCassNos = ''
	CurrRDSNos  = ''
	
	FOR I = 1 TO OrgLineCnt
		IF OrgCassNos<1,I> NE '' THEN
			CurrStepNos<1,-1> = OrgArray<1,I>
			CurrCassNos<1,-1> = OrgArray<2,I>
			CurrRDSNos<1,-1> = OrgArray<3,I>
		END
	NEXT I
	
	FOR I = 1 TO COUNT(NewRows,@FM) + (NewRows NE '')
		NewStepNo	= NewRows<I,1>
		NewCassNo	= NewRows<I,2>
		NewRdsNo	= NewRows<I,3>
		
		LOCATE NewCassNo IN CurrCassNos USING @VM  SETTING Pos ELSE
			CurrStepNos	= INSERT(CurrStepNos,1,Pos,0,NewStepNo)
			CurrCassNos	= INSERT(CurrCassNos,1,Pos,0,NewCassNo)
			CurrRdsNos	= INSERT(CurrRdsNos,1,Pos,0,NewRdsNo)
		END
	NEXT I
	
	CurrLineCnt = COUNT(CurrRdsNos,@VM) + (CurrRdsNos NE '')
	
	IF CurrLineCnt < OrgLineCnt THEN
		CurrStepNos := Str(@VM,OrgLineCnt - CurrLineCnt)		;* Pad with blank lines to fill edit table control
		CurrCassNos := Str(@VM,OrgLineCnt - CurrLineCnt)
		CurrRdsNos	:= Str(@VM,OrgLineCnt - CurrLineCnt)
	END ELSE
		CurrStepNos	:= @VM
		CurrCassNos	:= @VM		
		CurrRdsNos 	:= @VM									;* Pad with single blank line at end of edit table
	END
	
	Set_Property(@WINDOW:'.RDS_DETAIL','DEFPROP',CurrStepNos:@FM:CurrCassNos:@FM:CurrRdsNos)
	
	FOR I = COL$RDS_LOT_NO TO COL$RDS_STAT_CD
		Send_Event(@WINDOW:'.RDS_DETAIL','CALCULATE',I)
	NEXT I
	
	GOSUB Refresh
	
END

RETURN



* * * * * * *
Pick:
* * * * * * *

IF Get_Property(@WINDOW:'.PICK_DTM','TEXT') NE '' THEN RETURN  ;* Check for pre-existing picked flag

ShipNo = Get_Property(@WINDOW,'ID')

IF ShipNo = '' THEN RETURN

Send_Event(@WINDOW,'WRITE')

obj_Shipment('Pick',ShipNo)

IF Get_Status(errCode) THEN
	ErrMsg(errCode)
END

obj_Appwindow('LoadFormKeys',@WINDOW:@RM:ShipNo)

Send_Event(@WINDOW,'PAGE',2)

GOSUB REFRESH

RETURN


* * * * * *
UnPick:
* * * * * *

IF Get_Property(@WINDOW:'.PICK_DTM','TEXT') = '' THEN RETURN  ;* Check for null pickeded flag

ShipNo = Get_Property(@WINDOW:'.SHIP_NO','TEXT')
IF ShipNo = '' THEN RETURN

Set_Property(@WINDOW,'SAVEWARN',0)
Send_Event(@WINDOW,'CLEAR')

obj_Shipment('UnPick',ShipNo)

IF Get_Status(errCode) THEN
	ErrMsg(errCode)
END

obj_AppWindow('LoadFormKeys',@WINDOW:@RM:ShipNo)

Send_Event(@WINDOW,'PAGE',2)

GOSUB Refresh

RETURN


* * * * * * *
ViewWO:
* * * * * * *

WONo = Get_Property(@WINDOW:'.WO_NO','TEXT')

IF WONo NE '' THEN
	WOStepKeys = XLATE('WO_LOG',WONo,34,'X')
	LastStepKey = WOStepKeys[-1,'B':@VM]
	obj_Appwindow('ViewRelated','WO_PROD':@RM:LastStepKey)
END

RETURN


* * * * * * *
PrintCassLabel:
* * * * * * * 

CtrlEntID = @WINDOW:'.RDS_DETAIL'

RDSArray = Get_Property(CtrlEntID,'DEFPROP')

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


PDisplay = ''
LineCnt = 0
FOR I = 1 TO COUNT(RDSArray<1>,@VM) + (RDSArray<1> NE '')
	IF RDSArray<COL$RDS_NO,I> NE '' OR RDSArray<COL$CASS_NO,I> NE '' THEN
		LineCnt += 1
		PDisplay<1,LineCnt,1> = RDSArray<COL$WO_STEP,I>
		PDisplay<1,LineCnt,2> = RDSArray<COL$CASS_NO,I>
		PDisplay<1,LineCnt,3> = RDSArray<COL$RDS_NO,I>
	END
NEXT I

TypeOver = ''
TypeOver<PDISPLAY$> = PDisplay

SelectedCassettes = Popup(@WINDOW,TypeOver,'PRINT_CASS_SHIP_LABELS')

WOStepNos = ''
WOCassNos = ''
RDSNos = ''

FOR I = 1 TO COUNT(SelectedCassettes,@FM) + (SelectedCassettes NE '')
	WOStepNos<1,I>	= SelectedCassettes<I,1>
	WOCassNos<1,I>	= SelectedCassettes<I,2>
	RDSNos<1,I>		= SelectedCassettes<I,3>
NEXT I

Print_SAP_Cass_Ship_Label( WONo,WOStepNos,WOCassNos,RDSNos )

RETURN


* * * * * * *
PrintPackingList:
* * * * * * * 

ShipNo = Get_Property(@WINDOW:'.SHIP_NO','TEXT')

IF ShipNo = '' THEN RETURN

IF security_check( 'COC', Print$ ) THEN
	
	Send_Event(@WINDOW,'WRITE')
	Print_Packing_Slip(ShipNo)
	obj_Appwindow('LoadFormKeys',@WINDOW:@RM:ShipNo)
	
END ELSE
    Security_Err_Msg( 'COC', Print$ )
END

RETURN


* * * * * * *
PrintCheck:
* * * * * * *

ShipNo = Get_Property(@WINDOW:'.SHIP_NO','TEXT')

IF ShipNo = '' THEN RETURN

Send_Event(@WINDOW,'WRITE')

Print_Ship_CheckList(ShipNo)

obj_Appwindow('LoadFormKeys',@WINDOW:@RM:ShipNo)

RETURN


* * * * * * *
PrintDocuments:
* * * * * * * 

ShipNo = Get_Property(@WINDOW:'.SHIP_NO','TEXT')

IF ShipNo = '' THEN RETURN

IF Security_Check( 'COC', Print$ ) THEN

	Send_Event(@WINDOW,'WRITE')

	Print_Shipment(ShipNo)
	
	obj_Appwindow('LoadFormKeys',@WINDOW:@RM:ShipNo)

END ELSE
    Security_Err_Msg( 'COC', Print$ )
END

RETURN


* * * * * * *
PrintCoCInvoice:
* * * * * * *

ShipNo = Get_Property(@WINDOW:'.SHIP_NO','TEXT')

IF ShipNo = '' THEN RETURN

IF Security_Check( 'COC', Print$ ) THEN

	Send_Event(@WINDOW,'WRITE')
	Print_CoC_Invoice( ShipNo )
	obj_Appwindow('LoadFormKeys',@WINDOW:@RM:ShipNo)

END ELSE
    Security_Err_Msg( 'COC', Print$ )
END

RETURN


* * * * * * *
PrintCommInvoice:
* * * * * * *

ShipNo = Get_Property(@WINDOW:'.SHIP_NO','TEXT')

IF ShipNo = '' THEN RETURN

IF Security_Check( 'COC', Print$ ) THEN
	Send_Event(@WINDOW,'WRITE')
	Print_Comm_Invoice( ShipNo )
	obj_Appwindow('LoadFormKeys',@WINDOW:@RM:ShipNo)
END ELSE
    Security_Err_Msg( 'COC', Print$ )
END

RETURN



* * * * * * * 
TxTechData:
* * * * * * *

ShipNo = Get_Property(@WINDOW:'.SHIP_NO','TEXT')
IF ShipNo = '' THEN RETURN

IF NOT(Security_Check('Vision',WRITE$)) THEN
	IF NOT(MemberOf(@USER4,'SHIPPING')) THEN
		Security_Err_Msg('Vision',WRITE$)
		RETURN
	END
END

Set_Property(@WINDOW,'SAVEWARN',0)
Send_Event(@WINDOW,'CLEAR')

obj_Shipment('SendTechnical',ShipNo)

IF Get_Status(errCode) THEN
	ErrMsg(errCode)
END

obj_AppWindow('LoadFormKeys',@WINDOW:@RM:ShipNo)


RETURN


* * * * * * *
Repost:
* * * * * * *

ShipNo = Get_Property(@WINDOW,'ID')

IF ShipNo = '' THEN RETURN

Send_Event(@WINDOW,'WRITE')

obj_Shipment('Repost',ShipNo)

IF Get_Status(errCode) THEN
	ErrMsg(errCode)
END

obj_Appwindow('LoadFormKeys',@WINDOW:@RM:ShipNo)

GOSUB REFRESH

RETURN

