DBFINVOI.MOD 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. IMPLEMENTATION MODULE DBFInvoice;
  2. (*
  3. * ModBase
  4. * Release 3.0
  5. * (c) Copyright 1986 - 1991 PMI
  6. * P.O. Box 8402
  7. * Green Bay Wi 53308
  8. * All Rights Reserved
  9. * by Ed Ross
  10. *)
  11. FROM ModBase3 IMPORT InitDBF,OpenDBF,CloseDBF,ReadDBRec,GetField,
  12. DBFile,DefaultFixUp,NilDBF;
  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,DBIndex,InitCompIndex,BuildCompIndex;
  18. FROM DBStuff IMPORT MakeKey;
  19. FROM Drectory IMPORT DeleteFile;
  20. FROM StrEdit IMPORT CrunchBlanks,CAPstr,Append;
  21. FROM StrConv IMPORT StrToReal;
  22. FROM NumTypes IMPORT Real8,REALToReal8;
  23. FROM ScanUtils IMPORT Present,CaseSens;
  24. FROM DBFields IMPORT GetDateField,GetLogicalField,GetNumField,Replace,
  25. ReplaceD,ReplaceN;
  26. CONST
  27. Buffer = 0;
  28. Safty = TRUE;
  29. Exclusive = FALSE;
  30. AutoLock = TRUE;
  31. VAR
  32. DBInit,IndexOpen : BOOLEAN;
  33. PROCEDURE MoveInvoiceToDBF(Rec : InvoiceRec );
  34. (* This code will move the data from the record to *)
  35. (* the data base *)
  36. BEGIN
  37. WITH Rec DO
  38. Replace( InvoiceDBF, 1,INVOICE); (* Invoice number *)
  39. ReplaceD( InvoiceDBF, 2,INVDATE ); (* Invoce date *)
  40. Replace( InvoiceDBF, 3,CUSTID); (* FK - customer id number *)
  41. ReplaceN( InvoiceDBF, 4,INVNET ); (* Invoice net *)
  42. ReplaceN( InvoiceDBF, 5,INVTAX ); (* Invoice Tax *)
  43. ReplaceN( InvoiceDBF, 6,AMTOUT ); (* Amount outstanding *)
  44. ReplaceN( InvoiceDBF, 7,TOTALAMT ); (* Invoice discount *)
  45. Replace( InvoiceDBF, 8,SPORDER ); (* special order boolean *)
  46. Replace( InvoiceDBF, 9,HELIUM ); (* Helium associated with order *)
  47. ReplaceN( InvoiceDBF, 10,INVDSCNT ); (* special discount *)
  48. Replace( InvoiceDBF, 11,CUSTPO ); (* customer's purchase order *)
  49. Replace( InvoiceDBF, 12,INVPRNT ); (* Invoice printed Y/N *)
  50. Replace( InvoiceDBF, 13,INVCLSD ); (* Invoice closed - no special out *)
  51. ReplaceD( InvoiceDBF, 14,SHIPDATE ); (* Date Shipped *)
  52. Replace( InvoiceDBF, 15,SALESMAN ); (* Whodoneit *)
  53. Replace( InvoiceDBF, 16,TERMS ); (* terms of invoice *)
  54. Replace( InvoiceDBF, 17,SHIPVIA ); (* method of shippment *)
  55. ReplaceN( InvoiceDBF, 18,SHIPPING ); (* shipping charge *)
  56. ReplaceN( InvoiceDBF, 19,REALToReal8(FLOAT(DFLTLVL))); (* default price level *)
  57. CAPstr(TAXABLE);
  58. Replace(InvoiceDBF,20,TAXABLE); (* if taxable *)
  59. CAPstr(FREEFRGHT);
  60. Replace(InvoiceDBF,21,FREEFRGHT); (* free freight *)
  61. Replace( InvoiceDBF, 22,NOTESFOR ); (* Notes for Inv, Pkg or both *)
  62. Replace( InvoiceDBF, 23,NOTE1 ); (* *)
  63. Replace( InvoiceDBF, 24,NOTE2 ); (* *)
  64. Replace( InvoiceDBF, 25,NOTE3 ); (* *)
  65. END; (* end of with REC *)
  66. END MoveInvoiceToDBF;
  67. PROCEDURE MoveInvoiceFromDBF(VAR Rec : InvoiceRec );
  68. (* This code will move the data from the Database to *)
  69. (* the record *)
  70. VAR B : BOOLEAN;
  71. R : Real8;
  72. BEGIN
  73. WITH Rec DO
  74. GetField( InvoiceDBF, 1,INVOICE); (* Invoice number *)
  75. GetDateField( InvoiceDBF, 2,INVDATE ); (* Invoce date *)
  76. GetField( InvoiceDBF, 3,CUSTID); (* FK - customer id number *)
  77. GetNumField( InvoiceDBF, 4,INVNET ); (* Invoice net *)
  78. GetNumField( InvoiceDBF, 5,INVTAX ); (* Invoice Tax *)
  79. GetNumField( InvoiceDBF, 6,AMTOUT ); (* Amount outstanding *)
  80. GetNumField( InvoiceDBF, 7,TOTALAMT ); (* Invoice discount *)
  81. GetField( InvoiceDBF, 8,SPORDER); (* special order boolean *)
  82. GetField( InvoiceDBF, 9,HELIUM ); (* Helium associated with order *)
  83. GetNumField( InvoiceDBF, 10,INVDSCNT);
  84. GetField( InvoiceDBF, 11,CUSTPO ); (* customer's purchase order *)
  85. GetField( InvoiceDBF, 12,INVPRNT); (* Invoice printed Y/N *)
  86. GetField( InvoiceDBF, 13,INVCLSD); (* Invoice closed - no special out *)
  87. GetDateField( InvoiceDBF, 14,SHIPDATE ); (* Date Shipped *)
  88. GetField( InvoiceDBF, 15,SALESMAN ); (* Whodoneit *)
  89. GetField( InvoiceDBF, 16,TERMS ); (* terms of invoice *)
  90. GetField( InvoiceDBF, 17,SHIPVIA ); (* method of shippment *)
  91. GetNumField(InvoiceDBF,18,SHIPPING); (* shipping amount *)
  92. GetNumField(InvoiceDBF,19,R); (* default discount table level*)
  93. DFLTLVL := TRUNC(R);
  94. GetField( InvoiceDBF, 20,TAXABLE); (* if taxable invoice *)
  95. GetField( InvoiceDBF,21,FREEFRGHT);
  96. GetField( InvoiceDBF, 22,NOTESFOR ); (* Notes for Inv, Pkg or both *)
  97. GetField( InvoiceDBF, 23,NOTE1 ); (* *)
  98. GetField( InvoiceDBF, 24,NOTE2 ); (* *)
  99. GetField( InvoiceDBF, 25,NOTE3 ); (* *)
  100. END; (* end of with REC^ *)
  101. END MoveInvoiceFromDBF;
  102. PROCEDURE MakeCustKey(DBF : DBFile; Idx: DBIndex;
  103. VAR Key : ARRAY OF CHAR);
  104. (* when indexed by customer id - append the status of on the key *)
  105. VAR B : BOOLEAN;
  106. Str : ARRAY[0..3] OF CHAR;
  107. BEGIN
  108. GetField(DBF,3,Key);
  109. GetField(DBF,12,Str);
  110. Append(Key,Str);
  111. MakeKey(Key);
  112. END MakeCustKey;
  113. PROCEDURE MakeInvoiceKey(DBF : DBFile; Idx: DBIndex;
  114. VAR Key : ARRAY OF CHAR);
  115. (* when indexed by customer id - append the status of on the key *)
  116. VAR B : BOOLEAN;
  117. Str : ARRAY[0..3] OF CHAR;
  118. BEGIN
  119. GetField(DBF,1,Key);
  120. MakeKey(Key);
  121. END MakeInvoiceKey;
  122. PROCEDURE OpenInvoiceDBF(WithIdx : BOOLEAN);
  123. VAR
  124. B : CARDINAL;
  125. BEGIN
  126. IndexOpen := WithIdx;
  127. (* Open the DBF file *)
  128. IF NOT DBInit THEN
  129. DBInit:=TRUE;
  130. InitDBF("Invoice.DBF", InvoiceDBF,Buffer,Safty,Exclusive,AutoLock,
  131. DefaultFixUp );
  132. InitCompIndex( "Invoice.Idx",InvoiceIdx,InvoiceDBF,MakeInvoiceKey,
  133. Buffer, Safty,FALSE,Exclusive);
  134. AddToUpdateList( InvoiceDBF, InvoiceIdx );
  135. InitCompIndex( "Custid.Idx",CustidIdx,InvoiceDBF,MakeCustKey,
  136. Buffer, Safty,FALSE,Exclusive);
  137. AddToUpdateList( InvoiceDBF, CustidIdx );
  138. END;
  139. IF NOT OpenDBF( InvoiceDBF)
  140. THEN END;
  141. IF WithIdx
  142. THEN
  143. (* open all indexes and append to dbfile *)
  144. IF NOT OpenIndex( InvoiceIdx )
  145. THEN
  146. B := BuildCompIndex(InvoiceIdx,'C', 'INVOICE',10);
  147. END;
  148. ActInvoiceIdx := InvoiceIdx; (* make current index *)
  149. IF NOT OpenIndex( CustidIdx )
  150. THEN
  151. B := BuildCompIndex(CustidIdx, 'C','CUSTID',10);
  152. END;
  153. ActInvoiceIdx := CustidIdx; (* make current index *)
  154. END; (* with index *)
  155. END OpenInvoiceDBF;
  156. PROCEDURE CloseInvoiceDBF (); (* close Data and index files *)
  157. BEGIN
  158. CloseDBF(InvoiceDBF); (* close dbf file *)
  159. IF IndexOpen
  160. THEN
  161. CloseIndex(InvoiceIdx ); (* close index file *)
  162. CloseIndex(CustidIdx ); (* close index file *)
  163. END;
  164. END CloseInvoiceDBF;
  165. PROCEDURE FindInvoiceByInvoice( Key : ARRAY OF CHAR) : BOOLEAN;
  166. VAR Found : BOOLEAN;
  167. CKey : ARRAY[0..80] OF CHAR;
  168. BEGIN
  169. ActInvoiceIdx := InvoiceIdx ; (* make this index the active idx*)
  170. MakeKey(Key);
  171. FindPositionCh( InvoiceIdx, Key, Found);
  172. CurrentKeyCh(InvoiceIdx,CKey);
  173. Found := Present(Key,CKey,CaseSens);
  174. IF Found
  175. THEN ReadDBRec( InvoiceDBF, CurrentRec( InvoiceIdx));
  176. END;
  177. RETURN Found;
  178. END FindInvoiceByInvoice;
  179. PROCEDURE FindInvoiceByCustid( Key : ARRAY OF CHAR) : BOOLEAN;
  180. VAR Found : BOOLEAN;
  181. CKey : ARRAY[0..80] OF CHAR;
  182. BEGIN
  183. ActInvoiceIdx := CustidIdx ; (* make this index the active idx*)
  184. MakeKey(Key);
  185. FindPositionCh( CustidIdx, Key, Found);
  186. CurrentKeyCh(CustidIdx,CKey);
  187. Found := Present(Key,CKey,CaseSens);
  188. IF Found
  189. THEN ReadDBRec( InvoiceDBF, CurrentRec( CustidIdx));
  190. END;
  191. RETURN Found;
  192. END FindInvoiceByCustid;
  193. PROCEDURE NextInvoice () : BOOLEAN;
  194. VAR
  195. L : LONGINT; (* record number *)
  196. BEGIN
  197. IF NextRecord( ActInvoiceIdx,L)
  198. THEN ReadDBRec( InvoiceDBF,L );
  199. RETURN TRUE;
  200. ELSE RETURN FALSE;
  201. END;
  202. END NextInvoice;
  203. PROCEDURE PrevInvoice () : BOOLEAN;
  204. VAR
  205. L : LONGINT; (* record number *)
  206. BEGIN
  207. IF PrevRecord( ActInvoiceIdx,L)
  208. THEN ReadDBRec( InvoiceDBF,L );
  209. RETURN TRUE;
  210. ELSE RETURN FALSE;
  211. END;
  212. END PrevInvoice;
  213. PROCEDURE FirstInvoice ();
  214. VAR
  215. L : LONGINT; (* record number *)
  216. BEGIN
  217. GoTop(ActInvoiceIdx);
  218. ReadDBRec( InvoiceDBF,CurrentRec( ActInvoiceIdx));
  219. END FirstInvoice;
  220. PROCEDURE LastInvoice ();
  221. VAR
  222. L : LONGINT; (* record number *)
  223. BEGIN
  224. GoBottom(ActInvoiceIdx);
  225. ReadDBRec( InvoiceDBF,CurrentRec( ActInvoiceIdx));
  226. END LastInvoice;
  227. PROCEDURE PackInvoice();
  228. VAR
  229. EM : CARDINAL;
  230. BEGIN
  231. CloseInvoiceDBF();
  232. InitDBF("Invoice.DBF", InvoiceDBF,Buffer,Safty,TRUE,AutoLock,DefaultFixUp );
  233. IF NOT OpenDBF( InvoiceDBF)
  234. THEN END;
  235. DBPack(InvoiceDBF);
  236. CloseDBF(InvoiceDBF);
  237. EM := DeleteFile('Invoice.IDX');
  238. EM := DeleteFile('CustId.Idx');
  239. OpenInvoiceDBF(TRUE); (* open & rebuild the index *)
  240. CloseInvoiceDBF();
  241. END PackInvoice;
  242. BEGIN
  243. NilDBF(InvoiceDBF);
  244. IndexOpen := FALSE;
  245. DBInit:=FALSE;
  246. END DBFInvoice.
  247.