function wo_daily_sched_comm2(Branch)
#pragma precomp SRP_PreCompiler
declare function   set_property, fieldcount, get_property, msg, dialog_box, security_check, send_message, Memberof
declare function   utility, key_sort, start_window, entid, repository, relational_call, popup, next_key
declare function   rds_supplement_maint, get_mode_icon, obj_Prod_Spec, rds_wo_verify_maint, GetTickCount
declare subroutine extract_si_keys, end_dialog, make.list, security_err_msg, ErrMsg, Set_Property, obj_Appwindow
declare subroutine ShowWindow, Start_Window

$insert msg_equates
$insert lsl_users_equ
$insert rds_equ
$insert security_rights_equ
$insert logical
$insert popup_equates
$insert react_mode_equ
$insert quote_spec_equ
$insert wo_log_equ
$insert wo_daily_sched_equ
$insert wo_master_sched_equ
$insert wo_verify_equ
$INSERT WO_STEP_EQU
$INSERT ORDER_DET_EQU
$INSERT PROD_SPEC_EQUATES
$INSERT PRS_LAYER_EQU
$INSERT EPI_PART_EQUATES

Equ HIDE$ To 0
Equ NORMAL$ To 1
Equ MINIMIZE$ To 2
Equ MAXIMIZE$ To 3

equ CrLf$   to char(13):char(10)
equ Blue$   to 16711680
equ Red$    to 255
equ Green$  to 65280
equ Yellow$ to 65535
equ White$  to 16777215
equ Black$  to 1
equ Gray$   to 12632256

ForceModeChange = false$ 
* If @USER4 EQ 'DANIEL_ST' then debug
ReturnVar = 0
Branches = 'WO_GOT_FOCUS,WO_LOST_FOCUS,FORM_CREATE,FORM_CLOSE,FORM_SAVE,FORM_CANCEL,CALL_WINDOW,REFRESH,OPTIONS,REACT_MODE'
convert ',' to @fm in Branches
locate Branch in Branches using @fm setting Bpos then
	on Bpos gosub WO_GOT_FOCUS, WO_LOST_FOCUS, FORM_CREATE, FORM_CLOSE, FORM_SAVE, FORM_CANCEL, CALL_WINDOW, REFRESH, OPTIONS, REACT_MODE
end else
	Void = msg( '', 'Invalid Branch ':Bpos:' passed to wo_daily_sched_comm' )
end
return ReturnVar

*============================================================================*
WO_GOT_FOCUS:
	OrigWoVal = get_property( @window:'.WOCUST', 'TEXT' )
	Void = set_property( @window, '@OrigWoVal', OrigWoVal )
return

*============================================================================*
WO_LOST_FOCUS:
	NewWoVal = get_property( @window:'.WOCUST', 'TEXT' )
	OrigWoVal = get_property( @window, '@OrigWoVal' )
	if NewWoVal <> OrigWoVal then
		* NOW FORCE THEM TO CHANGE THE STATUS OR APPLY SETTING THIS WORK ORDER
		ForceModeChange = true$ 
		Mode = ''    
		gosub react_mode
		if Mode = 'CANCEL' then
			* could not get a lock so someone else is changing the mode with a 
			* different work order than the one we have changed to
			* so do not change the work order
			Void = set_property( @window:'.WOCUST', 'TEXT', OrigWoVal )
		end else
			* check to see if we are running this wo anywhere else
			* and warn user - as to not forget to finish a wo before 
			* starting a new one
			if OrigWoVal then
				gosub CheckWo
			end
			CurWoVal     = NewWoVal
			CurArray = get_property( @window:'.ROS', 'ARRAY' )
			for i = 1 to 96
				* to gray boxes
				CurArray<i,2> = 0
			next i
			Void = set_property( @window:'.ROS', 'ARRAY', CurArray )    
			gosub PrepWo
			gosub RecalcWo
		end
	end
return

*============================================================================*
RecalcWo:
	* called from this code only no external branch
	RNum = get_property( @window, '@Reactor' )
	RMId = 'REACT_MODE':RNum
	Mode = xlate( 'CONFIG', RMId, Mode$, 'X' )
	if Mode then
		Icon = get_mode_icon( Mode )
		Extension = '.BMP'
		DosBmp = 'BMPS\':Icon:Extension
		Void = set_property( @window:'.RMODE', 'BITMAP', DosBmp )
	end
