compile function ORDER_RPT1() 
begin condition
pre:
post:
end condition
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 order_rpt1_prn
$insert rlist_equates
$insert msg_equates

Params = dialog_box( 'ORDER_RPT1', @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_RPT1*':@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 BY ENTRY_DATE'
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
rlist( Stmt, target_savelist$, ListsId, '', '' )
activate_save_select( ListsId )
if @reccount then
   Cmd = "LIST ":OrderTable:" JUSTLEN '8' ENTRY_DATE PO BREAK-ON CUST_CITY JUSTLEN '60' TOTAL TOTAL_QTY JUSTLEN '10' 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
   
		PrintPath = Printer_Select('',1)	;* Get default printer path
       Void = set_printer( 'INIT', '', '', '':@fm:1.25, 1, '',PrintPath )
       
       order_rpt1_prn( iconv( BookFrom, 'D' ), iconv( BookThru, 'D' ), OrderTable )
       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 )
       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 )
          Void = set_printer( 'INIT', '', '', '':@fm:1.25, 1, '' )
          order_rpt1_prn( iconv( BookFrom, 'D' ), iconv( BookThru, 'D' ), OrderTable )
          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
