added suggestions

This commit is contained in:
2022-07-26 07:01:18 -07:00
parent 96c80853ef
commit 84f7e734f0
65 changed files with 130 additions and 1140 deletions

View File

@@ -41,10 +41,12 @@
(lc/pull-context "container") (lc/pull-context "container")
(lc/pull-context "ip"))) (lc/pull-context "ip")))
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(mount/defstate logging-context (mount/defstate logging-context
:start (set-logging-context) :start (set-logging-context)
:stop (stop-logging-context)) :stop (stop-logging-context))
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(mount/defstate metrics-setup (mount/defstate metrics-setup
:start (statsd/setup! :host "127.0.0.1" :port 8125 :prefix "integreat.app" :tags (into #{(str "env:" (:dd-env env)) :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))} (str "service:" (:dd-service env))}

View File

@@ -30,6 +30,7 @@
(= ":plaid" body) (= ":plaid" body)
(p/import-plaid))))) (p/import-plaid)))))
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(defn fake-message [] (defn fake-message []
(sqs/send-message {:queue-url (:requests-queue-url env) (sqs/send-message {:queue-url (:requests-queue-url env)
:message-body ":intuit"} )) :message-body ":intuit"} ))

View File

@@ -100,6 +100,7 @@
(s3/delete-object {:bucket-name bucket-name (s3/delete-object {:bucket-name bucket-name
:key k})) :key k}))
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(defn unmark-key [k] (defn unmark-key [k]
(s3/copy-object {:source-bucket-name bucket-name (s3/copy-object {:source-bucket-name bucket-name
:destination-bucket-name bucket-name :destination-bucket-name bucket-name

View File

@@ -14,9 +14,11 @@
#_(def uri "datomic:mem://datomic-transactor:4334/invoice") #_(def uri "datomic:mem://datomic-transactor:4334/invoice")
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(defn create-database [] (defn create-database []
(d/create-database uri)) (d/create-database uri))
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(defn drop-database [] (defn drop-database []
(d/delete-database uri)) (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]) [ 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])
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(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))))
(defn migrate-vendors [_] (defn migrate-vendors [_]
[[]]) [[]])
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(defn migrate-clients [_] (defn migrate-clients [_]
[[]]) [[]])
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(defn migrate-invoices [_] (defn migrate-invoices [_]
[[]]) [[]])
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(defn migrate-payments [_] (defn migrate-payments [_]
[[]]) [[]])
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(defn migrate-invoices-payments [_] (defn migrate-invoices-payments [_]
[[]]) [[]])
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(defn migrate-invoices-expense-accounts [_] (defn migrate-invoices-expense-accounts [_]
[[]]) [[]])
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(defn migrate-transactions [_] (defn migrate-transactions [_]
[[]]) [[]])
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(defn migrate-users [_] (defn migrate-users [_]
[[]]) [[]])

View File

@@ -85,12 +85,3 @@
:args [(d/db (d/connect uri)) code]})) :args [(d/db (d/connect uri)) code]}))
(first) (first)
(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" )

View File

@@ -124,8 +124,3 @@
[(->> (graphql-results ids-to-retrieve db args)) [(->> (graphql-results ids-to-retrieve db args))
matching-count])) matching-count]))
(defn get-by-id [id]
(->>
(d/pull (d/db conn) default-read id)
(<-datomic)))

View File

@@ -5,52 +5,17 @@
[clj-time.coerce :as c] [clj-time.coerce :as c]
[auto-ap.datomic.accounts :as d-accounts])) [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] (defn raw-graphql-ids [db args]
(let [query (cond-> {:query {:find [] (let [query (cond-> {:query {:find []
:in ['$ ] :in ['$ ]
:where []} :where []}
:args [db]} :args [db]}
(:client-id args) (:client-id args)
(merge-query {:query {:in ['?client-id] (merge-query {:query {:in ['?client-id]
:where ['[?e :journal-entry/client ?client-id]]} :where ['[?e :journal-entry/client ?client-id]]}
:args [(:client-id args)]}) :args [(:client-id args)]})
(:only-external args) (:only-external args)
(merge-query {:query {:where ['(not [?e :journal-entry/original-entity ])]}}) (merge-query {:query {:where ['(not [?e :journal-entry/original-entity ])]}})

View File

@@ -23,12 +23,14 @@
(:import (:import
(datomic Util))) (datomic Util)))
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(defn read-dtm (defn read-dtm
"Reads a dtm file (i.e., an edn file with datomic tags in it) from the classpath "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." and returns a vector of all forms contained within."
[filename] [filename]
(-> (io/resource filename) (io/reader) (Util/readAll))) (-> (io/resource filename) (io/reader) (Util/readAll)))
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(defn functions [_] (defn functions [_]
[[{:db/ident :pay [[{:db/ident :pay
:db/doc "Data function that increments value of attribute a by amount." :db/doc "Data function that increments value of attribute a by amount."
@@ -47,6 +49,7 @@
:code [[:db/add e a :code [[:db/add e a
(-> (d/entity db e) a (+ amount))]] })}]] ) (-> (d/entity db e) a (+ amount))]] })}]] )
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(defn fix-pay-function [_] (defn fix-pay-function [_]
[[{:db/ident :pay [[{:db/ident :pay
:db/doc "Data function that increments value of attribute a by amount." :db/doc "Data function that increments value of attribute a by amount."

View File

@@ -2,6 +2,7 @@
(:require [datomic.api :as d])) (:require [datomic.api :as d]))
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(defn add-account-visibility-fields [_] (defn add-account-visibility-fields [_]
[[ [[
{:db/ident :bank-account/visible {:db/ident :bank-account/visible
@@ -13,6 +14,7 @@
:db/cardinality :db.cardinality/one :db/cardinality :db.cardinality/one
:db/doc "The sort order of the bank account"}]]) :db/doc "The sort order of the bank account"}]])
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(defn make-every-account-visible [conn] (defn make-every-account-visible [conn]
(let [all-account-ids (d/query (let [all-account-ids (d/query
{:query {:find ['?e] {:query {:find ['?e]

View File

@@ -3,6 +3,7 @@
[clojure.string :as str] [clojure.string :as str]
[datomic.api :as d])) [datomic.api :as d]))
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(defn add-bank-account-codes-schema [_] (defn add-bank-account-codes-schema [_]
[[{:db/ident :bank-account/code [[{:db/ident :bank-account/code
:db/valueType :db.type/string :db/valueType :db.type/string
@@ -11,6 +12,7 @@
:db/doc "A bank account's computer-friendly name"}]]) :db/doc "A bank account's computer-friendly name"}]])
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(defn add-bank-account-codes [conn] (defn add-bank-account-codes [conn]
(let [db (d/db conn) (let [db (d/db conn)
all-bank-accounts (d/query {:query {:find ['?b '?original-id '?client-code] all-bank-accounts (d/query {:query {:find ['?b '?original-id '?client-code]

View File

@@ -33,6 +33,7 @@
["Iguanas Burritozilla" "IBC"]] ["Iguanas Burritozilla" "IBC"]]
(into {})) (into {}))
) )
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(defn add-client-codes [a] (defn add-client-codes [a]
[(->> (d/query {:query {:find '[?name ?e] [(->> (d/query {:query {:find '[?name ?e]
:in ['$] :in ['$]

View File

@@ -1,25 +1,10 @@
(ns auto-ap.datomic.migrate.add-general-ledger (ns auto-ap.datomic.migrate.add-general-ledger
(:require [datomic.api :as d] (:require
[auto-ap.datomic :refer [remove-nils]] [auto-ap.datomic :refer [remove-nils]]
[auto-ap.datomic.accounts :as accounts] [auto-ap.datomic.accounts :as accounts]
[auto-ap.expense-accounts :as expense-accounts] [auto-ap.expense-accounts :as expense-accounts]
[auto-ap.ledger :as ledger] [auto-ap.ledger :as ledger]
[auto-ap.utils :refer [by]] [datomic.api :as d]))
[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))
)))
(def add-general-ledger (def add-general-ledger
[[{:db/ident :journal-entry/source [[{:db/ident :journal-entry/source
@@ -195,7 +180,8 @@
:account/location location :account/location location
:account/account-set "default"}))))]) :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/ident :replace-general-ledger
:db/doc "Deletes the general ledger entries for an entity" :db/doc "Deletes the general ledger entries for an entity"
:db/fn (d/function '{:lang "clojure" :db/fn (d/function '{:lang "clojure"
@@ -208,6 +194,7 @@
(into [] (into []
(map (fn [i] [:db/retractEntity i ]) ids)))})}]] ) (map (fn [i] [:db/retractEntity i ]) ids)))})}]] )
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(defn bulk-load-invoice-ledger [conn] (defn bulk-load-invoice-ledger [conn]
(let [invoice-ids (map first (d/query {:query {:find '[?e] (let [invoice-ids (map first (d/query {:query {:find '[?e]
:in '[$] :in '[$]
@@ -219,6 +206,7 @@
z)) z))
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(defn bulk-load-transaction-ledger [conn] (defn bulk-load-transaction-ledger [conn]
(let [transaction-ids (map first (d/query {:query {:find '[?e] (let [transaction-ids (map first (d/query {:query {:find '[?e]
:in '[$] :in '[$]
@@ -258,6 +246,7 @@
:db/cardinality :db.cardinality/one :db/cardinality :db.cardinality/one
:db/doc "The account will be used when a bill is created."}]]) :db/doc "The account will be used when a bill is created."}]])
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(defn convert-vendors [conn] (defn convert-vendors [conn]
(let [vendors (d/query {:query {:find '[?v ?expense-account-id] (let [vendors (d/query {:query {:find '[?v ?expense-account-id]
:in '[$] :in '[$]
@@ -269,6 +258,7 @@
:vendor/default-account (accounts/get-account-by-numeric-code-and-sets expense-account-id ["default"])})) :vendor/default-account (accounts/get-account-by-numeric-code-and-sets expense-account-id ["default"])}))
vendors)])) vendors)]))
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(defn convert-invoices [conn] (defn convert-invoices [conn]
(let [invoice-expense-accounts (d/query {:query {:find '[?iea ?expense-account-id] (let [invoice-expense-accounts (d/query {:query {:find '[?iea ?expense-account-id]
:in '[$] :in '[$]
@@ -280,7 +270,8 @@
:invoice-expense-account/account (accounts/get-account-by-numeric-code-and-sets expense-account-id ["default"])})) :invoice-expense-account/account (accounts/get-account-by-numeric-code-and-sets expense-account-id ["default"])}))
invoice-expense-accounts)])) invoice-expense-accounts)]))
(defn convert-transactions [conn] #_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(defn convert-transactions [_]
(println "here") (println "here")
(let [matched-transactions (d/query {:query {:find '[?transaction ?v ?amount] (let [matched-transactions (d/query {:query {:find '[?transaction ?v ?amount]
:in '[$] :in '[$]
@@ -442,34 +433,3 @@
{:db/id v {:db/id v
:vendor/hidden false}) :vendor/hidden false})
vendors))]) 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."))

View File

