Start fees table rework using new primitives.

This commit is contained in:
Dominik Pantůček 2023-04-03 12:01:14 +02:00
parent ea9c76d2fc
commit f2e47b9ad3
5 changed files with 101 additions and 88 deletions

View file

@ -174,7 +174,7 @@ MEMBERS-PRINT-SOURCES=members-print.scm dictionary.import.scm \
table.import.scm listing.import.scm ansi.import.scm \ table.import.scm listing.import.scm ansi.import.scm \
period.import.scm primes.import.scm members-base.import.scm \ period.import.scm primes.import.scm members-base.import.scm \
configuration.import.scm bank-account.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.o: members-print.import.scm
members-print.import.scm: $(MEMBERS-PRINT-SOURCES) 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) members-payments.import.scm: $(MEMBERS-PAYMENTS-SOURCES)
WEB-STATIC-SOURCES=web-static.scm member-record.import.scm \ 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.o: web-static.import.scm
web-static.import.scm: $(WEB-STATIC-SOURCES) web-static.import.scm: $(WEB-STATIC-SOURCES)

View file

@ -67,8 +67,6 @@
member-record-add-payment member-record-add-payment
member-payments member-payments
member-balance
member-total-balance
member-record-tests! member-record-tests!
) )
@ -357,19 +355,6 @@
(define (member-payments mr) (define (member-payments mr)
(dict-ref mr 'payments '())) (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 ;; Self-tests
(define (member-record-tests!) (define (member-record-tests!)
(run-tests (run-tests

View file

@ -30,6 +30,8 @@
( (
member-payments-total member-payments-total
members-payments-process members-payments-process
member-balance
member-total-balance
) )
(import scheme (import scheme
@ -110,26 +112,35 @@
(let* ((accounts (load-accounts (let* ((accounts (load-accounts
(load-accounts-list apikeys-file) (load-accounts-list apikeys-file)
dir))) dir)))
(map member-add-balance (map member-sort-payments
(foldl members-payments-process-bank (foldl members-payments-process-bank
mb mb
accounts))) accounts)))
mb)) mb))
;; Adds all balances - payments are converted to CZK in member-payments-total ;; Adds all balances - payments are converted to CZK in member-payments-total
(define (member-add-balance mr) (define (member-sort-payments mr)
(let ((mr0 (dict-set mr (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 'payments
(sort (dict-ref mr0 'payments '()) (sort (dict-ref mr 'payments '())
(lambda (a b) (lambda (a b)
(string<? (bank-transaction-date a) (string<? (bank-transaction-date a)
(bank-transaction-date b))))))) (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 ;; Total amount paid - calculated from payments
(define (member-payments-total mr) (define (member-payments-total mr)

View file

@ -57,7 +57,8 @@
members-base members-base
configuration configuration
bank-account bank-account
member-fees) member-fees
members-payments)
;; Prints human-readable information ;; Prints human-readable information
(define (print-member-info mr) (define (print-member-info mr)
@ -334,6 +335,20 @@
;; Prints summary table of all fees and credits for all members ;; Prints summary table of all fees and credits for all members
(define (print-members-fees-table MB) (define (print-members-fees-table MB)
(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 (print
(table->string (table->string
(cons (cons
@ -372,8 +387,7 @@
a:default) a:default)
))) )))
(sort MB member<?)) (sort MB member<?))
(let* ((balances (map member-balance MB)) (let* ((fees (foldl + 0 (map (lambda (b) (dict-ref b 'fees)) balances)))
(fees (foldl + 0 (map (lambda (b) (dict-ref b 'fees)) balances)))
(credit (foldl + 0 (map (lambda (b) (dict-ref b 'credit)) balances))) (credit (foldl + 0 (map (lambda (b) (dict-ref b 'credit)) balances)))
(payment (foldl + 0 (map (lambda (b) (dict-ref b 'payment)) balances))) (payment (foldl + 0 (map (lambda (b) (dict-ref b 'payment)) balances)))
(total (- (+ credit payment) fees))) (total (- (+ credit payment) fees)))
@ -391,5 +405,6 @@
))))) )))))
#:col-border #t #:row0-border #t #:ansi #t)) #:col-border #t #:row0-border #t #:ansi #t))
) )
)
) )

View file

@ -41,7 +41,8 @@
(chicken file) (chicken file)
member-record member-record
utils utils
configuration) configuration
members-payments)
;; Generate all the files in specified (default current) directory. ;; Generate all the files in specified (default current) directory.
(define (gen-web-static-member mr . dirs) (define (gen-web-static-member mr . dirs)