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

DECLARE FUNCTION Set_Printer,Get_Printer,Msg, Get_Status, Dialog_Box, obj_Install, Print_React_Mode_Log_Services, SRP_SORT_ARRAY
DECLARE FUNCTION FieldCount,Get_Status,Set_Status,Set_FSError,Printer_Select, SRP_Array, Excel_Services, Error_Services, Environment_Services,Datetime

DECLARE SUBROUTINE Reduce,MSG,Utility,ErrMsg, Set_Status, Btree.Extract, RList, Make.List, Print_REACT_MODE_LOG_SERVICES
Declare subroutine Excel_Services, SRP_Run_Command

// 01/11/23 - djs - This service module appears to be deprecated in favor of the REACTOR_MODE_HISTORY form.


$INSERT OIPRINT_EQUATES
$INSERT REACT_MODE_EQU
$INSERT APPCOLORS
$INSERT MSG_EQUATES
$insert LOGICAL
$INSERT REACTOR_LOG_EQUATES
$Insert REACT_MODE_EQUATES

colHeader      = 'Start DTM'						; colFmt		= '<1080'	
colHeader<1,2> = 'Elap Hrs'						    ; colFmt<1,2>	= '>720'
colHeader<1,3> = 'Mode'							    ; colFmt<1,3>	= '<1440'
colHeader<1,4> = 'Notes'							; colFmt<1,4>	= '<2160'
colHeader<1,5> = 'Category Description'				; colFmt<1,5>	= '<2100'
colHeader<1,6> = 'Start User'						; colFmt<1,6>  = '<1260'
colHeader<1,7> = 'RL ID'							; colFmt<1,7>	= '^720'
colHeader<1,8> = 'Service Description'				; colFmt<1,8>	= '<2500'
colHeader<1,9> = 'Service Notes'                    ; colFmt<1,9>   = '<2500'

font = 'Arial'
font<2> = '10'
font<4> = 1		;* Bold

GoToService

Return Response or ""

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

