compile subroutine invoice_rpt4_prn( FromDate, ThruDate, InvoiceTable )
declare function set_printer
! 
* LIST INVOICE JUSTLEN '8' CUST_CITY JUSTLEN '50' ENTRY_DATE DUE_DATE PO GL_ACCT_TOTS TOTAL TOTAL_SHIP_AMOUNT TOTAL DISCOUNT_AMOUNT TOTAL INVOICE_AMOUNT HEADING " Invoices by Invoice No 'T' PAGE # 'P' by selected entry dates from (01/01/96) TO (01/08/96 ) "
! 
*PRINTER ON
* 
* HEADING/FOOTING
Font = 'Courier New,7,L,1'
convert ',' to @fm in Font
HeadPos = '.5,1.75,.81,.75,1.25,1.75,1.06,1.06,1.06'
convert ',' to @fm in HeadPos
TheHeader = "Epitronics, formerly Lawrence Semiconductor Labs."
TheHeader<-1> = "Invoices by Invoice No. 'T' PAGE # 'P' by selected entry dates from (":oconv(FromDate, 'D2/' ):') TO (':oconv(ThruDate, 'D2/' ):")":@fm
ColHeader = "Key" : @vm : "Customer/City" : @vm : "Entry Date" : @vm : "Due Date" : @vm : "PO" : @vm : "G/L Account Totals" : @vm : "Tot Ship Amt" : @vm : "Discount Amt" : @vm : "Invoice Amt"
Tvar = str( '_', 8):@vm:str( '_', 30):@vm:str( '_', 10):@vm:str( '_', 10):@vm
Tvar:= str( '_',17 ):@vm:str( '_', 25):@vm:str( '_', 17):@vm:str( '_', 17):@vm
Tvar:= str( '_',17 )
*COLHEADER = ''
ColHeader<-1> = Tvar
*TheHeader = ''
Void = set_printer( 'FONTHEADFOOT', Font )
Void = set_printer( 'HEADER', TheHeader, HeadPos, ColHeader )
Void = set_printer( 'FONT', Font )
*FOOTING ""
* 
@RECCOUNT=0
FIRST.PASS=1
LAST.RECORD=0
READERR=0
* 
* OPEN DICT AND DATA FILES
* 
OPEN "DICT",InvoiceTable TO @DICT ELSE return
OPEN "",InvoiceTable TO FILE.IN ELSE return
* 
* MAKE COLUMN HEADING
* 
* ZERO ACCUMULATORS FOR EACH BREAK
* 
TOTALULSHIPULAMOUNT.GRAND.TOTAL=0
TOTALULSHIPULAMOUNT.GRAND.COUNT=0
* 
DISCOUNTULAMOUNT.GRAND.TOTAL=0
DISCOUNTULAMOUNT.GRAND.COUNT=0
* 
INVOICEULAMOUNT.GRAND.TOTAL=0
INVOICEULAMOUNT.GRAND.COUNT=0
* 
! 
READRECORD:
! 
* 
* 
@FILE.ERROR.MODE=1
READNEXT @ID,WHICH.VALUE ELSE
@FILE.ERROR.MODE=0
IF STATUS() GT 0 THEN
@ANS=@FILE.ERROR<1>
Void = set_printer( 'TEXT',{RLIST_TEXT_5} )
return
END
IF @FILE.ERROR<1> EQ 421 THEN
Void = set_printer( 'TEXT', {RLIST_TEXT_6} )
GOTO READRECORD
END
IF @FILE.ERROR<1> NE 111 THEN
@ANS=@FILE.ERROR<1>
Void = set_printer( 'TEXT', {RLIST_TEXT_4} )
READERR+=1
GOTO READRECORD
END
LAST.RECORD=1
END
@FILE.ERROR.MODE=0
* 
S.ATID=@ID
* 
IF FIRST.PASS AND LAST.RECORD THEN
Void = set_printer( 'TEXT', {RLIST_TEXT_2} )
return
END
* 
IF LAST.RECORD THEN GOTO BREAKS
* 
IF @REDUCTION.DONE THEN
@FILE.ERROR.MODE=1
READO @RECORD FROM FILE.IN,@ID ELSE
@FILE.ERROR.MODE=0
IF STATUS() GT 0 THEN
@ANS=@FILE.ERROR<1>
Void = set_printer( 'TEXT', {RLIST_TEXT_5} )
return
END
IF @FILE.ERROR<1> NE 100 THEN
@ANS=@FILE.ERROR<1>
Void = set_printer( 'TEXT', {RLIST_TEXT_4} )
READERR+=1
END
GOTO READRECORD
END
@FILE.ERROR.MODE=0
END
* 
@RECCOUNT+=1
* 
* 
* CALCULATE VALUE(S) FOR COLUMN(S)
* 
S.ATID={@ID}
I.ATID=S.ATID
S.CUSTULCITY={CUST_CITY}
I.CUSTULCITY=S.CUSTULCITY
S.ENTRYULDATE={ENTRY_DATE}
I.ENTRYULDATE=S.ENTRYULDATE
S.DUEULDATE={DUE_DATE}
I.DUEULDATE=S.DUEULDATE
S.PO={PO}
I.PO=S.PO
M.GLULACCTULTOTS={GL_ACCT_TOTS}<1,WHICH.VALUE> ; P.GLULACCTULTOTS=1 ; C.GLULACCTULTOTS=7
S.TOTALULSHIPULAMOUNT={TOTAL_SHIP_AMOUNT}
I.TOTALULSHIPULAMOUNT=S.TOTALULSHIPULAMOUNT
S.DISCOUNTULAMOUNT={DISCOUNT_AMOUNT}
I.DISCOUNTULAMOUNT=S.DISCOUNTULAMOUNT
S.INVOICEULAMOUNT={INVOICE_AMOUNT}
I.INVOICEULAMOUNT=S.INVOICEULAMOUNT
* 
PREVIOUS.MARK.LEVEL=0
* 
IF FIRST.PASS THEN
FIRST.PASS=0
GOTO DETAIL
END
* 
* 
! 
BREAKS:
! 
* 
* 
* PERFORM LAST RECORD OUTPUT IF DONE
* 
IF LAST.RECORD THEN
Void = set_printer( 'TEXT', '' )
PRINTLINE ="***":@vm
PRINTLINE:= '':@vm
PRINTLINE:= '':@vm
PRINTLINE:= '':@vm
PRINTLINE:= '':@vm
PRINTLINE:= '':@vm
PRINTLINE:= OCONV(TOTALULSHIPULAMOUNT.GRAND.TOTAL ,"MD2,$"):@vm
PRINTLINE:= OCONV(DISCOUNTULAMOUNT.GRAND.TOTAL ,"MD2,$"):@vm
PRINTLINE:= OCONV(INVOICEULAMOUNT.GRAND.TOTAL ,"MD2,$")
TableColInfo = '>+720':@vm:'<+2520':@vm:'<+1166':@vm:'<+1080':@vm:'<+1800':@vm:'<+2520':@vm:'>+1526':@vm:'>+1526':@vm:'>+1526'
Void = set_printer( 'ADDTABLE', TableColInfo, '', PRINTLINE, '', '', 1, TB_NONE ) 

