aboutsummaryrefslogtreecommitdiff
path: root/overlays/kookie/invoice/invoice.sh
diff options
context:
space:
mode:
Diffstat (limited to 'overlays/kookie/invoice/invoice.sh')
-rwxr-xr-xoverlays/kookie/invoice/invoice.sh24
1 files changed, 24 insertions, 0 deletions
diff --git a/overlays/kookie/invoice/invoice.sh b/overlays/kookie/invoice/invoice.sh
new file mode 100755
index 00000000000..1374f9219d2
--- /dev/null
+++ b/overlays/kookie/invoice/invoice.sh
@@ -0,0 +1,24 @@
+#!/bin/sh
+
+set -ueo pipefail
+
+SOURCE=$1
+
+if [ -z $SOURCE ]; then
+ echo "Usage: invoice <file>"
+ exit 2
+fi
+
+TARGET=$(dirname $SOURCE)
+ACCOUNT=$(basename $SOURCE .yml)
+
+# The reason behind this awk madness is that we want to be able to write
+# a date as yyyy-mm-dd in the invoice descriptor, but LaTeX needs the
+# date as three elements to fill in a {d}{m}{y} pattern. Thus we replace
+# a simple "date" line with three seperate fields that we can then read
+# from LaTeX
+cat $SOURCE | xargs -d '\n' -L 1 \
+ | awk -F '-' '{ if(match($0, /date/)) { gsub(/date: /,"", $1); \
+ print "date_year: " $1 "\n" "date_month: " $2 "\n" "date_day: " $3 } \
+ else { print $0} }' \
+ | pandoc - -o $TARGET/$ACCOUNT.pdf --template=$TEMPLATE_FILE --pdf-engine=xelatex