return

*============================================================================*
FORM_CREATE:
    
    * field one of the config "WO_DAILY_SCHED"1-9999 will have as follows
    *<1> = REACTOR
    *<2> = WO CUSTNAME
    *<3> = BOX SELECTION INFO
       
    DailySchedName = 'WO_DAILY_SCHED':get_property( @window, '@Reactor' )
    open 'CONFIG' to ConfigTable else
        Void = msg( '', 'Unable to open CONFIG table' )
        end_dialog( @window, '' )
        return 0
    end
    if memberof( @user4, 'SUPERVISOR' ) or memberof( @user4, 'DATA_ENTRY' ) or memberof( @user4, 'MAINTENANCE' ) then
        gosub DoRead
    end else
        Void = set_property( @window:'.SAVE', 'ENABLED', 0 )
        Void = set_property( @window:'.CANCEL', 'TEXT', 'OK' )
        gosub DoRead
        Void = set_property( @window:'.WOCUST', 'ENABLED', 0 )
    end
    
RETURN 0


FORM_CLOSE:
	
return 0

*===========================================================================*
DoRead:
	
	* called from this code only no external branch
	
	READ DailySched FROM ConfigTable, DailySchedName THEN
		
		IF DailySched THEN
			
			CurWoVal = DailySched<WOCust$>
			Set_Property( @WINDOW:'.WOCUST', 'TEXT', CurWoVal )
			
			WONo = CurWoVal[1,' ']
			
			IF INDEX(WONo,'.',1) THEN WONo = WONo[1,'.']
			IF INDEX(WONo,'*',1) THEN WONo = WONo[1,'*']
			
			WOQty		= OCONV(XLATE('WO_LOG',WONo,'WO_QTY','X'),'MD0,')
			RxQty 		= OCONV(XLATE('WO_LOG',WONo,'RX_QTY','X'),'MD0,')
			RelQty		= OCONV(XLATE('WO_LOG',WONo,'REL_QTY','X'),'MD0,')
			UnRelQty	= OCONV(XLATE('WO_LOG',WONo,'UNREL_QTY','X'),'MD0,')
			ShipQty		= OCONV(XLATE('WO_LOG',WONo,'SHIP_QTY','X'),'MD0,')
			
			Ctrls  = @WINDOW:'.WO_QTY':@RM		; Props  = 'DEFPROP':@RM		; Vals  = WOQty:@RM
			Ctrls := @WINDOW:'.RX_QTY':@RM		; Props := 'DEFPROP':@RM		; Vals := RxQty:@RM
			Ctrls := @WINDOW:'.REL_QTY':@RM		; Props := 'DEFPROP':@RM		; Vals := RelQty:@RM
			Ctrls := @WINDOW:'.UNREL_QTY':@RM	; Props := 'DEFPROP':@RM		; Vals := UnRelQty:@RM
			Ctrls := @WINDOW:'.SHIP_QTY'		; Props := 'DEFPROP'			; Vals := ShipQty
			
			Set_Property(Ctrls,Props,Vals)
			
			GOSUB PrepWo
			
			GOSUB RecalcWo
			
			ReactType = Xlate('WO_LOG', WONo, 'REACT_TYPE', 'X')
			If ReactType EQ 'EPP' then
				Set_Property(@Window:'.PUB_WMO_QUICKVIEW', 'VISIBLE', True$)
			end
			
			// Populate loaded runs and total runs
			AllRDS   = Xlate('WO_STEP', WONo:'*1', 'RDS_KEY', 'X')
			RDSCount = DCount(AllRDS, @VM)
			Set_Property(@Window:'.EDL_TOTAL_RUNS', 'TEXT', RDSCount)
			
			Reactor    = get_property( @window, '@Reactor' )
			LoadedRDS  = Xlate('REACT_STATUS', Reactor, 'LOAD_RDS', 'X')
			LoadedRuns = Xlate('RDS', LoadedRDS, 'RUN_ORDER_NUM', 'X')
			
			LoadedData = ''
			For each RDSNo in LoadedRDS using @VM setting vPos
				LoadedData<vPos, 1> = RDSNo
				LoadedData<vPos, 2> = LoadedRuns<0, vPos>
			Next RDSNo
			Set_Property(@Window:'.EDT_LOADED_CASSETTES', 'LIST', LoadedData)
			
		END	;* End of check for DailySched 
	END ELSE
		Ccnt = 0
	END
	
