Add vendor pre-population for bulk code and individual edit forms
- Add vendor-changed HTMX handlers for both bulk code and individual edit - Pre-populate default account at 100% when vendor is selected and no accounts exist - Fix render-accounts-section to render from step-params correctly - Change bulk code vendor-changed from hx-get to hx-post to include form data - Add routes for vendor-changed endpoints - Update e2e tests to cover vendor pre-population - Run lein cljfmt fix across codebase
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
(ns auto-ap.ssr.transaction.common
|
||||
(ns auto-ap.ssr.transaction.common
|
||||
(:require
|
||||
[auto-ap.datomic :refer [add-sorter-fields apply-pagination apply-sort-4
|
||||
conn merge-query observable-query pull-many]]
|
||||
[auto-ap.datomic.accounts :as d-accounts]
|
||||
[auto-ap.graphql.utils :refer [extract-client-ids is-admin?]]
|
||||
[auto-ap.datomic :refer [add-sorter-fields apply-pagination apply-sort-4
|
||||
conn merge-query observable-query pull-many]]
|
||||
[auto-ap.datomic.accounts :as d-accounts]
|
||||
[auto-ap.graphql.utils :refer [extract-client-ids is-admin?]]
|
||||
[auto-ap.routes.invoice :as invoice-routes]
|
||||
[auto-ap.routes.ledger :as ledger-routes]
|
||||
[auto-ap.routes.payments :as payment-routes]
|
||||
@@ -33,26 +33,26 @@
|
||||
[:amount-gte {:optional true} [:maybe :double]]
|
||||
[:amount-lte {:optional true} [:maybe :double]]
|
||||
[:client-id {:optional true} [:maybe entity-id]]
|
||||
[:import-batch-id {:optional true} [:maybe entity-id]]
|
||||
[:unresolved {:optional true}
|
||||
[:maybe [:boolean {:decode/string {:enter #(cond (= % "on") true
|
||||
(= % "") false
|
||||
:else
|
||||
(boolean %))}}]]]
|
||||
[:description {:optional true} [:maybe [:string {:decode/string strip}]]]
|
||||
[:vendor {:optional true :default nil} [:maybe [:entity-map {:pull [:db/id :vendor/name]}]]]
|
||||
[:bank-account {:optional true :default nil} [:maybe [:entity-map {:pull [:db/id :bank-account/numeric-code]}]]]
|
||||
[:account {:optional true :default nil} [:maybe [:entity-map {:pull [:db/id :account/name]}]]]
|
||||
[:linked-to {:optional true}
|
||||
[:maybe [:enum {:decode/string {:enter #(if (seq %) % nil)}}
|
||||
"payment" "expected-deposit" "invoice" "none"]]]
|
||||
[:location {:optional true} [:maybe [:string {:decode/string strip}]]]
|
||||
[:potential-duplicates {:optional true}
|
||||
[:maybe [:boolean {:decode/string {:enter #(cond (= % "on") true
|
||||
(= % "") false
|
||||
:else
|
||||
(boolean %))}}]]]
|
||||
#_[:status {:optional true} [:maybe (ref->enum-schema "transaction-status")]]
|
||||
[:import-batch-id {:optional true} [:maybe entity-id]]
|
||||
[:unresolved {:optional true}
|
||||
[:maybe [:boolean {:decode/string {:enter #(cond (= % "on") true
|
||||
(= % "") false
|
||||
:else
|
||||
(boolean %))}}]]]
|
||||
[:description {:optional true} [:maybe [:string {:decode/string strip}]]]
|
||||
[:vendor {:optional true :default nil} [:maybe [:entity-map {:pull [:db/id :vendor/name]}]]]
|
||||
[:bank-account {:optional true :default nil} [:maybe [:entity-map {:pull [:db/id :bank-account/numeric-code]}]]]
|
||||
[:account {:optional true :default nil} [:maybe [:entity-map {:pull [:db/id :account/name]}]]]
|
||||
[:linked-to {:optional true}
|
||||
[:maybe [:enum {:decode/string {:enter #(if (seq %) % nil)}}
|
||||
"payment" "expected-deposit" "invoice" "none"]]]
|
||||
[:location {:optional true} [:maybe [:string {:decode/string strip}]]]
|
||||
[:potential-duplicates {:optional true}
|
||||
[:maybe [:boolean {:decode/string {:enter #(cond (= % "on") true
|
||||
(= % "") false
|
||||
:else
|
||||
(boolean %))}}]]]
|
||||
#_[:status {:optional true} [:maybe (ref->enum-schema "transaction-status")]]
|
||||
[:exact-match-id {:optional true} [:maybe entity-id]]
|
||||
[:all-selected {:optional true :default nil} [:maybe :boolean]]
|
||||
[:selected {:optional true :default nil} [:maybe [:vector {:coerce? true}
|
||||
@@ -66,14 +66,14 @@
|
||||
'[:transaction/amount
|
||||
:transaction/description-original
|
||||
:transaction/description-simple
|
||||
[ :transaction/date :xform clj-time.coerce/from-date]
|
||||
[ :transaction/post-date :xform clj-time.coerce/from-date]
|
||||
[:transaction/date :xform clj-time.coerce/from-date]
|
||||
[:transaction/post-date :xform clj-time.coerce/from-date]
|
||||
:transaction/type
|
||||
:transaction/status
|
||||
:transaction/client-overrides
|
||||
:db/id
|
||||
{:transaction/vendor [:vendor/name :db/id]
|
||||
:transaction/client [:client/name :client/code :db/id [ :client/locked-until :xform clj-time.coerce/from-date]]
|
||||
:transaction/client [:client/name :client/code :db/id [:client/locked-until :xform clj-time.coerce/from-date]]
|
||||
:transaction/bank-account [:bank-account/numeric-code :bank-account/name]
|
||||
:transaction/accounts [{:transaction-account/account [:account/name :db/id]}
|
||||
:transaction-account/location
|
||||
@@ -104,13 +104,13 @@
|
||||
[all-ids]
|
||||
(->> all-ids
|
||||
(dc/q '[:find ?t
|
||||
:in $ [?t ...]
|
||||
:where
|
||||
[?t :transaction/client ?c]
|
||||
[(get-else $ ?c :client/locked-until #inst "2000-01-01") ?lu]
|
||||
[?t :transaction/date ?d]
|
||||
[(>= ?d ?lu)]]
|
||||
(dc/db conn))
|
||||
:in $ [?t ...]
|
||||
:where
|
||||
[?t :transaction/client ?c]
|
||||
[(get-else $ ?c :client/locked-until #inst "2000-01-01") ?lu]
|
||||
[?t :transaction/date ?d]
|
||||
[(>= ?d ?lu)]]
|
||||
(dc/db conn))
|
||||
(map first)))
|
||||
|
||||
(defn fetch-ids [db {:keys [query-params route-params] :as request}]
|
||||
@@ -161,75 +161,75 @@
|
||||
:where ['[?e :transaction/bank-account ?ba]]}
|
||||
:args [(:db/id (:bank-account args))]})
|
||||
|
||||
(:vendor args)
|
||||
(merge-query {:query {:in ['?vendor-id]
|
||||
:where ['[?e :transaction/vendor ?vendor-id]]}
|
||||
:args [(:db/id (:vendor args))]})
|
||||
(:vendor args)
|
||||
(merge-query {:query {:in ['?vendor-id]
|
||||
:where ['[?e :transaction/vendor ?vendor-id]]}
|
||||
:args [(:db/id (:vendor args))]})
|
||||
|
||||
(:db/id (:account args))
|
||||
(merge-query {:query {:in ['?account-id]
|
||||
:where ['[?e :transaction/accounts ?tas]
|
||||
'[?tas :transaction-account/account ?account-id]]}
|
||||
:args [(:db/id (:account args))]})
|
||||
(:import-batch-id args)
|
||||
(merge-query {:query {:in ['?import-batch-id]
|
||||
:where ['[?import-batch-id :import-batch/entry ?e]]}
|
||||
:args [(:import-batch-id args)]})
|
||||
(:db/id (:account args))
|
||||
(merge-query {:query {:in ['?account-id]
|
||||
:where ['[?e :transaction/accounts ?tas]
|
||||
'[?tas :transaction-account/account ?account-id]]}
|
||||
:args [(:db/id (:account args))]})
|
||||
(:import-batch-id args)
|
||||
(merge-query {:query {:in ['?import-batch-id]
|
||||
:where ['[?import-batch-id :import-batch/entry ?e]]}
|
||||
:args [(:import-batch-id args)]})
|
||||
|
||||
(:unresolved args)
|
||||
(merge-query {:query {:where ['[?e :transaction/date]
|
||||
'(or-join [?e]
|
||||
(not [?e :transaction/accounts])
|
||||
(and [?e :transaction/accounts ?tas]
|
||||
(not [?tas :transaction-account/account]))) ]}})
|
||||
(:unresolved args)
|
||||
(merge-query {:query {:where ['[?e :transaction/date]
|
||||
'(or-join [?e]
|
||||
(not [?e :transaction/accounts])
|
||||
(and [?e :transaction/accounts ?tas]
|
||||
(not [?tas :transaction-account/account])))]}})
|
||||
|
||||
(seq (:location args))
|
||||
(merge-query {:query {:in ['?location]
|
||||
:where ['[?e :transaction/accounts ?tas]
|
||||
'[?tas :transaction-account/location ?location]]}
|
||||
:args [(:location args)]})
|
||||
(seq (:location args))
|
||||
(merge-query {:query {:in ['?location]
|
||||
:where ['[?e :transaction/accounts ?tas]
|
||||
'[?tas :transaction-account/location ?location]]}
|
||||
:args [(:location args)]})
|
||||
|
||||
(= (:linked-to args) "payment")
|
||||
(merge-query {:query {:where ['[?e :transaction/payment]]}})
|
||||
(= (:linked-to args) "payment")
|
||||
(merge-query {:query {:where ['[?e :transaction/payment]]}})
|
||||
|
||||
(= (:linked-to args) "expected-deposit")
|
||||
(merge-query {:query {:where ['[?e :transaction/expected-deposit]]}})
|
||||
(= (:linked-to args) "expected-deposit")
|
||||
(merge-query {:query {:where ['[?e :transaction/expected-deposit]]}})
|
||||
|
||||
(= (:linked-to args) "invoice")
|
||||
(merge-query {:query {:where ['[?e :transaction/payment ?p]
|
||||
'[_ :invoice-payment/payment ?p]]}})
|
||||
(= (:linked-to args) "invoice")
|
||||
(merge-query {:query {:where ['[?e :transaction/payment ?p]
|
||||
'[_ :invoice-payment/payment ?p]]}})
|
||||
|
||||
(= (:linked-to args) "none")
|
||||
(merge-query {:query {:where ['(not [?e :transaction/payment])
|
||||
'(not [?e :transaction/expected-deposit])]}})
|
||||
(= (:linked-to args) "none")
|
||||
(merge-query {:query {:where ['(not [?e :transaction/payment])
|
||||
'(not [?e :transaction/expected-deposit])]}})
|
||||
|
||||
(:potential-duplicates args)
|
||||
(merge-query (let [bank-account-id (:db/id (:bank-account args))
|
||||
_ (when-not bank-account-id
|
||||
(throw (ex-info "In order to select potential duplicates, you must choose a bank account."
|
||||
{:validation-error "In order to select potential duplicates, you must choose a bank account."})))
|
||||
duplicate-ids (->> (dc/q '[:find ?tx ?amount ?date
|
||||
:in $ ?ba
|
||||
:where
|
||||
[?tx :transaction/bank-account ?ba]
|
||||
[?tx :transaction/amount ?amount]
|
||||
[?tx :transaction/date ?date]
|
||||
(not [?tx :transaction/approval-status :transaction-approval-status/suppressed])]
|
||||
db
|
||||
bank-account-id)
|
||||
(group-by (fn [[_ amount date]]
|
||||
[amount date]))
|
||||
(filter (fn [[_ txes]]
|
||||
(> (count txes) 1)))
|
||||
(vals)
|
||||
(mapcat identity)
|
||||
(map first)
|
||||
set)]
|
||||
{:query {:in '[[?e ...]]
|
||||
:where []}
|
||||
:args [duplicate-ids]}))
|
||||
(:potential-duplicates args)
|
||||
(merge-query (let [bank-account-id (:db/id (:bank-account args))
|
||||
_ (when-not bank-account-id
|
||||
(throw (ex-info "In order to select potential duplicates, you must choose a bank account."
|
||||
{:validation-error "In order to select potential duplicates, you must choose a bank account."})))
|
||||
duplicate-ids (->> (dc/q '[:find ?tx ?amount ?date
|
||||
:in $ ?ba
|
||||
:where
|
||||
[?tx :transaction/bank-account ?ba]
|
||||
[?tx :transaction/amount ?amount]
|
||||
[?tx :transaction/date ?date]
|
||||
(not [?tx :transaction/approval-status :transaction-approval-status/suppressed])]
|
||||
db
|
||||
bank-account-id)
|
||||
(group-by (fn [[_ amount date]]
|
||||
[amount date]))
|
||||
(filter (fn [[_ txes]]
|
||||
(> (count txes) 1)))
|
||||
(vals)
|
||||
(mapcat identity)
|
||||
(map first)
|
||||
set)]
|
||||
{:query {:in '[[?e ...]]
|
||||
:where []}
|
||||
:args [duplicate-ids]}))
|
||||
|
||||
(:status route-params)
|
||||
(:status route-params)
|
||||
(merge-query {:query {:in ['?status]
|
||||
:where ['[?e :transaction/approval-status ?status]]}
|
||||
:args [(:status route-params)]})
|
||||
@@ -253,8 +253,8 @@
|
||||
(->> (observable-query query)
|
||||
(apply-sort-4 (assoc query-params :default-asc? true))
|
||||
(apply-pagination query-params))))
|
||||
|
||||
(defn fetch-page [request]
|
||||
|
||||
(defn fetch-page [request]
|
||||
(let [db (dc/db conn)
|
||||
{ids-to-retrieve :ids matching-count :count
|
||||
all-ids :all-ids} (fetch-ids db request)]
|
||||
@@ -263,8 +263,6 @@
|
||||
matching-count
|
||||
(sum-amount all-ids)]))
|
||||
|
||||
|
||||
|
||||
(defn exact-match-id* [request]
|
||||
(if (nat-int? (:exact-match-id (:query-params request)))
|
||||
[:div {:x-data (hx/json {:exact_match (:exact-match-id (:query-params request))}) :id "exact-match-id-tag"}
|
||||
@@ -290,8 +288,6 @@
|
||||
(com/link {"@click" "import_batch_id=null; $nextTick(() => $dispatch('change'))"}
|
||||
svg/x)]])]))
|
||||
|
||||
|
||||
|
||||
(defn bank-account-filter* [request]
|
||||
[:div {:hx-trigger "clientSelected from:body"
|
||||
:hx-get (bidi.bidi/path-for ssr-routes/only-routes ::route/bank-account-filter)
|
||||
@@ -313,7 +309,6 @@
|
||||
{:value (:db/id ba)
|
||||
:content (:bank-account/name ba)}))}))))])
|
||||
|
||||
|
||||
(defn filters [request]
|
||||
[:form#transaction-filters {"hx-trigger" "change delay:500ms, keyup changed from:.hot-filter delay:1000ms"
|
||||
"hx-get" (bidi/path-for ssr-routes/only-routes
|
||||
@@ -324,94 +319,93 @@
|
||||
(com/hidden {:name "status"
|
||||
:value (some-> (:status (:query-params request)) name)})
|
||||
[:fieldset.space-y-6
|
||||
(com/field {:label "Vendor"}
|
||||
(com/typeahead {:name "vendor"
|
||||
:id "vendor"
|
||||
:url (bidi/path-for ssr-routes/only-routes :vendor-search)
|
||||
:value (:vendor (:query-params request))
|
||||
:value-fn :db/id
|
||||
:content-fn :vendor/name}))
|
||||
(com/field {:label "Financial 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))))}))
|
||||
(bank-account-filter* request)
|
||||
(com/field {:label "Vendor"}
|
||||
(com/typeahead {:name "vendor"
|
||||
:id "vendor"
|
||||
:url (bidi/path-for ssr-routes/only-routes :vendor-search)
|
||||
:value (:vendor (:query-params request))
|
||||
:value-fn :db/id
|
||||
:content-fn :vendor/name}))
|
||||
(com/field {:label "Financial 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))))}))
|
||||
(bank-account-filter* request)
|
||||
|
||||
(date-range-field* request)
|
||||
(com/field {:label "Description"}
|
||||
(com/text-input {:name "description"
|
||||
:id "description"
|
||||
:class "hot-filter"
|
||||
:value (:description (:query-params request))
|
||||
:placeholder "e.g., Groceries"
|
||||
:size :small}))
|
||||
(com/field {:label "Description"}
|
||||
(com/text-input {:name "description"
|
||||
:id "description"
|
||||
:class "hot-filter"
|
||||
:value (:description (:query-params request))
|
||||
:placeholder "e.g., Groceries"
|
||||
:size :small}))
|
||||
|
||||
(com/field {:label "Location"}
|
||||
(com/text-input {:name "location"
|
||||
:id "location"
|
||||
:class "hot-filter"
|
||||
:value (:location (:query-params request))
|
||||
:placeholder "SC"
|
||||
:size :small}))
|
||||
(com/field {:label "Location"}
|
||||
(com/text-input {:name "location"
|
||||
:id "location"
|
||||
:class "hot-filter"
|
||||
:value (:location (:query-params request))
|
||||
:placeholder "SC"
|
||||
:size :small}))
|
||||
|
||||
(com/field {:label "Amount"}
|
||||
[:div.flex.space-x-4.items-baseline
|
||||
(com/money-input {:name "amount-gte"
|
||||
:id "amount-gte"
|
||||
:hx-preserve "true"
|
||||
:class "hot-filter w-20"
|
||||
:value (:amount-gte (:query-params request))
|
||||
:placeholder "0.01"
|
||||
:size :small})
|
||||
[:div.align-baseline
|
||||
"to"]
|
||||
(com/money-input {:name "amount-lte"
|
||||
:hx-preserve "true"
|
||||
:id "amount-lte"
|
||||
:class "hot-filter w-20"
|
||||
:value (:amount-lte (:query-params request))
|
||||
:placeholder "9999.34"
|
||||
:size :small})])
|
||||
(com/field {:label "Amount"}
|
||||
[:div.flex.space-x-4.items-baseline
|
||||
(com/money-input {:name "amount-gte"
|
||||
:id "amount-gte"
|
||||
:hx-preserve "true"
|
||||
:class "hot-filter w-20"
|
||||
:value (:amount-gte (:query-params request))
|
||||
:placeholder "0.01"
|
||||
:size :small})
|
||||
[:div.align-baseline
|
||||
"to"]
|
||||
(com/money-input {:name "amount-lte"
|
||||
:hx-preserve "true"
|
||||
:id "amount-lte"
|
||||
:class "hot-filter w-20"
|
||||
:value (:amount-lte (:query-params request))
|
||||
:placeholder "9999.34"
|
||||
:size :small})])
|
||||
|
||||
(com/field {:label "Linking"}
|
||||
(com/radio-card {:size :small
|
||||
:name "linked-to"
|
||||
:value (or (:linked-to (:query-params request)) "")
|
||||
:options [{:value ""
|
||||
:content "All"}
|
||||
{:value "none"
|
||||
:content "None"}
|
||||
{:value "invoice"
|
||||
:content "Invoice"}
|
||||
{:value "expected-deposit"
|
||||
:content "Expected Deposit"}
|
||||
{:value "payment"
|
||||
:content "Payment"}]}))
|
||||
(com/field {:label "Linking"}
|
||||
(com/radio-card {:size :small
|
||||
:name "linked-to"
|
||||
:value (or (:linked-to (:query-params request)) "")
|
||||
:options [{:value ""
|
||||
:content "All"}
|
||||
{:value "none"
|
||||
:content "None"}
|
||||
{:value "invoice"
|
||||
:content "Invoice"}
|
||||
{:value "expected-deposit"
|
||||
:content "Expected Deposit"}
|
||||
{:value "payment"
|
||||
:content "Payment"}]}))
|
||||
|
||||
(when (is-admin? (:identity request))
|
||||
[:div.mt-4 {:x-data (hx/json {:unresolvedOnly (:unresolved (:query-params request))})}
|
||||
(com/hidden {:name "unresolved"
|
||||
":value" "unresolvedOnly ? 'on' : ''"})
|
||||
(com/checkbox {:value (:unresolved (:query-params request))
|
||||
:x-model "unresolvedOnly"}
|
||||
"Unresolved only")])
|
||||
(when (is-admin? (:identity request))
|
||||
[:div.mt-4 {:x-data (hx/json {:unresolvedOnly (:unresolved (:query-params request))})}
|
||||
(com/hidden {:name "unresolved"
|
||||
":value" "unresolvedOnly ? 'on' : ''"})
|
||||
(com/checkbox {:value (:unresolved (:query-params request))
|
||||
:x-model "unresolvedOnly"}
|
||||
"Unresolved only")])
|
||||
|
||||
(when (and (is-admin? (:identity request))
|
||||
(:db/id (:bank-account (:query-params request))))
|
||||
[:div.mt-4 {:x-data (hx/json {:potentialDuplicates (:potential-duplicates (:query-params request))})}
|
||||
(com/hidden {:name "potential-duplicates"
|
||||
":value" "potentialDuplicates ? 'on' : ''"})
|
||||
(com/checkbox {:value (:potential-duplicates (:query-params request))
|
||||
:x-model "potentialDuplicates"}
|
||||
"Same Amount + Date")])
|
||||
|
||||
(import-batch-id* request)
|
||||
(exact-match-id* request)]])
|
||||
(when (and (is-admin? (:identity request))
|
||||
(:db/id (:bank-account (:query-params request))))
|
||||
[:div.mt-4 {:x-data (hx/json {:potentialDuplicates (:potential-duplicates (:query-params request))})}
|
||||
(com/hidden {:name "potential-duplicates"
|
||||
":value" "potentialDuplicates ? 'on' : ''"})
|
||||
(com/checkbox {:value (:potential-duplicates (:query-params request))
|
||||
:x-model "potentialDuplicates"}
|
||||
"Same Amount + Date")])
|
||||
|
||||
(import-batch-id* request)
|
||||
(exact-match-id* request)]])
|
||||
|
||||
(def grid-page
|
||||
(helper/build {:id "entity-table"
|
||||
@@ -420,19 +414,17 @@
|
||||
:page-specific-nav filters
|
||||
:fetch-page fetch-page
|
||||
:query-schema query-schema
|
||||
:oob-render
|
||||
(fn [request]
|
||||
[(assoc-in (date-range-field* request) [1 :hx-swap-oob] true)
|
||||
(assoc-in (exact-match-id* request) [1 :hx-swap-oob] true)
|
||||
(some-> (import-batch-id* request) (assoc-in [1 :hx-swap-oob] true))])
|
||||
:oob-render
|
||||
(fn [request]
|
||||
[(assoc-in (date-range-field* request) [1 :hx-swap-oob] true)
|
||||
(assoc-in (exact-match-id* request) [1 :hx-swap-oob] true)
|
||||
(some-> (import-batch-id* request) (assoc-in [1 :hx-swap-oob] true))])
|
||||
:action-buttons (fn [request]
|
||||
[
|
||||
(com/button {:color :primary
|
||||
[(com/button {:color :primary
|
||||
:hx-get (bidi/path-for ssr-routes/only-routes ::route/bulk-code)
|
||||
:hx-target "#modal-holder"
|
||||
"x-bind:hx-vals" "JSON.stringify({selected: $data.selected, 'all-selected': $data.all_selected})"
|
||||
"hx-include" "#transaction-filters"
|
||||
}
|
||||
"hx-include" "#transaction-filters"}
|
||||
"Code")
|
||||
(com/button {:color :primary
|
||||
:hx-post (bidi/path-for ssr-routes/only-routes ::route/bulk-delete)
|
||||
@@ -454,13 +446,13 @@
|
||||
tx-date (:transaction/date entity)
|
||||
is-locked (and locked-until tx-date (time/before? tx-date locked-until))]
|
||||
(if is-locked
|
||||
[ [:div.p-3.rounded-full.bg-gray-50.text-gray-400.w-6.h-6.box-content
|
||||
svg/lock]]
|
||||
[[:div.p-3.rounded-full.bg-gray-50.text-gray-400.w-6.h-6.box-content
|
||||
svg/lock]]
|
||||
[(com/icon-button {:hx-get (bidi/path-for ssr-routes/only-routes
|
||||
::route/edit-wizard
|
||||
:db/id (:db/id entity))}
|
||||
svg/pencil)])))
|
||||
|
||||
::route/edit-wizard
|
||||
:db/id (:db/id entity))}
|
||||
svg/pencil)])))
|
||||
|
||||
:breadcrumbs [[:a {:href (bidi/path-for ssr-routes/only-routes ::route/page)}
|
||||
"Transactions"]]
|
||||
:title (fn [r]
|
||||
@@ -477,9 +469,7 @@
|
||||
(= (-> request :query-params :sort first :name) "Vendor")
|
||||
(or (-> entity :transaction/vendor :vendor/name)
|
||||
"No vendor")
|
||||
|
||||
|
||||
|
||||
|
||||
:else nil))
|
||||
:page->csv-entities (fn [[transactions]]
|
||||
transactions)
|
||||
@@ -529,20 +519,20 @@
|
||||
:render (fn [i]
|
||||
(let [db (dc/db conn)
|
||||
journal-entries (when (:db/id i)
|
||||
(dc/q '[:find (pull ?je [:db/id :journal-entry/id])
|
||||
:in $ ?t-id
|
||||
:where
|
||||
[?je :journal-entry/original-entity ?t-id]]
|
||||
db
|
||||
(:db/id i)))
|
||||
(dc/q '[:find (pull ?je [:db/id :journal-entry/id])
|
||||
:in $ ?t-id
|
||||
:where
|
||||
[?je :journal-entry/original-entity ?t-id]]
|
||||
db
|
||||
(:db/id i)))
|
||||
linked-invoices (when (and (:db/id i) (:transaction/payment i))
|
||||
(dc/q '[:find (pull ?inv [:db/id :invoice/invoice-number :invoice/total])
|
||||
:in $ ?payment-id
|
||||
:where
|
||||
[?ip :invoice-payment/payment ?payment-id]
|
||||
[?ip :invoice-payment/invoice ?inv]]
|
||||
db
|
||||
(:db/id (:transaction/payment i))))]
|
||||
(dc/q '[:find (pull ?inv [:db/id :invoice/invoice-number :invoice/total])
|
||||
:in $ ?payment-id
|
||||
:where
|
||||
[?ip :invoice-payment/payment ?payment-id]
|
||||
[?ip :invoice-payment/invoice ?inv]]
|
||||
db
|
||||
(:db/id (:transaction/payment i))))]
|
||||
(link-dropdown
|
||||
(cond-> []
|
||||
;; Payment link
|
||||
@@ -553,41 +543,36 @@
|
||||
{:exact-match-id (:db/id (:transaction/payment i))})
|
||||
:color :primary
|
||||
:content (format "Payment '%s'" (-> i :transaction/payment :payment/date (atime/unparse-local atime/normal-date)))})
|
||||
|
||||
|
||||
;; Journal entry links
|
||||
(seq journal-entries)
|
||||
(concat
|
||||
(for [[je] journal-entries]
|
||||
{:link (hu/url (bidi/path-for ssr-routes/only-routes ::ledger-routes/all-page)
|
||||
{:exact-match-id (:db/id je)})
|
||||
:color :yellow
|
||||
:content "Ledger entry"}))
|
||||
|
||||
{:exact-match-id (:db/id je)})
|
||||
:color :yellow
|
||||
:content "Ledger entry"}))
|
||||
|
||||
;; Invoice links
|
||||
(seq linked-invoices)
|
||||
(concat
|
||||
(for [[inv] linked-invoices]
|
||||
{:link (hu/url (bidi/path-for ssr-routes/only-routes
|
||||
::invoice-routes/all-page)
|
||||
::invoice-routes/all-page)
|
||||
{:exact-match-id (:db/id inv)})
|
||||
:color :secondary
|
||||
:content (format "Invoice '%s'" (:invoice/invoice-number inv))}))
|
||||
|
||||
))))
|
||||
:content (format "Invoice '%s'" (:invoice/invoice-number inv))}))))))
|
||||
|
||||
:render-for #{:html}}]}))
|
||||
(defn wrap-status-from-source [handler]
|
||||
(fn [{:keys [matched-current-page-route] :as request}]
|
||||
(let [ request (cond-> request
|
||||
(let [request (cond-> request
|
||||
(= ::route/unapproved-page matched-current-page-route) (assoc-in [:route-params :status] :transaction-approval-status/unapproved)
|
||||
(= ::route/approved-page matched-current-page-route) (assoc-in [:route-params :status] :transaction-approval-status/approved)
|
||||
(= ::route/requires-feedback-page matched-current-page-route) (assoc-in [:route-params :status] :transaction-approval-status/requires-feedback)
|
||||
(= ::route/page matched-current-page-route) (assoc-in [:route-params :status] nil))]
|
||||
(handler request))))
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
(defn selected->ids [request params]
|
||||
(let [all-selected (:all-selected params)
|
||||
selected (:selected params)
|
||||
@@ -598,7 +583,6 @@
|
||||
(assoc-in [:query-params :start] 0)
|
||||
(assoc-in [:query-params :per-page] 250))))
|
||||
|
||||
|
||||
:else
|
||||
selected)]
|
||||
ids))
|
||||
Reference in New Issue
Block a user