4 local select="$1" n name address iban bic
5 [ -d senders/ ] && for n in '' senders/*; do
6 [ "$n" ] && read -r address iban bic x<"$n"
7 name="$(UNSTRING "${address#address=}" |sed q |HTML)"
8 [ "${n#senders/}" = "$select" ] \
9 && printf '<option value="%s" selected=selected>%s</option>' "${n#senders/}" "$name" \
10 || printf '<option value="%s">%s</option>' "${n#senders/}" "$name"
15 local select="$1" n address hourly name
16 [ -d clients/ ] && for n in '' clients/*; do
17 [ "$n" ] && read -r address hourly x<"$n"
18 name="$(UNSTRING "${address#address=}" |sed q |HTML)"
19 [ "${n#clients/}" = "$select" ] \
20 && printf '<option value="%s" selected=selected>%s</option>' "${n#clients/}" "$name" \
21 || printf '<option value="%s">%s</option>' "${n#clients/}" "$name"
26 local sender client date number vat vatrate iban bic hourly \
27 taxtype nett tax gross total
29 [ -d invoices/ ] && for i in invoices/*; do
30 read -r sender client date number vat vatrate hourly x<<-EOF
34 [ ! -f "senders/${sender#sender=}" ] \
36 || read -r sender iban bic x<"senders/${sender#sender=}"
38 [ ! -f "clients/${client#client=}" ] \
40 || read -r client hourly x<"clients/${client#client=}"
42 [ "${date#date=}" -ge 0 ] 2>&- \
43 && date="$(date -d "@${date#date=}" +%x)" \
46 read -r taxtype nett tax gross x<<-EOF
47 $(invoice_total "${i#invoices/}")
50 nett) total="${nett} € + VAT";;
51 gross) total="${gross} € incl. VAT";;
52 *) total="${gross} €";;
58 [label From:] %s [label To:] %s [label on] %s
60 [a href="/invoices/%s" Edit]
61 ]' "$(UNSTRING "${number#number=}" |HTML)" \
62 "$(UNSTRING "${sender#address=}" |sed q |HTML)" \
63 "$(UNSTRING "${client#address=}" |sed q |HTML)" "$(HTML "$date")" \
65 "$(HTML ${i#invoices/})"
70 local id="$1" sender client date number vat vatrate caddress hourly \
71 taxtype nett tax gross
73 if [ -f "invoices/$id" ]; then
74 read -r sender client date number vat vatrate hourly x<<-EOF
75 $(sed q "invoices/$id")
79 [ "${date#date=}" -ge 0 ] 2>&- \
80 && date="$(date -d "@${date#date=}" +%F)" \
82 [ "${number#number=}" ] \
83 && number="${number#number=}" \
84 || number="$(date +%s)"
85 [ "${vatrate#vatrate=}" -ge 0 ] 2>&- \
86 && vatrate="${vatrate#vatrate=}" \
89 [ -f "clients/${client#client=}" ] \
90 && read -r caddress chourly x<"clients/${client#client=}"
91 [ "${chourly#hourly=}" -ge 0 ] 2>&- \
92 && chourly="${chourly#hourly=}" \
94 [ "${hourly#hourly=}" -ge 0 ] 2>&- \
95 && hourly="${hourly#hourly=}" \
96 || hourly="${chourly}"
98 tid="$(tid "invoices/$id")"
100 read -r taxtype nett tax gross x<<-EOF
101 $(invoice_total "$id")
105 [form method="POST" action="/update_invoice"
106 [hidden "id" "$(HTML "$id")"]
110 $(sender_list "${sender#sender=}")
115 $(client_list "${client#client=}")
118 [label for=number Invoice Number:]
119 [input #number name=number value="$(UNSTRING "${number}" |HTML)"]
121 [label for=date Date:]
122 [input #date name=date value="${date}" placeholder="YYYY-MM-TT"]
124 [label for=hourly Hourly Rate:]
125 [input #hourly type=number name=hourly value="${hourly}"]
127 [radio "vat" "smallbusiness" #vatsb $([ "${vat#vat=}" = smallbusiness ] && printf checked) ]
128 [label for=vatsb Small business exemption from VAT]
129 [radio "vat" "nett" #vatnett $([ "${vat#vat=}" = nett ] && printf checked)]
130 [label for=vatnett Nett]
131 [radio "vat" "gross" #vatgross $([ "${vat#vat=}" = gross ] && printf checked)]
132 [label for=vatgross Gross]
133 [label for=vatrate VAT Rate: [input type=number name="vatrate" value="${vatrate}"]% ]
136 [tr [th Date] [th Work] [th Hours] [th Price] ]
137 $({ sed 1d "invoices/$id"; printf 'time= work= hours=\n'; } \
138 | while read -r time work hours x; do
139 hours="$(UNSTRING "${hours#hours=}" |grep -m1 -xE '[0-9]+' || printf 0)"
141 [td [textarea name=time
143 [td [textarea name=work
145 [td [input type=number name=hours value="%s"] ]
147 ]' "$(UNSTRING "${time#time=}" |HTML)" \
148 "$(UNSTRING "${work#work=}" |HTML)" \
149 "$hours" "$((hours * hourly)) €"
154 (nett) printf 'Sum: %7.2f €[br] + VAT: %7.2f €[br] [strong Total:] %7.2f €' \
156 (gross) printf '[strong Total:] %7.2f €[br] incl. nett: %7.2f €[br] + VAT: %7.2f €' \
158 (*) printf '[strong Total:] %.2f €' $nett ;;
162 [submit "genpdf" "$tid" Export PDF]
163 [submit "update" "$tid" Update]
169 local id="$1" sender client date number vat vatrate \
170 total=0 caddress hourly time work hours
172 if [ -f "invoices/$id" ]; then
173 read -r sender client date number vat vatrate hourly x<<-EOF
174 $(sed q "invoices/$id")
177 [ "${hourly#hourly=}" -gt 0 ] 2>&- \
178 && hourly="${hourly#hourly=}" \
180 [ "${vatrate#vatrate=}" -ge 0 ] 2>&- \
181 && vatrate="${vatrate#vatrate=}" \
184 sed 1d "invoices/$id" \
185 | { while read -r time work hours; do
186 [ "${hours#hours=}" -gt 0 ] 2>&- \
187 && hours="${hours#hours=}" \
189 total=$((total + hours * hourly))
194 printf \"nett %.2f %.2f %.2f\",
195 $total, int($total * $vatrate + .5) / 100,
196 $total + int($total * $vatrate + .5) / 100
200 printf \"gross %.2f %.2f %.2f\",
201 $total - int($total / (100 + $vatrate) * $vatrate * 100 + .5) / 100,
202 int($total / (100 + $vatrate) * $vatrate * 100 + .5) / 100, $total
206 printf \"notax %.2f %.2f %.2f\",
217 local id="$(POST id |checkid)" extra=0 tid
218 tid="$(tid invoices/$id)"
220 if [ "$(POST update)" = "$tid" ] || [ "$(POST genpdf)" = "$tid" ]; then
223 for n in "$(POST_COUNT time)" "$(POST_COUNT work)" "$(POST_COUNT hours)"; do
224 [ "$n" -gt "$extra" ] && extra="$n"
227 { printf 'sender=%s client=%s date=%s number=%s vat=%s vatrate=%s hourly=%s\n' \
228 "$(POST sender)" "$(POST client)" \
229 "$(date -d "$(POST date)" +%s)" \
230 "$(POST number |STRING)" \
231 "$(POST vat |grep -m1 -xE 'smallbusiness|gross|nett')" \
232 "$(POST vatrate |grep -m1 -xE '[0-9]+')" \
233 "$(POST hourly |grep -m1 -xE '[0-9]+')"
234 for n in $(seq 1 $extra); do
235 printf 'time=%s work=%s hours=%s\n' \
236 "$(POST time $n |STRING)" "$(POST work $n |STRING)" \
237 "$(POST hours $n |STRING)" \
238 | grep -xvF 'time= work= hours=0'
242 if [ "$(POST genpdf)" ]; then
243 read -r sender client date x<"invoices/$id"
244 read -r saddress x <"senders/${sender#sender=}"
245 read -r caddress x <"clients/${client#client=}"
246 filename="Rechnung $(UNSTRING "${saddress#address=}" |sed 1q) an $(UNSTRING "${caddress#address=}" |sed 1q) $(date -d@"${date#date=}" +%F).pdf"
250 REDIRECT "/export/${id}.pdf/$(URL "${filename}" |sed s/%0D//g)"
253 REDIRECT "/invoices/$id"