Converting Print Files to HTML Invoices

Sometimes general purpose programs don't quite do what you need them to do. Such was the case for a small sales organization who uses Great Plains accounting software. They needed more flexibility for invoicing than what the software gave them.

That's not at all unusual. Although modern software is very flexible and can often be greatly customized, sometimes the end user still needs more than what it provides.


Hate these ads?

What they specifically wanted was:

  • To be able to quickly view historical invoices
  • To allow customers to view their own historical invoices
  • To be able to attach invoices to e-mail
  • To be able to print in different formats

The solution we developed takes data exported from Great Plains as a CSV file and turns it into HTML invoices that are ready to print. Additionally, it creates plain text files at the same time, and in the future will also create an XML representation of the invoice.

Note that ANY application that can print can be controlled in this way. This happened to be Great Plains, and the CSV files happened to be a convenient output format, but this type of thing can be accomplished with virtually any software.

The basic transformation is done by a Perl script running on a Windows server. The user doesn't directly interact with the script; they simply choose a printer and doing that automatically creates the output files.

The ability to define a Windows or Unix printer that actually runs a program opens up many possibilities for capturing, diverting, and changing output before sending to a real printer. Although we didn't do it in this project, the completed output could also be printed, faxed, e-mailed to others, or even transferred to CD storage all automatically simply by "printing" a file from any application.


My Unix and Linux Troubleshooting E-Book will show you how to solve tough system problems!



This transparency eliminates user errors and can guarantee consistency. As data can be transformed as necessary, it is easy to do such things as removing information that should not be available publicly or merging in data from other sources. For example, internally stored invoices might extract cost information from another database while the publicly stored versions would have that removed. Remember that this can all happen with ONE print operation by the user, on Windows or Unix platforms. The data itself can have originated anywhere - if it can be printed, it can be transformed, diverted, stored - whatever you need.

An HTML Invoice

You can view a sample of a created HTML page at http://aplawrence.com/CS/F-net_002559.html. Note that this is a two page invoice that is combined on one HTML page; if you print it with any current browser it should correctly print two separate pages. How that is done is explained in the script itself.

The data that this works with looks like this:

(This was exported from Great Plains)



"002559"
"10/25/02"
"1"
"Univ of Hard Knocks","Univ of Hard Knocks
"PO Box 4031","345 Elling Street"
"",""
"Farmville MA    02098-4031",""
""
"Farmville MA    02098"
"3P579820","BM0210008","TJK","FEDEX","Upon Receipt","10/25/02","2,881"
"15","0","BJ-20822H","Visible Light Cloaking Shield","$60.00","$900.00"
"18","0","BK-2L402","2 Ply Anti Gravity Sheets","$50.00","$900.00"
"1","0","","--------------------------------------------","",""
"1","0","","Note that Anti-Grav Sheets are not returnable","",""
"1","0","","--------------------------------------------","",""
"1","0","AQ-02","Light Sabre","$50.00","$50.00"
"2","0","AQ-03","Junior Light Sabre","$25.00","$50.00"
"1","0","","--------------------------------------------","",""
"1","0","","No Diluthium Crystals included for Sabres","",""
"1","0","","--------------------------------------------","",""
"1","0","AKQ-02","Sonic Cannon","$500.00","$500.00"
"1","0","","--------------------------------------------","",""
"1","0","","AKQ-02 cannot be exported!!","",""
"1","0","","--------------------------------------------","",""
"1","0","","","",""
"1","0","AB-897-A","Laser Cannon","$750.00","$750.00"
"1","0","AB-897-B","Laser Cannon","$750.00","$750.00"
"1","0","AB-897-C","Laser Cannon","$750.00","$750.00"
"1","0","AB-897-D","Laser Cannon","$750.00","$750.00"
"1","0","AB-897-E","Laser Cannon","$750.00","$750.00"
"1","0","AB-897-R","Laser Cannon","$750.00","$750.00"
"$6,900.00"
"","$0.00"
"","$30.00"
"","$130.00"
"","$6,800.00"


The careful observer might note that Great Plains originally considered this a one page invoice; that's the "1" in the third line of the data. We reformatted it to two pages in our script. We've also eliminated extraneous "0"'s in an unused column of the item data and done other cosmetic changes. Changes like this are easy to do.

The Script

The Perl script allows flexibility of font choices, number of items printed per page and other user customization. The ability of one script to produce multiple outputs means that the user only has to select one "printer". The special printer redirects the output to our Perl script. We used the Redmon printer redirection program available from http://www.cs.wisc.edu/~ghost/redmon/en/redmon.htm to provide this capability. This freely downloadable program allows you to specify a script that will receive the output that normally will be printed (no special program is necessary on Linux or Unix systems).

In order to print correctly, the generated HTML output includes a special CSS style tag that asks browsers to separate printed output wherever we use it. This makes neat, professional output (note that you may want to adjust the margins and header/footer text in the Page Setup if you actually print this sample).

The script could have been written in Vbscript, C or any other language supported on Windows or Unix. I simply chose Perl because that's the easiest for me, and it is completely unimportant and transparent to the user.

A simplified version of the Perl script itself can be found at ftp://aplawrence.com/pub/gpcsv.pl

cartoon
My Working for yourself E-Book will show you how to break free
from the 9 to 5 grind.

Publish your articles, comments, book reviews or opinions here!

© November 2002 Tony Lawrence All rights reserved









-
Google Friend Connect users can
comment on this page here


Enter your email address for automatic notification of new posts here
(be sure to whitelist 'feedburner.com' if you use spam filtering)

Or use any RSS reader

Delivered by FeedBurner



Views for this page
Today This Week This Month This Year  Overall
11917952 10,045

Have you tried Searching this site?

Unix/Linux/Mac OS X support by phone, email or on-site: Support Rates

This is a Unix/Linux resource website. It contains technical articles about Unix, Linux and general computing related subjects, opinion, news, help files, how-to's, tutorials and more. We appreciate comments and article submissions.

Publishing your articles here

pavatar.jpg
More:
       - Code
       - Perl
       - Printing
       - Programming
       - Web/HTML




Unix/Linux Consultants


http://www.breakthru.com.au SCO (Openserver and Unixware), Unix, Solaris and Linux Consulting services including: Secure Networking Solutions; Linux based Firewalls; Backup Solutions; Secure Home to Office Network Setup; Phone, Remote and On-Site Support available - Satisfaction Guaranteed!


http://www.vss3.com SCO/Caldera OpenServer, Unixware & Linux. Tarantella & Non-stop Clustering


http://thatitguy.com Business networking servers, Linux and Unix experts. In business since 1997! Windows and Exchange to Samba and Scalix migration experts.



Twitter
  • Dec 4 07:16
    Being tired will cost me at Poker tonight but I don't see how I can squeeze in a nap.
  • Dec 4 04:06
    Wife had a nightmare at 2:00 AM; I never got back to sleep. Gave up at 4:00 and got up.









Change Congress