2

I'm trying to assemble invoices based on CSV data. I found this example: Combining invoice and datatool to create serial invoices

This is the code:

\documentclass{letter}
\usepackage{invoice}
\usepackage{datatool}
\address{ABC AG \\
    Nonamestreet 4 \\
    1100 Vienna \\
    bill@example.com}
\date{16. September 2013}
\begin{document}    
\DTLloaddb{bills}{billdata.csv}
\DTLforeach{bills}
{\firstname=firstname,
\lastname=lastname,
\caddress=customeraddress,
\tariffname=tariffname,
\service=service,
\rateperunit=rateperunit,
\unitcount=unitcount}
{
\begin{letter}{\firstname~ \lastname \\ \caddress}
\opening{Invoice}     Dear customer \lastname! This is your current bill.
\begin{invoice}{Euro}{20}
\ProjectTitle{\tariffname}
\Fee{Regular charge} {\rateperunit} {\unitcount}
\end{invoice}
\closing{Best regards, ABC AG}
\end{letter}
\clearpage
}
\end{document}

And this is my CSV file:

firstname,lastname,customeraddress,tariffname,service,rateperunit,unitcount
John,Doe,Musterstraße 4,Tariff 1,Call,0.04,4
Andy,Ball,Molenstraat 178B,Tariff 2,Extra,56.78,5

However, looks like it cannot retrieve more data than just the first line of the CVS file.

What I'm trying to achieve is the following: - have a database with all the entries (services, quantity, price, etc...) for a single invoice

What I'm doing wrong?

  • Welcome to TeX.SX! Unfortunately we cannot answer what you are doing wrong without seeing a minimal compilable code example illustrating your issue. The answer in the linked post works for me (even for more rows). – TeXnician Dec 21 '18 at 19:01
  • I added the code both from the example I found and the CSV file I created – matteo-gambarutti Dec 21 '18 at 19:23
  • This creates as expected two letters, one for John Doe and one for Andy Ball. If you want more entries for each customer you will need a different structure both in the csv and in the code. – Ulrike Fischer Dec 21 '18 at 19:34
  • Do you perhaps have a suggestion on how to change the CSV and the code? Thank you very much. – matteo-gambarutti Dec 21 '18 at 19:41
2

There may be a few items that benefit from simplification. The following example will compile 3 pages with just an overfull \hbox per page

here is the simpler csv.

first,last,address,tariff,service,rate,units
Andy,Ball,Molenstraat 178B,Tariff 2,Extra,56.78,5
John,Doe,Musterstraße 4,Tariff 1,Call,0.04,4
Jane,Doe,Musterstraße 6,Tariff 1,Call,0.04,4

This package has been updated recently and I have altered some names to see where values were applied in your mwe (change dutch to english or german as per the package documentation)

\documentclass[a4paper,11pt]{letter}
\usepackage[latin1]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{datatool}
\address{ABC AG \\    Nonamestreet 4 \\    Amsterdam \\    bill@example.com}
\date{16. September 2013}
\usepackage[dutch]{invoice}
\DTLloaddb[]{bill}{bills.csv}

\begin{document}    
\DTLforeach{bill}{\firstname=first,\lastname=last,\caddress=address,\tariffname=tariff,\service=service,\rateperunit=rate,\unitcount=units}
{
\begin{letter}{\firstname~ \lastname \\ \caddress}
\opening{}Dear \firstname$ $ \lastname. Here is your current bill.
\begin{invoice}{Euro}{20.0}
\ProjectTitle{\tariffname}
\Fee{Regular Charge}{\rateperunit}{\unitcount}
\end{invoice}
\closing{Best regards, ABC AG}
\end{letter}
}
\end{document}

If you require a comma in place of the decimal point in the currency output add it to the language line e.g. \usepackage[dutch,comma]{invoice}

| improve this answer | |
  • Thank you! One thing: how can I have a space between \firstname and \lastname in the line \opening{}Dear \firstname \lastname. Here is your current bill.? I tried a '~' (like in the line before) but the space is larger than usual spaces. – matteo-gambarutti Dec 24 '18 at 18:33
  • I may be wrong (not a regular user of TeX) thus best solution may depend on your final preamble but Dear \firstname$ $ \lastname works for me in this case with a space in front of each \ – user170109 Dec 24 '18 at 18:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.