compile subroutine invoice_rpt1_prn( FromDate, ThruDate, InvoiceTable )
! 
* LIST INVOICE JUSTLEN '8' BREAK-ON CUST_CITY JUSTLEN '50' BREAK-ON STATUS SHIP_DATE DUE_DATE PO TOTAL BALANCE TOTAL INVOICE_AMOUNT  HEADING " Invoices by Customer by Status by Due Date 'T' PAGE # 'P' by selected due dates from ((12/31/95) TO ( ) "
! 
*PRINTER ON
* 
* HEADING/FOOTING
declare function set_printer, MSG
Font = 'Courier New,8,L,0'
convert ',' to @fm in Font
HeadPos = '.69,3,.75,.89,.75,1.5,1.25,1.25'
convert ',' to @fm in HeadPos
TheHeader = "Epitronics, formerly Lawrence Semiconductor Labs."
TheHeader<-1> = "Invoices by Customer by Status by Due Date 'T' PAGE # 'P' by selected due dates from (":oconv(FromDate, 'D2/'):") Thru (":oconv(ThruDate, 'D2/' ):')':@fm
ColHeader = "Key" : @vm : "Customer/City" : @vm : "Status" : @vm : "Ship Date" : @vm : "Due Date" : @vm : "PO" : @vm : "Balance" : @vm : "Invoice Amount"
Tvar = str( '_',12):@vm:str( '_', 42):@vm:str( '_', 7):@vm:str( '_', 10):@vm
Tvar:= str( '_',9 ):@vm:str( '_', 25):@vm:str( '_', 20 ):@vm:str( '_', 20)
*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
* 
BALANCE.CUSTULCITY.TOTAL=0
BALANCE.CUSTULCITY.COUNT=0
BALANCE.STATUS.TOTAL=0
BALANCE.STATUS.COUNT=0
BALANCE.GRAND.TOTAL=0
BALANCE.GRAND.COUNT=0
* 
INVOICEULAMOUNT.CUSTULCITY.TOTAL=0
INVOICEULAMOUNT.CUSTULCITY.COUNT=0
INVOICEULAMOUNT.STATUS.TOTAL=0
INVOICEULAMOUNT.STATUS.COUNT=0
INVOICEULAMOUNT.GRAND.TOTAL=0
INVOICEULAMOUNT.GRAND.COUNT=0
* 
* NULL PREVIOUS BREAK BUCKETS
* 
PREV.CUSTULCITY=''
LAST.CUSTULCITY.BREAK = 1
PREV.STATUS=''
LAST.STATUS.BREAK = 1
* 
! 
READRECORD:
! 
* 
* 
* ZERO BREAK FLAGS TO FALSE
* 
CUSTULCITY.BREAK=0
STATUS.BREAK=0
* 
* 
@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
CUSTULCITY.BREAK=1
CUSTULCITY=PREV.CUSTULCITY
STATUS.BREAK=1
STATUS=PREV.STATUS
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.STATUS={STATUS}
I.STATUS=S.STATUS
S.SHIPULDATE={SHIP_DATE}
I.SHIPULDATE=S.SHIPULDATE
S.DUEULDATE={DUE_DATE}
I.DUEULDATE=S.DUEULDATE
S.PO={PO}
I.PO=S.PO
S.BALANCE={BALANCE}
I.BALANCE=S.BALANCE
S.INVOICEULAMOUNT={INVOICE_AMOUNT}
I.INVOICEULAMOUNT=S.INVOICEULAMOUNT
* 
* 
* TEST FOR CONTROL BREAK(S)
* 
IF (S.CUSTULCITY NE PREV.CUSTULCITY) OR CUSTULCITY.BREAK THEN
CUSTULCITY=PREV.CUSTULCITY
PREV.CUSTULCITY=S.CUSTULCITY
CUSTULCITY.BREAK+=1
STATUS.BREAK=3
END
* 
IF (S.STATUS NE PREV.STATUS) OR STATUS.BREAK THEN
STATUS=PREV.STATUS
PREV.STATUS=S.STATUS
STATUS.BREAK+=1
END
* 
* 
IF FIRST.PASS THEN
FIRST.PASS=0
GOTO DETAIL
END
* 
* 
! 
BREAKS:
! 
* 
* PRINT BREAK TOTAL(S) AND ACCUMULATE TOTAL(S)
* 
* 
IF STATUS.BREAK THEN
Void = set_printer( 'TEXT', '' )
PRINTLINE = '':@vm
PRINTLINE:= '':@vm
PRINTLINE:= "***":@vm
PRINTLINE:= '':@vm
PRINTLINE:= '':@vm
PRINTLINE:= '':@vm
PRINTLINE:= OCONV(BALANCE.STATUS.TOTAL ,"MD2,$"):@vm
PRINTLINE:= OCONV(INVOICEULAMOUNT.STATUS.TOTAL ,"MD2,$")
TableColInfo = '>+993':@vm:'<+4320':@vm:'<+1080':@vm:'<+1281':@vm:'<+1080':@vm:'<+2160':@vm:'>+1800':@vm:'>+1800'
Void = set_printer( 'ADDTABLE', TableColInfo, '', PRINTLINE, '', '', 1, TB_NONE ) 
Void = set_printer( 'TEXT', '' )
* 
BALANCE.CUSTULCITY.TOTAL+=BALANCE.STATUS.TOTAL
BALANCE.STATUS.TOTAL=0
BALANCE.CUSTULCITY.COUNT+=BALANCE.STATUS.COUNT
BALANCE.STATUS.COUNT=0
INVOICEULAMOUNT.CUSTULCITY.TOTAL+=INVOICEULAMOUNT.STATUS.TOTAL
INVOICEULAMOUNT.STATUS.TOTAL=0
INVOICEULAMOUNT.CUSTULCITY.COUNT+=INVOICEULAMOUNT.STATUS.COUNT
INVOICEULAMOUNT.STATUS.COUNT=0
END
* 
IF CUSTULCITY.BREAK THEN
Void = set_printer( 'TEXT', '' )
PRINTLINE = '':@vm
PRINTLINE:= "***":@vm
PRINTLINE:= '':@vm
PRINTLINE:= '':@vm
PRINTLINE:= '':@vm
PRINTLINE:= '':@vm
PRINTLINE:= OCONV(BALANCE.CUSTULCITY.TOTAL ,"MD2,$"):@vm
PRINTLINE:= OCONV(INVOICEULAMOUNT.CUSTULCITY.TOTAL ,"MD2,$")
TableColInfo = '>+993':@vm:'<+4320':@vm:'<+1080':@vm:'<+1281':@vm:'<+1080':@vm:'<+2160':@vm:'>+1800':@vm:'>+1800'
Void = set_printer( 'ADDTABLE', TableColInfo, '', PRINTLINE, '', '', 1, TB_NONE ) 
Void = set_printer( 'TEXT', '' )
* 
BALANCE.GRAND.TOTAL+=BALANCE.CUSTULCITY.TOTAL
BALANCE.CUSTULCITY.TOTAL=0
BALANCE.GRAND.COUNT+=BALANCE.CUSTULCITY.COUNT
BALANCE.CUSTULCITY.COUNT=0
INVOICEULAMOUNT.GRAND.TOTAL+=INVOICEULAMOUNT.CUSTULCITY.TOTAL
INVOICEULAMOUNT.CUSTULCITY.TOTAL=0
INVOICEULAMOUNT.GRAND.COUNT+=INVOICEULAMOUNT.CUSTULCITY.COUNT
INVOICEULAMOUNT.CUSTULCITY.COUNT=0
END
* 
* 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(BALANCE.GRAND.TOTAL ,"MD2,$"):@vm
PRINTLINE:= OCONV(INVOICEULAMOUNT.GRAND.TOTAL ,"MD2,$")
TableColInfo = '>+993':@vm:'<+4320':@vm:'<+1080':@vm:'<+1281':@vm:'<+1080':@vm:'<+2160':@vm:'>+1800':@vm:'>+1800'
Void = set_printer( 'ADDTABLE', TableColInfo, '', PRINTLINE, '', '', 1, TB_NONE ) 

