Allows making rules by client group

This commit is contained in:
2024-02-08 15:56:46 -08:00
parent a5e6b0549d
commit c290c34ec7
8 changed files with 75 additions and 23 deletions

View File

@@ -70,12 +70,20 @@
:class "hot-filter"
:value (:description (:parsed-query-params request))
:placeholder "LOWES"
:size :small}))
(com/field {:label "Client group"}
(com/text-input {:name "client-group"
:id "client-group"
:class "hot-filter"
:value (:client-group (:parsed-query-params request))
:placeholder "NTG"
:size :small}))]])
(def default-read '[:db/id
:transaction-rule/description
:transaction-rule/note
:transaction-rule/amount-lte
:transaction-rule/client-group
:transaction-rule/amount-gte
:transaction-rule/dom-lte
:transaction-rule/dom-gte
@@ -139,6 +147,11 @@
'[(clojure.string/includes? ?d2 ?description)]]}
:args [(clojure.string/lower-case (:description query-params))]})
(not (str/blank? (:client-group query-params)))
(merge-query {:query {:in ['?client-group]
:where ['[?e :transaction-rule/client-group ?client-group] ]}
:args [(clojure.string/upper-case (:client-group query-params))]})
true
(merge-query {:query {:find ['?e]
:where ['[?e :transaction-rule/transaction-approval-status]]}}))]
@@ -198,7 +211,8 @@
:headers [{:key "client"
:name "Client"
:sort-key "client"
:render #(-> % :transaction-rule/client :client/name)}
:render #(or (-> % :transaction-rule/client :client/name)
(some->> % :transaction-rule/client-group (str "group ") (com/pill {:color :primary})))}
{:key "bank-account"
:name "Bank account"
:sort-key "bank-account"
@@ -281,7 +295,7 @@
:db/id
[:transaction/date :xform clj-time.coerce/from-date]])
(defn transactions-matching-rule [{{:transaction-rule/keys [description client bank-account amount-lte amount-gte dom-lte dom-gte]}
(defn transactions-matching-rule [{{:transaction-rule/keys [description client bank-account amount-lte amount-gte dom-lte dom-gte client-group]}
:entity
clients :clients
only-uncoded? :only-uncoded?}]
@@ -297,7 +311,11 @@
(merge-query {:query {:in ['?descr]
:where ['[(iol-ion.query/->pattern ?descr) ?description-regex]]}
:args [description]})
client-group
(merge-query {:query {:in ['?client-group]
:where ['[?e :transaction/client ?client-group-client]
'[?client-group-client :client/groups ?client-group]]}
:args [client-group]})
valid-clients
(merge-query {:query {:in ['[?xx ...]]
:where ['[?e :transaction/client ?xx]]}
@@ -553,6 +571,7 @@
[:map
[:db/id {:optional true} [:maybe entity-id]]
[:transaction-rule/client {:optional true} [:maybe entity-id]]
[:transaction-rule/client-group {:optional true} [:maybe :string]]
[:transaction-rule/description [:and regex
[:string {:min 3}]]]
[:transaction-rule/bank-account [:maybe entity-id]]
@@ -652,6 +671,7 @@
:class "w-96"
:value (fc/field-value)})))
[:div.filters {:x-data (hx/json {:clientFilter (boolean (fc/field-value (:transaction-rule/client fc/*current*)))
:clientGroupFilter (boolean (fc/field-value (:transaction-rule/client-group fc/*current*)))
:bankAccountFilter (boolean (fc/field-value (:transaction-rule/bank-account fc/*current*)))
:amountFilter (boolean (or (fc/field-value (:transaction-rule/amount-gte fc/*current*))
(fc/field-value (:transaction-rule/amount-lte fc/*current*))))
@@ -661,6 +681,8 @@
[:div.flex.gap-2.mb-2
(com/a-button {"@click" "clientFilter=true"
"x-show" "!clientFilter"} "Filter client")
(com/a-button {"@click" "clientGroupFilter=true"
"x-show" "!clientGroupFilter"} "Filter client group")
(com/a-button {"@click" "bankAccountFilter=true"
"x-show" "clientFilter && !bankAccountFilter"} "Filter bank account")
(com/a-button {"@click" "amountFilter=true"
@@ -683,7 +705,19 @@
:x-model "clientId"
:value (fc/field-value)
:content-fn (fn [c] (pull-attr (dc/db conn) :client/name c))})]))
(fc/with-field :transaction-rule/client-group
(com/validated-field
(-> {:label "Client Group"
:errors (fc/field-errors)
:x-show "clientGroupFilter"}
(hx/alpine-appear))
[:div.w-96
(com/text-input {:name (fc/field-name)
:error? (fc/error?)
:class "w-24"
:placeholder "NTG"
:value (fc/field-value)})]))
(fc/with-field :transaction-rule/bank-account
(com/validated-field
(-> {:label "Bank Account"
@@ -846,6 +880,7 @@
(let [transaction-rule (:snapshot multi-form-state)
_ (validate-transaction-rule transaction-rule)
entity (cond-> transaction-rule
(:transaction-rule/client-group transaction-rule) (update :transaction-rule/client-group str/upper-case)
(= :post request-method) (assoc :db/id "new")
true (assoc :transaction-rule/note (entity->note transaction-rule)))
{:keys [tempids]} (audit-transact [[:upsert-entity entity]]