shithub: rech

ref: 982ba593935d007955d7d53f69622af34b3436ab
dir: /mkfile/

View raw version
invoices=`{cd invoice; walk -d -n 1}
targets=`{for (f in $invoices) { echo invoice/^$f^/invoice-^$f^.pdf }}

all:V: test invoices

test:VQ:
	# run tests for data integrity
	bin/test/vmissingfiles
	bin/test/vvariables

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
	echo built $target `{cat invoice/$stem1/md5sum}