From 15f35d0dea982c686d885264a3ca774b6b212f21 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Paul=20H=C3=A4nsch?= Date: Tue, 14 May 2024 19:50:24 +0200 Subject: [PATCH] transaction list on account page --- ledgers/account.sh | 60 ++++++++++++++++++++++++++++++++++++---------- style.css | 56 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 103 insertions(+), 13 deletions(-) diff --git a/ledgers/account.sh b/ledgers/account.sh index a92694f..d9d3f4b 100755 --- a/ledgers/account.sh +++ b/ledgers/account.sh @@ -1,11 +1,17 @@ #!/bin/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;,.;' +} + if [ "$REQUEST_METHOD" = POST ]; then uid="$(POST uid)" cfile="$(grep -lxF "UID;:${uid}" "${_DATA}/vcard/"*.vcf || grep -lxF "UID:${uid}" "${_DATA}/vcard/"*.vcf)" REDIRECT "${_BASE}/ledgers/account.sh?card=${cfile##*/}" fi +. "${_EXEC}/cgilite/storage.sh" . "${_EXEC}/pdiread.sh" . "${_EXEC}/cards/l10n.sh" . "${_EXEC}/cards/widgets.sh" @@ -16,6 +22,9 @@ if [ ! -f "$cardfile" ]; then REDIRECT "${_BASE}/ledgers/" fi +cledger="${cardfile##*/}" +cledger="${_DATA}/ledgers/vcf.${cledger%.vcf}.account" + { card="$(pdi_load "$cardfile")" cat <<-EOF [h1 $(l10n Payments)] @@ -36,19 +45,44 @@ fi $(card_item "$card" CATEGORIES) ] ] - [ul .transactions - $(cnt="$(pdi_count "$card" X-IBAN)" - while [ "$cnt" -gt 0 ]; do - pdi_value X-IBAN "$cnt" |RXLITERAL - cnt=$((cnt - 1)) - done \ - | while read -r iban; do - printf '[li . ' - grep -E "^[^\t]+ [^\t]+ ${iban} " |HTML - printf ']' - done - )] EOF - + printf '[table .transactions [thead + [tr [th .date . %s][th .orig . %s][th .reference . %s][th .amount . %s][th .balance . %s]]' \ + "$(l10n Date)" "$(l10n Originator)" "$(l10n "Reference Text")" "$(l10n Amount)" "$(l10n Balance)" + printf '][tbody' + cnt="$(pdi_count "$card" X-IBAN)" + while [ "$cnt" -gt 0 ]; do + pdi_value "$card" X-IBAN "$cnt" |RXLITERAL + cnt=$((cnt - 1)) + done \ + | { + while read -r iban; do + grep -hE "^[^\t]+ [^\t]+ ${iban} " "${_DATA}/ledgers/"*.tbl + done + if [ -f "$cledger" ]; then + : + fi + } \ + | sort -n -k2 \ + | { total=0 + while read -r date dtstamp iban accname subject amount; do + total=$((total + amount)) + printf '[tr [td .date . %s][td .orig [span . %s][span . %s]][td .reference . %s][td .amount . %s][td .balance . %s]]' \ + "$date" "$(HTML "$iban")" \ + "$(UNSTRING "$accname" |HTML)" "$(UNSTRING "$subject" |HTML)" \ + "$(credit "$amount")" "$(credit "$total")" + done + } + printf '[tr [th colspan=5 . %s]]' "$(l10n 'Manual Record')" + printf '[tr [td .date [input type=date placeholder="%s" name=tdate]] + [td .orig [input id=trec_once type=radio name="trec" value="once" selected] + [label for=trec_once . %s]
+ [input id=trec_month type=radio name="trec" value="month"] + [label for=trec_month . %s] + [input type=date name="trec_until" placeholder="%s"]] + [td .reference . [textarea placeholder="%s" name=treference]] + [td .amount colspan=2 [input type=number placeholder="%s" name=tamount value=0.00 step=.01]]' \ + "$(l10n Date)" "$(l10n once)" "$(l10n "monthly until")" "$(l10n until)" "$(l10n "Reference Text")" "$(l10n Amount)" + printf ']]]' } \ | yield_page ledgers diff --git a/style.css b/style.css index a8ebe90..c00829e 100644 --- a/style.css +++ b/style.css @@ -475,3 +475,59 @@ form.ledgers { margin: auto; display: block; } + +body.ledgers .transactions { + width: 98%; + width: calc(100% - 2em); + margin: auto; +} +body.ledgers .transactions thead { + position: sticky; + top: 0; + z-index: 1; +} +body.ledgers .transactions th { + text-align: left; + background-color: #FFF; +} +body.ledgers .transactions td { + vertical-align: top; + font-family: monospace; + font-size: 12pt; +} + +body.ledgers .transactions td:nth-child(2n) { + background-color: #DDD; +} +body.ledgers .transactions td:nth-child(2n + 1) { + background-color: #EEE; +} + +body.ledgers .transactions .date { + min-width: 8em; +} +body.ledgers .transactions .orig span { + display: block; +} +body.ledgers .transactions .amount, +body.ledgers .transactions .balance { + vertical-align: bottom; + min-width: 6em; + text-align: right; +} + +body.ledgers .transactions .reference textarea { + width: 100%; +} +body.ledgers .transactions .orig input[type=date], +body.ledgers .transactions .date input[type=date], +body.ledgers .transactions .amount input[type=number] { + display: block; + width: 100%; +} + +body.ledgers .transactions .orig input:not(:checked) + label + input[type=date] { + background-color: #DDD; + border-color: #888; + pointer-events: none; +} -- 2.39.2