Merge branch 'master' into try-tailwind

This commit is contained in:
Bryce
2023-05-24 15:44:00 -07:00
32 changed files with 1706 additions and 5557 deletions

View File

@@ -656,7 +656,7 @@
(defn audit-transact [txes id]
(try
@(dc/transact conn (conj txes {:db/id "datomic.tx"
@(dc/transact-async conn (conj txes {:db/id "datomic.tx"
:audit/user (str (:user/role id) "-" (:user/name id))}))
(catch Exception e
(mu/log ::transaction-error

View File

@@ -100,10 +100,10 @@
(defn code->id [code]
(->>
(dc/q (-> {:find ['?e]
:in ['$ '?code]
:where [['?e :client/code '?code ]]}
(dc/db conn) code))
(dc/q '[:find ?e
:in $ ?code
:where [?e :client/code ?code]]
(dc/db conn) code)
(first)
(first)))
@@ -114,7 +114,8 @@
"fields" "id"})
first
:id
Long/parseLong)))
Long/parseLong
(#(hash-map :db/id %)))))
@@ -125,7 +126,8 @@
"fields" "id"})
first
:id
Long/parseLong)))
Long/parseLong
(#(hash-map :db/id %)))))
(defn rebuild-search-index []
(solr/index-documents-raw solr/impl
@@ -171,8 +173,6 @@
true
(merge-query {:query {:find ['?sort-default '?e] :where ['[?e :client/name ?sort-default]]}}))]
(mu/log ::q
:query query)
(->> (query2 query)
(apply-sort-3 (update args :sort conj {:sort-key "default-2" :asc true}))
(apply-pagination args))))

View File

@@ -14,6 +14,7 @@
[auto-ap.time-utils :refer [next-dom]]
[clj-time.coerce :as coerce]
[clj-time.core :as time]
[com.brunobonacci.mulog :as mu]
[clojure.set :refer [rename-keys]]
[datomic.api :as dc]
[iol-ion.tx :refer [random-tempid]]))
@@ -293,6 +294,8 @@
[]))
(defn code-invoice [invoice]
(mu/log ::trying-to-code-invoice
:invoice invoice)
(let [db (dc/db auto-ap.datomic/conn)
client-id (:invoice/client invoice)
vendor-id (:invoice/vendor invoice)

View File

@@ -187,24 +187,23 @@
clients (dc/q '[:find (pull ?c [:db/id :client/code {:client/bank-accounts [:db/id :bank-account/code]}])
:where [?c :client/code]]
db )]
@(dc/transact conn
(for [[{client :db/id code :client/code bank-accounts :client/bank-accounts}] clients
{bank-account :db/id bac :bank-account/code} bank-accounts]
{:db/id bank-account
:bank-account/current-balance
(or
(->> (dc/index-pull db
{:index :avet
:selector [:db/id :journal-entry-line/location :journal-entry-line/account :journal-entry-line/running-balance :journal-entry-line/client+account+location+date {:journal-entry/_line-items [:journal-entry/date :journal-entry/client]}]
:start [:journal-entry-line/client+account+location+date [client bank-account "A" #inst "2030-01-01"]]
:reverse true
})
(filter (fn [{[c b] :journal-entry-line/client+account+location+date}]
(and (= c client)
(= b bank-account))))
(map :journal-entry-line/running-balance)
(first))
0.0)})))))
(doseq [[{client :db/id code :client/code bank-accounts :client/bank-accounts}] clients
{bank-account :db/id bac :bank-account/code} bank-accounts]
@(dc/transact conn [{:db/id bank-account
:bank-account/current-balance
(or
(->> (dc/index-pull db
{:index :avet
:selector [:db/id :journal-entry-line/location :journal-entry-line/account :journal-entry-line/running-balance :journal-entry-line/client+account+location+date {:journal-entry/_line-items [:journal-entry/date :journal-entry/client]}]
:start [:journal-entry-line/client+account+location+date [client bank-account "A" #inst "2030-01-01"]]
:reverse true
})
(filter (fn [{[c b] :journal-entry-line/client+account+location+date}]
(and (= c client)
(= b bank-account))))
(map :journal-entry-line/running-balance)
(first))
0.0)}])))))
(defn get-client [context _ _]
(->graphql

View File

@@ -60,8 +60,7 @@
(assert-power-user (:id context))
(doseq [i invoices]
(assert-can-see-client (:id context) (:db/id (:invoice/client (dc/pull (dc/db conn) [{:invoice/client [:db/id]}] i)))))
(let [transactions (mapcat (fn [i] [[:db/retractEntity i]
[:db/retractEntity [:journal-entry/original-invoice i]]])
(let [transactions (mapcat (fn [i] [[:db/retractEntity i]])
invoices)]
(audit-transact transactions (:id context))
invoices))

View File

@@ -532,7 +532,7 @@
#_(log/info (map :tx success))
(mu/trace ::success-tx
[:count (count success)]
(doseq [n (:tempids (audit-transact-batch (map :tx success) (:id context)))]
(doseq [[_ n] (:tempids (audit-transact-batch (map :tx success) (:id context)))]
(solr/touch n)))
{:successful (map (fn [x] {:external_id (:external_id x)}) success)

View File

@@ -11,7 +11,7 @@
(defn wrap-integration [f bank-account]
(try
(let [result (f)]
@(dc/transact conn [{:db/id bank-account
@(dc/transact-async conn [{:db/id bank-account
:bank-account/integration-status
{:db/id (bank-account->integration-id bank-account)
:integration-status/state :integration-state/success
@@ -19,7 +19,7 @@
:integration-status/last-updated (java.util.Date.)}}])
result)
(catch Exception e
@(dc/transact conn [{:db/id bank-account
@(dc/transact-async conn [{:db/id bank-account
:bank-account/integration-status
{:db/id (bank-account->integration-id bank-account)
:integration-status/state :integration-state/failed

View File

@@ -1,6 +1,6 @@
(ns auto-ap.import.plaid
(:require
[auto-ap.datomic :refer [conn]]
[auto-ap.datomic :refer [conn random-tempid]]
[auto-ap.import.common :refer [wrap-integration]]
[auto-ap.import.transactions :as t]
[auto-ap.plaid.core :as p]
@@ -27,6 +27,7 @@
(defn plaid->transaction [t]
#:transaction {:description-original (:name t)
:raw-id (:transaction_id t)
:db/id (random-tempid)
:id #_{:clj-kondo/ignore [:unresolved-var]}
(di/sha-256 (:transaction_id t))
:amount (if (= "credit" (:type (:account t)))

View File

@@ -296,7 +296,7 @@
:import-batch/not-ready 0
:import-batch/extant 0})
extant-cache (atom (cache/ttl-cache-factory {} :ttl 60000 ))
import-id (get (:tempids @(dc/transact conn [{:db/id "import-batch"
import-id (get (:tempids @(dc/transact-async conn [{:db/id "import-batch"
:import-batch/date (coerce/to-date (t/now))
:import-batch/source source
:import-batch/status :import-status/started
@@ -334,10 +334,10 @@
(fail! [_ error]
(log/errorf "Couldn't complete import %d with error." import-id)
(log/error error)
@(dc/transact conn [(merge {:db/id import-id
:import-batch/status :import-status/completed
:import-batch/error-message (str error)}
@stats)]))
@(dc/transact-async conn [(merge {:db/id import-id
:import-batch/status :import-status/completed
:import-batch/error-message (str error)}
@stats)]))
(finish! [_]
(log/infof "Finishing import batch %d for %s with stats %s " import-id (name source) (pr-str @stats))

View File

@@ -1,6 +1,6 @@
(ns auto-ap.import.yodlee2
(:require
[auto-ap.datomic :refer [conn]]
[auto-ap.datomic :refer [conn random-tempid]]
[auto-ap.import.common :refer [wrap-integration]]
[auto-ap.import.transactions :as t]
[auto-ap.time :as atime]
@@ -32,6 +32,7 @@
#:transaction
{:post-date (coerce/to-date (atime/parse post-date "YYYY-MM-dd"))
:id (di/sha-256 (str id))
:db/id (random-tempid)
:raw-id (str id)
:account-id account-id
:date (if use-date-instead-of-post-date?

View File

@@ -81,7 +81,8 @@
(log/warn ::missing-client
:client-hint location-hint)
(swap! missing-client-hints conj location-hint))
{:invoice/location location
{:db/id (random-tempid)
:invoice/location location
:invoice/date (coerce/to-date (atime/parse ship-date atime/normal-date))
:invoice/invoice-number invoice-number
:invoice/total (Double/parseDouble invoice-total)

View File

@@ -3,7 +3,7 @@
[amazonica.aws.s3 :as s3]
[auto-ap.datomic :refer [conn]]
[auto-ap.jobs.core :refer [execute]]
[auto-ap.datomic :refer [audit-transact]]
[auto-ap.datomic :refer [audit-transact random-tempid]]
[auto-ap.datomic.clients :as d-clients]
[auto-ap.datomic.invoices :refer [code-invoice]]
[auto-ap.parse :as parse]
@@ -11,6 +11,7 @@
[clj-time.coerce :as coerce]
[clojure.data.csv :as csv]
[clojure.java.io :as io]
[com.brunobonacci.mulog :as mu]
[clojure.string :as str]
[clojure.tools.logging :as log]
[com.unbounce.dogstatsd.core :as statsd]
@@ -79,6 +80,7 @@
(log/infof "Importing %s for %s" (header-row "InvoiceNumber") (header-row "CustomerName"))
(cond-> #:invoice {:invoice-number (header-row "InvoiceNumber")
:db/id (random-tempid)
:total (+ total tax)
:outstanding-balance (+ total tax)
:location (parse/best-location-match (dc/pull (dc/db conn)

View File

@@ -6,26 +6,28 @@
[datomic.api :as dc]))
(defn refresh-vendor-usages []
@(dc/transact conn (->> (dc/q '[:find ?v ?c (count ?e)
:in $
:where
[?v :vendor/name]
(or-join [?v ?c ?e]
(and
[?e :invoice/vendor ?v]
[?e :invoice/client ?c])
(and
[?e :transaction/vendor ?v]
[?e :transaction/client ?c])
(and
[?e :journal-entry/vendor ?v]
[?e :journal-entry/client ?c]))]
(dc/db conn))
(map (fn [[v c cnt]]
#:vendor-usage {:vendor v
:client c
:key (str v "-" c)
:count cnt})))))
@(dc/transact-async
conn
(->> (dc/q '[:find ?v ?c (count ?e)
:in $
:where
[?v :vendor/name]
(or-join [?v ?c ?e]
(and
[?e :invoice/vendor ?v]
[?e :invoice/client ?c])
(and
[?e :transaction/vendor ?v]
[?e :transaction/client ?c])
(and
[?e :journal-entry/vendor ?v]
[?e :journal-entry/client ?c]))]
(dc/db conn))
(map (fn [[v c cnt]]
#:vendor-usage {:vendor v
:client c
:key (str v "-" c)
:count cnt})))))
(defn -main [& _]
(execute "vendor-usages" refresh-vendor-usages))

View File

@@ -407,7 +407,7 @@
(daily-results client location start end))]
(doseq [x (partition-all 20 to-create)]
(log/info "Loading " (count x))
@(dc/transact conn x))))))
@(dc/transact-async conn x))))))
(defn upsert-settlements
([client]
@@ -419,7 +419,7 @@
:client (:client/code client)}
(doseq [x (partition-all 20 (daily-settlements client location))]
(log/info "Loading expected deposit" (count x))
@(dc/transact conn x))
@(dc/transact-async conn x))
(log/info "Done loading settlements"))))
(defn upsert-refunds
@@ -433,7 +433,7 @@
:location (:square-location/client-location client)}
(doseq [x (partition-all 20 (refunds client location))]
(log/info "Loading refund" (count x))
@(dc/transact conn x))
@(dc/transact-async conn x))
(log/info "Done loading refunds"))))
(def square-read [:db/id
@@ -474,7 +474,7 @@
[(:square-location/square-id sl)
(:db/id sl)])
(:client/square-locations client)))]
@(dc/transact conn (for [square-location (client-locations client)]
@(dc/transact-async conn (for [square-location (client-locations client)]
{:db/id (or (square-id->id (:id square-location)) (random-tempid))
:client/_square-locations (:db/id client)
:square-location/name (:name square-location)
@@ -492,7 +492,7 @@
(map (fn [x] [:db/retractEntity x]))))
(defn mark-integration-status [client integration-status]
@(dc/transact conn
@(dc/transact-async conn
[{:db/id (:db/id client)
:client/square-integration-status (assoc integration-status
:db/id (or (-> client :client/square-integration-status :db/id)

View File

@@ -394,7 +394,7 @@
(->
(de/chain (search client location start end)
(fn [search-results]
(->> search-results
(->> (or search-results [])
(s/->source)
(s/filter (fn [order]
;; sometimes orders stay open in square. At least one payment
@@ -568,7 +568,7 @@
(doseq [x (partition-all 100 results)]
(log/info ::loading-orders
:count (count x))
@(dc/transact conn x))))))))
@(dc/transact-async conn x))))))))
(defn upsert-settlements
@@ -588,7 +588,7 @@
(doseq [x (partition-all 20 settlements)]
(log/info ::loading-deposits
:count (count x))
@(dc/transact conn x))
@(dc/transact-async conn x))
(log/info ::done-loading-deposits)))))))
(defn upsert-refunds
@@ -609,7 +609,7 @@
(log/info ::loading-refunds
:count (count x)
:sample (first x))
@(dc/transact conn x))
@(dc/transact-async conn x))
(catch Throwable e
(log/error ::upsert-refunds-failed
@@ -687,7 +687,7 @@
(log/info ::loading-cash-shifts
:count (count x)
:sample (first x))
@(dc/transact conn x))
@(dc/transact-async conn x))
(catch Throwable e
(log/error ::upsert-cash-shifts-failed
@@ -737,7 +737,7 @@
(:client/square-locations client)))]
(de/chain (client-locations client)
(fn [client-locations]
@(dc/transact conn
@(dc/transact-async conn
(for [square-location client-locations]
{:db/id (or (square-id->id (:id square-location)) (str (java.util.UUID/randomUUID)))
:client/_square-locations (:db/id client)
@@ -756,7 +756,7 @@
(map (fn [x] [:db/retractEntity x]))))
(defn mark-integration-status [client integration-status]
@(dc/transact conn
@(dc/transact-async conn
[{:db/id (:db/id client)
:client/square-integration-status (assoc integration-status
:db/id (or (-> client :client/square-integration-status :db/id)