3 _EXEC="$(realpath "${0%/*}")"
4 . "$_EXEC/cgilite/cgilite.sh"
5 . "$_EXEC/cgilite/storage.sh"
11 printf %s\\n "$*" >/dev/stderr
16 # generate time based ID
17 # Fixme: Unix time stamps assumed to be 32bit always
20 while [ "$d" -gt 0 ]; do
21 printf \\%o\\n $((d % 256))
28 | sed -n '2{y;+/;:_;;p}'
32 grep -m 1 -xE '[0-9a-zA-Z:_]{12}';
36 printf 'Content-Type: text/html; charset=utf-8\r\n\r\n'
37 ./cgilite/html-sh.sed <<EOF
39 [meta name="viewport" content="width=device-width"]
40 [link rel="stylesheet" type="text/css" href="invoices.css"]
44 [a "/invoices/" Invoices]
45 [a "/clients/" Clients]
46 [a "/senders/" Senders]
55 if [ -f "clients/$id" ]; then
56 read -r address hourly <"clients/$id"
58 [ "$address" ] || address="address="
59 [ "$hourly" ] || hourly="hourly="
61 [form method="POST" action="/update_client"
63 <textarea name="address" placeholder="address">
65 [label for=hourly Hourly Rate:]
66 [input #hourly type=number name=hourly value="%s"]
67 [submit "update" "update" Update]
70 "$(UNSTRING "${address#address=}" |HTML)" \
71 "$(UNSTRING "${hourly#hourly=}" |grep -xE '[0-9]+')"
76 if [ -f "senders/$id" ]; then
77 address="$(cat "senders/$id")"
79 [ "$address" ] || address="Name
90 [form method="POST" action="/update_sender"
92 <textarea name="address" placeholder="address">%s</textarea>
93 [submit "update" "update" Update]
96 "$(HTML "${address}")"
100 [ -d clients/ ] && for c in clients/*; do
101 read -r address hourly <"$c"
102 address="$(UNSTRING "${address#address=}")"
103 [ "$address" ] || address="(no address)"
104 printf '[div .client .address <!--
105 -->%s[a href="/clients/%s" Edit]]
106 ' "$(HTML "$address")" "$(HTML "${c#clients/}")"
111 [ -d senders/ ] && for s in senders/*; do
113 [ "$address" ] || address="(no address)"
114 printf '[div .sender .address <!--
115 -->%s[a href="/senders/%s" Edit]]
116 ' "$(HTML "$address")" "$(HTML "${s#senders/}")"
121 [ -d invoices/ ] && for i in invoices/*; do
122 read -r sender client date number vat<<-EOF
125 [ -f "senders/${sender#sender=}" ] \
126 && sender="$(sed q "senders/${sender#sender=}")" \
128 [ -f "clients/${client#client=}" ] \
129 && client="$(sed q "client/${client#client=}")" \
132 && date="$(date -d @$date +%x)" \
135 printf '[div .invoice
138 [label From:] %s [label To:] %s [label on] %s
139 [a href="/invoices/%s" Edit]
140 ]' "$(HTML "$number")" "$(HTML "$sender")" \
141 "$(HTML "$client")" "$(HTML "$date")"
145 info="$(PATH "${PATH_INFO}")"
149 . "$_EXEC/cgilite/file.sh"
150 FILE "$_EXEC/invoices.css"
154 printf '[a .new href="/clients/%s" New]' "$(timeid)"
155 } | yield_page clients
158 edit_client "${info#/clients/}" |yield_page client
161 id="$(POST id |checkid)"
162 if [ "$(POST update)" = update -a "$id" ]; then
164 printf 'address=%s hourly=%s' \
165 "$(POST address |STRING)" "$(POST hourly |STRING)" \
168 echo Invalid Data "$(POST id)" "$(POST update)" >&2
174 printf '[a .new href="/senders/%s" New]' "$(timeid)"
175 } | yield_page senders
178 edit_sender "${info#/senders/}" |yield_page sender
181 id="$(POST id |checkid)"
182 if [ "$(POST update)" = update -a "$id" ]; then
184 POST address >"senders/$id"
190 printf '[a href="/invoices/%s" New]' "$(timeid)"
191 } | yield_page invoices
194 edit_invoice "${info#/invoices/}" |yield_page invoice
196 *) REDIRECT /invoices