DBFPAYME.MOD 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. (*
  2. * ModBase
  3. * Release 3.0
  4. * (c) Copyright 1986 - 1991 PMI
  5. * P.O. Box 8402
  6. * Green Bay Wi 53308
  7. * All Rights Reserved
  8. * by Ed Ross
  9. *)
  10. IMPLEMENTATION MODULE DBFPayments;
  11. FROM ModBase3 IMPORT InitDBF,OpenDBF,CloseDBF,ReadDBRec,GetField,
  12. DeleteRecord,DBFile,DefaultFixUp,NilDBF,Record;
  13. FROM DBCopier IMPORT DBPack;
  14. FROM DBIndxes IMPORT InitIndex,OpenIndex,AddToUpdateList,CloseIndex,
  15. CurrentRec,FindPositionCh,BuildIndex,GoTop,GoBottom,
  16. NextRecord,PrevRecord,CurrentKeyCh,FindPositionN,
  17. CurrentKeyN,InitCompIndex,BuildCompIndex,DBIndex;
  18. FROM StrEdit IMPORT CrunchBlanks;
  19. FROM PMIGlobals IMPORT Today,Config;
  20. FROM Drectory IMPORT DeleteFile;
  21. FROM StrConv IMPORT StrToReal;
  22. FROM NumTypes IMPORT Real8;
  23. FROM DBStuff IMPORT MakeKey;
  24. FROM DateFunctions IMPORT DaysSince1900;
  25. FROM ScanUtils IMPORT Present,CaseSens;
  26. FROM DBFields IMPORT GetDateField,GetLogicalField,GetNumField,Replace,
  27. ReplaceD,ReplaceN;
  28. CONST
  29. Buffer = 0;
  30. Safty = TRUE;
  31. Exclusive = FALSE;
  32. AutoLock = TRUE;
  33. VAR IndexOpen,DBInit : BOOLEAN;
  34. PROCEDURE MovePaymentsToDBF(Rec : PaymentsRec );
  35. (* This code will move the data from the record to *)
  36. (* the data base *)
  37. BEGIN
  38. WITH Rec DO
  39. Replace( PaymentsDBF, 1,INVOICE); (* Invoice number *)
  40. ReplaceD( PaymentsDBF, 2,PMTDATE ); (* Payment Date *)
  41. ReplaceN( PaymentsDBF, 3,PMTAMT ); (* Payment amount *)
  42. Replace( PaymentsDBF, 4,CHECKNB ); (* Check number *)
  43. Replace( PaymentsDBF, 5,CUSTID); (* Customer who payed *)
  44. END; (* end of with REC *)
  45. END MovePaymentsToDBF;
  46. PROCEDURE MovePaymentsFromDBF(VAR Rec : PaymentsRec );
  47. (* This code will move the data from the Database to *)
  48. (* the record *)
  49. VAR B : BOOLEAN;
  50. R : Real8;
  51. BEGIN
  52. WITH Rec DO
  53. GetField( PaymentsDBF, 1,INVOICE ); (* Invoice number *)
  54. GetDateField( PaymentsDBF, 2,PMTDATE ); (* Payment Date *)
  55. GetNumField( PaymentsDBF, 3,PMTAMT ); (* Payment amount *)
  56. GetField( PaymentsDBF, 4,CHECKNB ); (* Check number *)
  57. GetField( PaymentsDBF, 5,CUSTID ); (* Customer who payed *)
  58. END; (* end of with REC^ *)
  59. END MovePaymentsFromDBF;
  60. PROCEDURE MakeCustidKey( DBF : DBFile; Idx : DBIndex;
  61. VAR Key : ARRAY OF CHAR);
  62. VAR
  63. B : BOOLEAN;
  64. BEGIN
  65. GetField( PaymentsDBF, 5,Key ); (* Customer who payed *)
  66. MakeKey(Key);
  67. END MakeCustidKey;
  68. PROCEDURE OpenPaymentsDBF(WithIdx : BOOLEAN);
  69. VAR ER : CARDINAL;
  70. BEGIN
  71. IndexOpen := WithIdx;
  72. (* Open the DBF file *)
  73. IF NOT DBInit THEN
  74. DBInit:=TRUE;
  75. InitDBF("Payments.DBF", PaymentsDBF,Buffer,Safty,Exclusive,AutoLock,
  76. DefaultFixUp );
  77. InitCompIndex( "Pymts.Idx",CustidIdx,PaymentsDBF,MakeCustidKey,Buffer,
  78. Safty,FALSE,Exclusive);
  79. AddToUpdateList( PaymentsDBF, CustidIdx );
  80. END;
  81. IF NOT OpenDBF( PaymentsDBF)
  82. THEN
  83. HALT;
  84. END;
  85. IF WithIdx THEN
  86. (* open all indexes and append to dbfile *)
  87. IF NOT OpenIndex( CustidIdx )
  88. THEN
  89. ER := BuildCompIndex(CustidIdx,'C','Custid',12); (* check key lenght *)
  90. END;
  91. END; (* end with idx *)
  92. END OpenPaymentsDBF;
  93. PROCEDURE ClosePaymentsDBF (); (* close Data and index files *)
  94. BEGIN
  95. CloseDBF(PaymentsDBF); (* close dbf file *)
  96. IF IndexOpen
  97. THEN
  98. CloseIndex(CustidIdx ); (* close index file *)
  99. END;
  100. END ClosePaymentsDBF;
  101. PROCEDURE FindPaymentsByCustid( Key : ARRAY OF CHAR) : BOOLEAN;
  102. VAR Found : BOOLEAN;
  103. CKey : ARRAY[0..80] OF CHAR;
  104. BEGIN
  105. FindPositionCh( CustidIdx, Key, Found);
  106. CurrentKeyCh(CustidIdx,CKey);
  107. Found := Present(Key,CKey,CaseSens);
  108. IF Found
  109. THEN ReadDBRec( PaymentsDBF, CurrentRec( CustidIdx));
  110. END;
  111. RETURN Found;
  112. END FindPaymentsByCustid;
  113. PROCEDURE DeletePayments();
  114. (* go through the payments file and delete all payments greater than
  115. the number of weeks to keep payments *)
  116. VAR
  117. LI : LONGINT;
  118. DeleteDate, PaymentDate : CARDINAL;
  119. Payment : PaymentsRec;
  120. BEGIN
  121. DeleteDate := DaysSince1900(Today) + (Config.KeepPaymentHist * 7);
  122. (* payment hist is in weeks *)
  123. FOR LI := 1 TO Record(PaymentsDBF) DO
  124. ReadDBRec(PaymentsDBF,LI);
  125. MovePaymentsFromDBF(Payment);
  126. IF ( DaysSince1900(Payment.PMTDATE) > DeleteDate)
  127. THEN DeleteRecord(PaymentsDBF);
  128. END;
  129. END;
  130. END DeletePayments;
  131. PROCEDURE PackPayments();
  132. VAR
  133. EM : CARDINAL;
  134. BEGIN
  135. ClosePaymentsDBF();
  136. OpenPaymentsDBF(FALSE);
  137. DeletePayments();
  138. DBPack(PaymentsDBF);
  139. CloseDBF(PaymentsDBF);
  140. EM := DeleteFile("Pymts.Idx");
  141. OpenPaymentsDBF(TRUE); (* open & rebuild the index *)
  142. ClosePaymentsDBF();
  143. END PackPayments;
  144. BEGIN
  145. NilDBF(PaymentsDBF);
  146. IndexOpen := FALSE;
  147. DBInit:=FALSE;
  148. END DBFPayments.
  149.