diff --git a/project.clj b/project.clj index fa0c0049..634dca39 100644 --- a/project.clj +++ b/project.clj @@ -119,7 +119,7 @@ :profiles { :dev - { + {:main user :resource-paths ["resources" "target"] :dependencies [#_[binaryage/devteols "1.0.2"] [postgresql/postgresql "9.3-1102.jdbc41"] @@ -144,7 +144,7 @@ [com.bhauman/rebel-readline-cljs "0.1.4" :exclusions [org.clojure/clojurescript]] [javax.servlet/servlet-api "2.5"]] :plugins [[lein-pdo "0.1.1"]] - :jvm-opts ["-Dconfig=config/dev.edn" "-Xms4G" "-Xmx20G" "-XX:-OmitStackTraceInFastThrow" ]} + :jvm-opts ["-Dconfig=config/dev.edn" "-Xms4G" "-Xmx20G" "-XX:-OmitStackTraceInFastThrow"]} :uberjar { diff --git a/src/clj/auto_ap/graphql/utils.clj b/src/clj/auto_ap/graphql/utils.clj index dd1b4055..e49f5b6b 100644 --- a/src/clj/auto_ap/graphql/utils.clj +++ b/src/clj/auto_ap/graphql/utils.clj @@ -18,38 +18,38 @@ (defn kebab [x] (if (qualified-keyword? x) - (keyword (snake->kebab (namespace x)) (snake->kebab (name x)) ) + (keyword (snake->kebab (namespace x)) (snake->kebab (name x))) (keyword (snake->kebab (name x))))) (defn kebab->snake [s] - (str/replace (str/replace s #"-" "_") #"\?$" "" )) + (str/replace (str/replace s #"-" "_") #"\?$" "")) (defn snake [x] (keyword (kebab->snake (name x)))) (defn ->graphql [m] (walk/postwalk - (fn [node] - (cond + (fn [node] + (cond - (keyword? node) - (snake node) + (keyword? node) + (snake node) - :else - node)) - m)) + :else + node)) + m)) (defn <-graphql [m] (walk/postwalk - (fn [node] - (cond + (fn [node] + (cond - (keyword? node) - (kebab node) + (keyword? node) + (kebab node) - :else - node)) - m)) + :else + node)) + m)) (defn is-admin? [id] (= "admin" (:user/role id))) @@ -141,7 +141,7 @@ not-empty (str "*")) query (as-> exacts e - (filter #(not (str/blank? %)) e) + (filter #(not (str/blank? %)) e) (mapv #(str "+" %) e) (conj e partial) (str/join " " e))] @@ -150,44 +150,43 @@ (defn trace-query [key f] (fn trace [a b c] (mu/with-context (merge - (:log-context a {}) - {:query key - :mutation (boolean (= "mutation" - (namespace key))) - :user (:id a)}) + (:log-context a {}) + {:query key + :mutation (boolean (= "mutation" + (namespace key))) + :user (:id a)}) (mu/trace (keyword "graphql" (name key)) - [] - (f a b c))))) + [] + (f a b c))))) (defn attach-tracing-resolvers [schema m] (attach-resolvers schema (reduce - (fn [resolvers [resolver-key resolver-fn]] - (assoc resolvers - resolver-key (trace-query resolver-key resolver-fn)) - ) - {} - m))) + (fn [resolvers [resolver-key resolver-fn]] + (assoc resolvers + resolver-key (trace-query resolver-key resolver-fn))) + {} + m))) (defn extract-client-ids [user-clients & possible-clients] (let [coerce-client-ids (fn coerce-client-ids [x] - (cond (and (map? x) - (:db/id x)) - [(:db/id x)] + (cond (and (map? x) + (:db/id x)) + [(:db/id x)] - (nat-int? x) - [x] + (nat-int? x) + [x] - (and (vector? x) - (= :client/code (first x))) - [(entid (dc/db conn) x)] + (and (vector? x) + (= :client/code (first x))) + [(entid (dc/db conn) x)] - (sequential? x) - (mapcat coerce-client-ids x) + (sequential? x) + (mapcat coerce-client-ids x) - :else - [])) + :else + [])) user-client-ids (set (mapcat coerce-client-ids user-clients)) extra-client-ids (set (mapcat coerce-client-ids possible-clients))] (if (seq extra-client-ids) diff --git a/src/clj/auto_ap/jobs/bulk_journal_import.clj b/src/clj/auto_ap/jobs/bulk_journal_import.clj index 600bdf72..bc633edc 100644 --- a/src/clj/auto_ap/jobs/bulk_journal_import.clj +++ b/src/clj/auto_ap/jobs/bulk_journal_import.clj @@ -1,5 +1,4 @@ (ns auto-ap.jobs.bulk-journal-import - (:gen-class) (:require [amazonica.aws.s3 :as s3] [auto-ap.graphql.ledger :refer [import-ledger]] diff --git a/src/clj/auto_ap/jobs/close_auto_invoices.clj b/src/clj/auto_ap/jobs/close_auto_invoices.clj index 13ec8e95..ce433cad 100644 --- a/src/clj/auto_ap/jobs/close_auto_invoices.clj +++ b/src/clj/auto_ap/jobs/close_auto_invoices.clj @@ -1,5 +1,4 @@ (ns auto-ap.jobs.close-auto-invoices - (:gen-class) (:require [auto-ap.datomic :refer [conn]] [auto-ap.jobs.core :refer [execute]] diff --git a/src/clj/auto_ap/jobs/current_balance_cache.clj b/src/clj/auto_ap/jobs/current_balance_cache.clj index 8f9d447a..7a155c80 100644 --- a/src/clj/auto_ap/jobs/current_balance_cache.clj +++ b/src/clj/auto_ap/jobs/current_balance_cache.clj @@ -1,5 +1,4 @@ (ns auto-ap.jobs.current-balance-cache - (:gen-class) (:require [auto-ap.graphql.clients :as clients] [auto-ap.jobs.core :refer [execute]])) diff --git a/src/clj/auto_ap/jobs/ezcater_upsert.clj b/src/clj/auto_ap/jobs/ezcater_upsert.clj index f28c3a34..7478fb55 100644 --- a/src/clj/auto_ap/jobs/ezcater_upsert.clj +++ b/src/clj/auto_ap/jobs/ezcater_upsert.clj @@ -1,5 +1,4 @@ (ns auto-ap.jobs.ezcater-upsert - (:gen-class) (:require [auto-ap.jobs.core :refer [execute]] [auto-ap.ezcater.core :as ezcater])) diff --git a/src/clj/auto_ap/jobs/intuit.clj b/src/clj/auto_ap/jobs/intuit.clj index 787e1dfa..d7fe08fb 100644 --- a/src/clj/auto_ap/jobs/intuit.clj +++ b/src/clj/auto_ap/jobs/intuit.clj @@ -1,5 +1,4 @@ (ns auto-ap.jobs.intuit - (:gen-class) (:require [auto-ap.import.intuit :as intuit] [auto-ap.jobs.core :refer [execute]])) diff --git a/src/clj/auto_ap/jobs/ledger_reconcile.clj b/src/clj/auto_ap/jobs/ledger_reconcile.clj index 76dcc2b7..47326f75 100644 --- a/src/clj/auto_ap/jobs/ledger_reconcile.clj +++ b/src/clj/auto_ap/jobs/ledger_reconcile.clj @@ -1,5 +1,4 @@ (ns auto-ap.jobs.ledger-reconcile - (:gen-class) (:require [auto-ap.jobs.core :refer [execute]] [auto-ap.ledger :as ledger])) diff --git a/src/clj/auto_ap/jobs/load_historical_sales.clj b/src/clj/auto_ap/jobs/load_historical_sales.clj index 230a063c..f7b7286b 100644 --- a/src/clj/auto_ap/jobs/load_historical_sales.clj +++ b/src/clj/auto_ap/jobs/load_historical_sales.clj @@ -1,5 +1,4 @@ (ns auto-ap.jobs.load-historical-sales - (:gen-class) (:require [auto-ap.datomic :refer [conn]] [auto-ap.jobs.core :refer [execute]] diff --git a/src/clj/auto_ap/jobs/plaid.clj b/src/clj/auto_ap/jobs/plaid.clj index ae552e59..cc474704 100644 --- a/src/clj/auto_ap/jobs/plaid.clj +++ b/src/clj/auto_ap/jobs/plaid.clj @@ -1,5 +1,4 @@ (ns auto-ap.jobs.plaid - (:gen-class) (:require [auto-ap.import.plaid :as plaid] [auto-ap.jobs.core :refer [execute]])) diff --git a/src/clj/auto_ap/jobs/register_invoice_import.clj b/src/clj/auto_ap/jobs/register_invoice_import.clj index 48862d59..e5821988 100644 --- a/src/clj/auto_ap/jobs/register_invoice_import.clj +++ b/src/clj/auto_ap/jobs/register_invoice_import.clj @@ -1,5 +1,4 @@ (ns auto-ap.jobs.register-invoice-import - (:gen-class) (:require [amazonica.aws.s3 :as s3] [auto-ap.datomic :refer [audit-transact conn pull-attr]] diff --git a/src/clj/auto_ap/jobs/square.clj b/src/clj/auto_ap/jobs/square.clj index db22c9b5..3620b29d 100644 --- a/src/clj/auto_ap/jobs/square.clj +++ b/src/clj/auto_ap/jobs/square.clj @@ -1,5 +1,4 @@ (ns auto-ap.jobs.square - (:gen-class) (:require [auto-ap.jobs.core :refer [execute]] [auto-ap.square.core3 :as square3])) diff --git a/src/clj/auto_ap/jobs/vendor_usages.clj b/src/clj/auto_ap/jobs/vendor_usages.clj index 1dfe76da..3a674697 100644 --- a/src/clj/auto_ap/jobs/vendor_usages.clj +++ b/src/clj/auto_ap/jobs/vendor_usages.clj @@ -1,5 +1,4 @@ (ns auto-ap.jobs.vendor-usages - (:gen-class) (:require [auto-ap.datomic :refer [conn]] [auto-ap.jobs.core :refer [execute]] diff --git a/src/clj/auto_ap/jobs/yodlee2.clj b/src/clj/auto_ap/jobs/yodlee2.clj index aec0e65b..a902bd89 100644 --- a/src/clj/auto_ap/jobs/yodlee2.clj +++ b/src/clj/auto_ap/jobs/yodlee2.clj @@ -1,5 +1,4 @@ (ns auto-ap.jobs.yodlee2 - (:gen-class) (:require [auto-ap.import.yodlee2 :as yodlee2] [auto-ap.jobs.core :refer [execute]] diff --git a/src/clj/auto_ap/main.clj b/src/clj/auto_ap/main.clj deleted file mode 100644 index ca9d506b..00000000 --- a/src/clj/auto_ap/main.clj +++ /dev/null @@ -1,107 +0,0 @@ -(ns auto-ap.main - (:gen-class) - (:require - [auto-ap.handler :refer [app]] - [auto-ap.server :as server] - [auto-ap.jobs.restore-from-backup :as job-restore-from-backup] - [auto-ap.jobs.bulk-journal-import :as job-bulk-journal-import] - [auto-ap.jobs.close-auto-invoices :as job-close-auto-invoices] - [auto-ap.jobs.current-balance-cache :as job-current-balance-cache] - [auto-ap.jobs.ezcater-upsert :as job-ezcater-upsert] - [auto-ap.jobs.import-uploaded-invoices :as job-import-uploaded-invoices] - [auto-ap.jobs.intuit :as job-intuit] - [auto-ap.jobs.ntg :as job-ntg] - #_[auto-ap.backup :as backup] - [auto-ap.jobs.ledger-reconcile :as job-reconcile-ledger] - [auto-ap.jobs.load-historical-sales :as job-load-historical-sales] - [auto-ap.jobs.plaid :as job-plaid] - [auto-ap.jobs.register-invoice-import :as job-register-invoice-import] - [auto-ap.jobs.square :as job-square] - [auto-ap.jobs.sysco :as job-sysco] - [auto-ap.jobs.vendor-usages :as job-vendor-usages] - [auto-ap.jobs.yodlee2 :as job-yodlee2] - [auto-ap.logging :as alog] - [com.unbounce.dogstatsd.core :as statsd] - [config.core :refer [env]] - [mount.core :as mount] - [nrepl.server :refer [start-server]] - [ring.adapter.jetty :refer [run-jetty]] - [yang.scheduler :as scheduler] - [auto-ap.jobs.insight-outcome-recommendation :as insight-outcome-recommendation]) - (:import - (org.eclipse.jetty.server.handler StatisticsHandler) - (org.eclipse.jetty.server.handler.gzip GzipHandler))) - -(defn add-shutdown-hook! [^Runnable f] - (.addShutdownHook (Runtime/getRuntime) - (Thread. f))) - -(defn shutdown-mount [] - (mount/stop)) - -(defn -main [& _] - (let [job (System/getenv "INTEGREAT_JOB")] - (println "JOB is" job) - (cond (= job "square-import-job") - (job-square/-main) - - (= job "reconcile-ledger") - (job-reconcile-ledger/-main) - - (= job "current-balance-cache") - (job-current-balance-cache/-main) - - (= job "yodlee2") - (job-yodlee2/-main) - - (= job "yodlee2-accounts") - (job-yodlee2/accounts-only) - - (= job "plaid") - (job-plaid/-main) - - (= job "intuit") - (job-intuit/-main) - - (= job "vendor-usages") - (job-vendor-usages/-main) - - (= job "import-uploaded-invoices") - (job-import-uploaded-invoices/-main) - - (= job "sysco") - (job-sysco/-main) - - (= job "close-auto-invoices") - (job-close-auto-invoices/-main) - - (= job "ezcater-upsert") - (job-ezcater-upsert/-main) - - (= job "register-invoice-import") - (job-register-invoice-import/-main) - - (= job "load-historical-sales") - (job-load-historical-sales/-main) - - (= job "bulk-journal-import") - (job-bulk-journal-import/-main) - - (= job "restore-from-backup") - (job-restore-from-backup/-main) - - (= job "insight-outcome-recommendation") - (insight-outcome-recommendation/-main) - - ;; (= job "export-backup") - ;; (backup/-main) - - (= job "ntg") - (job-ntg/-main) - - :else - (do - (add-shutdown-hook! shutdown-mount) - (start-server :port 9000 :bind "0.0.0.0" #_#_:handler (cider-nrepl-handler)) - (mount/start) - #_(alter-var-root #'nrepl.middleware.print/*print-fn* (constantly clojure.pprint/pprint)))))) \ No newline at end of file diff --git a/src/clj/auto_ap/server.clj b/src/clj/auto_ap/server.clj index 0f53c817..77c11d3b 100644 --- a/src/clj/auto_ap/server.clj +++ b/src/clj/auto_ap/server.clj @@ -31,6 +31,9 @@ (org.eclipse.jetty.server.handler StatisticsHandler) (org.eclipse.jetty.server.handler.gzip GzipHandler))) +(println "LOADING SERVER") + + (defn add-shutdown-hook! [^Runnable f] (.addShutdownHook (Runtime/getRuntime) (Thread. f))) diff --git a/src/clj/auto_ap/ssr/account.clj b/src/clj/auto_ap/ssr/account.clj index aaaec0cc..e44677d7 100644 --- a/src/clj/auto_ap/ssr/account.clj +++ b/src/clj/auto_ap/ssr/account.clj @@ -27,22 +27,22 @@ query (format "_text_:(%s) AND %s" (cleanse-query query) client-part)] (mu/log ::searching :search-query query) (for [{:keys [account_id name] :as g} (solr/query solr/impl "accounts" - {"query" query - "fields" "id, name, client_id, numeric_code, applicability, account_id"})] - + {"query" query + "fields" "id, name, client_id, numeric_code, applicability, account_id"})] + {:account_id (first account_id) - :name (first name)}))) + :name (first name)}))) (defn account-search [{{:keys [q client-id allowance vendor-id] :as qp} :query-params id :identity}] - + (when client-id - (assert-can-see-client id client-id)) + (assert-can-see-client id client-id)) (let [num (some-> (re-find #"([0-9]+)" q) second - (not-empty ) + (not-empty) Integer/parseInt) - + valid-allowances (cond-> #{:allowance/allowed :allowance/warn} (is-admin? id) (conj :allowance/admin-only)) @@ -55,23 +55,23 @@ vendor-account (when vendor-id (-> (dc/q '[:find ?da - :in $ ?v - :where [?v :vendor/default-account ?da]] - (dc/db conn) - vendor-id) + :in $ ?v + :where [?v :vendor/default-account ?da]] + (dc/db conn) + vendor-id) ffirst)) xform (comp - (filter (fn [[_ a]] - (or - (valid-allowances (-> a allowance :db/ident)) - (= (:db/id a) vendor-account)))) - (map (fn [[n a]] - {:label (str (:account/numeric-code a) " - " n) - :value (:db/id a) - :location (:account/location a) - :warning (when (= :allowance/warn (-> a allowance :db/ident)) - "This account is not typically used for this purpose.")})))] - {:body (take 10 (if q + (filter (fn [[_ a]] + (or + (valid-allowances (-> a allowance :db/ident)) + (= (:db/id a) vendor-account)))) + (map (fn [[n a]] + {:label (str (:account/numeric-code a) " - " n) + :value (:db/id a) + :location (:account/location a) + :warning (when (= :allowance/warn (-> a allowance :db/ident)) + "This account is not typically used for this purpose.")})))] + {:body (take 10 (if q (if num (->> (dc/q '[:find ?n (pull ?i pattern) :in $ ?numeric-code ?allowance pattern @@ -87,18 +87,18 @@ (sequence xform)) (->> (search- id q client-id) (sequence - (comp (map (fn [i] [(:name i) (dc/pull (dc/db conn) search-pattern (:account_id i))])) - xform)))) + (comp (map (fn [i] [(:name i) (dc/pull (dc/db conn) search-pattern (:account_id i))])) + xform)))) []))})) (def account-search (wrap-json-response (wrap-schema-enforce account-search - :query-schema [:map - [:q :string] - [:client-id {:optional true - :default nil} - [:maybe entity-id]] - [:vendor-id {:optional true} - [:maybe entity-id]] - [:allowance {:optional true} - [:maybe (ref->enum-schema "allowance")]]]))) + :query-schema [:map + [:q :string] + [:client-id {:optional true + :default nil} + [:maybe entity-id]] + [:vendor-id {:optional true} + [:maybe entity-id]] + [:allowance {:optional true} + [:maybe (ref->enum-schema "allowance")]]]))) diff --git a/src/clj/auto_ap/ssr/admin/clients.clj b/src/clj/auto_ap/ssr/admin/clients.clj index e9b9d088..81030bfe 100644 --- a/src/clj/auto_ap/ssr/admin/clients.clj +++ b/src/clj/auto_ap/ssr/admin/clients.clj @@ -40,6 +40,7 @@ [manifold.deferred :as de]) (:import [java.util UUID])) + ;; TODO make more reusable malli schemas, use unions if it would be helpful ;; TODO copy save logic from graphql version ;; TODO cash drawer shift @@ -1416,8 +1417,7 @@ (first step-key))))) (form-schema [_] form-schema-2) (submit [_ {:keys [multi-form-state request-method identity] :as request}] - (let [ - snapshot (mc/decode + (let [snapshot (mc/decode form-schema-2 (:snapshot multi-form-state) mt/strip-extra-keys-transformer) diff --git a/src/clj/user.clj b/src/clj/user.clj index a468adc4..614fe2bc 100644 --- a/src/clj/user.clj +++ b/src/clj/user.clj @@ -1,36 +1,30 @@ (ns user - (:require - [amazonica.aws.s3 :as s3] - [clojure.tools.namespace.repl :refer [set-refresh-dirs refresh]] - [auto-ap.datomic :refer [conn pull-attr random-tempid]] - [auto-ap.ledger :as l] - [clj-http.core :as http] - [clj-http.client :as client] - [figwheel.main.api] - [hawk.core] - [auto-ap.server] - [auto-ap.time :as atime] - [auto-ap.utils :refer [by]] - [clj-time.coerce :as c] - [clj-time.core :as t] - [clj-time.periodic :as per] - [clojure.core.async :as async] - [clojure.data.csv :as csv] - [clojure.java.io :as io] - [clojure.pprint] - [clojure.string :as str] - [config.core :refer [env]] - [datomic.api :as dc] - [mount.core :as mount] - [nrepl.middleware.print] - [com.brunobonacci.mulog :as mu] - [com.brunobonacci.mulog.buffer :as rb] - [datomic.api :as d] - [puget.printer :as puget] - [clojure.data.json :as json] - [auto-ap.solr :as solr]) - (:import - (org.apache.commons.io.input BOMInputStream))) + (:require [amazonica.aws.s3 :as s3] + [auto-ap.datomic :refer [conn pull-attr random-tempid]] + [auto-ap.solr :as solr] + [auto-ap.time :as atime] + [auto-ap.utils :refer [by]] + [clj-time.coerce :as c] + [clj-time.core :as t] + [clojure.core.async :as async] + [auto-ap.handler :refer [app]] + [ring.adapter.jetty :refer [run-jetty]] + [clojure.data.csv :as csv] + [clojure.java.io :as io] + [clojure.pprint] + [clojure.string :as str] + [clojure.tools.namespace.repl :refer [refresh set-refresh-dirs]] + [com.brunobonacci.mulog :as mu] + [com.brunobonacci.mulog.buffer :as rb] + [config.core :refer [env]] + [datomic.api :as dc] + [datomic.api :as d] + [figwheel.main.api] + [hawk.core] + [mount.core :as mount] + [nrepl.middleware.print]) + (:import (org.apache.commons.io.input BOMInputStream) + [org.eclipse.jetty.server.handler.gzip GzipHandler])) (defn println-event [item] @@ -307,11 +301,6 @@ accounts))) vec)) -#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]} -(defn go [] - (require '[mount.core :as mount]) - (require '[auto-ap.server]) - (mount/start-without #'auto-ap.server/jetty)) #_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]} (defn entity-history [i] @@ -367,12 +356,48 @@ (hawk.core/watch! [{:paths ["src/"] :handler auto-reset-handler}])) + + +(defn gzip-handler [] + (doto (GzipHandler.) + (.setIncludedMimeTypes (into-array ["text/css" + "text/plain" + "text/javascript" + "text/csv" + "text/html" + "text/html;charset=utf-8" + "application/javascript" + "application/csv" + "application/edn" + "application/json" + "image/svg+xml"])) + (.setMinGzipSize 1024))) + +(defn configure-jetty [server] + (let [ gzip-handler (gzip-handler) + default-handler (.getHandler server)] + + (.setHandler gzip-handler default-handler) + (.setHandler server gzip-handler)) + (.setStopAtShutdown server true)) + +(mount/defstate port :start (Integer/parseInt (or (env :port) "3000"))) + +(mount/defstate jetty + :start (run-jetty app {:port port + :join? false + :configurator configure-jetty + :response-header-size 16384 + :request-header-size 16384}) + :stop (.stop jetty)) (defn start-http [] - (mount.core/start (mount.core/only #{#'auto-ap.server/port #'auto-ap.server/jetty}))) + (mount.core/start (mount.core/only #{#'user/port #'user/jetty}))) (defn start-dev [] (set-refresh-dirs "src") + #_(clojure.tools.namespace.repl/disable-reload! (find-ns 'auto-ap.server)) + (clojure.tools.namespace.repl/disable-reload! (find-ns 'auto-ap.time)) (start-db) (start-http) (auto-reset)) @@ -386,8 +411,6 @@ (mount.core/stop (mount.core/only #{#'auto-ap.datomic/conn})) (start-db)) - - #_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]} (defn spit-csv [columns data] (csv/write-csv *out* diff --git a/src/clj/user.fiddle b/src/clj/user.fiddle index aabb653b..07910133 100644 --- a/src/clj/user.fiddle +++ b/src/clj/user.fiddle @@ -1,129 +1,152 @@ -(defn setup-randy-queries [] - (import '[java.util UUID]) - (def my-id "a4345849-00a7-424e-b393-06257d3c1820") - - (auto-ap.routes.queries/put-query - my-id - (str '[:find ?an ?cn ?a ?fmt-date ?action ?payee - :where [(ground ["SCSJ-USB9606" "SCCB-USB9598" "SCMH-USB4250" "SCM8-UB3082" "PWL-PWL2370"]) [?bac ...]] - [(iol-ion.query/recent-date 5) ?sd] - [(ground (clj-time.format/with-zone (clj-time.format/formatter "MMddyyyy") (clj-time.core/time-zone-for-id "America/Los_Angeles"))) ?fmt] - [?ba :bank-account/code ?bac] - [?ba :bank-account/number ?an] - [?p :payment/bank-account ?ba] - [?p :payment/date ?pd] - [(>= ?pd ?sd)] - [?p :payment/type :payment-type/check] - [?p :payment/amount ?a] - [?p :payment/check-number ?cn] - [(clj-time.coerce/from-date ?pd) ?pd2] - [(clj-time.format/unparse ?fmt ?pd2) ?fmt-date] - [(ground "IS") ?action] - [?p :payment/vendor ?v] - [(get-some $ ?v :vendor/print-as :vendor/name) [_ ?payee]]]) - "One-off for randy")) - - -(dc/q - '[:find ?cd ?bal (count ?l) - :where [?b :bank-account/locations ?bal] - [?c :client/bank-accounts ?b] - [?c :client/code ?cd] - [?c :client/locations ?l]] - (dc/db conn)) - - (init-repl) +(comment + (defn setup-randy-queries [] + (import '[java.util UUID]) + (def my-id "a4345849-00a7-424e-b393-06257d3c1820") -(seq (dc/q - '[:find ?a ?n ?n2 - :where [?a :account/name ?n] - [?a :account/numeric-code ?n2] - (not [?a :account/code])] - (dc/db conn))) - -(dc/q - '[:find (pull ?a [* {:account/applicability [:db/ident] :account/default-allowance [*]}]) - :where [?a :account/numeric-code 34090]] - (dc/db conn)) + (auto-ap.routes.queries/put-query + my-id + (str '[:find ?an ?cn ?a ?fmt-date ?action ?payee + :where [(ground ["SCSJ-USB9606" "SCCB-USB9598" "SCMH-USB4250" "SCM8-UB3082" "PWL-PWL2370"]) [?bac ...]] + [(iol-ion.query/recent-date 5) ?sd] + [(ground (clj-time.format/with-zone (clj-time.format/formatter "MMddyyyy") (clj-time.core/time-zone-for-id "America/Los_Angeles"))) ?fmt] + [?ba :bank-account/code ?bac] + [?ba :bank-account/number ?an] + [?p :payment/bank-account ?ba] + [?p :payment/date ?pd] + [(>= ?pd ?sd)] + [?p :payment/type :payment-type/check] + [?p :payment/amount ?a] + [?p :payment/check-number ?cn] + [(clj-time.coerce/from-date ?pd) ?pd2] + [(clj-time.format/unparse ?fmt ?pd2) ?fmt-date] + [(ground "IS") ?action] + [?p :payment/vendor ?v] + [(get-some $ ?v :vendor/print-as :vendor/name) [_ ?payee]]]) + "One-off for randy")) -(dc/q - '[:find ?a - :where [?a :account/numeric-code ?nc] - (not [?a :account/default-allowance])] - (dc/since (dc/db conn) #inst "2023-02-01")) - -@(dc/transact conn - (->> - (dc/q - '[:find ?a - :where [?a :account/numeric-code ?nc] - (not [?a :account/default-allowance])] - (dc/since (dc/db conn) #inst "2023-02-01")) - (map (fn [[a]] - {:db/id a - :account/default-allowance :allowance/allowed})))) + (dc/q + '[:find ?cd ?bal (count ?l) + :where [?b :bank-account/locations ?bal] + [?c :client/bank-accounts ?b] + [?c :client/code ?cd] + [?c :client/locations ?l]] + (dc/db conn)) -(dc/q '[:find (pull ?l [*]) - :in $ ?a - :where [?a :invoice/client] - [?l :journal-entry/original-entity ?a]] - (dc/db conn) - 17592316421929) + (init-repl) -(dc/pull (dc/db conn) '[*] 17592316421929) + (seq (dc/q + '[:find ?a ?n ?n2 + :where [?a :account/name ?n] + [?a :account/numeric-code ?n2] + (not [?a :account/code])] + (dc/db conn))) -(entity-history 17592316421929) + (dc/q + '[:find (pull ?a [* {:account/applicability [:db/ident] :account/default-allowance [*]}]) + :where [?a :account/numeric-code 34090]] + (dc/db conn)) -(dc/q '[:find (pull ?l [*]) - :in $ ?a - :where [?a :invoice/client] - [?l :journal-entry/original-entity ?a]] - (dc/db conn) - 17592316421929) + (dc/q + '[:find ?a + :where [?a :account/numeric-code ?nc] + (not [?a :account/default-allowance])] + (dc/since (dc/db conn) #inst "2023-02-01")) + + @(dc/transact conn + (->> + (dc/q + '[:find ?a + :where [?a :account/numeric-code ?nc] + (not [?a :account/default-allowance])] + (dc/since (dc/db conn) #inst "2023-02-01")) + (map (fn [[a]] + {:db/id a + :account/default-allowance :allowance/allowed})))) + + + (dc/q '[:find (pull ?l [*]) + :in $ ?a + :where [?a :invoice/client] + [?l :journal-entry/original-entity ?a]] + (dc/db conn) + 17592316421929) + + (dc/pull (dc/db conn) '[*] 17592316421929) + + (entity-history 17592316421929) + + + (dc/q '[:find (pull ?l [*]) + :in $ ?a + :where [?a :invoice/client] + [?l :journal-entry/original-entity ?a]] + (dc/db conn) + 17592316421929) ;; Find journal entries that have been divorced from the original entity -@(dc/transact auto-ap.datomic/conn - (->> - (dc/q '[:find ?l - :in $ $$ $$$ - :where [$$ ?l :journal-entry/amount] - (not [$ ?l :journal-entry/external-id]) - [$ ?l :journal-entry/source "invoice"] - (not [$ ?l :journal-entry/original-entity]) - [$ ?l :journal-entry/client ?c] - [$ ?c :client/code ?cd] - [$$$ ?l :journal-entry/original-entity _ ?tx false]] - (dc/db conn) - (dc/since (dc/db conn) #inst "2024-02-04") - (dc/history (dc/db conn))) - (map (fn [[jl]] - [:db/retractEntity jl])) - seq) - - ) + @(dc/transact auto-ap.datomic/conn + (->> + (dc/q '[:find ?l + :in $ $$ $$$ + :where [$$ ?l :journal-entry/amount] + (not [$ ?l :journal-entry/external-id]) + [$ ?l :journal-entry/source "invoice"] + (not [$ ?l :journal-entry/original-entity]) + [$ ?l :journal-entry/client ?c] + [$ ?c :client/code ?cd] + [$$$ ?l :journal-entry/original-entity _ ?tx false]] + (dc/db conn) + (dc/since (dc/db conn) #inst "2024-02-04") + (dc/history (dc/db conn))) + (map (fn [[jl]] + [:db/retractEntity jl])) + seq)) -(entity-history 13194269907490) + (entity-history 13194269907490) -(user/tx-detail 13194269907766) + (user/tx-detail 13194269907766) -(dc/tx-range (dc/log conn) - 13194269907490 - 13194269907490) -(dc/q '[:find ?l - :in $ $$ $$$ - :where [$$ ?l :journal-entry/amount] - (not [$ ?l :journal-entry/external-id]) - [$ ?l :journal-entry/source "invoice"] - (not [$ ?l :journal-entry/original-entity]) - [$ ?l :journal-entry/client ?c] - [$ ?c :client/code ?cd] - [$$$ ?l :journal-entry/original-entity _ ?tx false]] - (dc/db conn) - (dc/since (dc/db conn) #inst "2024-02-04") - (dc/history (dc/db conn))) + (dc/tx-range (dc/log conn) + 13194269907490 + 13194269907490) + (dc/q '[:find ?l + :in $ $$ $$$ + :where [$$ ?l :journal-entry/amount] + (not [$ ?l :journal-entry/external-id]) + [$ ?l :journal-entry/source "invoice"] + (not [$ ?l :journal-entry/original-entity]) + [$ ?l :journal-entry/client ?c] + [$ ?c :client/code ?cd] + [$$$ ?l :journal-entry/original-entity _ ?tx false]] + (dc/db conn) + (dc/since (dc/db conn) #inst "2024-02-04") + (dc/history (dc/db conn))) + +(dc/transact conn (->> (dc/q '[:find ?v + :in $ + :where [?v :vendor/plaid-merchant] + (not [?v :vendor/name]) + [?t :transaction/vendor ?v] + [?t :transaction/date ?d]] + (dc/db conn)) + (mapv (fn [[i]] + [:db/retractEntity i])))) + + +@(dc/transact conn (->> (dc/q '[:find ?c + :where [?c :client/name ?n] + [(clojure.string/upper-case ?n) ?n2] + [(clojure.string/includes? ?n2 "NICK")]] + (dc/db conn)) + (map (fn [[c]] + {:db/id c :client/groups ["NTG"]})))) + + + + )