COMPILE FUNCTION GaN_WO_New(Method, Parm1)

/*
	Commuter module for GAN_WO_NEW dialog window
	
	04/13/2016 - John C. Henry, J.C. Henry & Co., Inc.
*/

DECLARE SUBROUTINE Set_Property, End_Dialog, Set_Status, ErrMsg
DECLARE SUBROUTINE obj_Appwindow, Start_Window, Msg
DECLARE FUNCTION Get_Property, Get_Status, Dialog_Box, Popup

EQU CRLF$	TO \0D0A\

$INSERT WO_MAT_EQUATES

ErrTitle = 'Error in GaN_WO_New'
ErrorMsg = ''

Result = ''

BEGIN CASE
	CASE Method = 'Create'			; GOSUB Create
	CASE Method = 'OK'				; GOSUB OK
	CASE Method = 'Cancel'			; GOSUB Cancel
	CASE Method = 'Refresh'			; GOSUB Refresh
	CASE 1
		ErrMsg(ErrTitle:@SVM:'Unknown method ':QUOTE(Method):' passed to routine.')
		
END CASE


RETURN Result


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

obj_AppWindow('Create')

WONo		= Parm1[1,@FM]
CassKeys	= Parm1[COL2()+1,@FM]

Title = 'Work Order: ':WONo:' - Cassette Qty Change'

Set_Property(@WINDOW,'TEXT',Title)

CassCnt = COUNT(CassKeys,@VM) + (CassKeys NE '')

CassettesList = ''


FOR I = 1 TO CassCnt
	CassKey = CassKeys<1,I>
	WOMatRec = XLATE('WO_MAT',CassKey,'','X')
	CassettesList<I,1> 	= CassKey[-1,'B*']
	CassettesList<I,2>	= WOMatRec<WO_MAT_SAP_BATCH_NO$>
	CassettesList<I,3>	= WOMatRec<WO_MAT_LOT_NO$>
	CassettesList<I,4>	= WOMatRec<WO_MAT_WAFER_QTY$>
	CassettesList<I,5>	= WOMatRec<WO_MAT_CUST_PART_NO$>
NEXT I

Set_Property(@WINDOW:'.CASSETTES','LIST',CassettesList)

RETURN



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

RETURN


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


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

End_Dialog(@WINDOW,'Cancel')

RETURN



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

Ctrls  = @WINDOW:'.CASSETTES':@RM		; Props  = 'SELPOS':@RM
Ctrls := @WINDOW:'.CASSETTES':@RM		; Props := 'DEFPROP':@RM
Ctrls := @WINDOW:'.NEW_CASS_QTY':@RM	; Props := 'DEFPROP':@RM
Ctrls := @WINDOW:'.REASON'				; Props := 'DEFPROP'

Vals = Get_Property(Ctrls,Props)

SelCassette	= Vals[1,@RM]
CassArray	= Vals[COL2()+1,@RM]
NewCassQty	= Vals[COL2()+1,@RM]
Reason		= Vals[COL2()+1,@RM]

IF SelCassette = '' THEN
	ErrMsg('You must select a cassette to change!')
	Set_Property(@WINDOW,'FOCUS',@WINDOW:'.CASSETTES')
	RETURN
END

IF NewCassQty = '' THEN
	ErrMsg('New Cassette Qty is a required field and must be filled in.')
	Set_Property(@WINDOW,'FOCUS',@WINDOW:'.NEW_CASS_QTY')
	RETURN
END

IF Reason = '' THEN
	ErrMsg('Reason is a required field and must be filled in.')
	Set_Property(@WINDOW,'FOCUS',@WINDOW:'.REVISION')
	RETURN
END

SelectedLine = SelCassette<2>

CassNo		= CassArray<COL$CASS_NO,SelectedLine>
OrgCassQty	= CassArray<COL$CURR_QTY,SelectedLine>

Result = CassNo:@FM:Reason:@FM:OrgCassQty:@FM:NewCassQty

End_Dialog(@WINDOW,Result)

RETURN