Service Run(ReactNo)
        
    TypeOver = ''
    TypeOver<MCAPTION$> = 'Reactor Mode Log Report'
    
    DaysToReport = Msg(@WINDOW,TypeOver,'REPORT_DAYS')
    
    IF DaysToReport = '' OR DaysToReport = CHAR(27) THEN RETURN
    
    Def         = ""
    Def<MTEXT$> = "Building report..."
    Def<MTYPE$> = "U"
    MsgUp       = Msg(@window, Def)   ;* display the processing message
    
    StartDt = Date() - DaysToReport
    IntStartDt = StartDt
    StartDt = OCONV(StartDt,'D4/')
    
    Set_Status(0)
    
    EQU TARGET_ACTIVELIST$ TO 5
    EQU TARGET_SAVELIST$ TO 4
    
    errCode = ''
    ModeList = ''
    
    ClearSelect TARGET_ACTIVELIST$
    
    //Select from old generation react_mode
    SelectSent = 'SELECT REACT_MODE WITH REACT_NO = ':ReactNo:' AND WITH START_DT > ':QUOTE(IntStartDt):'  BY-DSND START_DTM '
    Set_Status(0)
    RList(SelectSent, TARGET_ACTIVELIST$, "", "", "")
    IF Get_Status(errCode) THEN
        ErrMsg(errCode)
        RETURN
    END
    test = @RecCount 
    IF @RecCount then
        EoF = 0
        NumKeys = @RecCount
        Cnt = 0
        
        Loop
            ReadNext Mode Else EoF = 1
        until EoF
            ModeList<-1> = Mode : @VM: 'REACT_MODE'
            
        Repeat
        
    end
    GoSub ClearCursors
    //Select from New Generation react_mode
    ClearSelect TARGET_ACTIVELIST$
    SelectSent = 'SELECT REACT_MODE_NG WITH REACT_NO = ':ReactNo:' AND WITH START_DT > ':QUOTE(IntStartDt):'  BY-DSND START_DTM '
    //SelectSent = 'SELECT REACT_MODE_NG WITH REACT_NO = ':ReactNo:' AND WITH START_DT > ':StartDt:'  BY-DSND START_DTM '
    Set_Status(0)
    //RList(SelectSent, TARGET_SAVELIST$, "REACT_MODE_LIST_NG", "", "")
    RList(SelectSent, TARGET_ACTIVELIST$, "", "", "")
    IF Get_Status(errCode) THEN
        ErrMsg(errCode)
        RETURN
    END
    IF @RecCount then
        EoF = 0
        NumKeys = @RecCount
        Cnt = 0
        
        Loop
            ReadNext Mode Else EoF = 1
        until EoF
            ModeList<-1> = Mode : @VM: 'REACT_MODE_NG'
        Repeat
        
    end
    
    ModeList = SRP_Array('SortRows',ModeList, 'DL1', 'LIST', @FM, @VM, 0)
    
    
    **START PRINTING PROCESS**
    
    FileName	= 'Print Reactor Mode Log':@VM:'6'
    Title		= 'Printing Reactor Mode Log':@VM:'Report'
    
    TopMargin		= 0.5
    BottomMargin	= 0.5
    LeftMargin		= 0.25
    RightMargin		= 0.25
    
    Margins		= LeftMargin:@FM:TopMargin:@FM:RightMargin:@FM:BottomMargin
    
    PageSetup	= '1'		;* LandScape
    PrintSetup	= '2'		;* Preview Normal
    * PrintSetup<1,2> = '5'	;* Print & PDF buttons
    PrintSetup<1,2> = '0'	;* Show all buttons
    PrintSetup<1,5> = '1'	;* Page Range
    PrintSetup<1,6> = 7		;* full mouse and keyboard support
    
    * PrintPath = Printer_Select('',1)		;* Get Default printer path
    PrintPath        = ''
    PrintSetup<1, 4> = 2 ; // StartMode = hidden
    stat             = Set_Printer("INIT",FileName,Title,Margins,PageSetup,PrintSetup,PrintPath)

    IF stat < 0 THEN  GOTO OIPrint_Err
    
    Header		= @VM:obj_Install('Get_Prop','CompTitle'):' Reactor Mode Log - Reactor ':ReactNo:' - Last ':DaysToReport:' days'
    Header<2>	= @VM:''
    
    font = 'Arial'
    font<2> = '10'
    font<4> = 1		;* Bold
    
    stat = Set_Printer("FONTHEADFOOT", font)
    stat = Set_Printer("HEADER",Header)
    
    footer = " 'D' 'T'":@VM:@VM:" Page: 'P'"
    colfooter = " "
    
    stat = Set_Printer("FOOTER",footer,colfooter)
    
    @RECCOUNT	= 0
    FirstPass	= 1
    LastRecord	= 0
    ReadErr		= 0
    FirstLine	= 1
    
    *    colHeader      = 'Start DTM'						; colFmt		= '<1080'	
    *        colHeader<1,2> = 'Elap Hrs'						    ; colFmt<1,2>	= '>720'
    *        colHeader<1,3> = 'Mode'							    ; colFmt<1,3>	= '<1440'
    *        colHeader<1,4> = 'Notes'							; colFmt<1,4>	= '<2160'	
    *        colHeader<1,5> = 'RL ID'							; colFmt<1,5>	= '^720'
    *        colHeader<1,6> = 'Category Description'				; colFmt<1,6>	= '<3240'
    *        colHeader<1,7> = 'Service Description'				; colFmt<1,7>	= '<4500'
    *        colHeader<1,8> = 'Start User'						; colFmt<1,8>  = '<1260'
    
    colHeader      = 'Start DTM'						; colFmt		= '<1080'	
    colHeader<1,2> = 'Elap Hrs'						    ; colFmt<1,2>	= '>720'
    colHeader<1,3> = 'Mode'							    ; colFmt<1,3>	= '<1440'
    colHeader<1,4> = 'Notes'							; colFmt<1,4>	= '<2160'
    colHeader<1,5> = 'Category Description'				; colFmt<1,5>	= '<2100'
    colHeader<1,6> = 'Start User'						; colFmt<1,6>  = '<1260'
    colHeader<1,7> = 'RL ID'							; colFmt<1,7>	= '^720'
    colHeader<1,8> = 'Service Description'				; colFmt<1,8>	= '<2500'
    colHeader<1,9> = 'Service Notes'                    ; colFmt<1,9>   = '<2500'
    
    Print_React_Mode_Log_Services('PrintHeader', colHeader) 
    Print_React_Mode_Log_Services('ReadRecords',ModeList)
    GoSub   Bail    
    
End Service

