]> git.plutz.net Git - confetti/blob - ledgers/iban_assign.sh
styles and translations ledgers
[confetti] / ledgers / iban_assign.sh
1 #!/bin/sh
2
3 credit() {
4   printf '%03i\n' "$1" \
5   | sed -E 's;[0-9]{2}$;d&;; :0 s;([0-9])([0-9]{3}[dm]);\1m\2;; t0; y;dm;,.;'
6 }
7
8 { printf '
9   [h1 . %s]
10   [form .ibanassign action="%s/ledgers/set_iban.sh" method=POST
11     [input type=hidden name=session_id value="%s"]
12   ' "$(l10n "IBAN Assignments")" "${_BASE}" "$SESSION_ID"
13   printf '[datalist id=lattendants .'
14   pdi_load "${_DATA}"/vcard/*.vcf |sed -n '/^FN\;:/!b; s;^FN\;:;;; p;' \
15   | while read name; do
16     printf '[option value="%s"]' "$(HTML "$name")"
17   done
18   printf ']'
19   l10n_attendant="$(l10n attendant)"
20   printf %s\\n "$IBAN_ASSIGN" \
21   | while read -r state iban data; do
22     iban="$(UNSTRING "$iban")"
23     [ ! "$iban" ] && iban="??????????"
24     printf '[input type=checkbox id="use_%s" name="use_%s" value=true]' "$iban" "$iban"
25     printf '[fieldset .iban .%s [legend . %s ]' \
26            "$state" "$iban"
27     if   [ $state = sure ]; then
28       for card in $data; do
29         uid="${card%%/*}" name="$(UNSTRING "${card#*/}")"
30         printf '[span .card . %s]' "$(HTML "${name}")"
31       done
32       :
33     elif [ $state = guess ]; then
34       record="$(UNSTRING "${data%%      *}")"
35       cards="${data#*   }"
36       date="${record%%  *}"
37       principal="${record#*     *       *       }" principal="${principal%%     *}"
38       subject="${record#*       *       *       *       }" subject="${subject%% *}"
39       amount="${record#*        *       *       *       *       }" amount="${amount%%   *}"
40       printf '[p .principal . %s][p .date %s][p .amount %s][p .subject . %s]' \
41              "$(UNSTRING "$principal" |HTML)" "$date" "$(credit "$amount")" "$(UNSTRING "$subject" |HTML)"
42       n=0; for card in $cards; do
43         n=$((n+1)); uid="${card%%/*}" name="$(UNSTRING "${card#*/}")"
44         cat <<-EOF
45           [input type=checkbox id="check_${iban}_$n" name="check_${iban}_$n" value=true checked=checked]
46           [input .card name="fn_${iban}_$n" value="$(HTML "$name")" .disabled tabindex="-1"]
47           [label .del for="check_${iban}_$n" . -]
48         EOF
49       done
50       for m in 1 2 3 4 5 6 7 8; do
51         cat <<-EOF
52           [input type=checkbox id="check_${iban}_$((n+m))" name="check_${iban}_$((n+m))" value=true]
53           [input .card name="fn_${iban}_$((n+m))" value="" placeholder="${l10n_attendant}" list="lattendants"]
54           [label .add for="check_${iban}_$((n+m))" . +]
55         EOF
56       done
57       printf '[label .button for="use_%s" . %s]' "$iban" "$(l10n Accept Suggestions)"
58       printf '[label .button for="use_%s" . %s]' "$iban" "$(l10n Ignore Suggestions)"
59     elif [ $state = unknown ]; then
60       date="${data%%    *}"
61       principal="${data#*       *       *       }" principal="${principal%%     *}"
62       subject="${data#* *       *       *       }" subject="${subject%% *}"
63       amount="${data#*  *       *       *       *       }" amount="${amount%%   *}"
64       printf '[p .principal . %s][p .date %s][p .amount %s][p .subject . %s]' \
65              "$(UNSTRING "$principal" |HTML)" "$date" "$(credit "$amount")" "$(UNSTRING "$subject" |HTML)"
66       printf '[input name="check_" type=hidden][input type=hidden][label .del]'
67       n=0; for m in 1 2 3 4 5 6 7 8; do
68         cat <<-EOF
69           [input type=checkbox id="check_${iban}_$((n+m))" name="check_${iban}_$((n+m))" value=false]
70           [input .card name="fn_${iban}_$((n+m))" value="" placeholder="${l10n_attendant}" list="lattendants"]
71           [label .add for="check_${iban}_$((n+m))" . +]
72         EOF
73       done
74       printf '[label .button for="use_%s" . %s]' "$iban" "$(l10n Accept Suggestions)"
75       printf '[label .button for="use_%s" . %s]' "$iban" "$(l10n Ignore Suggestions)"
76     fi
77   printf ']'
78   done
79   printf '[button type=submit . %s]' "$(l10n Submit Changes)"
80   printf '  ]'
81 } | yield_page ledgers