ref: debb5dccc7b87c897de9d6167e8af3e7e4b8fbb8
dir: /mkfile/
invoices=`{cd invoice; walk -d -n 1}
targets=`{for (f in $invoices) { echo invoice/^$f^/invoice-^$f^.pdf }}
all:V: $targets
test:VQ:
invoice/([^/]+)/invoice-([^/]+).pdf:RQ: invoice/\1/template invoice/\1/data.tsv
rfork en
ramfs
# data
bin/formatdata.awk <invoice/$stem1/data.tsv | tbl >/tmp/positions.tmp
cat <<EOF > /tmp/pre.tmp
.ds iv "$stem1
.de IV
.LP
.so /tmp/positions.tmp
..
EOF
# template
t=`{cat invoice/$stem1/template}
cp template/$t /tmp/template.tmp
cp template/$t.msg /tmp/msg.tmp
# date
date -f 'DD.MM.YYYY' `{cat invoice/$stem1/date} >/tmp/date.tmp
# client info
cl=`{cat invoice/$stem1/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/$stem1/msg && cp invoice/$stem1/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/$stem1/md5sum
# pdfmark overrides
bin/genpdfmark $stem1 > /tmp/info.pdfmark
# build
cat /tmp/pre.tmp /tmp/template.tmp | 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 > $target
echo built $target `{cat invoice/$stem1/md5sum}