| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281 |
- IMPLEMENTATION MODULE LateLetters;
- (*
- * ModBase
- * Release 3.0
- * (c) Copyright 1986 - 1991 PMI
- * P.O. Box 8402
- * Green Bay Wi 53308
- * All Rights Reserved
- * by Ed Ross
- *)
- FROM ModBase3 IMPORT ReadDBRec,NumberRecords,Deleted;
- FROM DBFInvoice IMPORT OpenInvoiceDBF,OpenInvoiceDBF,CloseInvoiceDBF,
- InvoiceDBF,MoveInvoiceFromDBF,InvoiceRec;
- FROM DateFunctions IMPORT DateDiff,ValidDate;
- FROM DspFiles IMPORT ReadDisplayFrame;
- FROM PMIGlobals IMPORT Today,TodayStr,Config,PMIScreens;
- FROM ScrnUtl2 IMPORT CloseDisplayFrame;
- FROM ScrnUtl1 IMPORT FieldNum;
- FROM NumTypes IMPORT Real8;
- FROM ScreenInput IMPORT ListToEdField,ListFromEdField;
- FROM DBFCustomer IMPORT OpenCustomerDBF,MoveCustomerFromDBF,FindCustomerByCin;
- FROM Customer IMPORT GetCustAddr,GetCustName,AddressRec,AddressTypes;
- FROM M2Strings IMPORT CompareStr,Length,Assign;
- FROM StringIO IMPORT WriteStr,WriteEol,outp;
- FROM StrEdit IMPORT CrunchBlanks;
- FROM PosUtils IMPORT Equal;
- FROM ScrnTypes IMPORT DisplayFrame,
- InitDisplayFrame;
- FROM GenLists IMPORT GenList,GetElmt,NewList,DisposeList,ListInsert,SortList,
- ListLength,GetElmtAdr;
- FROM ListUtils IMPORT TextFileToList,TextListToFile;
- FROM FramePainter IMPORT ShowDisplayFrame;
- FROM ControlUtils IMPORT Control;
- IMPORT VWindows;
- FROM SYSTEM IMPORT ADDRESS,ADR;
- FROM HandleIO IMPORT FileExists,CloseHandle,CreateFile,OpenFile;
- FROM PrinterUtils IMPORT DisplayLine,SetupDisplayLine,RemoveDisplayLine,
- AddPrintElemt,PrintDisplayLine,ClearDisplayLine;
- CONST
- FileNamePre = 'Late30.Pre';
- FileNameSuf = 'Late30.Suf';
- PROCEDURE CreateLateLetters();
- VAR DF : DisplayFrame;
- Pre,Suf : GenList;
- Err : CARDINAL;
- B : BOOLEAN;
- FN : ARRAY[0..20] OF CHAR;
- BEGIN
- InitDisplayFrame(DF,VWindows.CurrentWindow);
- ReadDisplayFrame(PMIScreens,DF,'LateLetter');
- NewList(Pre);
- NewList(Suf);
- FN := FileNamePre;
- Err := TextFileToList(FN,Pre);
- FN := FileNameSuf;
- Err := TextFileToList(FN,Suf);
- B := ListToEdField(Pre,DF,FieldNum(DF,'Prefix'));
- B := ListToEdField(Suf,DF,FieldNum(DF,'Suffix'));
- ShowDisplayFrame(DF,0,0,0,0);
- Control(DF);
- B := ListFromEdField(DF,FieldNum(DF,'Prefix'),Pre);
- B := ListFromEdField(DF,FieldNum(DF,'Suffix'),Suf);
- Err := TextListToFile(Pre,FileNamePre);
- Err := TextListToFile(Suf,FileNameSuf);
- CloseDisplayFrame(DF);
- END CreateLateLetters;
- PROCEDURE SortInvList(A1 : ADDRESS; Len1 : CARDINAL;
- A2 : ADDRESS; Len2 : CARDINAL) : INTEGER;
- VAR
- I1 : POINTER TO InvoiceRec;
- I2 : POINTER TO InvoiceRec;
- BEGIN
- I1 := A1;
- I2 := A2;
- IF NOT Equal(I1^.CUSTID,I2^.CUSTID)
- THEN RETURN CompareStr(I1^.CUSTID,I2^.CUSTID);
- ELSE IF NOT Equal(I1^.INVOICE,I2^.INVOICE)
- THEN RETURN CompareStr(I1^.INVOICE,I2^.INVOICE)
- ELSE RETURN 0;
- END;
- END;
- END SortInvList;
- PROCEDURE ProduceLateLetters();
- CONST
- FF = CHR(12);
- VAR
- B : BOOLEAN;
- L : LONGINT;
- J : LONGINT;
- M : CARDINAL;
- Code : CARDINAL;
- Inv : InvoiceRec;
- OutStd : GenList;
- Pre,Suf : GenList;
- ER,prt : CARDINAL;
- CurrentCIN : ARRAY[0..20] OF CHAR;
- CustName : ARRAY[0..60] OF CHAR;
- TotalOut : Real8;
- Line : DisplayLine;
- L1,L2,L3,L4,L5 : DisplayLine;
- Hand : CARDINAL;
- Err : CARDINAL;
- FN : ARRAY[0..40] OF CHAR;
- PROCEDURE PrintHeader();
- CONST
- Blanks = ' ';
- VAR
- J : CARDINAL;
- P : POINTER TO ARRAY[0..500] OF CHAR;
- Code,Size : CARDINAL;
- CompName : ARRAY[0..60] OF CHAR;
- CompAddr : AddressRec;
- BEGIN
- PrintDisplayLine(L1,Hand);
- PrintDisplayLine(L2,Hand);
- PrintDisplayLine(L3,Hand);
- PrintDisplayLine(L4,Hand);
- (* print comany name and address here *)
- GetCustName(CurrentCIN,CustName);
- GetCustAddr(CompAddr,Billing);
- (* WriteEol(Hand,CustName); *)
- FOR J := 1 TO 6 DO
- WriteEol(Hand,'');
- END;
- WriteStr(Hand,Blanks);
- WriteEol(Hand,CompAddr.Line[0]);
- WriteStr(Hand,Blanks);
- WriteEol(Hand,CompAddr.Line[1]);
- WriteStr(Hand,Blanks);
- WriteEol(Hand,CompAddr.Line[2]);
- WriteStr(Hand,Blanks);
- WriteEol(Hand,CompAddr.Line[3]);
- FOR J := 1 TO 2 DO
- WriteEol(Hand,'');
- END;
- FOR J := 1 TO ListLength(Pre) DO
- GetElmtAdr(Pre,J,P,Size,Code);
- WriteEol(Hand,P^);
- END;
- WriteEol(Hand,' ');
- WriteEol(Hand,' ');
- PrintDisplayLine(L5,Hand);
- END PrintHeader;
- PROCEDURE PrintFooter();
- VAR J, Size,Code : CARDINAL;
- P : ARRAY[0..100] OF CHAR;
- BEGIN
- ClearDisplayLine(Line);
- AddPrintElemt(Line,TotalOut,'R',45,14,'L');
- AddPrintElemt(Line,'Total outstanding ','S',15,15,'L');
- PrintDisplayLine(Line,Hand);
- WriteEol(Hand,' ');
- FOR J := 1 TO ListLength(Suf) DO
- GetElmt(Suf,J,P,Code);
- WriteEol(Hand,P);
- END;
- WriteStr(Hand,12C);
- END PrintFooter;
- PROCEDURE PrintLine();
- (* print line should look like this
- 1 2 3 4 5 6 7
- 01234567890123456789012345678901234567890123456789012345678901234567890
- Invoice Date Invoice Amount Amount Due
- xx-xxxxxx xx-xx-xx $xxxxxxxxx.xx $xxxxxxxxxx.xx
- *)
- VAR B : BOOLEAN;
- BEGIN
- WITH Inv DO
- ClearDisplayLine(Line);
- AddPrintElemt(Line,INVOICE,'S',2,10,'L');
- AddPrintElemt(Line,INVDATE,'D',14,20,'L');
- AddPrintElemt(Line,TOTALAMT,'R',28,10,'R');
- AddPrintElemt(Line,AMTOUT,'R',45,10,'R');
- PrintDisplayLine(Line,Hand);
- ClearDisplayLine(Line);
- END;
- END PrintLine;
- BEGIN
- (* Set up the titles and the prefix * suffix *)
- SetupDisplayLine(Line,76);
- SetupDisplayLine(L1,76);
- SetupDisplayLine(L2,76);
- SetupDisplayLine(L3,76);
- SetupDisplayLine(L4,76);
- SetupDisplayLine(L5,76);
- CrunchBlanks(Config.CompanyName);
- CrunchBlanks(Config.CompanyAddr1);
- CrunchBlanks(Config.CompanyAddr2);
- CrunchBlanks(Config.Phone);
- AddPrintElemt(L1,Config.CompanyName,'S',
- 40-(Length(Config.CompanyName) DIV 2),30,'L');
- AddPrintElemt(L1,Today,'D',65,Length(TodayStr),'L');
- AddPrintElemt(L2,Config.CompanyAddr1,'S',
- 40- (Length(Config.CompanyAddr1) DIV 2),79,'L');
- AddPrintElemt(L3,Config.CompanyAddr2,'S',
- 40- (Length(Config.CompanyAddr2) DIV 2),79,'L');
- AddPrintElemt(L4,Config.Phone,'S',
- 40 - (Length(Config.Phone) DIV 2),20,'L');
- AddPrintElemt(L5,
- ' Invoice Date Invoice Amount Amount Due', 'S',0,75,'L');
- NewList(Pre);
- NewList(Suf);
- FN := FileNamePre;
- Err := TextFileToList(FN,Pre);
- FN := FileNameSuf;
- Err := TextFileToList(FN,Suf);
- OpenInvoiceDBF(FALSE);
- NewList(OutStd);
- L := NumberRecords(InvoiceDBF);
- FOR J := 1 TO L DO
- ReadDBRec(InvoiceDBF,J);
- IF NOT Deleted(InvoiceDBF)
- THEN
- MoveInvoiceFromDBF(Inv);
- IF (Inv.INVPRNT = 'P') AND ValidDate(Inv.INVDATE) (* Been printed but not closed *)
- THEN
- IF DateDiff(Today,Inv.INVDATE) > 30
- THEN ListInsert(Inv,1,OutStd,1);
- END; (*out longer than 30 days *)
- END; (* been printed *)
- END; (* not deleted *)
- END; (* loop reading out *)
- CloseInvoiceDBF();
- SortList(OutStd,SortInvList); (* sort by cust by invoice number *)
- CurrentCIN := 'XxXxX??'; (* make sure the first doesn't match *)
- ER := OpenFile(Hand,Config.ReportPrt); (* open report printer *)
- FOR M :=1 TO ListLength(OutStd) DO
- GetElmt(OutStd,M,Inv,Code);
- CrunchBlanks(Inv.CUSTID);
- IF NOT Equal(CurrentCIN,Inv.CUSTID)
- THEN (* new customer in list *)
- IF NOT (Equal(CurrentCIN,'XxXxX??')) (* if not the first cust*)
- THEN
- PrintFooter();
- END;
- Assign( Inv.CUSTID,CurrentCIN );
- B := FindCustomerByCin(CurrentCIN);
- PrintHeader();
- TotalOut := 0.0;
- END; (* end new customer *)
- TotalOut := TotalOut + Inv.AMTOUT;
- PrintLine();
- END;
- Err := CloseHandle(Hand);
- DisposeList(Pre);
- DisposeList(Suf);
- RemoveDisplayLine(Line);
- RemoveDisplayLine(L1);
- RemoveDisplayLine(L2);
- RemoveDisplayLine(L3);
- RemoveDisplayLine(L4);
- RemoveDisplayLine(L5);
- END ProduceLateLetters;
- END LateLetters.
|