compile function REACTOR_LOG_RPT4()
begin condition
pre:
post:
end condition
declare function getprinterlist, getprofilestring, writeprofilestring, extdevicemode
declare function msg, set_property, send_event, dialog_box, utility, get_property
declare function set_printer, Printer_Select
declare subroutine rlist, or_view, activate_save_select, yield
declare subroutine reactor_log_rpt4_prn
$insert rlist_equates
$insert msg_equates

Params = dialog_box( 'REACTOR_LOG_RPT4', @window, '*CENTER' )
if Params = 'CANCEL' or Params = '' then
    return 0
end
open 'SYSLISTS' to SysListsTable else
    MsgInfo = ''
    MsgInfo<mcol$> = -2
    MsgInfo<mrow$> = -2
    MsgInfo<mtext$> = 'Unable to open SYSLISTS...'
    Void = msg( '', MsgInfo )
    return 0
end
ListsId = 'REACTOR_LOG_RPT4*':@station
write '' on SysListsTable, ListsId else
    MsgInfo = ''
    MsgInfo<mcol$> = -2
    MsgInfo<mrow$> = -2
    MsgInfo<mtext$> = 'Unable to clear SYSLISTS ':ListsId:'...'
    Void = msg( '', MsgInfo )
    return 0
end
convert '*' to @fm in Params
StartDateFrom   = Params<1>
StartDateThru   = Params<2>
Reactors        = Params<3>
Probs           = Params<4>
Servs           = Params<5>
DirToPrinter    = Params<6>

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

Stmt = 'SELECT REACTOR_LOG BY REACTOR BY-DSND START_DATE BY-DSND START_TIME'
* FORCE TO MAINTENANCE RECORDS
* THIS WAY NO PASS DOWN RECORDS WILL SHOW UP 
Stmt := ' WITH CATEGORY = "M"'
if StartDateFrom and StartDateThru then
   Stmt := ' AND WITH START_DATE FROM ':QUOTE(StartDateFrom):' TO ':QUOTE(StartDateThru)
end else
	if StartDateFrom then
	    Stmt := " AND WITH START_DATE GE ":QUOTE(StartDateFrom)
	end
	if StartDateThru then
	    Stmt := " AND WITH START_DATE LE ":QUOTE(StartDateThru)
	end
end
if Reactors then
    swap @vm with "' '" in Reactors
    Reactors = "'":Reactors:"'"
    Stmt := ' AND WITH REACTOR = ':Reactors
end
if Probs then
    swap @vm with "' '" in Probs
    Probs = "'":Probs:"'"
    Stmt := ' AND WITH REACT_PROB_ID = ':Probs
end
if Servs then
    swap @vm with "' '" in Servs
    Servs = "'":Servs:"'"
    Stmt := ' AND WITH REACT_SERV_ID = ':Servs
end

*IF @user4 = 'BRYCE_M' THEN
*   DEBUG
*END
rlist( Stmt, target_savelist$, ListsId, '', '' )

activate_save_select( ListsId )

if @reccount then
   Cmd = "LIST REACTOR_LOG ID-SUPP"
   Cmd:= " REACTOR JUSTLEN 5 REACT_AREA_DESC REACT_PROB_DESC "
   Cmd:= " JUSTLEN 30 REACT_SERV_DESC JUSTLEN 30 REACT_ITEM_IDS REACT_ITEMS_DESC "
   Cmd:= " JUSTLEN 30 REACT_ITEM_QTY JUSTLEN 4 COLHEAD 'Qty' NOTES JUSTLEN 30 START_DATE JUSTLEN 10 START_TIME JUSTLEN 10 ELAPSED_HOURS JUSTLEN 7 COLHEAD 'Hours'"
   Cmd:= " HEADING ":'"':" Run Date: 'TS39'Page 'P''LS22'Reactor Log Report "
   Cmd:= StartDateFrom:' To ':StartDateThru:'"'
   if DirToPrinter = 'Yes' then
       *rlist( Cmd, 0, '', '', 1 )
       PrintPath = Printer_Select('',1)
       Void = set_printer( 'INIT', '', '', '':@fm:1.25, 1, '',PrintPath )
       reactor_log_rpt4_prn( iconv( StartDateFrom, 'D' ), iconv( StartDateThru, 'D' ), DetSum )
       Void = set_printer( 'TERM' )
       Void = set_printer( 'INIT', '', '', '', 0, '' )
       Void = set_printer( 'TERM' )
   end else
       or_view( '', Cmd )
       Void = set_property( 'ORPRV.PRINT', 'ENABLED', 0 )
       *Void = set_property( 'ORPRV', 'VISIBLE', 3 )
       WinId = 'ORPRV'
       loop
         while get_property( WinId, 'HANDLE' )
          yield()
       repeat
       ToPrint = ''
       MsgInfo = ''
       MsgInfo<mtext$> = 'Do you want to print this report?'
       MsgInfo<micon$> = '?'
       MsgInfo<mtype$> = 'BNY'
       MsgInfo<mcol$>  = -2
       MsgInfo<mrow$>  = -2
       MsgInfo<mdefbtn$> = 2 ;* default to no
       ToPrint = msg( @window, MsgInfo )
       if ToPrint then
           activate_save_select( ListsId )
           *rlist( Cmd, 0, '', '', '' )
           Void = set_printer( 'INIT', '', '', '':@fm:1.25, 1, '' )         
           reactor_log_rpt4_prn( iconv( StartDateFrom, 'D' ), iconv( StartDateThru, 'D' ), DetSum )
           Void = set_printer( 'TERM' )
           Void = set_printer( 'INIT', '', '', '', 0, '' )
           Void = set_printer( 'TERM' )
       end
   end 
end else
   MsgInfo = ''
   MsgInfo<mcol$>  = -2
   MsgInfo<mrow$>  = -2
   MsgInfo<mtext$> = 'NO Records meeting your date criteria!!'
   MsgInfo<micon$> = '!'
   Void = MSG( '', MsgInfo )
end
write '' on SysListsTable, ListsId else
    MsgInfo = ''
    MsgInfo<mcol$>  = -2
    MsgInfo<mrow$>  = -2
    MsgInfo<mtext$> = 'Unable to clear SYSLISTS ':ListsId:'...'
    Void = msg( '', MsgInfo )
    return 0
end
return 0

