adds glimpse for power users
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
[auto-ap.routes.outgoing-invoice :as oi-routes]
|
||||
[auto-ap.routes.payments :as payment-routes]
|
||||
[auto-ap.ssr-routes :as ssr-routes]
|
||||
[auto-ap.ssr.components.tags :as tags]
|
||||
[auto-ap.ssr.hiccup-helper :as hh]
|
||||
[auto-ap.ssr.hx :as hx]
|
||||
[auto-ap.ssr.svg :as svg]
|
||||
@@ -45,8 +46,8 @@
|
||||
:class (fnil hh/add-class "") "space-y-1.5 max-h-0 transition transition-all overflow-hidden")
|
||||
true (assoc ":class" (format "selected == '%s' ? 'py-0.5' : 'py-0'" (:selector params))
|
||||
:x-ref "submenu"
|
||||
:style (cond-> {} (:active? params) (assoc "max-height" "400px"))
|
||||
":style" (format "selected == '%s' ? 'max-height: ' + $refs.submenu.scrollHeight + 'px' : ''" (:selector params))))
|
||||
:style (cond-> {} (:active? params) (assoc "max-height" "900px"))
|
||||
":style" (format "selected == '%s' ? 'max-height: ' + $el.scrollHeight + 'px' : ''" (:selector params))))
|
||||
(for [c children]
|
||||
[:li
|
||||
(update-in c [1 1 :class ] (fn [c]
|
||||
@@ -83,7 +84,7 @@
|
||||
|
||||
(defn main-aside-nav- [request]
|
||||
(let [selected (cond
|
||||
(#{::invoice-route/all-page ::invoice-route/unpaid-page ::invoice-route/voided-page ::invoice-route/paid-page ::oi-routes/new} (:matched-route request))
|
||||
(#{::invoice-route/all-page ::invoice-route/unpaid-page ::invoice-route/voided-page ::invoice-route/paid-page ::oi-routes/new :invoice-glimpse :invoice-glimpse-textract-invoice} (:matched-route request))
|
||||
"invoices"
|
||||
|
||||
(#{:pos-sales :pos-expected-deposits :pos-tenders :pos-refunds :pos-cash-drawer-shifts} (:matched-route request))
|
||||
@@ -140,6 +141,17 @@
|
||||
:activity :import})
|
||||
(menu-button- {:href (bidi/path-for client-routes/routes
|
||||
:import-invoices)} "Import"))
|
||||
|
||||
(when (can? (:identity request)
|
||||
{:subject :invoice
|
||||
:activity :import})
|
||||
(menu-button- {:href (hu/url (bidi/path-for ssr-routes/only-routes
|
||||
:invoice-glimpse))
|
||||
:active? (= :invoice-glimpse (:matched-route request))
|
||||
:hx-boost "true"}
|
||||
[:div.flex.gap-2
|
||||
"Glimpse"
|
||||
(tags/pill- {:color :secondary} "Beta")]))
|
||||
|
||||
|
||||
(when (can? (:identity request)
|
||||
|
||||
@@ -1,41 +1,41 @@
|
||||
(ns auto-ap.ssr.core
|
||||
(:require
|
||||
[auto-ap.routes.ezcater-xls :as ezcater-xls]
|
||||
[auto-ap.routes.utils
|
||||
(:require [auto-ap.permissions :refer [wrap-must]]
|
||||
[auto-ap.routes.ezcater-xls :as ezcater-xls]
|
||||
[auto-ap.routes.utils
|
||||
:refer [wrap-admin wrap-client-redirect-unauthenticated wrap-secure]]
|
||||
[auto-ap.ssr.account :as account]
|
||||
[auto-ap.ssr.payments :as payments]
|
||||
[auto-ap.ssr.admin :as admin]
|
||||
[auto-ap.ssr.admin.accounts :as admin-accounts]
|
||||
[auto-ap.ssr.admin.background-jobs :as admin-jobs]
|
||||
[auto-ap.ssr.admin.excel-invoice :as admin-excel-invoices]
|
||||
[auto-ap.ssr.admin.history :as history]
|
||||
[auto-ap.ssr.admin.import-batch :as import-batch]
|
||||
[auto-ap.ssr.admin.transaction-rules :as admin-rules]
|
||||
[auto-ap.ssr.admin.vendors :as admin-vendors]
|
||||
[auto-ap.ssr.admin.clients :as admin-clients]
|
||||
[auto-ap.ssr.admin.sales-summaries :as admin-sales-summaries]
|
||||
[auto-ap.ssr.auth :as auth]
|
||||
[auto-ap.ssr.indicators :as indicators]
|
||||
[auto-ap.ssr.company :as company]
|
||||
[auto-ap.ssr.company-dropdown :as company-dropdown]
|
||||
[auto-ap.ssr.company.company-1099 :as company-1099]
|
||||
[auto-ap.ssr.company.plaid :as company-plaid]
|
||||
[auto-ap.ssr.company.reports :as company-reports]
|
||||
[auto-ap.ssr.company.yodlee :as company-yodlee]
|
||||
[auto-ap.ssr.invoice.glimpse :as invoice-glimpse]
|
||||
[auto-ap.ssr.pos.cash-drawer-shifts :as pos-cash-drawer-shifts]
|
||||
[auto-ap.ssr.pos.expected-deposits :as pos-expected-deposits]
|
||||
[auto-ap.ssr.pos.refunds :as pos-refunds]
|
||||
[auto-ap.ssr.pos.sales-orders :as pos-sales]
|
||||
[auto-ap.ssr.pos.tenders :as pos-tenders]
|
||||
[auto-ap.ssr.invoices :as invoice]
|
||||
[auto-ap.ssr.outgoing-invoice.new :as oin]
|
||||
[auto-ap.ssr.search :as search]
|
||||
[auto-ap.ssr.transaction.insights :as insights]
|
||||
[auto-ap.ssr.users :as users]
|
||||
[auto-ap.ssr.vendor :as vendors]
|
||||
[ring.middleware.json :refer [wrap-json-response]]))
|
||||
[auto-ap.ssr.account :as account]
|
||||
[auto-ap.ssr.admin :as admin]
|
||||
[auto-ap.ssr.admin.accounts :as admin-accounts]
|
||||
[auto-ap.ssr.admin.background-jobs :as admin-jobs]
|
||||
[auto-ap.ssr.admin.clients :as admin-clients]
|
||||
[auto-ap.ssr.admin.excel-invoice :as admin-excel-invoices]
|
||||
[auto-ap.ssr.admin.history :as history]
|
||||
[auto-ap.ssr.admin.import-batch :as import-batch]
|
||||
[auto-ap.ssr.admin.sales-summaries :as admin-sales-summaries]
|
||||
[auto-ap.ssr.admin.transaction-rules :as admin-rules]
|
||||
[auto-ap.ssr.admin.vendors :as admin-vendors]
|
||||
[auto-ap.ssr.auth :as auth]
|
||||
[auto-ap.ssr.company :as company]
|
||||
[auto-ap.ssr.company-dropdown :as company-dropdown]
|
||||
[auto-ap.ssr.company.company-1099 :as company-1099]
|
||||
[auto-ap.ssr.company.plaid :as company-plaid]
|
||||
[auto-ap.ssr.company.reports :as company-reports]
|
||||
[auto-ap.ssr.company.yodlee :as company-yodlee]
|
||||
[auto-ap.ssr.indicators :as indicators]
|
||||
[auto-ap.ssr.invoice.glimpse :as invoice-glimpse]
|
||||
[auto-ap.ssr.invoices :as invoice]
|
||||
[auto-ap.ssr.outgoing-invoice.new :as oin]
|
||||
[auto-ap.ssr.payments :as payments]
|
||||
[auto-ap.ssr.pos.cash-drawer-shifts :as pos-cash-drawer-shifts]
|
||||
[auto-ap.ssr.pos.expected-deposits :as pos-expected-deposits]
|
||||
[auto-ap.ssr.pos.refunds :as pos-refunds]
|
||||
[auto-ap.ssr.pos.sales-orders :as pos-sales]
|
||||
[auto-ap.ssr.pos.tenders :as pos-tenders]
|
||||
[auto-ap.ssr.search :as search]
|
||||
[auto-ap.ssr.transaction.insights :as insights]
|
||||
[auto-ap.ssr.users :as users]
|
||||
[auto-ap.ssr.vendor :as vendors]
|
||||
[ring.middleware.json :refer [wrap-json-response]]))
|
||||
|
||||
;; from auto-ap.ssr-routes, because they're shared
|
||||
|
||||
@@ -66,11 +66,11 @@
|
||||
:company-yodlee-fastlink-dialog (wrap-client-redirect-unauthenticated (wrap-secure company-yodlee/fastlink-dialog))
|
||||
:company-yodlee-provider-account-refresh (wrap-client-redirect-unauthenticated (wrap-admin company-yodlee/refresh-provider-account))
|
||||
:company-yodlee-provider-account-reauthenticate (wrap-client-redirect-unauthenticated (wrap-secure company-yodlee/reauthenticate))
|
||||
:invoice-glimpse (wrap-client-redirect-unauthenticated (wrap-admin invoice-glimpse/page))
|
||||
:invoice-glimpse-upload (wrap-client-redirect-unauthenticated (wrap-admin invoice-glimpse/upload))
|
||||
:invoice-glimpse-textract-invoice (wrap-client-redirect-unauthenticated (wrap-admin invoice-glimpse/textract-invoice))
|
||||
:invoice-glimpse-create-invoice (wrap-client-redirect-unauthenticated (wrap-admin invoice-glimpse/create-invoice))
|
||||
:invoice-glimpse-update-textract-invoice (wrap-client-redirect-unauthenticated (wrap-admin invoice-glimpse/update-textract-invoice))
|
||||
:invoice-glimpse (wrap-client-redirect-unauthenticated (wrap-must (wrap-secure invoice-glimpse/page) {:activity :import :subject :invoice}))
|
||||
:invoice-glimpse-upload (wrap-client-redirect-unauthenticated (wrap-must (wrap-secure invoice-glimpse/upload) {:activity :import :subject :invoice}))
|
||||
:invoice-glimpse-textract-invoice (wrap-client-redirect-unauthenticated (wrap-must (wrap-secure invoice-glimpse/textract-invoice) {:activity :import :subject :invoice}))
|
||||
:invoice-glimpse-create-invoice (wrap-client-redirect-unauthenticated (wrap-must (wrap-secure invoice-glimpse/create-invoice) {:activity :import :subject :invoice}))
|
||||
:invoice-glimpse-update-textract-invoice (wrap-client-redirect-unauthenticated (wrap-must (wrap-secure invoice-glimpse/update-textract-invoice) {:activity :import :subject :invoice}))
|
||||
:vendor-search (wrap-client-redirect-unauthenticated (wrap-secure vendors/search))
|
||||
:transaction-insights (wrap-client-redirect-unauthenticated (wrap-admin insights/page))
|
||||
:transaction-insight-table (wrap-client-redirect-unauthenticated (wrap-admin insights/insight-table))
|
||||
|
||||
@@ -1,33 +1,32 @@
|
||||
|
||||
(ns auto-ap.ssr.invoice.glimpse
|
||||
(:require
|
||||
[amazonica.aws.s3 :as s3]
|
||||
[amazonica.aws.textract :as textract]
|
||||
[auto-ap.datomic :refer [conn pull-attr pull-id]]
|
||||
[auto-ap.datomic.clients :as d-clients]
|
||||
[auto-ap.logging :as alog]
|
||||
[auto-ap.solr :as solr]
|
||||
[auto-ap.ssr-routes :as ssr-routes]
|
||||
[auto-ap.ssr.components :as com]
|
||||
[auto-ap.ssr.ui :refer [base-page]]
|
||||
[auto-ap.ssr.utils :refer [html-response path->name]]
|
||||
[auto-ap.time :as atime]
|
||||
[bidi.bidi :as bidi]
|
||||
[cemerick.url :as url]
|
||||
[clj-time.coerce :as coerce]
|
||||
[cheshire.core :as cheshire]
|
||||
[clojure.java.io :as io]
|
||||
[clojure.string :as str]
|
||||
[com.brunobonacci.mulog :as mu]
|
||||
[config.core :refer [env]]
|
||||
[datomic.api :as dc]
|
||||
[hiccup2.core :as hiccup]
|
||||
[iol-ion.tx :refer [random-tempid]]
|
||||
[auto-ap.client-routes :as client-routes]
|
||||
[auto-ap.datomic.vendors :as d-vendors]
|
||||
[clj-time.core :as time])
|
||||
(:import
|
||||
(java.util UUID)))
|
||||
(:require [amazonica.aws.s3 :as s3]
|
||||
[amazonica.aws.textract :as textract]
|
||||
[auto-ap.client-routes :as client-routes]
|
||||
[auto-ap.datomic :refer [conn pull-attr]]
|
||||
[auto-ap.datomic.clients :as d-clients]
|
||||
[auto-ap.datomic.vendors :as d-vendors]
|
||||
[auto-ap.graphql.utils :refer [extract-client-ids]]
|
||||
[auto-ap.logging :as alog]
|
||||
[auto-ap.solr :as solr]
|
||||
[auto-ap.ssr-routes :as ssr-routes]
|
||||
[auto-ap.ssr.components :as com]
|
||||
[auto-ap.ssr.ui :refer [base-page]]
|
||||
[auto-ap.ssr.utils :refer [html-response path->name]]
|
||||
[auto-ap.time :as atime]
|
||||
[bidi.bidi :as bidi]
|
||||
[cemerick.url :as url]
|
||||
[cheshire.core :as cheshire]
|
||||
[clj-time.coerce :as coerce]
|
||||
[clj-time.core :as time]
|
||||
[clojure.java.io :as io]
|
||||
[clojure.string :as str]
|
||||
[com.brunobonacci.mulog :as mu]
|
||||
[config.core :refer [env]]
|
||||
[datomic.api :as dc]
|
||||
[hiccup2.core :as hiccup]
|
||||
[iol-ion.tx :refer [random-tempid]])
|
||||
(:import (java.util UUID)))
|
||||
|
||||
(def bucket-name (:data-bucket env))
|
||||
|
||||
@@ -63,8 +62,12 @@
|
||||
[[] #{}]
|
||||
xs)))
|
||||
|
||||
(defn textract->textract-invoice [id tx]
|
||||
(defn textract->textract-invoice [request id tx]
|
||||
(let [lookup (lookup tx)
|
||||
valid-client-ids (extract-client-ids (:clients request)
|
||||
(:client-id request)
|
||||
(when (:client-code request)
|
||||
[:client/code (:client-code request)]))
|
||||
total-options (->> (stack-rank #{"AMOUNT_DUE"} lookup)
|
||||
(map (fn [t]
|
||||
[t (some->> t
|
||||
@@ -87,8 +90,16 @@
|
||||
[t (->> (solr/query solr/impl "clients" {"query" (format "name:(%s) ", (clean-customer t)) "fields" "score, *"})
|
||||
#_(filter (fn [d] (> (:score d) 4.0)))
|
||||
(map (comp #(Long/parseLong %) :id))
|
||||
first)]))))
|
||||
first)]))
|
||||
(filter (fn [[t id]]
|
||||
(valid-client-ids id)))))
|
||||
deduplicate)
|
||||
customer-identifier-options (if (seq customer-identifier-options)
|
||||
customer-identifier-options
|
||||
(->> valid-client-ids
|
||||
(take 10)
|
||||
(map (fn [c]
|
||||
[(pull-attr (dc/db conn) :client/name c) c]))))
|
||||
vendor-name-options (->> (stack-rank #{"VENDOR_NAME"} lookup)
|
||||
(mapcat (fn [t]
|
||||
(for [m (->> (solr/query solr/impl "vendors" {"query" (format "name:(%s) ", t) "fields" "score, *"})
|
||||
@@ -161,13 +172,13 @@ invoice_dropzone = new Dropzone(\"#invoice\", {
|
||||
(update :textract-invoice/vendor-name vendor-name-tuple->vendor-tuple)
|
||||
(update :textract-invoice/vendor-name-options #(map vendor-name-tuple->vendor-tuple %) )))
|
||||
|
||||
(defn refresh-job [id]
|
||||
(defn refresh-job [request id]
|
||||
(let [{:keys [:db/id :textract-invoice/job-id :textract-invoice/textract-status]} (get-job id)]
|
||||
(when (and job-id (= "IN_PROGRESS" textract-status))
|
||||
(let [result (textract/get-expense-analysis {:job-id job-id})
|
||||
new-status (:job-status result)]
|
||||
(cond (= "SUCCEEDED" new-status)
|
||||
@(dc/transact conn [[:upsert-entity (textract->textract-invoice id result)]])
|
||||
@(dc/transact conn [[:upsert-entity (textract->textract-invoice request id result)]])
|
||||
:else
|
||||
@(dc/transact conn [{:db/id id :textract-invoice/textract-status new-status}]))))
|
||||
(get-job id)))
|
||||
@@ -198,6 +209,7 @@ invoice_dropzone = new Dropzone(\"#invoice\", {
|
||||
(com/field {:label "Client"}
|
||||
(com/text-input {:name (path->name [:invoice/client])
|
||||
:value (-> textract-invoice :textract-invoice/customer-identifier second second)
|
||||
:class "w-96"
|
||||
:placeholder "Client"
|
||||
:disabled true
|
||||
:autofocus true}))]
|
||||
@@ -213,6 +225,7 @@ invoice_dropzone = new Dropzone(\"#invoice\", {
|
||||
[:div.col-span-6
|
||||
(com/field {:label "Vendor"}
|
||||
(com/text-input {:name (path->name [:invoice/vendor])
|
||||
:class "w-96"
|
||||
:value (-> textract-invoice :textract-invoice/vendor-name second second)
|
||||
:disabled true
|
||||
:placeholder "Vendor"}))]
|
||||
@@ -270,8 +283,8 @@ invoice_dropzone = new Dropzone(\"#invoice\", {
|
||||
(str invoice-number))})]
|
||||
(com/button {:color :primary} "Save")])
|
||||
|
||||
(defn job-progress* [id]
|
||||
(let [textract-invoice (refresh-job id)]
|
||||
(defn job-progress* [request id]
|
||||
(let [textract-invoice (refresh-job request id)]
|
||||
(cond
|
||||
(= "IN_PROGRESS" (:textract-invoice/textract-status textract-invoice))
|
||||
[:div.bg-blue-100.border-2.border-dashed.rounded-lg.border-blue-300.p-4.max-w-md.w-md.text-center.cursor-pointer
|
||||
@@ -290,12 +303,12 @@ invoice_dropzone = new Dropzone(\"#invoice\", {
|
||||
[:div {:style {:width "805"}}
|
||||
(com/card {}
|
||||
[:iframe.p-4 {:src (:textract-invoice/pdf-url textract-invoice) :width 791 :height 700}])]
|
||||
[:div {:class "basis-1/4"}
|
||||
[:div {:class "basis-1/2"}
|
||||
(com/card {}
|
||||
[:div.p-4
|
||||
(textract->invoice-form* textract-invoice)])]]])))
|
||||
|
||||
(defn page* [id]
|
||||
(defn page* [request id]
|
||||
[:div#invoice-glimpse-content.mt-4
|
||||
(com/card {}
|
||||
[:div.px-4.py-3.space-y-4.flex.flex-col
|
||||
@@ -307,7 +320,7 @@ invoice_dropzone = new Dropzone(\"#invoice\", {
|
||||
[:p.text-sm.italic "Import your invoices with the power of AI. Please only use PDFs with a single invoice in them."]
|
||||
|
||||
(when id
|
||||
(job-progress* id))
|
||||
(job-progress* request id))
|
||||
(when-not id
|
||||
(upload-form*))])])
|
||||
|
||||
@@ -402,7 +415,7 @@ invoice_dropzone = new Dropzone(\"#invoice\", {
|
||||
_ (when new-invoice-id @(dc/transact conn [{:db/id (:db/id current-job)
|
||||
:textract-invoice/invoice new-invoice-id}]))]
|
||||
(if new-invoice-id
|
||||
(html-response (page* nil)
|
||||
(html-response (page* request nil)
|
||||
:headers {"hx-push-url" (bidi/path-for ssr-routes/only-routes :invoice-glimpse)
|
||||
"hx-retarget" "#invoice-glimpse-content"
|
||||
"hx-trigger" (cheshire/generate-string {"notification" (str (hiccup/html [:div "Successfully created "
|
||||
@@ -420,10 +433,11 @@ invoice_dropzone = new Dropzone(\"#invoice\", {
|
||||
:method request-method)
|
||||
(base-page
|
||||
request
|
||||
(com/page {:nav com/admin-aside-nav
|
||||
(com/page {:nav com/main-aside-nav
|
||||
:client-selection (:client-selection request)
|
||||
:client (:client request)
|
||||
:clients (:clients request)
|
||||
:request request
|
||||
:identity (:identity request)
|
||||
:app-params {:hx-get (bidi/path-for ssr-routes/only-routes
|
||||
:invoice-glimpse)
|
||||
@@ -437,7 +451,7 @@ invoice_dropzone = new Dropzone(\"#invoice\", {
|
||||
[:a {:href (bidi/path-for ssr-routes/only-routes
|
||||
:invoice-glimpse)}
|
||||
"Glimpse"])
|
||||
(page* (some-> request
|
||||
(page* request (some-> request
|
||||
:route-params
|
||||
:textract-invoice-id
|
||||
Long/parseLong)))
|
||||
@@ -446,7 +460,7 @@ invoice_dropzone = new Dropzone(\"#invoice\", {
|
||||
|
||||
(defn textract-invoice [request]
|
||||
(if (get-in request [:headers "hx-request"])
|
||||
(html-response (job-progress* (some-> request
|
||||
(html-response (job-progress* request (some-> request
|
||||
:route-params
|
||||
:textract-invoice-id
|
||||
Long/parseLong)))
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
(ns auto-ap.permissions)
|
||||
(ns auto-ap.permissions
|
||||
#?(:clj
|
||||
(:require [cemerick.url :as url])))
|
||||
|
||||
;; TODO after getting rid of cljs, use malli schemas to decode this
|
||||
(defn get-client-id [client]
|
||||
@@ -113,3 +115,13 @@
|
||||
|
||||
:else
|
||||
false)))
|
||||
|
||||
#? (:clj
|
||||
(defn wrap-must [handler policy]
|
||||
(fn [request]
|
||||
(if (can? (:identity request) policy)
|
||||
(handler request)
|
||||
{:status 302
|
||||
:headers {"Location" (str "/login?"
|
||||
(url/map->query {"redirect-to" (:uri request)}))}}))))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user