

       REM CHECKBOOK FOR CBASIC VERSION 2...
       REM     BY CHRIS KOVACS            JUNE 21, 1982 \
	     ***VERSION 1.6***  OCTOBER 29, 1982
       
       REM  10/20/82  ADDS BACK-UP FILE FEATURE AND ERROR MESSAGES\
	    ABOUT ALLOTTED TRANSACTION LIMITS

       REM  -1.6- 10/29/82 ADDED SERVICE CHRG ENTRY WHEN CLEARING\
            CHECKS.

MT%=80 : NA%=0
   CD=0
   A$=""
   PRINT CHR$(26)
   GOTO 50
30 CREATE FILENAME$+".CHK" AS 1:PRINT #1; 0,0,0," ":CLOSE 1:GOTO 100
50 INPUT "ENTER THE MONTH OF THE DESIRED CHECKBOOK FILE"; FILENAME$
   IF LEN(FILENAME$)>8 OR LEN(FILENAME$)<0 THEN 50
   DIM PY$(MT%), CN(MT%), DT(MT%), AM(MT%)
   PRINT

REM  OPEN  FILE

    IF END #1 THEN 30
100  OPEN FILENAME$+".CHK" AS 1
    FOR EP% = 0 TO MT%
        READ #1; CN(EP%), DT(EP%), AM(EP%), PY$(EP%)
        IF CN(EP%) <> 0 THEN \
    NEXT
    CLOSE 1
    NA%=EP%
200 PRINT

       REM MAIN MENU DISPLAY

    PRINT : PRINT " 1 - MAKE AN ENTRY"
    PRINT " 2 - DELETE AN ENTRY"
    PRINT " 3 - CHANGE AN ENTRY"
    PRINT " 4 - BALANCE STATEMENT"
    PRINT " 5 - VIEW AN ENTRY"
    PRINT " 6 - LIST LEDGER FILE ON PRINTER"
    PRINT " 9 - QUIT"
    P%=1
300 PRINT : INPUT "    SELECT ONE"; T%
      IF T%<1 OR T%>9 THEN GOTO 300
      IF T%=7 OR T%=8 THEN 200
      IF T%=9 THEN 9000
    ON T% GOSUB 1000, 2000, 3000, 4000, 5000, 6000
    GOTO 200

        REM      FORMAT $ NUMBER ROUTINE


600  X=ABS(AM(EP%))
     FOR$ = "$$#,###.##"
     PRINT USING FOR$; X;
     RETURN

        REM INPUT DAY AND MONTH - CONVERT TO T

700 INPUT "  MONTH (1-12)"; I% 
	IF I%<1 OR I%>12 THEN 700
710 INPUT "  DAY   (1-31)"; J%
    IF J%<1 OR J%>31 THEN 710
    K=82 : REM YEAR
    T=10000*K+100*I%+J%
    RETURN

        REM RECOVER DAY AND MONTH CONVERT TO T - AND PRINT RECORD

900 PRINT
    IF P%>22 THEN INPUT "CONTINUE ?"; LINE A$ : PRINT : P%=1
    PRINT ABS(CN(EP%)); TAB(8);
    I=DT(EP%)/10000
    J=(I- INT(I))*100
    K=(J-INT(J))*100
    PRINT INT(J+.1); "/" ; INT(K+.1); "/" ; INT(I+.1);
    PRINT TAB(22);
    PRINT CHR$(68+(AM(EP%)<0)); TAB(26);
    PRINT PY$(EP%); TAB(50);
    GOSUB 600
    PRINT TAB(64);
    IF CN(EP%) > 0 THEN GOTO 990
    PRINT "CLRD";
990 P%=P%+1
    RETURN

        REM MAKE ENTRY

1000 FOR EP% = 0 TO MT%
     IF CN(EP%) <>0 THEN NEXT
     INPUT "   CHECK/DEPOSIT"; A$
     CD=(LEFT$(A$,1) = "C")
1070 IF CD THEN PRINT "  CHECK";
     IF NOT CD THEN PRINT "  DEPOSIT";
     INPUT "  NUMBER"; CN(EP%)
        IF CN(EP%)<1 THEN GOTO 1070
     FOR I% = 0 TO NA%
       IF I%=EP% OR ABS(CN(I%)) <> ABS(CN(EP%)) THEN NEXT : GOTO 1100
     PRINT : PRINT CN(EP%); "ALREADY ENTERED"; : GOTO 200
1100 GOSUB 700
     DT(EP%)=T
     INPUT "  NOTATION"; PY$(EP%)
1137 INPUT "  AMOUNT"; AM(EP%)
     IF AM(EP%)<0 THEN GOTO 1137
     IF CD THEN AM(EP%) = -AM(EP%)
     GOSUB 900
