]> git.plutz.net Git - confetti/blob - ledgers/index.cgi
simplified pipeline protocol
[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   printf '[datalist id=lattendants .'
37   pdi_load "${_DATA}"/vcard/*.vcf |sed -n '/^FN\;:/!b; s;^FN\;:;;; p;' \
38   | while read name; do
39     printf '[option value="%s"]' "$(HTML "$name")"
40   done
41   printf ']'
42   l10n_attendant="$(l10n attendant)"
43   { pdi_load "${_DATA}"/vcard/*.vcf
44     printf 'BEGIN:LEDGERS\n'
45     cat "${_DATA}"/ledgers/????-??-??\ -\ ????-??-??\ -\ ????.tbl
46   } | "${_EXEC}"/ledgers/iban_assign.awk \
47   | while read -r state iban data; do
48     printf '[fieldset .iban .%s [legend . %s ]' \
49            "$state" "$iban"
50     if   [ $state = sure ]; then
51       for card in $data; do
52         uid="${card%%/*}" name="$(UNSTRING "${card#*/}")"
53         printf '[span .card . %s]' "$(HTML "${name}")"
54       done
55       :
56     elif [ $state = guess ]; then
57       record="$(UNSTRING "${data%%      *}")"
58       cards="${data#*   }"
59       date="${record%%  *}"
60       principal="${record#*     *       *       }" principal="${principal%%     *}"
61       subject="${record#*       *       *       *       }" subject="${subject%% *}"
62       amount="${record#*        *       *       *       *       }" amount="${amount%%   *}"
63       printf '[p .principal . %s][p .date %s][p .amount %s][p .subject . %s]' \
64              "$(UNSTRING "$principal" |HTML)" "$date" "$(credit "$amount")" "$(UNSTRING "$subject" |HTML)"
65       printf '[input type=checkbox id="use_%s" name="use_%s" value=true]' "$iban" "$iban"
66       n=0; for card in $cards; do
67         n=$((n+1)); uid="${card%%/*}" name="$(UNSTRING "${card#*/}")"
68         cat <<-EOF
69           [input type=checkbox id="check_${iban}_$n" name="check_${iban}_$n" value=true checked=checked]
70           [input .card name="fn_${iban}_$n" value="$(HTML "$name")" .disabled tabindex="-1"]
71           [label .del for="check_${iban}_$n" . -]
72         EOF
73       done
74       for m in 1 2 3 4 5 6 7 8; do
75         cat <<-EOF
76           [input type=checkbox id="check_${iban}_$((n+m))" name="check_${iban}_$((n+m))" value=true]
77           [input .card name="fn_${iban}_$((n+m))" value="" placeholder="${l10n_attendant}" list="lattendants"]
78           [label .add for="check_${iban}_$((n+m))" . +]
79         EOF
80       done
81       printf '[label for="use_%s" . %s]' "$iban" "$(l10n Accept Suggestions)"
82       printf '[label for="use_%s" . %s]' "$iban" "$(l10n Ignore Suggestions)"
83     elif [ $state = unknown ]; then
84       date="${data%%    *}"
85       principal="${data#*       *       *       }" principal="${principal%%     *}"
86       subject="${data#* *       *       *       }" subject="${subject%% *}"
87       amount="${data#*  *       *       *       *       }" amount="${amount%%   *}"
88       printf '[p .principal . %s][p .date %s][p .amount %s][p .subject . %s]' \
89              "$(UNSTRING "$principal" |HTML)" "$date" "$(credit "$amount")" "$(UNSTRING "$subject" |HTML)"
90       printf '[input name="check_" type=hidden][input type=hidden][label .del]'
91       n=0; for m in 1 2 3 4 5 6 7 8; do
92         cat <<-EOF
93           [input type=checkbox id="check_${iban}_$((n+m))" name="check_${iban}_$((n+m))" value=false]
94           [input .card name="fn_${iban}_$((n+m))" value="" placeholder="${l10n_attendant}" list="lattendants"]
95           [label .add for="check_${iban}_$((n+m))" . +]
96         EOF
97       done
98     fi
99   printf ']'
100   done
101   printf '[button type=submit . %s]' "$(l10n Submit Changes)"
102   printf '  ]'
103 } | yield_page ledgers