Service ReadRecords(ModeList)
    ReactModeKeyIndex = 1
    For each ReactModeKey in ModeList using @FM
        
        //StartDTM		= OCONV({START_DTM},'DT2/^HS')
        StartDTM        = OCONV(XLATE(ModeList<ReactModeKeyIndex,2>, ModeList<ReactModeKeyIndex,1>, 'START_DTM', 'X'),'DT4/^S')
        //StopDTM 		= OCONV({STOP_DTM},'DT2/^HS')
        StopDTM         = OCONV(XLATE(ModeList<ReactModeKeyIndex,2>, ModeList<ReactModeKeyIndex,1>,'STOP_DTM','X'),'DT4/^S')
        //ElapsedHrs		= OCONV({ELAP_HRS},'MD2,')
        ElapsedHrs      = OCONV(XLATE(ModeList<ReactModeKeyIndex,2>, ModeList<ReactModeKeyIndex,1>,'ELAP_HRS','X'),'MD2,')
        //Mode			= OCONV({MODE},'[REACT_MODE_CONV]')
        if ReactModeKey<1,2> eq 'REACT_MODE' then
            Mode            = OCONV(XLATE('REACT_MODE', ReactModeKey<1,1>, 'MODE', 'X' ),'[REACT_MODE_CONV]')
        end else
            Mode            = XLATE('REACT_MODE_NG', ReactModeKey<1,1>, 'MODE', 'X' )
        end
        
        //StartRLID		= {START_RL_ID}
        StartRLID       = XLATE(ModeList<ReactModeKeyIndex,2>, ModeList<ReactModeKeyIndex,1>, 'START_RL_ID', 'X')
        //ProbCatIDs		= {PROB_CAT_ID}
        ProbCatIDs      = XLATE(ModeList<ReactModeKeyIndex,2>, ModeList<ReactModeKeyIndex,1>, 'PROB_CAT_ID', 'X')
        //ProbCatDescs	= {PROB_CAT_DESC}
        ProbCatDescs    = XLATE(ModeList<ReactModeKeyIndex,2>, ModeList<ReactModeKeyIndex,1>, 'PROB_CAT_DESC', 'X')
        //ServIDs			= {SERV_ID}
        ServIDs         = XLATE(ModeList<ReactModeKeyIndex,2>, ModeList<ReactModeKeyIndex,1>, 'SERV_ID', 'X')
        //ServDescs		= {SERV_DESC}
        ServDescs       = XLATE(ModeList<ReactModeKeyIndex,2>, ModeList<ReactModeKeyIndex,1>, 'SERV_DESC', 'X')
        //StartUser		= {START_USER}
        StartUser       = XLATE(ModeList<ReactModeKeyIndex,2>, ModeList<ReactModeKeyIndex,1>, 'START_USER', 'X')
        //StopUser		= {STOP_USER}
        StopUser        = XLATE(ModeList<ReactModeKeyIndex,2>, ModeList<ReactModeKeyIndex,1>, 'STOP_USER', 'X')
        //Notes			= {START_NOTES}
        Notes           = XLATE(ModeList<ReactModeKeyIndex,2>, ModeList<ReactModeKeyIndex,1>, 'START_NOTES', 'X')
        RLNotes         = XLATE('REACTOR_LOG',StartRLID, REACTOR_LOG_NOTES$, 'X')
        
        //SWAP ' ' WITH CRLF$ IN StartDTM
        //SWAP ' ' WITH CRLF$ IN StopDTM
        
        FOR I = 1 TO COUNT(ProbCatIDs,@VM) + (ProbCatIDs NE '')
            ProbCatDescs<1,I> = ProbCatIDs<1,I>:' - ':ProbCatDescs<1,I>
        NEXT I
        
        FOR I = 1 TO COUNT(ServIDs,@VM) + (ServIDs NE '')
            ServDescs<1,I> = ServIDs<1,I>:' - ':ServDescs<1,I>
        NEXT I
        
        SWAP @VM WITH CRLF$ IN ProbCatDescs
        SWAP @VM WITH CRLF$ IN ServDescs
        
        
        *        colData = ''
        *        colData		= StartDTM
        *        
        *        colData<1,2> = ElapsedHrs
        *        colData<1,3> = Mode
        *        colData<1,4> = Notes
        *        colData<1,5> = StartRLID
        *        colData<1,6> = ProbCatDescs
        *        colData<1,7> = ServDescs
        *        colData<1,8> = StartUser
        
        colData		= StartDTM
        
        colData<1,2> = ElapsedHrs
        colData<1,3> = Mode
        colData<1,4> = Notes
        colData<1,5> = ProbCatDescs
        colData<1,6> = StartUser
        colData<1,7> = StartRLID
        colData<1,8> = ServDescs
        colData<1,9> = RLNotes
        
        
        
        
        fontSpacing = 100
        PRINT_REACT_MODE_LOG_SERVICES('PrintData',colData)
        ReactModeKeyIndex = ReactModeKeyIndex + 1
        //GOSUB PrintTable    
    Next ReactModeKey
    
    //gosub Bail
end service

Service PrintHeader()
    stat = Set_Printer('CALCTABLE',colHeader)
    TableSize = Get_Printer('CALCTABLE')
    TableHeight = TableSize<2>
    Test = Get_Printer('POS')<2>
    stat = Set_Printer('ADDTABLE',colFmt,'',colData,LTGREY$,'',1,TB_ALL)
    
    
    //stat = Set_Printer('PAGEBREAK')
    
    //FirstLine = 0
    font<2> = 8
    font<4> = 1		;* Bold
    stat = Set_Printer('FONT',font,'100')
    stat = Set_Printer('ADDTABLE',colFmt,colHeader,'',LTGREY$,'',0,TB_ALL)
    font<4> = 0
    stat = Set_Printer('FONT',font,fontSpacing)
    //stat = Set_Printer('ADDTABLE',colFmt,'',colData,LTGREY$,'',0,7)
end service

Service PrintData(colData)
    
    stat = Set_Printer('CALCTABLE',colFmt:@FM:colData)
    TableSize = Get_Printer('CALCTABLE')
    TableHeight = TableSize<2>
    Test = Get_Printer('POS')<2>
    stat = Set_Printer('ADDTABLE',colFmt,'',colData,LTGREY$,'',1,TB_ALL)
    
    font<2> = 8
    font<4> = 0
    stat = Set_Printer('FONT',font,fontSpacing)
    //stat = Set_Printer('ADDTABLE',colFmt,'',colData,LTGREY$,'',1,TB_ALL)
    
    
end service

