]> git.plutz.net Git - confetti/blob - ledgers/index.cgi
process split fields as arrays
[confetti] / ledgers / index.cgi
1 #!/bin/sh
2
3 . "$_EXEC/cgilite/storage.sh"
4 . "$_EXEC/pdiread.sh"
5
6 if [ "$(POST show_account)" ]; then
7   uid="$(POST show_account)"
8   cfile="$(grep -lxF "UID;:${uid}" "${_DATA}/vcard/"*.vcf || grep -lxF "UID:${uid}" "${_DATA}/vcard/"*.vcf)"
9   REDIRECT "${_BASE}/ledgers/account.sh?card=${cfile##*/}"
10   exit 0;
11 fi
12
13 credit() {
14   printf '%03i\n' "$1" \
15   | sed -E 's;[0-9]{2}$;d&;; :0 s;([0-9])([0-9]{3}[dm]);\1m\2;; t0; y;dm;,.;'
16 }
17
18 IBAN_ASSIGN="$(
19   { pdi_load "${_DATA}"/vcard/*.vcf
20     printf 'BEGIN:LEDGERS\n'
21     cat "${_DATA}"/ledgers/????-??-??\ -\ ????-??-??\ -\ ????.tbl
22   } | "${_EXEC}"/ledgers/iban_assign.awk
23   printf '\n'
24 )"
25
26 if [ "${PATH_INFO%/iban_assign/}" != "${PATH_INFO}" ]; then
27   . "${_EXEC}/ledgers/iban_assign.sh"
28   exit 0
29 fi
30
31 { printf '
32   [form .upload action="%s/ledgers/csv_upload.sh" method="POST" enctype="multipart/form-data"
33     [label for=ledger_upload . %s:]
34     [input #ledger_upload type="file" name="csv" accept=".csv,text/csv"]
35     [input type=hidden name=session_id value="%s"]
36     [button type="submit" %s]
37   ]' \
38   "${_BASE}" "$(l10n "Postbank CSV")" "$SESSION_ID" "$(l10n Upload)"
39   printf '
40   [form .ledgers action="%s/ledgers/delete.sh" method=POST
41     [input type=hidden name=session_id value="%s"]
42     [h3 . %s]
43   ' "${_BASE}" "$SESSION_ID" "$(l10n Ledgers)"
44   for ledger in "$_DATA"/ledgers/????-??-??\ -\ ????-??-??\ -\ ????.tbl; do
45     ledger="${ledger##*/}"
46     [ "$ledger" = "????-??-?? - ????-??-?? - ????.tbl" ] && continue
47     printf '[p .ledger . %s [button type=submit name=delete value="%s" . %s]]' \
48            "$(HTML "${ledger% - ????.tbl}")" "$(HTML "$ledger")" "$(l10n delete)"
49   done
50   printf '  ]'
51   unassigned="$(printf %s\\n "$IBAN_ASSIGN" |grep -E '^guess|^unknown' |wc -l)"
52   cat <<-EOF
53         [div
54           [h1 . $(l10n IBAN Assignments)]
55           $(printf "$(l10n "%i IBANs are unassigned")" "$unassigned")
56           [a href="${_BASE}/ledgers/iban_assign/" . $(l10n Assign IBANs)]
57         ]
58         [form action="${_BASE}/ledgers/account.sh" method=POST
59           [select name=uid
60           $(printf %s\\n "$IBAN_ASSIGN" \
61             | sed -E '
62               /^sure    /!d;
63               s;^sure   [^\t]+;;;
64               s;([^\t]+)/([^\t]+);\1    \2\n;g;
65               s;\n$;;
66             ' \
67             | while read uid fn; do
68               uid="$(HTML "$uid")"
69               fn="$(UNSTRING "$fn" |HTML)"
70               printf '[option value="%s" . %s]' "$uid" "$fn"
71             done)
72           ]
73           [button type="submit" . $(l10n Account)]
74         ]
75         EOF
76 } | yield_page ledgers