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