REM                      ANNTOT1.BAS
REM
REM   This is a source program written in CBASIC version 2 for use with
REM   CP/M on a 48K machine with dual floppy discs.  It is possible to
REM   get by with less memory and a single disc, so try it with smaller
REM   configurations.  The program reads monthly categorized totals from
REM   disc files (64 character record fixed length) and outputs them in
REM   ledger form for optional printing on hardcopy or vision on the screen.
REM   Use the programs BUDGET1 and LEDGER1 to prepare the records.
REM                     Patrick Cunningham (512)822-3593

     PRINT TAB(10);"ANNTOT1.BAS: SUMS MONTHLY FILES GENERATED BY LEDGER1"
     PRINT:PRINT:PRINT
     INPUT "If listing is to be done at lineprinter, type 1;console,0";LP%
REM  
REM  Later we will reference LP% and set up the printer if desired.
REM
10   PRINT "What year are you totalling";
     INPUT LINE YEAR$
     IF LEN(YEAR$)<>4 THEN GOTO 10
11   PRINT "How many months of the year have passed [are totalled on disc]";
     INPUT NO.MONTHS 
     IF NO.MONTHS<1 OR NO.MONTHS>12 THEN PRINT "Improper number":GOTO 11
     NO.MONTHS%=INT(NO.MONTHS)
     PRINT "Number of months on disc:";NO.MONTHS%;
     INPUT "If this is correct,<cr>.";LINE RESP$
     IF RESP$<>"" THEN GOTO 11
     FILE.NAME$="EXP"+YEAR$+"."+"TOT"
     OPEN FILE.NAME$ RECL 64 AS 1
     PRINT FILE.NAME$ ; " OPENED."
REM
REM  We now read all the months' data into memory.
REM
     DIM MONTH$(NO.MONTHS%)
     DIM CAT$(19)
     DIM AMOUNT(NO.MONTHS%,19)
     DIM TOTAL(NO.MONTHS%)
     FOR L%=1 TO NO.MONTHS%
          READ # 1; SYMBOL$,MONTH$(L%),D.YEAR$
          IF SYMBOL$<>"*" THEN PRINT "* not found with month.":GOTO 1000
          IF D.YEAR$<>YEAR$ THEN PRINT D.YEAR$;" on disc not ";YEAR$:GOTO 1000
          FOR M%=1 TO 19
               READ # 1; SYMBOL$,CAT$(M%),T.AMOUNT
               IF SYMBOL$<>" " THEN PRINT "<> not found with amount":GOTO 1000
               AMOUNT(L%,M%)=T.AMOUNT
               NEXT M%
          READ # 1; SYMBOL$,T.TOTAL
          IF SYMBOL$<>"=" THEN PRINT "= not found with total.":GOTO 1000
          TOTAL(L%)=T.TOTAL
          PRINT TAB(20);  "Data for "; MONTH$(L%); " is in memory."
          NEXT L%
REM
REM  We now total each category and list on the printer, if desired
REM
     
     DIM CAT.TOTAL(19)
     DIM CAT.NAME$(19)
     CAT.NAME$(1)="CHARITY ": CAT$(1)="C"
     CAT.NAME$(2)="DRUGS/PH": CAT$(2)="D"
     CAT.NAME$(3)="CLOTHING": CAT$(3)="G"
     CAT.NAME$(4)="FOOD    ": CAT$(4)="F"
     CAT.NAME$(5)="HOUSEHLD": CAT$(5)="H"
     CAT.NAME$(6)="MORTGAGE": CAT$(6)="I"
     CAT.NAME$(7)="INSURANC": CAT$(7)="J"
     CAT.NAME$(8)="MEDICAL ": CAT$(8)="Y"
     CAT.NAME$(9)="MISC/TAX": CAT$(9)="M"
     CAT.NAME$(10)= "MISC/NONTAX": CAT$(10)="N"
     CAT.NAME$(11)= "PERS.PHONE ": CAT$(11)="P"
     CAT.NAME$(12)= "BUS. PHONE ": CAT$(12)="B"
     CAT.NAME$(13)= "REIMB.PHONE": CAT$(13)="R"
     CAT.NAME$(14)= "SAVINGS    ": CAT$(14)="S"
     CAT.NAME$(15)= "UTILITIES  ": CAT$(15)="U"
     CAT.NAME$(16)= "GAS/PERS.  ": CAT$(16)="E"
     CAT.NAME$(17)= "AUTO PARTS ": CAT$(17)="X"
     CAT.NAME$(18)= "AUTO REPAIR": CAT$(18)="W"
     CAT.NAME$(19)= "SALES TAX  ": CAT$(19)="T"
     IF LP% THEN LPRINTER WIDTH 132
     LP%=0
     PRINT:PRINT
     PRINT TAB(40);"E X P E N S E    S U M M A R Y    F O R  "; YEAR$
     PRINT:PRINT:PRINT
     PRINT "MONTH  CHARITY DRUGS   CLOTHES FOOD   HOUSEHLD MORTGAGE INSURANCE MEDICAL MISC.TX   MISC.NO.TX"
     PRINT
     YR.TOTAL=0.0
     FOR K%=1 TO 19 : CAT.TOTAL(K%)=0.0 :NEXT K%
     FOR L%=1 TO NO.MONTHS%
          PRINT MONTH$(L%):PRINT "  ";
          FOR K%=1 TO 10
               PRINT USING "$$####.##"; AMOUNT(L%,K%);
               CAT.TOTAL(K%)=CAT.TOTAL(K%)+AMOUNT(L%,K%)
               YR.TOTAL=YR.TOTAL+AMOUNT(L%,K%)
               NEXT K%
          PRINT
          NEXT L%
     PRINT "____________________________________________________________________________________"
     PRINT:PRINT "  "
     FOR K%=1 TO 10
          PRINT USING "$$####.##"; CAT.TOTAL(K%);
          NEXT K%
     PRINT:PRINT
     PRINT " PHONE B.PHONE R.PHONE SAVING UTILITY FUEL  AUTO.PT AUTOREP TAX    TOTAL"
     PRINT 
     FOR L%=1 TO NO.MONTHS%
          PRINT MONTH$(L%)
          FOR K%=11 TO 19
               PRINT USING "$$##.##"; AMOUNT(L%,K%);
               CAT.TOTAL(K%)=CAT.TOTAL(K%)+AMOUNT(L%,K%)
               YR.TOTAL=YR.TOTAL+AMOUNT(L%,K%)
               NEXT K%
          PRINT USING "$$####.##"; TOTAL(L%)
          PRINT
          NEXT L%
     PRINT "_________________________________________________________________________"
     PRINT
     FOR K%=11 TO 19
          PRINT USING "$$##.##"; CAT.TOTAL(K%);
          NEXT K%
     PRINT USING "$$#####.##";YR.TOTAL
     PRINT:PRINT:PRINT:PRINT:PRINT
     IF NOT LP% THEN CONSOLE
1000 INPUT "To start over, type 1;otherwise type 0"; ANS%
     IF ANS% THEN GOTO 10 ELSE PRINT TAB(30);"Adios.[VIVA TEJAS!]"
END
