Move sources to separate directory.
This commit is contained in:
parent
aa7a340d51
commit
69d0b8ee10
25 changed files with 0 additions and 0 deletions
77
src/bank-fio.scm
Normal file
77
src/bank-fio.scm
Normal file
|
@ -0,0 +1,77 @@
|
|||
;;
|
||||
;; 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
|
||||
csv-simple
|
||||
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)))
|
||||
(make-bank-transaction id date amount currency varsym message type)))
|
||||
|
||||
;; 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)))))
|
||||
|
||||
)
|
Loading…
Add table
Add a link
Reference in a new issue