@@ -1,6 +1,7 @@
(ns auto-ap.datomic.migrate.check-numbers (ns auto-ap.datomic.migrate.check-numbers
(:require [datomic.api :as d])) (:require [datomic.api :as d]))
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(defn fix-check-numbers [conn] (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)]})] (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 [(for [[bank-account check-number max-check _] max-check-numbers

View File

@@ -23,6 +23,7 @@
:db/doc "The location of the location match"} :db/doc "The location of the location match"}
]]) ]])
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(defn add-starter [conn] (defn add-starter [conn]
(if (seq (d/query {:query {:find '[?e] (if (seq (d/query {:query {:find '[?e]
:in ['$] :in ['$]
@@ -34,12 +35,14 @@
:location-match/matches ["campbell brewing company"]}]}]] :location-match/matches ["campbell brewing company"]}]}]]
[[]])) [[]]))
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(defn add-default-location [_] (defn add-default-location [_]
[[{:db/ident :client/default-location [[{:db/ident :client/default-location
:db/valueType :db.type/string :db/valueType :db.type/string
:db/cardinality :db.cardinality/one :db/cardinality :db.cardinality/one
:db/doc "The default location if one can't be found"}]]) :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] (defn add-default-location-2 [conn]
(if (seq (d/query {:query {:find '[?e] (if (seq (d/query {:query {:find '[?e]
:in ['$] :in ['$]
@@ -58,6 +61,7 @@
{:db/ident :import-status/pending} {:db/ident :import-status/pending}
{:db/ident :import-status/imported}]]) {:db/ident :import-status/imported}]])
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(defn add-import-status-existing-invoices [conn] (defn add-import-status-existing-invoices [conn]
(let [existing-invoices (->> (d/query {:query {:find ['?e] (let [existing-invoices (->> (d/query {:query {:find ['?e]
:in ['$] :in ['$]

View File

@@ -26,6 +26,7 @@
) )
) )
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(defn rename-codes-1 [_] (defn rename-codes-1 [_]
(let [result (apply concat [(rename "WE" "WME" (d/connect uri)) (let [result (apply concat [(rename "WE" "WME" (d/connect uri))
(rename "HM" "HIM" (d/connect uri)) (rename "HM" "HIM" (d/connect uri))

View File

@@ -127,7 +127,3 @@
matching-count matching-count
(summarize-orders ids-to-retrieve)])) (summarize-orders ids-to-retrieve)]))
(defn get-by-id [id]
(->>
(d/pull (d/db (d/connect uri)) default-read id)
(<-datomic)))

View File

@@ -76,7 +76,3 @@
true (drop (:start args 0)) true (drop (:start args 0))
true (take (:count args 500))))) true (take (:count args 500)))))
(defn count-graphql [args]
(->> (raw-graphql args)
(count)))

View File

@@ -42,31 +42,6 @@
:vendor/default-account [:db/id :account/numeric-code :account/name] :vendor/default-account [:db/id :account/numeric-code :account/name]
:vendor-usage/_vendor [:vendor-usage/client :vendor-usage/count]}]) :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] (defn raw-graphql-ids [db args]
(let [query (cond-> {:query {:find [] (let [query (cond-> {:query {:find []

View File

@@ -59,8 +59,3 @@
[(->> (graphql-results ids-to-retrieve db args)) [(->> (graphql-results ids-to-retrieve db args))
matching-count])) matching-count]))
(defn get-by-id [id]
(-> (d/db (d/connect uri))
(d/pull default-read id)
(<-datomic)))

View File

@@ -92,6 +92,7 @@
[[:subscription [:parentId :parentEntity :eventEntity :eventKey]]]]]})) [[:subscription [:parentId :parentEntity :eventEntity :eventKey]]]]]}))
))) )))
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(defn upsert-ezcater (defn upsert-ezcater
([] (upsert-ezcater (get-integrations))) ([] (upsert-ezcater (get-integrations)))
([integrations] ([integrations]

View File

@@ -591,23 +591,6 @@
node)) node))
m)) m))
(defn <-graphql [m]
(walk/postwalk
(fn [node]
(cond
(keyword? node)
(kebab node)
:else
node))
m))
(defn get-user [context args _] (defn get-user [context args _]
(assert-admin (:id context)) (assert-admin (:id context))
@@ -638,12 +621,6 @@
(for [[account-id account-name total] result] (for [[account-id account-name total] result]
{:account {:id account-id :name account-name} :total total}))) {: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] } _] (defn get-invoice-stats [_ {:keys [client_id] } _]
(let [result (cond-> {:query {:find ['?name '(sum ?outstanding-balance) '(sum ?total)] (let [result (cond-> {:query {:find ['?name '(sum ?outstanding-balance) '(sum ?total)]
:in ['$] :in ['$]

View File

@@ -7,8 +7,7 @@
:refer [->graphql assert-admin can-see-client? is-admin?]] :refer [->graphql assert-admin can-see-client? is-admin?]]
[auto-ap.routes.queries :as q] [auto-ap.routes.queries :as q]
[auto-ap.square.core :as square] [auto-ap.square.core :as square]
[auto-ap.utils :refer [by heartbeat]] [auto-ap.utils :refer [heartbeat]]
[auto-ap.yodlee.core :refer [in-memory-cache]]
[clj-time.coerce :as coerce] [clj-time.coerce :as coerce]
[clojure.java.io :as io] [clojure.java.io :as io]
[clojure.string :as str] [clojure.string :as str]
@@ -253,6 +252,7 @@
(catch Exception e (catch Exception e
(log/error "Can't refresh current balance" e))))) (log/error "Can't refresh current balance" e)))))
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(defn refresh-all-current-balance [] (defn refresh-all-current-balance []
(lc/with-context {:source "current-balance-cache"} (lc/with-context {:source "current-balance-cache"}
(build-current-balance (->> (d/query {:query {:find ['?ba] (build-current-balance (->> (d/query {:query {:find ['?ba]
@@ -285,9 +285,7 @@
(update c :client/bank-accounts (update c :client/bank-accounts
(fn [bank-accounts] (fn [bank-accounts]
(mapv (fn [ba] (mapv (fn [ba]
;; TODO remove when new yodlee replaces (assoc ba :bank-account/yodlee-balance-old nil))
(assoc ba :bank-account/yodlee-balance-old (get-in (by :id (mapcat :accounts @in-memory-cache) )
[(:bank-account/yodlee-account-id ba) :balance :amount])))
bank-accounts)))))))) bank-accounts))))))))

