This commit is contained in:
2023-08-31 23:24:42 -07:00
parent 1d82ec29e0
commit 7d251c8398
40 changed files with 333 additions and 286 deletions

View File

@@ -166,7 +166,8 @@
(some-> route-params (get :entity-id) Long/parseLong))]
(base-page request
(com/page {:nav (com/admin-aside-nav)
:active-client (:client (:session request))
:client-selection (:client-selection (:session request))
:client (:client request)
:identity (:identity request)
:app-params {:hx-get (bidi/path-for ssr-routes/only-routes
:admin-history)

View File

@@ -50,7 +50,8 @@
(base-page
request
(com/page {:nav (com/company-aside-nav)
:active-client (:client (:session request))
:client-selection (:client-selection (:session request))
:client (:client request)
:identity (:identity request)
:app-params {
:hx-get (bidi/path-for ssr-routes/only-routes
@@ -62,6 +63,6 @@
[:a {:href (bidi/path-for ssr-routes/only-routes
:company)}
"My Company"])
(main-content* {:client (:client (:session request))}))
(main-content* {:client (:client request)}))
"My Company"))

View File

@@ -44,23 +44,16 @@
client-id
vendor-id)))
(defn get-1099-companies [user {:keys [client-id] :as args}]
(let [clients (->> (dc/q '[:find ?c
:in $ ?user
:where [?c :client/code]
[(iol-ion.query/can-see-client? ?user ?c)]]
(dc/db conn) user)
(map first)
set)
(defn get-1099-companies [user {:keys [clients] :as args}]
(let [
results (cond
(and client-id
(can-see-client? user client-id))
clients
(dc/q '[:find
(pull ?c [:client/code :db/id])
(pull ?v vendor-read)
(sum ?a)
:with ?d
:in $ ?c vendor-read
:in $ [?c ...] vendor-read
:where
[?p :payment/client ?c]
[?p :payment/date ?d ]
@@ -70,7 +63,7 @@
[?p :payment/amount ?a]
[?p :payment/vendor ?v]]
(dc/db conn)
client-id
(set (map :db/id clients))
vendor-read)
(is-admin? user)

View File

@@ -45,10 +45,10 @@
"status" ['[?e :plaid-item/status ?sort-status]]}
args)
(limited-clients (:id args))
(:clients args)
(merge-query {:query {:in ['[?xx ...]]
:where ['[?e :plaid-item/client ?xx]]}
:args [ (set (map :db/id (limited-clients (:id args))))]})
:args [ (set (map :db/id (:clients args)))]})
(:client-id args)
(merge-query {:query {:in '[?client-id]

View File

@@ -12,7 +12,8 @@
[auto-ap.time :as atime]
[bidi.bidi :as bidi]
[config.core :refer [env]]
[datomic.api :as dc]))
[datomic.api :as dc]
[com.brunobonacci.mulog :as mu]))
(def grid-page {:id "report-table"
:nav (com/company-aside-nav)

View File

@@ -1,8 +1,7 @@
(ns auto-ap.ssr.company-dropdown
(:require
[auto-ap.datomic :refer [conn pull-many]]
[auto-ap.graphql.utils
:refer [assert-can-see-client cleanse-query is-admin?]]
[auto-ap.datomic :refer [conn pull-attr pull-many]]
[auto-ap.graphql.utils :refer [assert-can-see-client cleanse-query]]
[auto-ap.solr :as solr]
[auto-ap.ssr-routes :as ssr-routes]
[auto-ap.ssr.svg :as svg]
@@ -17,10 +16,14 @@
(for [{:keys [id name]} options]
[:li
[:div {:class "flex items-center pl-2 rounded hover:bg-green-100 dark:hover:bg-green-600"}
[:a {:href "#" :class "w-full py-2 ml-2 text-sm font-medium text-gray-900 rounded dark:text-gray-300"
"_" (hiccup/raw "on click set value of <#company-search-value/> to @data-value then send selected to #company-dropdown")
:data-value id}
[:a {:href "#" :class "w-full py-2 ml-2 text-sm font-medium text-gray-900 rounded dark:text-gray-300"
:hx-put (bidi/path-for ssr-routes/only-routes
:active-client
:request-method :put)
:hx-target "#company-dropdown"
:hx-headers (format "{\"x-clients\": \"[%d]\"}" id)
:hx-swap "outerHTML"
:hx-trigger "click"}
name]]])])
@@ -41,27 +44,29 @@
(defn dropdown-search-results [{:keys [identity] :as request}]
(html-response
(dropdown-search-results* {:options (get-clients identity (get (:query-params request) "search-text"))
:client (:client (:session request))})))
(dropdown-search-results* {:options (get-clients identity (get (:query-params request) "search-text"))})))
(defn dropdown [{:keys [client]}]
(defn dropdown [{:keys [client-selection client identity]}]
[:div#company-dropdown
{:hx-put (bidi/path-for ssr-routes/only-routes
:active-client
:request-method :put)
:hx-target "#company-dropdown"
:hx-include "#company-search-value"
:hx-swap "outerHTML"
:hx-trigger "selected"}
[:script
(hiccup/raw
"localStorage.setItem(\"last-client-id\", \""(:db/id client)"\")")]
"localStorage.setItem(\"last-client-id\", \"" (:db/id client) "\")" "\n"
"localStorage.setItem(\"last-selected-clients\", \"" client-selection "\")"
)]
[:div
[:button#company-dropdown-button { :class "text-white bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:outline-none focus:ring-blue-300 font-medium rounded-lg text-sm px-4 py-2.5 text-center inline-flex items-center dark:bg-blue-600 dark:hover:bg-blue-700 dark:focus:ring-blue-800"
:type "button"}
(if client
(:client/name client)
"All Companies")
(cond
(= :mine client-selection)
"My Companies"
(= :all client-selection)
"All Companies"
(and (sequential? client-selection)
(= 1 (count client-selection)))
(pull-attr (dc/db conn) :client/name (first client-selection))
:else
(str (count client-selection) " Companies"))
[:div.w-4.h-4.ml-2
svg/drop-down]]
[:div#company-dropdown-list.hidden {"_" (hiccup/raw "init call initCompanyDropdown()")
@@ -84,9 +89,21 @@
:hx-target "#company-search-results"
:hx-swap "innerHTML"} ]]
[:input#company-search-value {:type "hidden"
:name "search-client"}]]
:name "x-clients"}]]
[:div.divide-y.divide-gray-100
[:div#company-search-results {:class "h-48 px-3 pb-3 overflow-y-auto text-sm text-gray-700 dark:text-gray-200"}]
(when (= "admin" (:user/role identity))
[:div {:class "flex items-center pl-2 rounded hover:bg-green-100 dark:hover:bg-green-600"}
[:button {:class "w-full py-2 ml-2 text-sm font-medium text-gray-900 rounded dark:text-gray-300"
:hx-put (bidi/path-for ssr-routes/only-routes
:active-client
:request-method :put)
:hx-target "#company-dropdown"
:hx-headers "{\"x-clients\": \":mine\"}"
:hx-swap "outerHTML"
:hx-trigger "click"}
"Mine"]])
[:div {:class "flex items-center pl-2 rounded hover:bg-green-100 dark:hover:bg-green-600"}
[:button {:class "w-full py-2 ml-2 text-sm font-medium text-gray-900 rounded dark:text-gray-300"
@@ -94,6 +111,7 @@
:active-client
:request-method :put)
:hx-target "#company-dropdown"
:hx-headers "{\"x-clients\": \":all\"}"
:hx-swap "outerHTML"
:hx-trigger "click"}
"All"]]]
@@ -126,48 +144,10 @@ function initCompanyDropdown() {
")]]])
(defn active-client [{:keys [identity params] :as request}]
(let [client-search (or (:search-client params)
(get params "search-client"))
client-id (try (some-> client-search
(not-empty )
Long/parseLong)
(catch Exception _
nil))]
(when client-id
(assert-can-see-client identity client-id))
(let [new-session (assoc (:session request)
:client
(when client-id
(dc/pull (dc/db conn) [:db/id :client/name :client/code] client-id))
:clients
(cond (int? client-id)
[(dc/pull (dc/db conn) [:db/id :client/name :client/code] client-id)]
(= ":mine" client-search)
(->> (dc/q '[:find (pull ?c [:db/id :client/name :client/code])
:in $ ?u
:where [?u :user/clients ?c]]
(dc/db conn)
(:db/id identity))
(map first))
(and (or (empty? client-search)
(= ":all" client-search))
(is-admin? identity))
(->> (dc/q '[:find (pull ?c [:db/id :client/name :client/code])
:in $ ?u
:where [?c :client/code]]
(dc/db conn)
(:db/id identity))
(map first))))]
(assoc
(html-response
(dropdown {:client (:client new-session)
:identity identity}))
:session
new-session
:headers
{"hx-trigger" "clientSelected"}))))
(assoc
(html-response
(dropdown {:client-selection (:client-selection (:session request))
:client (:client request)
:identity identity}))
:headers
{"hx-trigger" "clientSelected"}))

