Search by financial account
This commit is contained in:
@@ -35,61 +35,62 @@
|
||||
:name (first name)})))
|
||||
|
||||
|
||||
(defn account-search [{{:keys [q client-id purpose vendor-id] :as qp} :query-params id :identity}]
|
||||
(when client-id
|
||||
(assert-can-see-client id client-id))
|
||||
(let [num (some-> (re-find #"([0-9]+)" q)
|
||||
second
|
||||
(not-empty)
|
||||
Integer/parseInt)
|
||||
(defn account-search [{{:keys [q client-id purpose vendor-id] :as qp} :query-params id :identity :as request}]
|
||||
(let [client-id (or client-id (:db/id (:client request)))]
|
||||
(when client-id
|
||||
(assert-can-see-client id client-id))
|
||||
(let [num (some-> (re-find #"([0-9]+)" q)
|
||||
second
|
||||
(not-empty)
|
||||
Integer/parseInt)
|
||||
|
||||
valid-allowances (cond-> #{:allowance/allowed
|
||||
:allowance/warn}
|
||||
(is-admin? id) (conj :allowance/admin-only))
|
||||
allowance (cond (= purpose "vendor")
|
||||
:account/vendor-allowance
|
||||
(= purpose "invoice")
|
||||
:account/invoice-allowance
|
||||
:else
|
||||
:account/default-allowance)
|
||||
valid-allowances (cond-> #{:allowance/allowed
|
||||
:allowance/warn}
|
||||
(is-admin? id) (conj :allowance/admin-only))
|
||||
allowance (cond (= purpose "vendor")
|
||||
:account/vendor-allowance
|
||||
(= purpose "invoice")
|
||||
:account/invoice-allowance
|
||||
:else
|
||||
:account/default-allowance)
|
||||
|
||||
vendor-account (when vendor-id
|
||||
(-> (dc/q '[:find ?da
|
||||
:in $ ?v
|
||||
:where [?v :vendor/default-account ?da]]
|
||||
(dc/db conn)
|
||||
vendor-id)
|
||||
ffirst))
|
||||
xform (comp
|
||||
(filter (fn [[_ a]]
|
||||
(or
|
||||
(valid-allowances (-> a allowance :db/ident))
|
||||
(= (:db/id a) vendor-account))))
|
||||
(map (fn [[n a]]
|
||||
{:label (str (:account/numeric-code a) " - " n)
|
||||
:value (:db/id a)
|
||||
:location (:account/location a)
|
||||
:warning (when (= :allowance/warn (-> a allowance :db/ident))
|
||||
"This account is not typically used for this purpose.")})))]
|
||||
{:body (take 10 (if q
|
||||
(if num
|
||||
(->> (dc/q '[:find ?n (pull ?i pattern)
|
||||
:in $ ?numeric-code ?allowance pattern
|
||||
:where [?i :account/numeric-code ?numeric-code]
|
||||
[?i :account/name ?n]
|
||||
(or [?i :account/applicability :account-applicability/global]
|
||||
[?i :account/applicability :account-applicability/optional]
|
||||
[?i :account/applicability :account-applicability/customized])]
|
||||
(dc/db conn)
|
||||
num
|
||||
allowance
|
||||
search-pattern)
|
||||
(sequence xform))
|
||||
(->> (search- id q client-id)
|
||||
(sequence
|
||||
(comp (map (fn [i] [(:name i) (dc/pull (dc/db conn) search-pattern (:account_id i))]))
|
||||
xform))))
|
||||
[]))}))
|
||||
vendor-account (when vendor-id
|
||||
(-> (dc/q '[:find ?da
|
||||
:in $ ?v
|
||||
:where [?v :vendor/default-account ?da]]
|
||||
(dc/db conn)
|
||||
vendor-id)
|
||||
ffirst))
|
||||
xform (comp
|
||||
(filter (fn [[_ a]]
|
||||
(or
|
||||
(valid-allowances (-> a allowance :db/ident))
|
||||
(= (:db/id a) vendor-account))))
|
||||
(map (fn [[n a]]
|
||||
{:label (str (:account/numeric-code a) " - " n)
|
||||
:value (:db/id a)
|
||||
:location (:account/location a)
|
||||
:warning (when (= :allowance/warn (-> a allowance :db/ident))
|
||||
"This account is not typically used for this purpose.")})))]
|
||||
{:body (take 10 (if q
|
||||
(if num
|
||||
(->> (dc/q '[:find ?n (pull ?i pattern)
|
||||
:in $ ?numeric-code ?allowance pattern
|
||||
:where [?i :account/numeric-code ?numeric-code]
|
||||
[?i :account/name ?n]
|
||||
(or [?i :account/applicability :account-applicability/global]
|
||||
[?i :account/applicability :account-applicability/optional]
|
||||
[?i :account/applicability :account-applicability/customized])]
|
||||
(dc/db conn)
|
||||
num
|
||||
allowance
|
||||
search-pattern)
|
||||
(sequence xform))
|
||||
(->> (search- id q client-id)
|
||||
(sequence
|
||||
(comp (map (fn [i] [(:name i) (dc/pull (dc/db conn) search-pattern (:account_id i))]))
|
||||
xform))))
|
||||
[]))})))
|
||||
|
||||
(def account-search (wrap-json-response (wrap-schema-enforce account-search
|
||||
:query-schema [:map
|
||||
|
||||
@@ -84,6 +84,14 @@
|
||||
:value (:vendor (:query-params request))
|
||||
:value-fn :db/id
|
||||
:content-fn :vendor/name}))
|
||||
(com/field {:label "Account"}
|
||||
(com/typeahead {:name "account"
|
||||
:id "account"
|
||||
:url (bidi/path-for ssr-routes/only-routes :account-search)
|
||||
:value (:account (:query-params request))
|
||||
:value-fn :db/id
|
||||
:content-fn #(:account/name (d-accounts/clientize (dc/pull (dc/db conn) d-accounts/default-read (:db/id %))
|
||||
(:db/id (:client request))))}))
|
||||
(date-range-field* request)
|
||||
(com/field {:label "Check #"}
|
||||
(com/text-input {:name "check-number"
|
||||
@@ -99,7 +107,7 @@
|
||||
:value (:invoice-number (:query-params request))
|
||||
:placeholder "e.g., ABC-456"
|
||||
:size :small}))
|
||||
|
||||
|
||||
(com/field {:label "Amount"}
|
||||
[:div.flex.space-x-4.items-baseline
|
||||
(com/money-input {:name "amount-gte"
|
||||
@@ -179,11 +187,11 @@
|
||||
:where ['[?e :invoice/vendor ?vendor-id]]}
|
||||
:args [(:db/id (:vendor query-params))]})
|
||||
|
||||
(:account-id query-params)
|
||||
(:account query-params)
|
||||
(merge-query {:query {:in ['?account-id]
|
||||
:where ['[?e :invoice/expense-accounts ?iea ?]
|
||||
'[?iea :invoice-expense-account/account ?account-id]]}
|
||||
:args [(:account-id query-params)]})
|
||||
:args [(:db/id (:account query-params))]})
|
||||
|
||||
(:amount-gte query-params)
|
||||
(merge-query {:query {:in ['?amount-gte]
|
||||
@@ -296,6 +304,7 @@
|
||||
[:amount-gte {:optional true} [:maybe :double]]
|
||||
[:amount-lte {:optional true} [:maybe :double]]
|
||||
[:vendor {:optional true :default nil} [:maybe [:entity-map {:pull [:db/id :vendor/name]}]]]
|
||||
[:account {:optional true :default nil} [:maybe [:entity-map {:pull [:db/id :account/name]}]]]
|
||||
[:check-number {:optional true} [:maybe [:string {:decode/string strip}]]]
|
||||
[:invoice-number {:optional true} [:maybe [:string {:decode/string strip}]]]
|
||||
[:status {:optional true} [:maybe (ref->enum-schema "invoice-status")]]
|
||||
|
||||
Reference in New Issue
Block a user