Function SVC_Process_Time(Service, Param1, Param2, Param3, Param4, Param5, Param6, Param7)

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

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

    Name        :   SVC Process Time

    Description :   

    Tags		:	[SRP]

    Notes		:	WO_MAST_SCHED_REL, WO number key w/ associated list of appointments in <1>
					WO_MAST_SCHED_DATES, Date (date_span) key w/ associated list of appointments in <1>

    History (Date, Initials, Notes)
        05/26/10    fjt     Initial development
        05/31/10	fjt		Last updated

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

$insert SRP_APP_INSERTS
$insert SERVICE_INSERT

Declare function SRP_Rotate_Array, SRP_Sort_Array

Equ Sched_Win$	to "WO_MASTER_SCHEDULER"
Equ Ctrl$		to Sched_Win$:".OLE_SCHEDULE"
Equ Mid$		to Iconv("12:00AM", "MT")
Equ Noon$		to Iconv("12:00PM", "MT")

Begin Case
	Case Service _eqc "CalcRange"	; GoSub Calc_Range
	
	Case Service _eqc "ProcTime"	; GoSub Proc_Time
	Case Service _eqc "ProcToday"	; GoSub Proc_Today
		
	Case Service _eqc "RDSact"		; GoSub RDS_Actual
	Case Service _eqc "RDScomp"		; GoSub RDS_Completed
	Case Service _eqc "RDSpace"		; GoSub RDS_Pace
		
	Case Service _eqc "TimeSum"		; GoSub Time_Summary
End Case

Return Ans


!----- SERVICES -----------------------------------------------------------------------------------------


Calc_Range:
	StartDate = Param1
	StartTime = Param2
	Proc.Hrs  = Param3

	Days	 = Int(Proc.Hrs / 240)
	Partial  = Mod(Proc.Hrs, 240)
	
 	Begin Case
 		Case Days EQ 0 and Partial GE 120 and StartTime EQ Mid$
 			EndTime = Mid$  ; Days += 1

 		Case Days EQ 0 and Partial EQ 0 and StartTime EQ Noon$
 			EndTime = Noon$ ; Days += 1
 		
 		Case Days EQ 0 and Partial EQ 0 and StartTime EQ Mid$
 			EndTime = Mid$  ; Days += 1
 		
		Case Partial GE 120
			EndTime = Iconv("12:00AM", "MT") ; Days += 1
			
		Case Otherwise$
			EndTime = Iconv("12:00PM", "MT")
			
 	End Case
 	
 	EndDate = StartDate + Days
* 	debug

 	Ans<1> = StartDate
 	Ans<2> = StartTime
 	Ans<3> = EndDate
 	Ans<4> = EndTime
return


Proc_Time:
	// Process time for an instance of a WO on the scheduler
	WO    = Param1
	Rec   = Param2
	PSNno = Rec<06>
	PSrec = Xlate("PROD_SPEC", PSNno, "", "X")
	
	GoSub RDS_Completed
	
* 	RDS_Cnt  = Param2	;// Boxes
* 	RDS_Comp = Param3
* 	WO_Step  = Param4

	Rem.Min  = 0
	Per.Box  = 0
	Ttl.Hrs  = 0
	Rem.Day  = ""
	Proc.Hrs = ""
	Proc.Day = ""

	// Minutes per wafer, minutes in 1 decimal
	Per.Waf  = PSrec<96>
	Per.Waf  = Iconv(Oconv(Per.Waf, "MD3"), "MD1")
	
	// Wafer count
	Wafers = Xlate("RDS", WO_Step<6>, "WAFERS_SCHEDULED", "X")
	
	// Related reactors
	Rel.React = Xlate("WO_MAST_SCHED_REL", WO, "REACTOR_COUNT", "X")
	If Rel.React LT 1 then Rel.React = 1

	If Per.Waf GT "" and Wafers<0,1> then
		
		// Minutes per box is time per wafer times the wafers in the RDS run
		Per.Box	 = Per.Waf * Wafers<0,1>
		
		// Converted to hours
		Proc.Hrs = Iconv(Per.Box / 600, "MD1")
		Ttl.Hrs  = (Proc.Hrs * RDS_Cnt)
		Ttl.Hrs  = Ttl.Hrs / Rel.React
		
		// Converted to days and hours
		Proc.Day = Int(Ttl.Hrs / 240) :" days - ": Oconv(Mod(Ttl.Hrs, 240), "MD1") :" hrs."
		Rem.Hrs  = Per.Box * (RDS_Cnt - RDS_Comp)
		Rem.Hrs  = Iconv(Rem.Hrs / 600, "MD1")
		Rem.Day  = Int(Rem.Hrs / 240) :" days - ": Oconv(Mod(Rem.Hrs, 240), "MD1") :" hrs."
		
	end
	
	* Proc.Day = "Estimated ":Proc.Day
	Wafers   = Sum(Wafers)
	Ans 	 = Ttl.Hrs :@RM: Per.Box :@RM: Per.Waf :@RM: Rem.Day :@RM: Proc.Day :@RM: Wafers
return


Proc_Today:
	// Provides a LIST of all appointments scheduled on the current date with the associated reactor
	Appts = ""
	Appts<2> = Xlate("WO_MAST_SCHED_DATES", Date(), 1, "X")
	Appts<1> = Xlate("WO_MAST_SCHED", Appts<2>, 15, "X")
	Ans = SRP_Rotate_Array(Appts)
	Ans = SRP_Sort_Array(Ans, "AR1", Yes$)
return


Time_Summary:
return


RDS_Actual:
	GoSub RDS_Completed
	
	WO.Done = (RDS_Comp EQ RDS_Cnt) and (RDS_Comp NE 0)
	Ans = "0.0"
	If WO.Done then
		Ans = Sum(Xlate("RDS", RDS_Keys, "ELAPSED_HOURS", "X"))
		Ans = Iconv(Comp.Time, "MD0")
		Ans = Oconv(Comp.Time, "MD2")
	end
	Ans = Ans :@FM: RDS_Comp :@FM: RDS_Cnt
return


RDS_Completed:
	WO	  = Param1
	Pos   = 0
	Delim = ""
	
	GoSub RDS_Data

	Loop
		Remove Val from RDS_Unload at Pos setting Delim
		If Val GT "" then RDS_Comp += 1
	Until Delim EQ 0
	Repeat
	Ans = RDS_Comp :@FM: RDS_Cnt
return


RDS_Data:
	StepKey	   = WO:"*1"
	RDS_Comp   = 0
	WO_Step    = Xlate("WO_STEP", StepKey, "", "X")
	RDS_Keys   = WO_Step<06>
	RDS_Unload = Xlate("REACT_RUN", RDS_Keys, "UNLOAD_SIG", "X")	
	RDS_Cnt    = Count(RDS_Keys, @VM) + (RDS_Keys NE "")
return


RDS_Pace:
	WO = Param1
	
	GoSub RDS_Completed
	
	If RDS_Comp GT 0 then
		T1 = Sum(Xlate("RDS", RDS_Keys, "ELAPSED_HOURS", "X"))
		Avg = T1 / RDS_Comp
		Avg = Iconv(Avg, "MD0")
		Avg = Oconv(Avg, "MD2")
		Ans = Avg * RDS_Cnt
		Ans = Iconv(Ans, "MD1")
	end else
		Ans = 0
	end
return
