bugfix.
This commit is contained in:
@@ -24,11 +24,10 @@
|
||||
:end (+ (:start args 0) (count transactions))}]))
|
||||
|
||||
(defn transaction-account->entity [{:keys [id account_id amount location]}]
|
||||
(doto (remove-nils #:transaction-account {:amount (Double/parseDouble amount)
|
||||
:db/id id
|
||||
:account account_id
|
||||
:location location})
|
||||
println))
|
||||
(remove-nils #:transaction-account {:amount (Double/parseDouble amount)
|
||||
:db/id id
|
||||
:account account_id
|
||||
:location location}))
|
||||
|
||||
|
||||
(defn deleted-accounts [transaction accounts]
|
||||
@@ -42,21 +41,21 @@
|
||||
(set/difference existing-ids specified-ids)))
|
||||
|
||||
(defn edit-transaction [context {{:keys [id accounts vendor_id] :as transaction} :transaction} value]
|
||||
(let [transaction (d-transactions/get-by-id id)
|
||||
deleted (deleted-accounts transaction accounts)
|
||||
(let [existing-transaction (d-transactions/get-by-id id)
|
||||
deleted (deleted-accounts existing-transaction accounts)
|
||||
account-total (reduce + 0 (map (fn [x] (Double/parseDouble (:amount x))) accounts))
|
||||
missing-locations (seq (set/difference
|
||||
(->> (:transaction/accounts transaction)
|
||||
(map :transaction-account/location)
|
||||
(->> accounts
|
||||
(map :location)
|
||||
set)
|
||||
(-> (:transaction/client transaction)
|
||||
(-> (:transaction/client existing-transaction)
|
||||
:client/locations
|
||||
set
|
||||
(conj "A")
|
||||
(conj "HQ"))))]
|
||||
(assert-can-see-client (:id context) (:transaction/client transaction) )
|
||||
(when-not (dollars= (Math/abs (:transaction/amount transaction)) account-total)
|
||||
(let [error (str "Expense account total (" account-total ") does not equal transaction total (" (Math/abs (:transaction/amount transaction)) ")")]
|
||||
(assert-can-see-client (:id context) (:transaction/client existing-transaction) )
|
||||
(when-not (dollars= (Math/abs (:transaction/amount existing-transaction)) account-total)
|
||||
(let [error (str "Expense account total (" account-total ") does not equal transaction total (" (Math/abs (:transaction/amount existing-transaction)) ")")]
|
||||
(throw (ex-info error {:validation-error error}))))
|
||||
(when missing-locations
|
||||
(throw (ex-info (str "Location '" (str/join ", " missing-locations) "' not found on client.") {})) )
|
||||
|
||||
@@ -69,33 +69,32 @@
|
||||
credit-from-bank? decreasing?
|
||||
debit-from-bank? (not decreasing?)]
|
||||
|
||||
(when (:transaction/vendor entity)
|
||||
(remove-nils
|
||||
{:journal-entry/source "transaction"
|
||||
:journal-entry/client (:db/id (:transaction/client entity))
|
||||
:journal-entry/date (:transaction/date entity)
|
||||
:journal-entry/original-entity (:db/id entity)
|
||||
:journal-entry/vendor (:db/id (:transaction/vendor entity))
|
||||
:journal-entry/amount (Math/abs (:transaction/amount entity))
|
||||
(remove-nils
|
||||
{:journal-entry/source "transaction"
|
||||
:journal-entry/client (:db/id (:transaction/client entity))
|
||||
:journal-entry/date (:transaction/date entity)
|
||||
:journal-entry/original-entity (:db/id entity)
|
||||
:journal-entry/vendor (:db/id (:transaction/vendor entity))
|
||||
:journal-entry/amount (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 credit-from-bank?
|
||||
(Math/abs (:transaction/amount entity)))
|
||||
:journal-entry-line/debit (when debit-from-bank?
|
||||
(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 credit-from-bank?
|
||||
(Math/abs (:transaction-account/amount a)))
|
||||
:journal-entry-line/credit (when debit-from-bank?
|
||||
(Math/abs (:transaction-account/amount a)))}))
|
||||
(:transaction/accounts entity)))
|
||||
|
||||
:journal-entry/cleared true}))))
|
||||
: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 credit-from-bank?
|
||||
(Math/abs (:transaction/amount entity)))
|
||||
:journal-entry-line/debit (when debit-from-bank?
|
||||
(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 credit-from-bank?
|
||||
(Math/abs (:transaction-account/amount a)))
|
||||
:journal-entry-line/credit (when debit-from-bank?
|
||||
(Math/abs (:transaction-account/amount a)))}))
|
||||
(:transaction/accounts entity)))
|
||||
|
||||
:journal-entry/cleared true})))
|
||||
|
||||
(defmethod entity-change->ledger :invoice-expense-account
|
||||
[db [entity changes]]
|
||||
|
||||
Reference in New Issue
Block a user