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

/*
	Commuter module for DIALOG_WO_REP_SCAN (Scan RDS numbers from original cassette RDS labels)
	
	09/10/2009 - John C. Henry, J.C. Henry & Co., Inc.
*/

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

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


$INSERT MSG_EQUATES
$INSERT APPCOLORS
$INSERT LSL_USERS_EQU
$INSERT SECURITY_RIGHTS_EQU
$INSERT REACT_EVENT_EQUATES
$INSERT POPUP_EQUATES

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

EQU COL$LOT_NO 	TO 1

EQU CA$ITEM_NO				TO 1		;* Equates for Checking Array passed to Scan routine
EQU CA$LOT_NO				TO 2
EQU CA$LOT_QTY				TO 3
EQU CA$CUST_PART_NO			TO 4
EQU CA$SUB_PART_NO			TO 5
EQU CA$SCANNED_LOT_QTY		TO 6
EQU CA$VERIFY_PART_NO		TO 7



ErrTitle = 'Error in Dialogg_WO_Rep_Scan commuter module'
ErrorMsg = ''

Result = ''

BEGIN CASE
	CASE EntID = @WINDOW
		BEGIN CASE
			CASE Event = 'CREATE' 			; GOSUB Create
			CASE Event = 'CLOSE'			; GOSUB Close
		END CASE
		
	CASE EntID = @WINDOW:'.LOT' AND Event = 'POSCHANGED'		; GOSUB LotPC
	
	CASE EntID = @WINDOW:'.OK_BUTTON' AND Event = 'CLICK'		; GOSUB OK
	CASE EntID = @WINDOW:'.CANCEL_BUTTON' AND Event = 'CLICK'	; 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:
* * * * * * *

OrderNo		= Parm1[1,@FM]
CheckArray	= FIELD(Parm1,@FM,2,999)

Set_Property(@WINDOW:'@ORDER_NO',OrderNo)
Set_Property(@WINDOW,'@CHECK_ARRAY',CheckArray)

obj_Appwindow('Create',@WINDOW)

TimeStamp = OCONV(Date(),'D4/'):' ':OCONV(Time(),'MTS')
Set_Property(@WINDOW:'.RX_DTM','DEFPROP',TimeStamp)
Set_Property(@WINDOW,'FOCUS',@WINDOW:'.RX_DTM')
Set_Property(@WINDOW:'.RX_DTM','SELECTION',1:@FM:65534)

GOSUB Refresh

RETURN



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

RETURN


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

ListArray	= Get_Property(@WINDOW:'.LOT','ARRAY')
CheckArray = Get_Property(@WINDOW,'@CHECK_ARRAY')

TotalScannedQty = SUM(CheckArray<CA$SCANNED_LOT_QTY>)
TotalOrderQty	= SUM(CheckArray<CA$LOT_QTY>)

Set_Property(@WINDOW:'.ORDER_QTY','TEXT',OCONV(TotalOrderQty,'MD0,'))
Set_Property(@WINDOW:'.SCANNED_QTY','TEXT',OCONV(TotalScannedQty,'MD0,'))

IF TotalScannedQty = TotalOrderQty THEN
	Set_Property(@WINDOW:'.SCANNED_QTY','BACKCOLOR',GREEN$)
END ELSE
	Set_Property(@WINDOW:'.SCANNED_QTY','BACKCOLOR',RED$)
END
RETURN



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

End_Dialog(@WINDOW,'Cancel')

RETURN


* * * * * * *
LotPC:
* * * * * * *


CheckArray = Get_Property(@WINDOW,'@CHECK_ARRAY')

CtrlEntID = @WINDOW:'.LOT'

ColCnt = 1

PrevSelPos	= Get_Property(CtrlEntId,"PREVSELPOS")
PrevCol 	= PrevSelPos<1>
PrevRow 	= PrevSelPos<2>

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

ListData	= Get_Property(CtrlEntId,'LIST')
ArrayData	= Get_Property(CtrlEntId,'DEFPROP')

IF ListData<CurrRow,CurrCol> = '' THEN
	
	ColPointer = CurrCol
	LinePointer = CurrRow
	
	* Find the first non-empty cell
	
	LOOP
		Test = ListData<LinePointer,(ColPointer) >
	UNTIL Test NE '' OR (LinePointer = 0 AND ColPointer = 1)
		ColPointer -= 1
		IF ColPointer = 0 THEN
			ColPointer = ColCnt
			LinePointer -= 1
		END
	REPEAT
	
	* Move one past the non empty cell
	
	BEGIN CASE
		CASE LinePointer = 0 
			* Empty Table
			LinePointer = 1
			CoilPointer = 1
			
		CASE ColPointer = ColCnt
			LinePointer += 1
			ColPointer = 1
			
		CASE 1
			ColPointer += 1
			
	END CASE
	Set_Property(CtrlEntId,"SELPOS",ColPointer:@FM:LinePointer)
