compile function INVOICE_RPT2()
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
declare subroutine rlist, or_view, activate_save_select, yield, update_index
$insert rlist_equates
$insert msg_equates

Params = dialog_box( 'INVOICE_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 = 'INVOICE_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
FromDate     = Params<1>
ThruDate     = Params<2>
DirToPrinter = Params<3>
Plant        = Params<4>
begin case
  case Plant = 'All'
    PlantStmt = ''
  case Plant = 'Tempe'
    PlantStmt = ' AND WITH PLANT = "T" '
  case Plant = 'Mesa'
    PlantStmt = ' AND WITH PLANT = "M" '  
end case
InvoiceTable = 'INVOICE'

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

Stmt = 'SELECT ':InvoiceTable
if FromDate and ThruDate then
   Stmt :=  " WITH ENTRY_DATE FROM ":QUOTE(FromDate):' TO ':QUOTE(ThruDate)
end else
	if FromDate then
	    Stmt := " WITH ENTRY_DATE GE ":QUOTE(FromDate)
	end
	if ThruDate then
	    Stmt := " WITH ENTRY_DATE LE ":QUOTE(ThruDate)
	end
end
Stmt := PlantStmt
rlist( Stmt, target_savelist$, ListsId, '', '' )

activate_save_select( ListsId )

if @reccount then
   Cmd = "LIST ":InvoiceTable:" ID-SUPP BY GL_ACCT BREAK-ON GL_ACCT ":quote("'V'")
   Cmd:= " TOTAL AMOUNT DET-SUPP "
   Cmd:= " HEADING ":'"':" Epitronics, formerly Lawrence Semiconductor Labs. 'L' Invoices G/L Account Account totals 'TL'"
   Cmd:= " PAGE #  'P'  by G/L Account for selected dates from "
   Cmd:= "(":FromDate:") TO (":ThruDate:" ) ":'"'
   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<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, '', '', '' )
       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