View File

@@ -7,11 +7,6 @@
(def status->graphql (ident->enum-f :expected-deposit/status)) (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 _] (defn get-all-expected-deposits [context args _]
(assert-admin (:id context)) (assert-admin (:id context))
(map (map

View File

@@ -42,37 +42,6 @@
journal-entries)] journal-entries)]
(result->page journal-entries journal-entries-count :journal_entries (:filters args)))) (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 (defn roll-up-until
([lookup-account all-ledger-entries end-date] ([lookup-account all-ledger-entries end-date]
@@ -527,6 +496,7 @@
(build-running-balance-cache)) (build-running-balance-cache))
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(mount/defstate running-balance-cache-worker (mount/defstate running-balance-cache-worker
:start (scheduler/every (* 15 60 1000) (heartbeat refresh-running-balance-cache "running-balance-cache")) :start (scheduler/every (* 15 60 1000) (heartbeat refresh-running-balance-cache "running-balance-cache"))
:stop (scheduler/stop running-balance-cache-worker)) :stop (scheduler/stop running-balance-cache-worker))

View File

@@ -105,9 +105,6 @@
((ident->enum-f :transaction-rule/transaction-approval-status)) ((ident->enum-f :transaction-rule/transaction-approval-status))
(->graphql)))) (->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] (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 (d/query

View File

@@ -119,6 +119,7 @@
(>= (compare locked-until (coerce/to-date date)) 0)) (>= (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)) "."))))) (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] (defn assert-none-locked [client-id dates]
(doseq [d dates] (doseq [d dates]
(assert-not-locked client-id d))) (assert-not-locked client-id d)))

View File

@@ -15,7 +15,7 @@
[clojure.string :as str] [clojure.string :as str]
[clojure.tools.logging :as log] [clojure.tools.logging :as log]
#_{:clj-kondo/ignore [:refer-all]} #_{:clj-kondo/ignore [:refer-all]}
[compojure.core :refer :all] [compojure.core :refer [defroutes GET routes context ANY]]
[compojure.route :as route] [compojure.route :as route]
[config.core :refer [env]] [config.core :refer [env]]
[mount.core :as mount] [mount.core :as mount]
@@ -31,6 +31,7 @@
(def running? (atom false)) (def running? (atom false))
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(mount/defstate manage-running? (mount/defstate manage-running?
:start (reset! running? true) :start (reset! running? true)
:stop (reset! running? false)) :stop (reset! running? false))
@@ -85,6 +86,7 @@
(log/info "Beginning request" (:uri request))) (log/info "Beginning request" (:uri request)))
(handler request)))) (handler request))))
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(def app (def app
(-> #'app-routes (-> #'app-routes
(wrap-logging) (wrap-logging)

View File

@@ -5,7 +5,7 @@
[auto-ap.import.transactions :as t] [auto-ap.import.transactions :as t]
[auto-ap.intuit.core :as i] [auto-ap.intuit.core :as i]
[auto-ap.time :as atime] [auto-ap.time :as atime]
[auto-ap.utils :refer [allow-once heartbeat]] [auto-ap.utils :refer [heartbeat]]
[clj-time.coerce :as coerce] [clj-time.coerce :as coerce]
[clj-time.core :as time] [clj-time.core :as time]
[clojure.string :as str] [clojure.string :as str]
@@ -76,8 +76,6 @@
:priority :normal} :priority :normal}
nil))))) nil)))))
(def upsert-transactions (allow-once upsert-transactions))
(defn upsert-accounts [] (defn upsert-accounts []
(let [token (i/get-fresh-access-token) (let [token (i/get-fresh-access-token)
bank-accounts (i/get-bank-accounts token)] bank-accounts (i/get-bank-accounts token)]

View File

@@ -20,13 +20,6 @@
(catch Exception e (catch Exception e
(throw (Exception. (str "Could not parse expense account from value '" (:account-numeric-code i) "'") 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]}] (defn parse-date [{:keys [raw-date]}]
(when-not (when-not
(re-find #"\d{1,2}/\d{1,2}/\d{4}" raw-date) (re-find #"\d{1,2}/\d{1,2}/\d{4}" raw-date)

View File

@@ -222,6 +222,7 @@
:location "A" :location "A"
:amount (Math/abs (double amount))}]))) :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}] (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))] (when-let [autopay-invoices-matches (seq (match-transaction-to-unfulfilled-autopayments amount client))]
(add-new-payment transaction autopay-invoices-matches bank-account client))) (add-new-payment transaction autopay-invoices-matches bank-account client)))
@@ -356,18 +357,3 @@
(range) (range)
group))))) 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)))))

View File

@@ -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))

View File

