compile function REACTOR_LOG_SRPT1()

declare function getprinterlist, getprofilestring, writeprofilestring, extdevicemode, PrintSetup, Set_Printer
declare function msg, set_property, send_event, dialog_box, utility, get_property, obj_Install, Printer_Select
declare function set_printer
declare subroutine rlist, or_view, activate_save_select, yield
declare subroutine btree.extract, update_index, rlist, end_dialog
declare subroutine activate_save_select
declare function msg, key_sort, utility, fieldcount, ex_vm_rem

$insert lsl_users_equ
$insert msg_equates
$insert rlist_equates
$INSERT PRINTSETUP_EQUATES

equ CRLF$ TO \0D0A\	;* CarriageReturn and Linefeed

* IF THIS CODE IS EVER USED, IT MUST CHANGE THE MSG CALLS WITH MCOL=-2 MROW=-2

Params = dialog_box( 'REACTOR_LOG_SRPT1', @window, '*CENTER' )
if Params = 'CANCEL' or Params = '' then
    return 0
end
open 'SYSLISTS' to SysListsTable else
    Void = msg( '', 'Unable to open SYSLISTS...' )
    return 0
end
ListsId = 'REACTOR_LOG_SRPT1*':@station
write '' on SysListsTable, ListsId else
    Void = msg( '', 'Unable to clear SYSLISTS ':ListsId:'...' )
    return 0
end
convert '*' to @fm in Params
StartDateFrom   = Params<1>
StartDateThru   = Params<2>
Reactors        = Params<3>
ProblemCats     = Params<4>
ServiceIDs      = Params<5>
Grid            = Params<6>

*************************************************************
* NEXT REPORT TRY ONLY USING SLIST
*************************************************************
WithStmt = ''

if StartDateFrom and StartDateThru then
    WithStmt:= 'WITH START_DATE FROM "':StartDateFrom:'" TO "':StartDateThru:'"'
end else
	if StartDateFrom then
	    WithStmt:= 'WITH START_DATE >= "':StartDateFrom:'"'
	end
	if StartDateThru then
	    WithStmt:= 'WITH START_DATE <= "':StartDateThru:'"'
	end
end

if ( Reactors <> '' ) then
    swap @vm with "' '" in Reactors
    Reactors = "'":Reactors:"'"
    WithStmt:=' AND WITH REACTOR = ':Reactors
end

if ( ProblemCats <> '' ) then
    swap @vm with "' '" in ProblemCats
    ProblemCats = "'":ProblemCats:"'"
    WithStmt:=' AND WITH REACT_PROB_CAT_ID = ':ProblemCats
end

if ( ServiceIDs <> '' ) then
    swap @vm with "' '" in ServiceIDs
    ServiceIDs = "'":ServiceIDs:"'"
    WithStmt:=' AND WITH REACT_SERV_ID = ':ServiceIDs
end

TtlWidth = 100
TableName = "REACTOR_LOG"
DatColFont='"Courier New,8" '
TtlColFont='"Courier New,10,B" '
TitleFont='"Courier New,12,B" '
RptDate = OCONV(Date(),"D4/")

RptTitle = obj_Install('Get_Prop','CompTitle'):" Reactor Maintenance Report"
RptTitleSpaces = Space((TtlWidth-20-Len(RptTitle))/2)
TitleLine1 =  RptDate:RptTitleSpaces:RptTitle:RptTitleSpaces:" Pg. 'P''L'"

if Reactors <> '' then
   TReactors = Reactors
   swap "'" with '' in TReactors
   Swap " " With ", " In TReactors
   TReactors[-4,4]= " & ":TReactors[-2,2]
   RptTitle = "Reactors: ":TReactors 
   RptTitleSpaces = Space((TtlWidth-Len(RptTitle))/2)
   TitleLine2 = RptTitleSpaces:RptTitle:" 'L'"
end else
   TitleLine2 = ''
end

RptTitle = "Dates: ":StartDateFrom:" Through ": StartDateThru
RptTitleSpaces = Space((TtlWidth-Len(RptTitle))/2)
TitleLine3 = RptTitleSpaces:RptTitle

Feed = "'L'"

ListsID = "ReactorLogReportSaveList"

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

WithStmt = 'SELECT REACTOR_LOG ':WithStmt


RLIST( WithStmt, target_activelist$, ListsId, '', '' )

IF Get_Status(errCode) THEN CALL ErrMsg(errCode)

WithStmt ="SELECT REACTOR_LOG BY REACTOR BY START_DATE WITH CATEGORY = 'M'"


RLIST(WithStmt,TARGET_ACTIVELIST$,'','','')

IF Get_Status(errCode) THEN CALL ErrMsg(errCode)

If @Reccount = 0 Then   
   Void = msg( '', 'No records selected with that criteria...' )
   return 0
End

TestVar = QUOTE('L')

Stmt = ''
Stmt:= "LIST ":TableName:" "
Stmt:= 'BREAK-ON REACTOR '
Stmt:= '"':"'V'":'" '
Stmt:= 'COLHEAD "':Feed:'R#" JUSTLEN "C4" COLFONT ':DatColFont
Stmt:= 'REACT_PROB_CAT_DESC COLHEAD "':Feed:'Problem Category Description" JUSTLEN T30 COLFONT ':DatColFont
Stmt:= 'REACT_SERV_ID COLHEAD "Serv':Feed:'  ID " JUSTLEN "C10" COLFONT ':DatColFont
Stmt:= 'REACT_SERV_DESC COLHEAD "':Feed:'Reactor Service Description" JUSTLEN T35 COLFONT ':DatColFont
Stmt:= 'TECH_SIG COLHEAD "':Feed:'Tech" JUSTLEN 10 COLFONT ':DatColFont
Stmt:= 'REACT_ITEM_IDS COLHEAD "':Feed:'Item SN" JUSTLEN 20 COLFONT ':DatColFont
Stmt:= 'START_DATE COLHEAD "Start Dt" JUSTLEN "C10" COLFONT ':DatColFont
Stmt:= 'TOTAL ELAPSED_HOURS COLHEAD "':Feed:'Hours" JUSTLEN 10 COLFONT ':DatColFont

Hdng = ""
Hdng:= 'HEADING "': TitleLine1 : TitleLine2: TitleLine3:' " '
Hdng:= 'HDRFONT ':TitleFont 
Hdng:= 'COLHDRFONT ':TtlColFont:' ID-SUPP  KEEP-TOGETHER BOX ':Grid:' CENTRE  LANDSCAPE'
Stmt:= Hdng


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

* Added after upgrade to OI4.13a to reset default printer in OIPI32 engine.

PrinterID		 	= ''
GetDefaultPrinter	= 1
PrintPath			= Printer_Select(PrinterID,GetDefaultPrinter)	;* Get Default printer path

Void = set_printer( 'INIT', '', '', .63:@fm:.63:@fm:.25:@fm:'', 0,'',PrintPath )
Void = Set_Printer('TERM')

void = Set_Status(0)
call slist( Stmt )


write '' on SysListsTable, ListsId else
    Void = msg( '', 'Unable to clear SYSLISTS ':ListsId:'...' )
    return 0
end
return 0


