Innokentiy Enikeev 3 gadi atpakaļ
vecāks
revīzija
953f56db51
4 mainītis faili ar 35 papildinājumiem un 20 dzēšanām
  1. 10 6
      plugins/ledger.lisp
  2. 13 6
      plugins/revolut.lisp
  3. 5 1
      plugins/saver.lisp
  4. 7 7
      plugins/tinkoff.lisp

+ 10 - 6
plugins/ledger.lisp

@@ -273,7 +273,7 @@
 
 (defvar *expenses-account-root* "expenses" "Expenses accounts root.")
 
-(defun create-entry (chat-id text amount currency)
+(defun create-entry (chat-id text amount currency &optional account)
   (with-chat-journal (chat-id journal updated)
     (let* ((old (match-entry text journal))
            (new (or (when old (pta-ledger:clone-entry old))
@@ -290,7 +290,7 @@
             (pta-ledger:posting-amount (cadr postings)) (pta-ledger:make-amount
                                                          :quantity (- amount)
                                                          :commodity currency)
-            (pta-ledger:posting-account (cadr postings)) (format nil "assets:Cash:~A" currency))
+            (pta-ledger:posting-account (cadr postings)) (or account (format nil "assets:cash:~(~A~)" currency)))
       new)))
 
 (defun find-posting (entry root)
@@ -589,13 +589,17 @@
                     (account-edit chat-id *source-message-id* entry posting
                                   account next))))))))
 
-(def-message-cmd-handler handler-create (:rub :usd :eur :thb :btc :czk)
+(def-message-cmd-handler handler-create (:rub :usd :eur :thb :btc :czk :fuy)
   (cond
     ((>= (length *args*) 2)
      (ledger/new-chat-entry *chat-id* (create-entry *chat-id*
                                                     (spaced (subseq *args* 1))
                                                     (parse-float (car *args*))
-                                                    (symbol-name *cmd*))))
+						    (case *cmd*
+						      (:fuy "CZK")
+						      (t (symbol-name *cmd*)))
+						    (case *cmd*
+						      (:fuy "liabilities:people:fuy")))))
     (:otherwise (bot-send-message (format nil "/~A <amount> <description>" *cmd*)))))
 
 (defun get-harshly-state (journal account day next-day)
@@ -638,8 +642,8 @@
                    left-days
                    (mapcar #'pta-ledger:render (list balance daily-amount)))))))
 
-(defvar *harshly-account* "assets:Raiffeisen:Debit")
-(defvar *harshly-payday-schedule* '(:day-of-month (member 5 20)))
+(defvar *harshly-account* "assets:revolut:czk")
+(defvar *harshly-payday-schedule* '(:day-of-month (member 8)))
 (defun show-harshly ()
   (with-chat-journal (*chat-id* journal updated)
     (format-harshly-state

+ 13 - 6
plugins/revolut.lisp

@@ -122,10 +122,11 @@
 (defun get-quote (symbol)
   (poller-call :revolut "quote" :|symbol| symbol))
 
+
 (defun get-transactions-last (&key (count 10) pocket to)
   (poller-call :revolut "user/current/transactions/last"
                :|count| count
-               :|to| to
+               :|to| to ;; timestamp (startedDate) of last received transaction
                :|internalPocketId| pocket))
 
 (defun get-transactions-vault (&key id)
@@ -212,7 +213,7 @@
                                               (agets tr "account" "id") pockets)))
          (rcv-amount (get-amount (agets tr "amount")))
          (rcv-currency (agets tr "currency"))
-         (snd-account (agets *topup-accounts* description))
+         (snd-account (or (agets *topup-accounts* description) "income"))
          (snd-amount (* -1 rcv-amount))
          (snd-currency rcv-currency))         
     (values description nil
@@ -293,9 +294,15 @@
             rcv-account rcv-amount rcv-currency
             snd-account snd-amount snd-currency)))
 
+(defun default-account (currency)
+  (concatenate 'string "assets:revolut:" (string-downcase currency)))
+
 (defun transaction->entry (tr pockets)
   (let* ((date (get-date (agets tr "startedDate")))
-         (type (keyify (agets tr "type"))))
+         (type (keyify (agets tr "type")))
+	 (state (keyify (agets tr "state"))))
+    (case state ((:declined :failed :cancelled :reverted :deleted)
+		 (return-from transaction->entry)))
     (multiple-value-bind (description comment
                           rcv-account rcv-amount rcv-currency
                           snd-account snd-amount snd-currency)
@@ -307,14 +314,14 @@
           (:fee (params-fee tr pockets))
           (:card-payment (params-card-payment tr pockets))
 	  (:card-refund (params-card-refund tr pockets)))
-      (when snd-account
+      (when snd-amount
         (pta-ledger:make-entry
          :date date
          :description description
          :comment comment
          :postings (list
                     (pta-ledger:make-posting
-                     :account rcv-account
+                     :account (or rcv-account (default-account rcv-currency))
                      :amount (pta-ledger:make-amount
                               :quantity rcv-amount
                               :commodity rcv-currency)
@@ -323,7 +330,7 @@
                                      :quantity (abs snd-amount)
                                      :commodity snd-currency)))
                     (pta-ledger:make-posting
-                     :account snd-account
+                     :account (or snd-account (default-account snd-currency))
                      :amount (pta-ledger:make-amount
                               :quantity snd-amount
                               :commodity snd-currency))))))))

+ 5 - 1
plugins/saver.lisp

@@ -324,7 +324,11 @@
                                                                      #\- (elt groups 3)))
                                                           (encode-universal-time 0 0 0 day month year))
                                                         (get-universal-time)))))
-          (saver/payment-next-time payment (get-universal-time))
+	  (handler-case
+	      (saver/payment-next-time payment (get-universal-time))
+	    (error ()
+	      (bot-send-message "Платёж невалидный")
+	      (return-from saver/add-payment)))          
           (handler-case
               (db/saver/add-payment *chat-id* payment)
             (error () (bot-send-message (format nil "Платёж '~A' уже есть!"

+ 7 - 7
plugins/tinkoff.lisp

@@ -6,14 +6,14 @@
 (eval-when (:compile-toplevel :load-toplevel :execute)
   (ql:quickload :pta-ledger))
 
-(defsetting *account-default-prefix* "assets:Tinkoff:")
+(defsetting *account-default-prefix* "assets:tinkoff:")
 (defsetting *account-aliases* nil "tinkoff account to ledger account")
-(defsetting *category-aliases* '((60 . "expenses:Food:Fast-food")
-                                 (36 . "expenses:Transport")
-                                 (32 . "expenses:Food:Restaurant")
-                                 (20 . "expenses:Life:Wear")
-                                 (16 . "expenses:Transport:Car:Gas")
-                                 (10 . "expenses:Food:Grocery")) "tinkoff category to expense account mapping")
+(defsetting *category-aliases* '((60 . "expenses:food:fast-food")
+                                 (36 . "expenses:transport")
+                                 (32 . "expenses:food:restaurant")
+                                 (20 . "expenses:life:wear")
+                                 (16 . "expenses:transport:car:gas")
+                                 (10 . "expenses:food:groceries")) "tinkoff category to expense account mapping")
 
 (defsetting *ua* "OnePlus ONE A2003/android: 6.0.1/TCSMB/3.4.2" "User agent")
 (defsetting *device-id* "1df9bdeac787e08")