Latest news 2024-02-16: Experimental (unstable) datatool v2.49a available for testing. Download from the experimental page if you would like to try it out.

Exercise 13: Creating an Invoice for a Customer (invoice.sty) using SQL Data (Solution)

This is a solution to the SQL part of Exercise 13. I've used the letter class file for my solution and used an empty \opening{} to ensure the recipient's address is displayed.

You need the sample SQL data supplied in samples.sql. This requires two calls to datatooltk before the document can be built:

  1. The first call creates a file called order.dbtex that contains the customer details and the discount and postage for the order identified by the group order id 2:

    datatooltk --output order.dbtex --sqldb samples --sqluser sampleuser --sql "SELECT people.surname, people.forenames, people.title, people.address1, people.address2, people.town, people.county, countries.name AS countryname, people.postcode, ordergroups.discount, ordergroups.postage FROM people, ordergroups, countries WHERE people.id = ordergroups.customerid AND ordergroups.id = 2 AND countries.code = people.country"
  2. The second call creates a file called orderlist/dbtex that contains the details of each of the books in the order along with the quantity ordered:

    datatooltk --output orderlist.dbtex --sqldb samples --sqluser sampleuser --sql "SELECT books.title AS booktitle, books.author, books.format, books.price, orders.quantity FROM books, orders WHERE orders.groupid = 2 AND orders.bookid = books.id"










\begin{letter}{\DTLifnullorempty{\Title}{}{\Title\ }%
  \Forenames\ \Surname\\%


   \ProjectTitle{Book Order}%
     by \BookAuthor\ (\BookFormat)}{\BookPrice}{\OrderQuantity}%
   \EBC{Postage and Packaging}{\Postage}%



Download invoice-csv.tex or invoice-csv.pdf.

© 2015 Dickimaw Books. "Dickimaw", "Dickimaw Books" and the Dickimaw parrot logo are trademarks. The Dickimaw parrot was painted by Magdalene Pritchett.

Terms of Use Privacy Policy Cookies Site Map FAQs