66 lines
1.9 KiB
Scheme
66 lines
1.9 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 irregex)
|
|
bank-account
|
|
csv-simple)
|
|
|
|
;; Converts Fio account statement transaction row into standardized
|
|
;; bank transaction structure.
|
|
(define (make-fio-transaction row)
|
|
(let ((id (string->number (car row)))
|
|
(date (cadr row))
|
|
(amount (string->number
|
|
(irregex-replace (irregex "," 'u)
|
|
(caddr row)
|
|
".")))
|
|
(currency (string->symbol (cadddr row)))
|
|
(varsym (list-ref row 9)))
|
|
(make-bank-transaction id date amount currency varsym)))
|
|
|
|
;; Loads Fio bank accound statement.
|
|
(define (bank-fio-parse 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))))
|
|
|
|
)
|