-edit_client(){
- id="$1"
- if [ -f "clients/$id" ]; then
- read -r address hourly <"clients/$id"
- fi
- [ "$address" ] || address="address="
- [ "$hourly" ] || hourly="hourly="
- printf '
- [form method="POST" action="/update_client"
- [hidden "id" "%s"]
- <textarea name="address" placeholder="address">
-%s</textarea>
- [label for=hourly Hourly Rate:]
- [input #hourly type=number name=hourly value="%s"]
- [submit "update" "update" Update]
- ]' \
- "$(HTML $id)" \
- "$(UNSTRING "${address#address=}" |HTML)" \
- "$(UNSTRING "${hourly#hourly=}" |grep -xE '[0-9]+')"
-}
-
-edit_sender(){
- id="$1"
- if [ -f "senders/$id" ]; then
- address="$(cat "senders/$id")"
- fi
- [ "$address" ] || address="Name
-Street
-City
-
-Phone:
-000 000000
-
-Tax no.
-xxx / 000 / ###
-"
- printf '
- [form method="POST" action="/update_sender"
- [hidden "id" "%s"]
- <textarea name="address" placeholder="address">%s</textarea>
- [submit "update" "update" Update]
- ]' \
- "$(HTML $id)" \
- "$(HTML "${address}")"
-}
-
-list_clients(){
- [ -d clients/ ] && for c in clients/*; do
- read -r address hourly <"$c"
- address="$(UNSTRING "${address#address=}")"
- [ "$address" ] || address="(no address)"
- printf '[div .client .address <!--
- -->%s
-
-[label Hourly Rate:] %s€
- [a href="/clients/%s" Edit]]
- ' "$(HTML "$address")" \
- "$(HTML "${hourly#hourly=}")" \
- "$(HTML "${c#clients/}")"
- done
-}
-
-list_senders(){
- [ -d senders/ ] && for s in senders/*; do
- address=$(cat "$s")
- [ "$address" ] || address="(no address)"
- printf '[div .sender .address <!--
- -->%s[a href="/senders/%s" Edit]]
- ' "$(HTML "$address")" "$(HTML "${s#senders/}")"
- done
-}
-
-sender_list(){
- local select="$1" n name
- [ -d senders/ ] && for n in '' senders/*; do
- [ "$n" ] && name="$(sed q "$n" |HTML)"
- [ "${n#senders/}" = "$select" ] \
- && printf '<option value="%s" selected=selected>%s</option>' "${n#senders/}" "$name" \
- || printf '<option value="%s">%s</option>' "${n#senders/}" "$name"
- done
-}
-
-client_list(){
- local select="$1" n address hourly name
- [ -d clients/ ] && for n in '' clients/*; do
- [ "$n" ] && read -r address hourly <"$n"
- name="$(UNSTRING "${address#address=}" |sed q |HTML)"
- [ "${n#clients/}" = "$select" ] \
- && printf '<option value="%s" selected=selected>%s</option>' "${n#clients/}" "$name" \
- || printf '<option value="%s">%s</option>' "${n#clients/}" "$name"
- done
-}
-
-list_invoices(){
- [ -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 "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)"
-
- printf '[div .invoice
- [h2
- %s]
- [label From:] %s [label To:] %s [label on] %s
- [a href="/invoice/%s" Edit]
- ]' "$(UNSTRING "${number#number=}" |HTML)" \
- "$(HTML "$sender")" \
- "$(UNSTRING "${client#address=}" |sed q |HTML)" "$(HTML "$date")" \
- "$(HTML ${i#invoices/})"
- done
-}
-
-edit_invoice(){
- id="$1"
- if [ -f "invoices/$id" ]; then
- read -r sender client date number vat vatrate<<-EOF
- $(sed q "invoices/$id")
- EOF
- fi
-
- [ "${date#date=}" -ge 0 ] 2>&- \
- && date="$(date -d "@${date#date=}" +%F)" \
- || date="$(date +%F)"
- [ "${number#number=}" ] || number="number=$(date +%s)"
- [ "${vatrate#vatrate=}" -ge 0 ] 2>&- || vatrate="vatrate=19"
-
- cat <<-EOF
- [form method="POST" action="/update_invoice"
- [hidden "id" "$(HTML "$id")"]