STATEMENT - two page formats

 

Top  Previous  Next

In this sample, a two-page, plain paper statement is printed.  The two pages contain two slightly different formats, with the second page containing detail lines and a customer aging, and the first page containing some more detail lines and the phrase "CONTINUED" at the bottom.  In the same statement print run, some statements may contain a single page, others two or more pages.

 

The trick here is to get UnForm to produce two formats based on the content of each page.  In order to accomplish this, we define the job to produce multiple copies, and assign certain copies to certain formats.  Using a precopy{} code block, we can then control the printing of the different formats.

 

uf90c –i sample2.txt –f advanced.rul –p pdf –o client:statement.pdf

 

 

This statement header identifies this rule set.

 

[Statement]

 

The word STATEMENT appears at column 34, row 2, and a date appears at column 65, row 7.  To further clarify, a date format is matched at position 65, 7.

 

detect 34,2,"STATEMENT"

detect 65,7,"~../../.."                                # statement date

 

 

 

The page dimensions are 66 rows and 75 columns.  The text input to UnForm doesn't contain any form-feeds to indicate the end of a page, so the command "page 66" tells UnForm to consider each 66 lines to be a page.

 

Pcopies 4 is used to tell UnForm to print 4 copies of each page, with copies following each other in sequence for each page (collated).  You will find later that UnForm doesn't actually print all copies of each page, but instead simply prints selected copies, depending on the format required.  As each page is processed, if the page contains aging totals, UnForm prints 2 copies of that format, and if it does not contain aging totals, then UnForm prints 2 copies of the second format.

 

# set up document constants

const MAXCOLS=75                                        # max cols to output

const MAXRCOLS=74                                        # MAXCOLS-1

const LEFTCOL=1                                        # use 1 if empty

const RIGHTCOL=75                                        # MAXCOLS for symmetry

const MAXROWS=66                                        # max rows to output

 

portrait

dpi 300

gs on                                                        # graphical shading

cols MAXCOLS                                                # max output columns

rows MAXROWS                                                # max output rows

page MAXROWS                                                # no form-feeds used

 

# to print more copies, increase value and add copy titles in prejob

# Copy 1,2        Statement with aging totals

# Copy 3,4        Statement w/o  aging totals

pcopies 4                                                        # max # of copies

 

 

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

 

title "Statement Sample"                                # view in PDF properties

 

 

The prejob command defines a string variable form_title$, assigning it the value "STATEMENT".  This variable is used later in the rule set for a page heading and also in a watermark.

 

prejob {

 # set up variables needed by merged routines below

 # if form title changes per page,

 # set up in prepage routine below

 form_title$="STATEMENT"

}

 

 

The prepage code block performs 2 functions.  It checks the input data for the word "CONTINUED" at position 66, 64.  If that word is present, then a variable continued$ is assigned to the phrase "Continued"; otherwise it is set to null.  In addition, at three individual lines (16, 62, and 64), there may be single ! characters used as character-mode vertical lines in the input data.  Elsewhere in the rule set is a 'vline "!!", erase' command, which erases instances of 2 or more ! characters vertically on the page.  This code takes care of the single-row instances.

 

prepage {

 # get continued if it exists

 continued$=get(66,64,9)

 if continued$="CONTINUED" then continued$="Continued" \

         else continued$=""

 

# remove single ! from line draw regions

       x=pos("!"=text$[16]); \

       while x>0; text$[16](x,1)="",x=pos("!"=text$[16]);wend

 

       x=pos("!"=text$[62]); \

       while x>0; text$[62](x,1)="",x=pos("!"=text$[62]);wend

 

       x=pos("!"=text$[64]); \

       while x>0; text$[64](x,1)="",x=pos("!"=text$[64]);wend

 

}

 

 

The precopy code block is executed as each of the 4 copies are about to be printed.  The logic here indicates the copies 1 and 2 are for pages that do not contain the word "CONTINUED" (remember the prepage code block?), and copies 3 and 4 do contain that word.  By setting the variable skip to a non-zero value, the copy being processed is skipped.  Only 1 of the 2 formats is printed, depending on the content of the page.

 

precopy {

 if copy=1 or copy=2 then if continued$="Continued" then skip=1

 if copy=3 or copy=4 then if continued$<>"Continued" then skip=1

}

 

 

The following lines remove most of the existing character-mode line drawing elements from the input data.  The hline and vline commands scan for places where at least the indicated number of characters, horizontally or vertically, occur on the page.  The erase option removes them rather than replacing them with graphical lines.

 

#remove existing lines

hline "--",erase

hline "==",erase

vline "!!",erase

cerase 1,1,1,MAXROWS                                        # erase all 1st column

cerase MAXCOLS,1,MAXCOLS,MAXROWS                        # erase all last column

 

 

The following lines draw the page headings.  Some of the commands are stored in another rule set, "Mrg Form Header", which is merged as the rule set is parsed.  The headings already exist, and are moved and fonted with text commands using expressions, such as {cut(66,5,4,"")}.

 

# heading section

const HFONT=univers,12                                        # headings

cerase 1,1,MAXCOLS,10

cbox LEFTCOL,1,RIGHTCOL,MAXROWS,5                        # complete page box

merge "Mrg Form Header"                                        # merge std hdr rules

 

# right top ribbon section

const HFONT=univers,11,italic                                # headings

const DFONT=cgtimes,11,bold                                # data

# draw info box with internal grid and shading

# horizontal line at 6

