On Thu, Apr 17 2008, Taco Hoekwater wrote:

>    * Quite a bit of correspondence is invoices and quotes,
>      with automatic calculations in them (VAT etc).

Hello Taco,

Quite funny: Just 3 days ago, I wrote t-invoice.tex for my personal needs,
just 1 command and very very simple:
\startInvoice
\invoiceItem[description=Ballon eau chaude, price={5063,4 + 1115,87}]
\invoiceItem[description=Vase d'expansion, price={386,25}]
\invoiceItem[description=Plan d'implantation du bâtiment, price={257,14}]
\invoiceItem[description=Branchement d'eau, price={2891,62}]
\stopInvoice

\stopInvoice prints the total.



Here the definitions (can be enhanced and/or wikified):

\startluacode
-- namespace
thirddata = thirddata or { }
thirddata.invoices = {}
thirddata.invoices.total = 0
thirddata.invoices.pos = 1

-- get price with right format
-- p: the price
-- return price with right format
function thirddata.invoices.format(p)
        local s = string.format("%.2f", p)
        s = s:gsub("%.", ",")
        return s
end

-- print new item
-- d: the description
-- p: the price
function thirddata.invoices.new_item(d, p)
        thirddata.invoices.total = thirddata.invoices.total + p
        tex.print("\\bTR\\bTD" .. string.format("%03d", thirddata.invoices.pos) 
..
                  "\\eTD\\bTD " .. d .. "\\eTD\\bTD " ..
                  thirddata.invoices.format(p) .. "\\eTD\\eTR")
        thirddata.invoices.pos = thirddata.invoices.pos + 1
end
\stopluacode

\def\invoiceItem{\dosingleargument\doinvoiceItem}
\def\doinvoiceItem[#1]{\getparameters[IV][#1]
  \ctxlua{thirddata.invoices.new_item("\IVdescription",
    \ctxlua{local s = string.gsub("\IVprice", ",", "."); tex.print(s)})}}

\def\invoiceTotal{%
  \ctxlua{tex.print(thirddata.invoices.format(thirddata.invoices.total))}}

\def\startInvoice{\start
  \setupTABLE[frame=off,textwidth=\textwidth,option=stretch]
  \setupTABLE[r][first][bottomframe=on]
  \setupTABLE[r][2,last][top=\blank]
  \setupTABLE[c][first,2][align=flushleft]
  \setupTABLE[c][last][align={flushright,lohi}]
  \bTABLE\bTR\bTH Position \eTH\bTH Description \eTH\bTH Prix \eTH\eTR}

\def\stopInvoice{\bTR\bTD[nc=2,align=flushright]Total:\eTD
  \bTD \invoiceTotal\eTD\eTR\eTABLE\stop}


Cheers, Peter

-- 
http://pmrb.free.fr/contact/

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : https://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________

Reply via email to