* PRINT
* @ANS=@RECCOUNT
* PRINT {RLIST_TEXT_1}
IF READERR THEN
@ANS=READERR
Void = set_printer( 'TEXT', {RLIST_TEXT_3} )
END
return
END
* 
! 
DETAIL:
! 
* 
* REMOVE APPROPRIATE VALUE FROM MULTI-VALUED COLUMN(S)
* 
NEW.MARK.LEVEL=0
* 
IF C.GLULACCTULTOTS GE PREVIOUS.MARK.LEVEL THEN
REMOVE I.GLULACCTULTOTS FROM M.GLULACCTULTOTS AT P.GLULACCTULTOTS SETTING C.GLULACCTULTOTS
S.GLULACCTULTOTS=I.GLULACCTULTOTS
END
IF C.GLULACCTULTOTS GT NEW.MARK.LEVEL THEN NEW.MARK.LEVEL=C.GLULACCTULTOTS
* 
* DO CONVERSIONS IF ANY
* 
IF S.ENTRYULDATE NE "" THEN S.ENTRYULDATE=OCONV(S.ENTRYULDATE,"D2/")
IF S.DUEULDATE NE "" THEN S.DUEULDATE=OCONV(S.DUEULDATE,"D2/")
IF S.TOTALULSHIPULAMOUNT NE "" THEN S.TOTALULSHIPULAMOUNT=OCONV(S.TOTALULSHIPULAMOUNT,"MD2,$")
IF S.DISCOUNTULAMOUNT NE "" THEN S.DISCOUNTULAMOUNT=OCONV(S.DISCOUNTULAMOUNT,"MD2,$")
IF S.INVOICEULAMOUNT NE "" THEN S.INVOICEULAMOUNT=OCONV(S.INVOICEULAMOUNT,"MD2,$")
* 
* ACCUMULATE TOTAL(S)
* 
IF NUM(I.TOTALULSHIPULAMOUNT) AND I.TOTALULSHIPULAMOUNT NE "" THEN
TOTALULSHIPULAMOUNT.GRAND.TOTAL+=I.TOTALULSHIPULAMOUNT
TOTALULSHIPULAMOUNT.GRAND.COUNT+=1
I.TOTALULSHIPULAMOUNT=''
END
IF NUM(I.DISCOUNTULAMOUNT) AND I.DISCOUNTULAMOUNT NE "" THEN
DISCOUNTULAMOUNT.GRAND.TOTAL+=I.DISCOUNTULAMOUNT
DISCOUNTULAMOUNT.GRAND.COUNT+=1
I.DISCOUNTULAMOUNT=''
END
IF NUM(I.INVOICEULAMOUNT) AND I.INVOICEULAMOUNT NE "" THEN
INVOICEULAMOUNT.GRAND.TOTAL+=I.INVOICEULAMOUNT
INVOICEULAMOUNT.GRAND.COUNT+=1
I.INVOICEULAMOUNT=''
END
* 
* PRINT DETAIL LINE
* 
PRINTLINE = S.ATID:@vm
PRINTLINE:= S.CUSTULCITY:@vm
PRINTLINE:= S.ENTRYULDATE:@vm
PRINTLINE:= S.DUEULDATE:@vm
PRINTLINE:= S.PO:@vm
PRINTLINE:= S.GLULACCTULTOTS:@vm
PRINTLINE:= S.TOTALULSHIPULAMOUNT:@vm
PRINTLINE:= S.DISCOUNTULAMOUNT:@vm
PRINTLINE:= S.INVOICEULAMOUNT
TableColInfo = '>+720':@vm:'<+2520':@vm:'<+1166':@vm:'<+1080':@vm:'<+1800':@vm:'<+2520':@vm:'>+1526':@vm:'>+1526':@vm:'>+1526'
Void = set_printer( 'ADDTABLE', TableColInfo, '', PRINTLINE, '', '', 1, TB_NONE ) 

* 
IF NEW.MARK.LEVEL THEN
S.ATID=''
S.CUSTULCITY=''
S.ENTRYULDATE=''
S.DUEULDATE=''
S.PO=''
S.GLULACCTULTOTS=''
S.TOTALULSHIPULAMOUNT=''
S.DISCOUNTULAMOUNT=''
S.INVOICEULAMOUNT=''
PREVIOUS.MARK.LEVEL=NEW.MARK.LEVEL
GOTO DETAIL
END
* 
GOTO READRECORD
* 
END

