Printing for tax reports

I’m not an accountant. I don’t know how to keep a journal of a company. My program, a mix between ERP and CMS, just prints the invoices then exports the values to be imported into the program I’m trying to port. This is the program with the official financial data. And the data from this program is used for tax reports.

The program is – as you know – Clipper 87 code, and it was written to be used with dot-matrix printer: they were the printers available at the time! And for several years the only way to print some tax reports was using dot-matrix paper: you had to buy the paper and to bring it to an office and have it “stamped” with a progressive number, so that it could be visible if, in case of a control, a paper was missing.
Unfortunately I don’t know the details.

I just remember the accounting lady reserving a full day to ready and print these reports: nobody could enter her room and she was carefully attending at the printer and checking that the paper didn’t jam.

Nowadays, you don’t get this kind of paper anymore. But the program still uses it. The solution in the last years was to export data from the program and import them into the new version, that I said in the first post, is written in a new language and uses SQL. And as I said the new version lacks some features and… you know, I’m doing the port just for this reason.

By the way, you can now print on lasers, of course. And you can use A4 paper, but you still need to have it stamped. When you get the paper back, looking at the box, you can see that page 1 is at the top, 2 is the second, all with the stampint towards you. To have the reports printed correctly, you must use a laser printer that can use the paper stacked in that position. And the first time you will surely discovered the problem when it’s too late. The lady had to revert hundreds of pages, since her laser prints on the down-facing size of the paper.

I have the program start and could create the indexes for a workarea. Now it is time to check one of the most important reason to port the program to Harbour: printing.

Looking at the menu, I choosed one option, the one that prints all the financial movements of one year. I don’t know if it is the one to print on the stamped paper but it is long and… it prints something.

My hope was to find that an external library was used, so that I could locate it or a clone in open source, or rewrite it myself. Instead, plain Clipper 87 commands are used:
SET DEVICE TO PRINTER
a series of @ SAY
EJECT
SET DEVICE TO SCREEN
as needed. Everything is plain code, neither an internal library to easy form feed, headings, footers or subtotals is used. Just plain Clipper code. This means that I have to check all the printing functions and apply the same changes to all… probably I will refactor a bit, but I first want to understand clearly how this work and, as I already said, I’d like not to change printing code too much.

Since I never used this kind of printing method, I asked harbour-users newsgroup. Daniele replied with a good answer: set the printer to a file, let the program print, open the file and convert to PDF. While reading the file, look for special chars, the ones used in dot-matrix printers to set character spacing, font width, eject, etc.
I remember to have written some code for this job when I was porting the ERP to Harbour, to create a rendering engine external to the main program, but in the end I converted my library to output to Win32 first and then to haruPdf.

In this case, my idea is to create the printed file using a temporary file name and then call a function to convert it to PDF, without calling an external program (except the PDF viewer).

Let’s test Daniele idea. The diff is quite simple, isn’t it?

The little diff to set printing on a file

The little diff to set printing on a file

Compile, link, run, select the function from the main menu: the function starts with a form asking for from-to filters pre-filled with first and last values present in the database. Confirmed the printing, the program thinks for about 10 seconds and then a message tells me the printing is completed.

With a command prompt I went to the program directory but I didn’t find the file. Current directory is another!! So I went to that directory and found the file. Opened in vim: the heading was ok, the first data line was ok, then 10 empty lines, then one line with some spaces but no data, then the second data line, in a loop. What is happening? Let’s have a look at the code!

The code uses the variable row to keep track to which line to print and it is correctly upped by 1 correctly. There should be another reason.

In the loop there are two functions called: the first one was the emergency button for the tax reports prints: pressing space during printing would stop the printing, so that you could un-jam the paper, if needed. A menu appeared and you could resume when ready. Back at DOS time, the printing was “online”, with the program waiting for the line to be ouput before executin the following instruction. If the printing took 2 hours, the program was locked for two hours!
This function checks inkey() but if it founds nothing, nothing is done with the screen. This function is outdated, there is no reason to keep it so I deleted from the printing loop: one call less.

Then there is another function call. In the next post I will explain which was the problem and other problems found in the printing code.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>