Compile function JONATHAN_Services(@Service, @Params)
#pragma precomp SRP_PreCompiler

Declare function Gan_Services, Obj_Notes_Sent, msg, Check_Notes, Jonathan_Services, Database_Services, SRP_Datetime
Declare function Lsl_Users_Services, SRP_Time, RList, Error_Services, Obj_Wo_Mat, Pm_Services, Date_Services, Test_Run_Services
Declare function Reactor_Services, Reactor_Log_Services, Environment_Services, Logging_Services, Obj_Wm_out, Obj_wo_mat
Declare subroutine Start_Window, RList, Set_Status, Database_Services, Obj_Sap, Sap_Services, Btree.Extract
Declare subroutine Reactor_Services, Logging_Services

$insert LOGICAL
$insert NOTE_PTRS_EQU
$insert MSG_EQUATES
$Insert APP_INSERTS
$Insert RLIST_EQUATES
$Insert	WO_LOG_EQUATES
$Insert RDS_EQUATES
$Insert WO_STEP_EQUATES
$Insert WO_MAT_QA_EQUATES
$Insert REACT_RUN_EQUATES
$Insert RDS_LAYER_EQUATES
$Insert RDS_TEST_EQUATES
$Insert PM_EQUATES
$Insert PM_SPEC_EQUATES
$Insert WO_MAT_EQUATES
$Insert WM_OUT_EQUATES
/*$Insert TEST_RUN_EQUATES
$Insert TEST_RUN_WAFER_EQUATES
$Insert TEST_WAFER_PROD_EQUATES
$Insert TEST_RUN_TYPE_EQUATES
*/
$Insert REACTOR_EQUATES


GoToService

Return Response or ""

//-----------------------------------------------------------------------------
// SERVICES
//-----------------------------------------------------------------------------

Service GetRDSwithMultipleRDSTestKeys()
	debug
	LotsWithBadRDSTestKeys = ''
	RDSList = Database_Services('ReadDataRow', 'SYSLISTS', 'TEST_JONATHAN')
	for each RDS in RDSList using @FM setting rPos
		RDSLayerKeys = XLATE('REACT_RUN', RDS, 5, 'X')
		for each RDSLayerKey in RDSLayerKeys using @Fm
			RDSTestKeys = XLATE('RDS_LAYER', RDSLayerKey, 3, 'X')
			IF Dcount(RDSTestKeys, @VM) GE 2 then
				LotsWithBadRDSTestKeys<-1> = RDSLayerKey
			end
		Next RDSLayerKey
	Next RDS
end service

Service GetWOMatRepStatus()
	debug
	WONo = 173078
	CassNo = 5
	ID = WONo : '*' : CassNo
	WOMatRec = Database_Services('ReadDataRow', 'WO_MAT', ID)
	test = obj_WO_Mat('ReportStatus',ID:@RM:WOMatRec)
end service

Service GetWMOutRepStatus()
	debug
	WONo = 173078
	CassNo = 5
	RepStatus = XLATE('WO_MAT',WONo:'*':CassNo,'REP_STATUS','X')[-1,'B':@VM]
	IF RepStatus = ''  OR RepStatus[1,3] NE 'WMO' THEN
		CurrStatus = Jonathan_Services('GetWMOutCurrStatus')
		test = OCONV(CurrStatus,'[WM_OUT_CURR_STATUS_CONV]')
	end else
     test = RepStatus
	END
end service

Service GetWMOutCurrStatus()
	debug
	RecID = '173078*1*5'
	Record = Database_Services('ReadDataRow', 'WM_OUT', RecID)
	CurrStatus = OBJ_WM_OUT('CurrStatus', RecID:@RM:Record)
	Response = CurrStatus
end service

Service Get5SType()
	Datalist = Database_Services('ReadDataRow', 'SYSLISTS', 'TEST_JONATHAN')
	PMSpecs = ''
	for each data in datalist using @FM setting iPos
		PMSpecs<iPos, 1> = data
		Is5S = Xlate('PM_SPEC', data, PM_SPEC_FIVE_S_FLAG$, 'X')
		PMSpecs<iPos, 2> = Is5S
	Next data
	debug
end service

Service TestLogging()
	Headers         = 'Logging DTM' : @FM : 'Machine' : @FM : 'Log'
	ColumnWidths    = 20 : @FM : 15 : @FM : 300
	LogPath         = Environment_Services('GetApplicationRootPath') : '\LogFiles\JonathansTest'
	LogDate         = Oconv(Date(), 'D4/')
	LogFileName     = LogDate[7, 4] : '-' : LogDate[1, 2] : '-' : LogDate[4, 2] : '_ReactorLogPM.csv'
	objLog          = Logging_Services('NewLog', LogPath, LogFileName, CRLF$, ' ', Headers, ColumnWidths, False$, False$)
	
	LogData    = ''
	LogData<1> = ''
	LogData<2> = ''
	LogData<3> = 'This is a test'
	Logging_Services('AppendLog', objLog, LogData, @RM, @FM, False$) 
end service


