COMPILE SUBROUTINE Export_OEE( Dummy )

DECLARE FUNCTION Msg, Dialog_Box, Utility, Environment_Services
DECLARE FUNCTION Set_Printer, Get_Printer, obj_Install, obj_OEE

DECLARE SUBROUTINE Btree.Extract, RList, END_Dialog, Make.List, Msg, ErrMsg

$INSERT LSL_USERS_EQU
$INSERT MSG_EQUATES
$INSERT RLIST_EQUATES
$INSERT OIPRINT_EQUATES


CRLF$ = \0D0A\

Parms = Dialog_Box( 'REACTOR_UTIL_SRPT2', @WINDOW, '*CENTER' )

IF Parms = 'CANCEL' OR Parms = '' THEN
    RETURN
END


CONVERT '*' TO @FM IN Parms


RepStartDt	= Parms<1>
RepEndDt	= Parms<2>
Reactors	= ''

Results = obj_OEE('ReactorDetail',RepStartDt:@RM:RepEndDt:@RM:Reactors)	;* This uses STATUS_LINE control to report progress




* FileName = "C:\OIReport\UtilRpt.csv"
FileName = Environment_Services('GetReportsRootPath') : "\UtilRpt.csv"
OsByte = 0

OpenFile:

OSDelete FileName
OSOpen FileName TO OsFile ELSE
   OSWrite "" TO FileName
   IF Status() THEN
      GoSub ReportStatus
      Msg( '', StatusMsg )
      RETURN
   END
   
   OSOpen FileName TO OSFile ELSE 
      GoSub ReportStatus
      Msg( '', StatusMsg )
      RETURN
   END
END


TitleLine1 = ''
TitleLine2 = ''
TitleLine3 = ''

RptDt = OCONV(Date(),"D4/")

RptTitle = obj_Install('Get_Prop','CompTitle'):" Reactors Utilization Report"

TitleLine1 = RptDt:'    ':RptTitle

IF Reactors NE '' THEN
	HeadReactors = 'Reactors ':Reactors
	SWAP @VM WITH ', ' IN HeadReactors
	
	IF INDEX(HeadReactors,', ',1) THEN
		HeadReactors[-4,2] = ' & '
	END
	TitleLine2 = HeadReactors
END Else
	TitleLine2 = 'All Reactors'
END

TitleLine3 = "Dates: ":RepStartDt:" Through ": RepEndDt

RptTtl = TitleLine1:CRLF$:TitleLine2:CRLF$:TitleLine3:CRLF$

OSBWrite RptTtl TO OSFile AT OSByte    
OSByte += LEN(RptTtl)


CONVERT @VM TO ',' IN Results
SWAP @FM WITH CRLF$ IN Results

OSBWrite Results TO OSFile AT OSByte    
OSByte += Len(Results)
	

OSClose OSFile

Void = utility( 'CURSOR', 'A' )

Msg( '', 'Report Written > ':FileName )

RETURN

*========================
ReportStatus:
*========================
   Begin Case
      Case Status() = 1
         StatusMsg = "Bad OS filename"
      Case Status() = 2
         StatusMsg = "Access Denied - File probably locked by another process."   
      Case Status() = 3
         StatusMsg =  "Disk or Directory Full"  
      Case Status() = 4
         StatusMsg =  "What ???"  
      Case Status() = 5
         StatusMsg =  "OS Error not defined elsewhere."    
      Case Status() = 6
         StatusMsg =  "OS File is Read Only."
      Case 1
         StatusMsg = "BAD STATUS"      
   END Case
   
   Return
