|
@@ -1,3 +1,9 @@
|
|
|
|
|
+(in-package :cl-user)
|
|
|
|
|
+(defpackage #:timeliner.financisto
|
|
|
|
|
+ (:use :cl #:timeliner.utils :cl-mongo)
|
|
|
|
|
+ (:export #:import-financisto-events))
|
|
|
|
|
+(in-package #:timeliner.financisto)
|
|
|
|
|
+
|
|
|
(defvar *financisto-backup-path* #P"/home/enikesha/Documents/backups/financisto/")
|
|
(defvar *financisto-backup-path* #P"/home/enikesha/Documents/backups/financisto/")
|
|
|
|
|
|
|
|
(defun find-last-backup ()
|
|
(defun find-last-backup ()
|
|
@@ -44,14 +50,14 @@
|
|
|
(from-decimals (expt 10d0 (parse-integer (getf from-currency :decimals))))
|
|
(from-decimals (expt 10d0 (parse-integer (getf from-currency :decimals))))
|
|
|
(from-amount (/ (parse-integer (getf e :from-amount)) from-decimals))
|
|
(from-amount (/ (parse-integer (getf e :from-amount)) from-decimals))
|
|
|
(from-balance (/ (gethash (parse-integer (getf from-account :-id)) balances 0) from-decimals))
|
|
(from-balance (/ (gethash (parse-integer (getf from-account :-id)) balances 0) from-decimals))
|
|
|
- (spend (< from-amount 0))
|
|
|
|
|
|
|
+ (spend (< from-amount 0))
|
|
|
(original-currency (gethash (parse-integer (getf e :original-currency-id)) currencies))
|
|
(original-currency (gethash (parse-integer (getf e :original-currency-id)) currencies))
|
|
|
(original-from-amount (and original-currency
|
|
(original-from-amount (and original-currency
|
|
|
(/ (parse-integer (getf e :original-from-amount))
|
|
(/ (parse-integer (getf e :original-from-amount))
|
|
|
(expt 10d0 (parse-integer (getf original-currency :decimals))))))
|
|
(expt 10d0 (parse-integer (getf original-currency :decimals))))))
|
|
|
(payee (gethash (parse-integer (getf e :payee-id)) (gethash "payee" db)))
|
|
(payee (gethash (parse-integer (getf e :payee-id)) (gethash "payee" db)))
|
|
|
(category (gethash (parse-integer (getf e :category-id)) (gethash "category" db)))
|
|
(category (gethash (parse-integer (getf e :category-id)) (gethash "category" db)))
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
(to-account (gethash (parse-integer (getf e :to-account-id)) accounts))
|
|
(to-account (gethash (parse-integer (getf e :to-account-id)) accounts))
|
|
|
(to-currency (and to-account (gethash (parse-integer (getf to-account :currency-id)) currencies)))
|
|
(to-currency (and to-account (gethash (parse-integer (getf to-account :currency-id)) currencies)))
|
|
|
(to-decimals (and to-account (expt 10d0 (parse-integer (getf to-currency :decimals)))))
|
|
(to-decimals (and to-account (expt 10d0 (parse-integer (getf to-currency :decimals)))))
|
|
@@ -90,7 +96,7 @@
|
|
|
(getf to-account :currency-id)))
|
|
(getf to-account :currency-id)))
|
|
|
(abs to-amount))
|
|
(abs to-amount))
|
|
|
(getf to-currency :symbol)
|
|
(getf to-currency :symbol)
|
|
|
- to-balance (getf to-currency :symbol)
|
|
|
|
|
|
|
+ to-balance (getf to-currency :symbol)
|
|
|
(getf e :note))
|
|
(getf e :note))
|
|
|
(format
|
|
(format
|
|
|
nil "~A ~$~A~:[~*~;~:* (~$~A)~] ~A ~A~@[ for ~A~]~@[ at ~A~]~@[ (~A)~]. Balance ~$~A"
|
|
nil "~A ~$~A~:[~*~;~:* (~$~A)~] ~A ~A~@[ for ~A~]~@[ at ~A~]~@[ (~A)~]. Balance ~$~A"
|
|
@@ -135,7 +141,7 @@
|
|
|
(kv "note" (getf e :note))
|
|
(kv "note" (getf e :note))
|
|
|
financisto)))))
|
|
financisto)))))
|
|
|
|
|
|
|
|
-(defun financisto-import ()
|
|
|
|
|
|
|
+(defun import-financisto-events ()
|
|
|
(let* ((filename (find-last-backup))
|
|
(let* ((filename (find-last-backup))
|
|
|
(db (load-backup filename))
|
|
(db (load-backup filename))
|
|
|
(transactions (sort (loop for entity being the hash-values of (gethash "transactions" db)
|
|
(transactions (sort (loop for entity being the hash-values of (gethash "transactions" db)
|
|
@@ -163,7 +169,8 @@
|
|
|
(if (and existing-doc (= new-ts (cl-mongo::raw
|
|
(if (and existing-doc (= new-ts (cl-mongo::raw
|
|
|
(get-element "ts" existing-doc))))
|
|
(get-element "ts" existing-doc))))
|
|
|
(get-element "loc" existing-doc)
|
|
(get-element "loc" existing-doc)
|
|
|
- (point->doc (find-location-at new-ts))))
|
|
|
|
|
|
|
+ (timeliner.locations:point->doc
|
|
|
|
|
+ (timeliner.locations:find-location-at new-ts))))
|
|
|
new-doc)
|
|
new-doc)
|
|
|
(if existing-doc
|
|
(if existing-doc
|
|
|
(progn
|
|
(progn
|