Service UpdateYesterdayAvail()
		Today = 20702
		DataArray = ''
		//ASM Reactors
		ASMRecordKey = 'ASM*': Today
		ASMUptimeRec = Reactor_Services('GetReactorUptimeMetricsByTypeAndTimeSpan', Today, Today + 1, 'ASM')
		Database_Services('WriteDataRow', 'REACTOR_DAILY_UPTIME', ASMRecordKey, ASMUptimeRec, True$, False$, True$)
		//HTR Reactors
		HTRRecordKey = 'HTR*': Today
		HTRUptimeRec = Reactor_Services('GetReactorUptimeMetricsByTypeAndTimeSpan', Today, Today + 1, 'HTR')
		Database_Services('WriteDataRow', 'REACTOR_DAILY_UPTIME', HTRRecordKey, HTRUptimeRec, True$, False$, True$)
		//EPP Reactors
		EPPRecordKey = 'EPP*': Today
		EPPUptimeRec = Reactor_Services('GetReactorUptimeMetricsByTypeAndTimeSpan', Today, Today + 1, 'EPP')
		Database_Services('WriteDataRow', 'REACTOR_DAILY_UPTIME', EPPRecordKey, EPPUptimeRec, True$, False$, True$)
		//All Reactors
		ALLRecordKey = 'ALL*': Today
		ALLUptimeRec = Reactor_Services('GetReactorUptimeMetricsByTypeAndTimeSpan', Today, Today + 1, 'ALL')
		Database_Services('WriteDataRow', 'REACTOR_DAILY_UPTIME', ALLRecordKey, ALLUptimeRec, True$, False$, True$)
end service



Service SetReactorMetrics()
    Reactors = Reactor_Services('GetReactorNumbers')
    table    = 'REACTOR_LOG'
        for each ReactorNo in Reactors using @FM setting rPos
            LatestTubeChangeRLIDASM                    = ''
            LatestTubeChangeASMDTM                     = ''
            LatestSuscChangRLIDASM                     = ''
            LatestArmChangeIDASM                       = ''
            LatestSuscChangRLIDHTR                     = ''
            LatestArmChangeIDHTR                       = ''
            ReactorType                                = XLATE('REACTOR', ReactorNo, REACTOR_REACT_TYPE$, 'X')
            
            //Reset all metrics to 0
            ReactorRec                                 = Database_Services('ReadDataRow', 'REACTOR', ReactorNo)
            ReactorRec<REACTOR_SUSC_THK$>              = 0;
            ReactorRec<REACTOR_SUSC_WFR_CNT$>          = 0;
            ReactorRec<REACTOR_TUBE_BELL_JAR_THK$>     = 0;
            ReactorRec<REACTOR_TUBE_BELL_JAR_WFR_CNT$> = 0;
            ReactorRec<REACTOR_LOWER_QUARTZ_THK$>      = 0;
            ReactorRec<REACTOR_LOWER_QUARTZ_WFR$>      = 0;
            ReactorRec<REACTOR_ARMS_WFR_CNT$>          = 0;
            Database_Services('WriteDataRow', 'REACTOR', ReactorNo, ReactorRec)
             
            
            Begin Case
                Case ReactorType EQ 'ASM' OR ReactorType EQ 'ASM+'
                    //Susceptor 699
                    LatestSusceptorChangeRLID = Reactor_Log_Services('GetLogsByReactorAndServID', ReactorNo, '699')<1,4>
                    RLDTM                     = XLATE('REACTOR_LOG', LatestSusceptorChangeRLID, 'END_DTM', 'X')
                    RDSList                   = Reactor_Services('GetReactorCassLoadHistoryRange', ReactorNo, RLDTM, SRP_Datetime('Now'))
                    for each RDSRow in RDSList using @FM
                        OldReactorRec                                 = Database_Services('ReadDataRow', 'REACTOR', ReactorNo)
                        
                        CurrTubeBellJarThk = OldReactorRec<REACTOR_TUBE_BELL_JAR_THK$>
                        CurrTubeBellJarCnt = OldReactorRec<REACTOR_TUBE_BELL_JAR_WFR_CNT$>
                        CurrSuscThk = OldReactorRec<REACTOR_SUSC_THK$>
                        CurrSuscWfrCnt = OldReactorRec<REACTOR_SUSC_WFR_CNT$>
                        CurrLowerQuartzThk = OldReactorRec<REACTOR_LOWER_QUARTZ_THK$>
                        CurrLowerQuartzWfr = OldReactorRec<REACTOR_LOWER_QUARTZ_WFR$>
                        
                        // Set values to 0 if blank
                        If CurrTubeBellJarThk = '' then CurrTubeBellJarThk = 0
                        If CurrTubeBellJarCnt = '' then CurrTubeBellJarCnt = 0
                        If CurrSuscThk = '' then CurrSuscThk = 0
                        If CurrSuscWfrCnt = '' then CurrSuscWfrCnt = 0
                        If CurrLowerQuartzThk = '' then CurrLowerQuartzThk = 0
                        If CurrLowerQuartzWfr = '' then CurrLowerQuartzWfr = 0
                        
                        RDSNo                                         = RDSRow<1,1>
                        TargetThickness                               = Xlate('RDS', RDSNo, 'THICK_TARGET_TOT', 'X', '')
	                    TargetThickness                               = OConv(TargetThickness, 'MD3')
                        WaferCount                                    = XLATE('RDS', RDSNo, RDS_WAFERS_IN$, 'X')
                        ThkAddition                                   = WaferCount * TargetThickness
                        NewReactorRec                                 = OldReactorRec
                        NewReactorRec<REACTOR_SUSC_THK$>              = CurrSuscThk + ThkAddition
                        NewReactorRec<REACTOR_SUSC_WFR_CNT$>          = CurrSuscWfrCnt + WaferCount
	                    Database_Services('WriteDataRow', 'REACTOR', ReactorNo, NewReactorRec)
                    Next RDSRow
                    
                    //TubeChange 240
                    LatestSusceptorChangeRLID = Reactor_Log_Services('GetLogsByReactorAndServID', ReactorNo, '240')<1,4>
                    RLDTM                     = XLATE('REACTOR_LOG', LatestSusceptorChangeRLID, 'END_DTM', 'X')
                    RDSList                   = Reactor_Services('GetReactorCassLoadHistoryRange', ReactorNo, RLDTM, SRP_Datetime('Now'))
                    for each RDSRow in RDSList using @FM
                        OldReactorRec                                 = Database_Services('ReadDataRow', 'REACTOR', ReactorNo)
                        
                        CurrTubeBellJarThk = OldReactorRec<REACTOR_TUBE_BELL_JAR_THK$>
                        CurrTubeBellJarCnt = OldReactorRec<REACTOR_TUBE_BELL_JAR_WFR_CNT$>
                        
                        // Set values to 0 if blank
                        If CurrTubeBellJarThk = '' then CurrTubeBellJarThk = 0
                        If CurrTubeBellJarCnt = '' then CurrTubeBellJarCnt = 0
                        
                        RDSNo                                         = RDSRow<1,1>
                        TargetThickness                               = Xlate('RDS', RDSNo, 'THICK_TARGET_TOT', 'X', '')
	                    TargetThickness                               = OConv(TargetThickness, 'MD3')
                        WaferCount                                    = XLATE('RDS', RDSNo, RDS_WAFERS_IN$, 'X')
                        ThkAddition                                   = WaferCount * TargetThickness
                        NewReactorRec                                 = OldReactorRec
                        NewReactorRec<REACTOR_TUBE_BELL_JAR_THK$>     = CurrTubeBellJarThk + ThkAddition
                        NewReactorRec<REACTOR_TUBE_BELL_JAR_WFR_CNT$> = CurrTubeBellJarCnt + WaferCount
	                    Database_Services('WriteDataRow', 'REACTOR', ReactorNo, NewReactorRec)
                    Next RDSRow
                    //Arms 21
                    LatestSusceptorChangeRLID = Reactor_Log_Services('GetLogsByReactorAndServID', ReactorNo, '21')<1,4>
                    RLDTM                     = XLATE('REACTOR_LOG', LatestSusceptorChangeRLID, 'END_DTM', 'X')
                    RDSList                   = Reactor_Services('GetReactorCassLoadHistoryRange', ReactorNo, RLDTM, SRP_Datetime('Now'))
                    for each RDSRow in RDSList using @FM
                        OldReactorRec                        = Database_Services('ReadDataRow', 'REACTOR', ReactorNo)
                        CurrArmsWfrCnt                       = OldReactorRec<REACTOR_ARMS_WFR_CNT$>
                        If CurrArmsWfrCnt = '' then CurrArmsWfrCnt = 0
                        RDSNo                                = RDSRow<1,1>
                        WaferCount                           = XLATE('RDS', RDSNo, RDS_WAFERS_IN$, 'X')
                        NewReactorRec                        = OldReactorRec
                        NewReactorRec<REACTOR_ARMS_WFR_CNT$> = CurrArmsWfrCnt + WaferCount
	                    Database_Services('WriteDataRow', 'REACTOR', ReactorNo, NewReactorRec)
                    Next RDSRow
                Case ReactorType EQ 'HTR'
                    //Susceptor 699
                    LatestSusceptorChangeRLID = Reactor_Log_Services('GetLogsByReactorAndServID', ReactorNo, '699')<1,4>
                    RLDTM                     = XLATE('REACTOR_LOG', LatestSusceptorChangeRLID, 'END_DTM', 'X')
                    RDSList                   = Reactor_Services('GetReactorCassLoadHistoryRange', ReactorNo, RLDTM, SRP_Datetime('Now'))
                    for each RDSRow in RDSList using @FM
                        OldReactorRec                                 = Database_Services('ReadDataRow', 'REACTOR', ReactorNo)
                        
                        CurrSuscThk = OldReactorRec<REACTOR_SUSC_THK$>
                        CurrSuscWfrCnt = OldReactorRec<REACTOR_SUSC_WFR_CNT$>
                        
                        // Set values to 0 if blank
                        If CurrSuscThk = '' then CurrSuscThk = 0
                        If CurrSuscWfrCnt = '' then CurrSuscWfrCnt = 0
                        
                        RDSNo                                         = RDSRow<1,1>
                        TargetThickness                               = Xlate('RDS', RDSNo, 'THICK_TARGET_TOT', 'X', '')
	                    TargetThickness                               = OConv(TargetThickness, 'MD3')
                        WaferCount                                    = XLATE('RDS', RDSNo, RDS_WAFERS_IN$, 'X')
                        CntAddition = (WaferCount / 5)
                        ThkAddition                                   = (WaferCount / 5) * TargetThickness
                        NewReactorRec                                 = OldReactorRec
                        NewReactorRec<REACTOR_SUSC_THK$>              = CurrSuscThk + ThkAddition
                        NewReactorRec<REACTOR_SUSC_WFR_CNT$>          = CurrSuscWfrCnt + CntAddition
	                    Database_Services('WriteDataRow', 'REACTOR', ReactorNo, NewReactorRec)
                    Next RDSRow
                    
                    //TubeChange 1280
                    LatestSusceptorChangeRLID = Reactor_Log_Services('GetLogsByReactorAndServID', ReactorNo, '1280')<1,4>
                    RLDTM                     = XLATE('REACTOR_LOG', LatestSusceptorChangeRLID, 'END_DTM', 'X')
                    RDSList                   = Reactor_Services('GetReactorCassLoadHistoryRange', ReactorNo, RLDTM, SRP_Datetime('Now'))
                    for each RDSRow in RDSList using @FM
                        OldReactorRec                                 = Database_Services('ReadDataRow', 'REACTOR', ReactorNo)
                        
                        CurrTubeBellJarThk = OldReactorRec<REACTOR_TUBE_BELL_JAR_THK$>
                        CurrTubeBellJarCnt = OldReactorRec<REACTOR_TUBE_BELL_JAR_WFR_CNT$>
                        
                        // Set values to 0 if blank
                        If CurrTubeBellJarThk = '' then CurrTubeBellJarThk = 0
                        If CurrTubeBellJarCnt = '' then CurrTubeBellJarCnt = 0
                        
                        RDSNo                                         = RDSRow<1,1>
                        TargetThickness                               = Xlate('RDS', RDSNo, 'THICK_TARGET_TOT', 'X', '')
	                    TargetThickness                               = OConv(TargetThickness, 'MD3')
                        WaferCount                                    = XLATE('RDS', RDSNo, RDS_WAFERS_IN$, 'X')
                        CntAddition                                   = (WaferCount / 5)
                        ThkAddition                                   = (WaferCount / 5) * TargetThickness
                        NewReactorRec                                 = OldReactorRec
                        NewReactorRec<REACTOR_TUBE_BELL_JAR_THK$>     = CurrTubeBellJarThk + ThkAddition
                        NewReactorRec<REACTOR_TUBE_BELL_JAR_WFR_CNT$> = CurrTubeBellJarCnt + CntAddition
	                    Database_Services('WriteDataRow', 'REACTOR', ReactorNo, NewReactorRec)
                    Next RDSRow
                    
                    //Arms 21
                    LatestSusceptorChangeRLID = Reactor_Log_Services('GetLogsByReactorAndServID', ReactorNo, '21')<1,4>
                    RLDTM                     = XLATE('REACTOR_LOG', LatestSusceptorChangeRLID, 'END_DTM', 'X')
                    RDSList                   = Reactor_Services('GetReactorCassLoadHistoryRange', ReactorNo, RLDTM, SRP_Datetime('Now'))
                    for each RDSRow in RDSList using @FM
                        OldReactorRec                        = Database_Services('ReadDataRow', 'REACTOR', ReactorNo)
                        CurrArmsWfrCnt                       = OldReactorRec<REACTOR_ARMS_WFR_CNT$>
                        If CurrArmsWfrCnt = '' then CurrArmsWfrCnt = 0
                        RDSNo                                = RDSRow<1,1>
                        WaferCount                           = XLATE('RDS', RDSNo, RDS_WAFERS_IN$, 'X')
                        NewReactorRec                        = OldReactorRec
                        NewReactorRec<REACTOR_ARMS_WFR_CNT$> = CurrArmsWfrCnt + WaferCount
	                    Database_Services('WriteDataRow', 'REACTOR', ReactorNo, NewReactorRec)
                    Next RDSRow
                
                Case ReactorType EQ 'EPP'
                    
                    //BellJar 1092
                    LatestSusceptorChangeRLID = Reactor_Log_Services('GetLogsByReactorAndServID', ReactorNo, '1092')<1,4>
                    RLDTM                     = XLATE('REACTOR_LOG', LatestSusceptorChangeRLID, 'END_DTM', 'X')
                    RDSList                   = Reactor_Services('GetReactorCassLoadHistoryRange', ReactorNo, RLDTM, SRP_Datetime('Now'))
                    
                    for each RDSRow in RDSList using @FM
                        OldReactorRec                                 = Database_Services('ReadDataRow', 'REACTOR', ReactorNo)
                        RDSNo                                = RDSRow<1,1>
                        TargetThickness                               = Xlate('RDS', RDSNo, 'THICK_TARGET_TOT', 'X', '')
	                    TargetThickness                               = OConv(TargetThickness, 'MD3')
                        NewReactorRec                        = OldReactorRec
                        CurrTubeBellJarThk = OldReactorRec<REACTOR_TUBE_BELL_JAR_THK$>
                        CurrTubeBellJarCnt = OldReactorRec<REACTOR_TUBE_BELL_JAR_WFR_CNT$>
                        
                        // Set values to 0 if blank
                        If CurrTubeBellJarThk = '' then CurrTubeBellJarThk = 0
                        If CurrTubeBellJarCnt = '' then CurrTubeBellJarCnt = 0
                        NewReactorRec<REACTOR_TUBE_BELL_JAR_THK$>     = CurrTubeBellJarThk + TargetThickness
                        NewReactorRec<REACTOR_TUBE_BELL_JAR_WFR_CNT$> = CurrTubeBellJarCnt + 1
                        Database_Services('WriteDataRow', 'REACTOR', ReactorNo, NewReactorRec)
                    Next RDSRow
                    
                    
                    //1067 Lower Quartz
                    LatestSusceptorChangeRLID = Reactor_Log_Services('GetLogsByReactorAndServID', ReactorNo, '1067')<1,4>
                    RLDTM                     = XLATE('REACTOR_LOG', LatestSusceptorChangeRLID, 'END_DTM', 'X')
                    RDSList                   = Reactor_Services('GetReactorCassLoadHistoryRange', ReactorNo, RLDTM, SRP_Datetime('Now'))
                    
                    for each RDSRow in RDSList using @FM
                        OldReactorRec      = Database_Services('ReadDataRow', 'REACTOR', ReactorNo)
                        RDSNo              = RDSRow<1,1>
                        TargetThickness                               = Xlate('RDS', RDSNo, 'THICK_TARGET_TOT', 'X', '')
	                    TargetThickness                               = OConv(TargetThickness, 'MD3')
                        NewReactorRec      = OldReactorRec
                        CurrLowerQuartzThk = OldReactorRec<REACTOR_LOWER_QUARTZ_THK$>
                        CurrLowerQuartzCnt = OldReactorRec<REACTOR_LOWER_QUARTZ_WFR$>
                        
                        // Set values to 0 if blank
                        If CurrLowerQuartzThk = '' then CurrLowerQuartzThk = 0
                        If CurrLowerQuartzCnt = '' then CurrLowerQuartzCnt = 0
                        NewReactorRec<REACTOR_LOWER_QUARTZ_THK$> = CurrLowerQuartzThk + TargetThickness
                        NewReactorRec<REACTOR_LOWER_QUARTZ_WFR$> = CurrLowerQuartzCnt + 1
                        Database_Services('WriteDataRow', 'REACTOR', ReactorNo, NewReactorRec)
                    Next RDSRow
                    
                    //699 Susceptor
                    LatestSusceptorChangeRLID = Reactor_Log_Services('GetLogsByReactorAndServID', ReactorNo, '699')<1,4>
                    RLDTM                     = XLATE('REACTOR_LOG', LatestSusceptorChangeRLID, 'END_DTM', 'X')
                    RDSList                   = Reactor_Services('GetReactorCassLoadHistoryRange', ReactorNo, RLDTM, SRP_Datetime('Now'))
                    
                    for each RDSRow in RDSList using @FM
                        OldReactorRec   = Database_Services('ReadDataRow', 'REACTOR', ReactorNo)
                        RDSNo           = RDSRow<1,1>
                        TargetThickness = Xlate('RDS', RDSNo, 'THICK_TARGET_TOT', 'X', '')
	                    TargetThickness = OConv(TargetThickness, 'MD3')
                        NewReactorRec   = OldReactorRec
                        CurrSuscThk     = OldReactorRec<REACTOR_SUSC_THK$>
                        CurrSuscCnt     = OldReactorRec<REACTOR_SUSC_WFR_CNT$>
                        
                        // Set values to 0 if blank
                        If CurrSuscThk = '' then CurrSuscThk = 0
                        If CurrSuscCnt = '' then CurrSuscCnt = 0
                        NewReactorRec<REACTOR_SUSC_THK$>     = CurrSuscThk + TargetThickness
                        NewReactorRec<REACTOR_SUSC_WFR_CNT$> = CurrSuscCnt + 1
                        Database_Services('WriteDataRow', 'REACTOR', ReactorNo, NewReactorRec)
                    Next RDSRow
                    LatestSusceptorChangeRLID = Reactor_Log_Services('GetLogsByReactorAndServID', ReactorNo, '699')<1,4>
                    RLDTM                     = XLATE('REACTOR_LOG', LatestSusceptorChangeRLID, 'END_DTM', 'X')
                    RDSList                   = Reactor_Services('GetReactorCassLoadHistoryRange', ReactorNo, RLDTM, SRP_Datetime('Now'))
                    NewReactorRec<REACTOR_SUSC_THK$> = CurrSuscThk + TargetThickness
                    NewReactorRec<REACTOR_SUSC_WFR_CNT$> = CurrSuscWfrCnt + 1
                    Database_Services('WriteDataRow', 'REACTOR', ReactorNo, NewReactorRec)
            End Case
        Next ReactorNo
end service

Service LaunchWindow()
    Start_Window('NDW_VIEW_TEST_RUN','', '10000001')
end service

Service GetTestRunObj(TestRunID)
    debug
    TestRunObj    = ''
    TestRunRec    = Test_Run_Services('GetTestRunById', TestRunID)
    //Start getting translated values for object
    RunDTM        = OConv(TestRunRec<TEST_RUN_RUN_DTM$>, 'DT')
    ReasonForTest = Xlate('TEST_RUN_TYPE', TestRunRec<TEST_RUN_RUN_TYPE_ID$>, TEST_RUN_TYPE_RUN_TYPE$, 'X')
    RelatedRDS    = TestRunRec<TEST_RUN_RDS_ID$>
    RelatedPSN    = TestRunRec<TEST_RUN_PROD_SPEC_ID$>
    EqpType       = TestRunRec<TEST_RUN_EQUIPMENT_TYPE$>
    EqpID         = TestRunRec<TEST_RUN_EQUIPMENT_ID$>
    TWKeys        = TestRunRec<TEST_RUN_TEST_RUN_WAFER_IDS$>
    TWUsageProds  = ''
    TWUsageQtys   = ''
    for each TWKey in TWKeys using @VM setting tPos
        TRWRec            = Test_Run_Services('GetTestRunWaferByID', TWKey)
        TestWaferProdName = XLATE('TEST_WAFER_PROD', TRWRec<TEST_RUN_WAFER_TEST_WAFER_PROD_ID$>, TEST_WAFER_PROD_PART_NAME$, 'X')
        Locate TestWaferProdName in TWUsageProds setting iPos then
            TWUsageProds<1,iPos> = TestWaferProdName
            TWUsageQtys<1,iPos>  = TWUsageQtys<1,iPos> + 1
        end else
            TWUsageProds<1,-1> = TestWaferProdName
            TWUsageQtys<1,-1>  = 1
        end
    Next TWKey
end service

Service WFR_STATUS(WMOKey)

    Result         = ''
    WfrStatus      = ''
    WMOSlots       = Xlate('WM_OUT', WMOKey, 'RDS', 'X')
    WMOZoneProfile = Xlate('WM_OUT', WMOKey, WM_OUT_ZONE$, 'X')
    WMORDSTestKeys = XLATE('WM_OUT', WMOKey, 'CASS_RDS_MET_KEYS', 'X')
    for each RDSNo in WMOSlots using @VM setting sPos
        
        ReactRunRec         = Database_Services('ReadDataRow', 'REACT_RUN', RDSNo)
        SlotZone            = Xlate('WM_OUT', WMOKey, WM_OUT_ZONE$, 'X')<1, sPos>
        //Get the RDS_Test for this slot.
        //Find the right RDS Test Key
        ThisSlotRDSTestKeys = ''
        for each RDSTestKey in WMORDSTestKeys using @VM
            RDSTestRec = Database_Services('ReadDataRow', 'RDS_TEST', RDSTestKey)
            If RDSTestRec<RDS_TEST_ZONE$> EQ SlotZone AND RDSTestRec<RDS_TEST_RDS_NO$> EQ RDSNo then
                ThisSlotRDSTestKeys<1, -1> = RDSTestKey
                
            end
            
        Next RDSTestKey
        RDSTestDataEntered         = XLATE('RDS_TEST', ThisSlotRDSTestKeys, 'MET_ENTERED', 'X')
        If RDSTestDataEntered NE '' then
            Locate False$ in RDSTestDataEntered using @VM setting iPos then Result = 'ULMET' else
                MetOutOfSpec = Sum(Xlate('RDS_TEST', ThisSlotRDSTestKeys, 'OUT_OF_SPEC', 'X'))
                If MetOutOfSpec then
                    //Check for an NCR
                    SlotNcr = Xlate('WM_OUT', WMOKey, 'WM_OUT_SLOT_NCR', 'X')<1, sPos>
                    If SlotNcr NE '' then
                        MetOutOfSpec = False$
                    end
                end
                If MetOutOfSpec then
                    Result = 'SPEC'
                end else
                    Result = 'ULOAD'
                end
            end
        end else
            Result = 'ULMET'
        end

        WfrStatus<sPos> = Result
    Next RDSNo
    debug
end service

Service Test()
    Debug
    RDSTestKeys     = XLATE('WM_OUT', '172172*1*10', 'CASS_RDS_MET_KEYS', 'X')
    TestDataEntered = XLATE('RDS_TEST', RDSTestKeys, 'MET_ENTERED', 'X')
    //WMOWafers   = XLATE('WM_OUT', '172172*1*10', 'WFR_STATUS', 'X')
end service

Service TestEquates()
    debug
    test = WO_MAT_MAKEUP_BOX$
end service

Service GetWWInfo()
    debug
    WWInfo = Date_Services('GetWeekNum', '20345.12345')
end service

Service PMINformation()
    
end service

Service RGBToInt()
    debug
    R          = 242
    G          = 156
    B          = 63
    IntegerVal = (B * 65536) + (G * 256) + R
end service

Service TestPMMFS()
    Debug
    
    PMRec    = Database_Services('ReadDataRow', 'PM', '10115')
    Late     = XLATE('PM', '10115', 'LATE', 'X')
    SchedQty = XLATE('PM_SPEC', PMRec<PM_PMS_ID$>, 'LATE_START_QTY', 'X')
    CompQty  = PMRec<PM_COMP_QTY$>
    
end service

Service AddComments()
    debug
    Response = Dialog_Box('NDW_ADD_COMMENT', @WINDOW)
end service

Service Get5SPMs()
    test = Pm_Services('Get5SPMs', True$)
end service


Service GetOnShiftSupervisor()
    debug
    Response = Lsl_Users_Services('GetShiftByDate', '8/23/2023 06:00')
end service

Service TriggerCassComp(WOMatKey)
    debug
    SAP_Services('AddCassCompTransaction', WOMatKey)
end service

Service TestGRProps(WOMatKey)
    *172174
    *1
    debug
    WOMatRec = Database_Services('ReadDataRow', 'WO_MAT', WOMatKey)
    GRProps  = obj_WO_Mat('GetGRProps',WOMatKey:@RM:WOMatRec)
    
end service

Service TriggerScrap(WorkOrderNo, CassNo, TransQty)
    //172172
    //1
    //2
    obj_SAP('AddTransaction','SCRAP_IN':@RM:WorkOrderNo:@RM:CassNo:@RM:TransQty)
end service

Service TriggerBatchMove
    
end service

Service TestOEE
	keyId = '20259*35*5117*U442'
	stopDTM = XLATE('DAILY_PERFORMANCE_REPORT', keyId, 'STOP_DTM', 'X')
	OEE = XLATE('DAILY_PERFORMANCE_REPORT', keyId, 'OEE_CALCULATION', 'X')
	Response = OEE
end service

Service TestZero()
    debug
    ShouldBeZero = 1 - 1
end service

Service IsRDSMetOutOfSpec(RDSNo)
    debug
    *RDSNo       = '586181'
    RDSRec      = Database_Services('ReadDataRow', 'RDS', RDSNo)
    RDSWaferZones = RDSRec<RDS_ZONE$>
    ReactorType = Xlate('RDS', RDSNo, 'REACTOR_TYPE', 'X')
    IsEpiPro    = Xlate('RDS', RDSNo, 'REACTOR_TYPE', 'X') EQ 'EPP'
    LSKeys      = XLATE('REACT_RUN',RDSNo, REACT_RUN_RDS_LAYER_KEYS$, 'X')
    for each LayerSpecKey in LSKeys using @VM setting lPos
        LSRec = Database_Services('ReadDataRow', 'RDS_LAYER', LayerSpecKey)
        IsMetOOS = XLATE('RDS_LAYER',LayerSpecKey,'TEST_OUT_OF_SPEC','X')<1, lPos>
        IF IsMetOOS then
            If IsEpiPro then
                RDSTestKey   = LSRec<RDS_LAYER_RDS_TEST_KEYS$, lPos>
                RDSTestZone  = XLate('RDS_TEST', RDSTestKey, RDS_TEST_ZONE$, 'X')
                RDSTestLayer = XLate('RDS_TEST', RDSTestKey, RDS_TEST_LS_ID$, 'X')
                WafersInZone = ''
                
                for each WaferZone in RDSWaferZones using @VM setting wPos
                    If WaferZone EQ RDSTestZone then
                        WafersInZone<-1> = wPos
                    end
                Next WaferZone
                Response = RDSTestLayer : ' Zone ' : RDSTestZone : ' Out of Spec'
            end else
                Response = 'Out of Spec'
            end
        end

    Next LayerSpec
*    TestOutOfSpec = XLATE('RDS_LAYER',LSKeys,'TEST_OUT_OF_SPEC','X')
*    MetOutOfSpec  = SUM(XLATE('RDS_LAYER',LSKeys,'TEST_OUT_OF_SPEC','X'))
    
    
    
end service


Service TestCOMB_Status()
    debug


    RDSNo          = '586181'
    RDSWOMatKey    = XLATE('RDS', RDSNo, 'WO_MAT_KEY', 'X')
    WOMatRepStatus = XLATE('WO_MAT',RDSWOMatKey,'REP_STATUS','X')
    RunStatus      = XLATE('REACT_RUN',RDSNo,'RUN_STATUS','X')
    RunStatus      = OCONV(RunStatus,'[RUN_STATUS_CONV]')
Ans = ''
BEGIN CASE
     CASE WOMatRepStatus NE '' AND RunStatus NE ''
          Ans = WOMatRepStatus
         
      CASE WOMatRepStatus = '' AND RunStatus NE ''
          Ans = RunStatus
         
      CASE WOMatRepStatus NE '' AND RunStatus = ''
           Ans = WOMatRepStatus
           
       CASE 1
            Ans = ''
END CASE
    CombStatus = Xlate('RDS', RDSNo, 'COMB_STATUS', 'X')
    Response   = CombStatus
end service

Service TestChatGPT()
    Stop
end service

Service getWOMat()
    debug
    effectedCassettes = ''
    for WONo = 171809 to 172010
        for CassNo = 1 to 99
            WOMatKey = WONo : '*' : CassNo
            WOMatQaRec = Database_Services('ReadDataRow', 'WO_MAT_QA', WOMatKey)
            Profiles = WOMatQaRec<WO_MAT_QA_PROFILE$>
            DataPoints = WOMatQARec<WO_MAT_QA_DATA_POINTS$>
            For each Profile in Profiles using @VM setting ProfIndex
                If Profile EQ '1THICK_ONLY' then

                   List            = DataPoints<1, ProfIndex>
                   IF DCOUNT(List, @SVM) LT 5 AND DCOUNT(List, @SVM) GT 0 then
                       debug
                       EffectedCassettes<-1> = WOMatKey : ',' : XLATE('WO_MAT', WOMatKey, 'RDS_NO', 'X') : CRLF$
                   end
                end
                
            Next Profile
        
            
        Next CassNo
    Next WONo
    OSWrite effectedCassettes To 'C:\users\ecouellette\desktop\effectedCassettes.csv'
end service

Service ChangeCustNoByWO(WONo, NewCustNo, NewProdVerNo, NewPSNo)
    // Update WO_LOG record
    WOLogRec     = Database_Services('ReadDataRow', 'WO_LOG', WONo)
    If Error_Services('NoError') then
        WOLogRec<WO_LOG_CUST_NO$>     = NewCustNo
        WOLogRec<WO_LOG_PROD_VER_NO$> = NewProdVerNo
        Database_Services('WriteDataRow', 'WO_LOG', WONo, WOLogRec, True$, False$, True$)
        If Error_Services('NoError') then
            WOStepKey = WONo:'*1'
            // Update WO_STEP record
            WOStepRec = Database_Services('ReadDataRow', 'WO_STEP', WOStepKey)
            If Error_Services('NoError') then
                WOStepRec<WO_STEP_PROD_SPEC_ID$> = NewPSNo
                Database_Services('WriteDataRow', 'WO_STEP', WOStepKey, WOStepRec, True$, False$, True$)
                If Error_Services('NoError') then
                    // Update RDS Keys
                    RDSKeys   = Xlate('WO_STEP', WOStepKey, 'RDS_KEY', 'X')
                    If RDSKeys NE '' then
                        For each RDSKey in RDSKeys using @VM setting vPos
                            RDSRec = Database_Services('ReadDataRow', 'RDS', RDSKey)
                            If Error_Services('NoError') then
                                RDSRec<RDS_CUST_NO$>      = NewCustNo
                                RDSRec<RDS_PROD_SPEC_ID$> = NewPSNo
                                Database_Services('WriteDataRow', 'RDS', RDSKey, RDSRec, True$, False$, True$)
                            end
                        Until Error_Services('HasError')
                        Next RDSKey
                    end
                end
            end
        end
    end
    If Error_Services('HasError') then
        Error_Services('DisplayError')
    end
    
return
end service

Service GetRDSMovesByDays(Day, FilePath)
	
	SelectSent = 'SELECT RDS WITH DATE_OUT EQ ':QUOTE(Day)
    Set_Status(0)
    RList(SelectSent, TARGET_ACTIVELIST$, "", "", "")
    

        rdsArray = ''
        IF @RecCount then
            EoF = 0
            NumKeys = @RecCount
            Cnt = 0
            
            Loop
                ReadNext rds Else EoF = 1
            until EoF
				rdsMoves = XLATE('RDS', rds, 'WAFERS_IN', 'X')
				rdsArray := rds : ',' : rdsMoves : CRLF$
            Repeat
            
        end
        OSWrite rdsArray to FilePath
        ClearSelect TARGET_ACTIVELIST$
end service

Service DetermineNearShiftChange
    debug

    CurrTime = 64320
    CurrHour = SRP_TIME('Hour', CurrTime)
end service

Service OutPutSchedule(StartDate, EndDate)
    debug
    OutputData    = ''
    StartDateConv = IConv(StartDate, 'D')
    EndDateConv   = IConv(EndDate, 'D')
    
    for i = StartDateConv to EndDateConv
        //DayStartDTM   = i : '.' : 21600
        //NightStartDTM = i : '.' : 64800
        DayStartDTM   = SRP_Datetime('AddHours', i, 7)
        NightStartDTM = SRP_Datetime('AddHours', i, 18)
        
        DayShift    = Lsl_Users_Services('GetShiftByDate', OCONV(DayStartDTM, 'DT'))<1,1>
        NightShift  = Lsl_Users_Services('GetShiftByDate', OCONV(NightStartDTM, 'DT'))<1,1>
        OutputData := OConv(i, 'D4/H') : ',' : DayShift : ' and ' : NightShift : CRLF$
    Next i
    OSWrite OutputData to 'C:\Users\MESOuellette\Desktop\ShiftCalendar.csv'
end service

Service TestMassDates()
    OutputData     = ''
    ExpectedCalRec = Database_Services('ReadDataRow', 'SYSLISTS', 'CAL_EXPECTED')
    for i = 1 to DCOUNT(ExpectedCalRec<1>, @VM)
        Dtm           = ExpectedCalRec<1, i>
        ExpectedShift = ExpectedCalRec<2, i>
        ReturnedShift = Lsl_Users_Services('GetShiftByDate', Dtm)<1,1>
        Pass          = (ExpectedShift EQ ReturnedShift)
        
        ExpectedCalRec<3,i>  = ReturnedShift
        ExpectedCalRec<4,i>  = Pass
        OutputData          := Dtm : ',' : ExpectedShift : ',' : ReturnedShift : ',' : Pass : CRLF$
    Next i
    OSWrite OutputData to 'C:\Users\MESOuellette\Desktop\CalDataTestResults.csv'
end service

Service TestShiftCalendar
    debug
    shiftCalData = ''
    for date = 20090 to 20454
        
        DayShift   = SRP_Datetime('AddHours', date, 12)
        NightShift = SRP_Datetime('AddHours', DayShift, 11)
        
        OnShiftDay    = Lsl_Users_Services('GetShiftByDate', OCONV(DayShift, 'DT'), 1)
        OnShiftNight  = Lsl_Users_Services('GetShiftByDate', OCONV(NightShift, 'DT'), 1)
        ShiftCalData := OCONV(DayShift, 'DT') : ',' : OnShiftDay<1,1> : ',' : OnShiftNight : CRLF$
    Next date
    
    OSWrite shiftCalData to 'C:\Users\MESOuellette\Desktop\CalData.csv'
end service

Service GetInboundPending
	debug
	        rv = Set_Status(0)
        LookBack        = 15 /* Days */
        StartDate       = OCONV(Date()-LookBack, 'D4/')
*        SelectStatement = "SELECT WO_MAT WITH SAP_TX_DT >= ": Quote(StartDate) :" AND WITHOUT SAP_BATCH_NO"
        RowCount        = 0
        SelectStatement = "SELECT WO_MAT WITH SAP_BATCH_NO EQ ''"
        RList(SelectStatement, 5)
        If @List_Active EQ 3 then
            SelectStatement = "SELECT WO_MAT WITH SAP_TX_DT >= ": Quote(StartDate)
            RList(SelectStatement, 5)
            If @List_Active EQ 3 then
                EOF     = False$
                Loop
                    ReadNext KeyID else EOF = True$
                Until EOF
                    WOMatRow    = Database_Services('ReadDataRow', 'WO_MAT', KeyID)
                    If WOMatRow<87> EQ '' then RowCount += 1
                Repeat
            end
        end
end service

Service CheckForNew()

Response = True$
    if xlate( 'NOTE_PTRS', @user4, 'NEW_MESSAGES', 'X' ) then
        NotePtrRec = xlate( 'NOTE_PTRS', @user4, '', 'X' )
        LOCATE 'Yes' in NotePtrRec<note_ptrs_new$> using @VM setting mPos then
                    * the top one is new meaning they got a new one
            Response = True$
        end else
            Response = False$
        end    
    end
end service

Service GetNewNotes()
    debug
    void = Jonathan_Services('CheckForNew')
end service

Service TestGit()
    debug
end service

Service TestMessages()
	debug
	if xlate( 'NOTE_PTRS', @user4, 'NEW_MESSAGES', 'X' ) then
    NotePtrRec = xlate( 'NOTE_PTRS', @user4, '', 'X' )
    if NotePtrRec<note_ptrs_new$,1> = 'Yes' then
        * the top one is new meaning they got a new one
        MsgInfo = ''
        MsgInfo<micon$> = '!'
        Mtext = 'You have a new message from ':NotePtrRec<note_ptrs_from$,1>:'.'
        MsgInfo<mtext$> = MText
        MsgInfo<mcol$> = -2
        MsgInfo<mrow$> = -2
        Void = msg( '', MsgInfo )
    end
	end
	
	NotesSent = obj_Notes_Sent('GetUserKeys','LEHRICH')
	NewMessages = XLATE('NOTE_PTRS','LEHRICH','NEW_MESSAGES','X')
	//NotesSent = obj_Notes_Sent('GetUserKeys','JONATHAN_O')
	IF NotesSent NE '' OR NewMessages > 0 THEN
    Start_Window( 'NOTE_PTRS', @WINDOW, '*CENTER', '', '' )
	END
end service

Service GetSAPYield
	debug
	counts = Gan_Services('GetYieldInfo', 223271 , '')
end service

Service DoSomething()
    
    Response = "Hello, World!"
    
End Service

Service DoSomethingWithParameters(Input, Ref Output)
    
    Output = Input:", World!"
    
End Service




