84 lines
2.3 KiB
Scheme
84 lines
2.3 KiB
Scheme
;;
|
|
;; bank-fio.scm
|
|
;;
|
|
;; Fio CSV statements loader to common bank format.
|
|
;;
|
|
;; ISC License
|
|
;;
|
|
;; Copyright 2023 Brmlab, z.s.
|
|
;; Dominik Pantůček <dominik.pantucek@trustica.cz>
|
|
;;
|
|
;; Permission to use, copy, modify, and/or distribute this software
|
|
;; for any purpose with or without fee is hereby granted, provided
|
|
;; that the above copyright notice and this permission notice appear
|
|
;; in all copies.
|
|
;;
|
|
;; THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
|
|
;; WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
|
|
;; WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
|
|
;; AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR
|
|
;; CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
|
|
;; OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
|
;; NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
|
|
;; CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
;;
|
|
|
|
(declare (unit bank-fio))
|
|
|
|
(module
|
|
bank-fio
|
|
(
|
|
bank-fio-parse
|
|
)
|
|
|
|
(import scheme
|
|
(chicken base)
|
|
(chicken string)
|
|
bank-account
|
|
util-csv
|
|
progress)
|
|
|
|
;; Conversion of Fio date to ISO
|
|
(define (fio-date->iso str)
|
|
(string-intersperse
|
|
(reverse
|
|
(string-split str "."))
|
|
"-"))
|
|
|
|
;; Converts Fio account statement transaction row into standardized
|
|
;; bank transaction structure.
|
|
(define (make-fio-transaction row)
|
|
(let ((id (string->number (car row)))
|
|
(date (fio-date->iso (cadr row)))
|
|
(amount (string->number
|
|
(string-translate* (caddr row)
|
|
'(("," . ".")))))
|
|
(currency (string->symbol (cadddr row)))
|
|
(varsym (list-ref row 9))
|
|
(message (list-ref row 12))
|
|
(type (list-ref row 13))
|
|
(bank (list-ref row 6))
|
|
(account (list-ref row 4))
|
|
(specsym (list-ref row 10)))
|
|
(make-bank-transaction id date amount currency varsym message type
|
|
account bank specsym)))
|
|
|
|
;; Loads Fio bank accound statement.
|
|
(define (bank-fio-parse fn)
|
|
(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 (cdr body))))
|
|
(let ()
|
|
(print "Fio: cannot load account " fn)
|
|
#f
|
|
))))
|
|
|
|
)
|