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