Handle all bank loading gracefully.
This commit is contained in:
parent
cc4cfccae1
commit
e25a75ab27
5 changed files with 51 additions and 29 deletions
|
@ -213,7 +213,7 @@ bank-fio.import.scm: $(BANK-FIO-SOURCES)
|
|||
|
||||
MEMBERS-PAYMENTS-SOURCES=members-payments.scm bank-account.import.scm \
|
||||
dictionary.import.scm member-fees.import.scm \
|
||||
period.import.scm configuration.import.scm
|
||||
period.import.scm configuration.import.scm utils.import.scm
|
||||
|
||||
members-payments.o: members-payments.import.scm
|
||||
members-payments.import.scm: $(MEMBERS-PAYMENTS-SOURCES)
|
||||
|
|
|
@ -61,17 +61,20 @@
|
|||
|
||||
;; Loads Fio bank accound statement.
|
||||
(define (bank-fio-parse fn)
|
||||
(with-progress%
|
||||
#t fn
|
||||
(let* ((csv (csv-parse fn))
|
||||
(head+body (csv-split-header csv))
|
||||
(head (car head+body))
|
||||
(body (cadr head+body))
|
||||
(numrow (assoc "accountId" head))
|
||||
(num (if numrow (cadr numrow) "ERROR"))
|
||||
(bankrow (assoc "bankId" head))
|
||||
(bank (if bankrow (cadr bankrow) "ERROR")))
|
||||
(make-bank-account num bank
|
||||
(map make-fio-transaction body)))))
|
||||
(let ((csv (with-progress% #t fn (csv-parse fn))))
|
||||
(if csv
|
||||
(let* ((head+body (csv-split-header csv))
|
||||
(head (car head+body))
|
||||
(body (cadr head+body))
|
||||
(numrow (assoc "accountId" head))
|
||||
(num (if numrow (cadr numrow) "ERROR"))
|
||||
(bankrow (assoc "bankId" head))
|
||||
(bank (if bankrow (cadr bankrow) "ERROR")))
|
||||
(make-bank-account num bank
|
||||
(map make-fio-transaction body)))
|
||||
(let ()
|
||||
(print "Fio: cannot load account " fn)
|
||||
#f
|
||||
))))
|
||||
|
||||
)
|
||||
|
|
|
@ -38,6 +38,7 @@
|
|||
(chicken keyword)
|
||||
(chicken io)
|
||||
(chicken irregex)
|
||||
(chicken condition)
|
||||
testing
|
||||
progress)
|
||||
|
||||
|
@ -103,8 +104,14 @@
|
|||
|
||||
;; Loads given CSV file and parses its lines into lists
|
||||
(define (csv-parse fn . args)
|
||||
(let ((lines (read-lines (open-input-file fn))))
|
||||
(apply csv-parse-lines lines args)))
|
||||
(call/cc
|
||||
(lambda (ret)
|
||||
(with-exception-handler
|
||||
(lambda (ex)
|
||||
(ret #f))
|
||||
(lambda ()
|
||||
(let ((lines (read-lines (open-input-file fn))))
|
||||
(apply csv-parse-lines lines args)))))))
|
||||
|
||||
;; Splits CSV into header and body based on the first empty row.
|
||||
(define (csv-split-header csv)
|
||||
|
|
|
@ -43,8 +43,8 @@
|
|||
(let* ((edvar (get-environment-variable "EDITOR"))
|
||||
(editor (or edvar "editor"))
|
||||
(pid (process-run editor (list file-path))))
|
||||
(process-wait pid)
|
||||
(clrscr)
|
||||
(flush-output)))
|
||||
(let-values (((a b c) (process-wait pid)))
|
||||
(clrscr)
|
||||
(flush-output))))
|
||||
|
||||
)
|
||||
|
|
|
@ -42,6 +42,7 @@
|
|||
(chicken sort)
|
||||
(chicken process-context)
|
||||
(chicken pathname)
|
||||
(chicken condition)
|
||||
bank-account
|
||||
member-record
|
||||
members-base
|
||||
|
@ -49,7 +50,8 @@
|
|||
dictionary
|
||||
member-fees
|
||||
period
|
||||
configuration)
|
||||
configuration
|
||||
utils)
|
||||
|
||||
;; Exchange rates
|
||||
(define exchange-rates-lookup-table
|
||||
|
@ -103,9 +105,15 @@
|
|||
|
||||
;; Reads the payments
|
||||
(define (load-accounts-list apikeys)
|
||||
(map (compose car string-split)
|
||||
(read-lines
|
||||
(open-input-file apikeys))))
|
||||
(call/cc
|
||||
(lambda (ret)
|
||||
(with-exception-handler
|
||||
(lambda (ex)
|
||||
(ret #f))
|
||||
(lambda ()
|
||||
(map (compose car string-split)
|
||||
(read-lines
|
||||
(open-input-file apikeys))))))))
|
||||
|
||||
;; Loads all accounts - it expects .csv files in given directory.
|
||||
(define (load-accounts accounts-list dir)
|
||||
|
@ -117,13 +125,17 @@
|
|||
;; accounts and processes transactions.
|
||||
(define (members-payments-process mb apikeys-file dir)
|
||||
(if apikeys-file
|
||||
(let* ((accounts (load-accounts
|
||||
(load-accounts-list apikeys-file)
|
||||
dir)))
|
||||
(map member-sort-payments
|
||||
(foldl members-payments-process-bank
|
||||
mb
|
||||
accounts)))
|
||||
(let* ((acc-list (load-accounts-list apikeys-file))
|
||||
(accounts (if acc-list (load-accounts acc-list dir) #f)))
|
||||
(if accounts
|
||||
(map member-sort-payments
|
||||
(foldl members-payments-process-bank
|
||||
mb
|
||||
(filter identity
|
||||
accounts)))
|
||||
(let ()
|
||||
(print "Warning: no accounts loaded!")
|
||||
mb)))
|
||||
mb))
|
||||
|
||||
;; Adds all balances - payments are converted to CZK in member-payments-total
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue