Function Pop_Mast_Sched_Opts(WOStepKey, ApptID)

/******************************************************************************************************* 

    This program is proprietary and is not to be used by or disclosed to others, nor is it to
    be copied without written permission from SRP Computer Solutions, Inc.

    Name        :   Pop Mast Sched Opts

    Notes       :   Taken from the the DBLCLK event of the WO_MAST_SCHED window, and modified for
					standalone use.
					
	Tags		:	[SRP]

    Parameters  :
		WOStepKey	[in] -- 

    History (Date, Initials, Notes)
        11/12/09	fjt     Initial development
        08/17/10	fjt		Added Choose_Box option per David

*******************************************************************************************************/

$insert MSG_EQUATES
$insert POPUP_EQUATES
$INSERT LOGICAL
$insert RDS_EQU
$insert PROD_SPEC_EQU
$insert PRS_LAYER_EQU
$insert WO_STEP_EQU

Declare function Start_Window, Msg, Entid, Repository, Fieldcount, Relational_Call, MemberOf
Declare function RDS_Wo_Verify_Maint, RDS_Supplement_Maint, Obj_Prod_Spec, Utility, Key_Sort
Declare subroutine Extract_Si_Keys, Obj_Appwindow, Make.List

GoSub Record
GoSub Build_Popup

Begin Case
	Case ChoosenOpt EQ "EPIPRO_WOPS"	; GoSub EPIPRO_WOPS
	Case ChoosenOpt EQ "RECIPE"			; GoSub RECIPE   
	Case ChoosenOpt EQ "RDS"			; GoSub RDS
	Case ChoosenOpt EQ "WO"				; GoSub WO
	Case ChoosenOpt EQ "WO_STATUS"		; GoSub WO_STATUS
	Case ChoosenOpt EQ "WO_VERIFY"		; GoSub WO_VERIFY
	Case ChoosenOpt EQ "SUPPLEMENTS"	; GoSub SUPPLEMENTS
	Case ChoosenOpt EQ "PSN"			; GoSub PSN
End Case

Return


!----- INTERNAL ROUTINES --------------------------------------------------------------------------------


Record:
	Rec = Xlate("WO_MAST_SCHED", ApptID, "", "X")
	CurReactor = Rec<15> ;// Reactor
	RNum	   = Rec<15> ;// Reactor
return


Build_Popup:
	PopupId  = EntId(@appid<1>, 'POPUP', '', 'MAST_SCHED_OPTS')
	OverRide = ''
	Display  = Xlate("SYSREPOSPOPUPS", "LSL2**MAST_SCHED_OPTS", pDisplay$, "X")


	User.Engineer = MemberOf(@USER4, "ENGINEERING")
	User.Testing  = MemberOf(@USER4, "TESTING")
	User.Super    = MemberOf(@USER4, "SUPERVISOR")

	Begin Case

		Case User.Testing
			Display := @VM:"EpiPro WO Proc Status":@TM:"EPIPRO_WOPS"
			Display := @VM:'Assign WO Verifications':@TM:'WO_VERIFY'
			Display := @vm:'Assign Supplements' :@TM: "SUPPLEMENTS"
	
		Case User.Super
			Display := @VM:"EpiPro WO Proc Status":@TM:"EPIPRO_WOPS"
			Display := @VM:'Assign WO Verifications':@TM:'WO_VERIFY'
			Display := @vm:'Assign Supplements' :@TM: "SUPPLEMENTS"

		Case User.Engineer
			Display := @vm:'Assign Supplements' :@TM: "SUPPLEMENTS"

	End Case
	
	// Add product spec for all levels
	Display := @VM: "Product Spec" :@TM: "PSN"
	
	Override<6,0,1> = "Tahoma" :@SVM: 14 :@SVM: 400
	OverRide<Pdisplay$> = Display
	ChoosenOpt = Repository("EXECUTE", PopupId, @Window, OverRide)
