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
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue