+invoice_total(){
+ local id="$1" sender client date number vat vatrate \
+ total=0 caddress hourly time work hours
+
+ if [ -f "invoices/$id" ]; then
+ read -r sender client date number vat vatrate<<-EOF
+ $(sed q "invoices/$id")
+ EOF
+
+ [ -f "clients/${client#client=}" ] \
+ && read -r caddress hourly <"clients/${client#client=}"
+ [ "${hourly#hourly=}" -gt 0 ] 2>&- \
+ && hourly="${hourly#hourly=}" \
+ || hourly=0
+
+ sed 1d "invoices/$id" \
+ | { while read time work hours; do
+ [ "${hours#hours=}" -gt 0 ] 2>&- \
+ && hours="${hours#hours=}" \
+ || hours=0
+ total=$((total + hours * hourly))
+ done
+ printf %.2f\\n "$total"
+ }
+ else
+ printf %.2f\\n 0
+ fi
+}
+