ref: 3b8c26ceaf773a1dcb3b3abf1be53895de7b9911
dir: /bin/buildinvoice.rc/
#!/bin/rc
# buildinvoice.rc invid
if(! ~ $#* 1) exit 'expects invoice id as argument'
rfork en
ramfs
# template
t=`{cat invoice/$1/template}
cp template/$t /tmp/template.tmp
cp template/$t.msg /tmp/msg.tmp
# data
bin/formatdata.awk <invoice/$1/data.tsv | sed -f template/$t.sed | tbl >/tmp/positions.tmp
cat <<EOF > /tmp/pre.tmp
.ds iv "$1
.de IV
.LP
.so /tmp/positions.tmp
..
EOF
# date
date -f 'DD.MM.YYYY' `{cat invoice/$1/date} >/tmp/date.tmp
# client info
cl=`{cat invoice/$1/client}
cl=$cl(1)
cp client/$cl/addr /tmp/client_addr.tmp
test -f client/$cl/msg && cp client/$cl/msg /tmp/msg.tmp
# invoice overrides
test -f invoice/$1/msg && cp invoice/$1/msg /tmp/msg.tmp
# generate unique ID
sum=`{cat /tmp/pre.tmp /tmp/template.tmp /tmp/msg.tmp /tmp/date.tmp | md5sum | tr 'a-z' 'A-Z'}
echo $sum >invoice/$1/md5sum
# pdfmark overrides
bin/genpdfmark $1 > /tmp/info.pdfmark
# build
cat /tmp/pre.tmp /tmp/template.tmp | sed -f template/$t.sed | troff -ms | lp -dstdout > /tmp/invoice.ps
cat /tmp/invoice.ps /tmp/info.pdfmark | ps2pdf '-sPAPERSIZE=a4' > /tmp/invoice.pdf
bin/pdfid /tmp/invoice.pdf $sum