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:
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.
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 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 reservedEnter your email address for automatic notification of new posts here
(be sure to whitelist 'feedburner.com' if you use spam filtering)
| Views for this page | ||||
|---|---|---|---|---|
| Today | This Week | This Month | This Year | Overall |
| 1 | 19 | 17 | 952 | 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.
Add your comments
comment on this page here