ref: 3b8c26ceaf773a1dcb3b3abf1be53895de7b9911
parent: 521aed03530e987473d55abd50dfb263e1473181
author: sirjofri <sirjofri@sirjofri.de>
date: Sat Aug 30 05:17:45 EDT 2025
extracts pdf building to separate script
--- /dev/null
+++ b/bin/buildinvoice.rc
@@ -1,0 +1,47 @@
+#!/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
--- a/bin/mkinvoice
+++ b/bin/mkinvoice
@@ -32,7 +32,7 @@
EOF
cat <<EOF >invoice/$id/data.tsv
-# Amount Price (1) VAT Name
+# Amount Price (1) VAT Category Name
EOF
echo 'default' >invoice/$id/template
--- a/mkfile
+++ b/mkfile
@@ -17,46 +17,5 @@
invoices:VQ: $targets
invoice/([^/]+)/invoice-([^/]+).pdf:RQ: invoice/\1/template invoice/\1/data.tsv
- rfork en
- ramfs
-
- # template
- t=`{cat invoice/$stem1/template}- cp template/$t /tmp/template.tmp
- cp template/$t.msg /tmp/msg.tmp
-
- # data
- bin/formatdata.awk <invoice/$stem1/data.tsv | sed -f template/$t.sed | tbl >/tmp/positions.tmp
- cat <<EOF > /tmp/pre.tmp
- .ds iv "$stem1
- .de IV
- .LP
- .so /tmp/positions.tmp
- ..
- EOF
-
- # 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 | 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 > $target
+ bin/buildinvoice.rc $stem1 > $target
echo built $target `{cat invoice/$stem1/md5sum}--
⑨