#!/bin/sh
f=$1
if [ "$(date +%m)" -ge 7 ] ; then
	tax_year="$(date +%Y)-$(($(date +%Y)+1))"
else
	tax_year="$(($(date +%Y)-1))-$(date +%Y)"
fi
day="$(date +%F)"
day="$(date -d "$day -$(date -d "$day" +%w) days" +%F)"
w1="$(date -d "$day -$(date -d "$day" +%u) days" +%F)"
w2="$day"
rm -rf ~/tmp-adamant-invoice-"$f"
mkdir ~/tmp-adamant-invoice-"$f"
cd ~/tmp-adamant-invoice-"$f"
mkdir --parents ~/work/invoices/"$tax_year"/
cd ~/work/invoices/"$tax_year"/
test -e adamant-"$f".ods || cp ../../adamant/legal/invoice.ods adamant-"$f".ods
libreoffice adamant-"$f".ods
libreoffice --headless --convert-to pdf --outdir ~/tmp-adamant-invoice-"$f" adamant-"$f".ods
cd ~/tmp-adamant-invoice-"$f"
mv adamant-"$f".pdf adamant-paul-wise-invoice-"$f".pdf
evince adamant-paul-wise-invoice-"$f".pdf
find -type f -print0 | sed --null-data i--attach | xargs --null xdg-email --subject "Paul Wise ADAMANT invoice $f" --body "Hi Kylie,\n\nLatest invoice for recent work." 'Kylie Twomey <kylie@adamantservices.com.au>'
read foo
cd
rm -rf ~/tmp-adamant-invoice-"$f"
