Basic payments pairing.
This commit is contained in:
parent
d8b3f57868
commit
a1f059df8b
2 changed files with 49 additions and 7 deletions
12
bbstool.scm
12
bbstool.scm
|
@ -43,7 +43,8 @@ CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
member-parser
|
||||
member-fees
|
||||
members-dir
|
||||
csv-simple)
|
||||
csv-simple
|
||||
members-payments)
|
||||
|
||||
;; Print banner
|
||||
(print "bbstool 0.6 (c) 2023 Brmlab, z.s.")
|
||||
|
@ -51,6 +52,7 @@ CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
|
||||
;; Command-line options and configurable parameters
|
||||
(define *members-directory* (make-parameter "members"))
|
||||
(define *apikeys-file* (make-parameter "apikey.ntlm"))
|
||||
(define -member-id- (make-parameter #f))
|
||||
(define -member-nick- (make-parameter #f))
|
||||
(define -action- (make-parameter #f))
|
||||
|
@ -111,7 +113,9 @@ CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
(newline))
|
||||
|
||||
;; Load the members database (required for everything anyway)
|
||||
(define MB (load-members (*members-directory*) #t))
|
||||
(define MB (members-payments-process
|
||||
(load-members (*members-directory*) #t)
|
||||
(*apikeys-file*)))
|
||||
|
||||
;; If a member is specified by either id or nick, get its record
|
||||
(define mr
|
||||
|
@ -140,7 +144,9 @@ CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
(let ()
|
||||
(print-member-table mr)
|
||||
(print-member-calendar-table mr)
|
||||
(print "Total fees: " (member-fees-total mr)))
|
||||
(print "Total fees: " (member-fees-total mr))
|
||||
(print mr)
|
||||
)
|
||||
(print-members-base-table MB))
|
||||
(newline))
|
||||
((print-stats)
|
||||
|
|
|
@ -32,17 +32,53 @@
|
|||
)
|
||||
|
||||
(import scheme
|
||||
bank-account)
|
||||
(chicken base)
|
||||
(chicken string)
|
||||
(chicken io)
|
||||
bank-account
|
||||
member-record
|
||||
members-base
|
||||
bank-fio)
|
||||
|
||||
;; Merges bank account statement into members payment keys. The
|
||||
;; payment key will be a list of transactions.
|
||||
(define (members-payments-process mb ba)
|
||||
(define (members-payments-process-bank mb ba)
|
||||
(let loop ((mb mb)
|
||||
(transactions (bank-account-transactions ba)))
|
||||
(if (null? transactions)
|
||||
mb
|
||||
(let* ((transaction (car transactions)))
|
||||
(loop mb
|
||||
(let* ((transaction (car transactions))
|
||||
(varsym-id (string->number (bank-transaction-varsym transaction))))
|
||||
(loop (members-base-update mb
|
||||
(lambda (mr)
|
||||
(eq? (member-id mr)
|
||||
varsym-id))
|
||||
(lambda (mr)
|
||||
(member-record-add-payment mr transaction)))
|
||||
(cdr transactions))))))
|
||||
|
||||
;; Reads the payments
|
||||
(define (load-accounts-list apikeys)
|
||||
(map (compose car string-split)
|
||||
(read-lines
|
||||
(open-input-file apikeys))))
|
||||
|
||||
;; Loads all accounts - it expects .csv files in the current
|
||||
;; directory.
|
||||
(define (load-accounts accounts-list)
|
||||
(map (lambda (acc)
|
||||
(bank-fio-parse (string-append acc ".csv")))
|
||||
accounts-list))
|
||||
|
||||
;; If apikeys is not #f, loads the account numbers, loads bank
|
||||
;; accounts and processes transactions.
|
||||
(define (members-payments-process mb apikeys-file)
|
||||
(if apikeys-file
|
||||
(let* ((accounts (load-accounts
|
||||
(load-accounts-list apikeys-file))))
|
||||
(foldl members-payments-process-bank
|
||||
mb
|
||||
accounts))
|
||||
mb))
|
||||
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue