added suggestions
This commit is contained in:
@@ -41,10 +41,12 @@
|
||||
(lc/pull-context "container")
|
||||
(lc/pull-context "ip")))
|
||||
|
||||
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
|
||||
(mount/defstate logging-context
|
||||
:start (set-logging-context)
|
||||
:stop (stop-logging-context))
|
||||
|
||||
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
|
||||
(mount/defstate metrics-setup
|
||||
:start (statsd/setup! :host "127.0.0.1" :port 8125 :prefix "integreat.app" :tags (into #{(str "env:" (:dd-env env))
|
||||
(str "service:" (:dd-service env))}
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
(= ":plaid" body)
|
||||
(p/import-plaid)))))
|
||||
|
||||
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
|
||||
(defn fake-message []
|
||||
(sqs/send-message {:queue-url (:requests-queue-url env)
|
||||
:message-body ":intuit"} ))
|
||||
|
||||
@@ -100,6 +100,7 @@
|
||||
(s3/delete-object {:bucket-name bucket-name
|
||||
:key k}))
|
||||
|
||||
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
|
||||
(defn unmark-key [k]
|
||||
(s3/copy-object {:source-bucket-name bucket-name
|
||||
:destination-bucket-name bucket-name
|
||||
|
||||
@@ -14,9 +14,11 @@
|
||||
|
||||
#_(def uri "datomic:mem://datomic-transactor:4334/invoice")
|
||||
|
||||
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
|
||||
(defn create-database []
|
||||
(d/create-database uri))
|
||||
|
||||
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
|
||||
(defn drop-database []
|
||||
(d/delete-database uri))
|
||||
|
||||
@@ -535,70 +537,35 @@
|
||||
[ address-schema contact-schema vendor-schema client-schema bank-account-schema invoice-schema invoice-expense-account-schema payment-schema invoice-payment-schema transaction-schema user-schema])
|
||||
|
||||
|
||||
|
||||
(defn query-entities []
|
||||
(d/q '[:find (pull ?e [:vendor/name])
|
||||
:where [?e :vendor/name]]
|
||||
(d/db (d/connect uri))))
|
||||
|
||||
|
||||
|
||||
(defn query-vendors []
|
||||
(d/q '[:find (pull ?e [*])
|
||||
:where [?e :vendor/original-id]]
|
||||
(d/db (d/connect uri))))
|
||||
(defn query-clients []
|
||||
(d/q '[:find (pull ?e [*])
|
||||
:where [?e :client/original-id]]
|
||||
(d/db (d/connect uri))))
|
||||
|
||||
(defn query-invoices []
|
||||
(d/q '[:find (pull ?e [* {:invoice/vendor [*]
|
||||
:invoice/expense-accounts [*]}])
|
||||
:where [?e :invoice/original-id]]
|
||||
(d/db (d/connect uri))))
|
||||
|
||||
(defn query-payments []
|
||||
(d/q '[:find (pull ?e [* {:invoice-payment/_payment [* {:invoice-payment/invoice [*]}]}])
|
||||
:where [?e :payment/original-id]]
|
||||
(d/db (d/connect uri))))
|
||||
|
||||
(defn query-check-payments []
|
||||
(d/q '[:find (pull ?e [* {:invoice-payment/payment [*]}])
|
||||
:where [?e :invoice-payment/original-id]]
|
||||
(d/db (d/connect uri))))
|
||||
|
||||
(defn query-transactions []
|
||||
(d/q '[:find (pull ?e [*])
|
||||
:where [?e :transaction/original-id]]
|
||||
(d/db (d/connect uri))))
|
||||
|
||||
(defn query-users []
|
||||
(d/q '[:find (pull ?e [*])
|
||||
:where [?e :user/original-id]]
|
||||
(d/db (d/connect uri))))
|
||||
|
||||
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
|
||||
(defn migrate-vendors [_]
|
||||
[[]])
|
||||
|
||||
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
|
||||
(defn migrate-clients [_]
|
||||
[[]])
|
||||
|
||||
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
|
||||
(defn migrate-invoices [_]
|
||||
[[]])
|
||||
|
||||
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
|
||||
(defn migrate-payments [_]
|
||||
[[]])
|
||||
|
||||
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
|
||||
(defn migrate-invoices-payments [_]
|
||||
[[]])
|
||||
|
||||
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
|
||||
(defn migrate-invoices-expense-accounts [_]
|
||||
[[]])
|
||||
|
||||
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
|
||||
(defn migrate-transactions [_]
|
||||
[[]])
|
||||
|
||||
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
|
||||
(defn migrate-users [_]
|
||||
[[]])
|
||||
|
||||
|
||||
@@ -85,12 +85,3 @@
|
||||
:args [(d/db (d/connect uri)) code]}))
|
||||
(first)
|
||||
(first)))
|
||||
|
||||
(defn assoc-image [code image]
|
||||
@(d/transact (d/connect uri)
|
||||
[{ :client/code code
|
||||
:client/signature-file (str "https://s3.amazonaws.com/integreat-signature-images/" image)}]))
|
||||
|
||||
|
||||
#_(d/pull (d/db (d/connect uri)) '[*] [:client/code "FTLO"])
|
||||
#_(assoc-image "FTLO" "Fratello.jpg" )
|
||||
|
||||
@@ -124,8 +124,3 @@
|
||||
|
||||
[(->> (graphql-results ids-to-retrieve db args))
|
||||
matching-count]))
|
||||
|
||||
(defn get-by-id [id]
|
||||
(->>
|
||||
(d/pull (d/db conn) default-read id)
|
||||
(<-datomic)))
|
||||
|
||||
@@ -5,52 +5,17 @@
|
||||
[clj-time.coerce :as c]
|
||||
[auto-ap.datomic.accounts :as d-accounts]))
|
||||
|
||||
(def export-read
|
||||
[:journal-entry/external-id
|
||||
:journal-entry/cleared
|
||||
:journal-entry/alternate-description
|
||||
:journal-entry/date
|
||||
:journal-entry/note
|
||||
:journal-entry/amount
|
||||
:journal-entry/source
|
||||
:journal-entry/cleared-against
|
||||
:journal-entry/original-entity
|
||||
{:journal-entry/client [:client/name :client/code :db/id]
|
||||
:journal-entry/vendor [:vendor/name :db/id]
|
||||
:journal-entry/line-items [:journal-entry-line/location
|
||||
:journal-entry-line/debit
|
||||
:journal-entry-line/credit
|
||||
{:journal-entry-line/account [:bank-account/include-in-reports
|
||||
:bank-account/bank-name
|
||||
:bank-account/code
|
||||
:bank-account/visible
|
||||
:bank-account/name
|
||||
:bank-account/number
|
||||
:account/code
|
||||
:account/name
|
||||
:account/numeric-code
|
||||
:account/location
|
||||
{:account/client-overrides [:account-client-override/name
|
||||
{:account-client-override/client [:db/id]}]}
|
||||
{:account/type [:db/ident :db/id]}
|
||||
{:bank-account/type [:db/ident :db/id]}]}]}])
|
||||
|
||||
(defn raw-graphql-ids [db args]
|
||||
(let [query (cond-> {:query {:find []
|
||||
:in ['$ ]
|
||||
:where []}
|
||||
:args [db]}
|
||||
|
||||
|
||||
(:client-id args)
|
||||
(merge-query {:query {:in ['?client-id]
|
||||
:where ['[?e :journal-entry/client ?client-id]]}
|
||||
:args [(:client-id args)]})
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
(:only-external args)
|
||||
(merge-query {:query {:where ['(not [?e :journal-entry/original-entity ])]}})
|
||||
|
||||
|
||||
@@ -23,12 +23,14 @@
|
||||
(:import
|
||||
(datomic Util)))
|
||||
|
||||
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
|
||||
(defn read-dtm
|
||||
"Reads a dtm file (i.e., an edn file with datomic tags in it) from the classpath
|
||||
and returns a vector of all forms contained within."
|
||||
[filename]
|
||||
(-> (io/resource filename) (io/reader) (Util/readAll)))
|
||||
|
||||
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
|
||||
(defn functions [_]
|
||||
[[{:db/ident :pay
|
||||
:db/doc "Data function that increments value of attribute a by amount."
|
||||
@@ -47,6 +49,7 @@
|
||||
:code [[:db/add e a
|
||||
(-> (d/entity db e) a (+ amount))]] })}]] )
|
||||
|
||||
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
|
||||
(defn fix-pay-function [_]
|
||||
[[{:db/ident :pay
|
||||
:db/doc "Data function that increments value of attribute a by amount."
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
(:require [datomic.api :as d]))
|
||||
|
||||
|
||||
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
|
||||
(defn add-account-visibility-fields [_]
|
||||
[[
|
||||
{:db/ident :bank-account/visible
|
||||
@@ -13,6 +14,7 @@
|
||||
:db/cardinality :db.cardinality/one
|
||||
:db/doc "The sort order of the bank account"}]])
|
||||
|
||||
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
|
||||
(defn make-every-account-visible [conn]
|
||||
(let [all-account-ids (d/query
|
||||
{:query {:find ['?e]
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
[clojure.string :as str]
|
||||
[datomic.api :as d]))
|
||||
|
||||
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
|
||||
(defn add-bank-account-codes-schema [_]
|
||||
[[{:db/ident :bank-account/code
|
||||
:db/valueType :db.type/string
|
||||
@@ -11,6 +12,7 @@
|
||||
:db/doc "A bank account's computer-friendly name"}]])
|
||||
|
||||
|
||||
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
|
||||
(defn add-bank-account-codes [conn]
|
||||
(let [db (d/db conn)
|
||||
all-bank-accounts (d/query {:query {:find ['?b '?original-id '?client-code]
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
["Iguanas Burritozilla" "IBC"]]
|
||||
(into {}))
|
||||
)
|
||||
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
|
||||
(defn add-client-codes [a]
|
||||
[(->> (d/query {:query {:find '[?name ?e]
|
||||
:in ['$]
|
||||
|
||||
@@ -1,25 +1,10 @@
|
||||
(ns auto-ap.datomic.migrate.add-general-ledger
|
||||
(:require [datomic.api :as d]
|
||||
[auto-ap.datomic :refer [remove-nils]]
|
||||
[auto-ap.datomic.accounts :as accounts]
|
||||
[auto-ap.expense-accounts :as expense-accounts]
|
||||
[auto-ap.ledger :as ledger]
|
||||
[auto-ap.utils :refer [by]]
|
||||
[clojure.java.io :as io]
|
||||
[clojure.string :as str])
|
||||
(:import [org.apache.commons.io.input BOMInputStream]))
|
||||
|
||||
(defn test-run [txs-set]
|
||||
#_(println "processing " (count txs-set))
|
||||
(doseq [[i tx] (map vector (range) txs-set)]
|
||||
@(d/transact (d/connect auto-ap.datomic/uri)
|
||||
tx)
|
||||
(when (= 0 (mod i 100))
|
||||
(println "processed " i)
|
||||
(println "sample: " (first tx))
|
||||
)))
|
||||
|
||||
|
||||
(:require
|
||||
[auto-ap.datomic :refer [remove-nils]]
|
||||
[auto-ap.datomic.accounts :as accounts]
|
||||
[auto-ap.expense-accounts :as expense-accounts]
|
||||
[auto-ap.ledger :as ledger]
|
||||
[datomic.api :as d]))
|
||||
|
||||
(def add-general-ledger
|
||||
[[{:db/ident :journal-entry/source
|
||||
@@ -195,7 +180,8 @@
|
||||
:account/location location
|
||||
:account/account-set "default"}))))])
|
||||
|
||||
(defn add-general-ledger-fns [conn]
|
||||
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
|
||||
(defn add-general-ledger-fns [_]
|
||||
[[{:db/ident :replace-general-ledger
|
||||
:db/doc "Deletes the general ledger entries for an entity"
|
||||
:db/fn (d/function '{:lang "clojure"
|
||||
@@ -208,6 +194,7 @@
|
||||
(into []
|
||||
(map (fn [i] [:db/retractEntity i ]) ids)))})}]] )
|
||||
|
||||
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
|
||||
(defn bulk-load-invoice-ledger [conn]
|
||||
(let [invoice-ids (map first (d/query {:query {:find '[?e]
|
||||
:in '[$]
|
||||
@@ -219,6 +206,7 @@
|
||||
z))
|
||||
|
||||
|
||||
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
|
||||
(defn bulk-load-transaction-ledger [conn]
|
||||
(let [transaction-ids (map first (d/query {:query {:find '[?e]
|
||||
:in '[$]
|
||||
@@ -258,6 +246,7 @@
|
||||
:db/cardinality :db.cardinality/one
|
||||
:db/doc "The account will be used when a bill is created."}]])
|
||||
|
||||
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
|
||||
(defn convert-vendors [conn]
|
||||
(let [vendors (d/query {:query {:find '[?v ?expense-account-id]
|
||||
:in '[$]
|
||||
@@ -269,6 +258,7 @@
|
||||
:vendor/default-account (accounts/get-account-by-numeric-code-and-sets expense-account-id ["default"])}))
|
||||
vendors)]))
|
||||
|
||||
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
|
||||
(defn convert-invoices [conn]
|
||||
(let [invoice-expense-accounts (d/query {:query {:find '[?iea ?expense-account-id]
|
||||
:in '[$]
|
||||
@@ -280,7 +270,8 @@
|
||||
:invoice-expense-account/account (accounts/get-account-by-numeric-code-and-sets expense-account-id ["default"])}))
|
||||
invoice-expense-accounts)]))
|
||||
|
||||
(defn convert-transactions [conn]
|
||||
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
|
||||
(defn convert-transactions [_]
|
||||
(println "here")
|
||||
(let [matched-transactions (d/query {:query {:find '[?transaction ?v ?amount]
|
||||
:in '[$]
|
||||
@@ -442,34 +433,3 @@
|
||||
{:db/id v
|
||||
:vendor/hidden false})
|
||||
vendors))])
|
||||
|
||||
|
||||
|
||||
(defn reset-ledger [conn]
|
||||
(let [results (->> (d/query {:query {:find '[?e]
|
||||
:in '[$]
|
||||
:where ['[?e :journal-entry/original-entity ]]}
|
||||
:args [(d/db conn)]})
|
||||
(map (fn [[id]]
|
||||
[:db/retractEntity id]))
|
||||
(partition-all 100))]
|
||||
results))
|
||||
|
||||
(defn reset-manual-ledger [conn]
|
||||
(let [results (->> (d/query {:query {:find '[?e]
|
||||
:in '[$]
|
||||
:where ['[?e :journal-entry/external-id ]]}
|
||||
:args [(d/db conn)]})
|
||||
(mapv (fn [[id]]
|
||||
[:db/retractEntity id]))
|
||||
(partition-all 100))]
|
||||
results))
|
||||
|
||||
|
||||
|
||||
|
||||
#_(convert-accounts (d/connect auto-ap.datomic/uri))
|
||||
|
||||
#_(do (doseq [tran (convert-transactions (d/connect auto-ap.datomic/uri))]
|
||||
@(d/transact (d/connect auto-ap.datomic/uri) tran))
|
||||
(println "done."))
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
(ns auto-ap.datomic.migrate.check-numbers
|
||||
(:require [datomic.api :as d]))
|
||||
|
||||
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
|
||||
(defn fix-check-numbers [conn]
|
||||
(let [max-check-numbers (d/query {:query {:find '[?e ?check-number (max ?d)] :in ['$] :where ['[?e :bank-account/check-number ?check-number] '[?c :payment/bank-account ?e] '[?c :payment/check-number ?d]]} :args [(d/db conn)]})]
|
||||
[(for [[bank-account check-number max-check _] max-check-numbers
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
:db/doc "The location of the location match"}
|
||||
]])
|
||||
|
||||
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
|
||||
(defn add-starter [conn]
|
||||
(if (seq (d/query {:query {:find '[?e]
|
||||
:in ['$]
|
||||
@@ -34,12 +35,14 @@
|
||||
:location-match/matches ["campbell brewing company"]}]}]]
|
||||
[[]]))
|
||||
|
||||
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
|
||||
(defn add-default-location [_]
|
||||
[[{:db/ident :client/default-location
|
||||
:db/valueType :db.type/string
|
||||
:db/cardinality :db.cardinality/one
|
||||
:db/doc "The default location if one can't be found"}]])
|
||||
|
||||
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
|
||||
(defn add-default-location-2 [conn]
|
||||
(if (seq (d/query {:query {:find '[?e]
|
||||
:in ['$]
|
||||
@@ -58,6 +61,7 @@
|
||||
{:db/ident :import-status/pending}
|
||||
{:db/ident :import-status/imported}]])
|
||||
|
||||
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
|
||||
(defn add-import-status-existing-invoices [conn]
|
||||
(let [existing-invoices (->> (d/query {:query {:find ['?e]
|
||||
:in ['$]
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
)
|
||||
)
|
||||
|
||||
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
|
||||
(defn rename-codes-1 [_]
|
||||
(let [result (apply concat [(rename "WE" "WME" (d/connect uri))
|
||||
(rename "HM" "HIM" (d/connect uri))
|
||||
|
||||
@@ -127,7 +127,3 @@
|
||||
matching-count
|
||||
(summarize-orders ids-to-retrieve)]))
|
||||
|
||||
(defn get-by-id [id]
|
||||
(->>
|
||||
(d/pull (d/db (d/connect uri)) default-read id)
|
||||
(<-datomic)))
|
||||
|
||||
@@ -76,7 +76,3 @@
|
||||
true (drop (:start args 0))
|
||||
true (take (:count args 500)))))
|
||||
|
||||
(defn count-graphql [args]
|
||||
|
||||
(->> (raw-graphql args)
|
||||
(count)))
|
||||
|
||||
@@ -42,31 +42,6 @@
|
||||
:vendor/default-account [:db/id :account/numeric-code :account/name]
|
||||
:vendor-usage/_vendor [:vendor-usage/client :vendor-usage/count]}])
|
||||
|
||||
(defn get-usages [args]
|
||||
(->> (cond-> {:query {: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]))]}
|
||||
:args [(d/db conn)]}
|
||||
|
||||
(limited-clients (:id args))
|
||||
(merge-query {:query {:in ['?xx]
|
||||
:where [['(get ?xx ?c)]]}
|
||||
:args [(set (map :db/id (limited-clients (:id args))))]}))
|
||||
(d/query)
|
||||
(reduce
|
||||
(fn [usages [v c cnt]]
|
||||
(update usages v (fnil conj []) {:client-id c :count cnt}))
|
||||
{})))
|
||||
|
||||
(defn raw-graphql-ids [db args]
|
||||
(let [query (cond-> {:query {:find []
|
||||
|
||||
@@ -59,8 +59,3 @@
|
||||
[(->> (graphql-results ids-to-retrieve db args))
|
||||
matching-count]))
|
||||
|
||||
(defn get-by-id [id]
|
||||
(-> (d/db (d/connect uri))
|
||||
(d/pull default-read id)
|
||||
(<-datomic)))
|
||||
|
||||
|
||||
@@ -92,6 +92,7 @@
|
||||
[[:subscription [:parentId :parentEntity :eventEntity :eventKey]]]]]}))
|
||||
)))
|
||||
|
||||
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
|
||||
(defn upsert-ezcater
|
||||
([] (upsert-ezcater (get-integrations)))
|
||||
([integrations]
|
||||
|
||||
@@ -591,23 +591,6 @@
|
||||
node))
|
||||
m))
|
||||
|
||||
(defn <-graphql [m]
|
||||
(walk/postwalk
|
||||
(fn [node]
|
||||
(cond
|
||||
|
||||
(keyword? node)
|
||||
(kebab node)
|
||||
|
||||
:else
|
||||
node))
|
||||
m))
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
(defn get-user [context args _]
|
||||
(assert-admin (:id context))
|
||||
|
||||
@@ -638,12 +621,6 @@
|
||||
(for [[account-id account-name total] result]
|
||||
{:account {:id account-id :name account-name} :total total})))
|
||||
|
||||
(defn categorize [x]
|
||||
(cond (<= x 0) :due
|
||||
(<= x 30 ) :due-30
|
||||
(<= x 60 ) :due-60
|
||||
:else :due-later))
|
||||
|
||||
(defn get-invoice-stats [_ {:keys [client_id] } _]
|
||||
(let [result (cond-> {:query {:find ['?name '(sum ?outstanding-balance) '(sum ?total)]
|
||||
:in ['$]
|
||||
|
||||
@@ -7,8 +7,7 @@
|
||||
:refer [->graphql assert-admin can-see-client? is-admin?]]
|
||||
[auto-ap.routes.queries :as q]
|
||||
[auto-ap.square.core :as square]
|
||||
[auto-ap.utils :refer [by heartbeat]]
|
||||
[auto-ap.yodlee.core :refer [in-memory-cache]]
|
||||
[auto-ap.utils :refer [heartbeat]]
|
||||
[clj-time.coerce :as coerce]
|
||||
[clojure.java.io :as io]
|
||||
[clojure.string :as str]
|
||||
@@ -253,6 +252,7 @@
|
||||
(catch Exception e
|
||||
(log/error "Can't refresh current balance" e)))))
|
||||
|
||||
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
|
||||
(defn refresh-all-current-balance []
|
||||
(lc/with-context {:source "current-balance-cache"}
|
||||
(build-current-balance (->> (d/query {:query {:find ['?ba]
|
||||
@@ -285,9 +285,7 @@
|
||||
(update c :client/bank-accounts
|
||||
(fn [bank-accounts]
|
||||
(mapv (fn [ba]
|
||||
;; TODO remove when new yodlee replaces
|
||||
(assoc ba :bank-account/yodlee-balance-old (get-in (by :id (mapcat :accounts @in-memory-cache) )
|
||||
[(:bank-account/yodlee-account-id ba) :balance :amount])))
|
||||
(assoc ba :bank-account/yodlee-balance-old nil))
|
||||
bank-accounts))))))))
|
||||
|
||||
|
||||
|
||||
@@ -7,11 +7,6 @@
|
||||
|
||||
(def status->graphql (ident->enum-f :expected-deposit/status))
|
||||
|
||||
(defn get-expected-deposit [context args _]
|
||||
(let [args (assoc args :id (:id context))
|
||||
[sales-orders sales-orders-count] (d-expected-deposit/get-graphql (<-graphql args))]
|
||||
(result->page sales-orders sales-orders-count :data args)))
|
||||
|
||||
(defn get-all-expected-deposits [context args _]
|
||||
(assert-admin (:id context))
|
||||
(map
|
||||
|
||||
@@ -42,37 +42,6 @@
|
||||
journal-entries)]
|
||||
(result->page journal-entries journal-entries-count :journal_entries (:filters args))))
|
||||
|
||||
;; TODO a better way to do this might be to accumulate ALL credits and ALL debits, and then just do for credits: balance = credits - debits. and for debits balance = debits - credits
|
||||
(defn credit-account? [account]
|
||||
(or
|
||||
(#{:account-type/liability
|
||||
:account-type/equity
|
||||
:account-type/revenue}
|
||||
(:db/ident (:account/type account)))
|
||||
(#{:bank-account-type/credit}
|
||||
(-> account :bank-account/type :db/ident ))))
|
||||
|
||||
(defn debit-account? [account]
|
||||
|
||||
(or (#{:account-type/asset
|
||||
:account-type/dividend
|
||||
:account-type/expense}
|
||||
(:db/ident (:account/type account)))
|
||||
(#{:bank-account-type/check :bank-account-type/cash}
|
||||
(-> account :bank-account/type :db/ident ))))
|
||||
|
||||
(defn expense-account? [account]
|
||||
(= :account-type/expense (:db/ident (:account/type account))))
|
||||
|
||||
(defn account-name [account client]
|
||||
(let [overriden-name (->>
|
||||
(:account/client-overrides account)
|
||||
(filter (fn [co]
|
||||
(= (:db/id (:account-client-override/client co)) (:db/id client))))
|
||||
(map :account-client-override/name)
|
||||
first)]
|
||||
|
||||
(or overriden-name (:account/name account))))
|
||||
|
||||
(defn roll-up-until
|
||||
([lookup-account all-ledger-entries end-date]
|
||||
@@ -527,6 +496,7 @@
|
||||
(build-running-balance-cache))
|
||||
|
||||
|
||||
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
|
||||
(mount/defstate running-balance-cache-worker
|
||||
:start (scheduler/every (* 15 60 1000) (heartbeat refresh-running-balance-cache "running-balance-cache"))
|
||||
:stop (scheduler/stop running-balance-cache-worker))
|
||||
|
||||
@@ -105,9 +105,6 @@
|
||||
((ident->enum-f :transaction-rule/transaction-approval-status))
|
||||
(->graphql))))
|
||||
|
||||
(defn tr [z x]
|
||||
(re-find (re-pattern z) x))
|
||||
|
||||
(defn -test-transaction-rule [id {:keys [:transaction-rule/description :transaction-rule/client :transaction-rule/bank-account :transaction-rule/amount-lte :transaction-rule/amount-gte :transaction-rule/dom-lte :transaction-rule/dom-gte :transaction-rule/yodlee-merchant]} include-coded? count]
|
||||
(->>
|
||||
(d/query
|
||||
|
||||
@@ -119,6 +119,7 @@
|
||||
(>= (compare locked-until (coerce/to-date date)) 0))
|
||||
(assert-failure (str "Integreat has locked finances prior to " (-> locked-until coerce/to-date-time (atime/unparse-local atime/normal-date)) ".")))))
|
||||
|
||||
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
|
||||
(defn assert-none-locked [client-id dates]
|
||||
(doseq [d dates]
|
||||
(assert-not-locked client-id d)))
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
[clojure.string :as str]
|
||||
[clojure.tools.logging :as log]
|
||||
#_{:clj-kondo/ignore [:refer-all]}
|
||||
[compojure.core :refer :all]
|
||||
[compojure.core :refer [defroutes GET routes context ANY]]
|
||||
[compojure.route :as route]
|
||||
[config.core :refer [env]]
|
||||
[mount.core :as mount]
|
||||
@@ -31,6 +31,7 @@
|
||||
|
||||
(def running? (atom false))
|
||||
|
||||
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
|
||||
(mount/defstate manage-running?
|
||||
:start (reset! running? true)
|
||||
:stop (reset! running? false))
|
||||
@@ -85,6 +86,7 @@
|
||||
(log/info "Beginning request" (:uri request)))
|
||||
(handler request))))
|
||||
|
||||
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
|
||||
(def app
|
||||
(-> #'app-routes
|
||||
(wrap-logging)
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
[auto-ap.import.transactions :as t]
|
||||
[auto-ap.intuit.core :as i]
|
||||
[auto-ap.time :as atime]
|
||||
[auto-ap.utils :refer [allow-once heartbeat]]
|
||||
[auto-ap.utils :refer [heartbeat]]
|
||||
[clj-time.coerce :as coerce]
|
||||
[clj-time.core :as time]
|
||||
[clojure.string :as str]
|
||||
@@ -76,8 +76,6 @@
|
||||
:priority :normal}
|
||||
nil)))))
|
||||
|
||||
(def upsert-transactions (allow-once upsert-transactions))
|
||||
|
||||
(defn upsert-accounts []
|
||||
(let [token (i/get-fresh-access-token)
|
||||
bank-accounts (i/get-bank-accounts token)]
|
||||
|
||||
@@ -20,13 +20,6 @@
|
||||
(catch Exception e
|
||||
(throw (Exception. (str "Could not parse expense account from value '" (:account-numeric-code i) "'") e)))))
|
||||
|
||||
(defn parse-account-id [i]
|
||||
(try
|
||||
(Long/parseLong (second
|
||||
(re-matches #"[^0-9,\\-]*([0-9,\\-]+)[^0-9,]*" (:bank-account-id i))))
|
||||
(catch Exception e
|
||||
(throw (Exception. (str "Could not parse account from value '" (:bank-account-id i) "'") e)))))
|
||||
|
||||
(defn parse-date [{:keys [raw-date]}]
|
||||
(when-not
|
||||
(re-find #"\d{1,2}/\d{1,2}/\d{4}" raw-date)
|
||||
|
||||
@@ -222,6 +222,7 @@
|
||||
:location "A"
|
||||
:amount (Math/abs (double amount))}])))
|
||||
|
||||
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
|
||||
(defn maybe-autopay-invoices [{:transaction/keys [amount client bank-account] :as transaction}]
|
||||
(when-let [autopay-invoices-matches (seq (match-transaction-to-unfulfilled-autopayments amount client))]
|
||||
(add-new-payment transaction autopay-invoices-matches bank-account client)))
|
||||
@@ -356,18 +357,3 @@
|
||||
(range)
|
||||
group)))))
|
||||
|
||||
(defn add-single-transaction [bank-account-code tx]
|
||||
(let [bank-account (d/pull (d/db conn)
|
||||
[:bank-account/code
|
||||
:db/id
|
||||
:bank-account/locations
|
||||
:bank-account/start-date
|
||||
{:client/_bank-accounts [:client/code :client/locations :db/id]} ]
|
||||
[:bank-account/code bank-account-code])]
|
||||
|
||||
(transaction->txs (-> (merge {:transaction/amount 100.0 :transaction/description-original "boring" :transaction/approval-status :transaction-approval-status/approved :transaction/status "POSTED"}
|
||||
tx)
|
||||
(assoc :transaction/bank-account (:db/id bank-account)))
|
||||
bank-account
|
||||
(rm/rule-applying-fn (tr/get-all)))))
|
||||
|
||||
|
||||
@@ -1,85 +0,0 @@
|
||||
(ns auto-ap.import.yodlee
|
||||
(:require
|
||||
[auto-ap.datomic :refer [conn]]
|
||||
[auto-ap.import.transactions :as t]
|
||||
[auto-ap.time :as atime]
|
||||
[auto-ap.utils :refer [allow-once]]
|
||||
[auto-ap.yodlee.core :as client]
|
||||
[clj-time.coerce :as coerce]
|
||||
[clojure.string :as str]
|
||||
[clojure.tools.logging :as log]
|
||||
[com.unbounce.dogstatsd.core :as statsd]
|
||||
[datomic.api :as d]
|
||||
[digest :as di]))
|
||||
|
||||
(defn yodlee->transaction [transaction use-date-instead-of-post-date?]
|
||||
(let [{post-date :postDate
|
||||
account-id :accountId
|
||||
date :date
|
||||
id :id
|
||||
{amount :amount} :amount
|
||||
{description-original :original
|
||||
description-simple :simple} :description
|
||||
base-type :baseType
|
||||
type :type
|
||||
status :status} transaction
|
||||
amount (if (= "DEBIT" base-type)
|
||||
(- amount)
|
||||
amount)
|
||||
date (atime/parse date "YYYY-MM-dd")]
|
||||
#:transaction
|
||||
{:post-date (coerce/to-date (atime/parse post-date "YYYY-MM-dd"))
|
||||
:id #_{:clj-kondo/ignore [:unresolved-var]}
|
||||
(di/sha-256 (str id))
|
||||
:raw-id (str id)
|
||||
:account-id account-id
|
||||
:date (if use-date-instead-of-post-date?
|
||||
(coerce/to-date (atime/parse post-date "YYYY-MM-dd"))
|
||||
(coerce/to-date date))
|
||||
:amount (double amount)
|
||||
:description-original (some-> description-original (str/replace #"\s+" " "))
|
||||
:description-simple (some-> description-simple (str/replace #"\s+" " "))
|
||||
:type type
|
||||
:status status}))
|
||||
|
||||
(defn import-yodlee []
|
||||
(statsd/event {:title "Yodlee import started"
|
||||
:text "Starting"
|
||||
:priority :low}
|
||||
nil)
|
||||
(let [import-batch (t/start-import-batch :import-source/yodlee "Automated yodlee user")]
|
||||
(try
|
||||
(let [account-lookup (d/q '[:find ?ya ?ba ?ud ?c
|
||||
:in $
|
||||
:where [?ba :bank-account/yodlee-account-id ?ya]
|
||||
[(get-else $ ?ba :bank-account/use-date-instead-of-post-date? false) ?ud]
|
||||
[?c :client/bank-accounts ?ba]]
|
||||
(d/db conn))]
|
||||
(doseq [[yodlee-account bank-account use-date-instead-of-post-date? client-id] account-lookup
|
||||
transaction (try
|
||||
(client/get-specific-transactions yodlee-account (client/get-auth-header))
|
||||
(catch Exception e
|
||||
(log/warn e)
|
||||
[]))]
|
||||
(t/import-transaction! import-batch (assoc (yodlee->transaction transaction use-date-instead-of-post-date?)
|
||||
:transaction/bank-account bank-account
|
||||
:transaction/client client-id)))
|
||||
|
||||
(t/finish! import-batch))
|
||||
(statsd/event {:title "Yodlee import Finished"
|
||||
:text (pr-str (t/get-stats import-batch))
|
||||
:priority :low}
|
||||
nil)
|
||||
(catch Exception e
|
||||
(t/fail! import-batch e)
|
||||
(statsd/event {:title "Yodlee import failed"
|
||||
:text (str e)
|
||||
:alert-type :warning
|
||||
:priority :normal}
|
||||
nil)))))
|
||||
|
||||
(def import-yodlee (allow-once import-yodlee))
|
||||
|
||||
#_(mount/defstate import-worker
|
||||
:start (scheduler/every (* 1000 60 60 8) (heartbeat import-yodlee "import-yodlee"))
|
||||
:stop (scheduler/stop import-worker))
|
||||
@@ -3,15 +3,48 @@
|
||||
[auto-ap.datomic :refer [conn]]
|
||||
[auto-ap.import.common :refer [wrap-integration]]
|
||||
[auto-ap.import.transactions :as t]
|
||||
[auto-ap.import.yodlee :as y]
|
||||
[auto-ap.utils :refer [allow-once heartbeat]]
|
||||
[auto-ap.yodlee.core2 :as client2]
|
||||
[auto-ap.time :as atime ]
|
||||
[clojure.string :as str]
|
||||
[clj-time.coerce :as coerce]
|
||||
[digest :as di]
|
||||
[com.unbounce.dogstatsd.core :as statsd]
|
||||
[datomic.api :as d]
|
||||
[mount.core :as mount]
|
||||
[unilog.context :as lc]
|
||||
[yang.scheduler :as scheduler]))
|
||||
|
||||
(defn yodlee->transaction [transaction use-date-instead-of-post-date?]
|
||||
(let [{post-date :postDate
|
||||
account-id :accountId
|
||||
date :date
|
||||
id :id
|
||||
{amount :amount} :amount
|
||||
{description-original :original
|
||||
description-simple :simple} :description
|
||||
base-type :baseType
|
||||
type :type
|
||||
status :status} transaction
|
||||
amount (if (= "DEBIT" base-type)
|
||||
(- amount)
|
||||
amount)
|
||||
date (atime/parse date "YYYY-MM-dd")]
|
||||
#:transaction
|
||||
{:post-date (coerce/to-date (atime/parse post-date "YYYY-MM-dd"))
|
||||
:id #_{:clj-kondo/ignore [:unresolved-var]}
|
||||
(di/sha-256 (str id))
|
||||
:raw-id (str id)
|
||||
:account-id account-id
|
||||
:date (if use-date-instead-of-post-date?
|
||||
(coerce/to-date (atime/parse post-date "YYYY-MM-dd"))
|
||||
(coerce/to-date date))
|
||||
:amount (double amount)
|
||||
:description-original (some-> description-original (str/replace #"\s+" " "))
|
||||
:description-simple (some-> description-simple (str/replace #"\s+" " "))
|
||||
:type type
|
||||
:status status}))
|
||||
|
||||
(defn import-yodlee2-int []
|
||||
(lc/with-context {:source "Import yodlee2 transactions"}
|
||||
(statsd/event {:title "Yodlee2 import started"
|
||||
@@ -33,7 +66,7 @@
|
||||
(doseq [[yodlee-account bank-account client-code use-date-instead-of-post-date?] account-lookup
|
||||
transaction (wrap-integration #(client2/get-specific-transactions client-code yodlee-account)
|
||||
bank-account)]
|
||||
(t/import-transaction! import-batch (assoc (y/yodlee->transaction transaction use-date-instead-of-post-date?)
|
||||
(t/import-transaction! import-batch (assoc (yodlee->transaction transaction use-date-instead-of-post-date?)
|
||||
:transaction/bank-account bank-account
|
||||
:transaction/client [:client/code client-code])))
|
||||
|
||||
|
||||
@@ -49,20 +49,24 @@
|
||||
:metadata {:content-type "application/text"
|
||||
:content-length (count (.getBytes t))}))
|
||||
|
||||
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
|
||||
(defn copy-prod-refresh-token []
|
||||
(set-refresh-token (slurp (:object-content (s3/get-object
|
||||
:bucket-name "data.prod.app.integreatconsult.com"
|
||||
:key "intuit/refresh-token")))))
|
||||
|
||||
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
|
||||
(defn init-tokens [access refresh]
|
||||
(set-access-token access)
|
||||
(set-refresh-token refresh))
|
||||
|
||||
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
|
||||
(defn lookup-access-token []
|
||||
(slurp (:object-content (s3/get-object
|
||||
:bucket-name (:data-bucket env)
|
||||
:key "intuit/access-token"))))
|
||||
|
||||
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
|
||||
(defn lookup-refresh-token []
|
||||
(slurp (:object-content (s3/get-object
|
||||
:bucket-name (:data-bucket env)
|
||||
|
||||
@@ -25,19 +25,6 @@
|
||||
#_#_(namespaces "expected-deposit" ) [[:expected-deposit e]]
|
||||
:else nil)))
|
||||
|
||||
|
||||
|
||||
(defn infer-entity [_ [_ changes]]
|
||||
(let [namespaces (->> changes
|
||||
(map :a)
|
||||
(map namespace)
|
||||
set)]
|
||||
(cond (namespaces "invoice" ) :invoice
|
||||
(namespaces "invoice-expense-account" ) :invoice-expense-account
|
||||
(namespaces "transaction-account" ) :transaction-account
|
||||
#_#_(namespaces "expected-deposit" ) :expected-deposit
|
||||
:else nil)))
|
||||
|
||||
(defmulti entity-change->ledger (fn [_ [type]]
|
||||
type))
|
||||
|
||||
|
||||
@@ -136,6 +136,7 @@
|
||||
(into [new-table]
|
||||
(split-table remaining n))))))
|
||||
|
||||
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
|
||||
(defn break-apart-tables [pnl-data tables]
|
||||
(for [table tables
|
||||
table (split-table table (if (:include-deltas (:args pnl-data))
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
(def google-client-id "264081895820-0nndcfo3pbtqf30sro82vgq5r27h8736.apps.googleusercontent.com")
|
||||
(def google-client-secret "OC-WemHurPXYpuIw5cT-B90g")
|
||||
|
||||
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
|
||||
(defn make-api-token []
|
||||
(jwt/sign {:user "API"
|
||||
:exp (time/plus (time/now) (time/days 1000))
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
(ns auto-ap.routes.utils
|
||||
(:require [buddy.auth :refer [authenticated?]]
|
||||
[clojure.spec.alpha :as s]))
|
||||
(:require [buddy.auth :refer [authenticated?]]))
|
||||
|
||||
(defn wrap-secure [handler]
|
||||
(fn [request]
|
||||
@@ -8,11 +7,3 @@
|
||||
(handler request)
|
||||
{:status 401
|
||||
:body "not authenticated"})))
|
||||
|
||||
(defn wrap-spec [handler spec]
|
||||
(fn [request]
|
||||
(if (not (s/valid? spec (:edn-params request)))
|
||||
{:status 400
|
||||
:body (pr-str (s/explain-data spec (:edn-params request)))
|
||||
:headers {"Content-Type" "application/edn"}}
|
||||
(handler request))))
|
||||
|
||||
@@ -1,83 +0,0 @@
|
||||
(ns auto-ap.routes.yodlee
|
||||
(:require
|
||||
[auto-ap.graphql.utils :refer [assert-admin]]
|
||||
[auto-ap.routes.utils :refer [wrap-secure]]
|
||||
[auto-ap.yodlee.core :as yodlee]
|
||||
[clojure.tools.logging :as log]
|
||||
[compojure.core :refer [context defroutes GET POST wrap-routes]]
|
||||
[config.core :refer [env]]))
|
||||
|
||||
(defroutes routes
|
||||
(wrap-routes
|
||||
(context "/yodlee" []
|
||||
(GET "/fastlink" {:keys [identity]}
|
||||
(assert-admin identity)
|
||||
(let [[session token] (yodlee/get-access-token)]
|
||||
{:status 200
|
||||
:headers {"Content-Type" "application/edn"}
|
||||
:body (pr-str {:session session
|
||||
:token token
|
||||
:app (:yodlee-app env)
|
||||
|
||||
:url (:yodlee-fastlink env)})}))
|
||||
|
||||
(GET "/accounts" {:keys [identity]}
|
||||
(assert-admin identity)
|
||||
{:status 200
|
||||
:headers {"Content-Type" "application/edn"}
|
||||
:body (pr-str (yodlee/get-accounts (yodlee/get-auth-header)))})
|
||||
|
||||
(GET "/provider-accounts" {:keys [identity]}
|
||||
(assert-admin identity)
|
||||
(log/info "working on provider accounts...")
|
||||
{:status 200
|
||||
:headers {"Content-Type" "application/edn"}
|
||||
:body (pr-str @yodlee/in-memory-cache)})
|
||||
(POST "/reauthenticate/:id" {:keys [identity] {:keys [id]} :route-params
|
||||
data :edn-params}
|
||||
(assert-admin identity)
|
||||
(try
|
||||
{:status 200
|
||||
:headers {"Content-Type" "application/edn"}
|
||||
:body (pr-str (yodlee/reauthenticate-and-recache (Long/parseLong id) data (yodlee/get-auth-header)))}
|
||||
(catch Exception e
|
||||
(log/error e)
|
||||
{:status 500
|
||||
:headers {"Content-Type" "application/edn"}
|
||||
:body (pr-str {:message (.getMessage e)
|
||||
:error (.toString e)})})))
|
||||
(POST "/provider-accounts/refresh/:id" {:keys [identity] {:keys [id]} :route-params}
|
||||
(assert-admin identity)
|
||||
(try
|
||||
(yodlee/refresh-provider-account (Long/parseLong id) (yodlee/get-auth-header))
|
||||
{:status 200
|
||||
:headers {"Content-Type" "application/edn"}
|
||||
:body (pr-str @yodlee/in-memory-cache)}
|
||||
(catch Exception e
|
||||
{:status 400
|
||||
:headers {"Content-Type" "application/edn"}
|
||||
:body (pr-str {:message (.getMessage e)
|
||||
:error (.toString e)})})))
|
||||
(POST "/provider-accounts/delete/:id" {:keys [identity] {:keys [id]} :route-params}
|
||||
(assert-admin identity)
|
||||
(try
|
||||
(yodlee/delete-and-uncache-provider-account (Long/parseLong id) (yodlee/get-auth-header))
|
||||
{:status 200
|
||||
:headers {"Content-Type" "application/edn"}
|
||||
:body (pr-str @yodlee/in-memory-cache)}
|
||||
(catch Exception e
|
||||
{:status 400
|
||||
:headers {"Content-Type" "application/edn"}
|
||||
:body (pr-str {:message (.getMessage e)
|
||||
:error (.toString e)})})))
|
||||
(POST "/provider-accounts/:id" {:keys [identity] {:keys [id]} :route-params}
|
||||
(assert-admin identity)
|
||||
(try
|
||||
{:status 200
|
||||
:headers {"Content-Type" "application/edn"}
|
||||
:body (pr-str (yodlee/update-yodlee (Long/parseLong id) (yodlee/get-auth-header)))}
|
||||
(catch Exception e
|
||||
{:status 400
|
||||
:headers {"Content-Type" "application/edn"}
|
||||
:body (pr-str e)}))))
|
||||
wrap-secure))
|
||||
@@ -10,7 +10,6 @@
|
||||
[auto-ap.handler :refer [app]]
|
||||
[auto-ap.import.intuit :as intuit]
|
||||
[auto-ap.import.plaid :as plaid]
|
||||
[auto-ap.import.yodlee :as yodlee]
|
||||
[auto-ap.import.yodlee2 :as yodlee2]
|
||||
[auto-ap.ledger :as ledger]
|
||||
[auto-ap.square.core :as square]
|
||||
|
||||
@@ -98,6 +98,7 @@
|
||||
"sort_order" "DESC"
|
||||
}}})
|
||||
|
||||
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
|
||||
(defn get-order
|
||||
([client location order-id]
|
||||
(log/info "Searching for" (:square-location/client-location location))
|
||||
@@ -482,6 +483,7 @@
|
||||
(d/transact conn)
|
||||
deref))))
|
||||
|
||||
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
|
||||
(defn reset []
|
||||
(->>
|
||||
(d/query {:query {:find ['?e]
|
||||
|
||||
@@ -11,7 +11,6 @@
|
||||
|
||||
(def normal-date "MM/dd/yyyy")
|
||||
(def iso-date "yyyy-MM-dd")
|
||||
(def iso-date-time (:date-hour-minute-second-ms f/formatters))
|
||||
|
||||
(defn parse [v format]
|
||||
(try
|
||||
|
||||
@@ -1,426 +0,0 @@
|
||||
#_{:clj-kondo/ignore [:unused-namespace]}
|
||||
(ns auto-ap.yodlee.core
|
||||
(:require
|
||||
[auto-ap.utils :refer [by]]
|
||||
[clj-http.client :as client]
|
||||
[clojure.core.async :as async]
|
||||
[clojure.data.json :as json]
|
||||
[clojure.tools.logging :as log]
|
||||
[config.core :refer [env]]
|
||||
[mount.core :as mount]
|
||||
[unilog.context :as lc]
|
||||
[yang.scheduler :as scheduler]))
|
||||
|
||||
(def known-bad-yodlee-ids ;; these yodlee ids are ones we wish we could manually delete
|
||||
(set [
|
||||
3432269925
|
||||
3432269925
|
||||
3440074569
|
||||
3440074568
|
||||
3451368964
|
||||
3453413513
|
||||
3453413398
|
||||
3325396245
|
||||
3451368962
|
||||
2987488002
|
||||
3021618678
|
||||
3021618674
|
||||
3025625892
|
||||
3052944039
|
||||
3052944035
|
||||
3079067192
|
||||
3079067193
|
||||
3079067193
|
||||
3122287847
|
||||
3122287842
|
||||
3189405320
|
||||
3189405320
|
||||
3189405321
|
||||
3189405321
|
||||
3189405319
|
||||
3189405319
|
||||
3248171256
|
||||
3248171256
|
||||
3248171257
|
||||
3248171257
|
||||
3248171254
|
||||
3291944265
|
||||
3291944267
|
||||
3291944267
|
||||
3310943251
|
||||
3387770449
|
||||
3387770447
|
||||
3432269929]))
|
||||
|
||||
(defn auth-header
|
||||
([cob-session] (str "{cobSession=" cob-session "}"))
|
||||
([cob-session user-session] (str "{cobSession=" cob-session ",userSession=" user-session "}")))
|
||||
|
||||
(def other-config
|
||||
(if (:yodlee-proxy-host env)
|
||||
{:proxy-host (:yodlee-proxy-host env)
|
||||
:proxy-port (:yodlee-proxy-port env)
|
||||
:retry-handler (fn [ex _ _]
|
||||
(log/error "yodlee Error." ex)
|
||||
false)
|
||||
:socket-timeout 60000
|
||||
:connection-timeout 60000}
|
||||
{:retry-handler (fn [ex _ _]
|
||||
(log/error "yodlee Error." ex)
|
||||
false)
|
||||
:socket-timeout 60000
|
||||
:connection-timeout 60000}))
|
||||
|
||||
(defn retry-thrice
|
||||
([x] (retry-thrice x 0))
|
||||
([x i]
|
||||
(try
|
||||
(x)
|
||||
(catch Exception e
|
||||
(if (>= i 3)
|
||||
(throw e)
|
||||
(do
|
||||
(Thread/sleep 5000)
|
||||
(retry-thrice x (inc i))))))))
|
||||
|
||||
|
||||
(def base-headers {"Api-Version" "1.1"
|
||||
"Cobrand-Name" (:yodlee-cobrand-name env)
|
||||
"Content-Type" "application/json"})
|
||||
|
||||
|
||||
(defn login-cobrand []
|
||||
(retry-thrice
|
||||
(fn []
|
||||
(-> (str (:yodlee-base-url env) "/cobrand/login")
|
||||
(client/post (merge {:headers base-headers
|
||||
:body
|
||||
(json/write-str {:cobrand {:cobrandLogin (:yodlee-cobrand-login env)
|
||||
:cobrandPassword (:yodlee-cobrand-password env)
|
||||
:locale "en_US"}})
|
||||
:as :json}
|
||||
other-config))
|
||||
:body
|
||||
:session
|
||||
:cobSession))))
|
||||
|
||||
|
||||
(defn login-user
|
||||
([cob-session] (login-user cob-session (:yodlee-user-login env) (:yodlee-user-password env)))
|
||||
([cob-session user password]
|
||||
(retry-thrice
|
||||
(fn []
|
||||
(-> (str (:yodlee-base-url env) "/user/login")
|
||||
(client/post (merge {:headers (merge base-headers {"Authorization" (auth-header cob-session)})
|
||||
:body
|
||||
(json/write-str {:user {:loginName user
|
||||
:password password
|
||||
:locale "en_US"}})
|
||||
:as :json}
|
||||
other-config))
|
||||
:body
|
||||
:user
|
||||
:session
|
||||
:userSession)))))
|
||||
|
||||
|
||||
(defn get-auth-header []
|
||||
(let [cob-session (login-cobrand)
|
||||
user-session (login-user cob-session)]
|
||||
{"Authorization" (auth-header cob-session user-session)}))
|
||||
|
||||
|
||||
(defn get-accounts [auth-header]
|
||||
(retry-thrice
|
||||
(fn []
|
||||
(-> (str (:yodlee-base-url env) "/accounts")
|
||||
(client/get (merge {:headers (merge base-headers auth-header)
|
||||
:as :json}
|
||||
other-config))
|
||||
:body
|
||||
:account))))
|
||||
|
||||
|
||||
(defn get-accounts-for-provider-account [provider-account-id auth-header]
|
||||
(try
|
||||
(retry-thrice
|
||||
(fn []
|
||||
(-> (str (:yodlee-base-url env) "/accounts?providerAccountId=" provider-account-id)
|
||||
(client/get (merge {:headers (merge base-headers auth-header)
|
||||
:as :json}
|
||||
other-config))
|
||||
:body
|
||||
:account)))
|
||||
(catch Exception e
|
||||
(log/error (str "Couldn't get accounts for provider account '" provider-account-id "'")
|
||||
e)
|
||||
[])))
|
||||
|
||||
|
||||
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
|
||||
(defn get-account [i auth-header]
|
||||
(retry-thrice
|
||||
(fn []
|
||||
(-> (str (:yodlee-base-url env) (str "/accounts/" i))
|
||||
(client/get (merge {:headers (merge base-headers auth-header)
|
||||
:as :json}
|
||||
other-config))
|
||||
:body
|
||||
:account))))
|
||||
|
||||
|
||||
(defn get-provider-accounts [auth-header]
|
||||
(retry-thrice
|
||||
(fn []
|
||||
(-> (str (:yodlee-base-url env) "/providerAccounts")
|
||||
(client/get (merge {:headers (merge base-headers auth-header)
|
||||
:as :json}
|
||||
other-config))
|
||||
:body
|
||||
:providerAccount))))
|
||||
|
||||
|
||||
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
|
||||
(defn get-provider-account [id auth-header]
|
||||
(retry-thrice
|
||||
(fn []
|
||||
(-> (str (:yodlee-base-url env) "/providerAccounts/" id)
|
||||
(client/get (merge {:headers (merge base-headers auth-header)
|
||||
:as :json}
|
||||
other-config))
|
||||
:body
|
||||
:providerAccount))))
|
||||
|
||||
|
||||
(defn get-provider-account-detail [id auth-header]
|
||||
(retry-thrice
|
||||
(fn []
|
||||
(-> (str (:yodlee-base-url env) "/providerAccounts/" id)
|
||||
(client/get (merge {:headers (merge base-headers auth-header)
|
||||
:query-params {"include" "credentials,preferences"}
|
||||
:as :json}
|
||||
other-config))
|
||||
:body
|
||||
:providerAccount
|
||||
first))))
|
||||
|
||||
|
||||
(defn update-provider-account [pa auth-header]
|
||||
(retry-thrice
|
||||
(fn []
|
||||
(-> (str (:yodlee-base-url env) "/providerAccounts?providerAccountIds=" pa)
|
||||
(client/put (merge {:headers (merge base-headers auth-header)
|
||||
:body "{\"dataSetName\": [\"BASIC_AGG_DATA\"]}"
|
||||
:as :json}
|
||||
other-config))))))
|
||||
|
||||
|
||||
(defn delete-provider-account [id auth-header]
|
||||
(retry-thrice
|
||||
(fn []
|
||||
(-> (str (:yodlee-base-url env) "/providerAccounts/" id)
|
||||
(client/delete (merge {:headers (merge base-headers auth-header)
|
||||
:as :json}
|
||||
other-config))
|
||||
:body
|
||||
:providerAccount
|
||||
first))))
|
||||
|
||||
|
||||
(defn get-transaction-page
|
||||
([account batch-size skip auth-header]
|
||||
(retry-thrice
|
||||
(fn []
|
||||
(-> (str (:yodlee-base-url env) "/transactions?top=" batch-size "&skip=" skip "&accountId=" account)
|
||||
(client/get (merge {:headers (merge base-headers auth-header)
|
||||
:as :json}
|
||||
other-config))
|
||||
:body
|
||||
:transaction))))
|
||||
([account start end batch-size skip auth-header]
|
||||
(-> (str (:yodlee-base-url env) "/transactions?top=" batch-size "&fromDate=" start "&toDate=" end "&skip=" skip "&accountId=" account)
|
||||
(client/get (merge {:headers (merge base-headers auth-header)
|
||||
:as :json}
|
||||
other-config))
|
||||
:body
|
||||
:transaction)))
|
||||
|
||||
|
||||
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
|
||||
(defn count-specific-transactions [account auth-header]
|
||||
(retry-thrice
|
||||
(fn []
|
||||
(-> (str (:yodlee-base-url env) "/transactions/count?accountId=" account)
|
||||
(client/get (merge {:headers (merge base-headers auth-header)
|
||||
:as :json}
|
||||
other-config))
|
||||
:body
|
||||
:transaction))))
|
||||
|
||||
|
||||
(defn get-access-token []
|
||||
(try
|
||||
(let [cob-session (login-cobrand)
|
||||
user-session (login-user cob-session)
|
||||
token (->
|
||||
(str (:yodlee-base-url env) "/user/accessTokens?appIds=" 10003600)
|
||||
|
||||
(client/get
|
||||
(merge {:headers (merge base-headers {"Authorization" (auth-header cob-session user-session)})
|
||||
:as :json}
|
||||
other-config))
|
||||
(doto log/info)
|
||||
:body
|
||||
:user
|
||||
:accessTokens
|
||||
first
|
||||
:value)]
|
||||
[user-session token])
|
||||
(catch Exception e
|
||||
(log/error e)
|
||||
(throw e))))
|
||||
|
||||
|
||||
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
|
||||
(defn create-user []
|
||||
(let [cob-session (login-cobrand)]
|
||||
(-> (str (:yodlee-base-url env) "/user/register")
|
||||
(client/post (merge {:headers (merge base-headers {"Authorization" (auth-header cob-session)})
|
||||
:body (json/write-str {:user {:loginName "brycesPersoonal2"
|
||||
:password "kV@mdv3TU11"
|
||||
:email "yodleepersonal2@brycecovertoperations.com"}})
|
||||
:as :json}
|
||||
other-config))
|
||||
:body)))
|
||||
|
||||
|
||||
(defn reauthenticate [pa data auth-header]
|
||||
(try
|
||||
(retry-thrice
|
||||
(fn []
|
||||
(-> (str (:yodlee-base-url env) "/providerAccounts?providerAccountIds=" pa)
|
||||
(client/put (merge {:headers (merge base-headers auth-header)
|
||||
:body (json/write-str data)
|
||||
:as :json}
|
||||
other-config)))))
|
||||
(catch Exception e
|
||||
(log/error e))))
|
||||
|
||||
|
||||
;; helpers
|
||||
|
||||
|
||||
(defn get-specific-transactions [account auth-header]
|
||||
(log/infof "Getting yodlee transactions for account %s" account)
|
||||
(let [batch-size 100]
|
||||
(loop [transactions []
|
||||
skip 0]
|
||||
(let [transaction-batch (get-transaction-page account batch-size skip auth-header)]
|
||||
(if (seq transaction-batch)
|
||||
(recur (concat transactions transaction-batch) (+ batch-size skip))
|
||||
transactions)))))
|
||||
|
||||
|
||||
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
|
||||
(defn get-specific-transactions-with-date [account start end auth-header]
|
||||
(let [batch-size 100]
|
||||
(loop [transactions []
|
||||
skip 0]
|
||||
(let [transaction-batch (get-transaction-page account start end batch-size skip auth-header)]
|
||||
(if (seq transaction-batch)
|
||||
(recur (concat transactions transaction-batch) (+ batch-size skip))
|
||||
transactions)))))
|
||||
|
||||
|
||||
(defn get-provider-accounts-with-details [auth-header]
|
||||
(let [provider-accounts (get-provider-accounts auth-header)
|
||||
concurrent 10
|
||||
output-chan (async/chan)]
|
||||
(async/pipeline-blocking concurrent
|
||||
output-chan
|
||||
(map (fn [provider-account]
|
||||
(lc/with-context {:provider-account-id (:id provider-account)}
|
||||
(get-provider-account-detail (:id provider-account) auth-header))))
|
||||
(async/to-chan! provider-accounts)
|
||||
true
|
||||
(fn [e]
|
||||
(lc/with-context {:source "Yodlee"}
|
||||
(log/error "Yodlee pipeline error" e))))
|
||||
(async/<!! (async/into [] output-chan))))
|
||||
|
||||
|
||||
(defn concurrent-get-accounts-for-providers [provider-account-ids auth-header]
|
||||
(let [concurrent 20
|
||||
output-chan (async/chan)]
|
||||
(async/pipeline-blocking concurrent
|
||||
output-chan
|
||||
(map (fn [provider-account-id]
|
||||
(lc/with-context {:provider-account-id provider-account-id}
|
||||
[provider-account-id
|
||||
(get-accounts-for-provider-account provider-account-id auth-header)])))
|
||||
(async/to-chan! provider-account-ids)
|
||||
true
|
||||
(fn [e]
|
||||
(lc/with-context {:source "Yodlee"}
|
||||
(log/error "Yodlee pipeline error" e))))
|
||||
(async/<!! (async/into {} output-chan))))
|
||||
|
||||
|
||||
(defn get-provider-accounts-with-accounts [auth-header]
|
||||
(let [provider-accounts (by :id (get-provider-accounts-with-details auth-header))
|
||||
accounts (concurrent-get-accounts-for-providers (keys provider-accounts) auth-header)]
|
||||
(->> accounts
|
||||
(reduce
|
||||
(fn [provider-accounts [which accounts]]
|
||||
(assoc-in provider-accounts [which :accounts] accounts))
|
||||
provider-accounts)
|
||||
vals)))
|
||||
|
||||
|
||||
(mount/defstate in-memory-cache
|
||||
:start (atom []))
|
||||
|
||||
|
||||
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
|
||||
(defn refresh-in-memory-cache []
|
||||
(lc/with-context {:source "refreshing-in-memory-cache"}
|
||||
(try
|
||||
(log/info "Refreshing Yodlee in memory cache")
|
||||
(reset! in-memory-cache (get-provider-accounts-with-accounts (get-auth-header)))
|
||||
(catch Exception e
|
||||
(log/error e)))))
|
||||
|
||||
|
||||
#_(mount/defstate in-memory-cache-worker
|
||||
:start (scheduler/every (* 5 60 1000) refresh-in-memory-cache)
|
||||
:stop (scheduler/stop in-memory-cache-worker))
|
||||
|
||||
|
||||
(defn refresh-provider-account [id auth-header]
|
||||
(swap! in-memory-cache
|
||||
(fn [i]
|
||||
(-> (by :id i)
|
||||
(assoc id (assoc (get-provider-account-detail id auth-header)
|
||||
:accounts (get-accounts-for-provider-account id auth-header)))
|
||||
vals))))
|
||||
|
||||
|
||||
(defn delete-and-uncache-provider-account [id auth-header]
|
||||
(delete-provider-account id auth-header)
|
||||
(swap! in-memory-cache
|
||||
(fn [i]
|
||||
(-> (by :id i)
|
||||
(dissoc id)
|
||||
vals))))
|
||||
|
||||
|
||||
(defn update-yodlee [id auth-header]
|
||||
(update-provider-account id auth-header)
|
||||
(refresh-provider-account id auth-header))
|
||||
|
||||
|
||||
(defn reauthenticate-and-recache [pa data auth-header]
|
||||
(reauthenticate pa data auth-header)
|
||||
(refresh-provider-account pa auth-header))
|
||||
|
||||
|
||||
@@ -114,15 +114,6 @@
|
||||
"ZZZZZZ"
|
||||
(:location x))]))))
|
||||
|
||||
(defn locations [pnl-data]
|
||||
(->> (client-locations pnl-data)
|
||||
(map second)
|
||||
set
|
||||
(sort-by (fn [x]
|
||||
(if (= x "HQ" )
|
||||
"ZZZZZZ"
|
||||
x)))))
|
||||
|
||||
(defn aggregate-accounts [pnl-data]
|
||||
(reduce (fnil + 0.0) 0.0 (map :amount (:data pnl-data))))
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
[clojure.tools.logging :as log]
|
||||
[unilog.context :as lc])]))
|
||||
|
||||
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
|
||||
(defn by
|
||||
([f xs]
|
||||
(by f identity xs))
|
||||
@@ -14,15 +15,7 @@
|
||||
{}
|
||||
xs)))
|
||||
|
||||
(defn replace-if [f candidate existing]
|
||||
(reduce
|
||||
(fn [xs x]
|
||||
(if (f x candidate)
|
||||
(conj xs candidate)
|
||||
(conj xs x)))
|
||||
[]
|
||||
existing))
|
||||
|
||||
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
|
||||
(defn replace-by [xs f x]
|
||||
(let [found? (atom false)
|
||||
replaced (mapv
|
||||
@@ -36,34 +29,15 @@
|
||||
replaced
|
||||
(into [x] replaced))))
|
||||
|
||||
|
||||
(defn remove-by [xs f x]
|
||||
(into []
|
||||
(filter
|
||||
(fn [t]
|
||||
(if (= (f t) (f x))
|
||||
false
|
||||
true))
|
||||
xs)))
|
||||
(defn merge-by [xs f x]
|
||||
(let [found? (atom false)
|
||||
replaced (mapv
|
||||
(fn [t]
|
||||
(if (= (f t) (f x))
|
||||
(do (reset! found? true)
|
||||
(merge t x))
|
||||
t))
|
||||
xs)]
|
||||
(if @found?
|
||||
replaced
|
||||
(into [x] replaced))))
|
||||
|
||||
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
|
||||
(defn dollars-0? [amt]
|
||||
(< -0.001 amt 0.001))
|
||||
|
||||
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
|
||||
(defn dollars= [amt1 amt2]
|
||||
(dollars-0? (- amt1 amt2) ))
|
||||
|
||||
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
|
||||
(defn deep-merge [v & vs]
|
||||
(letfn [(rec-merge [v1 v2]
|
||||
(if (and (map? v1) (map? v2))
|
||||
@@ -73,8 +47,10 @@
|
||||
(reduce #(rec-merge %1 %2) v vs)
|
||||
(last vs))))
|
||||
|
||||
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
|
||||
(def default-pagination-size 20)
|
||||
|
||||
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
|
||||
(defn allow-once [f]
|
||||
(let [in-progress? (atom false)]
|
||||
(fn []
|
||||
@@ -86,22 +62,22 @@
|
||||
(reset! in-progress? false)))))))
|
||||
|
||||
|
||||
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
|
||||
(defn heartbeat [f id]
|
||||
(fn []
|
||||
#?(:clj (do
|
||||
(lc/with-context {:source id}
|
||||
(try
|
||||
(log/info "Starting background process " id)
|
||||
(f)
|
||||
(log/info "Completed background process " id)
|
||||
#?(:clj (lc/with-context {:source id}
|
||||
(try
|
||||
(log/info "Starting background process " id)
|
||||
(f)
|
||||
(log/info "Completed background process " id)
|
||||
(statsd/service-check {:name (str id)
|
||||
:status :ok}
|
||||
nil)
|
||||
(catch Exception e
|
||||
(log/error e)
|
||||
(statsd/service-check {:name (str id)
|
||||
:status :ok}
|
||||
nil)
|
||||
(catch Exception e
|
||||
(log/error e)
|
||||
(statsd/service-check {:name (str id)
|
||||
:status :critical}
|
||||
nil)))))
|
||||
:status :critical}
|
||||
nil))))
|
||||
|
||||
:cljs (do (println "Heartbeat for " id)
|
||||
(f)))))
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
(ns auto-ap.config)
|
||||
|
||||
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
|
||||
(def debug?
|
||||
^boolean goog.DEBUG)
|
||||
|
||||
@@ -39,15 +39,6 @@
|
||||
[k v])))
|
||||
(into {} )))))))
|
||||
|
||||
(re-frame/reg-fx
|
||||
:new-window
|
||||
(fn [url]
|
||||
(.open js/window url)))
|
||||
|
||||
#_(re-frame/reg-fx
|
||||
:dispatch-sync
|
||||
(fn [event]
|
||||
(re-frame/dispatch-sync event)))
|
||||
|
||||
(re-frame/reg-fx
|
||||
:set-local-storage
|
||||
@@ -121,47 +112,6 @@
|
||||
(conj on-success)
|
||||
(re-frame/dispatch))))))))
|
||||
|
||||
(re-frame/reg-fx
|
||||
:https
|
||||
(fn [{:keys [requests on-success on-failure owns-state]}]
|
||||
(go
|
||||
(when (:multi owns-state)
|
||||
(re-frame/dispatch-sync [::status/loading-multi (:multi owns-state) (:which owns-state)]))
|
||||
|
||||
(when (:single owns-state)
|
||||
(re-frame/dispatch-sync [::status/loading (:single owns-state)]))
|
||||
(let [results (->>
|
||||
(for [{:keys [method body headers uri token]} requests]
|
||||
(go
|
||||
(let [headers (if token
|
||||
(assoc headers "Authorization" (str "Token " token))
|
||||
headers)
|
||||
response (<! (http/request {:method method
|
||||
:body body
|
||||
:headers headers
|
||||
:url uri}))]
|
||||
(if (>= (:status response) 400)
|
||||
:error
|
||||
:success))))
|
||||
(async/merge)
|
||||
(async/reduce conj [])
|
||||
(async/<!))]
|
||||
(println "DONE")
|
||||
(if (some #{:error} results)
|
||||
(do
|
||||
(when (:multi owns-state)
|
||||
(re-frame/dispatch [::status/error-multi (:multi owns-state) (:which owns-state) results]))
|
||||
(when (:single owns-state)
|
||||
(re-frame/dispatch [::status/error (:single owns-state) results]))
|
||||
|
||||
(re-frame/dispatch on-failure))
|
||||
(do
|
||||
(when (:multi owns-state)
|
||||
(re-frame/dispatch [::status/completed-multi (:multi owns-state) (:which owns-state)]))
|
||||
(when (:single owns-state)
|
||||
(re-frame/dispatch [::status/completed (:single owns-state)]))
|
||||
(re-frame/dispatch on-success)))))))
|
||||
|
||||
(defn kebab->snake [s]
|
||||
(str/replace s #"-" "_"))
|
||||
|
||||
|
||||
@@ -76,17 +76,6 @@
|
||||
(fn [db [_ which]]
|
||||
(update-in db [:menu which :active?] #(not %))))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::logged-in
|
||||
(fn [{:keys [db]} [_ token user]]
|
||||
{:graphql {:token token
|
||||
:query-obj {:venia/queries [[:client (client-query token)]]}
|
||||
|
||||
:on-success [::received-initial]
|
||||
:on-error [::failed-initial]}
|
||||
:db (assoc db
|
||||
:user (assoc user :token token)
|
||||
:is-initial-loading? true)}))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::received-initial
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
(:require [re-frame.core :as re-frame]
|
||||
[re-frame.interceptor :as i]
|
||||
[auto-ap.status :as status]
|
||||
[auto-ap.views.utils :refer [dispatch-event]]
|
||||
[malli.core :as m]))
|
||||
|
||||
|
||||
@@ -20,13 +19,6 @@
|
||||
:data
|
||||
(get-in f))))
|
||||
|
||||
(re-frame/reg-sub
|
||||
::loading-class
|
||||
(fn [db [_ x]]
|
||||
(if (#{"loading" :loading} (get-in db [::forms x :status]) )
|
||||
"is-loading"
|
||||
"")))
|
||||
|
||||
(defn start-form
|
||||
([db form data]
|
||||
(start-form db form data nil))
|
||||
@@ -131,17 +123,13 @@
|
||||
(assoc-in [::forms form :error] (or (:message (first result))
|
||||
result)))))
|
||||
|
||||
|
||||
(defn ^:deprecated side-bar-form [{:keys [form]} children]
|
||||
[:div [:a.delete.is-pulled-right {:on-click (dispatch-event [::form-closing form])}] [:div children]])
|
||||
|
||||
|
||||
;; TODO ^:deprecated
|
||||
(defn loading [db id]
|
||||
(-> db
|
||||
(assoc-in [::forms id :status] :loading)
|
||||
(assoc-in [::forms id :error] nil)))
|
||||
|
||||
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
|
||||
(defn settles [{:keys [event time key]}]
|
||||
(i/->interceptor
|
||||
:id :settles
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
(ns ^:figwheel-hooks auto-ap.reload)
|
||||
|
||||
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
|
||||
(defn ^:after-load reload []
|
||||
(println "RELOADING")
|
||||
(@(resolve 'auto-ap.core/mount-root)))
|
||||
|
||||
@@ -13,14 +13,6 @@
|
||||
(def not-empty-string (m/schema [:re {:error/message "Required"} #"\S+"]))
|
||||
(def code-string (m/schema [:re #"[A-Z0-9\-]+"]))
|
||||
|
||||
(def positive-integer (m/schema [:int {:min 1}]))
|
||||
(def integer-code (m/schema [:int {:min 10000 :max 99999}]))
|
||||
|
||||
(def expense-account (m/schema [:map
|
||||
[:id :string]
|
||||
[:account reference]
|
||||
[:location :string]
|
||||
[:amount money]]))
|
||||
|
||||
|
||||
(def approval-status (m/schema [:enum :unapproved :requires-feedback :approved :excluded]))
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
[minisearch :as ms]))
|
||||
(set! *warn-on-infer* true)
|
||||
|
||||
#_{:clj-kondo/ignore [:unresolved-symbol]}
|
||||
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var :unresolved-symbol]}
|
||||
(def MiniSearch (if ms (aget ms "default")
|
||||
nil))
|
||||
|
||||
@@ -29,15 +29,6 @@
|
||||
(fn [c]
|
||||
(map #(select-keys % [:id :name]) c)))
|
||||
|
||||
(re-frame/reg-sub
|
||||
::all-accounts
|
||||
(fn [db]
|
||||
(:accounts db)))
|
||||
|
||||
(re-frame/reg-sub
|
||||
::all-accounts-by-id
|
||||
(fn [db]
|
||||
(by :id (:accounts db))))
|
||||
|
||||
(re-frame/reg-sub
|
||||
::bank-accounts
|
||||
@@ -101,10 +92,6 @@
|
||||
(fn [db [_ id]]
|
||||
(-> db :menu (get id) :active?)))
|
||||
|
||||
(re-frame/reg-sub
|
||||
::menu
|
||||
(fn [db]
|
||||
(:menu db)))
|
||||
|
||||
(re-frame/reg-sub
|
||||
::is-initial-loading?
|
||||
@@ -175,8 +162,3 @@
|
||||
(if (= 500 (:status error))
|
||||
"System error occured. If you are stuck, please notify ben@integreatconsult.com."
|
||||
(:message error)))))
|
||||
|
||||
(re-frame/reg-sub
|
||||
::yodlee-merchants
|
||||
(fn [db]
|
||||
(:yodlee-merchants db)))
|
||||
|
||||
@@ -18,8 +18,7 @@
|
||||
[auto-ap.views.utils
|
||||
:refer [dispatch-event str->int with-is-admin? with-user]]
|
||||
[malli.core :as m]
|
||||
[re-frame.core :as re-frame]
|
||||
[reagent.core :as r]))
|
||||
[re-frame.core :as re-frame]))
|
||||
|
||||
;; Remaining cleanup todos:
|
||||
;; test minification
|
||||
@@ -131,11 +130,6 @@
|
||||
{:dispatch-n [[::forms/attempted-submit ::vendor-form]
|
||||
[::status/error ::vendor-form [{:message "Please fix the errors and try again."}]]]})))
|
||||
|
||||
(defn pull-left []
|
||||
(into [:div {:style {:position "relative"
|
||||
:left "-40px"}}]
|
||||
(r/children (r/current-component))))
|
||||
|
||||
(defn contact-field [{:keys [name field]}]
|
||||
[form-builder/with-scope {:scope field}
|
||||
[form-builder/vertical-control
|
||||
|
||||
@@ -22,11 +22,6 @@
|
||||
(fn [db]
|
||||
(::users db)))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::params-change
|
||||
(fn [_ [_ params]]
|
||||
{:set-uri-params params}))
|
||||
|
||||
(re-frame/reg-sub
|
||||
::page
|
||||
:<- [::params]
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
(ns auto-ap.views.pages.admin.vendors.table
|
||||
(:require
|
||||
[auto-ap.subs :as subs]
|
||||
[auto-ap.views.components.buttons :as buttons]
|
||||
[auto-ap.views.components.grid :as grid]
|
||||
[auto-ap.views.components.vendor-dialog :as vendor-dialog]
|
||||
@@ -9,10 +8,7 @@
|
||||
[re-frame.core :as re-frame]))
|
||||
|
||||
(defn vendors-table [{:keys [data-page]}]
|
||||
(let [{:keys [data]} @(re-frame/subscribe [::data-page/page data-page])
|
||||
accounts @(re-frame/subscribe [::subs/all-accounts-by-id])]
|
||||
(println "DATA COUNT" (keys data))
|
||||
|
||||
(let [{:keys [data]} @(re-frame/subscribe [::data-page/page data-page])]
|
||||
[grid/grid {:data-page data-page
|
||||
:column-count 4}
|
||||
[grid/controls data]
|
||||
@@ -33,7 +29,7 @@
|
||||
[:div.mx-2.tag.is-info.is-light total-usage " usages, " (count (:usage v)) " clients" ]
|
||||
[:div.mx-2.tag.is-warning.is-light "Unused"]))]
|
||||
[grid/cell {} (:email (:primary-contact v))]
|
||||
[grid/cell {} (-> v :default-account :id accounts :name)]
|
||||
[grid/cell {} (-> v :default-account :name)]
|
||||
[grid/cell {}
|
||||
[buttons/fa-icon {:event [::vendor-dialog/started v]
|
||||
:icon "fa-pencil"}]]])]]]))
|
||||
|
||||
@@ -30,12 +30,6 @@
|
||||
(fn [table-params]
|
||||
table-params))
|
||||
|
||||
(re-frame/reg-sub
|
||||
::plaid-items
|
||||
(fn [db]
|
||||
(::plaid-items db)))
|
||||
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::data-requested
|
||||
(fn [{:keys [db]} [_ params]]
|
||||
@@ -119,11 +113,6 @@
|
||||
(-> db
|
||||
(assoc-in [::link-token] (:token (:plaid-link-token link-token))))))
|
||||
|
||||
(re-frame/reg-event-db
|
||||
::received
|
||||
(fn [db [_ d]]
|
||||
(assoc-in db [::plaid-items] (:plaid-item-page d))))
|
||||
|
||||
|
||||
(defn plaid-item-table []
|
||||
[table/table {:data-page ::page
|
||||
|
||||
@@ -127,9 +127,6 @@
|
||||
:filters filters
|
||||
:table-params table-params}))
|
||||
|
||||
(defn in-page-entities [which]
|
||||
(re-frame/path [::data which :data ] ))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::table-params-changed
|
||||
(fn [{:keys [db]} [_ which params]]
|
||||
|
||||
@@ -151,16 +151,6 @@
|
||||
[]]]}
|
||||
:on-success [::invalidated]}}))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::approve-invoices
|
||||
(fn [cofx [_ on-success]]
|
||||
{:http {:method :post
|
||||
:token (-> cofx :db :user)
|
||||
:uri (str "/api/invoices/approve"
|
||||
(when-let [client-id (:id @(re-frame/subscribe [::subs/client]))]
|
||||
(str "?client=" client-id)))
|
||||
:on-success on-success}}))
|
||||
|
||||
(defn approve-reject-button [checked]
|
||||
[:div.buttons
|
||||
[:button.button.is-primary {:on-click (dispatch-event [::approve-invoices-clicked checked])
|
||||
|
||||
@@ -18,16 +18,8 @@
|
||||
[auto-ap.events :as events]
|
||||
[vimsical.re-frame.cofx.inject :as inject]
|
||||
[auto-ap.forms.builder :as form-builder]
|
||||
[malli.core :as m]
|
||||
[auto-ap.schema :as schema]
|
||||
[auto-ap.views.components :as com]))
|
||||
|
||||
(re-frame/reg-sub
|
||||
::can-submit
|
||||
:<- [::forms/form ::form]
|
||||
(fn [{ {:keys []} :data}]
|
||||
true))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::coded
|
||||
(fn [_ [_ _ _]]
|
||||
@@ -107,15 +99,10 @@
|
||||
{::track/dispose {:id ::vendor-change}}))
|
||||
|
||||
|
||||
(def bulk-update-schema
|
||||
(m/schema
|
||||
[:map
|
||||
[:vendor schema/reference]]))
|
||||
(defn form-content [_]
|
||||
(let [{:keys [data]} @(re-frame/subscribe [::forms/form ::form])]
|
||||
[form-builder/builder {:submit-event [::code-selected]
|
||||
:change-event [::changed]
|
||||
:can-submit [::can-submit]
|
||||
:id ::form}
|
||||
|
||||
|
||||
|
||||
@@ -10,12 +10,6 @@
|
||||
[malli.core :as m]
|
||||
[re-frame.core :as re-frame]))
|
||||
|
||||
(re-frame/reg-sub
|
||||
::can-submit
|
||||
:<- [::forms/form ::form]
|
||||
(fn [{ {:keys [data]} :data}]
|
||||
(not-empty data)))
|
||||
|
||||
(def schema
|
||||
(m/schema [:map [:data schema/not-empty-string]]))
|
||||
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
|
||||
(def date-regex #"[2]{1}[0-9]{3}-[0-9]{1,2}-[0-9]{1,2}")
|
||||
(def money-regex #"\-?[0-9]+(\.[0-9]{2})?$")
|
||||
|
||||
(def nff
|
||||
(NumberFormat. Format/CURRENCY))
|
||||
@@ -54,9 +53,6 @@
|
||||
|
||||
))
|
||||
|
||||
(defn active-when= [active-page candidate]
|
||||
(when (= active-page candidate) " is-active"))
|
||||
|
||||
(defn active-when [active-page f & rest]
|
||||
|
||||
(when (apply f (into [active-page] rest)) " is-active"))
|
||||
@@ -72,12 +68,6 @@
|
||||
(re-frame/dispatch (conj event (.. e -target -value)))))
|
||||
|
||||
|
||||
(defn delayed-dispatch [e]
|
||||
(fn [_]
|
||||
(js/setTimeout #(re-frame/dispatch e) 151)
|
||||
false))
|
||||
|
||||
|
||||
(defn dispatch-event [event]
|
||||
(fn [e]
|
||||
(when (.-stopPropagation e)
|
||||
@@ -286,9 +276,6 @@
|
||||
(js/document.execCommand "copy")
|
||||
(.removeChild js/document.body el)))
|
||||
|
||||
(defn account->match-text [x]
|
||||
(str (:numeric-code x) " - " (:name x)))
|
||||
|
||||
(defn str->int [x]
|
||||
(cond
|
||||
(nil? x)
|
||||
|
||||
Reference in New Issue
Block a user