Compare commits
2 Commits
integreat-
...
ab27d3a4da
| Author | SHA1 | Date | |
|---|---|---|---|
| ab27d3a4da | |||
| 19d936693a |
@@ -209,6 +209,37 @@
|
|||||||
;; 3. CSVs
|
;; 3. CSVs
|
||||||
;; 4. better date range / advanced mode for dialog
|
;; 4. better date range / advanced mode for dialog
|
||||||
|
|
||||||
|
(defn- accounts-sharing-code
|
||||||
|
"The searched account, plus any of `clients`' bank accounts on the same numeric
|
||||||
|
code. :journal-entry-line/account points at either entity, so a search for the
|
||||||
|
financial account has to match lines posted to the bank account too."
|
||||||
|
[db clients account-id]
|
||||||
|
(into [account-id]
|
||||||
|
(when-let [code (:account/numeric-code (dc/entity db account-id))]
|
||||||
|
(dc/q '[:find [?ba ...]
|
||||||
|
|
||||||
|
:in $ [?client ...] ?code
|
||||||
|
|
||||||
|
:where
|
||||||
|
[?client :client/bank-accounts ?ba]
|
||||||
|
[?ba :bank-account/numeric-code ?code]]
|
||||||
|
db clients code))))
|
||||||
|
|
||||||
|
(defn- account-filter-query
|
||||||
|
"Ledger clause for the Account search. Stays a scalar binding when nothing
|
||||||
|
shares the account's code, so the common case costs what it always did."
|
||||||
|
[db clients account-id]
|
||||||
|
(let [ids (accounts-sharing-code db clients account-id)]
|
||||||
|
(if (second ids)
|
||||||
|
{:query {:in ['[?a3 ...]]
|
||||||
|
|
||||||
|
:where ['[?li :journal-entry-line/account ?a3]]}
|
||||||
|
:args [ids]}
|
||||||
|
{:query {:in ['?a3]
|
||||||
|
|
||||||
|
:where ['[?li :journal-entry-line/account ?a3]]}
|
||||||
|
:args [account-id]})))
|
||||||
|
|
||||||
(defn fetch-ids [db {:keys [query-params route-params] :as request}]
|
(defn fetch-ids [db {:keys [query-params route-params] :as request}]
|
||||||
(let [valid-clients (extract-client-ids (:clients request)
|
(let [valid-clients (extract-client-ids (:clients request)
|
||||||
(:client-id request)
|
(:client-id request)
|
||||||
@@ -288,9 +319,7 @@
|
|||||||
'[(<= ?c ?to-numeric-code)]]}
|
'[(<= ?c ?to-numeric-code)]]}
|
||||||
:args [(map (juxt :from :to) (:numeric-code args))]})
|
:args [(map (juxt :from :to) (:numeric-code args))]})
|
||||||
(seq (:account args))
|
(seq (:account args))
|
||||||
(merge-query {:query {:in ['?a3]
|
(merge-query (account-filter-query db valid-clients (:db/id (:account args))))
|
||||||
:where ['[?li :journal-entry-line/account ?a3]]}
|
|
||||||
:args [(:db/id (:account args))]})
|
|
||||||
|
|
||||||
(:amount-gte args)
|
(:amount-gte args)
|
||||||
(merge-query {:query {:in ['?amount-gte]
|
(merge-query {:query {:in ['?amount-gte]
|
||||||
|
|||||||
Reference in New Issue
Block a user