Service RunAllReport()
    DialogResult = Dialog_Box('DIALOG_REACT_MODE_EXPORT',@WINDOW,'')
    //FromDate     = ICONV(DialogResult<1>, "DT")
    //ToDate       = ICONV(DialogResult<2>, "DT")
    FromDate = DialogResult<1>
    ToDate = DialogResult<2>
    FilePath     = DialogResult<3>
    //Get All Modes
    AllModes     = Print_React_Mode_Log_Services('GetAllModes',FromDate,ToDate)
    BottleChanges = Print_React_Mode_Log_Services('GetAllBottleChange', FromDate, ToDate)
    ASMModes     = ''
    HTRModes     = ''
    EPPModes     = ''
    GaNModes     = ''
    
    //Sort each according to ReactorType
    for each mode in AllModes using @FM
        if mode<1,2> EQ 'ASM' OR mode<1,2> EQ 'ASM+' then
            ASMModes := mode : @FM
        end
        if mode<1,2> EQ 'HTR' then
            HTRModes := mode : @FM
        end
        if mode<1,2> EQ 'EPP' then
            EPPModes := mode : @FM
        end
        if mode<1,2> EQ 'GAN' then
            GaNModes := mode : @FM
        end
    Next mode
    
    //Sort by Reactor for each list
    ASMModes = SRP_SORT_Array(ASMModes, "AL1":@FM:"AL3",1)
    HTRModes = SRP_SORT_Array(HTRModes, "AL1":@FM:"AL3",1)
    EPPModes = SRP_SORT_Array(EPPModes, "AL1":@FM:"AL3",1)
    GaNModes = SRP_SORT_Array(GaNModes, "AL1":@FM:"AL3",1)
    BottleChanges = SRP_SORT_ARRAY(BottleChanges, "AL2", 1)
    //dataarray = SRP_SORT_Array(dataarray, "DR3", 1)
    TemplatePath = Environment_Services('GetApplicationRootPath') : '\Reports\ReactMode\All_Reactor_Modes.xlsx' 
    objDocument = Excel_Services('OpenDocument',TemplatePath)
    If Error_Services('HasError') then
        test = Error_Services('GetCode')
    end
    //Create ASM,ASM+ rows
    CellRow = 1
    LastReactorNo = ''
    For Each ReportRow in ASMModes using @FM
        ReactorNo = ReportRow<1,1>
        IF LastReactorNo NE ReactorNo  AND ReactorNo NE '' AND LastReactorNo NE '' then
            CellRow += 2
        end else
            CellRow += 1 
        end
        Excel_Services('SetCellValue', objDocument, 'ASM-ASM+', 'A', CellRow, ReportRow<1,1>)
        Excel_Services('SetCellValue', objDocument, 'ASM-ASM+', 'B', CellRow, ReportRow<1,2>)
        Excel_Services('SetCellValue', objDocument, 'ASM-ASM+', 'C', CellRow, OCONV(ReportRow<1,3>,'DT2/^HS'))
        Excel_Services('SetCellValue', objDocument, 'ASM-ASM+', 'D', CellRow, ReportRow<1,4>)
        Excel_Services('SetCellValue', objDocument, 'ASM-ASM+', 'E', CellRow, ReportRow<1,5>)
        Excel_Services('SetCellValue', objDocument, 'ASM-ASM+', 'F', CellRow, ReportRow<1,6>)
        //Services Required
        ServiceCats   = ReportRow<1,7>
        for ServiceCat = 1 to DCount(ServiceCats, @SVM)
            ServiceCats<1,1,ServiceCat> = ' - ' : ServiceCats<1,1,ServiceCat>
        Next ServiceCat
        swap @svm with CRLF$ in ServiceCats
        Excel_Services('SetCellValue', objDocument, 'ASM-ASM+', 'G', CellRow, ServiceCats)
        Excel_Services('SetCellValue', objDocument, 'ASM-ASM+', 'H', CellRow, ReportRow<1,8>)
        Excel_Services('SetCellValue', objDocument, 'ASM-ASM+', 'I', CellRow, ReportRow<1,9>)
        //Services Performed
        ServiceDescs = ReportRow<1,10>
        for ServiceDesc = 1 to DCount(ServiceDescs, @SVM)
            ServiceDescs<1,1,ServiceDesc> = ' - ' : ServiceDescs<1,1,ServiceDesc>
        Next ServiceDesc
        swap @svm with CRLF$ in ServiceDescs
        Excel_Services('SetCellValue', objDocument, 'ASM-ASM+', 'J', CellRow, ServiceDescs)
        Excel_Services('SetCellValue', objDocument, 'ASM-ASM+', 'K', CellRow, ReportRow<1,11>)
        LastReactorNo = ReactorNo
    Next ReportRow
    
    //Create HTR rows
    CellRow = 1
    LastReactorNo = ''
    For Each ReportRow in HTRModes using @FM
        ReactorNo = ReportRow<1,1>
        IF LastReactorNo NE ReactorNo  AND ReactorNo NE '' AND LastReactorNo NE ''  then
            CellRow += 2
        end else
            CellRow += 1 
        end
        Excel_Services('SetCellValue', objDocument, 'HTR', 'A', CellRow, ReportRow<1,1>)
        Excel_Services('SetCellValue', objDocument, 'HTR', 'B', CellRow, ReportRow<1,2>)
        Excel_Services('SetCellValue', objDocument, 'HTR', 'C', CellRow, OCONV(ReportRow<1,3>,'DT2/^HS'))
        Excel_Services('SetCellValue', objDocument, 'HTR', 'D', CellRow, ReportRow<1,4>)
        Excel_Services('SetCellValue', objDocument, 'HTR', 'E', CellRow, ReportRow<1,5>)
        Excel_Services('SetCellValue', objDocument, 'HTR', 'F', CellRow, ReportRow<1,6>)
        //Services Required
        ServiceCats   = ReportRow<1,7>
        for ServiceCat = 1 to DCount(ServiceCats, @SVM)
            ServiceCats<1,1,ServiceCat> = ' - ' : ServiceCats<1,1,ServiceCat>
        Next ServiceCat
        swap @svm with CRLF$ in ServiceCats
        Excel_Services('SetCellValue', objDocument, 'HTR', 'G', CellRow, ServiceCats)
        Excel_Services('SetCellValue', objDocument, 'HTR', 'H', CellRow, ReportRow<1,8>)
        Excel_Services('SetCellValue', objDocument, 'HTR', 'I', CellRow, ReportRow<1,9>)
        //Services Performed
        ServiceDescs = ReportRow<1,10>
        for ServiceDesc = 1 to DCount(ServiceDescs, @SVM)
            ServiceDescs<1,1,ServiceDesc> = ' - ' : ServiceDescs<1,1,ServiceDesc>
        Next ServiceDesc
        swap @svm with CRLF$ in ServiceDescs
        Excel_Services('SetCellValue', objDocument, 'HTR', 'J', CellRow, ServiceDescs)
        Excel_Services('SetCellValue', objDocument, 'HTR', 'K', CellRow, ReportRow<1,11>)
        LastReactorNo  = ReactorNo
    Next ReportRow
    
    //Create EPP rows
    CellRow = 1
    LastReactorNo = ''
    For Each ReportRow in EPPModes using @FM
        ReactorNo = ReportRow<1,1>
        IF LastReactorNo NE ReactorNo AND ReactorNo NE '' AND LastReactorNo NE '' then
            CellRow += 2
        end else
            CellRow += 1 
        end
        Excel_Services('SetCellValue', objDocument, 'EPP', 'A', CellRow, ReportRow<1,1>)
        Excel_Services('SetCellValue', objDocument, 'EPP', 'B', CellRow, ReportRow<1,2>)
        Excel_Services('SetCellValue', objDocument, 'EPP', 'C', CellRow, OCONV(ReportRow<1,3>,'DT2/^HS'))
        Excel_Services('SetCellValue', objDocument, 'EPP', 'D', CellRow, ReportRow<1,4>)
        Excel_Services('SetCellValue', objDocument, 'EPP', 'E', CellRow, ReportRow<1,5>)
        Excel_Services('SetCellValue', objDocument, 'EPP', 'F', CellRow, ReportRow<1,6>)
        //Services Required
        ServiceCats   = ReportRow<1,7>
        for ServiceCat = 1 to DCount(ServiceCats, @SVM)
            ServiceCats<1,1,ServiceCat> = ' - ' : ServiceCats<1,1,ServiceCat>
        Next ServiceCat
        swap @svm with CRLF$ in ServiceCats
        Excel_Services('SetCellValue', objDocument, 'EPP', 'G', CellRow, ServiceCats)
        Excel_Services('SetCellValue', objDocument, 'EPP', 'H', CellRow, ReportRow<1,8>)
        Excel_Services('SetCellValue', objDocument, 'EPP', 'I', CellRow, ReportRow<1,9>)
        //Services Performed
        ServiceDescs = ReportRow<1,10>
        for ServiceDesc = 1 to DCount(ServiceDescs, @SVM)
            ServiceDescs<1,1,ServiceDesc> = ' - ' : ServiceDescs<1,1,ServiceDesc>
        Next ServiceDesc
        swap @svm with CRLF$ in ServiceDescs
        Excel_Services('SetCellValue', objDocument, 'EPP', 'J', CellRow, ServiceDescs)
        Excel_Services('SetCellValue', objDocument, 'EPP', 'K', CellRow, ReportRow<1,11>)
        LastReactorNo  = ReactorNo
    Next ReportRow
    
    //Create GaN rows
    CellRow       = 1
    LastReactorNo = ''
    For Each ReportRow in GaNModes using @FM
        ReactorNo = ReportRow<1,1>
        IF LastReactorNo NE ReactorNo  AND ReactorNo NE '' AND LastReactorNo NE '' then
            CellRow += 2
        end else
            CellRow += 1 
        end       
        Excel_Services('SetCellValue', objDocument, 'GaN', 'A', CellRow, ReportRow<1,1>)
        Excel_Services('SetCellValue', objDocument, 'GaN', 'B', CellRow, ReportRow<1,2>)
        Excel_Services('SetCellValue', objDocument, 'GaN', 'C', CellRow, OCONV(ReportRow<1,3>,'DT2/^HS'))
        Excel_Services('SetCellValue', objDocument, 'GaN', 'D', CellRow, ReportRow<1,4>)
        Excel_Services('SetCellValue', objDocument, 'GaN', 'E', CellRow, ReportRow<1,5>)
        Excel_Services('SetCellValue', objDocument, 'GaN', 'F', CellRow, ReportRow<1,6>)
        //Services Required
        ServiceCats   = ReportRow<1,7>
        for ServiceCat = 1 to DCount(ServiceCats, @SVM)
            ServiceCats<1,1,ServiceCat> = ' - ' : ServiceCats<1,1,ServiceCat>
        Next ServiceCat
        swap @svm with CRLF$ in ServiceCats
        Excel_Services('SetCellValue', objDocument, 'GaN', 'G', CellRow, ServiceCats)
        Excel_Services('SetCellValue', objDocument, 'GaN', 'H', CellRow, ReportRow<1,8>)
        Excel_Services('SetCellValue', objDocument, 'GaN', 'I', CellRow, ReportRow<1,9>)
        //Services Performed
        ServiceDescs = ReportRow<1,10>
        for ServiceDesc = 1 to DCount(ServiceDescs, @SVM)
            ServiceDescs<1,1,ServiceDesc> = ' - ' : ServiceDescs<1,1,ServiceDesc>
        Next ServiceDesc
        swap @svm with CRLF$ in ServiceDescs
        Excel_Services('SetCellValue', objDocument, 'GaN', 'J', CellRow, ServiceDescs)
        Excel_Services('SetCellValue', objDocument, 'GaN', 'K', CellRow, ReportRow<1,11>)
        LastReactorNo  = ReactorNo
    Next ReportRow
        
    //Create Bottle Changes
    CellRow = 1
    LastReactorNo = ''
    For Each ReportRow in BottleChanges using @FM
        CellRow += 1 
        Excel_Services('SetCellValue', objDocument, 'Bottle Changes', 'A', CellRow, ReportRow<1,1>)
        Excel_Services('SetCellValue', objDocument, 'Bottle Changes', 'B', CellRow, OCONV(ReportRow<1,2>,'DT2/^HS'))
        Excel_Services('SetCellValue', objDocument, 'Bottle Changes', 'C', CellRow, OCONV(ReportRow<1,3>,'DT2/^HS'))
        Excel_Services('SetCellValue', objDocument, 'Bottle Changes', 'D', CellRow, ReportRow<1,6>)
        Excel_Services('SetCellValue', objDocument, 'Bottle Changes', 'E', CellRow, ReportRow<1,4>)
        Excel_Services('SetCellValue', objDocument, 'Bottle Changes', 'F', CellRow, ReportRow<1,5>)
    Next ReportRow
    
    FileSaveName = 'REACT_MODE_LOG_': OConv(DateTime(), 'DT2^HS ') : '.xlsx'
    //Excel_Services('SaveDocument',objDocument,FilePath : 'REACT_MODE_LOG.xlsx')
    Excel_Services('SaveDocument',objDocument,FilePath : FileSaveName)
    If Error_Services('HasError') then
        test = Error_Services('GetMessage')
    end
    Excel_Services('CloseDocument', objDocument)
    IF FilePath NE '' then
        SRP_Run_Command('start excel "':FilePath : FileSaveName:'"', 'VAR')
    end
    
    
    