@@ -3,15 +3,48 @@
[auto-ap.datomic :refer [conn]] [auto-ap.datomic :refer [conn]]
[auto-ap.import.common :refer [wrap-integration]] [auto-ap.import.common :refer [wrap-integration]]
[auto-ap.import.transactions :as t] [auto-ap.import.transactions :as t]
[auto-ap.import.yodlee :as y]
[auto-ap.utils :refer [allow-once heartbeat]] [auto-ap.utils :refer [allow-once heartbeat]]
[auto-ap.yodlee.core2 :as client2] [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] [com.unbounce.dogstatsd.core :as statsd]
[datomic.api :as d] [datomic.api :as d]
[mount.core :as mount] [mount.core :as mount]
[unilog.context :as lc] [unilog.context :as lc]
[yang.scheduler :as scheduler])) [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 [] (defn import-yodlee2-int []
(lc/with-context {:source "Import yodlee2 transactions"} (lc/with-context {:source "Import yodlee2 transactions"}
(statsd/event {:title "Yodlee2 import started" (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 (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) transaction (wrap-integration #(client2/get-specific-transactions client-code yodlee-account)
bank-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/bank-account bank-account
:transaction/client [:client/code client-code]))) :transaction/client [:client/code client-code])))

View File

@@ -49,20 +49,24 @@
:metadata {:content-type "application/text" :metadata {:content-type "application/text"
:content-length (count (.getBytes t))})) :content-length (count (.getBytes t))}))
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(defn copy-prod-refresh-token [] (defn copy-prod-refresh-token []
(set-refresh-token (slurp (:object-content (s3/get-object (set-refresh-token (slurp (:object-content (s3/get-object
:bucket-name "data.prod.app.integreatconsult.com" :bucket-name "data.prod.app.integreatconsult.com"
:key "intuit/refresh-token"))))) :key "intuit/refresh-token")))))
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(defn init-tokens [access refresh] (defn init-tokens [access refresh]
(set-access-token access) (set-access-token access)
(set-refresh-token refresh)) (set-refresh-token refresh))
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(defn lookup-access-token [] (defn lookup-access-token []
(slurp (:object-content (s3/get-object (slurp (:object-content (s3/get-object
:bucket-name (:data-bucket env) :bucket-name (:data-bucket env)
:key "intuit/access-token")))) :key "intuit/access-token"))))
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(defn lookup-refresh-token [] (defn lookup-refresh-token []
(slurp (:object-content (s3/get-object (slurp (:object-content (s3/get-object
:bucket-name (:data-bucket env) :bucket-name (:data-bucket env)

View File

@@ -25,19 +25,6 @@
#_#_(namespaces "expected-deposit" ) [[:expected-deposit e]] #_#_(namespaces "expected-deposit" ) [[:expected-deposit e]]
:else nil))) :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]] (defmulti entity-change->ledger (fn [_ [type]]
type)) type))

View File

@@ -136,6 +136,7 @@
(into [new-table] (into [new-table]
(split-table remaining n)))))) (split-table remaining n))))))
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(defn break-apart-tables [pnl-data tables] (defn break-apart-tables [pnl-data tables]
(for [table tables (for [table tables
table (split-table table (if (:include-deltas (:args pnl-data)) table (split-table table (if (:include-deltas (:args pnl-data))

View File

@@ -10,6 +10,7 @@
(def google-client-id "264081895820-0nndcfo3pbtqf30sro82vgq5r27h8736.apps.googleusercontent.com") (def google-client-id "264081895820-0nndcfo3pbtqf30sro82vgq5r27h8736.apps.googleusercontent.com")
(def google-client-secret "OC-WemHurPXYpuIw5cT-B90g") (def google-client-secret "OC-WemHurPXYpuIw5cT-B90g")
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(defn make-api-token [] (defn make-api-token []
(jwt/sign {:user "API" (jwt/sign {:user "API"
:exp (time/plus (time/now) (time/days 1000)) :exp (time/plus (time/now) (time/days 1000))

View File

@@ -1,6 +1,5 @@
(ns auto-ap.routes.utils (ns auto-ap.routes.utils
(:require [buddy.auth :refer [authenticated?]] (:require [buddy.auth :refer [authenticated?]]))
[clojure.spec.alpha :as s]))
(defn wrap-secure [handler] (defn wrap-secure [handler]
(fn [request] (fn [request]
@@ -8,11 +7,3 @@
(handler request) (handler request)
{:status 401 {:status 401
:body "not authenticated"}))) :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))))

View File

@@ -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))

View File

@@ -10,7 +10,6 @@
[auto-ap.handler :refer [app]] [auto-ap.handler :refer [app]]
[auto-ap.import.intuit :as intuit] [auto-ap.import.intuit :as intuit]
[auto-ap.import.plaid :as plaid] [auto-ap.import.plaid :as plaid]
[auto-ap.import.yodlee :as yodlee]
[auto-ap.import.yodlee2 :as yodlee2] [auto-ap.import.yodlee2 :as yodlee2]
[auto-ap.ledger :as ledger] [auto-ap.ledger :as ledger]
[auto-ap.square.core :as square] [auto-ap.square.core :as square]

View File

@@ -98,6 +98,7 @@
"sort_order" "DESC" "sort_order" "DESC"
}}}) }}})
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(defn get-order (defn get-order
([client location order-id] ([client location order-id]
(log/info "Searching for" (:square-location/client-location location)) (log/info "Searching for" (:square-location/client-location location))
@@ -482,6 +483,7 @@
(d/transact conn) (d/transact conn)
deref)))) deref))))
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(defn reset [] (defn reset []
(->> (->>
(d/query {:query {:find ['?e] (d/query {:query {:find ['?e]

View File

@@ -11,7 +11,6 @@
(def normal-date "MM/dd/yyyy") (def normal-date "MM/dd/yyyy")
(def iso-date "yyyy-MM-dd") (def iso-date "yyyy-MM-dd")
(def iso-date-time (:date-hour-minute-second-ms f/formatters))
(defn parse [v format] (defn parse [v format]
(try (try

View File

@@ -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))

View File

@@ -114,15 +114,6 @@
"ZZZZZZ" "ZZZZZZ"
(:location x))])))) (: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] (defn aggregate-accounts [pnl-data]
(reduce (fnil + 0.0) 0.0 (map :amount (:data pnl-data)))) (reduce (fnil + 0.0) 0.0 (map :amount (:data pnl-data))))

View File

@@ -5,6 +5,7 @@
[clojure.tools.logging :as log] [clojure.tools.logging :as log]
[unilog.context :as lc])])) [unilog.context :as lc])]))
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(defn by (defn by
([f xs] ([f xs]
(by f identity xs)) (by f identity xs))
@@ -14,15 +15,7 @@
{} {}
xs))) xs)))
(defn replace-if [f candidate existing] #_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(reduce
(fn [xs x]
(if (f x candidate)
(conj xs candidate)
(conj xs x)))
[]
existing))
(defn replace-by [xs f x] (defn replace-by [xs f x]
(let [found? (atom false) (let [found? (atom false)
replaced (mapv replaced (mapv
@@ -36,34 +29,15 @@
replaced replaced
(into [x] replaced)))) (into [x] replaced))))
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(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))))
(defn dollars-0? [amt] (defn dollars-0? [amt]
(< -0.001 amt 0.001)) (< -0.001 amt 0.001))
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(defn dollars= [amt1 amt2] (defn dollars= [amt1 amt2]
(dollars-0? (- amt1 amt2) )) (dollars-0? (- amt1 amt2) ))
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(defn deep-merge [v & vs] (defn deep-merge [v & vs]
(letfn [(rec-merge [v1 v2] (letfn [(rec-merge [v1 v2]
(if (and (map? v1) (map? v2)) (if (and (map? v1) (map? v2))
@@ -73,8 +47,10 @@
(reduce #(rec-merge %1 %2) v vs) (reduce #(rec-merge %1 %2) v vs)
(last vs)))) (last vs))))
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(def default-pagination-size 20) (def default-pagination-size 20)
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(defn allow-once [f] (defn allow-once [f]
(let [in-progress? (atom false)] (let [in-progress? (atom false)]
(fn [] (fn []
@@ -86,22 +62,22 @@
(reset! in-progress? false))))))) (reset! in-progress? false)))))))
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(defn heartbeat [f id] (defn heartbeat [f id]
(fn [] (fn []
#?(:clj (do #?(:clj (lc/with-context {:source id}
(lc/with-context {:source id} (try
(try (log/info "Starting background process " id)
(log/info "Starting background process " id) (f)
(f) (log/info "Completed background process " id)
(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) (statsd/service-check {:name (str id)
:status :ok} :status :critical}
nil) nil))))
(catch Exception e
(log/error e)
(statsd/service-check {:name (str id)
:status :critical}
nil)))))
:cljs (do (println "Heartbeat for " id) :cljs (do (println "Heartbeat for " id)
(f))))) (f)))))

View File

@@ -1,4 +1,5 @@
(ns auto-ap.config) (ns auto-ap.config)
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(def debug? (def debug?
^boolean goog.DEBUG) ^boolean goog.DEBUG)

View File

@@ -39,15 +39,6 @@
[k v]))) [k v])))
(into {} ))))))) (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 (re-frame/reg-fx
:set-local-storage :set-local-storage
@@ -121,47 +112,6 @@
(conj on-success) (conj on-success)
(re-frame/dispatch)))))))) (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] (defn kebab->snake [s]
(str/replace s #"-" "_")) (str/replace s #"-" "_"))

View File

@@ -76,17 +76,6 @@
(fn [db [_ which]] (fn [db [_ which]]
(update-in db [:menu which :active?] #(not %)))) (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 (re-frame/reg-event-fx
::received-initial ::received-initial

View File

@@ -2,7 +2,6 @@
(:require [re-frame.core :as re-frame] (:require [re-frame.core :as re-frame]
[re-frame.interceptor :as i] [re-frame.interceptor :as i]
[auto-ap.status :as status] [auto-ap.status :as status]
[auto-ap.views.utils :refer [dispatch-event]]
[malli.core :as m])) [malli.core :as m]))
@@ -20,13 +19,6 @@
:data :data
(get-in f)))) (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 (defn start-form
([db form data] ([db form data]
(start-form db form data nil)) (start-form db form data nil))
@@ -131,17 +123,13 @@
(assoc-in [::forms form :error] (or (:message (first result)) (assoc-in [::forms form :error] (or (:message (first result))
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 ;; TODO ^:deprecated
(defn loading [db id] (defn loading [db id]
(-> db (-> db
(assoc-in [::forms id :status] :loading) (assoc-in [::forms id :status] :loading)
(assoc-in [::forms id :error] nil))) (assoc-in [::forms id :error] nil)))
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(defn settles [{:keys [event time key]}] (defn settles [{:keys [event time key]}]
(i/->interceptor (i/->interceptor
:id :settles :id :settles

View File

@@ -1,5 +1,6 @@
(ns ^:figwheel-hooks auto-ap.reload) (ns ^:figwheel-hooks auto-ap.reload)
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(defn ^:after-load reload [] (defn ^:after-load reload []
(println "RELOADING") (println "RELOADING")
(@(resolve 'auto-ap.core/mount-root))) (@(resolve 'auto-ap.core/mount-root)))

View File

@@ -13,14 +13,6 @@
(def not-empty-string (m/schema [:re {:error/message "Required"} #"\S+"])) (def not-empty-string (m/schema [:re {:error/message "Required"} #"\S+"]))
(def code-string (m/schema [:re #"[A-Z0-9\-]+"])) (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 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])) (def approval-status (m/schema [:enum :unapproved :requires-feedback :approved :excluded]))

View File

@@ -8,7 +8,7 @@
[minisearch :as ms])) [minisearch :as ms]))
(set! *warn-on-infer* true) (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") (def MiniSearch (if ms (aget ms "default")
nil)) nil))
@@ -29,15 +29,6 @@
(fn [c] (fn [c]
(map #(select-keys % [:id :name]) 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 (re-frame/reg-sub
::bank-accounts ::bank-accounts
@@ -101,10 +92,6 @@
(fn [db [_ id]] (fn [db [_ id]]
(-> db :menu (get id) :active?))) (-> db :menu (get id) :active?)))
(re-frame/reg-sub
::menu
(fn [db]
(:menu db)))
(re-frame/reg-sub (re-frame/reg-sub
::is-initial-loading? ::is-initial-loading?
@@ -175,8 +162,3 @@
(if (= 500 (:status error)) (if (= 500 (:status error))
"System error occured. If you are stuck, please notify ben@integreatconsult.com." "System error occured. If you are stuck, please notify ben@integreatconsult.com."
(:message error))))) (:message error)))))
(re-frame/reg-sub
::yodlee-merchants
(fn [db]
(:yodlee-merchants db)))

View File

@@ -18,8 +18,7 @@
[auto-ap.views.utils [auto-ap.views.utils
:refer [dispatch-event str->int with-is-admin? with-user]] :refer [dispatch-event str->int with-is-admin? with-user]]
[malli.core :as m] [malli.core :as m]
[re-frame.core :as re-frame] [re-frame.core :as re-frame]))
[reagent.core :as r]))
;; Remaining cleanup todos: ;; Remaining cleanup todos:
;; test minification ;; test minification
@@ -131,11 +130,6 @@
{:dispatch-n [[::forms/attempted-submit ::vendor-form] {:dispatch-n [[::forms/attempted-submit ::vendor-form]
[::status/error ::vendor-form [{:message "Please fix the errors and try again."}]]]}))) [::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]}] (defn contact-field [{:keys [name field]}]
[form-builder/with-scope {:scope field} [form-builder/with-scope {:scope field}
[form-builder/vertical-control [form-builder/vertical-control

View File

@@ -22,11 +22,6 @@
(fn [db] (fn [db]
(::users db))) (::users db)))
(re-frame/reg-event-fx
::params-change
(fn [_ [_ params]]
{:set-uri-params params}))
(re-frame/reg-sub (re-frame/reg-sub
::page ::page
:<- [::params] :<- [::params]

View File

@@ -1,6 +1,5 @@
(ns auto-ap.views.pages.admin.vendors.table (ns auto-ap.views.pages.admin.vendors.table
(:require (:require
[auto-ap.subs :as subs]
[auto-ap.views.components.buttons :as buttons] [auto-ap.views.components.buttons :as buttons]
[auto-ap.views.components.grid :as grid] [auto-ap.views.components.grid :as grid]
[auto-ap.views.components.vendor-dialog :as vendor-dialog] [auto-ap.views.components.vendor-dialog :as vendor-dialog]
@@ -9,10 +8,7 @@
[re-frame.core :as re-frame])) [re-frame.core :as re-frame]))
(defn vendors-table [{:keys [data-page]}] (defn vendors-table [{:keys [data-page]}]
(let [{:keys [data]} @(re-frame/subscribe [::data-page/page 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))
[grid/grid {:data-page data-page [grid/grid {:data-page data-page
:column-count 4} :column-count 4}
[grid/controls data] [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-info.is-light total-usage " usages, " (count (:usage v)) " clients" ]
[:div.mx-2.tag.is-warning.is-light "Unused"]))] [:div.mx-2.tag.is-warning.is-light "Unused"]))]
[grid/cell {} (:email (:primary-contact v))] [grid/cell {} (:email (:primary-contact v))]
[grid/cell {} (-> v :default-account :id accounts :name)] [grid/cell {} (-> v :default-account :name)]
[grid/cell {} [grid/cell {}
[buttons/fa-icon {:event [::vendor-dialog/started v] [buttons/fa-icon {:event [::vendor-dialog/started v]
:icon "fa-pencil"}]]])]]])) :icon "fa-pencil"}]]])]]]))

