X-Git-Url: http://git.plutz.net/?a=blobdiff_plain;f=invoices.sh;h=d53ace75b41d3452e5224fb75d43222435ac6323;hb=refs%2Fheads%2Fmaster;hp=a88bc7fc59fc663892f198b92946407566f2f2cb;hpb=da0991fe5c1d910682dd7bcb03adafee2a42ca37;p=invoices diff --git a/invoices.sh b/invoices.sh index a88bc7f..d53ace7 100755 --- a/invoices.sh +++ b/invoices.sh @@ -34,7 +34,9 @@ list_invoices(){ for n in resent:Resent sent:Sent paid:Paid cancelled:Cancelled; do printf '[h1 %s]' "${n#*:}" - for i in invoices/*; do case "$(sed 1q <$i)" in + printf "%s\n" invoices/* \ + | sort -r \ + | while read i; do case "$(sed 1q <$i)" in *status=${n%:*}*) list_invoice "$i";; esac; done done @@ -167,17 +169,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="%g" 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 +225,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) @@ -274,7 +278,7 @@ update_invoice(){ printf 'time=%s work=%s hours=%s\n' \ "$(POST time $n |STRING)" "$(POST work $n |STRING)" \ "$(POST hours $n |STRING)" \ - | grep -xvF 'time= work= hours=0' + | grep -xvF 'time=\ work=\ hours=0' done } >"invoices/$id"