end service

Service GetAllModes(FromTime, ToTime)
    //if @USER4 EQ 'JONATHAN_O' THEN DEBUG
    Response = ''
    //if @user4 eq 'JONATHAN_O' then debug
    EQU REACTOR_NO$             TO 1
    EQU REACTOR_TYPE$           To 2
    EQU START_DTM$              TO 3
    Equ ELAPSED_HOURS$          TO 4
    EQU REACTOR_MODE$           TO 5
    EQU Notes$                  TO 6
    EQU CATEGORY_DESCRIPTION$   TO 7
    EQU START_USER$             TO 8
    EQU REACTOR_LOG_ID$         TO 9
    EQU SERVICE_DESCRIPTION$    TO 10
    EQU SERVICE_NOTES$          TO 11
    
    DayBegin = Field(FromTime, ' ', 1)
    FromTime     = ICONV(FromTime, "DT")
    ToTime       = ICONV(ToTime, "DT")
    IF FromTime NE '' AND ToTime NE '' then
    	//Old Modes
        SelectSent = 'SELECT REACT_MODE WITH START_DT >= ':QUOTE(DayBegin):' AND WITH START_DTM >= ':QUOTE(FromTime):'AND WITH START_DTM <= ':QUOTE(ToTime):' BY-DSND START_DTM '
        Set_Status(0)
        RList(SelectSent, TARGET_ACTIVELIST$, "", "", "")
        IF Get_Status(errCode) THEN
            ErrMsg(errCode)
            RETURN
        END
        modeArray = ''
        IF @RecCount then
            EoF = 0
            NumKeys = @RecCount
            Cnt = 0
            
            Loop
                ReadNext Mode Else EoF = 1
            until EoF
                
                ServiceCategories                   = XLATE('REACT_MODE', Mode, 'PROB_CAT_DESC', 'X')
                swap @VM with @svm in ServiceCategories
                ServiceDescs                        = XLATE('REACT_MODE', Mode, 'SERV_DESC', 'X')
                swap @VM with @svm in ServiceDescs
                
                ReactorLogId                        = XLATE('REACT_MODE', Mode, 'START_RL_ID', 'X')
                ReactorNo                           = Field(Mode,'*',1)
                ReactorType                         = XLATE('REACTOR', ReactorNo, 1, 'X')
                RowToAdd                            = ''
                RowToAdd <1,REACTOR_NO$>            = ReactorNo
                RowToAdd <1,REACTOR_TYPE$>          = ReactorType
                RowToAdd <1,START_DTM$>             = XLATE('REACT_MODE', Mode, 'START_DTM', 'X')
                RowToAdd <1,ELAPSED_HOURS$>         = OCONV(XLATE('REACT_MODE', Mode,'ELAP_HRS','X'),'MD2,')
                RowToAdd <1,REACTOR_MODE$>          = OCONV(XLATE('REACT_MODE', Mode, 'MODE', 'X' ),'[REACT_MODE_CONV]')
                RowToAdd <1,Notes$>                 = XLATE('REACT_MODE', Mode, 'START_NOTES', 'X')
                RowToAdd <1,CATEGORY_DESCRIPTION$>  = ServiceCategories
                RowToAdd <1,START_USER$>            = XLATE('REACT_MODE', Mode, 'START_USER', 'X')
                RowToAdd <1,REACTOR_LOG_ID$>        = ReactorLogId
                RowToAdd <1,SERVICE_DESCRIPTION$>   = ServiceDescs
                ServiceNotes                        = XLATE('REACTOR_LOG',ReactorLogId, REACTOR_LOG_NOTES$, 'X')
                NotesDTMs                           = Xlate('REACTOR_LOG',ReactorLogId, REACTOR_LOG_NOTES_DTMS$, 'X')
                NotesUsers                          = Xlate('REACTOR_LOG',ReactorLogId, REACTOR_LOG_NOTES_USERS$, 'X')
                FormattedServiceNotes               = ''
                For each ServiceNote in ServiceNotes using @VM setting vPos
                    FormattedServiceNotes<0, vPos> = OConv(NotesDTMs<0, vPos>, 'DT2/^H'):' - ':OConv(NotesUsers<0, vPos>, '[CONV_XLATE,LSL_USERS*FIRST_LAST]'):' - ':ServiceNote
                Next ServiceNote
                Swap @VM with CRLF$ in FormattedServiceNotes
                RowToAdd <1,SERVICE_NOTES$>  = FormattedServiceNotes
                modeArray                   := RowToAdd : @FM
            Repeat
            
        end
        
        GoSub ClearCursors
        ClearSelect TARGET_ACTIVELIST$
        //New Modes
        SelectSent = 'SELECT REACT_MODE_NG WITH START_DT >= ':QUOTE(DayBegin):' AND WITH START_DTM >= ':QUOTE(FromTime):'AND WITH START_DTM <= ':QUOTE(ToTime):' BY-DSND START_DTM '
        Set_Status(0)
        RList(SelectSent, TARGET_ACTIVELIST$, "", "", "")
        IF Get_Status(errCode) THEN
            ErrMsg(errCode)
            RETURN
        END
        IF @RecCount then
            EoF = 0
            NumKeys = @RecCount
            Cnt = 0
            
            Loop
                ReadNext Mode Else EoF = 1
            until EoF
                
                ServiceCategories                   = XLATE('REACT_MODE_NG', Mode, 'PROB_CAT_DESC', 'X')
                swap @VM with @svm in ServiceCategories
                ServiceDescs                        = XLATE('REACT_MODE_NG', Mode, 'SERV_DESC', 'X')
                swap @VM with @svm in ServiceDescs
                
                ReactorLogId                        = XLATE('REACT_MODE_NG', Mode, 'START_RL_ID', 'X')
                ReactorNo                           = Field(Mode,'*',1)
                ReactorType                         = XLATE('REACTOR', ReactorNo, 1, 'X')
                RowToAdd                            = ''
                RowToAdd <1,REACTOR_NO$>            = ReactorNo
                RowToAdd <1,REACTOR_TYPE$>          = ReactorType
                RowToAdd <1,START_DTM$>             = XLATE('REACT_MODE_NG', Mode, 'START_DTM', 'X')
                RowToAdd <1,ELAPSED_HOURS$>         = OCONV(XLATE('REACT_MODE_NG', Mode,'ELAP_HRS','X'),'MD2,')
                RowToAdd <1,REACTOR_MODE$>          = OCONV(XLATE('REACT_MODE_NG', Mode, 'MODE', 'X' ),'[REACT_MODE_CONV]')
                RowToAdd <1,Notes$>                 = XLATE('REACT_MODE_NG', Mode, 'START_NOTES', 'X')
                RowToAdd <1,CATEGORY_DESCRIPTION$>  = ServiceCategories
                RowToAdd <1,START_USER$>            = XLATE('REACT_MODE_NG', Mode, 'START_USER', 'X')
                RowToAdd <1,REACTOR_LOG_ID$>        = ReactorLogId
                RowToAdd <1,SERVICE_DESCRIPTION$>   = ServiceDescs
               ServiceNotes = XLATE('REACTOR_LOG',ReactorLogId, REACTOR_LOG_NOTES$, 'X')
                NotesDTMs                           = Xlate('REACTOR_LOG',ReactorLogId, REACTOR_LOG_NOTES_DTMS$, 'X')
                NotesUsers                          = Xlate('REACTOR_LOG',ReactorLogId, REACTOR_LOG_NOTES_USERS$, 'X')
                FormattedServiceNotes               = ''
                For each ServiceNote in ServiceNotes using @VM setting vPos
                    FormattedServiceNotes<0, vPos> = OConv(NotesDTMs<0, vPos>, 'DT2/^H'):' - ':OConv(NotesUsers<0, vPos>, '[CONV_XLATE,LSL_USERS*FIRST_LAST]'):' - ':ServiceNote
                Next ServiceNote
                Swap @VM with CRLF$ in FormattedServiceNotes
                RowToAdd <1,SERVICE_NOTES$>  = FormattedServiceNotes
                modeArray                          := RowToAdd : @FM
            Repeat
            
        end
        
        GoSub ClearCursors
        ClearSelect TARGET_ACTIVELIST$
        
        Response = modeArray 
    end else
        Response = 'Missing a time parameter, unable to run.'
    end
    
    