View File

@@ -8,7 +8,7 @@
[auto-ap.ssr.svg :as svg]
[bidi.bidi :as bidi]))
(defn navbar- [{:keys [client identity]}]
(defn navbar- [{:keys [client-selection client identity]}]
[:nav {:class "fixed z-30 w-full bg-white border-b border-gray-200 dark:bg-gray-800 dark:border-gray-700"}
[:div {:class "px-3 py-3 lg:px-5 lg:pl-3"}
[:div {:class "flex items-center justify-between"}
@@ -40,6 +40,6 @@
:hx-target "#modal-holder"
:hx-swap "outerHTML"}
svg/search)
(cd/dropdown {:client client :identity identity})
(cd/dropdown {:client-selection client-selection :client client :identity identity})
(user-dropdown/dropdown {:identity identity})]]]])

View File

@@ -5,9 +5,10 @@
[hiccup2.core :as hiccup]
[auto-ap.ssr.svg :as svg]))
(defn page- [{:keys [nav page-specific active-client identity app-params] :or {app-params {}}} & children]
(defn page- [{:keys [nav page-specific client client-selection identity app-params] :or {app-params {}}} & children]
[:div#app
(navbar- {:client active-client
(navbar- {:client-selection client-selection
:client client
:identity identity})
[:div#app-contents.flex.pt-16.overflow-hidden (assoc app-params :hx-disinherit "*")
(left-aside- {:nav nav

View File

@@ -8,7 +8,9 @@
[auto-ap.ssr-routes :as ssr-routes]
[cemerick.url :as url]
[clojure.string :as str]
[auto-ap.ssr.svg :as svg]))
[auto-ap.ssr.svg :as svg]
[unilog.context :as lc]
[com.brunobonacci.mulog :as mu]))
(defn row* [gridspec user entity {:keys [flash? delete-after-settle?] :as options}]
(let [cells (mapv (fn [header]
@@ -51,16 +53,15 @@
))
"default sort"))
(defn table* [grid-spec user {:keys [start per-page client flash-id sort request] :as params}]
(defn table* [grid-spec user {:keys [start per-page clients flash-id sort] :as params}]
(let [start (or start 0)
per-page (or per-page 30)
[entities total] ((:fetch-page grid-spec)
user
{:start start
:per-page per-page
:client-id (:db/id client)
:sort sort
:request request})]
:clients clients
:sort sort})]
(com/data-grid-card {:id (:id grid-spec)
:title (:title grid-spec)
:route (:route grid-spec)
@@ -161,7 +162,9 @@
q-sort (assoc :sort (parse-sort grid-spec q-sort))
(not-empty q-toggle-sort) (update :sort #(toggle-sort grid-spec % q-toggle-sort) )
(:session request) (assoc :session (:session request))
(:client (:session request)) (assoc :client (:client (:session request))))))
(:client-selection (:session request)) (assoc :client-selection (:client-selection (:session request)))
(:clients request) (assoc :clients (:clients request))
(:client request) (assoc :client (:client request)))))
(defn table [grid-spec {:keys [query-params hx-query-params identity session] :as request}]
(let [params (extract-params grid-spec request)
@@ -177,7 +180,8 @@
(base-page
request
(com/page {:nav (:nav grid-spec)
:active-client (:client (:session request))
:client-selection (:client-selection (:session request))
:client (:client request)
:identity (:identity request)}
(apply com/breadcrumbs {} (:breadcrumbs grid-spec))
(table* grid-spec

View File

@@ -419,7 +419,8 @@ invoice_dropzone = new Dropzone(\"#invoice\", {
(base-page
request
(com/page {:nav (com/admin-aside-nav)
:active-client (:client (:session request))
:client-selection (:client-selection (:session request))
:client (:client request)
:identity (:identity request)
:app-params {:hx-get (bidi/path-for ssr-routes/only-routes
:invoice-glimpse)

View File

@@ -41,7 +41,7 @@
:seen-by-client? s})
ors))))
(defn transaction-recommendations [identity selected-client & {:keys [after]}]
(defn transaction-recommendations [identity clients & {:keys [after]}]
(let [visible-clients (visible-clients identity)]
(->>
(dc/qseq {:query '[:find (pull ?t pull-expr)
@@ -56,9 +56,8 @@
:args [(dc/db conn)
(iol-ion.query/recent-date 120)
(if selected-client
[selected-client]
visible-clients)
(map :db/id clients)
pull-expr]})
(map first)
(drop-while (fn [x]
@@ -273,8 +272,8 @@
[:td (format "%.1f%%" (* 100 (double score)))]]))]]
[:div])))))
(defn transaction-rows* [{:keys [selected-client identity after]}]
(let [recommendations (transaction-recommendations identity selected-client :after after)]
(defn transaction-rows* [{:keys [clients identity after]}]
(let [recommendations (transaction-recommendations identity clients :after after)]
(if (seq recommendations)
(for [r recommendations
:let [last? (= r (last recommendations))]]
@@ -282,13 +281,13 @@
[:tr [:td.has-text-centered.has-text-gray {:colspan 7 }
[:i "That's the last of 'em!"]]])))
(defn transaction-rows [{:keys [session identity route-params]}]
(html-response (transaction-rows* {:selected-client (-> session :client :db/id)
(defn transaction-rows [{:keys [session identity route-params clients]}]
(html-response (transaction-rows* {:clients clients
:identity identity
:after (:after route-params)})))
(defn insight-table* [{:keys [selected-client identity]}]
(let [recommendations (transaction-recommendations identity selected-client)]
(defn insight-table* [{:keys [clients identity]}]
(let [recommendations (transaction-recommendations identity clients)]
(com/data-grid-card {:id "insight-table"
:title "Transaction Insights"
:route :transaction-insight-table
@@ -305,16 +304,16 @@
(com/data-grid-header {:style {:width "8em"}} "Amount")
(com/data-grid-header {})]})))
(defn insight-table [{:keys [session identity]}]
(html-response (insight-table* {:selected-client
(-> session :client :db/id)
(defn insight-table [{:keys [session identity clients]}]
(html-response (insight-table* {:clients clients
:identity identity})))
(defn page [{:keys [identity matched-route session] :as request}]
(base-page
request
(com/page {:nav (com/main-aside-nav)
:active-client (:client (:session request))
:client-selection (:client-selection (:session request))
:client (:client request)
:identity (:identity request)
:app-params {:hx-get (bidi/path-for ssr-routes/only-routes
:transaction-insights)