Generate total balance for member.
This commit is contained in:
parent
d092275797
commit
76ff48329a
3 changed files with 22 additions and 7 deletions
|
@ -66,6 +66,7 @@
|
||||||
member-record-add-payment
|
member-record-add-payment
|
||||||
member-payments
|
member-payments
|
||||||
member-balance
|
member-balance
|
||||||
|
member-total-balance
|
||||||
|
|
||||||
member-record-tests!
|
member-record-tests!
|
||||||
)
|
)
|
||||||
|
@ -350,6 +351,15 @@
|
||||||
(define (member-balance mr)
|
(define (member-balance mr)
|
||||||
(dict-ref mr 'balance (make-dict)))
|
(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
|
||||||
|
|
|
@ -29,7 +29,6 @@
|
||||||
members-payments
|
members-payments
|
||||||
(
|
(
|
||||||
members-payments-process
|
members-payments-process
|
||||||
member-payments-total
|
|
||||||
)
|
)
|
||||||
|
|
||||||
(import scheme
|
(import scheme
|
||||||
|
@ -114,7 +113,7 @@
|
||||||
accounts)))
|
accounts)))
|
||||||
mb))
|
mb))
|
||||||
|
|
||||||
;; Adds all balances - payments are converted to CZK.
|
;; Adds all balances - payments are converted to CZK in member-payments-total
|
||||||
(define (member-add-balance mr)
|
(define (member-add-balance mr)
|
||||||
(let ((mr0 (dict-set mr
|
(let ((mr0 (dict-set mr
|
||||||
'balance
|
'balance
|
||||||
|
@ -129,7 +128,7 @@
|
||||||
(bank-transaction-date b)))))))
|
(bank-transaction-date b)))))))
|
||||||
|
|
||||||
|
|
||||||
;; Total amount paid
|
;; Total amount paid - calculated from payments
|
||||||
(define (member-payments-total mr)
|
(define (member-payments-total mr)
|
||||||
(foldl + 0 (map (lambda (tr)
|
(foldl + 0 (map (lambda (tr)
|
||||||
(let ((amount (bank-transaction-amount tr))
|
(let ((amount (bank-transaction-amount tr))
|
||||||
|
@ -140,4 +139,5 @@
|
||||||
(else 0))))
|
(else 0))))
|
||||||
(member-payments mr))))
|
(member-payments mr))))
|
||||||
|
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
|
@ -26,12 +26,13 @@
|
||||||
(declare (unit web-static))
|
(declare (unit web-static))
|
||||||
|
|
||||||
(module
|
(module
|
||||||
web-static-output
|
web-static
|
||||||
(
|
(
|
||||||
gen-web-static-member
|
gen-web-static-member
|
||||||
)
|
)
|
||||||
|
|
||||||
(import scheme
|
(import scheme
|
||||||
|
(chicken base)
|
||||||
(chicken format)
|
(chicken format)
|
||||||
member-record)
|
member-record)
|
||||||
|
|
||||||
|
@ -40,8 +41,12 @@
|
||||||
(define (gen-web-static-member mr)
|
(define (gen-web-static-member mr)
|
||||||
(let ((nick (member-nick mr))
|
(let ((nick (member-nick mr))
|
||||||
(id (member-id mr)))
|
(id (member-id mr)))
|
||||||
(let ((nf (open-output-file (sprintf "~A.id" nick))))
|
(with-output-to-file (sprintf "~A.id" nick)
|
||||||
(display id nf)
|
(lambda ()
|
||||||
(newline nf))))
|
(print id)))
|
||||||
|
(with-output-to-file (sprintf "~A.balance" nick)
|
||||||
|
(lambda ()
|
||||||
|
(print (member-total-balance mr))))
|
||||||
|
))
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue