Function Test_Daniel4()
#pragma precomp SRP_PreCompiler

Declare subroutine Set_Property,  Set_Status, ErrMsg, Set_Property, obj_AppWindow, Send_Message, Logging_Services
Declare subroutine Btree.Extract, Send_Event, Security_Err_Msg, Forward_Event, End_Window, Start_Window, FTP_Services
Declare subroutine EditCell, obj_NCR, obj_Notes, Post_Event, obj_WO_Mat, obj_WO_Mat_Log, obj_WO_Wfr, obj_Tables, obj_RDS
Declare subroutine Error_Services, RDS_Services, Dialog_Box, Insert, Unlock, QA_Services, Validate, Development_Services
Declare subroutine Update_Index, Database_Services, Obj_WO_Mat_QA, Fmt, Yield, WinYield, Sleepery, Qa_Services, 
Declare subroutine Obj_Post_Log, GaN_Services, Excel_Services, obj_WO_React, Activate_Save_Select, Reduce, FSMsg
Declare subroutine SRP_Stopwatch, Copy_Record_To_SQL, SQL_Services, Material_Services, Messaging_Services
Declare subroutine Reactor_Services, Reactor_Services_Dev, SRP_Stopwatch, Btree.Extract, Set_Env, Test_Daniel3
Declare subroutine obj_WO_Log, SAP_Services, Report_Services, Make.List
Declare function Get_Property, Get_Status, Popup, Send_Message, Msg, Security_Check, Dialog_Box, RowExists, Utility
Declare function Dialog_Box, obj_WO_Log, obj_NCR, Check_Notes, obj_MUWafers, obj_WO_Mat, Error_Services, RDS_Services
Declare function MemberOf, obj_Tables, obj_RDS, Environment_Services, Logging_Services, Material_Services, ErrMsg
Declare function Work_Order_Services, RetStack, Min, Max, Obj_Prod_Spec, Insert, SRP_Trim, Xlate, Obj_Wo_Mat
Declare function Security_Services, QA_Services, Database_Services, RowExists, Rti_Lh_Info, UNICODE_ANSI, UNICODE_UTF8
Declare function index, Httpclient_Services, SRP_Encode, SRP_Decode, DirList, Obj_Rds_Test, Tool_Parms_Services
Declare function SQL_Services, RDS_Services, Obj_WM_out, Schedule_Services, Obj_Tool, SRP_Sort_Array, ICONV
Declare function Development_Services, Obj_WO_Mat_QA, SRP_Join_Arrays, NextKey, Obj_Prod_Spec, FTP_Services, SQL_Format
Declare function DateTime, GaN_Services, SRP_Array, Excel_Services, EpiPro_Services, Repository, RTI_Task_Submit
Declare function RTI_Task_Status, Rds_Services, StartDotNet, Reactor_Services, SRP_Get_FileVersion, Epi_Part_Services
Declare function Schedule_Services, List_Users, rti_lh_info_DEBUG, RTI_Lock_Owner, Popup_Services
Declare function GetCurrentProcessID, Report_Services

$INSERT ENVIRON_CONSTANTS
$INSERT POPUP_EQUATES
$INSERT MSG_EQUATES
$INSERT APPCOLORS
$INSERT WM_IN_EQUATES
$Insert WM_OUT_EQUATES
$INSERT WO_LOG_EQU
$INSERT WO_STEP_EQU
$INSERT WO_MAT_EQUATES
$INSERT ORDER_EQU
$INSERT RDS_EQUATES
$INSERT PROD_SPEC_EQU
$INSERT NOTIFICATION_EQU
$INSERT LSL_USERS_EQU
$INSERT SECURITY_RIGHTS_EQU
$INSERT LOGICAL
$INSERT RTI_LH_INFO_EQUATES
$INSERT WO_MAT_QA_EQUATES
$INSERT CUST_EPI_PART_EQUATES
$INSERT PRS_STAGE_EQUATES
$Insert RLIST_EQUATES
$Insert CLEAN_INSP_EQUATES
$Insert TOOL_PARMS_EQUATES
$Insert SCHEDULE_EQU
$Insert SCHED_DET_EQUATES
$Insert SCHEDULER_EQUATES
$Insert NCR_EQUATES
$Insert REACT_RUN_EQUATES
$Insert TOOL_EQUATES
$Insert TOOL_LOG_EQUATES
$Insert PM_EQUATES
$Insert WO_WFR_EQUATES
$Insert REVDOTNETEQUATES
$Insert REACTOR_EQUATES
$Insert RDS_TEST_EQUATES
$Insert RUN_STAGE_WFR_EQUATES

// Reduce modes (for Select statement)
Equ NEW_EXIST$ To 0 
Equ NEXT_CUR$  To 1
Equ ADD_EXIST$ To 2   

EQU COL$QA_MET_PHASE_MIN TO 17

Equ Tab$                    to \09\
Equ CRLF$                   to \0D0A\
Equ LF$                     to \0A\
Equ Comma$                  to ','

$INSERT PRINTSETUP_EQUATES


