home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1994 #1 / monster.zip / monster / FINANCE / CB_101.ZIP / CB.C next >
C/C++ Source or Header  |  1994-01-16  |  30KB  |  862 lines

  1. //------------------------------------------------------------------------------
  2. //
  3. //     FILE: CB.C
  4. //
  5. //    Freeware, not for resale. Copyright 1994 William Querry. All rights reserved.
  6. //
  7. //        1.01  01-16-94  Removed text "Bank Balance" (that was there in error)
  8. //                    on the "========" line in reconcile area.
  9. //          01-16-94  Added output header: Program name, version, run date
  10. //
  11. //        Program for us that rarely get around to balancing our checkbook and
  12. //        all of a sudden find that our balance and the bank's don't match for
  13. //        some reason. Nothing fancy here, but it works.
  14. //
  15. //        Reads text file (CHK_BOOK.TXT) of checkbook entries formatted as:
  16. //        1. Check:
  17. //            [O]C,number,date,amount[,who]
  18. //        2. Check (voided):
  19. //            V,number[,date]
  20. //        3. ATM withdrawal:
  21. //            [O]A,date,amount[,where]
  22. //        4. Deposit:
  23. //            [O]D,date,amount[,what]
  24. //            5. Service Charge:
  25. //            S,date,amount[,comment]
  26. //            6. Interest:
  27. //            I,date,amount[,comment]
  28. //            7. Manual deposit entry for balancing checkbook:
  29. //                +,date,amount[,comment]
  30. //            8. Manual withdrawal entry for balancing checkbook:
  31. //                -,date,amount[,comment]
  32. //
  33. //            [O] outstanding entry (not yet cleared bank)
  34. //       [,who] who check was written to (up to 80 chars)
  35. //            [,where] where ATM is located (up to 80 chars)
  36. //            [,what] what the deposit represents (up to 80 chars)
  37. //
  38. //------------------------------------------------------------------------------
  39. #include <dos.h>                       // MSC 5.xx standard lib. function proto
  40. #include <stdio.h>                     // MSC 5.xx standard lib. function proto
  41. #include <stdlib.h>                    // MSC 5.xx standard lib. function proto
  42. #include <string.h>                    // MSC 5.xx standard lib. function proto
  43.  
  44. #include "\lib\esiutil5\culproto.h"    // ESI Utility lib vers. 5.0 protos
  45.  
  46. #define DEBUG_ON 0                     // set to enable debugging printfs
  47.  
  48. #define MAX_TRANS 3000                 // max. number transactions permitted
  49.  
  50. int main(int argc, char *argv[]);
  51. void amt_to_bfr(long amt,char *amt_bfr);
  52. int display_trans(void);
  53. int read_trans(void);
  54.  
  55. extern int fgets_stripped(char *bfr,int size,FILE *fs,int *len);
  56. extern void MOV_MEM(void *sourceptr,void *destptr,int movbytes);
  57.  
  58. struct transactions_str
  59. {
  60.     int cleared;                        // set if check/deposit has cleared
  61.     int voided;                         // set if check was voided
  62.  
  63.     int type;                           // transaction type
  64.     unsigned int date;                  // transaction date
  65.     long amt;                           // transaction amount
  66.  
  67.     int no;                             // check number
  68.     char *desc;                         // optional who/what/where
  69. };
  70. struct transactions_str trans[MAX_TRANS];
  71.  
  72. //
  73. // Transaction types
  74. //
  75. #define CHECK 'C'                      // withdrawal
  76. #define ATM 'A'                        // withdrawal ATM or counter check
  77. #define SERVICE_CHARGE 'S'             // withdrawal
  78. #define DEPOSIT 'D'                    // deposit
  79. #define INTEREST 'I'                   // deposit
  80. #define MANUAL_PLUS '+'                // manual override deposit
  81. #define MANUAL_MINUS '-'               // manual override withdrawal
  82. #define VOIDED 'V'                     // voided check
  83. #define OUTSTANDING 'O'                // outstanding transaction
  84.  
  85. //
  86. // exit error codes
  87. //
  88. #define SUCCESS 0
  89. #define NO_FILE 1
  90. #define BAD_RECORD 2
  91. #define BAD_TYPE 3
  92.  
  93. int trecs;                             // total number of records in struct
  94.  
  95.  
  96. int main(int argc, char *argv[])
  97. {
  98.    int ecode;
  99.    struct dosdate_t date;
  100. #if DEBUG_ON
  101.     int x;
  102. #endif
  103.  
  104. #if DEBUG_ON
  105.    x = sizeof(struct transactions_str);
  106.    x = sizeof(trans);
  107. #endif
  108.  
  109.    argv = argv;                        // currently not used
  110.  
  111.    _dos_getdate(&date);
  112.  
  113.    printf("CB 1.01 (quick and dirty checkbook reconciler). Run on: %d/%d/%d\n\n",date.month,date.day,date.year-1900);
  114.  
  115.    if (argc >= 2)                      // wants some help since no parms used
  116.    {
  117.        printf("Freeware, not for resale. Copyright 1994 William Querry. All rights reserved.\n\n");
  118.        printf("Reads a checkbook file (CHK_BOOK.TXT) and displays a checkbook ledger.\n");
  119.        printf("Use command line re-direction if you want to make and print a file.\n");
  120.        printf("Look at source code header comments and sample CHK_BOOK.TXT for file format.\n");
  121.        return(0);
  122.    }
  123.    else
  124.    {
  125.        if ((ecode = read_trans()) == SUCCESS)
  126.            ecode = display_trans();
  127.  
  128.         if (ecode != SUCCESS)
  129.             beep();
  130.  
  131.         return(ecode);
  132.     }
  133. }                                      // end main()
  134.  
  135.  
  136. //------------------------------------------------------------------------------
  137. //
  138. //---void amt_to_bfr(long amt,char *bfr)
  139. //
  140. //------------------------------------------------------------------------------
  141. void amt_to_bfr(long amt,char *amt_bfr)
  142. {
  143.     int x;
  144.    char bfr[256],vbfr[20];
  145.  
  146.     ltoa(amt,bfr,10);
  147.     x = strlen(bfr);
  148.     switch (x)
  149.     {
  150.         case 0:
  151.             strcpy(vbfr,"0.00");
  152.             break;
  153.         case 1:
  154.             strcpy(vbfr,"0.0");
  155.             strcat(vbfr,bfr);
  156.             break;
  157.         case 2:
  158.             strcpy(vbfr,"0.");
  159.             strcat(vbfr,bfr);
  160.             break;
  161.         default:
  162.             memset(vbfr,0,9);
  163.             strleft(bfr,vbfr,x-2,10);
  164.             strcat(vbfr,".");
  165.             strright(bfr,&vbfr[x-1],x-2,8);
  166.             break;
  167.     }
  168.     amt_bfr[8] = 0;
  169.     strrfld(amt_bfr,vbfr,8);
  170. }                                      // end amt_to_bfr()
  171.  
  172. //------------------------------------------------------------------------------
  173. //
  174. //---int display_trans(void)
  175. //
  176. // Display format:
  177. //
  178. //          1         2         3         4         5         6         7
  179. //01234567890123456789012345678901234567890123456789012345678901234567890123456789
  180. //  Number    Date       Check Amt   Deposit Amt   Balance   Comments
  181. //  12345     11/11/95   12345.67                  12345.67  fffffff
  182. //O 12345     11/11/95   12345.67                  12345.67
  183. //  12345     VOID VOID VOID VOID VOID VOID VOID   12345.67
  184. //  Deposit   11/11/95               12345.67      12345.67
  185. //O Deposit   11/11/95               12345.67      12345.67
  186. //  ATM       11/11/95   12345.67                  12345.67
  187. //O ATM       11/11/95   12345.67                  12345.67
  188. //  SC        11/11/95   12345.67                  12345.67
  189. //  Interest  11/11/95               12345.67      12345.67
  190. //  Man. Sub  11/11/95   12345.67                  12345.67
  191. //  Man. Add  11/11/95               12345.67      12345.67
  192. //--------------------------------------------------------------------------------
  193. //Total Checks   : 1234  $123456.12
  194. //Total ATMs     : 1234  $123456.12
  195. //Total Deposits : 1234  $123456.12
  196. //Total Interests: 1234  $123456.12
  197. //Total S-Charges: 1234  $123456.12
  198. //Total Man. Adds: 1234  $123456.12
  199. //Total Man. Subs: 1234  $123456.12
  200. //Total Voids    : 1234
  201. //--------------------------------------------------------------------------------
  202. //Bank Balance                 $ ______.__
  203. //1234 Checks/ATM Outstanding -$ 123456.12
  204. //1234 Deposits Outstanding   +$ 123456.12
  205. //                             ===========
  206. //         Reconciled Balance $ _______.__
  207. //01234567890123456789012345678901234567890123456789012345678901234567890123456789
  208. //          1         2         3         4         5         6         7
  209. //------------------------------------------------------------------------------
  210. int display_trans(void)
  211. {
  212.     static char voided_txt[] = "VOID VOID VOID VOID VOID VOID VOID";
  213.     static char col_txt[] = "  Number    Date       Check Amt   Deposit Amt   Balance   Comments\n";
  214.     static char div_txt[] = "--------------------------------------------------------------------------------\n";
  215.  
  216.     static char no_atm_txt[] = "ATM";
  217.     static char no_dep_txt[] = "Deposit";
  218.     static char no_sc_txt[] = "SC";
  219.     static char no_int_txt[] = "Interest";
  220.     static char no_add_txt[] = "Man. Add";
  221.     static char no_sub_txt[] = "Man. Sub";
  222.  
  223.  
  224.    int ecode;
  225.    int yr,mon,day;
  226.    int i;
  227.    int tot_deposits,      tot_checks,     out_deposits,     out_checks;
  228.    long tot_deposits_amt, tot_checks_amt, out_deposits_amt, out_checks_amt;
  229.    int tot_int_no,   tot_sc_no,  tot_atm_no;
  230.    long tot_int_amt, tot_sc_amt, tot_atm_amt;
  231.    int tot_add_no,   tot_sub_no;
  232.    long tot_add_amt, tot_sub_amt;
  233.    long run_balance;
  234.    int tot_void_checks;
  235.    char date_bfr[20],no_bfr[20],amt_bfr[20],bal_bfr[20],dbfr[80];
  236.  
  237. #if DEBUG_ON
  238.     char bfr[256];
  239.  
  240.     printf("\nValues in transaction array:\n");
  241.     for (i = 0; i < trecs; i++)
  242.     {
  243.         unpacdat(trans[i].date,&yr,&mon,&day);
  244.         strdate(bfr,yr,mon,day,3);
  245.         printf("%d\t TYPE=%c\t DATE=%s\t ",i,trans[i].type,bfr);
  246.  
  247.         amt_to_bfr(trans[i].amt,bfr);
  248.         printf("AMT=%s (%ld)\t ",bfr,trans[i].amt);
  249.  
  250.         if (trans[i].desc)
  251.             printf("DESC=%s",trans[i].desc);
  252.         printf("\n");
  253.     }
  254. #endif
  255.  
  256.    // initialize totals
  257.    tot_deposits     = out_deposits     = tot_checks     = out_checks = 0;
  258.    tot_deposits_amt = out_deposits_amt = tot_checks_amt = out_checks_amt = 0L;
  259.    tot_int_no  = tot_sc_no  = tot_atm_no  = tot_add_no  = tot_sub_no = 0;
  260.    tot_int_amt = tot_sc_amt = tot_atm_amt = tot_add_amt = tot_sub_amt = 0L;
  261.    tot_void_checks = 0;
  262.    run_balance = 0L;
  263.    ecode = SUCCESS;                    // assume successful run
  264.  
  265.     printf(col_txt);
  266.     for (i = 0; i < trecs; i++)
  267.     {
  268.         itoa(trans[i].no,no_bfr,10);
  269.  
  270.         unpacdat(trans[i].date,&yr,&mon,&day);
  271.         strdate(date_bfr,yr,mon,day,3);
  272.  
  273.         amt_to_bfr(trans[i].amt,amt_bfr);
  274.  
  275.         memset(dbfr,' ',sizeof(dbfr));
  276.         dbfr[sizeof(dbfr)-1] = 0;
  277.  
  278.         if (trans[i].cleared)
  279.             dbfr[0] = ' ';
  280.         else
  281.             dbfr[0] = 'O';
  282.  
  283.         switch (trans[i].type)
  284.         {
  285.             case CHECK:                   // transaction = check
  286.                 tot_checks++;
  287.                 tot_checks_amt += trans[i].amt;
  288.                 run_balance -= trans[i].amt;
  289.                 if (!trans[i].cleared)
  290.                 {
  291.                     out_checks++;
  292.                     out_checks_amt += trans[i].amt;
  293.                 }
  294.                 MOV_MEM(no_bfr,   &dbfr[2],  strlen(no_bfr));
  295.                 MOV_MEM(date_bfr, &dbfr[12], strlen(date_bfr));
  296.                 MOV_MEM(amt_bfr,  &dbfr[23], strlen(amt_bfr));
  297.                 break;
  298.  
  299.             case VOIDED:                  // transaction = voided check
  300.                 tot_void_checks++;
  301.                 MOV_MEM(no_bfr,   &dbfr[2],  strlen(no_bfr));
  302.                 MOV_MEM(voided_txt,&dbfr[12],strlen(voided_txt));
  303.                 break;
  304.  
  305.             case ATM:                     // transaction = ATM/counter check
  306.                 tot_atm_no++;
  307.                 tot_atm_amt += trans[i].amt;
  308.                 run_balance -= trans[i].amt;
  309.                 if (!trans[i].cleared)
  310.                 {
  311.                     out_checks++;
  312.                     out_checks_amt += trans[i].amt;
  313.                 }
  314.                 MOV_MEM(no_atm_txt, &dbfr[2],  strlen(no_atm_txt));
  315.                 MOV_MEM(date_bfr,   &dbfr[12], strlen(date_bfr));
  316.                 MOV_MEM(amt_bfr,    &dbfr[23], strlen(amt_bfr));
  317.                 break;
  318.  
  319.             case SERVICE_CHARGE:          // transaction = service charge
  320.                 tot_sc_no++;
  321.                 tot_sc_amt += trans[i].amt;
  322.                 run_balance -= trans[i].amt;
  323.                 MOV_MEM(no_sc_txt, &dbfr[2],  strlen(no_sc_txt));
  324.                 MOV_MEM(date_bfr,  &dbfr[12], strlen(date_bfr));
  325.                 MOV_MEM(amt_bfr,   &dbfr[23], strlen(amt_bfr));
  326.                 break;
  327.  
  328.             case DEPOSIT:                 // transaction = deposit
  329.                 tot_deposits++;
  330.                 tot_deposits_amt += trans[i].amt;
  331.                 run_balance += trans[i].amt;
  332.                 if (!trans[i].cleared)
  333.                 {
  334.                     out_deposits++;
  335.                     out_deposits_amt += trans[i].amt;
  336.                 }
  337.                 MOV_MEM(no_dep_txt, &dbfr[2],strlen(no_dep_txt));
  338.                 MOV_MEM(date_bfr, &dbfr[12], strlen(date_bfr));
  339.                 MOV_MEM(amt_bfr,  &dbfr[35], strlen(amt_bfr));
  340.                 break;
  341.  
  342.             case INTEREST:                // transaction = interest
  343.                 tot_int_no++;
  344.                 tot_int_amt += trans[i].amt;
  345.                 run_balance += trans[i].amt;
  346.                 MOV_MEM(no_int_txt, &dbfr[2],strlen(no_int_txt));
  347.                 MOV_MEM(date_bfr, &dbfr[12], strlen(date_bfr));
  348.                 MOV_MEM(amt_bfr,  &dbfr[35], strlen(amt_bfr));
  349.                 break;
  350.  
  351.             case MANUAL_PLUS:             // transaction = balance checkbook, add
  352.                 tot_add_no++;
  353.                 tot_add_amt += trans[i].amt;
  354.                 run_balance += trans[i].amt;
  355.                 MOV_MEM(no_add_txt, &dbfr[2],strlen(no_add_txt));
  356.                 MOV_MEM(date_bfr, &dbfr[12], strlen(date_bfr));
  357.                 MOV_MEM(amt_bfr,  &dbfr[35], strlen(amt_bfr));
  358.                 break;
  359.  
  360.             case MANUAL_MINUS:            // transaction = balance checkbook, minus
  361.                 tot_sub_no++;
  362.                 tot_sub_amt += trans[i].amt;
  363.                 run_balance -= trans[i].amt;
  364.                 MOV_MEM(no_sub_txt, &dbfr[2],strlen(no_sub_txt));
  365.                 MOV_MEM(date_bfr, &dbfr[12], strlen(date_bfr));
  366.                 MOV_MEM(amt_bfr,  &dbfr[23], strlen(amt_bfr));
  367.                 break;
  368.  
  369.             default:
  370.                 printf("** ERROR ** Invalid type code=%d\n",trans[i].type);
  371.                 return(BAD_TYPE);
  372.                 break;
  373.         }
  374.  
  375.         amt_to_bfr(run_balance,bal_bfr);
  376.         MOV_MEM(bal_bfr,  &dbfr[49], strlen(amt_bfr));
  377.         if (trans[i].desc)
  378.             MOV_MEM(trans[i].desc,&dbfr[59],strlen(trans[i].desc));
  379.         printf("%s\n",dbfr);
  380.     }
  381.  
  382.     printf(div_txt);
  383.     amt_to_bfr(tot_checks_amt,bal_bfr);
  384.     printf("Total Checks   : %d  $%s\n",tot_checks,bal_bfr);
  385.  
  386.     amt_to_bfr(tot_atm_amt,bal_bfr);
  387.     printf("Total ATMs     : %d  $%s\n",tot_atm_no,bal_bfr);
  388.  
  389.     amt_to_bfr(tot_deposits_amt,bal_bfr);
  390.     printf("Total Deposits : %d  $%s\n",tot_deposits,bal_bfr);
  391.  
  392.     amt_to_bfr(tot_int_amt,bal_bfr);
  393.     printf("Total Interests: %d  $%s\n",tot_int_no,bal_bfr);
  394.  
  395.     amt_to_bfr(tot_sc_amt,bal_bfr);
  396.     printf("Total S-Charges: %d  $%s\n",tot_sc_no,bal_bfr);
  397.  
  398.     amt_to_bfr(tot_add_amt,bal_bfr);
  399.     printf("Total Man. Adds: %d  $%s\n",tot_add_no,bal_bfr);
  400.  
  401.     amt_to_bfr(tot_sub_amt,bal_bfr);
  402.     printf("Total Man. Subs: %d  $%s\n",tot_sub_no,bal_bfr);
  403.  
  404.     printf("Total Voids    : %d\n",tot_void_checks);
  405.  
  406.     printf(div_txt);
  407.     printf("Bank Balance                 $ ______.__\n");
  408.     amt_to_bfr(out_checks_amt,bal_bfr);
  409.     printf("Checks/ATM Outstanding      -$  %s   (%d)\n",bal_bfr,out_checks);
  410.  
  411.     amt_to_bfr(out_deposits_amt,bal_bfr);
  412.    printf("Deposits Outstanding        +$  %s   (%d)\n",bal_bfr,out_deposits);
  413.  
  414.     printf("                             ===========\n");
  415.     printf("         Reconciled Balance $ _______.__\n");
  416.     return(ecode);                      // return error code
  417. }                                      // end display_trans()
  418.  
  419.  
  420. //------------------------------------------------------------------------------
  421. //
  422. //---int read_trans(void)
  423. //
  424. //------------------------------------------------------------------------------
  425. int read_trans(void)
  426. {
  427.     static char split_txt[] = "\t,";
  428.  
  429.     FILE *fstuff;
  430.    struct transactions_str *tptr;
  431.    char bfr[256],*ptr,*tcode,*field,copy_bfr[256];
  432.    int ecode,line,len;
  433.    int yr,mon,day;
  434.  
  435.    ecode = SUCCESS;                    // assume successful run
  436.  
  437.     // open transactions file
  438.     if ((fstuff = fopen("CHK_BOOK.TXT","r")) == NULL)
  439.     {
  440.         printf("** ERROR: Check book file (CHK_BOOK.TXT) is missing!\n\n");
  441.         ecode = NO_FILE;
  442.         goto getout;
  443.     }
  444.  
  445.     // read and parse all transaction records
  446.     for (trecs = 0, line = 0, tptr = &trans[0]; (trecs < MAX_TRANS); line++)
  447.     {
  448.        if (fgets_stripped(bfr,255,fstuff,&len) == NULL)
  449.            break;                        // no more records
  450.  
  451. #if DEBUG_ON
  452.         printf("Line %d\t: %s \n",line+1,bfr);
  453. #endif
  454.  
  455.         strcpy(copy_bfr,bfr);            // used for reporting errors
  456.  
  457.         ptr = &bfr[0];                   // point to transaction type code
  458.  
  459.         tptr = &trans[trecs];              // point to next record posn
  460.  
  461.         if (*ptr == OUTSTANDING)
  462.         {
  463.             tptr->cleared = 0;            // set transaction has not cleared
  464.             ptr++;                        // point to transaction type code
  465.         }
  466.         else
  467.             tptr->cleared = 1;            // assume transaction has cleared
  468.  
  469.         tptr->voided = 0;                // assume no voided check
  470.         tptr->date = 0;                  // set invalid date
  471.         tptr->amt = 0;                   // set no transaction amount
  472.         tptr->desc = 0;                  // set no transaction desc
  473.  
  474.         tcode = strtok(ptr,split_txt);   // isolate transaction code in record
  475.  
  476.         switch (tptr->type = *tcode)     // save/determine transaction type
  477.         {
  478.             case 0:                       // blank line - ignore
  479.             case ';':                     // comment line - ignore
  480.                 break;
  481.  
  482.             case CHECK:                   // transaction = check
  483.                 // parse check number
  484.                 if ((field = strtok(NULL,split_txt)) == 0)
  485.                 {
  486.                     ecode = BAD_RECORD;
  487.                     printf("** ERROR (line %d): Check record missing required check number field:\n\t%s\n",line,copy_bfr);
  488.                     goto getout;
  489.                 }
  490.                 tptr->no = atoi(field);              // save check number
  491.  
  492.                 // parse check date
  493.                 if ((field = strtok(NULL,split_txt)) == 0)
  494.                 {
  495.                     ecode = BAD_RECORD;
  496.                     printf("** ERROR (line %d): Check record missing required date field:\n\t%s\n",line,copy_bfr);
  497.                     goto getout;
  498.                 }
  499.                 if (icondate(field,&yr,&mon,&day))
  500.                 {
  501.                     ecode = BAD_RECORD;
  502.                     printf("** ERROR (line %d): Check record has invalid date field:\n\t%s\n",line,copy_bfr);
  503.                     goto getout;
  504.                 }
  505.                 tptr->date = packdate(yr,mon,day);   // convert date to DOS format
  506.  
  507.                 // parse check amount (whole dollars portion)
  508.                 if ((field = strtok(NULL,".")) == 0) // get whole dollar amount
  509.                 {
  510.                     ecode = BAD_RECORD;
  511.                     printf("** ERROR (line %d): Check record missing or invalid amount field:\n\t%s\n",line,copy_bfr);
  512.                     goto getout;
  513.                 }
  514.                 tptr->amt = atol(field) * 100;       // save whole dollars
  515.                 if (tptr->amt < 0)                   // Check must be positive!
  516.                 {
  517.                     ecode = BAD_RECORD;
  518.                     printf("** ERROR (line %d): Check record amount field must be positive:\n\t%s\n",line,copy_bfr);
  519.                     goto getout;
  520.                 }
  521.  
  522.                 // parse check amount (cents portion)
  523.                 if ((field = strtok(NULL,split_txt)) == 0)     // get cents amount
  524.                 {
  525.                     ecode = BAD_RECORD;
  526.                     printf("** ERROR (line %d): Check record missing cents amount:\n\t%s\n",line,copy_bfr);
  527.                     goto getout;
  528.                 }
  529.                 tptr->amt += atol(field);            // add in cents
  530.  
  531.                 // parse check description
  532.                 if (field = strtok(NULL,split_txt))  // get Check description
  533.                 {                                    // (if there is one)
  534.                     tptr->desc = malloc(strlen(field) + 1);
  535.                     strcpy(tptr->desc,field);
  536.                 }
  537.                 trecs++;                   // point to next record
  538.                 break;
  539.  
  540.             case VOIDED:                  // transaction = voided check
  541.                 // parse check number
  542.                 if ((field = strtok(NULL,split_txt)) == 0)
  543.                 {
  544.                     ecode = BAD_RECORD;
  545.                     printf("** ERROR (line %d): Check record missing required check number field:\n\t%s\n",line,copy_bfr);
  546.                     goto getout;
  547.                 }
  548.                 tptr->no = atoi(field);              // save check number
  549.                 tptr->voided = 1;                    // set this check voided
  550.                 trecs++;                   // point to next record
  551.                 break;
  552.  
  553.             case ATM:                     // transaction = ATM/counter check
  554.                 // parse ATM date
  555.                 if ((field = strtok(NULL,split_txt)) == 0)
  556.                 {
  557.                     ecode = BAD_RECORD;
  558.                     printf("** ERROR (line %d): ATM record missing required date field:\n\t%s\n",line,copy_bfr);
  559.                     goto getout;
  560.                 }
  561.                 if (icondate(field,&yr,&mon,&day))
  562.                 {
  563.                     ecode = BAD_RECORD;
  564.                     printf("** ERROR (line %d): ATM record has invalid date field:\n\t%s\n",line,copy_bfr);
  565.                     goto getout;
  566.                 }
  567.                 tptr->date = packdate(yr,mon,day);   // convert date to DOS format
  568.  
  569.                 // parse ATM amount (whole dollars portion)
  570.                 if ((field = strtok(NULL,".")) == 0) // get whole dollar amount
  571.                 {
  572.                     ecode = BAD_RECORD;
  573.                     printf("** ERROR (line %d): ATM record missing or invalid amount field:\n\t%s\n",line,copy_bfr);
  574.                     goto getout;
  575.                 }
  576.                 tptr->amt = atol(field) * 100;       // save whole dollars
  577.                 if (tptr->amt < 0)                   // ATM must be positive!
  578.                 {
  579.                     ecode = BAD_RECORD;
  580.                     printf("** ERROR (line %d): ATM record amount field must be positive:\n\t%s\n",line,copy_bfr);
  581.                     goto getout;
  582.                 }
  583.  
  584.                 // parse ATM amount (cents portion)
  585.                 if ((field = strtok(NULL,split_txt)) == 0)     // get cents amount
  586.                 {
  587.                     ecode = BAD_RECORD;
  588.                     printf("** ERROR (line %d): ATM record missing cents amount:\n\t%s\n",line,copy_bfr);
  589.                     goto getout;
  590.                 }
  591.                 tptr->amt += atol(field);            // add in cents
  592.  
  593.                 // parse ATM description
  594.                 if (field = strtok(NULL,split_txt))  // get ATM description
  595.                 {                                    // (if there is one)
  596.                     tptr->desc = malloc(strlen(field) + 1);
  597.                     strcpy(tptr->desc,field);
  598.                 }
  599.                 trecs++;                   // point to next record
  600.                 break;
  601.  
  602.             case SERVICE_CHARGE:          // transaction = service charge
  603.                 // parse SC date
  604.                 if ((field = strtok(NULL,split_txt)) == 0)
  605.                 {
  606.                     ecode = BAD_RECORD;
  607.                     printf("** ERROR (line %d): SC record missing required date field:\n\t%s\n",line,copy_bfr);
  608.                     goto getout;
  609.                 }
  610.                 if (icondate(field,&yr,&mon,&day))
  611.                 {
  612.                     ecode = BAD_RECORD;
  613.                     printf("** ERROR (line %d): SC record has invalid date field:\n\t%s\n",line,copy_bfr);
  614.                     goto getout;
  615.                 }
  616.                 tptr->date = packdate(yr,mon,day);   // convert date to DOS format
  617.  
  618.                 // parse SC amount (whole dollars portion)
  619.                 if ((field = strtok(NULL,".")) == 0) // get whole dollar amount
  620.                 {
  621.                     ecode = BAD_RECORD;
  622.                     printf("** ERROR (line %d): SC record missing or invalid amount field:\n\t%s\n",line,copy_bfr);
  623.                     goto getout;
  624.                 }
  625.                 tptr->amt = atol(field) * 100;       // save whole dollars
  626.                 if (tptr->amt < 0)                   // SC must be positive!
  627.                 {
  628.                     ecode = BAD_RECORD;
  629.                     printf("** ERROR (line %d): SC record amount field must be positive:\n\t%s\n",line,copy_bfr);
  630.                     goto getout;
  631.                 }
  632.  
  633.                 // parse SC amount (cents portion)
  634.                 if ((field = strtok(NULL,split_txt)) == 0)     // get cents amount
  635.                 {
  636.                     ecode = BAD_RECORD;
  637.                     printf("** ERROR (line %d): SC record missing cents amount:\n\t%s\n",line,copy_bfr);
  638.                     goto getout;
  639.                 }
  640.                 tptr->amt += atol(field);            // add in cents
  641.  
  642.                 // parse SC description
  643.                 if (field = strtok(NULL,split_txt))  // get SC description
  644.                 {                                    // (if there is one)
  645.                     tptr->desc = malloc(strlen(field) + 1);
  646.                     strcpy(tptr->desc,field);
  647.                 }
  648.                 trecs++;                   // point to next record
  649.                 break;
  650.  
  651.             case DEPOSIT:                 // transaction = deposit
  652.                 // parse Deposit date
  653.                 if ((field = strtok(NULL,split_txt)) == 0)
  654.                 {
  655.                     ecode = BAD_RECORD;
  656.                     printf("** ERROR (line %d): Deposit record missing required date field:\n\t%s\n",line,copy_bfr);
  657.                     goto getout;
  658.                 }
  659.                 if (icondate(field,&yr,&mon,&day))
  660.                 {
  661.                     ecode = BAD_RECORD;
  662.                     printf("** ERROR (line %d): Deposit record has invalid date field:\n\t%s\n",line,copy_bfr);
  663.                     goto getout;
  664.                 }
  665.                 tptr->date = packdate(yr,mon,day);   // convert date to DOS format
  666.  
  667.                 // parse deposit amount (whole dollars portion)
  668.                 if ((field = strtok(NULL,".")) == 0) // get whole dollar amount
  669.                 {
  670.                     ecode = BAD_RECORD;
  671.                     printf("** ERROR (line %d): Deposit record missing or invalid amount field:\n\t%s\n",line,copy_bfr);
  672.                     goto getout;
  673.                 }
  674.                 tptr->amt = atol(field) * 100;       // get whole dollars
  675.                 if (tptr->amt < 0)                   // deposit must be positive!
  676.                 {
  677.                     ecode = BAD_RECORD;
  678.                     printf("** ERROR (line %d): Deposit record amount field must be positive:\n\t%s\n",line,copy_bfr);
  679.                     goto getout;
  680.                 }
  681.  
  682.                 // parse deposit amount (cents portion)
  683.                 if ((field = strtok(NULL,split_txt)) == 0)     // get cents amount
  684.                 {
  685.                     ecode = BAD_RECORD;
  686.                     printf("** ERROR (line %d): Deposit record missing cents amount:\n\t%s\n",line,copy_bfr);
  687.                     goto getout;
  688.                 }
  689.                 tptr->amt += atol(field);            // add in cents
  690.  
  691.                 // parse deposit description
  692.                 if (field = strtok(NULL,split_txt))  // get deposit description
  693.                 {                                    // (if there is one)
  694.                     tptr->desc = malloc(strlen(field) + 1);
  695.                     strcpy(tptr->desc,field);
  696.                 }
  697.                 trecs++;                   // point to next record
  698.                 break;
  699.  
  700.             case INTEREST:                // transaction = interest
  701.                 // parse Interest date
  702.                 if ((field = strtok(NULL,split_txt)) == 0)
  703.                 {
  704.                     ecode = BAD_RECORD;
  705.                     printf("** ERROR (line %d): Interest record missing required date field:\n\t%s\n",line,copy_bfr);
  706.                     goto getout;
  707.                 }
  708.                 if (icondate(field,&yr,&mon,&day))
  709.                 {
  710.                     ecode = BAD_RECORD;
  711.                     printf("** ERROR (line %d): Interest record has invalid date field:\n\t%s\n",line,copy_bfr);
  712.                     goto getout;
  713.                 }
  714.                 tptr->date = packdate(yr,mon,day);   // convert date to DOS format
  715.  
  716.                 // parse Interest amount (whole dollars portion)
  717.                 if ((field = strtok(NULL,".")) == 0) // get whole dollar amount
  718.                 {
  719.                     ecode = BAD_RECORD;
  720.                     printf("** ERROR (line %d): Interest record missing or invalid amount field:\n\t%s\n",line,copy_bfr);
  721.                     goto getout;
  722.                 }
  723.                 tptr->amt = atol(field) * 100;       // save whole dollars
  724.                 if (tptr->amt < 0)                   // Interest must be positive!
  725.                 {
  726.                     ecode = BAD_RECORD;
  727.                     printf("** ERROR (line %d): Interest record amount field must be positive:\n\t%s\n",line,copy_bfr);
  728.                     goto getout;
  729.                 }
  730.  
  731.                 // parse Interest amount (cents portion)
  732.                 if ((field = strtok(NULL,split_txt)) == 0)     // get cents amount
  733.                 {
  734.                     ecode = BAD_RECORD;
  735.                     printf("** ERROR (line %d): Interest record missing cents amount:\n\t%s\n",line,copy_bfr);
  736.                     goto getout;
  737.                 }
  738.                 tptr->amt += atol(field);            // add in cents
  739.  
  740.                 // parse Interest description
  741.                 if (field = strtok(NULL,split_txt))  // get Interest desc
  742.                 {                                    // (if there is one)
  743.                     tptr->desc = malloc(strlen(field) + 1);
  744.                     strcpy(tptr->desc,field);
  745.                 }
  746.                 trecs++;                   // point to next record
  747.                 break;
  748.  
  749.             case MANUAL_PLUS:             // transaction = balance checkbook, add
  750.                 // parse Manual Add date
  751.                 if ((field = strtok(NULL,split_txt)) == 0)
  752.                 {
  753.                     ecode = BAD_RECORD;
  754.                     printf("** ERROR (line %d): Manual Add record missing required date field:\n\t%s\n",line,copy_bfr);
  755.                     goto getout;
  756.                 }
  757.                 if (icondate(field,&yr,&mon,&day))
  758.                 {
  759.                     ecode = BAD_RECORD;
  760.                     printf("** ERROR (line %d): Manual Add record has invalid date field:\n\t%s\n",line,copy_bfr);
  761.                     goto getout;
  762.                 }
  763.                 tptr->date = packdate(yr,mon,day);   // convert date to DOS format
  764.  
  765.                 // parse Manual Add amount (whole dollars portion)
  766.                 if ((field = strtok(NULL,".")) == 0) // get whole dollar amount
  767.                 {
  768.                     ecode = BAD_RECORD;
  769.                     printf("** ERROR (line %d): Manual Add record missing or invalid amount field:\n\t%s\n",line,copy_bfr);
  770.                     goto getout;
  771.                 }
  772.                 tptr->amt = atol(field) * 100;       // save whole dollars
  773.                 if (tptr->amt < 0)                   // Manual Add must be positive!
  774.                 {
  775.                     ecode = BAD_RECORD;
  776.                     printf("** ERROR (line %d): Manual Add record amount field must be positive:\n\t%s\n",line,copy_bfr);
  777.                     goto getout;
  778.                 }
  779.  
  780.                 // parse Manual Add amount (cents portion)
  781.                 if ((field = strtok(NULL,split_txt)) == 0)     // get cents amount
  782.                 {
  783.                     ecode = BAD_RECORD;
  784.                     printf("** ERROR (line %d): Manual Add record missing cents amount:\n\t%s\n",line,copy_bfr);
  785.                     goto getout;
  786.                 }
  787.                 tptr->amt += atol(field);            // add in cents
  788.  
  789.                 // parse Manual Add description
  790.                 if (field = strtok(NULL,split_txt))  // get Manual Add description
  791.                 {                                    // (if there is one)
  792.                     tptr->desc = malloc(strlen(field) + 1);
  793.                     strcpy(tptr->desc,field);
  794.                 }
  795.  
  796.                 trecs++;                   // point to next record
  797.                 break;
  798.  
  799.             case MANUAL_MINUS:            // transaction = balance checkbook, minus
  800.                 // parse Manual Sub date
  801.                 if ((field = strtok(NULL,split_txt)) == 0)
  802.                 {
  803.                     ecode = BAD_RECORD;
  804.                     printf("** ERROR (line %d): Manual Sub record missing required date field:\n\t%s\n",line,copy_bfr);
  805.                     goto getout;
  806.                 }
  807.                 if (icondate(field,&yr,&mon,&day))
  808.                 {
  809.                     ecode = BAD_RECORD;
  810.                     printf("** ERROR (line %d): Manual Sub record has invalid date field:\n\t%s\n",line,copy_bfr);
  811.                     goto getout;
  812.                 }
  813.                 tptr->date = packdate(yr,mon,day);   // convert date to DOS format
  814.  
  815.                 // parse Manual Sub amount (whole dollars portion)
  816.                 if ((field = strtok(NULL,".")) == 0) // get whole dollar amount
  817.                 {
  818.                     ecode = BAD_RECORD;
  819.                     printf("** ERROR (line %d): Manual Sub record missing or invalid amount field:\n\t%s\n",line,copy_bfr);
  820.                     goto getout;
  821.                 }
  822.                 tptr->amt = atol(field) * 100;       // save whole dollars
  823.                 if (tptr->amt < 0)                   // Manual Sub must be positive!
  824.                 {
  825.                     ecode = BAD_RECORD;
  826.                     printf("** ERROR (line %d): Manual Sub record amount field must be positive:\n\t%s\n",line,copy_bfr);
  827.                     goto getout;
  828.                 }
  829.  
  830.                 // parse Manual Sub amount (cents portion)
  831.                 if ((field = strtok(NULL,split_txt)) == 0)     // get cents amount
  832.                 {
  833.                     ecode = BAD_RECORD;
  834.                     printf("** ERROR (line %d): Manual Sub record missing cents amount:\n\t%s\n",line,copy_bfr);
  835.                     goto getout;
  836.                 }
  837.                 tptr->amt += atol(field);            // add in cents
  838.  
  839.                 // parse Manual Sub description
  840.                 if (field = strtok(NULL,split_txt))  // get Manual Sub description
  841.                 {                                    // (if there is one)
  842.                     tptr->desc = malloc(strlen(field) + 1);
  843.                     strcpy(tptr->desc,field);
  844.                 }
  845.  
  846.                 trecs++;                   // point to next record
  847.                 break;
  848.         }
  849.     }
  850.  
  851. getout:
  852.     if (fstuff)                         // close transactions file if open
  853.         fclose(fstuff);
  854.  
  855.     return(ecode);                      // return error code
  856. }                                      // end read_trans()
  857.  
  858.  
  859.  
  860.  
  861.                            //-----  END CB.C  -----//
  862.