RETURN

*===========================================================================*
FORM_SAVE:
	* field one of the config "WO_DAILY_SCHED"1-9999 will have as follows
	*<1> = REACTOR
	*<2> = WO CUSTNAME
	*<3> = BOX SELECTION INFO
	
	open 'CONFIG' to ConfigTable else
		Void = msg( '', 'Unable to open CONFIG table' )
		end_dialog( @window, '' )
		return 0
	end
	Reactor = get_property( @window, '@Reactor' ) 
	DailySchedName = 'WO_DAILY_SCHED':Reactor
	OldRec = xlate( 'CONFIG', DailySchedName, '', 'X' )
	DailySchedRec  = ''
	DailySchedRec<Reactor$> = Reactor
	DailySchedRec<ReactorType$> = OldRec<ReactorType$>
	TWo = get_property( @window:'.WOCUST', 'TEXT' )
	
	DailySchedRec<WOCust$> = TWo
	CurWoVal = TWo
	
	gosub PrepWo
	
	PSNId = XLATE( 'WO_LOG', CurWoVal[1,'.'], 'SHIP_PSN', 'X' )					;* changed 8/3/2005 JCH
	EpiPartNo = XLATE( 'WO_LOG', CurWoVal[1,'.'], 'EPI_PART_NO', 'X' )
	SubInfo = XLATE( 'EPI_PART',EpiPartNo, EPI_PART_SUB_WAFER_SIZE$, 'X' )
	WaferSize = trim( field( SubInfo, ' ', 3, 2 ) )
	
	if Wafersize = '' then
		* LEAVE THE OLD SIZE THERE
		DailySchedRec<Size$> = OldRec<Size$>   
	end else 
		DailySchedRec<Size$> = WaferSize
	end
	CurArray = get_property( @window:'.ROS', 'ARRAY' )
	FieldOut = ''
	for j = 1 to 96
		FieldOut<1,j> = CurArray<j,2>
	next j
	DailySchedRec<BoxInfo$> = FieldOut
	write DailySchedRec on ConfigTable, DailySchedName else
		Void = msg( '', 'Unable to write ':DailySchedName:' in CONFIG table' )
		end_dialog( @window, '' )
		return 0
	end
	end_dialog( @window, '' )
RETURN

*============================================================================*
FORM_CANCEL:
	* field one of the config "WO_DAILY_SCHED"1-9999 will have as follows
	*<1> = REACTOR
	*<2> = WO CUSTNAME
	*<3> = BOX SELECTION INFO
	if memberof( @user4, 'SUPERVISOR' ) or memberof( @user4, 'DATA_ENTRY' ) or memberof( @user4, 'MAINTENANCE' ) then
		DailySchedName = 'WO_DAILY_SCHED':get_property( @window, '@Reactor' )
		open 'CONFIG' to ConfigTable else
			Void = msg( '', 'Unable to open CONFIG table' )
			end_dialog( @window, '' )
			return 0
		end
	end
	end_dialog( @window, '' )
RETURN

*============================================================================*
CALL_WINDOW:
	*Void = start_window( CurParam, 'LSL_MAIN2', '*CENTER', '', '' )
RETURN

*============================================================================*
PrepWo:
	* called internally
	CurReactor = get_property( @window, '@Reactor' )
	convert @upper_case to '' in CurReactor
	convert @lower_case to '' in CurReactor
	
	CurWoVal = CurWoVal[1,' ']
	
	swap '52nd' with '' in CurWoVal
	convert @upper_case to '' in CurWoVal
	convert @lower_case to '' in CurWoVal
	convert " `~!@#$%^&*()_+-=\][{}|';:/?.>,<" to '' in CurWoVal
	convert '"' to '' in CurWoVal
	
	IF LEN(CurWoVal) = 7 THEN
		CurWoVal = CurWoVal[1,6]:'.':CurWoVal[7,1]		;* Workorder plus a step  7/28/2005 JCH
	END
	
RETURN

*============================================================================*
REFRESH:
	
return


*============================================================================*************************************************8
OPTIONS:
	Reactor = get_property( @window, '@Reactor' )
	PopupId = entid( @appid<1>, 'POPUP', '', 'DAILY_SCHED_OPTS' )
	OverRide = ''
	Display = xlate( 'SYSREPOSPOPUPS', 'LSL2**DAILY_SCHED_OPTS', pdisplay$, 'X' )
	if memberof( @user4, 'SUPERVISOR' ) or memberof( @user4, 'DATA_ENTRY' ) then
		* add option to choose boxes if the save button is enabled meaning they have the lock
		if get_property( @window:'.SAVE', 'ENABLED' ) then
			*Display = 'Quote':@SVM:'QUOTE':@vm:'PSN':@SVM:'PSN':@vm:'Recipe':@SVM:'RECIPE':@vm:'RunData Sheet':@SVM:'RDS':@vm:'Work Order':@SVM:'WO'
			*Display:= @vm:'Choose Boxes':@SVM:'CHOOSE_BOXES'
			* WHEN THE POPUP DAILY_SCHED_OPTS CHANGES THE ABOVE 2 LINES NEED CHANGING
			*            Display := @vm:'Choose Boxes':@SVM:'CHOOSE_BOXES'      
			if memberof( @user4, 'SUPERVISOR' ) then
				Display := @vm:'Assign WO Verifications':@SVM:'WO_VERIFY'      
			end
		end
	end
	if memberof( @user4, 'ENGINEERING' ) or memberof( @user4, 'SUPERVISOR' ) or memberof( @user4, 'LEAD' ) Then			;* Added LEAD security group to allow asign supplements -dkk 12/5/14
		* ADD OPTION TO ASSIGN SUPPLEMENTS
		Display := @vm:'Assign Supplements':@SVM:'SUPPLEMENTS'
	end
	
	If MemberOf(@User4, 'ENGINEERING') then
		* Add PSN limit update option
		Display := @VM:'Update Metrology Limits':@SVM:'MET_LIMITS'
	end
	
	CurWoVal = get_property( @window:'.WOCUST', 'TEXT' )
	
	CurWoVal = CurWoVal[1,' ']
	HoldWoVal = CurWoVal
	
	
	swap '52nd' with '' in CurWoVal
	convert @upper_case to '' in CurWoVal
	convert @lower_case to '' in CurWoVal
	convert " `~!@#$%^&*()_+-=\][{}|';:/?.>,<" to '' in CurWoVal
	convert '"' to '' in CurWoVal
	
	IF LEN(CurWoVal) = 7 THEN
		WOStepKey = CurWoVal[1,6]:'*':CurWoVal[7,1]
	END ELSE
		WOStepKey = CurWoVal:'*1'
	END
	WONo = WOStepKey[1,6]
	
	ReactorType = Xlate('WO_LOG', WONo, 'REACT_TYPE', 'X')
	If ReactorType EQ 'EPP' then
		Display := @VM:'WM Outbound Cassettes':@SVM:'WM_OUTBOUND'
	end
	
	OverRide<Pdisplay$> = Display
	
	ChosenOpt = repository( 'EXECUTE', PopupId, @window, OverRide )
	
	RdsKeys = ''
	BEGIN CASE
		
		CASE ChosenOpt = 'PSN'
			IF security_check( 'Prod Spec', Read$ ) THEN   
				
				PSNId = XLATE('WO_STEP',WOStepKey,WO_STEP_PROD_SPEC_ID$,'X')
				Void = start_window( 'PROD_SPEC', @window, PSNId:'*CENTER', '', '' )
			END ELSE
				security_err_msg( 'Prod Spec', Read$ )      
			END
			
		CASE ChosenOpt = 'RDS'
			if security_check( 'RDS', Read$ ) then        
				
				SelRDSKeys = Dialog_Box('NDW_RDS_QUERY', 'NDW_MAIN', WONo : @FM : 'Detailed')
				IF SelRDSKeys NE '' THEN
					Void = Start_Window( 'RDS', @window, SelRDSKeys:'*CENTER', '', '' )
				END
				
			end else
				security_err_msg( 'RDS', Read$ )                  
			end
			
		CASE ChosenOpt = 'WO'
			if security_check( 'WO Log', Read$ ) then
				Start_Window('NDW_WO_LOG', @Window, WONo)
			end else
				security_err_msg( 'WO Log', Read$ )
			end
			
			
		CASE ChosenOpt = 'WO_STAT'
			
			PSN			= XLATE('WO_STEP',WOStepKey,1,'X')
			ReactorType = XLATE('PROD_SPEC', PSN, PROD_SPEC_REACTOR_TYPE$, 'X')
			
			BEGIN CASE
				CASE ReactorType = 'P' Or ReactorType = 'EPP'
					
					obj_Appwindow('ViewRelated','WO_PROD_EPI':@RM:WOStepKey)
					
				CASE ReactorType = 'GAN'
					obj_Appwindow('ViewRelated','WO_PROD_GAN':@RM:WOStepKey)
					
				CASE 1
					obj_Appwindow('ViewRelated','WO_PROD':@RM:WOStepKey)
					
			END CASE
			
		case ChosenOpt = 'WO_VERIFY'
			Void = rds_wo_verify_maint( WoNo )
			
		case ChosenOpt = 'SUPPLEMENTS'          	    
			Void = Dialog_Box('NDW_RDS_SUPPLEMENT', @WINDOW, WoNo)
			
		case ChosenOpt = 'MET_LIMITS'
			Void = Dialog_Box('NDW_RDS_UPDATE_MET_LIMITS', @WINDOW, WoNo)
			
		Case ChosenOpt = 'WM_OUTBOUND'
			Void = Dialog_Box('NDW_WM_OUT_QUICK_QUERY', @Window, WoNo)
			
	end case
	
