Updates allowed to change more than one entity at a time
This commit is contained in:
@@ -64,9 +64,15 @@
|
||||
(:invoice/expense-accounts entity)))
|
||||
:journal-entry/cleared (and (< (:invoice/outstanding-balance entity) 0.01)
|
||||
(every? #(= :payment-status/cleared (:payment/status %)) (:invoice/payments entity))
|
||||
)})))
|
||||
|
||||
)
|
||||
)}))))
|
||||
|
||||
(defn current-date [db]
|
||||
(let [ last-tx (dc/t->tx (dc/basis-t db))
|
||||
[[date]] (seq (dc/q '[:find ?ti :in $ ?tx
|
||||
:where [?tx :db/txInstant ?ti]]
|
||||
db
|
||||
last-tx))]
|
||||
date))
|
||||
|
||||
(defn upsert-invoice [db invoice]
|
||||
(let [upserted-entity [[:upsert-entity invoice]]
|
||||
@@ -86,4 +92,4 @@
|
||||
[[:upsert-ledger journal-entry]]
|
||||
[[:db/retractEntity [:journal-entry/original-entity (:db/id invoice)]]
|
||||
{:db/id client-id
|
||||
:client/ledger-last-change (Date.)}]))))
|
||||
:client/ledger-last-change (current-date db)}]))))
|
||||
|
||||
@@ -25,8 +25,13 @@
|
||||
(def extant-read '[:db/id :journal-entry/date :journal-entry/client {:journal-entry/line-items [:journal-entry-line/account :journal-entry-line/location :db/id :journal-entry-line/client+account+location+date]}])
|
||||
|
||||
|
||||
(defn now []
|
||||
(Date.))
|
||||
(defn current-date [db]
|
||||
(let [ last-tx (dc/t->tx (dc/basis-t db))
|
||||
[[date]] (seq (dc/q '[:find ?ti :in $ ?tx
|
||||
:where [?tx :db/txInstant ?ti]]
|
||||
db
|
||||
last-tx))]
|
||||
date))
|
||||
|
||||
(defn calc-client+account+location+date [je jel]
|
||||
[(or
|
||||
@@ -54,12 +59,12 @@
|
||||
(:db/id ledger-entry)
|
||||
(:db/id extant-entry)
|
||||
(-random-tempid)))
|
||||
(update :journal-entry/line-items
|
||||
(update :journal-entry/line-items
|
||||
(fn [lis]
|
||||
(mapv #(-> %
|
||||
(assoc :journal-entry-line/date (:journal-entry/date ledger-entry))
|
||||
(assoc :journal-entry-line/client (:journal-entry/client ledger-entry)))
|
||||
lis)))))]
|
||||
{:db/id (:journal-entry/client ledger-entry)
|
||||
:client/ledger-last-change (now)}])))
|
||||
:client/ledger-last-change (current-date db)}])))
|
||||
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -11,36 +11,6 @@
|
||||
[com.brunobonacci.mulog :as mu]
|
||||
[datomic.api :as dc]))
|
||||
|
||||
(defn refresh-all-current-balance []
|
||||
(mu/with-context {:source "current-balance-refresh"}
|
||||
(let [db (dc/db conn)
|
||||
clients (dc/q '[:find (pull ?c [:db/id :client/code {:client/bank-accounts [:db/id :bank-account/code]}])
|
||||
:where [?c :client/code]]
|
||||
db)]
|
||||
(doseq [[{client :db/id code :client/code bank-accounts :client/bank-accounts}] clients
|
||||
{bank-account :db/id bac :bank-account/code} bank-accounts]
|
||||
(let [balance (or
|
||||
(->> (dc/index-pull db
|
||||
{:index :avet
|
||||
:selector [:db/id :journal-entry-line/location :journal-entry-line/account :journal-entry-line/running-balance :journal-entry-line/client+account+location+date {:journal-entry/_line-items [:journal-entry/date :journal-entry/client]}]
|
||||
:start [:journal-entry-line/client+account+location+date [client bank-account "A" #inst "2030-01-01"]]
|
||||
:reverse true})
|
||||
(take 3)
|
||||
|
||||
(filter (fn [{[c b] :journal-entry-line/client+account+location+date}]
|
||||
(and (= c client)
|
||||
(= b bank-account))))
|
||||
|
||||
(map :journal-entry-line/running-balance)
|
||||
(first))
|
||||
0.0)]
|
||||
(alog/info ::updating
|
||||
:bank-account bac
|
||||
:balance balance)
|
||||
@(dc/transact conn [{:db/id bank-account
|
||||
:bank-account/current-balance-synced (c/to-date (time/now))
|
||||
:bank-account/current-balance balance}]))))))
|
||||
|
||||
(defn get-client [context _ _]
|
||||
(->graphql
|
||||
(->> (d-clients/get-minimal)
|
||||
|
||||
@@ -473,6 +473,8 @@
|
||||
|
||||
(comment
|
||||
(pull-id (dc/db conn) [:client/code "SCCB"])
|
||||
|
||||
|
||||
|
||||
(mark-all-clients-dirty)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user