LATELETT.MOD 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. IMPLEMENTATION MODULE LateLetters;
  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 ReadDBRec,NumberRecords,Deleted;
  12. FROM DBFInvoice IMPORT OpenInvoiceDBF,OpenInvoiceDBF,CloseInvoiceDBF,
  13. InvoiceDBF,MoveInvoiceFromDBF,InvoiceRec;
  14. FROM DateFunctions IMPORT DateDiff,ValidDate;
  15. FROM DspFiles IMPORT ReadDisplayFrame;
  16. FROM PMIGlobals IMPORT Today,TodayStr,Config,PMIScreens;
  17. FROM ScrnUtl2 IMPORT CloseDisplayFrame;
  18. FROM ScrnUtl1 IMPORT FieldNum;
  19. FROM NumTypes IMPORT Real8;
  20. FROM ScreenInput IMPORT ListToEdField,ListFromEdField;
  21. FROM DBFCustomer IMPORT OpenCustomerDBF,MoveCustomerFromDBF,FindCustomerByCin;
  22. FROM Customer IMPORT GetCustAddr,GetCustName,AddressRec,AddressTypes;
  23. FROM M2Strings IMPORT CompareStr,Length,Assign;
  24. FROM StringIO IMPORT WriteStr,WriteEol,outp;
  25. FROM StrEdit IMPORT CrunchBlanks;
  26. FROM PosUtils IMPORT Equal;
  27. FROM ScrnTypes IMPORT DisplayFrame,
  28. InitDisplayFrame;
  29. FROM GenLists IMPORT GenList,GetElmt,NewList,DisposeList,ListInsert,SortList,
  30. ListLength,GetElmtAdr;
  31. FROM ListUtils IMPORT TextFileToList,TextListToFile;
  32. FROM FramePainter IMPORT ShowDisplayFrame;
  33. FROM ControlUtils IMPORT Control;
  34. IMPORT VWindows;
  35. FROM SYSTEM IMPORT ADDRESS,ADR;
  36. FROM HandleIO IMPORT FileExists,CloseHandle,CreateFile,OpenFile;
  37. FROM PrinterUtils IMPORT DisplayLine,SetupDisplayLine,RemoveDisplayLine,
  38. AddPrintElemt,PrintDisplayLine,ClearDisplayLine;
  39. CONST
  40. FileNamePre = 'Late30.Pre';
  41. FileNameSuf = 'Late30.Suf';
  42. PROCEDURE CreateLateLetters();
  43. VAR DF : DisplayFrame;
  44. Pre,Suf : GenList;
  45. Err : CARDINAL;
  46. B : BOOLEAN;
  47. FN : ARRAY[0..20] OF CHAR;
  48. BEGIN
  49. InitDisplayFrame(DF,VWindows.CurrentWindow);
  50. ReadDisplayFrame(PMIScreens,DF,'LateLetter');
  51. NewList(Pre);
  52. NewList(Suf);
  53. FN := FileNamePre;
  54. Err := TextFileToList(FN,Pre);
  55. FN := FileNameSuf;
  56. Err := TextFileToList(FN,Suf);
  57. B := ListToEdField(Pre,DF,FieldNum(DF,'Prefix'));
  58. B := ListToEdField(Suf,DF,FieldNum(DF,'Suffix'));
  59. ShowDisplayFrame(DF,0,0,0,0);
  60. Control(DF);
  61. B := ListFromEdField(DF,FieldNum(DF,'Prefix'),Pre);
  62. B := ListFromEdField(DF,FieldNum(DF,'Suffix'),Suf);
  63. Err := TextListToFile(Pre,FileNamePre);
  64. Err := TextListToFile(Suf,FileNameSuf);
  65. CloseDisplayFrame(DF);
  66. END CreateLateLetters;
  67. PROCEDURE SortInvList(A1 : ADDRESS; Len1 : CARDINAL;
  68. A2 : ADDRESS; Len2 : CARDINAL) : INTEGER;
  69. VAR
  70. I1 : POINTER TO InvoiceRec;
  71. I2 : POINTER TO InvoiceRec;
  72. BEGIN
  73. I1 := A1;
  74. I2 := A2;
  75. IF NOT Equal(I1^.CUSTID,I2^.CUSTID)
  76. THEN RETURN CompareStr(I1^.CUSTID,I2^.CUSTID);
  77. ELSE IF NOT Equal(I1^.INVOICE,I2^.INVOICE)
  78. THEN RETURN CompareStr(I1^.INVOICE,I2^.INVOICE)
  79. ELSE RETURN 0;
  80. END;
  81. END;
  82. END SortInvList;
  83. PROCEDURE ProduceLateLetters();
  84. CONST
  85. FF = CHR(12);
  86. VAR
  87. B : BOOLEAN;
  88. L : LONGINT;
  89. J : LONGINT;
  90. M : CARDINAL;
  91. Code : CARDINAL;
  92. Inv : InvoiceRec;
  93. OutStd : GenList;
  94. Pre,Suf : GenList;
  95. ER,prt : CARDINAL;
  96. CurrentCIN : ARRAY[0..20] OF CHAR;
  97. CustName : ARRAY[0..60] OF CHAR;
  98. TotalOut : Real8;
  99. Line : DisplayLine;
  100. L1,L2,L3,L4,L5 : DisplayLine;
  101. Hand : CARDINAL;
  102. Err : CARDINAL;
  103. FN : ARRAY[0..40] OF CHAR;
  104. PROCEDURE PrintHeader();
  105. CONST
  106. Blanks = ' ';
  107. VAR
  108. J : CARDINAL;
  109. P : POINTER TO ARRAY[0..500] OF CHAR;
  110. Code,Size : CARDINAL;
  111. CompName : ARRAY[0..60] OF CHAR;
  112. CompAddr : AddressRec;
  113. BEGIN
  114. PrintDisplayLine(L1,Hand);
  115. PrintDisplayLine(L2,Hand);
  116. PrintDisplayLine(L3,Hand);
  117. PrintDisplayLine(L4,Hand);
  118. (* print comany name and address here *)
  119. GetCustName(CurrentCIN,CustName);
  120. GetCustAddr(CompAddr,Billing);
  121. (* WriteEol(Hand,CustName); *)
  122. FOR J := 1 TO 6 DO
  123. WriteEol(Hand,'');
  124. END;
  125. WriteStr(Hand,Blanks);
  126. WriteEol(Hand,CompAddr.Line[0]);
  127. WriteStr(Hand,Blanks);
  128. WriteEol(Hand,CompAddr.Line[1]);
  129. WriteStr(Hand,Blanks);
  130. WriteEol(Hand,CompAddr.Line[2]);
  131. WriteStr(Hand,Blanks);
  132. WriteEol(Hand,CompAddr.Line[3]);
  133. FOR J := 1 TO 2 DO
  134. WriteEol(Hand,'');
  135. END;
  136. FOR J := 1 TO ListLength(Pre) DO
  137. GetElmtAdr(Pre,J,P,Size,Code);
  138. WriteEol(Hand,P^);
  139. END;
  140. WriteEol(Hand,' ');
  141. WriteEol(Hand,' ');
  142. PrintDisplayLine(L5,Hand);
  143. END PrintHeader;
  144. PROCEDURE PrintFooter();
  145. VAR J, Size,Code : CARDINAL;
  146. P : ARRAY[0..100] OF CHAR;
  147. BEGIN
  148. ClearDisplayLine(Line);
  149. AddPrintElemt(Line,TotalOut,'R',45,14,'L');
  150. AddPrintElemt(Line,'Total outstanding ','S',15,15,'L');
  151. PrintDisplayLine(Line,Hand);
  152. WriteEol(Hand,' ');
  153. FOR J := 1 TO ListLength(Suf) DO
  154. GetElmt(Suf,J,P,Code);
  155. WriteEol(Hand,P);
  156. END;
  157. WriteStr(Hand,12C);
  158. END PrintFooter;
  159. PROCEDURE PrintLine();
  160. (* print line should look like this
  161. 1 2 3 4 5 6 7
  162. 01234567890123456789012345678901234567890123456789012345678901234567890
  163. Invoice Date Invoice Amount Amount Due
  164. xx-xxxxxx xx-xx-xx $xxxxxxxxx.xx $xxxxxxxxxx.xx
  165. *)
  166. VAR B : BOOLEAN;
  167. BEGIN
  168. WITH Inv DO
  169. ClearDisplayLine(Line);
  170. AddPrintElemt(Line,INVOICE,'S',2,10,'L');
  171. AddPrintElemt(Line,INVDATE,'D',14,20,'L');
  172. AddPrintElemt(Line,TOTALAMT,'R',28,10,'R');
  173. AddPrintElemt(Line,AMTOUT,'R',45,10,'R');
  174. PrintDisplayLine(Line,Hand);
  175. ClearDisplayLine(Line);
  176. END;
  177. END PrintLine;
  178. BEGIN
  179. (* Set up the titles and the prefix * suffix *)
  180. SetupDisplayLine(Line,76);
  181. SetupDisplayLine(L1,76);
  182. SetupDisplayLine(L2,76);
  183. SetupDisplayLine(L3,76);
  184. SetupDisplayLine(L4,76);
  185. SetupDisplayLine(L5,76);
  186. CrunchBlanks(Config.CompanyName);
  187. CrunchBlanks(Config.CompanyAddr1);
  188. CrunchBlanks(Config.CompanyAddr2);
  189. CrunchBlanks(Config.Phone);
  190. AddPrintElemt(L1,Config.CompanyName,'S',
  191. 40-(Length(Config.CompanyName) DIV 2),30,'L');
  192. AddPrintElemt(L1,Today,'D',65,Length(TodayStr),'L');
  193. AddPrintElemt(L2,Config.CompanyAddr1,'S',
  194. 40- (Length(Config.CompanyAddr1) DIV 2),79,'L');
  195. AddPrintElemt(L3,Config.CompanyAddr2,'S',
  196. 40- (Length(Config.CompanyAddr2) DIV 2),79,'L');
  197. AddPrintElemt(L4,Config.Phone,'S',
  198. 40 - (Length(Config.Phone) DIV 2),20,'L');
  199. AddPrintElemt(L5,
  200. ' Invoice Date Invoice Amount Amount Due', 'S',0,75,'L');
  201. NewList(Pre);
  202. NewList(Suf);
  203. FN := FileNamePre;
  204. Err := TextFileToList(FN,Pre);
  205. FN := FileNameSuf;
  206. Err := TextFileToList(FN,Suf);
  207. OpenInvoiceDBF(FALSE);
  208. NewList(OutStd);
  209. L := NumberRecords(InvoiceDBF);
  210. FOR J := 1 TO L DO
  211. ReadDBRec(InvoiceDBF,J);
  212. IF NOT Deleted(InvoiceDBF)
  213. THEN
  214. MoveInvoiceFromDBF(Inv);
  215. IF (Inv.INVPRNT = 'P') AND ValidDate(Inv.INVDATE) (* Been printed but not closed *)
  216. THEN
  217. IF DateDiff(Today,Inv.INVDATE) > 30
  218. THEN ListInsert(Inv,1,OutStd,1);
  219. END; (*out longer than 30 days *)
  220. END; (* been printed *)
  221. END; (* not deleted *)
  222. END; (* loop reading out *)
  223. CloseInvoiceDBF();
  224. SortList(OutStd,SortInvList); (* sort by cust by invoice number *)
  225. CurrentCIN := 'XxXxX??'; (* make sure the first doesn't match *)
  226. ER := OpenFile(Hand,Config.ReportPrt); (* open report printer *)
  227. FOR M :=1 TO ListLength(OutStd) DO
  228. GetElmt(OutStd,M,Inv,Code);
  229. CrunchBlanks(Inv.CUSTID);
  230. IF NOT Equal(CurrentCIN,Inv.CUSTID)
  231. THEN (* new customer in list *)
  232. IF NOT (Equal(CurrentCIN,'XxXxX??')) (* if not the first cust*)
  233. THEN
  234. PrintFooter();
  235. END;
  236. Assign( Inv.CUSTID,CurrentCIN );
  237. B := FindCustomerByCin(CurrentCIN);
  238. PrintHeader();
  239. TotalOut := 0.0;
  240. END; (* end new customer *)
  241. TotalOut := TotalOut + Inv.AMTOUT;
  242. PrintLine();
  243. END;
  244. Err := CloseHandle(Hand);
  245. DisposeList(Pre);
  246. DisposeList(Suf);
  247. RemoveDisplayLine(Line);
  248. RemoveDisplayLine(L1);
  249. RemoveDisplayLine(L2);
  250. RemoveDisplayLine(L3);
  251. RemoveDisplayLine(L4);
  252. RemoveDisplayLine(L5);
  253. END ProduceLateLetters;
  254. END LateLetters.
  255.