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")
(ansi-string #:bgblue #:brightyellow #:bold "Fees")
(ansi-string #:bgblue #:brightyellow #:bold "Credit")
(ansi-string #:bgblue #:brightyellow #:bold "Payments")
(ansi-string #:bgblue #:brightyellow #:bold "Balance"))
(append
(map (map
(lambda (mr) (lambda (mr)
(let* ((balance (member-balance mr)) (let* ((balance (member-balance mr))
(fees (dict-ref balance 'fees)) (fees (dict-ref balance 'fees))
(credit (dict-ref balance 'credit)) (credit (dict-ref balance 'credit))
(payment (dict-ref balance 'payment))) (payment (dict-ref balance 'payment))
(total (- (+ credit payment) fees)))
(list (member-nick mr) (list (member-nick mr)
(sprintf "\t~A" fees) (sprintf "\t~A" fees)
(sprintf "\t~A" credit) (sprintf "\t~A" credit)
(sprintf "\t~A" payment) (sprintf "\t~A" payment)
(sprintf "\t~A" (- (+ credit payment) fees)) (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<?))) (sort (filter-members-by-predicate MB member-active?) member<?))
#:col-border #t #:row0-border #t))) (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)))
) )