#!/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 '<option value="%s" selected=selected>%s</option>' "${n#senders/}" "$name" \
|| printf '<option value="%s">%s</option>' "${n#senders/}" "$name"
}
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)"
[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/})"
&& read -r caddress hourly <"clients/${client#client=}"
hourly="${hourly#hourly=}"
+ tid="$(tid "invoices/$id")"
total=$(invoice_total "$id")
cat <<-EOF
esac)
]]
]
- [submit "update" "$(tid "invoices/$id")" Update]
+ [submit "genpdf" "$tid" Export PDF]
+ [submit "update" "$tid" Update]
]
EOF
}
|| 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
}
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
done
} >"invoices/$id"
fi
+ if [ "$(POST genpdf)" ]; then
+ . $_EXEC/odtgen.sh
+ genodt "$id"
+ fi
REDIRECT "/invoices/$id"
}