end service

Service GetAllBottleChange(FromTime, ToTime)
    
    EQU ReactorNo$  to 1
    EQU StartDTM$   to 2
    Equ StopDTM$    to 3
    Equ RLNotes$    to 4
    Equ Technician$ to 5
    Equ RLService$  to 6
    
    
    Response = ''
    //if @user4 eq 'JONATHAN_O' then debug
    IF FromTime NE '' AND ToTime NE '' then
        DayFrom  = Field(FromTime, ' ', 1)
        //ICONV(DialogResult<2>, "DT")
        TimeFrom = Field(ICONV(FromTime, "DT"), '.', 2)
        DayTo    = Field(ToTime, ' ', 1)
        TimeTo   = Field(ICONV(ToTime, "DT"), '.', 2)
            
        SelectSent  = 'SELECT REACTOR_LOG WITH REACTOR LE 1 AND WITH START_DATE GE ' : Quote(DayFrom) : ' AND WITH START_TIME GE ' : Quote(TimeFrom) : ' '
        SelectSent := 'AND WITH START_DATE LE ' : Quote(DayTo)
        Set_Status(0)
        RList(SelectSent, TARGET_ACTIVELIST$, "", "", "")
        IF Get_Status(errCode) THEN
            ErrMsg(errCode)
            RETURN
        END
        
        //Here
        logArray      = ''
        logArrayIndex = 1
        IF @RecCount then
            EoF = 0
            NumKeys = @RecCount
            Cnt = 0
            
            Loop
                ReadNext log Else EoF = 1
            until EoF
                ReactorLogRec = Xlate('REACTOR_LOG', log, '', 'X')
                ReactorNo     = ReactorLogRec<REACTOR_LOG_REACTOR$>
                StartDT       = ReactorLogRec<REACTOR_LOG_START_DATE$>
                StartTime     = ReactorLogRec<REACTOR_LOG_START_TIME$>
                StartDTM      = StartDT : '.' : StartTime
                StopDT        = ReactorLogRec<REACTOR_LOG_END_DATE$>
                StopTime      = ReactorLogRec<REACTOR_LOG_END_TIME$>
                StopDTM       = StopDT : '.' : StopTime
                Notes         = ReactorLogRec<REACTOR_LOG_NOTES$>
                swap @TM with ' ' in Notes
                Technician    = ReactorLogRec<REACTOR_LOG_ENTRY_ID$>
                ServiceID     = ReactorLogRec<REACTOR_LOG_REACT_SERV_ID$>
                ServiceName   = Xlate('REACT_SERVS', ServiceID, 1, 'X')
                
                logArray<logArrayIndex, ReactorNo$>   = ReactorNo
                logArray<logArrayIndex, StartDTM$>    = StartDTM
                logArray<logArrayIndex, StopDTM$>     = StopDTM 
                logArray<logArrayIndex, RLNotes$>     = Notes
                logArray<logArrayIndex, Technician$>  = Technician
                logArray<logArrayIndex, RLService$>   = ServiceName
                logArrayIndex                        += 1
            Repeat
            
        end
        //to here
        GoSub ClearCursors
        ClearSelect TARGET_ACTIVELIST$
        Response = logArray
    end else
        Response = 'Missing a time parameter, unable to run.'
    end
    
    
    
    
    //SELECT REACTOR_LOG WITH REACTOR LE 1 AND WITH START_DATE GT 19500
end service
* * * * * * *
OIPrint_Err:
* * * * * * *
    
    *Set Error for OIPrint function and return to calling procedure
    
    Msg('',stat)
    
    Error_Msg	= 'Set_Printer Returned Error Status: ':QUOTE(stat)
    IF Get_Status(errCode) THEN
        Stat  = Set_Status(-1,'STPROC',ErrorTitle:@SVM:Error_Msg)
    END ELSE
        Stat  = Set_Status(1,'STPROC',ErrorTitle:@SVM:Error_Msg)
    END 
    
    stat = Set_Printer('TERM',1)
    
RETURN

Bail:
* * * * * *
        
    Msg(@window, MsgUp)         ;* take down the processing message
    stat = Set_Printer("TERM")	   			     ;* Terminiate this printing session
    IF stat < 0 THEN  GOTO OIPrint_Err
    
    Utility('CURSOR','A') 
    
RETURN

ClearCursors:
    For counter = 0 to 8
        ClearSelect counter
    Next counter
return


