X-Git-Url: http://git.plutz.net/?a=blobdiff_plain;f=invoices.sh;h=a1ec2339be82ce4e994d215282a221b5fe01b663;hb=af7737f425a9c32b53501fd9a72f8d1657c8aaf1;hp=f8dbf8514dfb97bc2bb957b604ff0ff0242858ca;hpb=82b730d7926c9d7141639c1305beaab3f843918a;p=invoices diff --git a/invoices.sh b/invoices.sh index f8dbf85..a1ec233 100755 --- a/invoices.sh +++ b/invoices.sh @@ -26,7 +26,7 @@ list_invoices(){ [ -d invoices/ ] || return 0 printf '[h1 Open]' - for i in invoices/*; do case "$(line <$i)" in + for i in invoices/*; do case "$(sed 1q <$i)" in *status=open*) list_invoice "$i";; *status=*) :;; *) list_invoice "$i";; @@ -34,7 +34,7 @@ list_invoices(){ for n in resent:Resent sent:Sent paid:Paid cancelled:Cancelled; do printf '[h1 %s]' "${n#*:}" - for i in invoices/*; do case "$(line <$i)" in + for i in invoices/*; do case "$(sed 1q <$i)" in *status=${n%:*}*) list_invoice "$i";; esac; done done @@ -167,17 +167,19 @@ edit_invoice(){ [tr [th Date] [th Work] [th Hours] [th Price] ] $({ sed 1d "invoices/$id"; printf 'time= work= hours=\n'; } \ | while read -r time work hours x; do - hours="$(UNSTRING "${hours#hours=}" |grep -m1 -xE '[0-9]+' || printf 0)" + hours="$(UNSTRING "${hours#hours=}" \ + |grep -m1 -xE '\.[0-9]+|[0-9]+\.?[0-9]*' || printf 0)" printf '[tr [td [textarea name=time %s] ] [td [textarea name=work %s] ] - [td [input type=number name=hours value="%s"] ] + [td [input type=number name=hours value="%.2g" step=any] ] [td %s] ]' "$(UNSTRING "${time#time=}" |HTML)" \ "$(UNSTRING "${work#work=}" |HTML)" \ - "$hours" "$((hours * hourly)) €" + "$hours" \ + "$(awk "BEGIN { printf \"%.2f €\", ${hours} * ${hourly}; }")" done ) [tr [td colspan=4 @@ -221,10 +223,10 @@ invoice_total(){ sed 1d "invoices/$id" \ | { while read -r time work hours; do - [ "${hours#hours=}" -gt 0 ] 2>&- \ + [ "${hours#hours=}" ] 2>&- \ && hours="${hours#hours=}" \ || hours=0 - total=$((total + hours * hourly)) + total=$(awk "BEGIN { printf \"%.2f\", ${total} + ${hours} * ${hourly}; }") done case $vat in vat=nett)