1160 PRINT 
     INPUT "  CORRECT (Y/N)"; A$
     IF LEFT$(A$,1)<> "Y" THEN GOSUB 3100 : GOTO 1160
     IF EP%=MT% THEN PRINT "Transaction numbers equal allotted memory":\
        GOTO 9000
     IF EP%>=NA% THEN NA%=EP%+1
     IF EP%>MT%-5 THEN PRINT "You have ";MT%-EP%;\
        " transactions before you exceed allotted memory"
     RETURN

         REM DELETE ENTRY

2000 PRINT : PRINT "FIND THE ENTRY YOU WISH TO DELETE"        
     GOSUB 5000
     PRINT
     INPUT "  IS THIS THE ENTRY YOU WISH TO DELETE"; A$
        IF LEFT$(A$,1)<>"Y" THEN RETURN
     PRINT CN(EP%); "DELETED" : CN(EP%)=0
     RETURN

         REM CHANGE ENTRY

3000 PRINT : PRINT "FIND THEN ENTRY YOU WISH TO CHANGE" : PRINT
      GOSUB 5000 : REM FIND OPTIONS
3100 PRINT
     PRINT "    1 - CHANGE NUMBER"
     PRINT "    2 - CHANGE DATE"
     PRINT "    3 - CHANGE AMOUNT"
     PRINT "    4 - CHANGE STATUS"
     PRINT "    5 - CHANGE NOTATION"
     PRINT "    6 - QUIT CHANGES"
3200 PRINT : INPUT "  SELECTION"; T%
       IF T%<1 OR T%>6 THEN GOTO 3100
       IF T%=6 THEN RETURN
     ON T% GOSUB 3300, 3350, 3400, 3450, 3500
     GOSUB 900
     GOTO 3100
3300  INPUT "NUMBER"; CN(EP%)
       IF CN(EP%)<1 THEN GOTO 3300
      RETURN
3350  GOSUB 700
      DT(EP%)=T
      RETURN
3400  INPUT "  CHECK OR DEPOSIT (C/D)"; A$
      INPUT "  AMOUNT"; AM(EP%)
       IF AM(EP%)<0 THEN GOTO 3400
       IF LEFT$(A$,1)="C" THEN AM(EP%)=-AM(EP%)
      RETURN
3450  INPUT "  HAS IT CLEARED THE BANK"; A$
        CN(EP%)=ABS(CN(EP%))
        IF LEFT$(A$,1)="Y" THEN CN(EP%)=-CN(EP%)
      RETURN
3500  INPUT "  NOTATION"; PY$(EP%)
      RETURN

          REM BALANCE STATEMENT

4000  PRINT 
      INPUT "ENTER SERVICE CHARGES (Y/N)? ";A$
       IF LEFT$(A$,1)<>"Y" THEN 4025

          REM SERVICE CHARGE ENTRY

4015    FOR EP%=0 TO MT%
        IF CN(EP%)<>0 THEN NEXT
        PRINT "ENTER SERVICE CHARGE DATE -" :GOSUB 700
        DT(EP%)=T:CN(EP%)=EP% : CN(EP%)=-CN(EP%)
        PY$(EP%)="SERVICE CHARGE"
        INPUT "AMOUNT - "; AM(EP%) :AM(EP%)=-AM(EP%)
         IF EP%>MA% THEN NA%=EP%+1
	INPUT "ENTER ANOTHER SERVICE CHARGE (Y/N)? "; A$
         IF LEFT$(A$,1)="Y" THEN 4015

4025  PRINT
      PRINT "  ENTER THE NUMBERS OF THE CHECKS AND DEPOSITS WHICH"
      PRINT "  HAVE CLEARED THE BANK (ENTER A ZERO TO QUIT) "
4050  INPUT "      "; T2%
       IF T2%=0 THEN GOTO 4110
         FOR I% = 0 TO NA%
          IF ABS(CN(I%))<>T2% THEN NEXT
	IF I%>NA% THEN PRINT TAB(4); T2%; " NOT FOUND" : GOTO 4050
	IF CN(I%)<0 THEN PRINT T2%; "HAS ALREADY CLEARED " : GOTO 4050
       CN(I%)=-CN(I%)
       GOTO 4050
4110   CB=0 : BB=0
        FOR I% = 0 TO NA%
         IF CN(I%)<>0 THEN CB=CB+AM(I%)
         IF CN(I%)<0 THEN BB=BB+AM(I%)
        NEXT
      EP%=NA% : AM(EP%)=CB       
      PRINT : PRINT : PRINT " CHECKBOOK" ; : GOSUB 600
       PRINT
