home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / simtel / sigm / vols000 / vol072 / checkbk.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1984-04-29  |  10.6 KB  |  450 lines

  1. (************************************************
  2. *
  3. *        CHECKBK PROGRAM
  4. *
  5. *  It always shocks me when I do something I don't
  6. * think I would ever do but when I was handed this 
  7. * program from BYTE magazine I really scared myself.
  8. * I sat down that same day and four hours later had
  9. * it all typed in and debugged. As lazy as I am that
  10. * set a record. I have never been know to stick to
  11. * it that long. Ray Penley you would have been 
  12. * proud of me.
  13. *
  14. *  I always like to give credit to the author of a 
  15. * program but in this case I'll need help. BYTE blew
  16. * it pretty bad during the Jan 1982 issue and lost
  17. * a huge chunk of the West Coast's mail of their 
  18. * issue. Furthermore, they refused to resend it.
  19. * So this program was send to me on a poor paper
  20. * copy. I was able to guess at the program because
  21. * it had some logic to it but the Author I couldn't
  22. * figure out. So whoever you are, I apologize. But
  23. * this was in the Jan 1982 issue of Byte under the
  24. * name of NOW. Pretty good job anyway.
  25. *  I wrote this in Pascal/Z and created a Data file
  26. * to go along with the program. You can go into the
  27. * source and change things but hang onto the data
  28. * file. Otherwise, you'll have to compile twice.
  29. * Once to comment out the READFILE procedure so you
  30. * can run the program and create the disk data file.
  31. * Then you'll have to put READFILE back in and re-
  32. * compile.
  33. *
  34. *  How about you all improveing this thing and sending
  35. * me the updates for the membership. I'll be 
  36. * working on it.
  37. *
  38. * Charlie Foster, March 1982
  39. **************************************************)
  40.     
  41. PROGRAM checkbk;
  42.  
  43. CONST
  44.     maxItems = 300;
  45.     maxCodes = 50;
  46.     maxAddCode = 10;
  47.     diskFile = 'a:DATA.82';
  48. TYPE
  49.     itemData = RECORD
  50.         itemNumber : INTEGER;
  51.         month      : INTEGER;
  52.         day        : INTEGER;
  53.         year       : INTEGER;
  54.         amount     : REAL;
  55.         description: STRING 30;
  56.         code       : INTEGER;
  57.         END;
  58.  
  59.     $STRING0 = STRING 0;
  60.     $STRING255 = STRING 255;
  61. VAR
  62.     command     : CHAR;
  63.     ItemCode   : ARRAY[1..maxCodes] OF STRING 15;
  64.     items  : ARRAY[1..maxItems] OF itemData;
  65.     itemLast    : 1..maxItems;
  66.     dataFile    : File of itemData;
  67.     linesPrinted    : 0..80;
  68.     codeAmount    : ARRAY[1..maxCodes] OF REAL;
  69.     entryYear    : INTEGER;
  70.     swaped        : BOOLEAN;
  71.     answer        : CHAR;
  72.     result        : INTEGER;
  73.  
  74. FUNCTION length (x:$STRING255) : INTEGER; EXTERNAL;
  75.  
  76. PROCEDURE initialize;    {this sets initial code values}
  77.  
  78. VAR
  79.     count : 0..maxItems;
  80. BEGIN
  81.     ItemLast := 1;
  82.     FOR count := 1 TO maxCodes DO
  83.       ItemCode[count] := '               ';
  84.     
  85.     {now we list the code items, can be changed}
  86. {Family}
  87.     ItemCode[1] := 'Zug Balance';
  88.     ItemCode[2] := 'Family Balance';
  89.     ItemCode[3] := 'Zug Deposit';
  90.     ItemCode[4] := 'Family Deposit';
  91.     ItemCode[5] := 'Zug Interest';
  92.     ItemCode[6] := 'Family Interest';
  93.     { #'s 7,8,8,10 for future}
  94.     ItemCode[11] := 'House Payment';
  95.     ItemCode[12] := 'Car Lease';
  96.     ItemCode[13] := 'Car Expenses';
  97.     ItemCode[14] := 'Electricity';
  98.     ItemCode[15] := 'Gas';
  99.     ItemCode[16] := 'Credit Cards';
  100.     ItemCode[17] := 'Insurance';
  101.     ItemCode[18] := 'Telephone';
  102.     ItemCode[19] := 'Contributions';
  103.     ItemCode[20] := 'Water/Sewer';
  104.     ItemCode[21] := 'Taxes';
  105.     ItemCode[22] := 'Food';
  106.     ItemCode[23] := 'Medical';
  107.     ItemCode[24] := 'Misc.expenses';
  108. {Pascal/Z}
  109.     ItemCode[25] := 'Computer Lease';
  110.     ItemCode[26] := 'Car Expenses';
  111.     ItemCode[27] := 'Disks';
  112.     ItemCode[28] := 'Printing';
  113.     ItemCode[29] := 'Postage';
  114.     ItemCode[30] := 'Books';
  115.     ItemCode[31] := 'Software';
  116.     ItemCode[32] := 'Printer Expen.';
  117.     ItemCode[33] := 'Trip Expen.';
  118.     ItemCode[34] := 'Equipment';
  119.     ItemCode[35] := 'Misc.expenses';
  120.     { #'s 36 through 50 for future }
  121.  
  122. END;
  123.  
  124. PROCEDURE newpage;
  125.     { print form-feed and 2 blank lines}
  126. BEGIN
  127.     WRITELN(CHR(12));
  128.     WRITELN;
  129.     WRITELN;
  130.     linesPrinted := 0;
  131. END;
  132.  
  133. PROCEDURE instructions;
  134.     { print description of program operation}
  135.     { ADD my header program once debugged}
  136. VAR
  137.     pause,answer : CHAR;
  138.     count        : INTEGER;
  139. BEGIN
  140.     newpage;
  141.     WRITELN(' ':15,'THE (your name) CHECKBOOK PROGRAM');
  142.     WRITELN(' ':24,'Version 1.0');
  143.     WRITELN;
  144.     WRITE('Do you want some instructions?  ');
  145.     READ(answer);
  146.     WRITELN;
  147.     IF (answer = 'Y') OR (answer ='y') THEN
  148.       BEGIN
  149.         newpage;
  150.         WRITELN('-----------Commands------------');
  151.         WRITELN;
  152.         WRITELN('A - Add an item');
  153.         WRITELN('R - Remove an item');
  154.         WRITELN('P - Print all items');
  155.         WRITELN('B - Print Balance');
  156.         WRITELN('S - Sort by date');
  157.         WRITELN('D - Dump to disk');
  158.         WRITELN('L - Load from disk');
  159.         WRITELN('Q - Quit');
  160.         WRITELN;
  161.         WRITELN;
  162.         WRITELN ('Hit any key to continue---');
  163.         READLN (pause);             
  164.         WRITELN('Code          Description');
  165.         FOR  count := 1 TO 27 DO
  166.         WRITE('-');
  167.         WRITELN;
  168.         FOR count := 1 TO 50 DO
  169.         IF ItemCode[count] <> '               ' THEN
  170.           WRITELN(count:3,'   ',ItemCode[count]);
  171.     END;
  172. END;
  173.  
  174.  
  175. PROCEDURE heading;
  176.     {print heading for new page of item printout}
  177. VAR
  178.     count : 0..79;
  179. BEGIN
  180.     WRITE(' Item     Date         Amount       ');
  181.     WRITE('      Description              Code');
  182.     WRITELN;
  183.     FOR count := 1 TO 79 DO
  184.       WRITE('-');
  185.     WRITELN;
  186. END;
  187.  
  188. PROCEDURE itemPrint ( count : INTEGER);
  189.     { print data on one item}
  190. BEGIN
  191.     WITH items[count] DO
  192.       BEGIN
  193.         WRITE(itemNumber:5);
  194.         WRITE(month:5,'/');
  195.         IF day < 10 THEN
  196.           WRITE('0',day:1)
  197.         ELSE
  198.           WRITE(DAY:2);
  199.         WRITE('/',year:2);
  200.         WRITE(amount:14:2);
  201.         WRITE('    ',description);
  202.         WRITE('  ',ItemCode[code]);
  203.         END;
  204. END;
  205.  
  206. PROCEDURE printAll;
  207.     { print data for all items in file}
  208. VAR
  209.     count : INTEGER;
  210. BEGIN
  211.     newpage;
  212.     heading;
  213.     FOR count := 1 TO itemLast-1 DO
  214.       BEGIN
  215.         IF linesPrinted = 55 THEN
  216.         BEGIN
  217.           newpage;
  218.           heading;
  219.         END;    
  220.             itemPrint(count);
  221.         WRITELN;
  222.       END;
  223.     WRITELN;
  224. END;
  225.  
  226. PROCEDURE balance;
  227.     { print totals by categories and net balance }
  228. VAR
  229.     item : 1..maxItems;
  230.     balance : REAL;
  231. BEGIN
  232.     FOR item := 1 TO maxCodes DO
  233.       codeAmount[item] := 0.00;
  234.     balance := 0.00;
  235.     FOR  item := 1 TO itemLast-1 DO
  236.       WITH items[item] DO
  237.       codeAmount[code] := codeAmount[code] + amount;
  238.     FOR item := 1 TO maxAddCode DO
  239.       balance := balance + codeAmount[item];
  240.     FOR item := maxAddCode + 1 TO maxCodes DO
  241.      balance := balance - codeAmount[item];
  242.     newpage;
  243.     WRITELN('   Category            Amount');
  244.     FOR item := 1 TO 32 DO
  245.       WRITE('-');
  246.     WRITELN;
  247.     FOR item := 1 TO maxCodes DO
  248.       IF codeAmount[item] <> 0.00 THEN
  249. WRITELN(itemCode[item],'  -',codeAmount[item]:14:2);
  250.     FOR item := 1 TO 32 DO
  251.       WRITE('-');
  252.     WRITELN;
  253.     WRITELN('Balance          -',balance:14:2);
  254.     WRITELN;
  255. END;
  256.  
  257. PROCEDURE remove;
  258.     { remove item from file }
  259. VAR
  260.     remove : CHAR;
  261.     found,
  262.     item   : INTEGER;
  263.     itemRemove : INTEGER;
  264. BEGIN
  265.     found := 0;
  266.     WRITELN;
  267.     WRITE(' Remove item number - ');
  268.     READ(itemRemove);
  269.     FOR item := 1 TO itemLast - 1 DO
  270.       IF items[item].itemNumber = itemRemove THEN
  271.         found := item;
  272.     WRITELN;
  273.     IF found <> 0 THEN
  274.       BEGIN
  275.         heading;
  276.         itemPrint(found);
  277.     WRITELN;
  278.     WRITELN;
  279.     WRITE(' Remove ? ');
  280.     READ(remove);
  281.     IF (remove = 'Y') OR (remove = 'y') THEN
  282.       BEGIN
  283.         FOR item := found TO itemLast - 1 DO
  284.           items[item] := items[item + 1];
  285.         itemLast := itemLast - 1;
  286.        END;
  287.       END;
  288.     IF found = 0 THEN
  289.       WRITELN(' Item not in list ...');
  290. END;
  291.  
  292. PROCEDURE entry;
  293.     { console entry of check/deposit data }
  294. VAR
  295.     ch : CHAR;
  296. BEGIN
  297.     REPEAT
  298.       WITH items[itemLast] DO
  299.         BEGIN
  300.           description := '                              ';
  301.           WRITELN;
  302.           WRITE(' Item number ? ');
  303.           READLN(itemNumber);
  304.           WRITE(' Month ? ');
  305.           READ(month);
  306.           WRITE(' Date ? ');
  307.           READ(day);
  308.           WRITE (' Amount ?');
  309.           READ(amount);
  310.           WRITELN('               ------------------------------');
  311.           WRITE(' Description ? ');
  312.           READLN(description);
  313.           WHILE length(description) <> 30 DO
  314.             APPEND(description,' ');
  315.           WRITE(' Code ? ');
  316.           READ(code);
  317.           year := entryYear;
  318.           WRITELN;
  319.        END;
  320.     heading;
  321.     itemPrint(itemLast);
  322.     WRITELN;
  323.     WRITELN;
  324.     WRITE(' Correct ?');
  325.     READ(ch);
  326.       UNTIL (ch = 'Y') OR (ch = 'y');
  327.     items[itemLast + 1] := items[itemLast];
  328.     items[itemLast + 1].itemNumber := 0;
  329.     itemLast := itemLast + 1;
  330.     WRITELN;
  331. END;
  332.  
  333. PROCEDURE swapItems(item : INTEGER ;
  334.             VAR swaped : BOOLEAN);
  335.     {exchange file data at location with location+1}
  336. BEGIN
  337.     items[maxItems] := items[item];
  338.     items[item] := items[item + 1];
  339.     items[item + 1] := items[maxItems];
  340.     swaped := TRUE
  341. END;
  342.  
  343. PROCEDURE dateSort;
  344.     { sort data file by date }
  345. VAR
  346.     finish,
  347.     item       : 0..maxItems;
  348.     dateFirst,
  349.     dateSecond : REAL;
  350.     itemFirst,
  351.     itemSecond : INTEGER;
  352. BEGIN
  353.     finish := itemLast - 2;
  354.     REPEAT
  355.       swaped := FALSE;
  356.       FOR item := 1 TO finish DO
  357.         BEGIN
  358.           WITH items[item] DO
  359.         BEGIN
  360.           dateFirst := year * 10000.0 + month
  361.                    * 100.0 + day;
  362.           itemFirst := itemNumber;
  363.         END;
  364.          WITH items[item+1] DO
  365.         BEGIN
  366.           dateSecond := year * 10000.0 + month
  367.                 * 100.0 + day;
  368.           itemSecond := itemNumber;
  369.         END;
  370.          IF dateFirst > dateSecond THEN
  371.         swapItems(item,swaped);
  372.          IF (dateFirst = dateSecond) AND
  373.         (itemFirst > itemSecond) THEN
  374.         swapItems(item,swaped);         
  375.              END;
  376.     IF finish > 2 THEN
  377.       finish := finish - 1;
  378.      UNTIL NOT swaped
  379. END;
  380.  
  381. PROCEDURE dump;
  382.     { write file of item information to disk }
  383. VAR
  384.     count : INTEGER;
  385. BEGIN
  386.     REWRITE(diskFile,dataFile);
  387.     FOR count := 1 TO itemLast DO
  388.       WRITE(dataFile,items[count]);
  389. END;
  390.  
  391. PROCEDURE readDisk;
  392.     { load data from disk to file}
  393. BEGIN
  394.     WRITELN;
  395.     RESET(diskFile,dataFile);
  396.     itemLast := 1;
  397.     REPEAT
  398.       READ(dataFile,items[itemLast]);
  399.       WRITE('.');
  400.       IF itemLast MOD 10 = 0 THEN
  401.         WRITELN;
  402.       itemLast := itemLast + 1;
  403.     UNTIL items[itemLast - 1].itemNumber = 0;
  404.       itemLast := itemLast - 1;
  405.       WRITELN;
  406. END;
  407.  
  408. PROCEDURE progCommands;
  409.     { console entry of program command }
  410. BEGIN
  411.     WRITELN;
  412.     WRITE(' Command ? ');
  413.     READ (command);
  414.     CASE command OF
  415.       'A','a' : entry;
  416.       'B','b' : balance;
  417.       'P','p' : printAll;
  418.       'R','r' : remove;
  419.       'S','s' : dateSort;
  420.       'D','d' : dump;
  421.       'L','l' : readDisk;
  422.     ELSE:
  423.       IF (command = 'Q') OR (command = 'q') THEN
  424.         WRITELN ('Leaving Program')
  425.           ELSE
  426.         WRITELN(' Invalid command...');
  427.     END;
  428. END;
  429.  
  430. {----------- MAIN ------------------}
  431. BEGIN
  432.     initialize;
  433.     instructions;
  434.     WRITELN;
  435.     WRITE('Enter Year "2-digit" for new entries - ');
  436.     READ(entryYear);
  437.     WRITELN;
  438.     WRITELN;
  439.     readDisk;
  440.     REPEAT
  441.       progCommands;
  442.     UNTIL (command = 'Q') OR (command = 'q');
  443.     WRITELN;
  444.     WRITE(' Save file ?   ');
  445.     READ(answer);
  446.     IF (answer = 'Y') OR (answer = 'y') THEN
  447.       dump;
  448. END.
  449.