X-Git-Url: http://git.plutz.net/?p=invoices;a=blobdiff_plain;f=invoices.sh;h=b8568493cbc689d30cd74f47a72bb052e7901d0c;hp=9e07e9fab11ffbec85a9d97fbd37c31c02f59e94;hb=b037f9960718351b0470ab7ea67271b291bebb0e;hpb=363a64cdc01d34e8b1e9ba3bf4b1a68ae2dfeb1c diff --git a/invoices.sh b/invoices.sh index 9e07e9f..b856849 100755 --- a/invoices.sh +++ b/invoices.sh @@ -1,9 +1,10 @@ #!/bin/sh sender_list(){ - local select="$1" n name + local select="$1" n name address iban bic [ -d senders/ ] && for n in '' senders/*; do - [ "$n" ] && name="$(sed q "$n" |HTML)" + [ "$n" ] && read -r address iban bic <"$n" + name="$(UNSTRING "${address#address=}" |sed q |HTML)" [ "${n#senders/}" = "$select" ] \ && printf '' "${n#senders/}" "$name" \ || printf '' "${n#senders/}" "$name" @@ -22,16 +23,20 @@ client_list(){ } list_invoices(){ + local sender client date number vat vatrate iban bic hourly [ -d invoices/ ] && for i in invoices/*; do read -r sender client date number vat vatrate<<-EOF $(sed q "$i") EOF - [ -f "senders/${sender#sender=}" ] \ - && sender="$(sed q "senders/${sender#sender=}")" \ - || sender="(unset)" + + [ ! -f "senders/${sender#sender=}" ] \ + && sender="(unset)" \ + || read -r sender iban bic <"senders/${sender#sender=}" + [ ! -f "clients/${client#client=}" ] \ && client="(unset)" \ || read -r client hourly <"clients/${client#client=}" + [ "${date#date=}" -ge 0 ] 2>&- \ && date="$(date -d "@${date#date=}" +%x)" \ || date="(unset)" @@ -43,7 +48,7 @@ list_invoices(){ [label Amount:] %.2f € [a href="/invoices/%s" Edit] ]' "$(UNSTRING "${number#number=}" |HTML)" \ - "$(HTML "$sender")" \ + "$(UNSTRING "${sender#address=}" |sed q |HTML)" \ "$(UNSTRING "${client#address=}" |sed q |HTML)" "$(HTML "$date")" \ "$(invoice_total "${i#invoices/}")" \ "$(HTML ${i#invoices/})" @@ -72,6 +77,7 @@ edit_invoice(){ && read -r caddress hourly <"clients/${client#client=}" hourly="${hourly#hourly=}" + tid="$(tid "invoices/$id")" total=$(invoice_total "$id") cat <<-EOF @@ -137,7 +143,8 @@ $({ sed 1d "invoices/$id"; printf 'time= work= hours=\n'; } \ esac) ]] ] - [submit "update" "$(tid "invoices/$id")" Update] + [submit "genpdf" "$tid" Export PDF] + [submit "update" "$tid" Update] ] EOF } @@ -158,7 +165,7 @@ invoice_total(){ || hourly=0 sed 1d "invoices/$id" \ - | { while read time work hours; do + | { while read -r time work hours; do [ "${hours#hours=}" -gt 0 ] 2>&- \ && hours="${hours#hours=}" \ || hours=0 @@ -172,9 +179,10 @@ invoice_total(){ } update_invoice(){ - local id="$(POST id |checkid)" extra=0 + local id="$(POST id |checkid)" extra=0 tid + tid="$(tid invoices/$id)" - if [ "$(POST update)" = "$(tid "invoices/$id")" ]; then + if [ "$(POST update)" = "$tid" ] || [ "$(POST genpdf)" = "$tid" ]; then mkdir -p invoices for n in "$(POST_COUNT time)" "$(POST_COUNT work)" "$(POST_COUNT hours)"; do @@ -195,5 +203,9 @@ update_invoice(){ done } >"invoices/$id" fi + if [ "$(POST genpdf)" ]; then + . $_EXEC/odtgen.sh + genodt "$id" + fi REDIRECT "/invoices/$id" }