Makes it so vendors and invoices respect allowances.
This commit is contained in:
@@ -74,50 +74,74 @@
|
||||
(->graphql
|
||||
(d-accounts/get-by-id (or id (get-in result [:tempids "new-account"])))))))
|
||||
|
||||
(defn search [context {query :query client :client_id} _]
|
||||
(defn search [context {query :query client :client_id allowance :allowance} _]
|
||||
(when client
|
||||
(assert-can-see-client (:id context) client))
|
||||
(let [query (cleanse-query query)
|
||||
num (some-> (re-find #"([0-9]+)" query)
|
||||
second
|
||||
(not-empty )
|
||||
Integer/parseInt)]
|
||||
Integer/parseInt)
|
||||
|
||||
pattern [:db/id :account/numeric-code :account/location {:account/vendor-allowance [:db/ident]} {:account/invoice-allowance [:db/ident]}]
|
||||
allowance (cond (= allowance :vendor)
|
||||
:account/vendor-allowance
|
||||
(= allowance :invoice)
|
||||
:account/invoice-allowance
|
||||
:else
|
||||
:account/default-allowance)]
|
||||
(if query
|
||||
(if num
|
||||
(->> (d/q '[:find ?n (pull ?i [:db/id :account/numeric-code :account/location])
|
||||
:in $ ?numeric-code
|
||||
(->> (d/q '[:find ?n (pull ?i pattern)
|
||||
:in $ ?numeric-code ?allowance pattern
|
||||
:where [?i :account/numeric-code ?numeric-code]
|
||||
[?i :account/name ?n]]
|
||||
[?i :account/name ?n]
|
||||
(or [?i ?allowance :allowance/allowed]
|
||||
[?i ?allowance :allowance/warn])]
|
||||
(d/db conn)
|
||||
num)
|
||||
num
|
||||
allowance
|
||||
pattern)
|
||||
(map (fn [[n a]]
|
||||
{:name (str (:account/numeric-code a) " - " n)
|
||||
:id (:db/id a)
|
||||
:location (:account/location a)})))
|
||||
:location (:account/location a)
|
||||
:warning (when (= :allowance/warn (-> a allowance :db/ident))
|
||||
"This account is not typically used for this purpose.")})))
|
||||
|
||||
(->> (d/q '[:find ?n (pull ?i [:db/id :account/numeric-code :account/location]) ?s
|
||||
:in $ ?q
|
||||
(->> (d/q '[:find ?n (pull ?i pattern) ?s
|
||||
:in $ ?q ?allowance pattern
|
||||
:where [(fulltext $ :account/search-terms ?q) [[?i ?n _ ?s]]]
|
||||
[?i :account/numeric-code ?numeric-code]
|
||||
(or [?i ?allowance :allowance/allowed]
|
||||
[?i ?allowance :allowance/warn])
|
||||
(or [?i :account/applicability :account-applicability/global]
|
||||
[?i :account/applicability :account-applicability/optional])]
|
||||
(d/db conn)
|
||||
query)
|
||||
query
|
||||
allowance
|
||||
pattern)
|
||||
(concat (when client
|
||||
(d/q '[:find ?n (pull ?a [:db/id :account/numeric-code :account/location]) ?s
|
||||
:in $ ?c ?q
|
||||
(d/q '[:find ?n (pull ?a pattern) ?s
|
||||
:in $ ?c ?q ?allowance pattern
|
||||
:where
|
||||
[?i :account-client-override/client ?c]
|
||||
[(fulltext $ :account-client-override/search-terms ?q) [[?i ?n _ ?s]]]
|
||||
[?a :account/client-overrides ?i]
|
||||
[?a :account/numeric-code ?numeric-code]]
|
||||
[?a :account/numeric-code ?numeric-code]
|
||||
(or [?a ?allowance :allowance/allowed]
|
||||
[?a ?allowance :allowance/warn])]
|
||||
(d/db conn)
|
||||
client
|
||||
query)))
|
||||
query
|
||||
allowance
|
||||
pattern)))
|
||||
(sort-by (comp - last))
|
||||
(map (fn [[n a]]
|
||||
{:name (str (:account/numeric-code a) " - " n)
|
||||
:id (:db/id a)
|
||||
:location (:account/location a)}))))
|
||||
:location (:account/location a)
|
||||
:warning (when (= :allowance/warn (-> a allowance :db/ident))
|
||||
"This account is not typically used for this purpose.")}))))
|
||||
[])))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user