]> git.plutz.net Git - confetti/blob - ledgers/index.cgi
attendent list in transaction assignment
[confetti] / ledgers / index.cgi
1 #!/bin/sh
2
3 . "$_EXEC/cgilite/storage.sh"
4 . "$_EXEC/pdiread.sh"
5
6 credit() {
7   printf '%03i\n' "$1" \
8   | sed -E 's;[0-9]{2}$;d&;; :0 s;([0-9])([0-9]{3}[dm]);\1m\2;; t0; y;dm;,.;'
9 }
10
11 { printf '
12   [form .upload action="%s/ledgers/csv_upload.sh" method="POST" enctype="multipart/form-data"
13     [label for=ledger_upload . %s:]
14     [input #ledger_upload type="file" name="csv" accept=".csv,text/csv"]
15     [input type=hidden name=session_id value="%s"]
16     [button type="submit" %s]
17   ]' \
18   "${_BASE}" "$(l10n "Postbank CSV")" "$SESSION_ID" "$(l10n Upload)"
19   printf '
20   [form .ledgers action="%s/ledgers/delete.sh" method=POST
21     [input type=hidden name=session_id value="%s"]
22     [h3 . %s]
23   ' "${_BASE}" "$SESSION_ID" "$(l10n Ledgers)"
24   for ledger in "$_DATA"/ledgers/????-??-??\ -\ ????-??-??\ -\ ????.tbl; do
25     ledger="${ledger##*/}"
26     [ "$ledger" = "????-??-?? - ????-??-?? - ????.tbl" ] && continue
27     printf '[p .ledger . %s [button type=submit name=delete value="%s" . %s]]' \
28            "$(HTML "${ledger% - ????.tbl}")" "$(HTML "$ledger")" "$(l10n delete)"
29   done
30   printf '  ]'
31   printf '
32   [form .ibanassign action="%s/ledgers/iban_assign.sh" method=POST
33     [input type=hidden name=session_id value="%s"]
34     [h3 . %s]
35   ' "${_BASE}" "$SESSION_ID" "$(l10n "IBAN Assignments")"
36   { pdi_load "${_DATA}"/vcard/*.vcf
37     cat "${_DATA}"/ledgers/????-??-??\ -\ ????-??-??\ -\ ????.tbl
38   } | "${_EXEC}"/ledgers/iban_assign.awk \
39   | while read -r state iban data; do
40     printf '[fieldset .iban .%s [legend . %s ]' \
41            "$state" "$iban"
42       if [ $state = sure ]; then
43       :
44     elif [ $state = guess ]; then
45       record="$(UNSTRING "${data%%      *}")"
46       cards="${data#*   }"
47       principal="${record#*     *       *       }" principal="${principal%%     *}"
48       subject="${record#*       *       *       *       }" subject="${subject%% *}"
49       amount="${record#*        *       *       *       *       }" amount="${amount%%   *}"
50       printf '[p .principal . %s][p .amount %s][p .subject . %s]' \
51              "$(UNSTRING "$principal" |HTML)" "$(credit "$amount")" "$(UNSTRING "$subject" |HTML)"
52       printf '[h4 . %s]' "$(l10n Guesses)"
53       for card in $cards; do
54         uid="${card%%/*}" name="$(UNSTRING "${card#*/}")"
55         printf '[input .card key="cardfn" value="%s" placeholder="%s"]' "$(HTML "${name}")" "$(l10n attendent)"
56       done
57     elif [ $state = unknown ]; then
58       principal="${data#*       *       *       }" principal="${principal%%     *}"
59       subject="${data#* *       *       *       }" subject="${subject%% *}"
60       amount="${data#*  *       *       *       *       }" amount="${amount%%   *}"
61       printf '[p .principal . %s][p .amount %s][p .subject . %s]' \
62              "$(UNSTRING "$principal" |HTML)" "$(credit "$amount")" "$(UNSTRING "$subject" |HTML)"
63     fi
64   printf ']'
65   done
66   printf '  ]'
67 } | yield_page ledgers