Customer Invoice History - demoilst.bbx
The customer invoice history display is used by the Customer Inquiry application to show a listing of invoices associated with a given customer. The application uses the Scrolling Customer Listing program, and each customer listed is linked to this program through a URL containing the customer ID.
0001 SETERR ERRTRAP
0010 REM "demoilst.bbx - BASIC Web Utility Customer Invoice Listing
Demo
0020 REM "Copyright 1996 by Allen Miglore. All rights reserved.
0030 REM "Permission to derive programs from this is hereby granted,
0040 REM "provided said programs utilize licensed copies of the BASIC
Web Utility.
As with the scrolling customer listing, a "startwith" value can be supplied to begin the invoice listing at a particular point. A "more records" link, containing the "startwith" value, is specified in this program where there are more than 10 invoices to display.
0100 REM ^100 - If continuing the invoice list, the CGI
field
0110 REM "startwith" is used to indicate what invoice.
0120 LET STARTWITH$="",STARTWITH$=FIELD(CGI$,"startwith",ERR=0130)
The invoices are presented in a HTML table structure, so each line from the invoices file is formatted with table row tags. In addition, the table and column heading tags are required above and below the invoice list and are stored in TABLETOP$ and TABLEBOT$.
0200 REM ^100 - Initialize other values
0210 LET KNUM=0,MAXRECS=10
0215 LET TABLETOP$="<table border><tr><th>Invoice</th><th>Date</th><th>Amount</th></tr>"
0220 LET STRUCTURE$="<tr><td>[invoice]</td> <td>[date]</td>
<td align=right>[amount]<br></td></tr>"
0225 LET TABLEBOT$="</table>"
0400 REM ^100 - Open Data Files
0410 LET CUSTCHAN=UNT;
OPEN (CUSTCHAN)"GENSMPL1"
0420 LET INVCHAN=UNT;
OPEN (INVCHAN)"GENSMPL3"
The customer record is read into CUST$, and a table is built from a list of fields in the CIST$ template. The HTML text for the table is placed in CUSTINFO$.
0450 REM ^100 - Get Customer Data and Create Display
0460 READ RECORD(CUSTCHAN,KEY=FIELD(CGI$, "cust_id", ERR=NODATA),
DOM=0470)CUST$
0470 CALL "uthtmgen.wbb",
CUST$,"cust_id,name,addr1,addr2,city,state,zip,phone,slsp", "",
"table border", "", "", CUSTINFO$
A list of invoices (up to MAXRECS at a time) is loaded into the variable
INVLIST$. The list begins with the customer ID, plus the invoice number
indicated in the STARTWITH$, and continues until all invoices for the
customer ID have been read. If there are more than MAXRECS invoices, the
CURKEY$ contains that next one in line, after the customer ID is trimmed
off. This is used to construct the global string $MOREURL, which is referenced
in the HTML text file "demoilst.txt" to allow the user to continue
the list. Note the use of the "startwith" value in the URL.
The CGI environment variable SCRIPT_NAME contains the name of the cgi script
that launched this program. Because the same script is used for all the
sample programs, it provides a convenient way of building another URL.
0500 REM ^100 - Construct Invoice List
0510 REM uthtmfil.wbb reads from a channel, and builds list of
0520 REM records, using a particular structure, into a string
0530 CALL "uthtmfil.wbb",INVCHAN,CGI.CUST_ID$+STARTWITH$,CGI.CUST_ID$,KNUM,
MAXRECS,COUNT,CURKEY$,INVOICE$,STRUCTURE$,INVLIST$,""
0540 IF CURKEY$>""
THEN
LET CURKEY$=CURKEY$(LEN(CGI.CUST_ID$)+1)
0600 REM ^100 - If there are more records in the file, add a "more
records"
0610 REM link URL to continue. curkey$ contains the key to the
0620 REM next record required. By placing this in a STBL, the
0630 REM uthtmout.wbb program that loads the HTML template can
0640 REM conditionally place it after the list.
0650 LET X$=STBL("$MOREURL","");
IF CURKEY$=""
THEN
GOTO 0680
0660 CALL "utencode.wbb",0,CURKEY$,NEXT_STARTWITH$
0670 LET MOREURL$=STBL("$MOREURL",ENV.SCRIPT_NAME$+"?pgm=demoilst.bbx&startwith="+NEXT_STARTWITH$+"&cust_id="+CGI.CUST_ID$)
Both the customer information and the invoice list are substituted into the demoilst.txt file, using specific comments as place markers, with the result sent to the user, and the program exits.
0680 REM ^100 - Load the HTML template, and add the list
to it
0690 CALL "uthtmout.wbb",CGI$,"{include demoilst.txt}",HTML$,""
0700 CALL "utsub.wbb",HTML$,"<!-- Customer Info -->",CUSTINFO$
0710 CALL "utsub.wbb",HTML$,"<!-- Invoice Table -->",
TABLETOP$+$0A$+INVLIST$+TABLEBOT$
0800 REM ^100 - Send it to the user
0810 CALL "utsend.wbb",HTML$
1000 DONE:
REM ^1000 - Clean up and exit
1010 CALL "utexit.wbb",CGI$
1020 IF RETURN_TO_WATCH
THEN
RUN "utwatch.wbb"
1030 RELEASE
2000 ERRTRAP:
REM ^1000 - generic error trap
2010 CALL "uterr.wbb",ERR,TCB(5),PGM(-2)
2020 GOTO DONE