Improve fees table display.

This commit is contained in:
Dominik Pantůček 2023-03-30 22:02:33 +02:00
parent e1b673a519
commit cbd5e89f6e

View file

@ -326,20 +326,49 @@
(print (print
(table->string (table->string
(cons (cons
(list "Member" "Fees" "Credit" "Payments" "Balance") (list (ansi-string #:bgblue #:brightyellow #:bold "Member")
(map (ansi-string #:bgblue #:brightyellow #:bold "Fees")
(lambda (mr) (ansi-string #:bgblue #:brightyellow #:bold "Credit")
(let* ((balance (member-balance mr)) (ansi-string #:bgblue #:brightyellow #:bold "Payments")
(fees (dict-ref balance 'fees)) (ansi-string #:bgblue #:brightyellow #:bold "Balance"))
(credit (dict-ref balance 'credit)) (append
(payment (dict-ref balance 'payment))) (map
(list (member-nick mr) (lambda (mr)
(sprintf "\t~A" fees) (let* ((balance (member-balance mr))
(sprintf "\t~A" credit) (fees (dict-ref balance 'fees))
(sprintf "\t~A" payment) (credit (dict-ref balance 'credit))
(sprintf "\t~A" (- (+ credit payment) fees)) (payment (dict-ref balance 'payment))
))) (total (- (+ credit payment) fees)))
(sort (filter-members-by-predicate MB member-active?) member<?))) (list (member-nick mr)
#:col-border #t #:row0-border #t))) (sprintf "\t~A" fees)
(sprintf "\t~A" credit)
(sprintf "\t~A" payment)
(sprintf "\t~A~A~A"
(if (< total -500)
a:error
(if (< total 0)
a:warning
a:success))
(exact->inexact total)
a:default)
)))
(sort (filter-members-by-predicate MB member-active?) member<?))
(let* ((balances (map member-balance MB))
(fees (foldl + 0 (map (lambda (b) (dict-ref b 'fees)) balances)))
(credit (foldl + 0 (map (lambda (b) (dict-ref b 'credit)) balances)))
(payment (foldl + 0 (map (lambda (b) (dict-ref b 'payment)) balances)))
(total (- (+ credit payment) fees)))
(list (list (ansi-string #:bold "Total")
(ansi-string "\t" #:bold (sprintf "~A" fees))
(ansi-string "\t" #:bold (sprintf "~A" credit))
(ansi-string "\t" #:bold (sprintf "~A" payment))
(ansi-string "\t" #:bold
(sprintf "~A~A"
(if (< total 0)
a:error
a:success)
total))
)))))
#:col-border #t #:row0-border #t #:ansi #t)))
) )