END

IF ListData<PrevRow,PrevCol> NE '' THEN

	LotNo = TRIM(ListData<PrevRow,PrevCol>)
	
	* Check for data already in the list (repeat scan)
	
	TestArray = ArrayData<1>								;* First Column
	TestArray<1,PrevRow> = ''								;* Remove the label just scanned
	LOCATE LotNo IN TestArray USING @VM SETTING Pos THEN
		Set_Property(CtrlEntId,"SELPOS",PrevSelPos)
		Set_Property(CtrlEntID,'INVALUE','',PrevSelPos)		;* Label Data already scanned
		RETURN
	END


	BEGIN CASE
		CASE PrevCol = COL$LOT_NO
			
			LotNo = TRIM(ListData<PrevRow,PrevCol>)
			
			LOCATE LotNo IN CheckArray<CA$LOT_NO> USING @VM SETTING Pos THEN
				Qty = XLATE('REACT_RUN',LotNo,'CURR_WFR_CNT','X')
				CheckArray<CA$SCANNED_LOT_QTY,Pos> = CheckArray<CA$SCANNED_LOT_QTY,Pos> + Qty
				Set_Property(@WINDOW,'@CHECK_ARRAY',CheckArray)
			END ELSE
				
				* Accept or Rescan message
				TypeOver = ''
				TypeOver<MTYPE$> = 'B&Rescan'
				TypeOver<MTEXT$> = 'Lot No ':QUOTE(LotNo):' not found in':@TM:'Order Item Lot Numbers OR has already been received.'
				Resp = Msg(@WINDOW,TypeOver,'LABEL_DATA_ERROR')
				
				LotNo = ''											;* Clear entered field for a rescan
				Set_Property(CtrlEntId,"SELPOS",PrevSelPos)			;* Cursor to Lot No for a rescan
			END

			Set_Property(CtrlEntID,'INVALUE',LotNo,PrevSelPos)

	END CASE
END 

GOSUB Refresh

RETURN


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

CheckArray = Get_Property(@WINDOW,'@CHECK_ARRAY')

ListData = Get_Property(@WINDOW:'.LOT','LIST')

TimeStamp = Get_Property(@WINDOW:'.RX_DTM','TEXT')
TimeStamp = ICONV(TimeStamp,'DT')
IF TimeStamp = '' THEN
	ErrMsg('Invalid Received DateTime data entered.  "mm/dd/yy hh:mm:ss" is the basic format.')
	RETURN
END

* TimeStamp = ICONV(OCONV(Date(),'D4/'):' ':OCONV(Time(),'MTS'),'DT')

LineCnt = 1

LOOP
	TestVal = ListData<LineCnt,1>
UNTIL TestVal = ''

	LotNo	= TRIM(ListData<LineCnt,1>)
	
	LOCATE LotNo IN CheckArray<CA$LOT_NO> USING @VM SETTING Pos THEN
		OrderItemNo = CheckArray<CA$ITEM_NO,Pos>
		CustPartNo	= CheckArray<CA$CUST_PART_NO,Pos>
		SubPartNo	= CheckArray<CA$SUB_PART_NO,Pos>
		ScanQty		= CheckArray<CA$SCANNED_LOT_QTY,Pos>
		
	END ELSE
		* Accept or Rescan message
		TypeOver = ''
		TypeOver<MTYPE$> = 'B&Rescan'
		TypeOver<MTEXT$> = 'Lot No ':QUOTE(LotNo):' not found in':@TM:'Order Item Lot Numbers!'
		Resp = Msg(@WINDOW,TypeOver,'LABEL_DATA_ERROR')
		
		LotNo = ''														;* Clear entered field for a rescan
		Set_Property(CtrlEntId,"SELPOS",COL$LOT_NO:@FM:LineCnt)			;* Cursor to Lot No for a rescan
		RETURN
	END
	
	Result<1,LineCnt> = LineCnt
	Result<2,LineCnt> = LotNo							;* Lot No  (Original RDS No)
	Result<3,LineCnt> = ScanQty
	Result<4,LineCnt> = CustPartNo
	Result<5,LineCnt> = SubPartNo
	Result<6,LineCnt> = OCONV(TimeStamp,'DT')
	Result<7,LineCnt> = @USER4
	Result<8,LineCnt> = OrderItemNo
	
	LineCnt += 1
	
REPEAT

End_Dialog(@WINDOW,Result)

RETURN












