INVOICE - from preprinted to UnForm

Top  Previous  Next

This sample is an invoice that is intended for a pre-printed form.  The data generated by the application doesn't include any headings or simulated line drawing like a plain-paper invoice might.  In this case, UnForm must simulate the entire pre-printed invoice form.

 

uf100c –i sample1.txt –f advanced.rul –p pdf -o client:invoice.pdf

 

A title header prefixes all rule sets, which is just a unique name enclosed in brackets.

[Invoice]

 

 

Detect statements are used to distinguish this form from any other report that the application might send to the printer through UnForm.  Unlike most form packages, UnForm doesn't dedicate a printer name to a particular form (though it can be configured to do so).  Instead, it reads the first page of data, then compares it to the detect statements found in the various rule sets in the rule file.

 

The detect statements below indicate that

* a date (mm/dd/yy format) followed by 2 spaces, followed by 7 more characters will appear at column 61, row 5
*6 characters will appear at column 9, row 11
*a date, a space, and 6 characters will appear at column 10, row 21

detect 61,5,"~../../..  ......."                # invoice date and #detect 9,11,"~......"                                # customer codedetect 10,21,"~../../.. ......"                # ord date and cust code

 

The following lines define several constants that are used elsewhere in the rule set.  Wherever the constant names appear in a command, the value is substituted.  Constants are not variables and are not interpreted while the job is processed.  They are simply literal placeholders used while UnForm reads rule set lines.

# set up document constantsconst MAXCOLS=80                                        # max cols to outputconst MAXRCOLS=79                                        # MAXCOLS-1const LEFTCOL=.5                                        # use 1 if emptyconst RIGHTCOL=80.5                                        # use LEFTCOL for symmetryconst MAXROWS=66                                        # max rows to output

 

 

The following lines define the page size and orientation.  The dpi command sets the printer to 600 dots per inch.  The rows and cols commands set the dimension for positioning and scaling.  All positioning will be based on 80 columns and 66 rows appearing within the printed margins of the page.  The gs on command triggers the use of graphical shading, which improves the look of shade regions over the native pcl shading of most laser printers, especially at higher dpi settings and shade percentages.  In addition, UnForm will generate two copies of the job, with each page producing two copies as processed (collated).

portraitdpi 600gs on                                                        # graphical shadingcols MAXCOLS                                                # max output columnsrows MAXROWS                                                # max output rows# to print more copies, increase value and add copy titles in prejob

pcopies 2                                                        # max # of copies

 

 

If this rule set is used to produce a PDF document, then the title of "Sample Invoice" will be added to the PDF file.  For laser output, the title command is ignored.

title "Invoice Sample"                                # view in PDF properties

 

The prejob code block is executed once at the beginning of the job, after the first page of data has been read and the rule set parsed.  This example is simply setting a variable form_title$ to a literal value INVOICE.  This variable is used later in the rule set.

 

The prepage code block is executed once per page, just after UnForm has read the text for the page, but before any copies of that page have been printed.  Within a prepage code block, you can insert any valid Business Basic code (though you need to be careful not to insert any UnForm commands.) This code initializes a variable shipzip$ to null, then looks for a regular expression pattern of 5 digits on line 15.  If the pattern is found, it sets shipzip$ to the zip code.  After the code block is closed, a barcode command is used to place a postnet barcode below the shipping address.  The barcode command uses the syntax "{shipzip$}", indicating the expression shipzip$ should be used to generate the data to barcode.

 

Once the prepage code block creates shipzip$, it then scans a range of rows looking for special memo format lines.  It marks these lines with the characters "mL" in the first two columns.  Later in the rule set, you'll see how these markers are used to treat memo lines differently than standard invoice lines.

 

The order of execution is controlled by UnForm.  There is actually no need to place the barcode command below the prepage code block, as UnForm will properly execute the code block before any form commands are executed at run-time.

 

prejob {        # set up variables needed by merged routines below        # if form title changes per page,

 # set up in prepage routine below

 form_title$="INVOICE"

}

 

prepage {

 # find zip code in city,state,zip line for bar code

 shipzip$=""

 # regular expression of 5 digits on line 15

 x=mask(text$[15],"[0-9][0-9][0-9][0-9][0-9]")

 if x>0 then shipzip$=get(x,15,5)

 

 # mark memo lines for special handling in detail section below

 # memo start in column 28 with all spaces before

 for i=25 to 56

         if len(text$[i])>27 and trim(text$[i](1,27))="" then \

                 text$[i](1,2)="mL"

 next i

}

 

The pdf driver supports the ability to email the PDF file created using the email command.  The commented # email line below provides an example of the command.  It requires four arguments, each of which can be a literal string value or a string expression enclosed in braces.  In order for the email command to work, the mailcall.ini file must be properly configured for your system.

# When run in PDF mode, and if mailcall.ini is configured properly,# and if the system can communicate with the mail server, then the

# next line would send the PDF invoice as an attachment to an email.

# email "someone@somewhere.com","me@mycompany.com", \

#        {"A test invoice "+cvs(get(71,5,7),3)}, \

