From: Henning Hraban Ramm <hraban@fiee.net>
To: mailing list for ConTeXt users <ntg-context@ntg.nl>
Subject: Re: Learning LuaTeX : Invoice
Date: Sun, 20 Feb 2011 14:29:56 +0100 [thread overview]
Message-ID: <18189696-3253-4F58-867E-F6A4E8BE8925@fiee.net> (raw)
In-Reply-To: <130608E6-A8C0-4B47-943F-C63C926D58E9@fiee.net>
Am 2011-02-20 um 13:58 schrieb Henning Hraban Ramm:
> That seems to work so far, but invoice.hours and invoice.sum are
> always doubled!
> In my letter setup, it’s even quadrupled!
> I guess my functions gets called several times, but how can I avoid
> that?
I found a better approach, but with the letter module involved, my
"RegisterItem" is called twice!
\starttext
\usemodule[letter]
\startluacode
userdata = userdata or {}
userdata.invoice = { amount = 0, hours = 0, perhour = 100, items = {} }
function userdata.numberformat(amount)
context(string.gsub(string.format("\%.2f", amount), "%.", ","))
end
function userdata.InvoiceLine(text, hours)
context.NC()
context(text)
context.NC()
userdata.numberformat(hours)
context("\\,h")
context.NC()
context.NC()
userdata.numberformat(hours * userdata.invoice.perhour)
context("\\,€")
context.NC()
context.NR()
end
function userdata.InvoiceSumLine(text)
context.HL()
context.NC()
context(text)
context.NC()
userdata.numberformat(userdata.invoice.hours)
context("\\,h")
context.NC()
context("à ")
userdata.numberformat(userdata.invoice.perhour)
context("\\,€/h")
context.NC()
userdata.numberformat(userdata.invoice.amount)
context("\\,€")
context.NC()
context.NR()
end
function userdata.RegisterItem(text, hours)
for no, item in ipairs(userdata.invoice.items) do
-- we need to check for double registering due to some call logic of
ConTeXt and the letter module
if item.text == text then
--return -- commented to show double calling
end
end
table.insert(userdata.invoice.items, {text=text, hours=hours})
end
function userdata.Invoice()
local amountsum, hoursum = 0,0
context("\\starttabulate[|lw(8cm)|rg(,)w(2cm)|rg(,)w(2cm)|
rg(,)w(3cm)|]")
for no, item in ipairs(userdata.invoice.items) do
userdata.InvoiceLine(item.text, item.hours)
hoursum = hoursum + item.hours
amountsum = amountsum + item.hours * userdata.invoice.perhour
end
userdata.invoice.hours = hoursum
userdata.invoice.amount = amountsum
userdata.InvoiceSumLine("Sum")
context.stoptabulate()
end
\stopluacode
\startletter[subject={INVOICE}]
\startluacode
userdata.RegisterItem("Do some \\CONTEXT ", 0.5)
userdata.RegisterItem("Do some \\LUATEX ", 1.5)
userdata.Invoice()
\stopluacode
\stopletter
\stoptext
Greetlings from Lake Constance!
Hraban
---
http://www.fiee.net/texnique/
http://wiki.contextgarden.net
https://www.cacert.org (I'm an assurer)
___________________________________________________________________________________
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 : http://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___________________________________________________________________________________
next prev parent reply other threads:[~2011-02-20 13:29 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-02-20 11:55 Henning Hraban Ramm
2011-02-20 12:07 ` Henning Hraban Ramm
2011-02-20 12:08 ` Wolfgang Schuster
2011-02-20 12:58 ` Henning Hraban Ramm
2011-02-20 13:29 ` Wolfgang Schuster
2011-02-20 13:29 ` Henning Hraban Ramm [this message]
2011-02-20 13:41 ` Wolfgang Schuster
2011-02-20 14:49 ` Henning Hraban Ramm
2011-02-20 15:12 ` Hans Hagen
2011-02-20 15:09 ` Hans Hagen
2011-02-20 19:16 ` Henning Hraban Ramm
2011-02-20 20:20 ` Philipp Gesang
2011-02-20 20:28 ` Wolfgang Schuster
2011-02-20 23:28 ` Hans Hagen
2011-02-22 9:47 ` Henning Hraban Ramm
2011-02-22 9:51 ` luigi scarso
2011-02-22 10:01 ` Wolfgang Schuster
2011-02-22 10:14 ` luigi scarso
2011-02-22 10:55 ` Henning Hraban Ramm
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=18189696-3253-4F58-867E-F6A4E8BE8925@fiee.net \
--to=hraban@fiee.net \
--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).