Updates allowed to change more than one entity at a time
This commit is contained in:
@@ -64,9 +64,15 @@
|
|||||||
(:invoice/expense-accounts entity)))
|
(:invoice/expense-accounts entity)))
|
||||||
:journal-entry/cleared (and (< (:invoice/outstanding-balance entity) 0.01)
|
:journal-entry/cleared (and (< (:invoice/outstanding-balance entity) 0.01)
|
||||||
(every? #(= :payment-status/cleared (:payment/status %)) (:invoice/payments entity))
|
(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]
|
(defn upsert-invoice [db invoice]
|
||||||
(let [upserted-entity [[:upsert-entity invoice]]
|
(let [upserted-entity [[:upsert-entity invoice]]
|
||||||
@@ -86,4 +92,4 @@
|
|||||||
[[:upsert-ledger journal-entry]]
|
[[:upsert-ledger journal-entry]]
|
||||||
[[:db/retractEntity [:journal-entry/original-entity (:db/id invoice)]]
|
[[:db/retractEntity [:journal-entry/original-entity (:db/id invoice)]]
|
||||||
{:db/id client-id
|
{: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]}])
|
(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 []
|
(defn current-date [db]
|
||||||
(Date.))
|
(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]
|
(defn calc-client+account+location+date [je jel]
|
||||||
[(or
|
[(or
|
||||||
@@ -54,12 +59,12 @@
|
|||||||
(:db/id ledger-entry)
|
(:db/id ledger-entry)
|
||||||
(:db/id extant-entry)
|
(:db/id extant-entry)
|
||||||
(-random-tempid)))
|
(-random-tempid)))
|
||||||
(update :journal-entry/line-items
|
(update :journal-entry/line-items
|
||||||
(fn [lis]
|
(fn [lis]
|
||||||
(mapv #(-> %
|
(mapv #(-> %
|
||||||
(assoc :journal-entry-line/date (:journal-entry/date ledger-entry))
|
(assoc :journal-entry-line/date (:journal-entry/date ledger-entry))
|
||||||
(assoc :journal-entry-line/client (:journal-entry/client ledger-entry)))
|
(assoc :journal-entry-line/client (:journal-entry/client ledger-entry)))
|
||||||
lis)))))]
|
lis)))))]
|
||||||
{:db/id (:journal-entry/client ledger-entry)
|
{: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]
|
[com.brunobonacci.mulog :as mu]
|
||||||
[datomic.api :as dc]))
|
[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 _ _]
|
(defn get-client [context _ _]
|
||||||
(->graphql
|
(->graphql
|
||||||
(->> (d-clients/get-minimal)
|
(->> (d-clients/get-minimal)
|
||||||
|
|||||||
@@ -473,6 +473,8 @@
|
|||||||
|
|
||||||
(comment
|
(comment
|
||||||
(pull-id (dc/db conn) [:client/code "SCCB"])
|
(pull-id (dc/db conn) [:client/code "SCCB"])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
(mark-all-clients-dirty)
|
(mark-all-clients-dirty)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user