* Round:
*    
*    Ratio = '97'
*    debug
*    Ratio = OConv(IConv(Ratio, 'MD2L'), 'MD2L')
*    
* return


* FiscalYr:
*    
*    CurrDate = Date()
*    Query    = 'SELECT FISCAL_QTR WITH FISCAL_YR EQ 2022 AND WITH START_DT LT ':CurrDate:' AND WITH END_DT GT ':CurrDate
*    RList(Query, TARGET_ACTIVELIST$, '', '', '')
*    If Not(Get_Status(ErrCode)) then
*        ReadNext FiscalQtrKey then
*            WorkingDays = Xlate('FISCAL_QTR', FiscalQtrKey, 'PLAN_WORKING_DAYS', 'X')
*            Targets     = Xlate('FISCAL_QTR', FiscalQtrKey, 'THRU_TARGET', 'X')
*            Qtys        = Xlate('FISCAL_QTR', FiscalQtrKey, 'THRU_QTY', 'X')
*            Locate 'Yield_Outs' in Targets using @VM setting vPos then
*                QtrTarget   = Qtys<0, vPos>
*                DailyTarget = QtrTarget / WorkingDays
*            end
*        end
*    end
*    
*    
*    
* return


* Projected:
* 
*    Open 'RDS' to hTable then
*        Open 'DICT.RDS' to hDict then
*            Date             = Date()
*            CurrTime         = Time()
*            SearchString     = 'DATE_OUT':@VM:(Date - 1):@FM:'TIME_OUT':@VM:'>':CurrTime
*            YesterdayRDSKeys = ''
*            Option           = ''
*            Flag             = ''
*            Set_Status(0)
*            Btree.Extract(SearchString, 'RDS', hDict, YesterdayRDSKeys, Option, Flag)
*            IF Not(Get_Status(errCode)) then
*                SearchString = 'DATE_OUT':@VM:Date
*                TodayRDSKeys = ''
*                Option       = ''
*                Flag         = ''
*                Set_Status(0)
*                Btree.Extract(SearchString, 'RDS', hDict, TodayRDSKeys, Option, Flag)
*                If Not(Get_Status(errCode)) then
*                    TotalRDSKeys = SRP_Array('Join', YesterdayRDSKeys, TodayRDSKeys, 'OR', @VM)
* 
*                    debug
*                    TotalThickness24   = 0
*                    TotalReactorsOut24 = 0
*                    For each RDS in TotalRDSKeys using @VM
*                        Database_Services('ActivateRecord', 'RDS', RDS)
*                        TargetThick       = OConv({THICK_TARGET_TOT}, 'MD3')
*                        ReactorsOut       = {WAFERS_IN}
*                        TotalThickness24 += TargetThick * ReactorsOut
*                    Next RDS
*                    DayRatio       = CurrTime / 86400
*                    ProjectedThick = TotalThickness24 / DayRatio
*                    ProjectedThick = ProjectedThick[1, 'F.']
*                    ProjectedYield
* 
*                end
*            end
*        end
*    end
*    
*    
* return



Metrics:
*    
*    debug
*    JSON = Report_Services("GetMetricsJSON", Date())
*    OSWrite JSON on 'D:\FITemp\Metrics.json'
*    
* return
    
    StartDate = Date() - 9
    EndDate   = Date() - 1
    For Date = StartDate to EndDate
        Report_Services('UpdateDailyMetrics', Date)
    Next Date
    
return


ReactMode:
    
    debug
    Tool      = 'SP101'
    Tool[4,1] = ' ' 
*    CurrModeKey = Xlate('REACTOR_CHILD_KEY_IDS_NG', 48, 1, 'X')
    
return



ErrorTest:
    
    Success = False$
    If Success then
        MsgStruct         = ''
        MsgStruct<MICON$> = '*' ; // Info icon
        Msg(@Window, MsgStruct, 'OK', '', 'Success':@FM:'Report generated.')
    end else
        MsgStruct         = ''
        MsgStruct<MICON$> = 'H' ; // Error icon
        Msg(@Window, MsgStruct, 'OK', '', 'Error':@FM:'Error generating report')
    end
    
return


Process:
    
    TableName    = 'RDS_QUEUE'
    CursorVar    = ''
    Flag         = ''
    SortList     = '#RDS_NO'
    ReduceScript = 'WITH {RDS_NO} FROM 440000 TO 459999'
    Mode         = 1 ; // Use next cursor available
    EOF          = False$
    
    Reduce(ReduceScript, SortList, Mode, TableName, CursorVar, Flag)
    If Flag then
        Select TableName By SortList Using CursorVar then
            Loop 
                Readnext KeyID using CursorVar by AT else EOF = True$
            Until EOF
                Material_Services('UpdateRDSStatus', KeyID)
                If Error_Services('NoError') then
                    // Successfully updated the current status, so delete the request from the queue.
                    Database_Services('DeleteDataRow', 'RDS_QUEUE', KeyID, True$, True$)
                end
            Repeat
        End else
            status = Set_FSError()
        end
    end
    
return