# vertical line at 68 with shading between 63 and 68

cbox 63,5,MAXCOLS,9,5,crows=7,ccols=68::20

text 64,6,{cut(66,5,4,"")},HFONT                        # page #

text 64,8,{cut(59,7,4,"")},HFONT                        # date

text 69,6,{trim(cut(71,5,3,""))},DFONT                # page #

text 69,8,{trim(cut(65,7,8,""))},DFONT                # date

 

# customer section

# draw info box with internal grid and shading

# vertical line at 10 with shading between 1 and 10

cbox LEFTCOL,10,MAXCOLS,15,5,ccols=10::10

text 2,11,{cut(2,10,2,"")},HFONT                        # to

text 4,13,{trim(cut(15,10,10,""))},DFONT                # cust code

cfont 12,11,MAXCOLS,14,DFONT                                # address

 

 

The detail section contains several columns of information.  There are fewer detail lines on pages with the aging data, so the grid drawing is made specific to particular formats with "if copy 1,2" and "if copy 3,4" sections.  Then two groups of font changes are used, first for the column headings and then for the data columns.

 

# detail section

# detail headings

# draw info box with internal grid and shading

# horizontal line at 6

# vertical line at 68 with shading between 63 and 68

if copy 1,2

 cbox LEFTCOL,15,MAXCOLS,56,5,crows=17::20, \

         ccols=10 18 27 39 48 60 63

end if

if copy 3,4

 cbox LEFTCOL,15,MAXCOLS,61,5,crows=17::20, \

         ccols=10 18 27 39 48 60 63

end if

const ROW=16

cfont 2,ROW,9,ROW,HFONT,center                                # date

cfont 11,ROW,17,ROW,HFONT                                        # inv #

cfont 19,ROW,26,ROW,HFONT,center                                # due date

cfont 28,ROW,38,ROW,HFONT,right                                # due amt

cfont 40,ROW,47,ROW,HFONT,center                                # pmt date

cfont 49,ROW,59,ROW,HFONT,right                                # pmt amt

cfont 61,ROW,62,ROW,HFONT,center                                # type

cfont 64,ROW,MAXRCOLS,ROW,HFONT,right                        # balance

# detail data

const DFONT=cgtimes,11                                                # data

cfont 2,18,9,60,DFONT,center                                        # date

cfont 11,18,17,60,DFONT                                                # inv #

cfont 19,18,26,60,DFONT,center                                # due date

cfont 28,18,38,60,DFONT,right                                        # due amt

cfont 40,18,47,60,DFONT,center                                # pmt date

cfont 49,18,59,60,DFONT,right                                        # pmt amt

cfont 61,18,62,60,DFONT,center                                # type

cfont 64,18,MAXRCOLS,60,DFONT,right,BOLD                # balance

 

 

A watermark prints the form title as large, lightly shaded text.  Its position depends upon the format, hence the use of if copy blocks.

 

# watermark - large font with light shading and rotation

if copy 1,2

 text 39,56,{form_title$},cgtimes,75,shade 20,center, \

         cols=MAXCOLS,rotate 90

end if

if copy 3,4

 text 44,61,{form_title$},cgtimes,85,shade 20,center, \

         cols=MAXCOLS,rotate 90

end if

 

 

The footer section differs considerably between the two formats.  Copies 1 and 2 are associated with pages that have aging data, so you see the fonting of the aging columns defined there.  Copies 3 and 4 are printed when the word "CONTINUED" appears, and that word is printed below, though as the value stored in continued$ ("Continued").

 

# footer section

# remarks

if copy 1,2

 cbox LEFTCOL,56,RIGHTCOL,61,5

 cfont 2,57,MAXRCOLS,60,HFONT

endif

# totals

const DFONT=cgtimes,11,bold                                        # data

if copy 1,2

 cbox LEFTCOL,61,RIGHTCOL,64.5,5,crows=63::20, \

         CCOLS=14 26 38 50 62

 const ROW=62

 cfont 1,ROW,13,ROW,HFONT,right                                # current

 cfont 15,ROW,25,ROW,HFONT,right                                # 1-15

 cfont 27,ROW,37,ROW,HFONT,right                                # 16-30

 cfont 39,ROW,49,ROW,HFONT,right                                # 31-45

 cfont 51,ROW,61,ROW,HFONT,right                                # over 45

 cfont 63,ROW,MAXRCOLS,ROW,HFONT,right,bold,12        # total due

 const ROW=64

 cfont 1,ROW,13,ROW,DFONT,right                                # current

 cfont 15,ROW,25,ROW,DFONT,right                                # 1-15

 cfont 27,ROW,37,ROW,DFONT,right                                # 16-30

 cfont 39,ROW,49,ROW,DFONT,right                                # 31-45

 cfont 51,ROW,61,ROW,DFONT,right                                # over 45

 cfont 63,ROW,MAXRCOLS,ROW,DFONT,right,bold,12        # total due

endif

 

if copy 3,4

 cerase 1,62,MAXCOLS,66

 text 1,65,{Continued$},HFONT,right,cols=MAXRCOLS

endif

 

 

Finally, within the two formats are two physical copies.  Each of these copies is either for the customer to keep or for the customer to return with their payment.  Copy 1, the first page of format 1, and copy 3, the first page of format 2, get the "Customer Copy" footer.  The others get the "Remittance Copy" footer.

 

# copy name section

const ROW=65.5

if copy 1,3

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

end if

if copy 2,4

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

end if