]> git.plutz.net Git - confetti/blobdiff - ledgers/index.cgi
styling for iban assignment
[confetti] / ledgers / index.cgi
index e8852941f20f72615c33e2b4c0f0d4d40878ad24..dbf8ee892a2b3c99454ce4a8632bf93feb131a17 100755 (executable)
@@ -3,6 +3,11 @@
 . "$_EXEC/cgilite/storage.sh"
 . "$_EXEC/pdiread.sh"
 
+credit() {
+  printf '%03i\n' "$1" \
+  | sed -E 's;[0-9]{2}$;d&;; :0 s;([0-9])([0-9]{3}[dm]);\1m\2;; t0; y;dm;,.;'
+}
+
 { printf '
   [form .upload action="%s/ledgers/csv_upload.sh" method="POST" enctype="multipart/form-data"
     [label for=ledger_upload . %s:]
   done
   printf '  ]'
   printf '
-  [form .ledgers action="%s/ledgers/delete.sh" method=POST
+  [form .ibanassign action="%s/ledgers/iban_assign.sh" method=POST
     [input type=hidden name=session_id value="%s"]
     [h3 . %s]
   ' "${_BASE}" "$SESSION_ID" "$(l10n "IBAN Assignments")"
+  printf '[datalist id=lattendants .'
+  pdi_load "${_DATA}"/vcard/*.vcf |sed -n '/^FN\;:/!b; s;^FN\;:;;; p;' \
+  | while read name; do
+    printf '[option value="%s"]' "$(HTML "$name")"
+  done
+  printf ']'
+  l10n_attendant="$(l10n attendant)"
   { pdi_load "${_DATA}"/vcard/*.vcf
     cat "${_DATA}"/ledgers/????-??-??\ -\ ????-??-??\ -\ ????.tbl
   } | "${_EXEC}"/ledgers/iban_assign.awk \
   | while read -r state iban data; do
     printf '[fieldset .iban .%s [legend . %s ]' \
            "$state" "$iban"
-      if [ $state = sure ]; then
+    if   [ $state = sure ]; then
+      for card in $data; do
+        uid="${card%%/*}" name="$(UNSTRING "${card#*/}")"
+        printf '[span .card . %s]' "$(HTML "${name}")"
+      done
       :
     elif [ $state = guess ]; then
       record="$(UNSTRING "${data%%     *}")"
+      cards="${data#*  }"
+      date="${record%% *}"
       principal="${record#*    *       *       }" principal="${principal%%     *}"
       subject="${record#*      *       *       *       }" subject="${subject%% *}"
-      printf '[p .principal . %s][p .subject . %s]' \
-             "$(UNSTRING "$principal" |HTML)" "$(UNSTRING "$subject" |HTML)"
+      amount="${record#*       *       *       *       *       }" amount="${amount%%   *}"
+      printf '[p .principal . %s][p .date %s][p .amount %s][p .subject . %s]' \
+             "$(UNSTRING "$principal" |HTML)" "$date" "$(credit "$amount")" "$(UNSTRING "$subject" |HTML)"
+      n=0; for card in $cards; do
+        n=$((n+1)); uid="${card%%/*}" name="$(UNSTRING "${card#*/}")"
+        cat <<-EOF
+         [input type=checkbox id="check_${iban}_$n" name="check_${iban}_$n" value=true checked=checked]
+         [input .card name="fn_${iban}_$n" value="$(HTML "$name")" disabled=disabled]
+         [label .del for="check_${iban}_$n" . -]
+       EOF
+      done
+      for m in 1 2 3 4 5 6 7 8; do
+        cat <<-EOF
+         [input type=checkbox id="check_${iban}_$((n+m))" name="check_${iban}_$((n+m))" value=false]
+         [input .card name="fn_${iban}_$((n+m))" value="" placeholder="${l10n_attendant}" list="lattendants"]
+         [label .add for="check_${iban}_$((n+m))" . +]
+       EOF
+      done
     elif [ $state = unknown ]; then
+      date="${data%%   *}"
       principal="${data#*      *       *       }" principal="${principal%%     *}"
       subject="${data#*        *       *       *       }" subject="${subject%% *}"
-      printf '[p .principal . %s][p .subject . %s]' \
-             "$(UNSTRING "$principal" |HTML)" "$(UNSTRING "$subject" |HTML)"
+      amount="${data#* *       *       *       *       }" amount="${amount%%   *}"
+      printf '[p .principal . %s][p .date %s][p .amount %s][p .subject . %s]' \
+             "$(UNSTRING "$principal" |HTML)" "$date" "$(credit "$amount")" "$(UNSTRING "$subject" |HTML)"
+      printf '[input name="check_" type=hidden][input type=hidden][label .del]'
+      n=0; for m in 1 2 3 4 5 6 7 8; do
+        cat <<-EOF
+         [input type=checkbox id="check_${iban}_$((n+m))" name="check_${iban}_$((n+m))" value=false]
+         [input .card name="fn_${iban}_$((n+m))" value="" placeholder="${l10n_attendant}" list="lattendants"]
+         [label .add for="check_${iban}_$((n+m))" . +]
+       EOF
+      done
     fi
   printf ']'
   done