Makes insights actually work
This commit is contained in:
@@ -26,6 +26,20 @@
|
||||
:transaction/bank-account [:bank-account/code]}
|
||||
:transaction/account-confidence
|
||||
:transaction/date])
|
||||
(defn parse-outcome [tx]
|
||||
(update tx :transaction/outcome-recommendation
|
||||
(fn [ors]
|
||||
(map
|
||||
(fn [[v a c s]]
|
||||
{:vendor (dc/pull (dc/db conn)
|
||||
[:vendor/name :db/id]
|
||||
v)
|
||||
:account (dc/pull (dc/db conn)
|
||||
[:account/name :db/id]
|
||||
a)
|
||||
:count c
|
||||
:seen-by-client? s})
|
||||
ors))))
|
||||
|
||||
(defn transaction-recommendations [identity selected-client & {:keys [after]}]
|
||||
(let [visible-clients (visible-clients identity)]
|
||||
@@ -54,20 +68,7 @@
|
||||
(#(if after
|
||||
(drop 1 %)
|
||||
%))
|
||||
(map (fn [tx]
|
||||
(update tx :transaction/outcome-recommendation
|
||||
(fn [ors]
|
||||
(map
|
||||
(fn [[v a c s]]
|
||||
{:vendor (dc/pull (dc/db conn)
|
||||
[:vendor/name :db/id]
|
||||
v)
|
||||
:account (dc/pull (dc/db conn)
|
||||
[:account/name :db/id]
|
||||
a)
|
||||
:count c
|
||||
:seen-by-client? s})
|
||||
ors)))))
|
||||
(map parse-outcome)
|
||||
(take 50)
|
||||
(into []))))
|
||||
|
||||
@@ -144,39 +145,52 @@
|
||||
[:div.tag.is-danger.is-light (str "$" (Math/round (:transaction/amount r)))]))
|
||||
|
||||
(com/data-grid-right-stack-cell {}
|
||||
(when-not hide-actions?
|
||||
[:div.flex.gap-2.flex-col {:style {:width "25em"}}
|
||||
(for [or (sort-by (comp - :count)
|
||||
(:transaction/outcome-recommendation r))]
|
||||
[:form {:hx-post (bidi/path-for ssr-routes/only-routes
|
||||
:transaction-insight-code
|
||||
:transaction-id (:db/id r))
|
||||
:hx-target "closest tr"}
|
||||
(when-let [vendor-id (:db/id (:vendor or))]
|
||||
[:input {:type :hidden :value vendor-id :name "vendor"}])
|
||||
(when-let [account-id (:db/id (:account or))]
|
||||
[:input {:type :hidden :value account-id :name "account"}])
|
||||
|
||||
(com/button {:color (if (:seen-by-client? or)
|
||||
:primary
|
||||
:secondary)
|
||||
:style {:position "relative"}}
|
||||
(:vendor/name (:vendor or))
|
||||
(when (:vendor/name (:vendor or))
|
||||
" | ")
|
||||
(:account/name (:account or))
|
||||
(com/badge {:color :secondary}
|
||||
(:count or)))])
|
||||
(com/icon-button {:hx-get (bidi/path-for ssr-routes/only-routes
|
||||
:transaction-insight-explain
|
||||
:transaction-id (:db/id r))
|
||||
:hx-target "#modal-holder"
|
||||
:hx-swap "outerHTML"}
|
||||
svg/question)]))))
|
||||
[:div.flex.gap-2.flex-col {:style {:width "25em"}}
|
||||
(for [or (take 3 (sort-by (comp - :count)
|
||||
(:transaction/outcome-recommendation r)))]
|
||||
[:form {:hx-post (bidi/path-for ssr-routes/only-routes
|
||||
:transaction-insight-code
|
||||
:transaction-id (:db/id r))
|
||||
:hx-target "closest tr"
|
||||
:hx-swap "outerHTML"
|
||||
:disabled hide-actions?}
|
||||
(when-let [vendor-id (:db/id (:vendor or))]
|
||||
[:input {:type :hidden :value vendor-id :name "vendor"}])
|
||||
(when-let [account-id (:db/id (:account or))]
|
||||
[:input {:type :hidden :value account-id :name "account"}])
|
||||
|
||||
(com/button {:color (if (:seen-by-client? or)
|
||||
:primary
|
||||
:secondary)
|
||||
:style {:position "relative"
|
||||
:display "block"
|
||||
:width "100%"}}
|
||||
(:vendor/name (:vendor or))
|
||||
(when (:vendor/name (:vendor or))
|
||||
" | ")
|
||||
(:account/name (:account or))
|
||||
(com/badge {:color :secondary}
|
||||
(:count or)))])
|
||||
[:div.flex.flex-row.gap-2
|
||||
(com/button {:hx-get (bidi/path-for ssr-routes/only-routes
|
||||
:transaction-insight-explain
|
||||
:transaction-id (:db/id r))
|
||||
:hx-target "#modal-holder"
|
||||
:hx-swap "outerHTML"}
|
||||
[:div.flex
|
||||
svg/question
|
||||
"Explain"])
|
||||
(com/button {:hx-delete (bidi/path-for ssr-routes/only-routes
|
||||
:transaction-insight-disapprove
|
||||
:transaction-id (:db/id r))
|
||||
:hx-target "closest tr"
|
||||
:hx-swap "outerHTML"}
|
||||
[:div.flex
|
||||
svg/question
|
||||
"Reject"])]])))
|
||||
|
||||
(defn code [{:keys [identity session] {:keys [transaction-id]} :route-params {:strs [vendor account]} :form-params}]
|
||||
(let [approval-details (dc/pull (dc/db conn) [{:transaction/recommended-account [:account/location :db/id]}
|
||||
:transaction/recommended-vendor
|
||||
(let [approval-details (dc/pull (dc/db conn) [:transaction/recommended-vendor
|
||||
:transaction/amount
|
||||
:db/id
|
||||
{:transaction/client [:client/locations]}]
|
||||
@@ -201,25 +215,25 @@
|
||||
:transaction-account/account (-> account :db/id)
|
||||
:transaction-account/amount (* 0.01 cents)
|
||||
:transaction-account/location location})
|
||||
(spread-cents cents-to-distribute (count valid-locations))))}]]
|
||||
(spread-cents cents-to-distribute (count valid-locations))))}]
|
||||
db-before (dc/db conn)]
|
||||
@(dc/transact conn [updated-transaction])
|
||||
(html-response (transaction-row
|
||||
(dc/pull (dc/db conn)
|
||||
pull-expr
|
||||
(Long/parseLong transaction-id))
|
||||
:auto-remove? true
|
||||
(parse-outcome (dc/pull db-before
|
||||
pull-expr
|
||||
(Long/parseLong transaction-id)))
|
||||
:hide-actions? true
|
||||
:class "live-added"))))
|
||||
:class "live-added"
|
||||
"_" (hiccup/raw "init transition opacity to 0 then remove me")))))
|
||||
|
||||
(defn disapprove [{:keys [identity session] {:keys [transaction-id]} :route-params}]
|
||||
(let [transaction-id (cond-> transaction-id string? (Long/parseLong))]
|
||||
@(dc/transact conn [[:upsert-transaction {:db/id transaction-id :transaction/recommended-account nil :transaction/recommended-vendor nil}]])
|
||||
(let [transaction-id (cond-> transaction-id string? (Long/parseLong))
|
||||
db-before (dc/db conn)]
|
||||
@(dc/transact conn [[:upsert-transaction {:db/id transaction-id :transaction/outcome-recommendation nil}]])
|
||||
(html-response (transaction-row
|
||||
(dc/pull (dc/db conn) pull-expr transaction-id)
|
||||
:auto-remove? true
|
||||
:hide-actions? true
|
||||
:class "live-removed"
|
||||
"_" (hiccup/raw "init transition opacity to 0 then remove me")))))
|
||||
(parse-outcome (dc/pull db-before pull-expr transaction-id))
|
||||
:hide-actions? true
|
||||
"_" (hiccup/raw "init transition opacity to 0 over 500ms then remove me")))))
|
||||
(defn explain [{:keys [identity session] {:keys [transaction-id]} :route-params}]
|
||||
(let [r (dc/pull (dc/db conn)
|
||||
pull-expr
|
||||
@@ -288,7 +302,8 @@
|
||||
(com/data-grid-header {:style {:width "15em"}} "Account")
|
||||
(com/data-grid-header {:style {:width "8em"}} "Date")
|
||||
(com/data-grid-header {} "Description")
|
||||
(com/data-grid-header {:style {:width "8em"}} "Amount")]})))
|
||||
(com/data-grid-header {:style {:width "8em"}} "Amount")
|
||||
(com/data-grid-header {})]})))
|
||||
|
||||
(defn insight-table [{:keys [session identity]}]
|
||||
(html-response (insight-table* {:selected-client
|
||||
|
||||
Reference in New Issue
Block a user