ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: "Peter Münster" <pmlists@free.fr>
To: mailing list for ConTeXt users <ntg-context@ntg.nl>
Subject: Re: Discussion: correspondence with ConTeXt
Date: Thu, 17 Apr 2008 22:59:27 +0200	[thread overview]
Message-ID: <20080417205927.GB31968@gaston.couberia.bzh> (raw)
In-Reply-To: <48074550.6030209@elvenkind.com>

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
___________________________________________________________________________________

  parent reply	other threads:[~2008-04-17 20:59 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-04-17  8:13 Wolfgang Schuster
2008-04-17 12:40 ` Taco Hoekwater
2008-04-17 12:45   ` Arthur Reutenauer
2008-04-17 13:13   ` Olivier Guéry
2008-04-17 14:02     ` Wolfgang Schuster
2008-04-17 14:07       ` Olivier Guéry
2008-04-17 14:21         ` Wolfgang Schuster
2008-04-19 11:49       ` Antoine Junod
2008-04-21  7:09         ` Wolfgang Schuster
2008-04-21  7:52           ` Antoine Junod
2008-04-17 13:19   ` Wolfgang Schuster
2008-04-17 20:59   ` Peter Münster [this message]
2008-04-17 14:12 ` Idris Samawi Hamid
2008-04-17 15:08   ` Wolfgang Schuster
2008-04-17 15:34     ` Henning Hraban Ramm
2008-04-18  6:03       ` Wolfgang Schuster
2008-04-17 14:17 ` Henning Hraban Ramm
2008-04-17 14:32   ` Wolfgang Schuster
2008-04-17 15:32     ` Henning Hraban Ramm
2008-04-18  7:12       ` Wolfgang Schuster
2008-04-17 19:24     ` Gour
2008-04-17 20:48 ` Peter Münster
2008-04-18  6:21   ` Wolfgang Schuster
2008-04-18  6:51     ` Peter Münster
2008-04-18  6:59       ` Wolfgang Schuster
2008-04-18  7:50         ` Peter Münster
2008-04-18  7:50 ` Willi Egger
2008-04-18  8:13   ` Wolfgang Schuster
2008-04-18 19:45     ` Willi Egger
2008-04-19 10:30       ` Wolfgang Schuster
     [not found] <mailman.1.1208512802.14653.ntg-context@ntg.nl>
2008-04-18 18:40 ` Wolfgang Werners-Lucchini
2008-04-19 10:36   ` Wolfgang Schuster
     [not found] <mailman.6074.1208608916.4340.ntg-context@ntg.nl>
2008-04-19 16:35 ` Wolfgang Werners-Lucchini
2008-04-21  7:02   ` Wolfgang Schuster

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20080417205927.GB31968@gaston.couberia.bzh \
    --to=pmlists@free.fr \
    --cc=ntg-context@ntg.nl \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).