supports validation and multiple account entering.
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
|
||||
|
||||
(defn datums->impacted-entity [db [e changes]]
|
||||
(let [entity (d/pull db '[* {:invoice/_expense-accounts [*]}] e)
|
||||
(let [entity (d/pull db '[* {:invoice/_expense-accounts [:db/id] :transaction/_accounts [:db/id]}] e)
|
||||
namespaces (->> changes
|
||||
(map :a)
|
||||
(map namespace)
|
||||
@@ -13,6 +13,7 @@
|
||||
|
||||
(cond (namespaces "invoice" ) [[:invoice e]]
|
||||
(namespaces "invoice-expense-account" ) [[:invoice (:db/id (:invoice/_expense-accounts entity))]]
|
||||
(namespaces "transaction-account" ) [[:transaction (:db/id (:transaction/_accounts entity))]]
|
||||
(namespaces "transaction" ) [[:transaction e]]
|
||||
:else nil)))
|
||||
|
||||
@@ -26,6 +27,7 @@
|
||||
|
||||
(cond (namespaces "invoice" ) :invoice
|
||||
(namespaces "invoice-expense-account" ) :invoice-expense-account
|
||||
(namespaces "transaction-account" ) :transaction-account
|
||||
:else nil)))
|
||||
|
||||
(defmulti entity-change->ledger (fn [_ [type]]
|
||||
@@ -57,7 +59,8 @@
|
||||
|
||||
(defmethod entity-change->ledger :transaction
|
||||
[db [type id]]
|
||||
(let [entity (d/pull db ['* {:transaction/vendor '[*] :transaction/client '[*] :transaction/account '[*]}] id)]
|
||||
(let [entity (d/pull db ['* {:transaction/vendor '[*] :transaction/client '[*] :transaction/accounts '[* {:transaction-account/account [*]}] }] id)]
|
||||
(println "processing entity" entity)
|
||||
(when (:transaction/vendor entity)
|
||||
(remove-nils
|
||||
{:journal-entry/source "transaction"
|
||||
@@ -67,20 +70,23 @@
|
||||
:journal-entry/vendor (:db/id (:transaction/vendor entity))
|
||||
:journal-entry/amount (Math/abs (:transaction/amount entity))
|
||||
|
||||
:journal-entry/line-items [(remove-nils{:journal-entry-line/account (:db/id (:transaction/account entity))
|
||||
:journal-entry-line/location (:transaction/location entity)
|
||||
:journal-entry-line/debit (when (< (:transaction/amount entity) 0.0)
|
||||
(Math/abs (:transaction/amount entity)))
|
||||
:journal-entry-line/credit (when (>= (:transaction/amount entity) 0.0)
|
||||
(Math/abs (:transaction/amount entity)))})
|
||||
|
||||
(remove-nils {:journal-entry-line/account (:db/id (:transaction/bank-account entity))
|
||||
:journal-entry-line/location "A"
|
||||
:journal-entry-line/credit (when (< (:transaction/amount entity) 0.0)
|
||||
(Math/abs (:transaction/amount entity)))
|
||||
:journal-entry-line/debit (when (>= (:transaction/amount entity) 0.0)
|
||||
(Math/abs (:transaction/amount entity)))})
|
||||
]
|
||||
:journal-entry/line-items (into [
|
||||
(remove-nils {:journal-entry-line/account (:db/id (:transaction/bank-account entity))
|
||||
:journal-entry-line/location "A"
|
||||
:journal-entry-line/credit (when (< (:transaction/amount entity) 0.0)
|
||||
(Math/abs (:transaction/amount entity)))
|
||||
:journal-entry-line/debit (when (>= (:transaction/amount entity) 0.0)
|
||||
(Math/abs (:transaction/amount entity)))})
|
||||
]
|
||||
(map
|
||||
(fn [a]
|
||||
(remove-nils{:journal-entry-line/account (:db/id (:transaction-account/account a))
|
||||
:journal-entry-line/location (:transaction-account/location a)
|
||||
:journal-entry-line/debit (when (< (:transaction/amount entity) 0.0)
|
||||
(Math/abs (:transaction-account/amount a)))
|
||||
:journal-entry-line/credit (when (>= (:transaction/amount entity) 0.0)
|
||||
(Math/abs (:transaction-account/amount a)))}))
|
||||
(:transaction/accounts entity)))
|
||||
|
||||
:journal-entry/cleared true}))))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user