return


!----- PROCESS OPTIONS ----------------------------------------------------------------------------------


EPIPRO_WOPS:
* 	WONos = Field(WOStepKey, "*", 1)
* 	rv = Start_Window("WO_PROD_EPI", @Window, WONos, "", "")
	obj_Appwindow('ViewRelated', 'WO_PROD_EPI':@RM:WOStepKey)
return


CHOOSE_BOXES:
* 	RDSIds = XLATE('WO_STEP', WOStepKey, WO_STEP_RDS_KEY$, 'X')
*    If RdsIds then
*       PopId = EntID(@appid<1>, 'POPUP', '', 'RDS_QUERY' )
*       OverRide = ''
*       OverRide<ptitle$> = 'Choose the RDS Run Orders for Reactor ':Reactor
*       Convert @VM to @FM in RdsIds
*       Make.List(0, RdsIds, '', '' )
*	   ChosenKeys = Repository("EXECUTE", PopId, @Window, OverRide) 
*	   If ChosenKeys then
*	      Ccnt = Fieldcount(ChosenKeys, @VM)
*      
*          RunNums = Xlate('RDS', ChosenKeys, 'RUN_ORDER_NUM', 'X')
* 
*              CurWoVal     = HoldWoVal    
*              gosub PrepWo
*              gosub RecalcWo
*	   end
*    end
return


PSN:
	PSN = Xlate("WO_MAST_SCHED", ApptID, 6, "X")
	If PSN then
		rv = Start_Window("PROD_SPEC", @Window, PSN, "", "")
	end
return


RECIPE:
		CurKeys    = ""
		RecipeKeys = ""

		IF LEN(WOStepKey) EQ 6 THEN
			WOStepKey = WOStepKey:'*1'
		END ELSE
			WOStepKey = WOStepKey[1,6]:'*':WOStepKey[7,1]
		END
		
		PSN = XLATE('WO_STEP', WOStepKey, 1, 'X')

		LayerSpecs  = obj_Prod_Spec('GetLayerProp',PSN:@RM:@RM:1)	;// Returns specs for all layers in internal format
		LayerSpec 	= FIELD(LayerSpecs,@RM,1)						;// Take the first Layer
		LayerSet	= FIELD(LayerSpec,@FM,1)						;// Not used here but shown for clarity
		LayerSpec	= FIELD(LayerSpec,@FM,2,99)						;// LayerSpec without the LayerSet 
		RecipeNo	= LayerSpec<PRS_LAYER_RECIPE$>
				
		IF RecipeNo NE '' THEN
			LOCATE RecipeNo IN RecipeKeys USING @VM SETTING Dum ELSE
				RecipeKeys<1,-1> = RecipeNo
			END
		END

		IF RecipeKeys NE '' THEN
			Void = start_window( 'RECIPE', @window, RecipeKeys:'*CENTER', '', '' )
		END
return


RDS:
	WOStepKeys = ""
	If Len(WOStepKey) EQ 6 then
		WOStepKey = WOStepKey:'*1'
	end else
		WOStepKey = WOStepKey[1,6]:'*':WOStepKey[7,1]
	end
	WOStepKeys<1,-1> = WOSTepKey
	RDSNos = Xlate("WO_STEP", WOStepKeys, WO_STEP_RDS_KEY$, "X")

	// Popup the run data sheet popup list		
	TypeOver = ""
	TypeOver<PMODE$> = "K"
	TypeOver<PDISPLAY$> = RDSNos
	RDSKeys = Popup(@WINDOW,TypeOver,'RDS_QUERY')
	If RDSKeys NE "" then
		rv = Start_Window("RDS", @Window, RDSKeys:"*CENTER", "", "")
	end
return


WO:
	WONos   = Field(WOStepKey, "*", 1)
    NewForm = Xlate('APP_INFO', 'NEW_WO_FORM', '', 'X')
    If NewForm then
        Form = 'NDW_WO_LOG'
    end else
        Form = 'WO_LOG2'
    end
	rv = Start_Window(Form, @Window, WONos, "", "")
return


WO_STATUS:
	WOStepKeys = WOStepKey
	PSN = Xlate("WO_STEP", WOStepKey, 1, "X")
	ReactorType = XLATE('PROD_SPEC', PSN, 80, 'X')
		
	If ReactorType EQ 'P' then
		obj_Appwindow('ViewRelated','WO_PROD_EPI':@RM:WOStepKeys)
	end else
		obj_Appwindow('ViewRelated','WO_PROD':@RM:WOStepKeys)
	end
return


WO_VERIFY:
	TWo = WOStepKey
	rv = RDS_WO_Verify_Maint(TWo)
return


SUPPLEMENTS:
	TWo = WOStepKey
	rv = RDS_Supplement_Maint(TWo)	
return

	  
!----- INTERNAL ROUTINES -------------------------------------------------------------------------------


PrepWo:
* 	* 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) EQ 7 then
*		CurWoVal = CurWoVal[1,6]:".":CurWoVal[7,1]		;// Workorder plus a step  7/28/2005 JCH
* 	end
return


RecalcWo:
	/*
	* 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
  
  if CurWoVal NE '' then
    Stat = Utility( 'CURSOR', 'H' )
    IF INDEX(CurWoVal,'.',1) THEN
    	WOStepKey = CurWoVal
    END ELSE
    	WOStepKey = CurWoVal:'.1'
    END
    
    CONVERT '.' TO '*' IN WOStepKey
    
    RdsToProc = XLATE('WO_STEP',WOStepKey,6,'X')
    if RdsToProc then
*        CurArray = get_property( @window:'.ROS', 'ARRAY' )
*        for i = 1 to 80
*           Void = send_message( @window:'.ROS', 'COLOR_BY_POS', i, 1, Black$ )
*        next i
	    Convert @vm to @fm in RdsToProc
	    RdsToProc = Key_Sort(RdsToProc, 'RDS', 'RUN_ORDER_NUM', 1)
	    Tcnt = fieldcount( RdsToProc, @fm )
	   
	    RdsToProc = field( RdsToProc, @fm, 1, 80 ) ;* only room for 80
	    Rcnt = fieldcount( RdsToProc, @fm )
	    for i = 1  to Rcnt
	      RdsRec = XLATE('RDS',RdsToProc<i>,'','X') 
	      IF RdsRec = '' THEN
	        Void = msg( '', 'Unable to read ':RdsToProc<i>:' from RDS...' )
	        return 0
	      end
	      *
	      if CurArray<i,2> = 0 then
	         // they do not want to run this box on this reactor
	         GrayBox = true$
	      end else
	         * it is either one on blank meaning show this box
	         GrayBox = false$
	      end
	      DateIn  = RdsRec<rds_date_in$>
	      DateOut = RdsRec<rds_date_out$>
	      Reactor = RdsRec<rds_reactor$>
	      begin case
	        case ( GrayBox ) and ( Reactor = CurReactor )
	          // this is a gray box meaning run on another reactor but it ran here so show blue
	          ColorToUse = Blue$
	        case GrayBox
	          ColorToUse = Gray$
	        case ( DateIn = '' ) and ( DateOut = '' )
	          ColorToUse = White$
	        case Reactor <> CurReactor
	          ColorToUse = Blue$
            case ( DateIn <> '' ) and ( DateOut = '' )
	          ColorToUse = Green$
	        case ( DateIn <> '' ) and ( DateOut <> '' )
	          ColorToUse = Red$ 
	      end case 
	      *
	      *Void = send_message( @window:'.ROS', 'COLOR_BY_POS', i, 1, ColorToUse )
	    next i
	end
    Stat = utility( 'CURSOR', 'A' )    
  end
  */
return

