home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / database / cdbms / payments.c < prev    next >
Encoding:
C/C++ Source or Header  |  1987-06-01  |  1.3 KB  |  73 lines

  1. /* ------------------ payments.c --------------------- */
  2.  
  3. #include <stdio.h>
  4. #include "keys.h"
  5. #include "cdata.h"
  6. #include "cbs.c1"
  7.  
  8. char *sc;
  9. char *malloc();
  10. int fl[] = {CLIENTS, -1};
  11. int els [] =
  12.     {CLIENT_NO, CLIENT_NAME, AMT_DUE, PAYMENT, DATE_PAID, 0};
  13. struct clients cl;
  14. int len;
  15.  
  16. main()
  17. {
  18.     int term = '\0';
  19.     int edcl();
  20.     long atol();
  21.     
  22.     db_open("", fl);
  23.     len = epos(0, els);
  24.     sc = malloc(len);
  25.     clrrcd(sc, els);
  26.     init_screen("Payments", els, sc);
  27.     edit(CLIENT_NO, edcl);
  28.     protect(CLIENT_NAME, TRUE);
  29.     protect(AMT_DUE, TRUE);
  30.     while (term != ESC)    {
  31.         term = data_entry();
  32.         switch (term)    {
  33.             case F1:
  34.                 if (atol(cl.amt_due) <
  35.                         atol(sc + epos(PAYMENT, els)))    {
  36.                     error_message("Overpayment");
  37.                     continue;
  38.                 }
  39.                 sprintf(cl.amt_due,"%8ld",
  40.                     atol(cl.amt_due)
  41.                    -atol(sc+epos(PAYMENT,els)));
  42.                 clrrcd(sc, els);
  43.                 rtn_rcd(CLIENTS, &cl);
  44.                 break;
  45.             case ESC:
  46.                 if (spaces(sc))
  47.                     break;
  48.                 clrrcd(sc, els);
  49.                 term = '\0';
  50.                 break;
  51.             default:
  52.                 break;
  53.         }
  54.     }
  55.     clear_screen();
  56.     free(sc);
  57.     db_cls();
  58. }
  59.  
  60. /* -------- client number ---------- */
  61. edcl(s)
  62. char *s;
  63. {
  64.     if (find_rcd(CLIENTS, 1, s, &cl) == ERROR)    {
  65.         dberror();
  66.         return ERROR;
  67.     }
  68.     rcd_fill(&cl, sc, file_ele[CLIENTS], els);
  69.     tally();
  70.     return OK;
  71. }
  72.  
  73.