compile function ORDER_RPT2() 
begin condition
pre:
post:
end condition
declare function msg, set_property, send_event, dialog_box, utility, get_property
declare subroutine rlist, or_view, activate_save_select, yield
$insert rlist_equates
$insert msg_equates

Params = dialog_box( 'ORDER_RPT2', @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 = 'ORDER_RPT2*':@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
BookFrom     = Params<1>
BookThru     = Params<2>
DirToPrinter = Params<3>
Custs        = Params<4>
OrderTable = 'ORDER'
Stat = utility( 'CURSOR', 'H' )
Stmt = 'SELECT ':OrderTable:' BY CUST_CITY '
if BookFrom and BookThru then
   Stmt :=  " WITH ENTRY_DATE FROM ":QUOTE(BookFrom):' TO ':QUOTE(BookThru)
end else
	if BookFrom then
	    Stmt := " WITH ENTRY_DATE GE ":QUOTE(BookFrom)
	end
	if BookThru then
	    Stmt := " WITH ENTRY_DATE LE ":QUOTE(BookThru)
	end
end
if Custs then
    swap @vm with "' '" in Custs
    Custs = "'":Custs:"'"
    Stmt := ' AND WITH CUST_NO = ':Custs
end

*DEBUG
rlist( Stmt, target_savelist$, ListsId, '', '' )
activate_save_select( ListsId )
if @reccount then
   Cmd = "LIST ":OrderTable:" ID-SUPP BREAK-ON CUST_CITY ":quote("'V'"):" JUSTLEN '60' TOTAL TOTAL_AMOUNT JUSTLEN '15' "
   Cmd:= " HEADING ":'"':"    Bookings by Company                   'T'   PAGE #  'PP''L'    for Selected Dates From (":BookFrom:" ) Thru (":BookThru:")":'" '
   if DirToPrinter = 'Yes' then
       rlist( Cmd, 0, '', '', '' )
   end else
       or_view( '', Cmd )
       Void = set_property( 'ORPRV.PRINT', 'ENABLED', 0 )
       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<mdefbtn$> = 2 ;* default to no
       MsgInfo<mcol$> = -2
       MsgInfo<mrow$> = -2       
       ToPrint = msg( @window, MsgInfo )
       if ToPrint then
          activate_save_select( ListsId )
          rlist( Cmd, 0, '', '', '' ) 
       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
