(OLDER) <- More Stuff -> (NEWER) (NEWEST)
Printer Friendly Version



We no longer offer ftp downloads. If there is a file you need referenced here, please contact me by email and I will get it to you.

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.

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.

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

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

© November 2002 Tony Lawrence All rights reserved




Click here to add your comments



Don't miss responses! Subscribe to Comments by RSS or by Email

Click here to add your comments


If you want a picture to show with your comment, go get a Gravatar



ad

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

Jump to Comments



Many of the products and books I review are things I purchased for my own use. Some were given to me specifically for the purpose of reviewing them. I resell or can earn commissions from the sale of some of these items. Links within these pages may be affiliate links that pay me for referring you to them. That's mostly insignificant amounts of money; whenever it is not I have made my relationship plain. I also may own stock in companies mentioned here. If you have any question, please do feel free to contact me.

Specific links that take you to pages that allow you to purchase the item I reviewed are very likely to pay me a commission. Many of the books I review were given to me by the publishers specifically for the purpose of writing a review. These gifts and referral fees do not affect my opinions; I often give bad reviews anyway.

We use Google third-party advertising companies to serve ads when you visit our website. These companies may use information (not including your name, address, email address, or telephone number) about your visits to this and other websites in order to provide advertisements about goods and services of interest to you. If you would like more information about this practice and to know your choices about not having this information used by these companies, click here.


book graphic unix and linux troubleshooting guide

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



 I sell and support
 Kerio Mail server




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


Unix/Linux Consultants

Skills Tests

Guest Post Here











My Favorites

Change Congress