#        "Attached is a sample invoice\n"

 

 

The next group of commands creates a page header with box and text commands.  The box commands are given as the cbox variant, which accepts two pairs of numbers as opposite corners of the box.  Some of the commands are stored in a different rule set, called "Mrg Form Header".  This rule set is also located in the advanced.rul file.  The lines in that rule set are merged in here as if they were part of this rule set.

 

Note that some of the text commands, and also a barcode command, use an expression rather than a literal.  An expression is an executable value assignment enclosed in braces.  For example, one text command uses an expression {cut(61,5,8,"")},which cuts out the text at column 61, row 5, for 8 columns, returning the result, while setting those positions to "".  The result is printing at position 75,5 what was at position 61,5.

 

# heading sectionconst HFONT=univers,12                                        # headingscbox LEFTCOL,1,RIGHTCOL,MAXROWS,5                        # complete page boxmerge "Mrg Form Header"                                        # merge std hdr rules# right top ribbonconst HFONT=univers,11,italic                                # headings

const DFONT=cgtimes,11,bold                                # data

 

# draw info box with internal grid and shading

# horizontal lines at 6 and 8

# vertical line at 74 with shading between 67 and 74

cbox 67,4,RIGHTCOL,10,5,crows=6 8,ccols=74::20

text 68,5,"Date",HFONT

text 68,7,"Invoice",HFONT

text 68,9,"Page #",HFONT

# cut data from old position and place in new

text 75,5,{cut(61,5,8,"")},DFONT

text 75,7,{cut(71,5,7,"")},DFONT

text 75,9,{cut(79,5,2,"")},DFONT

 

# sold to section

cbox LEFTCOL,10,41,18.5,5

cbox LEFTCOL,10,41,11.25,0,10

text 8,10.75,"SOLD TO",HFONT,bold

cfont 8,12,40,15,DFONT                                        # sold to address

if copy 1

 barcode 8,16,{shipzip$},900,10.0,2

end if

text 2,18,{"Your customer code is "+cut(9,11,6,"")+"."},8,cgtimes

 

# ship to section

cbox 41,10,RIGHTCOL,18.5,5

cbox 41,10,RIGHTCOL,11.25,0,10

text 48,10.75,"SHIP TO",HFONT,bold

# cut ship to address and place in new position

text 48,12,{mcut(51,12,30,4,"","Y","Y")},DFONT

text 43,18,{"Your ship to code is "+cut(55,11,6,"")+"."},8,cgtimes

 

This section draws order detail boxes and headings.  The first cbox command draws a grid, using the internal crows and ccols options.  In addition to the boxes and headings, the font used for the data from the input stream is changed using a series of cfont commands, one for each section.

# ribbon sectionconst L1=19const L2=20# draw info box with internal grid and shading# horizontal line at 20.5 with shading between 18.5 and 20.5# vertical lines at 9, 18, 25, and 65cbox LEFTCOL,18.5,RIGHTCOL,22.5,5,crows=20.5::20,ccols=9 18 25 65

# special internal grid in ribbon box

cbox 29,18.5,65,21.5

cbox 42,18.5,56,21.5

# ribbon headings

text 1,L1,"Order",HFONT,right,cols=8

text 1,L2,"Number",HFONT,right,cols=8

text 10,L1,"Order",HFONT,center,cols=8

text 10,L2,"Date",HFONT,center,cols=8

text 19,L1,"Cust.",HFONT

text 19,L2,"Number",HFONT

text 26,L1,"Sls",HFONT

text 26,L2,"Prs",HFONT

text 30,L1,"Purchase",HFONT

text 30,L2,"Order No.",HFONT

text 43,L2,"Ship Via",HFONT

text 57,L1,"Ship",HFONT,center,cols=8

text 57,L2,"Date",HFONT,center,cols=8

text 66,L2,"Terms",HFONT

# ribbon data

cfont 1,21,8,21,DFONT,right                                        # order #

cfont 10,21,17,21,DFONT,center                                # order date

cfont 19,21,24,21,DFONT                                                # cust #

cfont 26,21,28,21,DFONT                                                # sls prs code

cfont 26,22,64,22,DFONT                                                # sls prs name

cfont 30,21,41,21,DFONT                                                # po #

cfont 43,21,55,21,DFONT                                                # ship via

cfont 57,21,64,21,DFONT,center                                # ship date

cfont 66,21,MAXCOLS,22,DFONT                                        # terms

 

This section of lines controls the formatting of the invoice detail lines.  A grid is drawn around the column headers and detail lines.  The column headers are shaded.  Item detail lines are fonted using a series of font commands that look for the pattern "~\.[0-9][0-9][0-9][0-9]" which is a period followed by 4 digits.  Wherever that occurs, font changes are made relative to that position.  Similarly, the memo lines identified by the prepage code block and marked with the text marker "mL" are fonted with a different column structure.  In addition to the font command, an erase command is used to remove the text markers.

# detail section# detail headingsconst L1=23const L2=24# draw info box with internal grid and shading# horizontal line at 24.5 with shading between 22.5 and 24.5