*Void = set_printer( 'TEXT', '' )
*@ANS=@RECCOUNT
Void = set_printer( 'TEXT', @RECCOUNT:' Invoices Processed' )
* PRINT
* @ANS=@REC.COUNT
* PRINT {RLIST_TEXT_1}
IF READERR THEN
@ANS=READERR
Void = set_printer( 'TEXT', {RLIST_TEXT_3} )
END
return
END
* 
! 
DETAIL:
! 
* 
* DO CONVERSIONS IF ANY
* 
IF S.STATUS NE "" THEN S.STATUS=OCONV(S.STATUS,"[INVOICE_STATUS_CONV]")
IF S.SHIPULDATE NE "" THEN S.SHIPULDATE=OCONV(S.SHIPULDATE,"D2/")
IF S.DUEULDATE NE "" THEN S.DUEULDATE=OCONV(S.DUEULDATE,"D2/")
IF S.BALANCE NE "" THEN S.BALANCE=OCONV(S.BALANCE,"MD2,$")
IF S.INVOICEULAMOUNT NE "" THEN S.INVOICEULAMOUNT=OCONV(S.INVOICEULAMOUNT,"MD2,$")
* 
* ACCUMULATE TOTAL(S)
* 
IF NUM(I.BALANCE) AND I.BALANCE NE "" THEN
BALANCE.STATUS.TOTAL+=I.BALANCE
BALANCE.STATUS.COUNT+=1
I.BALANCE=''
END
IF NUM(I.INVOICEULAMOUNT) AND I.INVOICEULAMOUNT NE "" THEN
INVOICEULAMOUNT.STATUS.TOTAL+=I.INVOICEULAMOUNT
INVOICEULAMOUNT.STATUS.COUNT+=1
I.INVOICEULAMOUNT=''
END
* 
* PRINT DETAIL LINE
* 
PRINTLINE = S.ATID:@vm
PRINTLINE:= S.CUSTULCITY:@vm
PRINTLINE:= S.STATUS:@vm
PRINTLINE:= S.SHIPULDATE:@vm
PRINTLINE:= S.DUEULDATE:@vm
PRINTLINE:= S.PO:@vm
PRINTLINE:= S.BALANCE:@vm
PRINTLINE:= S.INVOICEULAMOUNT
TableColInfo = '>+993':@vm:'<+4320':@vm:'<+1080':@vm:'<+1281':@vm:'<+1080':@vm:'<+2160':@vm:'>+1800':@vm:'>+1800'
Void = set_printer( 'ADDTABLE', TableColInfo, '', PRINTLINE, '', '', 1, TB_NONE ) 
* 
* 
GOTO READRECORD
* 
END