4185    IF AM(EP%)<0 THEN PRINT "  >>>>> OVERDRAFT <<<<<"
       AM(EP%)=BB
       PRINT
4200   PRINT : PRINT "  STATEMENT : "; : GOSUB 600
        IF AM(EP%)<0 THEN PRINT "  >>>>> OVERDRAFT <<<<<"
       RETURN

          REM FIND OPTION

5000   PRINT
       PRINT "   1 - FIND BY NUMBER"
       PRINT "   2 - FIND BY DATE"
       PRINT "   3 - FIND BY AMOUNT"
       PRINT "   4 - FIND BY NOTATION"
       PRINT "   5 - VIEW ALL ENTRIES"
       PRINT : INPUT "  SELECTION"; T%
        IF T%<1 OR T%>5 THEN GOTO 5000
       ON T% GOSUB 5200, 5250, 5300, 5350, 5400
       RETURN
5200   PRINT : INPUT "  NUMBER" ;T2%
        FOR T1% = 0 TO NA%
          IF ABS(CN(T1%))=T2% THEN EP%=T1% : GOSUB 900
        NEXT
        GOTO 5249
       PRINT "      NUMBER RANGE"
       INPUT "          LOWER LIMIT"; T2%
       INPUT "          UPPER LIMIT"; T3%
        FOR T1% = 0 TO NA%
     IF ABS(CN(T1%))>=T2% AND ABS(CN(T1%))<=T3 THEN EP%=T1% : GOSUB 900
     IF ABS(CN(T1%))=T2% THEN EP%=T1%
        NEXT
5249   RETURN
5250   PRINT "   DATE RANGE"
       PRINT "      LOWER LIMIT"
         GOSUB 700 : T2=T
       PRINT "      UPPER LIMIT"
         GOSUB 700 : T3=T
       FOR T1% = 0 TO NA%
         IF DT(T1%)>=T2 AND DT(T1%)<=T3 THEN EP%=T1% : GOSUB 900
       NEXT
       RETURN
5300   PRINT "    AMOUNT"
       INPUT "       LOWER LIMIT"; T2%
       INPUT "       UPPER LIMIT"; T3%
       FOR T1% = 0 TO NA%
        IF AM(T1%)>=T2% AND AM(T1%)<=T3% THEN EP%=T1% : GOSUB 900
       NEXT
       RETURN
5350   INPUT "    EXACT NOTATION"; A$
       FOR T1% = 0 TO NA%
       IF PY$(T1%)=A$ THEN EP%=T1% : GOSUB 900
       NEXT
       RETURN
5400   FOR T1% = 0 TO NA%
        IF CN(T1%) <>0 THEN EP%=T1% : GOSUB 900
       NEXT
       PRINT : INPUT "  CONTINUE ?"; LINE A$
       RETURN
6000	 LPRINTER : LP%=1
	FOR T1% = 0 TO NA%
	  IF CN(T1%)<>0 THEN EP%=T1% : GOSUB 900
	  P%=1 : REM RESET COUNTER FOR CONT. MESS
	  LP%=LP%+1
	  IF LP%>55 THEN PRINT CHR$(12) : LP%=1
	NEXT
	GOSUB 4110
	CONSOLE
        RETURN

        REM SAVE FILE

9000  PRINT "  UPDATING "; FILENAME$

	REM  DELETE BACK-UP FILE
      IF END #1 THEN 9010
      OPEN FILENAME$+".BAK" AS 1
      DELETE 1

9010	REM  RENAME PRESENT FILE TO BAK

      DUMMY%=RENAME(FILENAME$+".BAK",FILENAME$+".CHK")
      IF NOT DUMMY% THEN PRINT "Cannot RENAME file"

	REM  UPDATE NEW FILE

       CREATE FILENAME$+".CHK" AS 1
       A$=" "
       T1=0 
9100   T2=999999
       FOR I% = 0 TO NA%-1
         IF ABS(CN(I%))>T1 AND ABS(CN(I%))<T2 THEN \
          T2=ABS(CN(I%)) : T3=I%
       NEXT I%
       IF T2=999999 THEN GOTO 9200
       I%=T3
       PRINT #1; CN(I%), DT(I%), AM(I%), PY$(I%)
       T1=T2
       GOTO 9100
9200   PRINT #1; 0, 0, 0, A$
       CLOSE 1
       PRINT "UPDATING COMPLETED.."
	CHAIN "CMENU"
       END
100
9200   PRINT #1; 0, 0, 0, A$
       CLOSE 1
       PRINT "UPDATING COMPLETED.."
	CHAIN "CMENU"
       END
