Start fees table rework using new primitives.
This commit is contained in:
parent
ea9c76d2fc
commit
f2e47b9ad3
5 changed files with 101 additions and 88 deletions
|
@ -174,7 +174,7 @@ MEMBERS-PRINT-SOURCES=members-print.scm dictionary.import.scm \
|
|||
table.import.scm listing.import.scm ansi.import.scm \
|
||||
period.import.scm primes.import.scm members-base.import.scm \
|
||||
configuration.import.scm bank-account.import.scm \
|
||||
member-fees.import.scm
|
||||
member-fees.import.scm members-payments.import.scm
|
||||
|
||||
members-print.o: members-print.import.scm
|
||||
members-print.import.scm: $(MEMBERS-PRINT-SOURCES)
|
||||
|
@ -218,7 +218,8 @@ members-payments.o: members-payments.import.scm
|
|||
members-payments.import.scm: $(MEMBERS-PAYMENTS-SOURCES)
|
||||
|
||||
WEB-STATIC-SOURCES=web-static.scm member-record.import.scm \
|
||||
utils.import.scm configuration.import.scm
|
||||
utils.import.scm configuration.import.scm \
|
||||
members-payments.import.scm
|
||||
|
||||
web-static.o: web-static.import.scm
|
||||
web-static.import.scm: $(WEB-STATIC-SOURCES)
|
||||
|
|
|
@ -67,8 +67,6 @@
|
|||
|
||||
member-record-add-payment
|
||||
member-payments
|
||||
member-balance
|
||||
member-total-balance
|
||||
|
||||
member-record-tests!
|
||||
)
|
||||
|
@ -357,19 +355,6 @@
|
|||
(define (member-payments mr)
|
||||
(dict-ref mr 'payments '()))
|
||||
|
||||
;; Balances totals
|
||||
(define (member-balance mr)
|
||||
(dict-ref mr 'balance (make-dict)))
|
||||
|
||||
;; Computes total member balance from credit, fees and payment
|
||||
;; information
|
||||
(define (member-total-balance mr)
|
||||
(let* ((bal (member-balance mr))
|
||||
(fees (dict-ref bal 'fees 0))
|
||||
(credit (dict-ref bal 'credit 0))
|
||||
(payment (dict-ref bal 'payment)))
|
||||
(- (+ credit payment) fees)))
|
||||
|
||||
;; Self-tests
|
||||
(define (member-record-tests!)
|
||||
(run-tests
|
||||
|
|
|
@ -30,6 +30,8 @@
|
|||
(
|
||||
member-payments-total
|
||||
members-payments-process
|
||||
member-balance
|
||||
member-total-balance
|
||||
)
|
||||
|
||||
(import scheme
|
||||
|
@ -110,26 +112,35 @@
|
|||
(let* ((accounts (load-accounts
|
||||
(load-accounts-list apikeys-file)
|
||||
dir)))
|
||||
(map member-add-balance
|
||||
(map member-sort-payments
|
||||
(foldl members-payments-process-bank
|
||||
mb
|
||||
accounts)))
|
||||
mb))
|
||||
|
||||
;; Adds all balances - payments are converted to CZK in member-payments-total
|
||||
(define (member-add-balance mr)
|
||||
(let ((mr0 (dict-set mr
|
||||
'balance
|
||||
(make-dict `((fees . ,(member-fees-total mr))
|
||||
(credit . ,(member-credit-total mr))
|
||||
(payment . ,(member-payments-total mr)))))))
|
||||
(dict-set mr0
|
||||
'payments
|
||||
(sort (dict-ref mr0 'payments '())
|
||||
(lambda (a b)
|
||||
(string<? (bank-transaction-date a)
|
||||
(bank-transaction-date b)))))))
|
||||
(define (member-sort-payments mr)
|
||||
(dict-set mr
|
||||
'payments
|
||||
(sort (dict-ref mr 'payments '())
|
||||
(lambda (a b)
|
||||
(string<? (bank-transaction-date a)
|
||||
(bank-transaction-date b))))))
|
||||
|
||||
;; Balances totals
|
||||
(define (member-balance mr)
|
||||
(make-dict `((fees . ,(member-fees-total mr))
|
||||
(credit . ,(member-credit-total mr))
|
||||
(payment . ,(member-payments-total mr)))))
|
||||
|
||||
;; Computes total member balance from credit, fees and payment
|
||||
;; information
|
||||
(define (member-total-balance mr)
|
||||
(let* ((bal (member-balance mr))
|
||||
(fees (dict-ref bal 'fees 0))
|
||||
(credit (dict-ref bal 'credit 0))
|
||||
(payment (dict-ref bal 'payment)))
|
||||
(- (+ credit payment) fees)))
|
||||
|
||||
;; Total amount paid - calculated from payments
|
||||
(define (member-payments-total mr)
|
||||
|
|
|
@ -57,7 +57,8 @@
|
|||
members-base
|
||||
configuration
|
||||
bank-account
|
||||
member-fees)
|
||||
member-fees
|
||||
members-payments)
|
||||
|
||||
;; Prints human-readable information
|
||||
(define (print-member-info mr)
|
||||
|
@ -334,62 +335,76 @@
|
|||
|
||||
;; Prints summary table of all fees and credits for all members
|
||||
(define (print-members-fees-table MB)
|
||||
(print
|
||||
(table->string
|
||||
(cons
|
||||
(list (ansi-string #:bgblue #:brightyellow #:bold "Member")
|
||||
(ansi-string #:bgblue #:brightyellow #:bold "Status")
|
||||
(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
|
||||
(lambda (mr)
|
||||
(let* ((balance (member-balance mr))
|
||||
(fees (dict-ref balance 'fees))
|
||||
(credit (dict-ref balance 'credit))
|
||||
(payment (dict-ref balance 'payment))
|
||||
(total (- (+ credit payment) fees)))
|
||||
(list (member-nick mr)
|
||||
(if (member-suspended? mr)
|
||||
"suspended"
|
||||
(if (member-student? mr)
|
||||
"student"
|
||||
(if (member-destroyed? mr)
|
||||
"destroyed"
|
||||
"active")))
|
||||
(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 MB 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))
|
||||
(let ((balances (map member-balance MB))
|
||||
(members ;; Pass 1
|
||||
(map
|
||||
(lambda (mr)
|
||||
(list (member-nick mr)
|
||||
(if (member-suspended? mr)
|
||||
"suspended"
|
||||
(if (member-student? mr)
|
||||
"student"
|
||||
(if (member-destroyed? mr)
|
||||
"destroyed"
|
||||
"active")))
|
||||
;; TODO: move let* below here and add fees, credit, payment and total
|
||||
)))))
|
||||
(print
|
||||
(table->string
|
||||
(cons
|
||||
(list (ansi-string #:bgblue #:brightyellow #:bold "Member")
|
||||
(ansi-string #:bgblue #:brightyellow #:bold "Status")
|
||||
(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
|
||||
(lambda (mr)
|
||||
(let* ((balance (member-balance mr))
|
||||
(fees (dict-ref balance 'fees))
|
||||
(credit (dict-ref balance 'credit))
|
||||
(payment (dict-ref balance 'payment))
|
||||
(total (- (+ credit payment) fees)))
|
||||
(list (member-nick mr)
|
||||
(if (member-suspended? mr)
|
||||
"suspended"
|
||||
(if (member-student? mr)
|
||||
"student"
|
||||
(if (member-destroyed? mr)
|
||||
"destroyed"
|
||||
"active")))
|
||||
(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 MB member<?))
|
||||
(let* ((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))
|
||||
)
|
||||
)
|
||||
|
||||
)
|
||||
|
|
|
@ -41,7 +41,8 @@
|
|||
(chicken file)
|
||||
member-record
|
||||
utils
|
||||
configuration)
|
||||
configuration
|
||||
members-payments)
|
||||
|
||||
;; Generate all the files in specified (default current) directory.
|
||||
(define (gen-web-static-member mr . dirs)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue