compile function WO_LOG_RPT1()
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 wo_log_rpt1_prn
$insert rlist_equates
$insert msg_equates

Params = dialog_box( 'WO_LOG_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 = 'WO_LOG_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
EntDateFrom   = Params<1>
EntDateThru   = Params<2>
DueDateFrom   = Params<3>
DueDateThru   = Params<4>
CloseDateFrom = Params<5>
CloseDateThru = Params<6>
WOFrom        = Params<7>
WOThru        = Params<8>
Custs         = Params<9>
Open          = Params<10>
Closed        = Params<11>
SchedYes      = Params<12>
SchedNo       = Params<13>
DirToPrinter  = Params<14>

Stat = utility( 'CURSOR', 'H' )
Stmt = 'SELECT WO_LOG BY WO'


EndStmt = ''
* ENTRY DATE INFORMATION
if EntDateFrom and EntDateThru then
   EndStmt :=  " WITH ENTRY_DATE FROM ":QUOTE(EntDateFrom):' TO ':QUOTE(EntDateThru)
end else
	if EntDateFrom then
	    EndStmt :=  " WITH ENTRY_DATE GE ":QUOTE(EntDateFrom)
	end
	if EntDateThru then
	    EndStmt := " WITH ENTRY_DATE LE ":QUOTE(EntDateThru)
	end
end

* DUE DATE INFORMATION
if DueDateFrom and DueDateThru then
   if EndStmt <> '' then
      EndStmt := " AND"
   end
   EndStmt :=  " WITH CUST_SHIP_DATE FROM ":QUOTE(DueDateFrom):' TO ':QUOTE(DueDateThru)
end else
	if DueDateFrom then
	    if EndStmt <> '' then
          EndStmt := " AND"
       end
       EndStmt :=  " WITH CUST_SHIP_DATE GE ":QUOTE(DueDateFrom)
	end
	if DueDateThru then
	    if EndStmt <> '' then
          EndStmt := " AND"
       end
	    EndStmt := " WITH CUST_SHIP_DATE LE ":QUOTE(DueDateThru)
	end
end
* CLOSE DATE INFORMATION
if CloseDateFrom and CloseDateThru then
   if EndStmt <> '' then
      EndStmt := " AND"
   end
   EndStmt :=  " WITH CLOSE_DATE FROM ":QUOTE(CloseDateFrom):' TO ':QUOTE(CloseDateThru)
end else
	if CloseDateFrom then
	    if EndStmt <> '' then
          EndStmt := " AND"
       end
       EndStmt :=  " WITH CLOSE_DATE GE ":QUOTE(CloseDateFrom)
	end
	if CloseDateThru then
	    if EndStmt <> '' then
          EndStmt := " AND"
       end
	    EndStmt := " WITH CLOSE_DATE LE ":QUOTE(CloseDateThru)
	end
end
* WORK ORDER INFORMATION
if WOFrom and WOThru then
   if EndStmt <> '' then
      EndStmt := " AND"
   end
   EndStmt :=  " WITH WO FROM ":QUOTE(WOFrom):' TO ':QUOTE(WOThru)
end else
	if WOFrom then
	    if EndStmt <> '' then
          EndStmt := " AND"
       end
       EndStmt :=  " WITH WO GE ":QUOTE(WOFrom)
	end
	if WOThru then
	    if EndStmt <> '' then
          EndStmt := " AND"
       end
	    EndStmt := " WITH WO LE ":QUOTE(WOThru)
	end
end
if Custs then
    swap @vm with "' '" in Custs
    Custs = "'":Custs:"'"
    if EndStmt <> '' then
       EndStmt := " AND"
    end
    EndStmt := ' WITH CUST_NO = ':Custs    
end

if Open then
    if EndStmt then
        EndStmt := ' AND WITH STATUS = "O"'
    end else
        EndStmt := ' WITH STATUS = "O"'
    end
end
if Closed then
    if EndStmt then
        EndStmt := ' AND WITH STATUS = "C"'
    end else
        EndStmt := ' WITH STATUS = "C"'
    end
end

if SchedYes then
    if EndStmt then
        EndStmt := ' AND WITH SCHEDULED = 1'
    end else
        EndStmt := ' WITH SCHEDULED = 1'
    end
end
if SchedNo then
    if EndStmt then
        EndStmt := ' AND WITH SCHEDULED = 0'
    end else
        EndStmt := ' WITH SCHEDULED = 0'
    end
end
Stmt:=EndStmt

Void = set_status(0)
rlist( Stmt, target_savelist$, ListsId, '', '' )

activate_save_select( ListsId )

if @reccount then
   Cmd = "LIST WO_LOG ID-SUPP WO JUSTLEN 6 CUST_NO JUSTLEN 6 COLHEAD 'CustNo' ABBREV_OR_CO_NAME JUSTLEN 18 "
   Cmd:= "PROD_SPEC_ID JUSTLEN 5 THICK_TARGET_L1 JUSTLEN 5 COLHEAD 'Thick' RES_TARGET_L1 "
   Cmd:= "JUSTLEN 5 COLHEAD 'Res' WAFER_INCHES JUSTLEN 4 QTY JUSTLEN 4 CUST_SHIP_DATE JUSTLEN 8 "
   Cmd:= "COLHEAD 'Ship Req' RECEIVED_DATE JUSTLEN 8 REACTORS_ONE_LINE JUSTLEN 11 "
   Cmd:= "SCHEDULED JUSTLEN 3 COLHEAD 'Sch' CLOSE_DATE JUSTLEN 8 "
   Cmd:= " HEADING ":'"':" Run Date: 'TS59'Page'P''LS32'Work Order Log Report by WO# ":'"'

   if DirToPrinter = 'Yes' then
   		PrintPath = Printer_Select('',1)		;* Get default printer path
       Void = set_printer( 'INIT', '', '', .5:@fm:.5:@fm:.5:@fm:.5, 0, '',PrintPath )
       
       wo_log_rpt1_prn( '' )
       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', '', '', .5:@fm:.5:@fm:.5:@fm:.5, 0, '' )
           wo_log_rpt1_prn( '' )
           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

