|
@@ -78,49 +78,51 @@
|
|
|
|
|
|
|
|
(defun expense-comment (name &optional user address price quantity sum)
|
|
(defun expense-comment (name &optional user address price quantity sum)
|
|
|
(declare (ignorable name user address price quantity sum))
|
|
(declare (ignorable name user address price quantity sum))
|
|
|
- (format nil "item: ~A~@[, ~A @ ~A~]"
|
|
|
|
|
|
|
+ (format nil "item: ~A~@[, ~A @ ~$~]"
|
|
|
name
|
|
name
|
|
|
(unless (= quantity 1) quantity)
|
|
(unless (= quantity 1) quantity)
|
|
|
(unless (= quantity 1) (/ price 100))))
|
|
(unless (= quantity 1) (/ price 100))))
|
|
|
|
|
|
|
|
-(defun asset-account (&optional user address)
|
|
|
|
|
|
|
+(defun expense-posting (item &optional user address)
|
|
|
|
|
+ (let ((name (agets item "name"))
|
|
|
|
|
+ (price (agets item "price"))
|
|
|
|
|
+ (quantity (agets item "quantity"))
|
|
|
|
|
+ (sum (agets item "sum")))
|
|
|
|
|
+ (pta-ledger:make-posting
|
|
|
|
|
+ :account (expense-account name user address)
|
|
|
|
|
+ :comment (expense-comment name user address price quantity sum)
|
|
|
|
|
+ :amount (pta-ledger:make-amount
|
|
|
|
|
+ :quantity (/ sum 100)
|
|
|
|
|
+ :commodity *default-currency*))))
|
|
|
|
|
+
|
|
|
|
|
+(defun asset-posting (amount &optional user address)
|
|
|
(declare (ignorable user address))
|
|
(declare (ignorable user address))
|
|
|
- *default-asset-account*)
|
|
|
|
|
|
|
+ (pta-ledger:make-posting
|
|
|
|
|
+ :account *default-asset-account*
|
|
|
|
|
+ :amount (pta-ledger:make-amount
|
|
|
|
|
+ :quantity (* -1 amount)
|
|
|
|
|
+ :commodity *default-currency*)))
|
|
|
|
|
|
|
|
(defun not-empty (str)
|
|
(defun not-empty (str)
|
|
|
(unless (string= str "")
|
|
(unless (string= str "")
|
|
|
str))
|
|
str))
|
|
|
|
|
|
|
|
(defun cheque->entry (c)
|
|
(defun cheque->entry (c)
|
|
|
- (let ((total-sum (agets c "totalSum"))
|
|
|
|
|
- (date (local-time:timestamp-to-universal
|
|
|
|
|
- (local-time:parse-timestring (agets c "dateTime") )))
|
|
|
|
|
- (user (or (not-empty (agets c "retailPlace"))
|
|
|
|
|
- (not-empty (agets c "user"))
|
|
|
|
|
- (format nil "ИНН ~A" (agets c "userInn"))))
|
|
|
|
|
- (address (not-empty (agets c "retailPlaceAddress")))
|
|
|
|
|
- (items (agets c "items")))
|
|
|
|
|
|
|
+ (let* ((total-sum (agets c "totalSum"))
|
|
|
|
|
+ (date (local-time:timestamp-to-universal
|
|
|
|
|
+ (local-time:parse-timestring (agets c "dateTime"))))
|
|
|
|
|
+ (inn (not-empty (agets c "userInn")))
|
|
|
|
|
+ (user (or (not-empty (agets c "retailPlace"))
|
|
|
|
|
+ (not-empty (agets c "user"))
|
|
|
|
|
+ (format nil "ИНН ~A" inn)))
|
|
|
|
|
+ (address (not-empty (agets c "retailPlaceAddress")))
|
|
|
|
|
+ (items (agets c "items")))
|
|
|
(pta-ledger:make-entry
|
|
(pta-ledger:make-entry
|
|
|
:date date
|
|
:date date
|
|
|
:description user
|
|
:description user
|
|
|
- :comment (when address (format nil "address: ~A" address))
|
|
|
|
|
- :postings (append (loop for i in items
|
|
|
|
|
- collect
|
|
|
|
|
- (let ((name (agets i "name"))
|
|
|
|
|
- (price (agets i "price"))
|
|
|
|
|
- (quantity (agets i "quantity"))
|
|
|
|
|
- (sum (agets i "sum")))
|
|
|
|
|
- (pta-ledger:make-posting
|
|
|
|
|
- :account (expense-account name user address)
|
|
|
|
|
- :comment (expense-comment name user address price quantity sum)
|
|
|
|
|
- :amount (pta-ledger:make-amount
|
|
|
|
|
- :quantity (/ sum 100)
|
|
|
|
|
- :commodity *default-currency*))))
|
|
|
|
|
- (list (pta-ledger:make-posting
|
|
|
|
|
- :account (asset-account user address)
|
|
|
|
|
- :amount (pta-ledger:make-amount
|
|
|
|
|
- :quantity (* -1 (/ total-sum 100))
|
|
|
|
|
- :commodity *default-currency*)))))))
|
|
|
|
|
|
|
+ :comment (format nil "~@[inn: ~A~]~@[, address: ~A~]" inn address)
|
|
|
|
|
+ :postings (append (mapcar #'expense-posting items)
|
|
|
|
|
+ (list (asset-posting (/ total-sum 100) user address))))))
|
|
|
|
|
|
|
|
|
|
|
|
|
(defun handle-auth (login pass)
|
|
(defun handle-auth (login pass)
|
|
@@ -135,18 +137,27 @@
|
|
|
((= 2 (length *args*)) (apply 'handle-auth *args*))
|
|
((= 2 (length *args*)) (apply 'handle-auth *args*))
|
|
|
(:otherwise (bot-send-message "/ofd <login> <pass>"))))
|
|
(:otherwise (bot-send-message "/ofd <login> <pass>"))))
|
|
|
|
|
|
|
|
|
|
+(defvar *chat-next-cheque-handlers* (make-hash-table) "chat cheque handlers")
|
|
|
|
|
+(defun handle-next-cheque (handler)
|
|
|
|
|
+ (setf (gethash *chat-id* *chat-next-cheque-handlers*) handler))
|
|
|
|
|
+
|
|
|
(def-message-handler ofd-handler (-10)
|
|
(def-message-handler ofd-handler (-10)
|
|
|
(let ((parsed (parse-qt *text*)))
|
|
(let ((parsed (parse-qt *text*)))
|
|
|
(when parsed
|
|
(when parsed
|
|
|
(telegram-send-chat-action *chat-id* "typing")
|
|
(telegram-send-chat-action *chat-id* "typing")
|
|
|
- (let ((cheque (apply #'receive parsed)))
|
|
|
|
|
|
|
+ (let ((cheque (apply #'receive parsed))
|
|
|
|
|
+ (handler (gethash *chat-id* *chat-next-cheque-handlers*)))
|
|
|
(if cheque
|
|
(if cheque
|
|
|
(let ((ledger-package (find-package :chatikbot.plugins.ledger))
|
|
(let ((ledger-package (find-package :chatikbot.plugins.ledger))
|
|
|
(entry (cheque->entry cheque)))
|
|
(entry (cheque->entry cheque)))
|
|
|
- (if ledger-package
|
|
|
|
|
- (let ((new-chat-entry (symbol-function
|
|
|
|
|
- (intern "LEDGER/NEW-CHAT-ENTRY" ledger-package))))
|
|
|
|
|
- (funcall new-chat-entry *chat-id* (pta-ledger:clone-entry entry)))
|
|
|
|
|
- (bot-send-message (pta-ledger:render entry) :parse-mode "markdown")))
|
|
|
|
|
|
|
+ (cond
|
|
|
|
|
+ (handler
|
|
|
|
|
+ (remhash *chat-id* *chat-next-cheque-handlers*)
|
|
|
|
|
+ (funcall handler entry))
|
|
|
|
|
+ (ledger-package
|
|
|
|
|
+ (let ((new-chat-entry (symbol-function
|
|
|
|
|
+ (intern "LEDGER/NEW-CHAT-ENTRY" ledger-package))))
|
|
|
|
|
+ (funcall new-chat-entry *chat-id* (pta-ledger:clone-entry entry))))
|
|
|
|
|
+ (:otherwise (bot-send-message (pta-ledger:render entry) :parse-mode "markdown"))))
|
|
|
(bot-send-message "Не смог в чек :(")))
|
|
(bot-send-message "Не смог в чек :(")))
|
|
|
t)))
|
|
t)))
|