X-Git-Url: https://git.plutz.net/?a=blobdiff_plain;f=ledgers%2Faccount.sh;h=d9d3f4bd08771b606c2c587f5300d43ccace7ffc;hb=15f35d0dea982c686d885264a3ca774b6b212f21;hp=a92694ffee0cd9801a79001b413f5851a6d6ed00;hpb=d55c2e8d7ae537ef9f6365ff620a08d3fa7aa79c;p=confetti 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