View File

@@ -30,12 +30,6 @@
(fn [table-params] (fn [table-params]
table-params)) table-params))
(re-frame/reg-sub
::plaid-items
(fn [db]
(::plaid-items db)))
(re-frame/reg-event-fx (re-frame/reg-event-fx
::data-requested ::data-requested
(fn [{:keys [db]} [_ params]] (fn [{:keys [db]} [_ params]]
@@ -119,11 +113,6 @@
(-> db (-> db
(assoc-in [::link-token] (:token (:plaid-link-token link-token)))))) (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 [] (defn plaid-item-table []
[table/table {:data-page ::page [table/table {:data-page ::page

View File

@@ -127,9 +127,6 @@
:filters filters :filters filters
:table-params table-params})) :table-params table-params}))
(defn in-page-entities [which]
(re-frame/path [::data which :data ] ))
(re-frame/reg-event-fx (re-frame/reg-event-fx
::table-params-changed ::table-params-changed
(fn [{:keys [db]} [_ which params]] (fn [{:keys [db]} [_ which params]]

View File

@@ -151,16 +151,6 @@
[]]]} []]]}
:on-success [::invalidated]}})) :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] (defn approve-reject-button [checked]
[:div.buttons [:div.buttons
[:button.button.is-primary {:on-click (dispatch-event [::approve-invoices-clicked checked]) [:button.button.is-primary {:on-click (dispatch-event [::approve-invoices-clicked checked])

View File

@@ -18,16 +18,8 @@
[auto-ap.events :as events] [auto-ap.events :as events]
[vimsical.re-frame.cofx.inject :as inject] [vimsical.re-frame.cofx.inject :as inject]
[auto-ap.forms.builder :as form-builder] [auto-ap.forms.builder :as form-builder]
[malli.core :as m]
[auto-ap.schema :as schema]
[auto-ap.views.components :as com])) [auto-ap.views.components :as com]))
(re-frame/reg-sub
::can-submit
:<- [::forms/form ::form]
(fn [{ {:keys []} :data}]
true))
(re-frame/reg-event-fx (re-frame/reg-event-fx
::coded ::coded
(fn [_ [_ _ _]] (fn [_ [_ _ _]]
@@ -107,15 +99,10 @@
{::track/dispose {:id ::vendor-change}})) {::track/dispose {:id ::vendor-change}}))
(def bulk-update-schema
(m/schema
[:map
[:vendor schema/reference]]))
(defn form-content [_] (defn form-content [_]
(let [{:keys [data]} @(re-frame/subscribe [::forms/form ::form])] (let [{:keys [data]} @(re-frame/subscribe [::forms/form ::form])]
[form-builder/builder {:submit-event [::code-selected] [form-builder/builder {:submit-event [::code-selected]
:change-event [::changed] :change-event [::changed]
:can-submit [::can-submit]
:id ::form} :id ::form}

View File

@@ -10,12 +10,6 @@
[malli.core :as m] [malli.core :as m]
[re-frame.core :as re-frame])) [re-frame.core :as re-frame]))
(re-frame/reg-sub
::can-submit
:<- [::forms/form ::form]
(fn [{ {:keys [data]} :data}]
(not-empty data)))
(def schema (def schema
(m/schema [:map [:data schema/not-empty-string]])) (m/schema [:map [:data schema/not-empty-string]]))

View File

@@ -18,7 +18,6 @@
(def date-regex #"[2]{1}[0-9]{3}-[0-9]{1,2}-[0-9]{1,2}") (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 (def nff
(NumberFormat. Format/CURRENCY)) (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] (defn active-when [active-page f & rest]
(when (apply f (into [active-page] rest)) " is-active")) (when (apply f (into [active-page] rest)) " is-active"))
@@ -72,12 +68,6 @@
(re-frame/dispatch (conj event (.. e -target -value))))) (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] (defn dispatch-event [event]
(fn [e] (fn [e]
(when (.-stopPropagation e) (when (.-stopPropagation e)
@@ -286,9 +276,6 @@
(js/document.execCommand "copy") (js/document.execCommand "copy")
(.removeChild js/document.body el))) (.removeChild js/document.body el)))
(defn account->match-text [x]
(str (:numeric-code x) " - " (:name x)))
(defn str->int [x] (defn str->int [x]
(cond (cond
(nil? x) (nil? x)

View File

@@ -24,7 +24,8 @@
(def base-transaction #:transaction {:date #inst "2020-01-02T00:00:00-08:00" (def base-transaction #:transaction {:date #inst "2020-01-02T00:00:00-08:00"
:raw-id "1" :raw-id "1"
:id (di/sha-256 "1") :id #_{:clj-kondo/ignore [:unresolved-var]}
(di/sha-256 "1")
:amount 12.0 :amount 12.0
:description-original "original-description" :description-original "original-description"
:status "POSTED" :status "POSTED"

View File

@@ -1,5 +1,5 @@
(ns auto-ap.import.yodlee-test (ns auto-ap.import.yodlee-test
(:require [auto-ap.import.yodlee :as sut] (:require [auto-ap.import.yodlee2 :as sut]
[clojure.test :as t])) [clojure.test :as t]))

View File

@@ -17,12 +17,14 @@
(d/release conn) (d/release conn)
(d/delete-database uri)))) (d/delete-database uri))))
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(defn admin-token [] (defn admin-token []
{:user "TEST ADMIN" {:user "TEST ADMIN"
:exp (time/plus (time/now) (time/days 1)) :exp (time/plus (time/now) (time/days 1))
:user/role "admin" :user/role "admin"
:user/name "TEST ADMIN"}) :user/name "TEST ADMIN"})
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(defn user-token [client-id] (defn user-token [client-id]
{:user "TEST USER" {:user "TEST USER"
:exp (time/plus (time/now) (time/days 1)) :exp (time/plus (time/now) (time/days 1))

View File

@@ -23,6 +23,7 @@
:user/role "admin" :user/role "admin"
:user/name "TEST ADMIN"}) :user/name "TEST ADMIN"})
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(defn user-token [client-id] (defn user-token [client-id]
{:user "TEST USER" {:user "TEST USER"
:exp (time/plus (time/now) (time/days 1)) :exp (time/plus (time/now) (time/days 1))
@@ -31,14 +32,6 @@
:user/clients [{:db/id client-id}]}) :user/clients [{:db/id client-id}]})
(defn new-invoice [args]
(merge {:invoice/total 100.0
:invoice/invoice-number (.toString (java.util.UUID/randomUUID))}
args))
(use-fixtures :each wrap-setup) (use-fixtures :each wrap-setup)

View File

@@ -18,10 +18,6 @@
(t/use-fixtures :each wrap-setup) (t/use-fixtures :each wrap-setup)
#_{:clj-kondo/ignore [:unused-binding]}
(defn noop-rule [transaction locations]
transaction)
(def base-transaction #:transaction {:amount -12.0 (def base-transaction #:transaction {:amount -12.0
:date #inst "2014-01-02T08:00:00.000-00:00" :date #inst "2014-01-02T08:00:00.000-00:00"
:bank-account 456 :bank-account 456