# vertical lines at 5, 10, 16, 51, 55, and 67

cbox LEFTCOL,22.5,RIGHTCOL,56.5,5,crows=24.5::10, \

 ccols=5 10 16 51 55 67

text 1,L1,"Qty",HFONT,right,cols=4

text 1,L2,"Ord",HFONT,right,cols=4

text 6,L1,"Qty",HFONT,right,cols=4

text 6,L2,"Ship",HFONT,right,cols=4

text 11,L1,"Qty",HFONT,right,cols=5

text 11,L2,"Bkord",HFONT,right,cols=5

text 20,L2,"Item & Description",HFONT

text 52,L2,"U/M",HFONT,center,cols=3

text 56,L1,"Unit",HFONT,right,cols=11

text 56,L2,"Price",HFONT,right,cols=11

text 68,L1,"Extended",HFONT,right,cols=12

text 68,L2,"Price",HFONT,right,cols=12

# detail data

# Modify fonts for lines. As comments may be present in the same rows,

# use a pattern to locate the .nnnn in the price column,

# which indicates a part number line.

# Use a prepage routine to find the comments and change their font.

font "~\.[0-9][0-9][0-9][0-9]",-61,0,4,1,DFONT,right        # qty ord

font "~\.[0-9][0-9][0-9][0-9]",-56,0,4,1,DFONT,right        # qty shipped

font "~\.[0-9][0-9][0-9][0-9]",-50,0,4,1,DFONT,right        # qty b/o

font "~\.[0-9][0-9][0-9][0-9]",-42,0,30,2,DFONT                # item # & desc

font "~\.[0-9][0-9][0-9][0-9]",-10,0,3,1,DFONT,center        # u/m

font "~\.[0-9][0-9][0-9][0-9]",-6,0,11,1,DFONT,right        # unit price

font "~\.[0-9][0-9][0-9][0-9]",6,0,12,1,DFONT,right        # ext price

 

# handle memo lines

# inserted 'mL' in prepage above

font "mL@1,25,2,56",10,0,63,1,HFONT

erase "mL@1,25,2,56",0,0,2,1

 

Watermark text is placed in the middle of the detail lines.  This text is centered between column 1 and MAXCOLS, is rendered at 120 points, and is printed at 20% gray shading.

# watermark - large font with light shadingtext 1,52,{form_title$},cgtimes,120,shade 20,center,cols=MAXCOLS

 

The totals section is formatted like the other sections, with a grid, text headings, and font changes that apply to the input stream text.

# totals section# draw info box with internal grid and shading# horizontal lines at 59 and 63# vertical line at 69 with shading between 58 and 69cbox 58,57,RIGHTCOL,65,5,ccols=69::20,crows=59 63

text 59,58,"Sales Amt",HFONT

text 59,61,"Sales Tax",HFONT

text 59,62,"Freight",HFONT

text 59,64.25,"TOTAL",HFONT,bold,14

cfont 59,60,68,60,HFONT                                                        # disc hdr

cfont 70,58,MAXRCOLS,65,DFONT,14,decimal                        # totals

 

These text lines simply demonstrate some of UnForm's paragraph features.  The first text command forces the longest line in the paragraph to fit within the number of defined columns.  The maximum point size is 12, but that may be adjusted down to accommodate the longest line.  Lines are delimited by the \n character sequence, or by a CHR(10) within an expression.  Line spacing is determined by the final point size, and may be adjusted with the spacing option.   For example, if the rendered size is 8 point, then the spacing of 1 will result in 9 lines per inch (9 x 8=72), while spacing of 1.5 would result in 6 lines per inch (9/1.5=6).
 

The second example will force use the defined point size to render the text, but any lines wider than the specified columns will be word-wrapped.
 

The third example shows how to use a specified ASCII value in a text command.  The ASCII value 174, when printed using the symbol set 9J, is a trademark symbol.  This technique can be used to print Latin characters and special symbols.  The symbol set determines what any given character value prints as.  The 9J symbol set is the default.  See the –testpr command line option for viewing printed tables of different symbol sets.

# footer section# These lines show fitting and wrapping of text

text 2,60,"This sample message text, which contains\nline breaks, \

 is sized to fit in 20 columns.",cols 20,cgtimes,12, \

 fit,spacing 1

 

text 28,60,"This sample message text is word wrapped to not exceed \

 20 columns, while retaining the specified 12 point size.",\

 cgtimes,cols 20,12,wrap,spacing 1

 

text 2,64,"This sample was generated by UnForm<174>.",7,cgtimes, \

         symset 9J,blue

 

 

This set of commands places the phrase "Customer Copy" on copy 1, and "Remittance Copy" on copy 2.  The text is placed at row 65.5, and is centered within the columns defined at column 1 and the constant MAXCOLS, which represents the whole page width.

# copy name sectionconst ROW=65.5if copy 1        text 1,ROW,"Customer Copy",HFONT,bold,center,cols=MAXCOLS

end if

if copy 2

 text 1,ROW,"Accounting Copy",HFONT,bold,center,cols=MAXCOLS

end if