return


*============================================================================*
GetRdsKeys:
	* called internally only
	extract_si_keys( 'RDS', 'WO',  CurWoVal, RdsKeys )
return


*============================================================================*
CheckWo:
	MaxReacts = xlate( 'CONFIG', 'WO_MAST_SCHED', MaxReacts$, 'X' )
	CurReactor = get_property( @window, '@Reactor' )
	* now look through all other windows using disk values
	open 'CONFIG' to ConfigTable else
		Void = msg( '', 'Unable to open CONFIG table' )
		end_dialog( @window, '' )
		return 0
	end
	ErrMsg = ''
	for i = 20 to MaxReacts
		ThisDailyWoId = 'WO_DAILY_SCHED':i
		if i = CurReactor then
			* SKIP CAUSE WE KNOW IT IS RUNNING ON THIS REACTOR 
		end else
			read DailyWoRec from ConfigTable, ThisDailyWoId else
				DailyWoRec = ''
			end
			if DailyWoRec<WOCust$> = OrigWoVal then
				ErrMsg := 'Reactor ':i:', '
			end 
		end
	next i
	ErrMsg[-2,2] = ''
	if ErrMsg then
		convert ',' to @fm in ErrMsg
		LastOne = fieldcount( ErrMsg, @fm )
		if LastOne > 1 then
			TWo = ErrMsg<LastOne>
			TWo = ' and ':TWo
			ErrMsg<LastOne> = TWo
			convert @fm to ',' in ErrMsg      
		end
		MsgInfo = ''
		MsgInfo<micon$> = '!'
		MsgInfo<mtext$> = quote( OrigWoVal ):' is currently running on ':ErrMsg:'...Please verify that all boxes for Work Order ':quote( OrigWoVal ):' are assigned to reactors before starting a new Work Order.'
		Void = msg( '', MsgInfo )
	end
return


*============================================================================*
* * * * * * *
REACT_MODE:
* * * * * * *
	
	CurWo = Get_Property( @WINDOW:'.WOCUST', 'TEXT' )
	
	SWAP '52nd' WITH '' IN CurWo
	CONVERT @UPPER_CASE TO '' IN CurWo
	CONVERT @LOWER_CASE TO '' IN CurWo
	CONVERT " `~!@#$%^&*()_+-=\][{}|';:/?.>,<" TO '' IN CurWo
	CONVERT '"' TO '' IN CurWo
	
	IF LEN(CurWo) = 7 THEN
		WONo = CurWo[1,6]:'.':CurWo[7,1]
	END ELSE
		WONo = CurWo
	END
	
	Reactor = Get_Property( @WINDOW, '@Reactor' )
	//Below is the entry point for either the new reactor mode change form or the old.
	
	CurMode = Dialog_Box( 'REACT_MODE_CHG_NG', @WINDOW, Reactor:'*':WONo:'*':ForceModechange:'*CENTER' )
	
	IF ( (CurMode NE '') and (CurMode NE 'CANCEL') ) THEN
		Icon = Get_Mode_Icon( CurMode )
		Extension = '.BMP'
		DosBmp = 'BMPS\':Icon:Extension
		Void = Set_Property( @WINDOW:'.RMODE', 'BITMAP', DosBmp )
	END
RETURN

