Adds little indicator on bank account form
This commit is contained in:
0
src/clj/auto_ap/graphql.fiddle
Normal file
0
src/clj/auto_ap/graphql.fiddle
Normal file
19
src/clj/auto_ap/import/intuit.fiddle
Normal file
19
src/clj/auto_ap/import/intuit.fiddle
Normal file
@@ -0,0 +1,19 @@
|
||||
(ns auto-ap.import.intuit
|
||||
(:require
|
||||
[auto-ap.datomic :refer [conn]]
|
||||
[auto-ap.import.common :refer [wrap-integration]]
|
||||
[auto-ap.import.transactions :as t]
|
||||
[auto-ap.intuit.core :as i]
|
||||
[auto-ap.logging :as alog]
|
||||
[auto-ap.time :as atime]
|
||||
[clj-time.coerce :as coerce]
|
||||
[clj-time.core :as time]
|
||||
[clojure.string :as str]
|
||||
[com.unbounce.dogstatsd.core :as statsd]
|
||||
[datomic.api :as dc]))
|
||||
(for [[e] (take 5 (get-intuit-bank-accounts (dc/db conn)))]
|
||||
|
||||
(i/get-transactions "2023-02-01"
|
||||
"2023-02-05"
|
||||
e))
|
||||
|
||||
15
src/clj/auto_ap/plaid/core.fiddle
Normal file
15
src/clj/auto_ap/plaid/core.fiddle
Normal file
@@ -0,0 +1,15 @@
|
||||
(let [client-code "NGKG-CH2231"
|
||||
[[external-id token]] (seq (dc/q '[:find ?external-id ?t
|
||||
:in $ ?ba
|
||||
:where
|
||||
[?ba :bank-account/plaid-account ?pa]
|
||||
[?pa :plaid-account/external-id ?external-id]
|
||||
[?pi :plaid-item/accounts ?pa]
|
||||
[?pi :plaid-item/access-token ?t]]
|
||||
(dc/db conn)
|
||||
[:bank-account/code client-code]))
|
||||
end (atime/local-now)
|
||||
start (clj-time.core/plus end (clj-time.core/days -30))
|
||||
]
|
||||
(get-transactions token start end))
|
||||
|
||||
@@ -7,6 +7,8 @@
|
||||
[auto-ap.logging :as alog]
|
||||
[auto-ap.routes.admin.clients :as route]
|
||||
[auto-ap.routes.queries :as q]
|
||||
[auto-ap.routes.indicators :as indicators]
|
||||
[auto-ap.ssr.indicators :as i]
|
||||
[auto-ap.routes.utils
|
||||
:refer [wrap-admin wrap-client-redirect-unauthenticated]]
|
||||
[auto-ap.solr :as solr]
|
||||
@@ -797,23 +799,33 @@
|
||||
:value (fc/field-value)})]))
|
||||
|
||||
(fc/with-field :bank-account/start-date
|
||||
(com/validated-field {:errors (fc/field-errors)
|
||||
:label "Start Date"}
|
||||
[:div {:class "w-[7em]"}
|
||||
(com/date-input {:name (fc/field-name)
|
||||
:error? (fc/error?)
|
||||
:placeholder "12/01/2023"
|
||||
:class "w-[5em]"
|
||||
:value (some-> (fc/field-value)
|
||||
[:div.flex.space-x-2.items-center
|
||||
(com/validated-field {:errors (fc/field-errors)
|
||||
:label "Start Date"}
|
||||
[:div {:class "w-[7em]"}
|
||||
(com/date-input {:name (fc/field-name)
|
||||
:error? (fc/error?)
|
||||
:placeholder "12/01/2023"
|
||||
:hx-get (bidi/path-for ssr-routes/only-routes
|
||||
::indicators/days-ago)
|
||||
:hx-trigger "change"
|
||||
:hx-target "#days-indicator"
|
||||
:hx-vals "js:{date: event.target.value}"
|
||||
:hx-swap "innerHTML"
|
||||
:class "w-[5em]"
|
||||
:value (some-> (fc/field-value)
|
||||
(clj-time.coerce/to-date-time)
|
||||
;; todo do date coercion in the input
|
||||
(atime/unparse-local atime/normal-date))})])
|
||||
[:div#days-indicator
|
||||
(i/days-ago* (some-> (fc/field-value)))]])
|
||||
|
||||
(clj-time.coerce/to-date-time)
|
||||
(atime/unparse-local atime/normal-date))})]))
|
||||
(fc/with-field :bank-account/include-in-reports
|
||||
(com/checkbox {:name (fc/field-name)
|
||||
:value (boolean (fc/field-value))
|
||||
:checked (fc/field-value)}
|
||||
"Include in reports"))
|
||||
[:div
|
||||
[:div
|
||||
(fc/with-field :bank-account/visible
|
||||
(com/checkbox {:name (fc/field-name)
|
||||
:value (boolean (fc/field-value))
|
||||
@@ -938,17 +950,27 @@
|
||||
:value (fc/field-value)})]))
|
||||
|
||||
(fc/with-field :bank-account/start-date
|
||||
(com/validated-field {:errors (fc/field-errors)
|
||||
:label "Start Date"}
|
||||
[:div {:class "w-[7em]"}
|
||||
(com/date-input {:name (fc/field-name)
|
||||
:error? (fc/error?)
|
||||
:placeholder "12/01/2023"
|
||||
:class "w-[5em]"
|
||||
:value (some-> (fc/field-value)
|
||||
(clj-time.coerce/to-date-time)
|
||||
[:div.flex.space-x-2.items-center
|
||||
(com/validated-field {:errors (fc/field-errors)
|
||||
:label "Start Date"}
|
||||
[:div {:class "w-[7em]"}
|
||||
(com/date-input {:name (fc/field-name)
|
||||
:error? (fc/error?)
|
||||
:placeholder "12/01/2023"
|
||||
:hx-get (bidi/path-for ssr-routes/only-routes
|
||||
::indicators/days-ago)
|
||||
:hx-trigger "change"
|
||||
:hx-target "#days-indicator"
|
||||
:hx-vals "js:{date: event.target.value}"
|
||||
:hx-swap "innerHTML"
|
||||
:class "w-[5em]"
|
||||
:value (some-> (fc/field-value)
|
||||
(clj-time.coerce/to-date-time)
|
||||
;; todo do date coercion in the input
|
||||
(atime/unparse-local atime/normal-date))})]))
|
||||
(atime/unparse-local atime/normal-date))})])
|
||||
[:div#days-indicator
|
||||
(i/days-ago* (some-> (fc/field-value))) ]])
|
||||
|
||||
|
||||
(fc/with-field :bank-account/include-in-reports
|
||||
(com/checkbox {:name (fc/field-name)
|
||||
@@ -956,7 +978,7 @@
|
||||
:checked (fc/field-value)}
|
||||
"Include in reports"))
|
||||
|
||||
[:div
|
||||
[:div
|
||||
(fc/with-field :bank-account/visible
|
||||
(com/checkbox {:name (fc/field-name)
|
||||
:value (boolean (fc/field-value))
|
||||
@@ -1038,17 +1060,26 @@
|
||||
:value (fc/field-value)})]))
|
||||
|
||||
(fc/with-field :bank-account/start-date
|
||||
(com/validated-field {:errors (fc/field-errors)
|
||||
:label "Start Date"}
|
||||
[:div {:class "w-[7em]"}
|
||||
(com/date-input {:name (fc/field-name)
|
||||
:error? (fc/error?)
|
||||
:placeholder "12/01/2023"
|
||||
:class "w-[5em]"
|
||||
:value (some-> (fc/field-value)
|
||||
(clj-time.coerce/to-date-time)
|
||||
[:div.flex.space-x-2.items-center
|
||||
(com/validated-field {:errors (fc/field-errors)
|
||||
:label "Start Date"}
|
||||
[:div {:class "w-[7em]"}
|
||||
(com/date-input {:name (fc/field-name)
|
||||
:error? (fc/error?)
|
||||
:placeholder "12/01/2023"
|
||||
:hx-get (bidi/path-for ssr-routes/only-routes
|
||||
::indicators/days-ago)
|
||||
:hx-trigger "change"
|
||||
:hx-target "#days-indicator"
|
||||
:hx-vals "js:{date: event.target.value}"
|
||||
:hx-swap "innerHTML"
|
||||
:class "w-[5em]"
|
||||
:value (some-> (fc/field-value)
|
||||
(clj-time.coerce/to-date-time)
|
||||
;; todo do date coercion in the input
|
||||
(atime/unparse-local atime/normal-date))})]))
|
||||
(atime/unparse-local atime/normal-date))})])
|
||||
[:div#days-indicator
|
||||
(i/days-ago* (some-> (fc/field-value))) ]])
|
||||
|
||||
(fc/with-field :bank-account/include-in-reports
|
||||
(com/checkbox {:name (fc/field-name)
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
[auto-ap.ssr.admin.vendors :as admin-vendors]
|
||||
[auto-ap.ssr.admin.clients :as admin-clients]
|
||||
[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]
|
||||
@@ -92,5 +93,7 @@
|
||||
(into admin-jobs/key->handler)
|
||||
(into admin-vendors/key->handler)
|
||||
(into admin-clients/key->handler)
|
||||
(into admin-rules/key->handler)))
|
||||
(into admin-rules/key->handler)
|
||||
(into indicators/key->handler)))
|
||||
|
||||
|
||||
|
||||
40
src/clj/auto_ap/ssr/indicators.clj
Normal file
40
src/clj/auto_ap/ssr/indicators.clj
Normal file
@@ -0,0 +1,40 @@
|
||||
(ns auto-ap.ssr.indicators
|
||||
(:require [auto-ap.routes.indicators :as route]
|
||||
[auto-ap.ssr.components :as com]
|
||||
[auto-ap.ssr.utils :refer [html-response wrap-schema-enforce]]
|
||||
[auto-ap.time :as atime]
|
||||
[clj-time.coerce :as c]
|
||||
[clj-time.core :as t]))
|
||||
|
||||
(defn days-ago* [date]
|
||||
(if date
|
||||
(let [start (c/to-date-time date)
|
||||
today (t/now)]
|
||||
|
||||
(if (t/before? start today)
|
||||
(let [days (t/in-days (t/interval start today))]
|
||||
(com/pill {:color (cond (< days 30)
|
||||
:primary
|
||||
(< days 60)
|
||||
:secondary
|
||||
(< days 90)
|
||||
:yellow
|
||||
:else
|
||||
:red)}
|
||||
(str days " days ago")))
|
||||
(com/pill {:color :primary}
|
||||
(str (inc (t/in-days (t/interval today start))) " days from now"))))
|
||||
[:div]))
|
||||
|
||||
(defn days-ago [request]
|
||||
(html-response (days-ago* (:date (:query-params request)))))
|
||||
|
||||
(def key->handler
|
||||
{::route/days-ago (wrap-schema-enforce days-ago
|
||||
:query-schema
|
||||
[:map [:date {:optional false
|
||||
:decode/arbitrary (fn [m]
|
||||
(if (string? m)
|
||||
(c/to-date (atime/parse m atime/normal-date))
|
||||
m))}
|
||||
inst?]])})
|
||||
6
src/cljc/auto_ap/routes/indicators.cljc
Normal file
6
src/cljc/auto_ap/routes/indicators.cljc
Normal file
@@ -0,0 +1,6 @@
|
||||
(ns auto-ap.routes.indicators)
|
||||
(def routes
|
||||
{"/days-ago" ::days-ago})
|
||||
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
(:require
|
||||
[auto-ap.routes.admin.excel-invoices :as ei-routes]
|
||||
[auto-ap.routes.admin.import-batch :as ib-routes]
|
||||
[auto-ap.routes.indicators :as indicator-routes]
|
||||
[auto-ap.routes.admin.vendors :as v-routes]
|
||||
[auto-ap.routes.admin.clients :as ac-routes]
|
||||
[auto-ap.routes.admin.transaction-rules :as tr-routes]))
|
||||
@@ -9,6 +10,7 @@
|
||||
(def routes {"impersonate" :impersonate
|
||||
"logout" :logout
|
||||
"search" :search
|
||||
"indicators" indicator-routes/routes
|
||||
"invoice" {"/glimpse" {"" {:get :invoice-glimpse
|
||||
:post :invoice-glimpse-upload
|
||||
["/" [#"\w+" :textract-invoice-id]] {:get :invoice-glimpse-textract-invoice
|
||||
|
||||
Reference in New Issue
Block a user