fixed warnings.
This commit is contained in:
@@ -13,7 +13,6 @@
|
||||
[clojure.tools.logging :as log]
|
||||
[config.core :refer [env]]
|
||||
[mount.core :as mount]
|
||||
[unilog.context :as lc]
|
||||
[yang.scheduler :as scheduler])
|
||||
(:import
|
||||
(java.util Properties UUID)
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
[amazonica.aws.sqs :as sqs]
|
||||
[auto-ap.import.intuit :as i]
|
||||
[auto-ap.import.plaid :as p]
|
||||
[auto-ap.import.yodlee :as y]
|
||||
[auto-ap.import.yodlee2 :as y2]
|
||||
[auto-ap.utils :refer [heartbeat]]
|
||||
[clojure.tools.logging :as log]
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
(ns auto-ap.datomic
|
||||
(:require [auto-ap.utils :refer [default-pagination-size]]
|
||||
[clj-time.coerce :as coerce]
|
||||
[datomic.api :as d]
|
||||
[clojure.tools.logging :as log]
|
||||
[mount.core :as mount]
|
||||
[config.core :refer [env]]))
|
||||
(:require
|
||||
[auto-ap.utils :refer [default-pagination-size]]
|
||||
[clojure.tools.logging :as log]
|
||||
[config.core :refer [env]]
|
||||
[datomic.api :as d]
|
||||
[mount.core :as mount]))
|
||||
|
||||
(def uri (:datomic-url env))
|
||||
|
||||
@@ -20,13 +20,6 @@
|
||||
(defn drop-database []
|
||||
(d/delete-database uri))
|
||||
|
||||
(defn merge-query [query-part-1 query-part-2]
|
||||
(-> query-part-1
|
||||
(update-in [:query :find] into (get-in query-part-2 [:query :find]))
|
||||
(update-in [:query :in] into (get-in query-part-2 [:query :in]))
|
||||
(update-in [:query :where] into (get-in query-part-2 [:query :where]))
|
||||
(update-in [:args] into (get-in query-part-2 [:args]))))
|
||||
|
||||
(defn remove-nils [m]
|
||||
(let [result (reduce-kv
|
||||
(fn [m k v]
|
||||
@@ -548,168 +541,7 @@
|
||||
:where [?e :vendor/name]]
|
||||
(d/db (d/connect uri))))
|
||||
|
||||
(defn load-vendors [vendors]
|
||||
(->> vendors
|
||||
(map
|
||||
(fn [{:keys [primary-phone address email primary-contact secondary-email secondary-contact primary-email name default-expense-account id code secondary-phone invoice-reminder-schedule print-as]}]
|
||||
(let [vendor-id (d/tempid :db.part/user)
|
||||
address-id (d/tempid :db.part/user)]
|
||||
(remove-nils #:vendor {:original-id id
|
||||
:name name
|
||||
:code (if (seq code) code nil)
|
||||
:email email
|
||||
:default-expense-account default-expense-account
|
||||
:invoice-reminder-schedule nil
|
||||
:address (remove-nils #:address {:street1 (:street1 address)
|
||||
:street2 (:street2 address)
|
||||
:city (:city address)
|
||||
:state (:state address)
|
||||
:zip (:zip address)})
|
||||
:primary-contact (remove-nils #:contact {:name primary-contact
|
||||
:phone primary-phone
|
||||
:email primary-email})
|
||||
:secondary-contact (remove-nils #:contact {:name secondary-contact
|
||||
:phone secondary-phone
|
||||
:email secondary-email})}))))
|
||||
)
|
||||
)
|
||||
|
||||
(defn load-clients [clients]
|
||||
(->> clients
|
||||
(map
|
||||
(fn [{:keys [name address id code locations email bank-accounts signature-file] client-id :id}]
|
||||
(remove-nils #:client {:original-id id
|
||||
:name (str name)
|
||||
:code nil
|
||||
:email email
|
||||
:signature-file signature-file
|
||||
:locations locations
|
||||
:address (remove-nils #:address {:street1 (:street1 address)
|
||||
:street2 (:street2 address)
|
||||
:city (:city address)
|
||||
:state (:state address)
|
||||
:zip (:zip address)})
|
||||
:bank-accounts (conj (map
|
||||
(fn [{:keys [number id check-number bank-name bank-code routing name yodlee-account-id type] }]
|
||||
(remove-nils #:bank-account {:number number
|
||||
:original-id (str client-id "-" id)
|
||||
:external-id id
|
||||
:check-number check-number
|
||||
:bank-name bank-name
|
||||
:bank-code bank-code
|
||||
:routing routing
|
||||
:name name
|
||||
:yodlee-account-id yodlee-account-id
|
||||
:type (if type
|
||||
(keyword "bank-account-type" type )
|
||||
:bank-account-type/check)}))
|
||||
bank-accounts)
|
||||
#:bank-account {:original-id (str client-id "-" 0)
|
||||
:external-id 0
|
||||
:type :bank-account-type/cash})} )))))
|
||||
|
||||
|
||||
(defn load-invoices [invoices]
|
||||
(->> invoices
|
||||
(map
|
||||
(fn [{:keys [id status total outstanding-balance invoice-number date customer-identifier company-id vendor-id default-location default-expense-account] invoice-id :id}]
|
||||
[(remove-nils #:invoice {:original-id id
|
||||
:invoice-number invoice-number
|
||||
:date (coerce/to-date date)
|
||||
:customer-identifier customer-identifier
|
||||
:client [:client/original-id company-id]
|
||||
:vendor (when vendor-id [:vendor/original-id vendor-id])
|
||||
|
||||
:default-location default-location
|
||||
:default-expense-account default-expense-account
|
||||
:total (double total)
|
||||
:outstanding-balance (double outstanding-balance)
|
||||
:status (keyword "invoice-status" status)})]))))
|
||||
|
||||
(defn load-invoices-expense-accounts [invoices-expense-accounts]
|
||||
(->> invoices-expense-accounts
|
||||
(map
|
||||
(fn [{:keys [id expense-account-id location amount invoice-id]}]
|
||||
[(remove-nils #:invoice {:original-id invoice-id
|
||||
:expense-accounts [(remove-nils #:invoice-expense-account {:original-id id
|
||||
:expense-account-id expense-account-id
|
||||
:location location
|
||||
:amount (double amount)})]})]))))
|
||||
|
||||
|
||||
(defn load-payments [checks]
|
||||
(->> checks
|
||||
(map
|
||||
(fn [{:keys [id s3-uuid s3-key s3-url vendor-id company-id check-number memo date amount paid-to data bank-account-id status type] invoice-id :id}]
|
||||
[(remove-nils #:payment {:original-id id
|
||||
:s3-uuid s3-uuid
|
||||
:s3-key s3-key
|
||||
:s3-url s3-url
|
||||
:vendor (when vendor-id [:vendor/original-id vendor-id])
|
||||
:client [:client/original-id company-id]
|
||||
:bank-account (when (and bank-account-id
|
||||
(not= "38-3" (str company-id "-" bank-account-id))) ;; TODO - 38-3 got removed at some ponitn
|
||||
[:bank-account/original-id (str company-id "-" bank-account-id)])
|
||||
:check-number check-number
|
||||
:memo memo
|
||||
:date (coerce/to-date date)
|
||||
:amount (double amount)
|
||||
:paid-to paid-to
|
||||
:pdf-data data
|
||||
:status (keyword "payment-status" status)
|
||||
:type (if type
|
||||
(keyword "payment-type" type)
|
||||
:payment-type/check)})]))))
|
||||
|
||||
(defn load-invoices-payments [invoices-checks]
|
||||
(->> invoices-checks
|
||||
(map
|
||||
(fn [{:keys [id invoice-id check-id amount]}]
|
||||
[(remove-nils #:invoice-payment {:original-id id
|
||||
:payment [:payment/original-id check-id]
|
||||
:invoice [:invoice/original-id invoice-id]
|
||||
:amount (double amount)})]))))
|
||||
|
||||
(defn load-transactions [transactions]
|
||||
(let [transactions (->> transactions
|
||||
(map
|
||||
(fn [{:keys [id amount description-original description-simple merchant-id merchant-name
|
||||
date post-date type account-id status vendor-id company-id check-id check-number
|
||||
bank-account-id]}]
|
||||
(remove-nils #:transaction {:original-id id
|
||||
:id id
|
||||
:description-original description-original
|
||||
:description-simple description-simple
|
||||
:merchant-id merchant-id
|
||||
:merchant-name merchant-name
|
||||
:date (coerce/to-date date)
|
||||
:post-date (coerce/to-date post-date)
|
||||
:type type
|
||||
:status status
|
||||
:amount (double amount)
|
||||
:account-id account-id
|
||||
:check-number check-number
|
||||
:vendor (when vendor-id [:vendor/original-id vendor-id])
|
||||
:client (when company-id [:client/original-id company-id])
|
||||
:payment (when check-id [:payment/original-id check-id])
|
||||
:bank-account (when (and bank-account-id
|
||||
(not= "38-3" (str company-id "-" bank-account-id)))
|
||||
[:bank-account/original-id (str company-id "-" bank-account-id)])})))
|
||||
(partition-all 10))]
|
||||
(println "transactions: " (count transactions) "batches of 50")
|
||||
transactions))
|
||||
|
||||
(defn load-users [users]
|
||||
(->> users
|
||||
(map
|
||||
(fn [{:keys [id role provider-id provider companies name]}]
|
||||
(remove-nils #:user {:original-id id
|
||||
:name name
|
||||
:role (keyword "user-role" role)
|
||||
:provider-id provider-id
|
||||
:provider provider
|
||||
:clients (map (fn [c] [:client/original-id c]) companies)})))
|
||||
))
|
||||
|
||||
(defn query-vendors []
|
||||
(d/q '[:find (pull ?e [*])
|
||||
@@ -746,28 +578,28 @@
|
||||
:where [?e :user/original-id]]
|
||||
(d/db (d/connect uri))))
|
||||
|
||||
(defn migrate-vendors [conn]
|
||||
(defn migrate-vendors [_]
|
||||
[[]])
|
||||
|
||||
(defn migrate-clients [conn]
|
||||
(defn migrate-clients [_]
|
||||
[[]])
|
||||
|
||||
(defn migrate-invoices [conn]
|
||||
(defn migrate-invoices [_]
|
||||
[[]])
|
||||
|
||||
(defn migrate-payments [conn]
|
||||
(defn migrate-payments [_]
|
||||
[[]])
|
||||
|
||||
(defn migrate-invoices-payments [conn]
|
||||
(defn migrate-invoices-payments [_]
|
||||
[[]])
|
||||
|
||||
(defn migrate-invoices-expense-accounts [conn]
|
||||
(defn migrate-invoices-expense-accounts [_]
|
||||
[[]])
|
||||
|
||||
(defn migrate-transactions [conn]
|
||||
(defn migrate-transactions [_]
|
||||
[[]])
|
||||
|
||||
(defn migrate-users [conn]
|
||||
(defn migrate-users [_]
|
||||
[[]])
|
||||
|
||||
(defn merge-query [query-part-1 query-part-2]
|
||||
@@ -780,7 +612,7 @@
|
||||
(defn add-sorter-fields [q sort-map args]
|
||||
(log/info "sort-map" (pr-str sort-map))
|
||||
(reduce
|
||||
(fn [q {:keys [sort-key asc]}]
|
||||
(fn [q {:keys [sort-key]}]
|
||||
(merge-query q
|
||||
{:query {:find [(symbol (str "?sort-" sort-key))]
|
||||
:where (sort-map
|
||||
|
||||
@@ -79,7 +79,7 @@
|
||||
(d/db conn )
|
||||
vendor-id)))
|
||||
|
||||
(defn get-account-by-numeric-code-and-sets [numeric-code sets]
|
||||
(defn get-account-by-numeric-code-and-sets [numeric-code _]
|
||||
(let [query (cond-> {:query {:find ['(pull ?e [* {:account/type [:db/ident :db/id]}])]
|
||||
:in ['$ '?numeric-code]
|
||||
:where ['[?e :account/numeric-code ?numeric-code]]}
|
||||
@@ -122,7 +122,7 @@
|
||||
true (apply-pagination args))))
|
||||
|
||||
|
||||
(defn graphql-results [ids db args]
|
||||
(defn graphql-results [ids db _]
|
||||
(let [results (->> (d/pull-many db default-read ids)
|
||||
(group-by :db/id))
|
||||
accounts (->> ids
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
(ns auto-ap.datomic.bank-accounts
|
||||
(:require [datomic.api :as d]
|
||||
[auto-ap.datomic :refer [uri]]
|
||||
[clj-time.coerce :as c]
|
||||
[clojure.set :refer [rename-keys]]))
|
||||
(:require
|
||||
[auto-ap.datomic :refer [uri]]
|
||||
[datomic.api :as d]))
|
||||
|
||||
(defn add-arg [query name value where & rest]
|
||||
(let [query (-> query
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
(ns auto-ap.datomic.clients
|
||||
(:require [auto-ap.datomic :refer [conn uri]]
|
||||
[clj-time.coerce :as coerce]
|
||||
[clojure.tools.logging :as log]
|
||||
[datomic.api :as d]))
|
||||
(:require
|
||||
[auto-ap.datomic :refer [conn uri]]
|
||||
[clj-time.coerce :as coerce]
|
||||
[datomic.api :as d]))
|
||||
|
||||
(defn cleanse [e]
|
||||
(-> e
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
(ns auto-ap.datomic.expected-deposit
|
||||
(:require [auto-ap.datomic :refer [add-sorter-fields apply-pagination apply-sort-3 merge-query conn]]
|
||||
[auto-ap.graphql.utils :refer [limited-clients]]
|
||||
[clj-time.coerce :as c]
|
||||
[datomic.api :as d]
|
||||
[clj-time.core :as t]))
|
||||
|
||||
(:require
|
||||
[auto-ap.datomic
|
||||
:refer [add-sorter-fields apply-pagination apply-sort-3 conn merge-query]]
|
||||
[auto-ap.graphql.utils :refer [limited-clients]]
|
||||
[clj-time.coerce :as c]
|
||||
[datomic.api :as d]))
|
||||
|
||||
(defn <-datomic [result]
|
||||
(let [transaction (first (:transaction/_expected-deposit result))
|
||||
|
||||
@@ -1,14 +1,15 @@
|
||||
(ns auto-ap.datomic.invoices
|
||||
(:require [datomic.api :as d]
|
||||
[auto-ap.datomic :refer [uri merge-query apply-pagination apply-sort-3 add-sorter-fields conn]]
|
||||
[auto-ap.graphql.utils :refer [limited-clients]]
|
||||
[clojure.set :refer [rename-keys]]
|
||||
[clj-time.coerce :as coerce]
|
||||
[auto-ap.time-utils :refer [next-dom]]
|
||||
[clj-time.core :as time]
|
||||
[auto-ap.datomic.vendors :as d-vendors]
|
||||
[clojure.tools.logging :as log]
|
||||
[auto-ap.datomic.accounts :as d-accounts]))
|
||||
(:require
|
||||
[auto-ap.datomic
|
||||
:refer [add-sorter-fields apply-pagination apply-sort-3 conn merge-query uri]]
|
||||
[auto-ap.datomic.accounts :as d-accounts]
|
||||
[auto-ap.datomic.vendors :as d-vendors]
|
||||
[auto-ap.graphql.utils :refer [limited-clients]]
|
||||
[auto-ap.time-utils :refer [next-dom]]
|
||||
[clj-time.coerce :as coerce]
|
||||
[clj-time.core :as time]
|
||||
[clojure.set :refer [rename-keys]]
|
||||
[datomic.api :as d]))
|
||||
|
||||
(def default-read '[*
|
||||
{:invoice/client [:client/name :db/id :client/locations :client/code]}
|
||||
@@ -41,7 +42,7 @@
|
||||
(->> (cond-> {:query {:find []
|
||||
:in ['$]
|
||||
:where ['[?e :invoice/client]]}
|
||||
:args [(d/db (d/connect uri))]}
|
||||
:args [db]}
|
||||
|
||||
(:exact-match-id args)
|
||||
(merge-query {:query {:in ['?e]
|
||||
@@ -162,7 +163,7 @@
|
||||
(apply-pagination args))))
|
||||
|
||||
|
||||
(defn graphql-results [ids db args]
|
||||
(defn graphql-results [ids db _]
|
||||
(let [results (->> (d/pull-many db default-read ids)
|
||||
(group-by :db/id))
|
||||
|
||||
@@ -218,10 +219,6 @@
|
||||
(d/pull default-read id)
|
||||
(<-datomic)))
|
||||
|
||||
(defn update [update]
|
||||
@(d/transact (d/connect uri) [update])
|
||||
(get-by-id (:db/id update) ))
|
||||
|
||||
(defn get-multi [ids]
|
||||
(map <-datomic
|
||||
(-> (d/db (d/connect uri))
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
[filename]
|
||||
(-> (io/resource filename) (io/reader) (Util/readAll)))
|
||||
|
||||
(defn functions [conn]
|
||||
(defn functions [_]
|
||||
[[{:db/ident :pay
|
||||
:db/doc "Data function that increments value of attribute a by amount."
|
||||
:db/fn (d/function '{:lang "clojure"
|
||||
@@ -47,7 +47,7 @@
|
||||
:code [[:db/add e a
|
||||
(-> (d/entity db e) a (+ amount))]] })}]] )
|
||||
|
||||
(defn fix-pay-function [conn]
|
||||
(defn fix-pay-function [_]
|
||||
[[{:db/ident :pay
|
||||
:db/doc "Data function that increments value of attribute a by amount."
|
||||
:db/fn (d/function '{:lang "clojure"
|
||||
@@ -65,7 +65,7 @@
|
||||
:db/valueType :db.type/string
|
||||
:db/cardinality :db.cardinality/one}]])
|
||||
|
||||
(defn reset-function [conn]
|
||||
(defn reset-function [_]
|
||||
[[{:db/ident :reset
|
||||
:db/doc "Resets a relationship to the values specified "
|
||||
:db/fn (d/function '{:lang "clojure"
|
||||
@@ -84,7 +84,7 @@
|
||||
a vs})))})}]])
|
||||
|
||||
|
||||
(defn propose-invoice-fn [conn]
|
||||
(defn propose-invoice-fn [_]
|
||||
[[{:db/ident :propose-invoice
|
||||
:db/doc "Adds an invoice if it's not found"
|
||||
:db/fn (d/function '{:lang "clojure"
|
||||
@@ -204,10 +204,8 @@
|
||||
:requires [:auto-ap/add-import-status]}
|
||||
:auto-ap/fix-check-numbers {:txes-fn 'auto-ap.datomic.migrate.check-numbers/fix-check-numbers
|
||||
:requires [:auto-ap/add-import-status-existing-invoices]}
|
||||
:auto-ap/add-new-vendors {:txes-fn 'auto-ap.datomic.migrate.add-new-vendors/add-new-vendors
|
||||
:requires [:auto-ap/fix-check-numbers]}
|
||||
:auto-ap/add-account-visibility-fields {:txes-fn 'auto-ap.datomic.migrate.account-sorting/add-account-visibility-fields
|
||||
:requires [:auto-ap/add-new-vendors]}
|
||||
:requires [:auto-ap/fix-check-numbers]}
|
||||
:auto-ap/make-every-account-visible {:txes-fn 'auto-ap.datomic.migrate.account-sorting/make-every-account-visible
|
||||
:requires [:auto-ap/add-account-visibility-fields]}
|
||||
:auto-ap/add-general-ledger6 {:txes add-general-ledger/add-general-ledger
|
||||
@@ -542,7 +540,7 @@
|
||||
(d/release conn))
|
||||
(println "Done")))
|
||||
|
||||
(defn -main [& args]
|
||||
(defn -main [& _]
|
||||
(mount/start (mount/only #{#'conn}))
|
||||
(migrate conn)
|
||||
(mount/stop))
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
(:require [datomic.api :as d]))
|
||||
|
||||
|
||||
(defn add-account-visibility-fields [conn]
|
||||
(defn add-account-visibility-fields [_]
|
||||
[[
|
||||
{:db/ident :bank-account/visible
|
||||
:db/valueType :db.type/boolean
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
(ns auto-ap.datomic.migrate.add-bank-account-codes
|
||||
(:require [datomic.api :as d]
|
||||
[auto-ap.datomic :refer [uri]]
|
||||
[clojure.string :as str]))
|
||||
(:require
|
||||
[clojure.string :as str]
|
||||
[datomic.api :as d]))
|
||||
|
||||
(defn add-bank-account-codes-schema [conn]
|
||||
(defn add-bank-account-codes-schema [_]
|
||||
[[{:db/ident :bank-account/code
|
||||
:db/valueType :db.type/string
|
||||
:db/unique :db.unique/identity
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
(ns auto-ap.datomic.migrate.add-client-codes
|
||||
(:require [auto-ap.datomic :refer [uri]]
|
||||
[datomic.api :as d]))
|
||||
(:require
|
||||
[datomic.api :as d]))
|
||||
|
||||
(def name->code
|
||||
(->>
|
||||
[["Moscini Pizza Inc" "MPI"]
|
||||
|
||||
@@ -1,28 +1,3 @@
|
||||
(ns auto-ap.datomic.migrate.add-new-vendors
|
||||
(:require [datomic.api :as d]
|
||||
[auto-ap.datomic :refer [uri]]
|
||||
[clojure.data.csv :as csv]
|
||||
[clojure.java.io :as io]
|
||||
[clojure.string :as str])
|
||||
(:import [org.apache.commons.io.input BOMInputStream]))
|
||||
(ns auto-ap.datomic.migrate.add-new-vendors)
|
||||
|
||||
|
||||
(defn add-new-vendors [conn]
|
||||
[[]]
|
||||
#_(let [[header & rows] (-> "vendor-list.csv" (io/resource) io/input-stream (BOMInputStream.) (io/reader) csv/read-csv)
|
||||
headers (map read-string header)
|
||||
new-vendors [(reduce
|
||||
(fn [rows r]
|
||||
(conj rows (reduce
|
||||
(fn [r [header value]]
|
||||
(condp = header
|
||||
[:vendor/address] r
|
||||
[:vendor/default-expense-account] (assoc-in r header (Integer/parseInt (str/replace value #"A" "")))
|
||||
[:vendor/invoice-reminder-schedule] r
|
||||
(assoc-in r header value)))
|
||||
{}
|
||||
(map vector headers r))))
|
||||
[]
|
||||
rows)]]
|
||||
(println (ffirst new-vendors))
|
||||
new-vendors
|
||||
))
|
||||
|
||||
@@ -3,6 +3,6 @@
|
||||
|
||||
(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 client] max-check-numbers
|
||||
[(for [[bank-account check-number max-check _] max-check-numbers
|
||||
:when (>= max-check check-number)]
|
||||
{:db/id bank-account :payment/check-number (inc max-check)})]))
|
||||
|
||||
@@ -34,7 +34,7 @@
|
||||
:location-match/matches ["campbell brewing company"]}]}]]
|
||||
[[]]))
|
||||
|
||||
(defn add-default-location [conn]
|
||||
(defn add-default-location [_]
|
||||
[[{:db/ident :client/default-location
|
||||
:db/valueType :db.type/string
|
||||
:db/cardinality :db.cardinality/one
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
)
|
||||
)
|
||||
|
||||
(defn rename-codes-1 [conn]
|
||||
(defn rename-codes-1 [_]
|
||||
(let [result (apply concat [(rename "WE" "WME" (d/connect uri))
|
||||
(rename "HM" "HIM" (d/connect uri))
|
||||
(rename "BES" "SBE" (d/connect uri))
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
(ns auto-ap.datomic.sales-orders
|
||||
(:require [auto-ap.datomic :refer [add-sorter-fields apply-pagination apply-sort-3 merge-query uri]]
|
||||
[auto-ap.graphql.utils :refer [limited-clients]]
|
||||
[auto-ap.utils :refer [dollars=]]
|
||||
[clj-time.coerce :as c]
|
||||
[datomic.api :as d]
|
||||
[clojure.tools.logging :as log]
|
||||
@@ -98,7 +97,7 @@
|
||||
true (apply-sort-3 (assoc args :default-asc? false))
|
||||
true (apply-pagination args))))
|
||||
|
||||
(defn graphql-results [ids db args]
|
||||
(defn graphql-results [ids db _]
|
||||
(let [results (->> (d/pull-many db default-read ids)
|
||||
(group-by :db/id))
|
||||
payments (->> ids
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
(ns auto-ap.datomic.transaction-rules
|
||||
(:require [datomic.api :as d]
|
||||
[auto-ap.datomic :refer [uri merge-query apply-sort-3 apply-pagination add-sorter-fields]]
|
||||
[auto-ap.graphql.utils :refer [limited-clients]]
|
||||
[clojure.set :refer [rename-keys]]
|
||||
[clj-time.coerce :as c]
|
||||
[clojure.string :as str]))
|
||||
(:require
|
||||
[auto-ap.datomic
|
||||
:refer [add-sorter-fields apply-pagination apply-sort-3 merge-query uri]]
|
||||
[auto-ap.graphql.utils :refer [limited-clients]]
|
||||
[clojure.string :as str]
|
||||
[datomic.api :as d]))
|
||||
|
||||
(defn <-datomic [result]
|
||||
result)
|
||||
@@ -76,7 +76,7 @@
|
||||
true (apply-sort-3 args)
|
||||
true (apply-pagination args))))
|
||||
|
||||
(defn graphql-results [ids db args]
|
||||
(defn graphql-results [ids db _]
|
||||
(let [results (->> (d/pull-many db default-read ids)
|
||||
(group-by :db/id))
|
||||
transaction-rules (->> ids
|
||||
|
||||
@@ -1,26 +1,16 @@
|
||||
(ns auto-ap.datomic.transactions
|
||||
(:require [datomic.api :as d]
|
||||
[auto-ap.datomic :refer [uri merge-query apply-sort-3 apply-pagination add-sorter-fields conn]]
|
||||
[auto-ap.graphql.utils :refer [limited-clients]]
|
||||
[clj-time.coerce :as c]
|
||||
[clj-time.coerce :as coerce]
|
||||
[clojure.tools.logging :as log]
|
||||
[clojure.string :as str]
|
||||
[auto-ap.datomic.accounts :as d-accounts]))
|
||||
|
||||
(defn sort-fn [sort-by]
|
||||
(cond
|
||||
(= "client" sort-by)
|
||||
#(-> % :transaction/client :client/name)
|
||||
|
||||
(= "account" sort-by)
|
||||
#(vector (-> % :transaction/account :account/name) (-> % :db/id))
|
||||
|
||||
:else
|
||||
(keyword "transaction" sort-by)))
|
||||
(:require
|
||||
[auto-ap.datomic
|
||||
:refer [add-sorter-fields apply-pagination apply-sort-3 conn merge-query uri]]
|
||||
[auto-ap.datomic.accounts :as d-accounts]
|
||||
[auto-ap.graphql.utils :refer [limited-clients]]
|
||||
[clj-time.coerce :as coerce]
|
||||
[clojure.string :as str]
|
||||
[clojure.tools.logging :as log]
|
||||
[datomic.api :as d]))
|
||||
|
||||
(defn potential-duplicate-ids [db args]
|
||||
(if (and (:potential-duplicates args)
|
||||
(when (and (:potential-duplicates args)
|
||||
(:bank-account-id args))
|
||||
(->> (d/q '[:find ?tx ?amount ?date
|
||||
:in $ ?ba
|
||||
@@ -31,9 +21,9 @@
|
||||
(not [?tx :transaction/approval-status :transaction-approval-status/suppressed])]
|
||||
db
|
||||
(:bank-account-id args))
|
||||
(group-by (fn [[tx amount date]]
|
||||
(group-by (fn [[_ amount date]]
|
||||
[amount date]))
|
||||
(filter (fn [[g txes]]
|
||||
(filter (fn [[_ txes]]
|
||||
(> (count txes) 1)))
|
||||
|
||||
(vals)
|
||||
@@ -183,7 +173,7 @@
|
||||
true (apply-sort-3 (assoc args :default-asc? false))
|
||||
true (apply-pagination args)))))
|
||||
|
||||
(defn graphql-results [ids db args]
|
||||
(defn graphql-results [ids db _]
|
||||
(let [results (->> (d/pull-many db '[* {:transaction/client [:client/name :db/id :client/code]
|
||||
:transaction/approval-status [:db/ident :db/id]
|
||||
:transaction/bank-account [:bank-account/name :bank-account/code :bank-account/yodlee-account-id :db/id :bank-account/locations :bank-account/current-balance]
|
||||
@@ -201,8 +191,8 @@
|
||||
{:account-client-override/client [:db/id]}]}]}]
|
||||
:transaction/yodlee-merchant [:db/id :yodlee-merchant/yodlee-id :yodlee-merchant/name]}]
|
||||
ids)
|
||||
(map #(update % :transaction/date c/from-date))
|
||||
(map #(update % :transaction/post-date c/from-date))
|
||||
(map #(update % :transaction/date coerce/from-date))
|
||||
(map #(update % :transaction/post-date coerce/from-date))
|
||||
(map #(update % :transaction/accounts
|
||||
(fn [tas]
|
||||
(map
|
||||
@@ -211,8 +201,8 @@
|
||||
tas))))
|
||||
(map (fn [transaction]
|
||||
(cond-> transaction
|
||||
(:transaction/payment transaction) (update-in [:transaction/payment :payment/date] c/from-date)
|
||||
(:transaction/expected-deposit transaction) (update-in [:transaction/expected-deposit :expected-deposit/date] c/from-date))
|
||||
(:transaction/payment transaction) (update-in [:transaction/payment :payment/date] coerce/from-date)
|
||||
(:transaction/expected-deposit transaction) (update-in [:transaction/expected-deposit :expected-deposit/date] coerce/from-date))
|
||||
))
|
||||
(map #(dissoc % :transaction/id))
|
||||
(group-by :db/id))]
|
||||
@@ -257,7 +247,7 @@
|
||||
{:account-client-override/client [:db/id]}]}]}]
|
||||
:transaction/yodlee-merchant [:db/id :yodlee-merchant/yodlee-id :yodlee-merchant/name]}]
|
||||
id)
|
||||
(update :transaction/date c/from-date)
|
||||
(update :transaction/post-date c/from-date)
|
||||
(update :transaction/date coerce/from-date)
|
||||
(update :transaction/post-date coerce/from-date)
|
||||
(dissoc :transaction/id)))
|
||||
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
(ns auto-ap.datomic.users
|
||||
(:require [datomic.api :as d]
|
||||
[auto-ap.datomic :refer [uri]]
|
||||
[clojure.set :refer [rename-keys]]
|
||||
[clj-time.coerce :as c]))
|
||||
(:require
|
||||
[auto-ap.datomic :refer [uri]]
|
||||
[datomic.api :as d]))
|
||||
|
||||
(defn add-arg [query name value where & rest]
|
||||
(let [query (-> query
|
||||
@@ -48,7 +47,7 @@
|
||||
is-first-user? (assoc :user/role :user-role/admin))])]
|
||||
(get-by-id (-> new-user-trans :tempids (get "user")))))))
|
||||
|
||||
(defn raw-graphql [args]
|
||||
(defn raw-graphql [_]
|
||||
(let [query (cond-> {:query {:find ['(pull ?e [*
|
||||
{:user/clients [*]}
|
||||
{:user/role [:db/ident]}])]
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
(ns auto-ap.datomic.yodlee2
|
||||
(:require [datomic.api :as d]
|
||||
[auto-ap.datomic :refer [uri remove-nils merge-query apply-pagination apply-sort-3 add-sorter-fields conn]]
|
||||
[auto-ap.graphql.utils :refer [limited-clients]]
|
||||
[auto-ap.parse :as parse]
|
||||
[clj-time.coerce :as c]
|
||||
[clojure.set :refer [rename-keys]]
|
||||
[clojure.string :as str]
|
||||
[clojure.tools.logging :as log]))
|
||||
(:require
|
||||
[auto-ap.datomic
|
||||
:refer [add-sorter-fields apply-pagination apply-sort-3 merge-query uri]]
|
||||
[auto-ap.graphql.utils :refer [limited-clients]]
|
||||
[clj-time.coerce :as c]
|
||||
[datomic.api :as d]))
|
||||
|
||||
(def default-read '[*])
|
||||
|
||||
@@ -17,8 +15,8 @@
|
||||
(->> (cond-> {:query {:find []
|
||||
:in ['$]
|
||||
:where ['[?e :yodlee-provider-account/id]]}
|
||||
:args [(d/db (d/connect uri))]}
|
||||
|
||||
:args [db]}
|
||||
|
||||
(limited-clients (:id args))
|
||||
(merge-query {:query {:in ['[?xx ...]]
|
||||
:where ['[?e :yodlee-provider-account/client ?xx]]}
|
||||
@@ -40,14 +38,13 @@
|
||||
true
|
||||
(merge-query {:query {:find ['?e ]
|
||||
:where ['[?e :yodlee-provider-account/id]]}}) )
|
||||
|
||||
|
||||
(d/query)
|
||||
(apply-sort-3 args)
|
||||
(apply-pagination args)))
|
||||
|
||||
|
||||
(defn graphql-results [ids db args]
|
||||
(defn graphql-results [ids db _]
|
||||
(let [results (->> (d/pull-many db default-read ids)
|
||||
(group-by :db/id))]
|
||||
(->> ids
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
(ns auto-ap.datomic.yodlee-merchants
|
||||
(:require [datomic.api :as d]
|
||||
[auto-ap.graphql.utils :refer [->graphql]]
|
||||
[auto-ap.datomic :refer [uri merge-query]]))
|
||||
(:require
|
||||
[auto-ap.datomic :refer [uri]]
|
||||
[datomic.api :as d]))
|
||||
|
||||
(defn get-merchants [args]
|
||||
(defn get-merchants [_]
|
||||
;; TODO admin?
|
||||
(let [query {:query {:find ['(pull ?e [:yodlee-merchant/name :yodlee-merchant/yodlee-id :db/id])]
|
||||
:in ['$]
|
||||
|
||||
@@ -1,28 +1,27 @@
|
||||
(ns auto-ap.graphql
|
||||
(:require
|
||||
[auto-ap.datomic :refer [merge-query uri]]
|
||||
[auto-ap.datomic.checks :as d-checks]
|
||||
[auto-ap.datomic.users :as d-users]
|
||||
[auto-ap.graphql.accounts :as gq-accounts]
|
||||
[auto-ap.graphql.checks :as gq-checks]
|
||||
[auto-ap.graphql.ezcater :as gq-ezcater]
|
||||
[auto-ap.graphql.clients :as gq-clients]
|
||||
[auto-ap.graphql.expected-deposit :as gq-expected-deposit]
|
||||
[auto-ap.graphql.ezcater :as gq-ezcater]
|
||||
[auto-ap.graphql.import-batch :as gq-import-batches]
|
||||
[auto-ap.graphql.intuit-bank-accounts :as gq-intuit-bank-accounts]
|
||||
[auto-ap.graphql.reports :as gq-reports]
|
||||
[auto-ap.graphql.invoices :as gq-invoices]
|
||||
[auto-ap.graphql.ledger :as gq-ledger]
|
||||
[auto-ap.graphql.plaid :as gq-plaid]
|
||||
[auto-ap.graphql.reports :as gq-reports]
|
||||
[auto-ap.graphql.requests :as gq-requests]
|
||||
[auto-ap.graphql.sales-orders :as gq-sales-orders]
|
||||
[auto-ap.graphql.transaction-rules :as gq-transaction-rules]
|
||||
[auto-ap.graphql.transactions :as gq-transactions]
|
||||
[auto-ap.graphql.users :as gq-users]
|
||||
[auto-ap.graphql.utils :refer [assert-admin assert-can-see-client]]
|
||||
[auto-ap.graphql.utils :refer [assert-admin]]
|
||||
[auto-ap.graphql.vendors :as gq-vendors]
|
||||
[auto-ap.graphql.yodlee-merchants :as ym]
|
||||
[auto-ap.graphql.yodlee2 :as gq-yodlee2]
|
||||
[auto-ap.graphql.plaid :as gq-plaid]
|
||||
[auto-ap.logging :refer [error-event info-event warn-event]]
|
||||
[auto-ap.time :as time]
|
||||
[clj-time.coerce :as coerce]
|
||||
@@ -30,14 +29,14 @@
|
||||
[clojure.string :as str]
|
||||
[clojure.tools.logging :as log]
|
||||
[clojure.walk :as walk]
|
||||
[com.unbounce.dogstatsd.core :as statsd]
|
||||
[com.walmartlabs.lacinia :refer [execute]]
|
||||
[com.walmartlabs.lacinia.parser :as p]
|
||||
[com.walmartlabs.lacinia.schema :as schema]
|
||||
[com.walmartlabs.lacinia.util :refer [attach-resolvers]]
|
||||
[datomic.api :as d]
|
||||
[unilog.context :as lc]
|
||||
[yang.time :refer [time-it]]
|
||||
[com.unbounce.dogstatsd.core :as statsd]
|
||||
[com.walmartlabs.lacinia.parser :as p])
|
||||
[yang.time :refer [time-it]])
|
||||
(:import
|
||||
(clojure.lang IPersistentMap)))
|
||||
|
||||
@@ -609,7 +608,7 @@
|
||||
|
||||
|
||||
|
||||
(defn get-user [context args value]
|
||||
(defn get-user [context args _]
|
||||
(assert-admin (:id context))
|
||||
|
||||
(let [users (d-users/get-graphql args)]
|
||||
@@ -619,7 +618,7 @@
|
||||
|
||||
|
||||
|
||||
(defn get-expense-account-stats [context {:keys [client_id] } value]
|
||||
(defn get-expense-account-stats [_ {:keys [client_id] } _]
|
||||
(let [result (cond-> {:query {:find ['?account '?account-name '(sum ?amount)]
|
||||
:in ['$]
|
||||
:where []}
|
||||
@@ -645,7 +644,7 @@
|
||||
(<= x 60 ) :due-60
|
||||
:else :due-later))
|
||||
|
||||
(defn get-invoice-stats [context {:keys [client_id] } value]
|
||||
(defn get-invoice-stats [_ {:keys [client_id] } _]
|
||||
(let [result (cond-> {:query {:find ['?name '(sum ?outstanding-balance) '(sum ?total)]
|
||||
:in ['$]
|
||||
:where []}
|
||||
@@ -687,7 +686,7 @@
|
||||
|
||||
(def first-week-a (coerce/to-date-time #inst "1999-12-27T00:00:00.000-07:00"))
|
||||
|
||||
(defn get-cash-flow [context {:keys [client_id]} value]
|
||||
(defn get-cash-flow [_ {:keys [client_id]} _]
|
||||
(when client_id
|
||||
(let [{:client/keys [week-a-credits week-a-debits week-b-credits week-b-debits forecasted-transactions ]} (d/pull (d/db (d/connect uri)) '[*] client_id)
|
||||
total-cash (reduce
|
||||
@@ -841,7 +840,7 @@
|
||||
(defn query-name [q]
|
||||
(try
|
||||
(str/join "__" (map name (:operations (p/operations (p/parse-query schema q)))))
|
||||
(catch Exception e
|
||||
(catch Exception _
|
||||
"unknown query")))
|
||||
|
||||
(defn query
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
(defn get-all-graphql [context args _]
|
||||
(assert-admin (:id context))
|
||||
(let [args (assoc args :id (:id context))
|
||||
[accounts accounts-count ] (d-accounts/get-graphql (assoc (<-graphql args) :per-page Integer/MAX_VALUE))]
|
||||
[accounts _ ] (d-accounts/get-graphql (assoc (<-graphql args) :per-page Integer/MAX_VALUE))]
|
||||
(map ->graphql accounts)))
|
||||
|
||||
(defn default-for-vendor [context args _]
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
[auto-ap.datomic.transactions :as d-transactions]
|
||||
[auto-ap.datomic.vendors :as d-vendors]
|
||||
[auto-ap.graphql.utils
|
||||
:refer [->graphql <-graphql assert-admin assert-failure assert-can-see-client enum->keyword assert-not-locked assert-none-locked]]
|
||||
:refer [->graphql <-graphql assert-admin assert-failure assert-can-see-client enum->keyword assert-not-locked]]
|
||||
[auto-ap.numeric :refer [num->words]]
|
||||
[auto-ap.time :refer [iso-date local-now parse]]
|
||||
[auto-ap.utils :refer [by dollars-0?]]
|
||||
@@ -296,7 +296,7 @@
|
||||
(into (invoice-payments invoices invoice-amounts)))))
|
||||
|
||||
|
||||
(defmethod invoices->entities :payment-type/balance-credit [invoices vendor client bank-account type index invoice-amounts]
|
||||
(defmethod invoices->entities :payment-type/balance-credit [invoices invoice-amounts]
|
||||
(when (<= (->> invoices
|
||||
(map (comp invoice-amounts :db/id))
|
||||
(reduce + 0.0))
|
||||
|
||||
@@ -3,23 +3,22 @@
|
||||
[auto-ap.datomic.expected-deposit :as d-expected-deposit]
|
||||
[auto-ap.graphql.utils
|
||||
:refer [->graphql <-graphql assert-admin ident->enum-f result->page]]
|
||||
[com.walmartlabs.lacinia.util :refer [attach-resolvers]]
|
||||
[clojure.tools.logging :as log]))
|
||||
[com.walmartlabs.lacinia.util :refer [attach-resolvers]]))
|
||||
|
||||
(def status->graphql (ident->enum-f :expected-deposit/status))
|
||||
|
||||
(defn get-expected-deposit [context args value]
|
||||
(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 value]
|
||||
(defn get-all-expected-deposits [context args _]
|
||||
(assert-admin (:id context))
|
||||
(map
|
||||
(comp ->graphql status->graphql)
|
||||
(first (d-expected-deposit/get-graphql (assoc (<-graphql args) :count Integer/MAX_VALUE)))))
|
||||
|
||||
(defn get-expected-deposit-page [context args value]
|
||||
(defn get-expected-deposit-page [context args _]
|
||||
(let [args (assoc args :id (:id context))
|
||||
[expected-deposits expected-deposit-count] (d-expected-deposit/get-graphql (<-graphql args))
|
||||
expected-deposits (map status->graphql expected-deposits)]
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
(ns auto-ap.graphql.import-batch
|
||||
(:require [auto-ap.datomic
|
||||
(:require
|
||||
[auto-ap.datomic
|
||||
:refer
|
||||
[add-sorter-fields apply-pagination apply-sort-3 conn merge-query]]
|
||||
[auto-ap.graphql.utils
|
||||
[auto-ap.graphql.utils
|
||||
:refer
|
||||
[<-graphql assert-admin ident->enum-f result->page]]
|
||||
[com.walmartlabs.lacinia.util :refer [attach-resolvers]]
|
||||
[datomic.api :as d]))
|
||||
[clj-time.coerce :as coerce]
|
||||
[com.walmartlabs.lacinia.util :refer [attach-resolvers]]
|
||||
[datomic.api :as d]))
|
||||
|
||||
(def default-read '[:db/id
|
||||
:import-batch/external-id
|
||||
@@ -37,7 +39,7 @@
|
||||
true (apply-sort-3 args)
|
||||
true (apply-pagination args))))
|
||||
|
||||
(defn graphql-results [ids db args]
|
||||
(defn graphql-results [ids db _]
|
||||
(let [results (->> (d/pull-many db default-read ids)
|
||||
(group-by :db/id))]
|
||||
(->> ids
|
||||
@@ -50,14 +52,14 @@
|
||||
[(graphql-results ids-to-retrieve db args)
|
||||
matching-count]))
|
||||
|
||||
(defn get-import-batch-page [context args value]
|
||||
(defn get-import-batch-page [context args _]
|
||||
(let [_ (assert-admin (:id context))
|
||||
args (assoc (:filters args) :id (:id context))
|
||||
[values matching-count] (get-graphql (<-graphql args))]
|
||||
(result->page (->> values
|
||||
(map (ident->enum-f :import-batch/source))
|
||||
(map (ident->enum-f :import-batch/status))
|
||||
(map #(update % :import-batch/date clj-time.coerce/to-date-time)))
|
||||
(map #(update % :import-batch/date coerce/to-date-time)))
|
||||
matching-count :data args)))
|
||||
|
||||
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
(ns auto-ap.graphql.intuit-bank-accounts
|
||||
(:require [auto-ap.graphql.utils :refer [->graphql <-graphql assert-admin]]
|
||||
[auto-ap.datomic :refer [conn]]
|
||||
[datomic.api :as d]))
|
||||
(:require
|
||||
[auto-ap.datomic :refer [conn]]
|
||||
[auto-ap.graphql.utils :refer [->graphql assert-admin]]
|
||||
[datomic.api :as d]))
|
||||
|
||||
(defn get-intuit-bank-accounts [context args value]
|
||||
#_(assert-admin (:id context))
|
||||
(defn get-intuit-bank-accounts [context _ _]
|
||||
(assert-admin (:id context))
|
||||
(->graphql (map first (d/q '[:find (pull ?e [*])
|
||||
:in $
|
||||
:where [?e :intuit-bank-account/external-id]]
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
(ns auto-ap.graphql.invoices
|
||||
(:require
|
||||
[auto-ap.datomic
|
||||
:refer [audit-transact audit-transact-batch conn remove-nils uri]]
|
||||
:refer [audit-transact conn remove-nils uri]]
|
||||
[auto-ap.datomic.clients :as d-clients]
|
||||
[auto-ap.datomic.invoices :as d-invoices]
|
||||
[auto-ap.datomic.vendors :as d-vendors]
|
||||
[auto-ap.graphql.checks :as gq-checks]
|
||||
[auto-ap.time :as atime]
|
||||
[auto-ap.graphql.utils
|
||||
:as u
|
||||
:refer [<-graphql
|
||||
|
||||
@@ -16,14 +16,14 @@
|
||||
[com.walmartlabs.lacinia.util :refer [attach-resolvers]]
|
||||
[datomic.api :as d]))
|
||||
|
||||
(defn plaid-link-token [context value args]
|
||||
(defn plaid-link-token [context value _]
|
||||
(when-not (:client_id value)
|
||||
(throw (ex-info "Client ID is required" {:validation-error "Client ID is required"})))
|
||||
(assert-can-see-client (:id context) (:client_id value))
|
||||
(let [client-code (:client/code (d/pull (d/db conn) [:client/code] (:client_id value)))]
|
||||
{:token (p/get-link-token client-code)}))
|
||||
|
||||
(defn link-plaid [context value args]
|
||||
(defn link-plaid [context value _]
|
||||
(when-not (:client_code value)
|
||||
(throw (ex-info "Client not provided" {:validation-error "Client not provided."})))
|
||||
(when-not (:public_token value)
|
||||
@@ -91,7 +91,7 @@
|
||||
true (apply-sort-3 args)
|
||||
true (apply-pagination args))))
|
||||
|
||||
(defn graphql-results [ids db args]
|
||||
(defn graphql-results [ids db _]
|
||||
(let [results (->> (d/pull-many db default-read ids)
|
||||
(group-by :db/id))]
|
||||
(->> ids
|
||||
@@ -106,7 +106,7 @@
|
||||
|
||||
|
||||
|
||||
(defn get-plaid-item-page [context args value]
|
||||
(defn get-plaid-item-page [context args _]
|
||||
|
||||
(let [args (assoc args :id (:id context))
|
||||
[plaid-items cnt] (get-graphql (<-graphql (assoc args :id (:id context))))]
|
||||
@@ -118,7 +118,7 @@
|
||||
:start (:start args 0)
|
||||
:end (+ (:start args 0) (count plaid-items))}))
|
||||
|
||||
(defn delete-plaid-item [context args value]
|
||||
(defn delete-plaid-item [context args _]
|
||||
(assert-admin (:id context))
|
||||
(assert-present args :id)
|
||||
@(d/transact conn [[:db/retractEntity (:id args)]])
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
[auto-ap.graphql.utils :refer [assert-admin]]
|
||||
[config.core :refer [env]]))
|
||||
|
||||
(defn request-import [context value args]
|
||||
(defn request-import [context value _]
|
||||
(assert-admin (:id context))
|
||||
(:message-id (sqs/send-message {:queue-url (:requests-queue-url env)
|
||||
:message-body (:which value)} )))
|
||||
|
||||
@@ -19,7 +19,6 @@
|
||||
[auto-ap.rule-matching :as rm]
|
||||
[auto-ap.utils :refer [dollars=]]
|
||||
[clj-time.coerce :as c]
|
||||
[clojure.set :as set]
|
||||
[clojure.string :as str]
|
||||
[datomic.api :as d]))
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
:manager :user-role/manager
|
||||
:user :user-role/user})
|
||||
|
||||
(defn edit-user [context {:keys [edit_user] :as args} value]
|
||||
(defn edit-user [context {:keys [edit_user]} _]
|
||||
(assert-admin (:id context))
|
||||
(let [user (d-users/get-by-id (:id edit_user))
|
||||
new-clients (set (map #(Long/parseLong %) (:clients edit_user)))
|
||||
|
||||
@@ -59,7 +59,7 @@
|
||||
([args key]
|
||||
(assert-present args key (name key)))
|
||||
([args key name]
|
||||
(if (not (get args key))
|
||||
(when (not (get args key))
|
||||
(throw (ex-info (str "Missing field '" name "'.")
|
||||
{:validation-error (str "Missing field '" name "'.")})))))
|
||||
|
||||
@@ -87,8 +87,7 @@
|
||||
|
||||
(defn limited-clients [id]
|
||||
(cond
|
||||
(or
|
||||
(= (:user/role id) "none"))
|
||||
(= (:user/role id) "none")
|
||||
[]
|
||||
|
||||
(= (:user/role id) "admin")
|
||||
|
||||
@@ -11,7 +11,6 @@
|
||||
enum->keyword
|
||||
is-admin?
|
||||
result->page]]
|
||||
[auto-ap.utils :refer [by]]
|
||||
[clojure.set :as set]
|
||||
[clojure.string :as str]
|
||||
[clojure.tools.logging :as log]
|
||||
@@ -31,7 +30,7 @@
|
||||
vendor-id))
|
||||
(set (map :db/id (:user/clients id)))))))
|
||||
|
||||
(defn upsert-vendor [context {{:keys [id name hidden terms code print_as primary_contact secondary_contact address default_account_id invoice_reminder_schedule schedule_payment_dom terms_overrides account_overrides] :as in} :vendor} value]
|
||||
(defn upsert-vendor [context {{:keys [id name hidden terms code print_as primary_contact secondary_contact address default_account_id invoice_reminder_schedule schedule_payment_dom terms_overrides account_overrides] :as in} :vendor} _]
|
||||
(when (and id (not (can-user-edit-vendor? id (:id context))))
|
||||
(assert-failure "This vendor is managed by Integreat. Please reach out to ben@integreatconsult.com for your changes."))
|
||||
|
||||
@@ -145,7 +144,7 @@
|
||||
(->graphql))
|
||||
log/info)))
|
||||
|
||||
(defn merge-vendors [context {:keys [from to]} value]
|
||||
(defn merge-vendors [context {:keys [from to]} _]
|
||||
(let [transaction (->> (d/query {:query {:find '[?x ?a2]
|
||||
:in '[$ ?vendor-from ]
|
||||
:where ['[?x ?a ?vendor-from]
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
(ns auto-ap.graphql.yodlee2
|
||||
(:require
|
||||
[auto-ap.datomic.yodlee2 :as d-yodlee2]
|
||||
[auto-ap.graphql.utils :refer [->graphql <-graphql assert-admin]]))
|
||||
[auto-ap.graphql.utils :refer [->graphql <-graphql]]))
|
||||
|
||||
(defn get-yodlee-provider-account-page [context args value]
|
||||
(defn get-yodlee-provider-account-page [context args _]
|
||||
(let [args (assoc args :id (:id context))
|
||||
[yodlee-provider-accounts cnt] (d-yodlee2/get-graphql (<-graphql (assoc args :id (:id context))))]
|
||||
{:yodlee_provider_accounts (map ->graphql yodlee-provider-accounts)
|
||||
@@ -12,10 +12,3 @@
|
||||
:start (:start args 0)
|
||||
:end (+ (:start args 0) (count yodlee-provider-accounts))}))
|
||||
|
||||
(defn get-all-yodlee-provider-accounts [context args value]
|
||||
(let [args (assoc args :id (:id context))]
|
||||
(map
|
||||
->graphql
|
||||
(first (d-yodlee2/get-graphql (assoc (<-graphql args)
|
||||
:count Integer/MAX_VALUE))))))
|
||||
|
||||
|
||||
@@ -2,6 +2,6 @@
|
||||
(:require [auto-ap.graphql.utils :refer [->graphql <-graphql]]
|
||||
[auto-ap.datomic.yodlee-merchants :as d-yodlee-merchants]))
|
||||
|
||||
(defn get-yodlee-merchants [context args value]
|
||||
(defn get-yodlee-merchants [_ args _]
|
||||
(->graphql (d-yodlee-merchants/get-merchants (<-graphql args))))
|
||||
|
||||
|
||||
@@ -1,15 +1,14 @@
|
||||
(ns auto-ap.import.manual
|
||||
(:require [auto-ap.datomic :refer [conn]]
|
||||
[auto-ap.import.manual.common :as c]
|
||||
[auto-ap.import.transactions :as t]
|
||||
[clj-time.coerce :as coerce]
|
||||
[clojure.data.csv :as csv]
|
||||
[clojure.tools.logging :as log]
|
||||
[datomic.api :as d]
|
||||
[unilog.context :as lc]))
|
||||
(:require
|
||||
[auto-ap.datomic :refer [conn]]
|
||||
[auto-ap.import.manual.common :as c]
|
||||
[auto-ap.import.transactions :as t]
|
||||
[clj-time.coerce :as coerce]
|
||||
[clojure.data.csv :as csv]
|
||||
[datomic.api :as d]
|
||||
[unilog.context :as lc]))
|
||||
|
||||
|
||||
(defn manual-import-batch [transactions user]
|
||||
)
|
||||
|
||||
(def columns [:status :raw-date :description-original :high-level-category nil nil :amount nil nil nil nil nil :bank-account-code :client-code])
|
||||
|
||||
@@ -19,9 +18,9 @@
|
||||
(drop 1)
|
||||
(map (fn [row]
|
||||
(into {} (->> (map vector columns row)
|
||||
(filter (fn [[k v]] k))))))))
|
||||
(filter (fn [[k _]] k))))))))
|
||||
|
||||
(defn manual->transaction [{:keys [description-original amount bank-account-code date] :as transaction} bank-account-lookup client-lookup]
|
||||
(defn manual->transaction [{:keys [description-original bank-account-code] :as transaction} bank-account-lookup client-lookup]
|
||||
(-> {:transaction/description-original description-original
|
||||
:transaction/status "POSTED"}
|
||||
(c/assoc-or-error :transaction/client #(if-let [client-id (client-lookup bank-account-code)]
|
||||
@@ -46,21 +45,21 @@
|
||||
(d/q '[:find ?bac ?ba
|
||||
:in $
|
||||
:where [?ba :bank-account/code ?bac]]
|
||||
(d/db conn)))]
|
||||
(let [import-batch (t/start-import-batch :import-source/manual user)
|
||||
transactions (->> transactions
|
||||
(map (fn [t]
|
||||
(manual->transaction t bank-account-code->bank-account bank-account-code->client)))
|
||||
(t/apply-synthetic-ids ))]
|
||||
(try
|
||||
(doseq [transaction transactions]
|
||||
(when-not (seq (:errors transaction))
|
||||
(t/import-transaction! import-batch transaction)))
|
||||
(d/db conn)))
|
||||
import-batch (t/start-import-batch :import-source/manual user)
|
||||
transactions (->> transactions
|
||||
(map (fn [t]
|
||||
(manual->transaction t bank-account-code->bank-account bank-account-code->client)))
|
||||
(t/apply-synthetic-ids ))]
|
||||
(try
|
||||
(doseq [transaction transactions]
|
||||
(when-not (seq (:errors transaction))
|
||||
(t/import-transaction! import-batch transaction)))
|
||||
|
||||
(t/finish! import-batch)
|
||||
(assoc (t/get-stats import-batch)
|
||||
:failed-validation (count (filter :errors transactions))
|
||||
:sample-error (first (first (map :errors (filter :errors transactions)))))
|
||||
(catch Exception e
|
||||
(t/fail! import-batch e)
|
||||
(t/get-stats import-batch)))))))
|
||||
(t/finish! import-batch)
|
||||
(assoc (t/get-stats import-batch)
|
||||
:failed-validation (count (filter :errors transactions))
|
||||
:sample-error (first (first (map :errors (filter :errors transactions)))))
|
||||
(catch Exception e
|
||||
(t/fail! import-batch e)
|
||||
(t/get-stats import-batch))))))
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
[clj-time.coerce :as coerce]
|
||||
[clj-time.core :as time]
|
||||
[datomic.api :as d]
|
||||
[digest :as di]
|
||||
[mount.core :as mount]
|
||||
[unilog.context :as lc]
|
||||
[yang.scheduler :as scheduler]))
|
||||
@@ -28,7 +29,8 @@
|
||||
(defn plaid->transaction [t]
|
||||
#:transaction {:description-original (:name t)
|
||||
:raw-id (:transaction_id t)
|
||||
:id (digest/sha-256 (:transaction_id t))
|
||||
:id #_{:clj-kondo/ignore [:unresolved-var]}
|
||||
(di/sha-256 (:transaction_id t))
|
||||
:amount (if (= "credit" (:type (:account t)))
|
||||
(- (double (:amount t)))
|
||||
(double (:amount t)))
|
||||
@@ -36,7 +38,7 @@
|
||||
:status "POSTED"})
|
||||
|
||||
|
||||
(defn import-plaid []
|
||||
(defn import-plaid-int []
|
||||
(lc/with-context {:source "Import plaid transactions"}
|
||||
(let [import-batch (t/start-import-batch :import-source/plaid "Automated plaid user")
|
||||
end (atime/local-now)
|
||||
@@ -57,7 +59,7 @@
|
||||
(catch Exception e
|
||||
(t/fail! import-batch e))))))
|
||||
|
||||
(def import-plaid (allow-once import-plaid))
|
||||
(def import-plaid (allow-once import-plaid-int))
|
||||
|
||||
(mount/defstate import-worker
|
||||
:start (scheduler/every (* 1000 60 60 3) (heartbeat import-plaid "import-plaid"))
|
||||
|
||||
@@ -1,18 +1,19 @@
|
||||
(ns auto-ap.import.transactions
|
||||
(:require [auto-ap.datomic :refer [audit-transact conn remove-nils uri]]
|
||||
[auto-ap.datomic.accounts :as a]
|
||||
[auto-ap.datomic.checks :as d-checks]
|
||||
[auto-ap.datomic.transaction-rules :as tr]
|
||||
[auto-ap.datomic.transactions :as d-transactions]
|
||||
[auto-ap.rule-matching :as rm]
|
||||
[auto-ap.utils :refer [dollars=]]
|
||||
[auto-ap.yodlee.core :as client]
|
||||
[clj-time.coerce :as coerce]
|
||||
[clj-time.core :as t]
|
||||
[clojure.core.cache :as cache]
|
||||
[clojure.tools.logging :as log]
|
||||
[datomic.api :as d]
|
||||
[digest :refer [sha-256]]))
|
||||
(:require
|
||||
[auto-ap.datomic :refer [audit-transact conn remove-nils uri]]
|
||||
[auto-ap.datomic.accounts :as a]
|
||||
[auto-ap.datomic.checks :as d-checks]
|
||||
[auto-ap.datomic.transaction-rules :as tr]
|
||||
[auto-ap.datomic.transactions :as d-transactions]
|
||||
[auto-ap.rule-matching :as rm]
|
||||
[auto-ap.time :as atime]
|
||||
[auto-ap.utils :refer [dollars=]]
|
||||
[clj-time.coerce :as coerce]
|
||||
[clj-time.core :as t]
|
||||
[clojure.core.cache :as cache]
|
||||
[clojure.tools.logging :as log]
|
||||
[datomic.api :as d]
|
||||
[digest :as di]))
|
||||
|
||||
(defn rough-match [client-id bank-account-id amount]
|
||||
(if (and client-id bank-account-id amount)
|
||||
@@ -35,7 +36,8 @@
|
||||
(cond (not (and client-id bank-account-id))
|
||||
nil
|
||||
|
||||
(:transaction/payment (d-transactions/get-by-id [:transaction/id (sha-256 (str id))]))
|
||||
(:transaction/payment (d-transactions/get-by-id [:transaction/id #_{:clj-kondo/ignore [:unresolved-var]}
|
||||
(di/sha-256 (str id))]))
|
||||
nil
|
||||
|
||||
check-number
|
||||
@@ -119,7 +121,7 @@
|
||||
:payment/type :payment-type/debit
|
||||
:payment/status :payment-status/cleared
|
||||
:db/id payment-id})
|
||||
(into (mapcat (fn [[vendor invoice-id invoice-amount]]
|
||||
(into (mapcat (fn [[_ invoice-id invoice-amount]]
|
||||
[{:invoice-payment/invoice invoice-id
|
||||
:invoice-payment/payment payment-id
|
||||
:invoice-payment/amount invoice-amount}
|
||||
@@ -143,7 +145,7 @@
|
||||
(if-let [[_ _ check-number] (re-find #"(?i)check(card|[^0-9]+([0-9]*))" description-original)]
|
||||
(try
|
||||
(Integer/parseInt check-number)
|
||||
(catch NumberFormatException e
|
||||
(catch NumberFormatException _
|
||||
nil))
|
||||
nil))
|
||||
|
||||
@@ -238,8 +240,7 @@
|
||||
))))
|
||||
|
||||
(defn maybe-code [{:transaction/keys [client amount] :as transaction} apply-rules valid-locations]
|
||||
(if-let [unpaid-invoices (seq (match-transaction-to-unpaid-invoices amount client))]
|
||||
nil
|
||||
(when (seq (match-transaction-to-unpaid-invoices amount client))
|
||||
(apply-rules transaction valid-locations)))
|
||||
|
||||
(defn transaction->txs [transaction bank-account apply-rules]
|
||||
@@ -294,7 +295,7 @@
|
||||
(log/info "Importing transactions from " source)
|
||||
|
||||
(reify ImportBatch
|
||||
(import-transaction! [this transaction]
|
||||
(import-transaction! [_ transaction]
|
||||
(let [bank-account (d/pull (d/db conn)
|
||||
[:bank-account/code
|
||||
:db/id
|
||||
@@ -318,10 +319,10 @@
|
||||
{:user/name user
|
||||
:user/role ":admin"}))))
|
||||
|
||||
(get-stats [this]
|
||||
(get-stats [_]
|
||||
@stats)
|
||||
|
||||
(fail! [this error]
|
||||
(fail! [_ error]
|
||||
(log/errorf "Couldn't complete import %d with error." import-id)
|
||||
(log/error error)
|
||||
@(d/transact conn [(merge {:db/id import-id
|
||||
@@ -329,7 +330,7 @@
|
||||
:import-batch/error-message (str error)}
|
||||
@stats)]))
|
||||
|
||||
(finish! [this]
|
||||
(finish! [_]
|
||||
(log/infof "Finishing import batch %d for %s with stats %s " import-id (name source) (pr-str @stats))
|
||||
@(d/transact conn [(merge {:db/id import-id
|
||||
|
||||
@@ -339,7 +340,7 @@
|
||||
|
||||
|
||||
(defn synthetic-key [{:transaction/keys [date bank-account description-original amount client] } index]
|
||||
(str (str (some-> date coerce/to-date-time auto-ap.time/localize)) "-" bank-account "-" description-original "-" amount "-" index "-" client))
|
||||
(str (str (some-> date coerce/to-date-time atime/localize)) "-" bank-account "-" description-original "-" amount "-" index "-" client))
|
||||
|
||||
(defn apply-synthetic-ids [transactions]
|
||||
(->> transactions
|
||||
@@ -349,7 +350,8 @@
|
||||
(map (fn [index transaction]
|
||||
(let [raw-id (synthetic-key transaction index)]
|
||||
(assoc transaction
|
||||
:transaction/id (digest/sha-256 raw-id)
|
||||
:transaction/id #_{:clj-kondo/ignore [:unresolved-var]}
|
||||
(di/sha-256 raw-id)
|
||||
:transaction/raw-id raw-id)))
|
||||
(range)
|
||||
group)))))
|
||||
|
||||
@@ -3,16 +3,14 @@
|
||||
[auto-ap.datomic :refer [conn]]
|
||||
[auto-ap.import.transactions :as t]
|
||||
[auto-ap.time :as atime]
|
||||
[auto-ap.utils :refer [allow-once heartbeat]]
|
||||
[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 :refer [sha-256]]
|
||||
[mount.core :as mount]
|
||||
[yang.scheduler :as scheduler]))
|
||||
[digest :as di]))
|
||||
|
||||
(defn yodlee->transaction [transaction use-date-instead-of-post-date?]
|
||||
(let [{post-date :postDate
|
||||
@@ -31,7 +29,8 @@
|
||||
date (atime/parse date "YYYY-MM-dd")]
|
||||
#:transaction
|
||||
{:post-date (coerce/to-date (atime/parse post-date "YYYY-MM-dd"))
|
||||
:id (sha-256 (str id))
|
||||
: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?
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
[unilog.context :as lc]
|
||||
[yang.scheduler :as scheduler]))
|
||||
|
||||
(defn import-yodlee2 []
|
||||
(defn import-yodlee2-int []
|
||||
(lc/with-context {:source "Import yodlee2 transactions"}
|
||||
(statsd/event {:title "Yodlee2 import started"
|
||||
:text "Starting"
|
||||
@@ -53,7 +53,7 @@
|
||||
|
||||
|
||||
|
||||
(def import-yodlee2 (allow-once import-yodlee2))
|
||||
(def import-yodlee2 (allow-once import-yodlee2-int))
|
||||
|
||||
|
||||
(mount/defstate import-worker
|
||||
|
||||
@@ -1,38 +1,30 @@
|
||||
(ns auto-ap.intuit.core
|
||||
(:require [auto-ap.datomic :refer [conn remove-nils]]
|
||||
[amazonica.aws.s3 :as s3]
|
||||
[auto-ap.utils :refer [by]]
|
||||
[clj-http.client :as client]
|
||||
[clj-time.coerce :as coerce]
|
||||
[clj-time.core :as time]
|
||||
[clj-time.format :as f]
|
||||
[config.core :refer [env] :as cfg ]
|
||||
[clojure.string :as str]
|
||||
[clojure.data.json :as json]
|
||||
[clojure.java.io :as io]
|
||||
[clojure.tools.logging :as log]
|
||||
[datomic.api :as d]
|
||||
[mount.core :as mount]
|
||||
[unilog.context :as lc]
|
||||
[yang.scheduler :as scheduler]
|
||||
[clojure.core.async :as async]
|
||||
[clojure.core.memoize :as m])
|
||||
(:import [org.apache.commons.codec.binary Base64]))
|
||||
(:require
|
||||
[amazonica.aws.s3 :as s3]
|
||||
[clj-http.client :as client]
|
||||
[clojure.core.memoize :as m]
|
||||
[clojure.java.io :as io]
|
||||
[clojure.string :as str]
|
||||
[clojure.tools.logging :as log]
|
||||
[config.core :as cfg :refer [env]])
|
||||
(:import
|
||||
(org.apache.commons.codec.binary Base64)))
|
||||
|
||||
;; (def authorization-code "AB11638463964I0tYPR3A1inog2HL407u2bZBXHg6LEqCbILRO")
|
||||
;; (def realm-id "4620816365202617680")
|
||||
|
||||
(def authorization-code "AB11638463964I0tYPR3A1inog2HL407u2bZBXHg6LEqCbILRO")
|
||||
(def realm-id "4620816365202617680")
|
||||
;; (def company-id "4620816365202617680")
|
||||
|
||||
(def company-id "4620816365202617680")
|
||||
|
||||
(def base-url "https://sandbox-quickbooks.api.intuit.com/v3")
|
||||
;; (def base-url "https://sandbox-quickbooks.api.intuit.com/v3")
|
||||
|
||||
|
||||
(def prod-client-id "ABFRwAiOqQiLN66HKplXfyRE3ipD390DHsrUquflRCiOa81mxa")
|
||||
(def prod-client-secret "xDUj04GeQXpLvrhxep1jjDYwjJWbzzOPrirUQTKF")
|
||||
(def prod-redirect-uri "https://developer.intuit.com/v2/OAuth2Playground/RedirectUrl")
|
||||
(def prod-authorization-code "AB11638464998wYuapsEGtIEnRqphrw0H97XUnvEG2dK4cGUyL")
|
||||
(def prod-realm-id "123146163906404")
|
||||
|
||||
;; (def prod-redirect-uri "https://developer.intuit.com/v2/OAuth2Playground/RedirectUrl")
|
||||
;; (def prod-authorization-code "AB11638464998wYuapsEGtIEnRqphrw0H97XUnvEG2dK4cGUyL")
|
||||
;; (def prod-realm-id "123146163906404")
|
||||
|
||||
;; "refreshToken": "AB11647191065B0olWYQ61wfq8uszBusfe6Jpn7Au7qY5exkLL",
|
||||
;; "accessToken":,
|
||||
;;
|
||||
@@ -122,10 +114,9 @@
|
||||
|
||||
(defn get-all-transactions [start end]
|
||||
(let [token (get-fresh-access-token)]
|
||||
(let [body (:body (client/get (str prod-base-url "/company/" prod-company-id "/reports/TransactionList" "?minorversion=63&start_date=" start "&end_date=" end)
|
||||
{:headers (with-auth prod-base-headers token)
|
||||
:as :json}))]
|
||||
body)))
|
||||
(:body (client/get (str prod-base-url "/company/" prod-company-id "/reports/TransactionList" "?minorversion=63&start_date=" start "&end_date=" end)
|
||||
{:headers (with-auth prod-base-headers token)
|
||||
:as :json}))))
|
||||
|
||||
(def memoize-get-all-transactions (m/ttl get-all-transactions :ttl/threshold 60000))
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
(ns auto-ap.parse
|
||||
(:require
|
||||
[auto-ap.logging :refer [info-event]]
|
||||
[auto-ap.parse.csv :as csv]
|
||||
[auto-ap.parse.excel :as excel]
|
||||
[auto-ap.parse.templates :as t]
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
[clojure.tools.logging :as log]))
|
||||
|
||||
(defn determine
|
||||
[[header :as z]]
|
||||
[[header]]
|
||||
(log/info "Importing with header" header)
|
||||
(let [csv-type (cond (str/includes? (second header) "Customer's PO No.")
|
||||
:mama-lus
|
||||
@@ -34,15 +34,16 @@
|
||||
|
||||
(defmulti parse-csv
|
||||
determine
|
||||
:default (fn default [rows]
|
||||
:default #_{:clj-kondo/ignore [:unused-binding]}
|
||||
(fn default [rows]
|
||||
nil))
|
||||
|
||||
(defn parse-date-fallover [d fmts]
|
||||
(if-let [valid-fmt (->> fmts
|
||||
(when-let [valid-fmt (->> fmts
|
||||
(filter (fn [f]
|
||||
(try
|
||||
(u/parse-value :clj-time f d)
|
||||
(catch Exception e
|
||||
(catch Exception _
|
||||
nil))
|
||||
))
|
||||
(first))]
|
||||
@@ -96,7 +97,7 @@
|
||||
[rows]
|
||||
(transduce
|
||||
(comp (drop 1)
|
||||
(map (fn [[_ po-number despatch-number invoice-number invoice-date customer value :as row]]
|
||||
(map (fn [[_ po-number _ invoice-number invoice-date customer value :as row]]
|
||||
{:vendor-code "Mama Lu's Foods"
|
||||
:customer-identifier customer
|
||||
:invoice-number (str po-number "-" invoice-number )
|
||||
@@ -112,7 +113,7 @@
|
||||
[rows]
|
||||
(transduce
|
||||
(comp (drop 1)
|
||||
(map (fn [[ po-number despatch-number invoice-number invoice-date customer value :as row]]
|
||||
(map (fn [[ po-number _ invoice-number invoice-date customer value :as row]]
|
||||
{:vendor-code "Mama Lu's Foods"
|
||||
:customer-identifier customer
|
||||
:invoice-number (str po-number "-" invoice-number )
|
||||
@@ -128,7 +129,7 @@
|
||||
[rows]
|
||||
(transduce
|
||||
(comp
|
||||
(filter (fn [[dt _ doc-number name _ status _ _ amount :as row]]
|
||||
(filter (fn [[_ _ _ _ _ status _ _ _ ]]
|
||||
(= status "Billed")))
|
||||
(map (fn [[dt _ doc-number name _ _ _ _ amount :as row]]
|
||||
{:vendor-code "PHILZ COFFEE, INC"
|
||||
@@ -161,11 +162,12 @@
|
||||
[]
|
||||
(drop 1 rows)))
|
||||
|
||||
#_{:clj-kondo/ignore [:unused-binding]}
|
||||
(defmethod parse-csv nil
|
||||
[rows]
|
||||
nil)
|
||||
|
||||
(defn parse-file [file filename]
|
||||
(defn parse-file [file _]
|
||||
(with-open [reader (io/reader file)]
|
||||
(let [rows (csv/read-csv reader :separator \,)]
|
||||
(parse-csv rows))))
|
||||
|
||||
@@ -39,7 +39,7 @@
|
||||
extract)]))
|
||||
|
||||
(defn parse-file
|
||||
[file filename]
|
||||
[file _]
|
||||
(let [wb (d/load-workbook file)
|
||||
text (->> wb
|
||||
(d/sheet-seq)
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
(ns auto-ap.parse.util
|
||||
(:require [clj-fuzzy.metrics :as m]
|
||||
[clojure.java.shell :as sh]
|
||||
[clojure.string :as str]
|
||||
[clj-time.format :as f]
|
||||
[clj-time.core :as time]
|
||||
[clojure.tools.logging :as log]))
|
||||
(:require
|
||||
[clj-time.core :as time]
|
||||
[clj-time.format :as f]
|
||||
[clojure.string :as str]
|
||||
[clojure.tools.logging :as log]))
|
||||
|
||||
(defmulti parse-value (fn [method _ _]
|
||||
method))
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
:body
|
||||
:link_token))
|
||||
|
||||
(defn exchange-public-token [public-token client-code]
|
||||
(defn exchange-public-token [public-token _]
|
||||
(-> (client/post (str base-url "/item/public_token/exchange")
|
||||
{:as :json
|
||||
:headers {"Content-Type" "application/json"}
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
{:alg :hs512}))
|
||||
|
||||
(defroutes routes
|
||||
(GET "/oauth" {{:strs [code]} :query-params :keys [scheme] :as r {:strs [host]} :headers}
|
||||
(GET "/oauth" {{:strs [code]} :query-params {:strs [host]} :headers}
|
||||
(try
|
||||
(let [auth (-> "https://accounts.google.com/o/oauth2/token"
|
||||
(http/post
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
(ns auto-ap.routes.events
|
||||
(:require [auto-ap.routes.utils :refer [wrap-secure]]
|
||||
[config.core :refer [env]]
|
||||
[clj-http.client :as http]
|
||||
[clj-time.coerce :as c]
|
||||
[clj-time.core :as time]
|
||||
[clj-time.periodic :as p]
|
||||
[clj-time.predicates :as pred]
|
||||
[clojure.data.json :as json]
|
||||
[compojure.core :refer [GET PUT POST context defroutes
|
||||
wrap-routes]]
|
||||
[clojure.tools.logging :as log]
|
||||
[unilog.context :as lc])
|
||||
(:import (org.joda.time DateTime)))
|
||||
@@ -1,13 +1,13 @@
|
||||
(ns auto-ap.routes.graphql
|
||||
(:require [auto-ap.routes.utils :refer [wrap-secure wrap-spec]]
|
||||
(:require [auto-ap.routes.utils :refer [wrap-secure]]
|
||||
[auto-ap.graphql :as ql]
|
||||
[auto-ap.logging :refer [warn-event]]
|
||||
[buddy.auth :refer [throw-unauthorized]]
|
||||
[clojure.edn :as edn]
|
||||
[compojure.core :refer [GET POST PUT context defroutes
|
||||
[compojure.core :refer [GET POST context defroutes
|
||||
wrap-routes]]
|
||||
[clojure.tools.logging :as log]))
|
||||
(defn handle-graphql [{:keys [request-method query-params body edn-params method] :as r}]
|
||||
(defn handle-graphql [{:keys [request-method query-params] :as r}]
|
||||
(when (= "none" (:user/role (:identity r)))
|
||||
(throw-unauthorized))
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
(defroutes routes
|
||||
(wrap-routes
|
||||
(context "/yodlee2" []
|
||||
(GET "/fastlink" {:keys [query-params identity] :as request}
|
||||
(GET "/fastlink" {:keys [query-params identity]}
|
||||
(assert-can-see-client identity (d/pull (d/db conn) [:db/id] [:client/code (get query-params "client")]))
|
||||
|
||||
(let [token (if-let [client-id (get query-params "client-id")]
|
||||
@@ -27,9 +27,7 @@
|
||||
:headers {"Content-Type" "application/edn"}
|
||||
:body (pr-str {:token token
|
||||
:url (:yodlee2-fastlink env)}) }))
|
||||
(POST "/provider-accounts/refresh/" {:keys [query-params identity edn-params]
|
||||
{:keys [id]} :route-params
|
||||
:as request}
|
||||
(POST "/provider-accounts/refresh/" {:keys [identity edn-params]}
|
||||
(assert-admin identity)
|
||||
(log/info "refreshing " edn-params)
|
||||
(try
|
||||
@@ -48,9 +46,8 @@
|
||||
:body (pr-str {:message (.getMessage e)
|
||||
:error (.toString e)})})))
|
||||
|
||||
(GET "/provider-accounts/:client/:id" {:keys [query-params identity edn-params]
|
||||
{:keys [client id]} :route-params
|
||||
:as request}
|
||||
(GET "/provider-accounts/:client/:id" {:keys [identity]
|
||||
{:keys [client id]} :route-params}
|
||||
(assert-admin identity)
|
||||
(log/info "looking-up " client id)
|
||||
(try
|
||||
@@ -68,7 +65,7 @@
|
||||
:headers {"Content-Type" "application/edn"}
|
||||
:body (pr-str {:message (.getMessage e)
|
||||
:error (.toString e)})})))
|
||||
(POST "/provider-accounts/delete/" {:keys [edn-params identity] {:keys [id]} :route-params :as request}
|
||||
(POST "/provider-accounts/delete/" {:keys [edn-params identity]}
|
||||
(assert-admin identity)
|
||||
(try
|
||||
(yodlee/delete-provider-account (-> (:client-id edn-params)
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
(ns auto-ap.server
|
||||
(:gen-class)
|
||||
#_{:clj-kondo/ignore [:unused-namespace]}
|
||||
(:require auto-ap.background.invoices
|
||||
[auto-ap.background.requests :as requests]
|
||||
[auto-ap.background.sysco :as sysco]
|
||||
@@ -84,7 +85,7 @@
|
||||
(defn shutdown-mount []
|
||||
(mount/stop))
|
||||
|
||||
(defn -main [& args]
|
||||
(defn -main [& _]
|
||||
(let [without (cond-> []
|
||||
(not (env :run-web? )) (into [#'jetty
|
||||
#'jetty-stats])
|
||||
|
||||
@@ -1,21 +1,23 @@
|
||||
(ns auto-ap.square.core
|
||||
(:require [auto-ap.datomic :refer [conn remove-nils]]
|
||||
[auto-ap.utils :refer [heartbeat]]
|
||||
[auto-ap.time :as atime]
|
||||
[clj-http.client :as client]
|
||||
[clj-time.coerce :as coerce]
|
||||
[clj-time.core :as time]
|
||||
[clj-time.periodic :as periodic]
|
||||
[clj-time.format :as f]
|
||||
[clojure.string :as str]
|
||||
[clojure.data.json :as json]
|
||||
[clojure.tools.logging :as log]
|
||||
[datomic.api :as d]
|
||||
[mount.core :as mount]
|
||||
[unilog.context :as lc]
|
||||
[yang.scheduler :as scheduler]
|
||||
[clojure.core.async :as async]
|
||||
[slingshot.slingshot :refer [try+]]))
|
||||
(:require
|
||||
[auto-ap.datomic :refer [conn remove-nils]]
|
||||
[auto-ap.time :as atime]
|
||||
[auto-ap.utils :refer [heartbeat]]
|
||||
[clj-http.client :as client]
|
||||
[clj-time.coerce :as coerce]
|
||||
[clj-time.core :as time]
|
||||
[clj-time.format :as f]
|
||||
[clj-time.periodic :as periodic]
|
||||
[clojure.core.async :as async]
|
||||
[clojure.data.json :as json]
|
||||
[clojure.set :as set]
|
||||
[clojure.string :as str]
|
||||
[clojure.tools.logging :as log]
|
||||
[datomic.api :as d]
|
||||
[mount.core :as mount]
|
||||
[slingshot.slingshot :refer [try+]]
|
||||
[unilog.context :as lc]
|
||||
[yang.scheduler :as scheduler]))
|
||||
|
||||
(defn client-base-headers [client]
|
||||
{"Square-Version" "2021-08-18"
|
||||
@@ -225,7 +227,7 @@
|
||||
(and (or (> (count (:tenders order)) 0)
|
||||
(seq (:returns order)))
|
||||
(or (= #{} (set (map #(:status (:card_details %)) (:tenders order))))
|
||||
(not= #{} (clojure.set/difference
|
||||
(not= #{} (set/difference
|
||||
(set (map #(:status (:card_details %)) (:tenders order)))
|
||||
#{"FAILED" "VOIDED"}))))))
|
||||
(filter (fn [order]
|
||||
@@ -519,7 +521,7 @@
|
||||
(mark-integration-status client {:integration-status/state :integration-state/failed
|
||||
:integration-status/message (-> data :body str)}))
|
||||
|
||||
(catch Object e
|
||||
(catch Object _
|
||||
(log/warn &throw-context)
|
||||
(mark-integration-status client {:integration-status/state :integration-state/failed
|
||||
:integration-status/message (or (some-> (:wrapper &throw-context) (.getMessage ))
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
(try
|
||||
(time/from-time-zone (f/parse (f/formatter format) v)
|
||||
(time/time-zone-for-id "America/Los_Angeles"))
|
||||
(catch Exception e
|
||||
(catch Exception _
|
||||
nil)))
|
||||
|
||||
(defn unparse [v format]
|
||||
@@ -31,7 +31,7 @@
|
||||
(try
|
||||
|
||||
(f/unparse (f/with-zone (f/formatter format) (time/time-zone-for-id "America/Los_Angeles")) v)
|
||||
(catch Exception e
|
||||
(catch Exception _
|
||||
nil)))
|
||||
|
||||
|
||||
|
||||
@@ -148,8 +148,7 @@
|
||||
|
||||
|
||||
(defn get-provider-account [client-code id]
|
||||
(let [cob-session (login-user (client-code->login client-code))
|
||||
batch-size 100]
|
||||
(let [cob-session (login-user (client-code->login client-code))]
|
||||
|
||||
(-> (str (:yodlee2-base-url env) "/providerAccounts/" id)
|
||||
|
||||
|
||||
135
src/clj/user.clj
135
src/clj/user.clj
@@ -1,24 +1,29 @@
|
||||
(ns user
|
||||
(:require [auto-ap.datomic :refer [uri]]
|
||||
[config.core :refer [env]]
|
||||
[auto-ap.utils :refer [by]]
|
||||
[auto-ap.time :as atime]
|
||||
[clojure.core.async :as async]
|
||||
[unilog.context :as lc]
|
||||
[auto-ap.square.core :as square]
|
||||
[mount.core :as mount]
|
||||
[auto-ap.server ]
|
||||
[datomic.api :as d]
|
||||
[clojure.data.csv :as csv]
|
||||
[clj-time.coerce :as c]
|
||||
[clj-time.core :as t]
|
||||
[clj-time.periodic :as per]
|
||||
[clojure.java.io :as io]
|
||||
[clojure.string :as str]
|
||||
|
||||
[amazonica.aws.s3 :as s3])
|
||||
(:import [org.apache.commons.io.input BOMInputStream]))
|
||||
(:require
|
||||
[amazonica.aws.s3 :as s3]
|
||||
[auto-ap.datomic :refer [uri]]
|
||||
[auto-ap.ledger :as l]
|
||||
[auto-ap.server ]
|
||||
[auto-ap.square.core :as square]
|
||||
[auto-ap.time :as atime]
|
||||
[auto-ap.utils :refer [by]]
|
||||
[clj-time.coerce :as c]
|
||||
[clj-time.core :as t]
|
||||
[clj-time.periodic :as per]
|
||||
[clojure.core.async :as async]
|
||||
[clojure.data.csv :as csv]
|
||||
[clojure.java.io :as io]
|
||||
clojure.pprint
|
||||
[clojure.string :as str]
|
||||
[config.core :refer [env]]
|
||||
[datomic.api :as d]
|
||||
[mount.core :as mount]
|
||||
nrepl.middleware.print
|
||||
[unilog.context :as lc])
|
||||
(:import
|
||||
[org.apache.commons.io.input BOMInputStream]))
|
||||
|
||||
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
|
||||
(defn mark-until-date [client end]
|
||||
(let [conn (d/connect uri)]
|
||||
(doseq [p (->>
|
||||
@@ -60,6 +65,7 @@
|
||||
|
||||
@(d/transact conn p) (println "process 100"))))
|
||||
|
||||
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
|
||||
(defn unapprove-all []
|
||||
(let [conn (d/connect uri)]
|
||||
(doseq [p (->>
|
||||
@@ -76,12 +82,9 @@
|
||||
@(d/transact conn p)
|
||||
(println "process 100"))))
|
||||
|
||||
|
||||
|
||||
|
||||
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
|
||||
(defn load-accounts [conn]
|
||||
(let [[header & rows] (-> "master-account-list.csv" (io/resource) io/input-stream (BOMInputStream.) (io/reader) csv/read-csv)
|
||||
headers (map read-string header)
|
||||
code->existing-account (by :account/numeric-code (map first (d/query {:query {:find ['(pull ?e [:account/numeric-code
|
||||
:db/id])]
|
||||
:in ['$]
|
||||
@@ -96,7 +99,7 @@
|
||||
:where ['[?a :account/numeric-code ?ac]]}
|
||||
:args [(d/db conn) also-merge ]}))]
|
||||
(into (mapv
|
||||
(fn [[entity id sunset-account]]
|
||||
(fn [[entity id _]]
|
||||
[:db/add entity id old-account-id])
|
||||
(d/query {:query {:find ['?e '?id '?a ]
|
||||
:in ['$ '?ac ]
|
||||
@@ -157,6 +160,7 @@
|
||||
rows)]
|
||||
@(d/transact conn txes)))
|
||||
|
||||
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
|
||||
(defn find-bad-accounts []
|
||||
(set (map second (d/query {:query {:find ['(pull ?x [*]) '?z]
|
||||
:in ['$]
|
||||
@@ -165,6 +169,7 @@
|
||||
'[?x ?a ?e]]}
|
||||
:args [(d/db (d/connect uri))]}))))
|
||||
|
||||
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
|
||||
(defn delete-4-digit-accounts []
|
||||
@(d/transact (d/connect uri)
|
||||
(transduce
|
||||
@@ -182,9 +187,10 @@
|
||||
)
|
||||
|
||||
|
||||
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
|
||||
(defn find-conflicting-accounts []
|
||||
(filter
|
||||
(fn [[k v]]
|
||||
(fn [[_ v]]
|
||||
(> (count v) 1))
|
||||
(reduce
|
||||
(fn [acc [e z]]
|
||||
@@ -195,15 +201,15 @@
|
||||
:where ['[?e :account/numeric-code ?z]]}
|
||||
:args [(d/db (d/connect uri))]}))))
|
||||
|
||||
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
|
||||
(defn customize-accounts [customer filename]
|
||||
(let [conn (d/connect uri)
|
||||
[header & rows] (-> filename (io/resource) io/input-stream (BOMInputStream.) (io/reader) csv/read-csv)
|
||||
[_ & rows] (-> filename (io/resource) io/input-stream (BOMInputStream.) (io/reader) csv/read-csv)
|
||||
[client-id] (first (d/query (-> {:query {:find ['?e]
|
||||
:in ['$ '?z]
|
||||
:where [['?e :client/code '?z]]}
|
||||
:args [(d/db (d/connect uri)) customer]})))
|
||||
_ (println client-id)
|
||||
headers (map read-string header)
|
||||
code->existing-account (by :account/numeric-code (map first (d/query {:query {:find ['(pull ?e [:account/numeric-code
|
||||
{:account/applicability [:db/ident]}
|
||||
:db/id])]
|
||||
@@ -218,7 +224,7 @@
|
||||
|
||||
|
||||
|
||||
_ (if-let [bad-rows (seq (->> rows
|
||||
_ (when-let [bad-rows (seq (->> rows
|
||||
(group-by (fn [[_ account]]
|
||||
account))
|
||||
vals
|
||||
@@ -278,13 +284,7 @@
|
||||
#_@(d/transact conn txes)))
|
||||
|
||||
|
||||
|
||||
(defn attach-signature [client-code filename]
|
||||
@(d/transact (d/connect uri)
|
||||
[{:db/id [:client/code client-code]
|
||||
:client/signature-file (str "https://s3.amazonaws.com/integreat-signature-images/" filename)}]))
|
||||
|
||||
|
||||
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
|
||||
(defn fix-transactions-without-locations [client-code location]
|
||||
(->>
|
||||
(d/query {:query {:find ['(pull ?e [*])]
|
||||
@@ -369,11 +369,13 @@
|
||||
:args [(d/db (d/connect uri))]})])
|
||||
|
||||
|
||||
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
|
||||
(defn go []
|
||||
(require '[mount.core :as mount])
|
||||
(require '[auto-ap.server])
|
||||
(mount/start-without #'auto-ap.server/jetty))
|
||||
|
||||
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
|
||||
(defn entity-history [i]
|
||||
(vec (sort-by first (d/query
|
||||
{:query {:find ['?tx '?z '?v ]
|
||||
@@ -383,6 +385,7 @@
|
||||
'[(= ?ad true)]]}
|
||||
:args [i (d/history (d/db (d/connect uri)))]}))))
|
||||
|
||||
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
|
||||
(defn entity-history-with-revert [i]
|
||||
(vec (sort-by first (d/query
|
||||
{:query {:find ['?tx '?z '?v '?ad ]
|
||||
@@ -391,12 +394,14 @@
|
||||
'[?a :db/ident ?z]]}
|
||||
:args [i (d/history (d/db (d/connect uri)))]}))))
|
||||
|
||||
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
|
||||
(defn tx-detail [i]
|
||||
(map (juxt :e #(d/ident (d/db (d/connect uri)) (:a %)) :v)
|
||||
(:data (first
|
||||
(d/tx-range (d/log (d/connect uri))
|
||||
i
|
||||
(inc i))))))
|
||||
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
|
||||
(defn tx-range-detail [i]
|
||||
(map (juxt :e #(d/ident (d/db (d/connect uri)) (:a %)) :v)
|
||||
|
||||
@@ -405,14 +410,17 @@
|
||||
(+ i 100)))))
|
||||
|
||||
|
||||
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
|
||||
(defn start-db []
|
||||
(mount.core/start (mount.core/only #{#'auto-ap.datomic/conn})))
|
||||
|
||||
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
|
||||
(defn touch-transaction-ledger [e]
|
||||
@(d/transact auto-ap.datomic/conn [[:db/retractEntity [:journal-entry/original-entity e]]])
|
||||
@(d/transact auto-ap.datomic/conn [(auto-ap.ledger/entity-change->ledger (d/db auto-ap.datomic/conn)
|
||||
[:transaction e])]))
|
||||
@(d/transact auto-ap.datomic/conn [(l/entity-change->ledger (d/db auto-ap.datomic/conn)
|
||||
[:transaction e])]))
|
||||
|
||||
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
|
||||
(defn mismatched-transactions []
|
||||
(let [jel-accounts (reduce
|
||||
(fn [acc [e lia]]
|
||||
@@ -444,6 +452,7 @@
|
||||
|
||||
|
||||
|
||||
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
|
||||
(defn spit-csv [columns data ]
|
||||
(csv/write-csv *out*
|
||||
(into [(map name columns)]
|
||||
@@ -451,32 +460,34 @@
|
||||
((apply juxt columns) r )))))
|
||||
|
||||
|
||||
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
|
||||
(defn find-queries [words]
|
||||
(let [obj (s3/list-objects-v2 :bucket-name (:data-bucket env)
|
||||
:prefix (str "queries/"))]
|
||||
(let [concurrent 30
|
||||
output-chan (async/chan)]
|
||||
(async/pipeline-blocking concurrent
|
||||
output-chan
|
||||
(comp
|
||||
(map #(do
|
||||
[(:key %)
|
||||
(str (slurp (:object-content (s3/get-object
|
||||
(let [obj (s3/list-objects-v2 :bucket-name (:data-bucket env)
|
||||
:prefix (str "queries/"))
|
||||
concurrent 30
|
||||
output-chan (async/chan)]
|
||||
(async/pipeline-blocking concurrent
|
||||
output-chan
|
||||
(comp
|
||||
(map #(do
|
||||
[(:key %)
|
||||
(str (slurp (:object-content (s3/get-object
|
||||
:bucket-name (:data-bucket env)
|
||||
:key (:key %)))))]))
|
||||
|
||||
(filter #(->> words
|
||||
(every? (fn [w] (str/includes? (second %) w)))))
|
||||
(map first)
|
||||
(map #(str/replace % #"queries/" ""))
|
||||
)
|
||||
(async/to-chan (:object-summaries obj))
|
||||
true
|
||||
(fn [e]
|
||||
(println "failed " e)))
|
||||
(async/<!! (async/into [] output-chan)))))
|
||||
|
||||
(filter #(->> words
|
||||
(every? (fn [w] (str/includes? (second %) w)))))
|
||||
(map first)
|
||||
(map #(str/replace % #"queries/" ""))
|
||||
)
|
||||
(async/to-chan! (:object-summaries obj))
|
||||
true
|
||||
(fn [e]
|
||||
(println "failed " e)))
|
||||
(async/<!! (async/into [] output-chan))))
|
||||
|
||||
|
||||
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
|
||||
(defn historical-load-sales [client-code days]
|
||||
(let [client (d/pull (d/db auto-ap.datomic/conn)
|
||||
square/square-read
|
||||
@@ -508,6 +519,7 @@
|
||||
|
||||
(square/upsert-settlements client square-location)))))
|
||||
|
||||
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
|
||||
(defn load-sales-for-day [date]
|
||||
(doseq [client (d/q [:find [(list 'pull '?e square/square-read ) '...]
|
||||
:where ['?e :client/square-locations ]]
|
||||
@@ -537,7 +549,7 @@
|
||||
]))
|
||||
(into {}))]
|
||||
(->>
|
||||
(for [[invoice-id invoice-expense-account-id target-account target-date amount expense-account location] (drop 1 data)
|
||||
(for [[invoice-id invoice-expense-account-id target-account target-date amount _ location] (drop 1 data)
|
||||
:let [
|
||||
invoice-id (Long/parseLong invoice-id)
|
||||
|
||||
@@ -567,7 +579,7 @@
|
||||
target-expense-account-location location
|
||||
|
||||
|
||||
[[payment-id payment-amount invoice-payment]] (vec (d/q
|
||||
[[_ _ invoice-payment]] (vec (d/q
|
||||
'[:find ?p ?a ?ip
|
||||
:in $ ?i
|
||||
:where [?ip :invoice-payment/invoice ?i]
|
||||
@@ -613,6 +625,7 @@
|
||||
vec)))
|
||||
|
||||
|
||||
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
|
||||
(defn get-schema [prefix]
|
||||
(->> (d/q '[:find ?i
|
||||
:in $ ?p
|
||||
@@ -621,6 +634,7 @@
|
||||
(mapcat identity)
|
||||
vec))
|
||||
|
||||
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
|
||||
(defn get-idents []
|
||||
(->> (d/q '[:find ?i
|
||||
:in $
|
||||
@@ -631,6 +645,7 @@
|
||||
(sort)
|
||||
vec))
|
||||
|
||||
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
|
||||
(defn init-repl []
|
||||
(set! nrepl.middleware.print/*print-fn* clojure.pprint/pprint))
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
(ns auto-ap.client-routes
|
||||
(:require [bidi.bidi :as bidi]))
|
||||
(ns auto-ap.client-routes)
|
||||
|
||||
(def routes ["/" {"" :index
|
||||
"login/" :login
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
(ns auto-ap.entities.account
|
||||
(:require [clojure.spec.alpha :as s]
|
||||
[clojure.string :as str]
|
||||
[auto-ap.entities.shared :as shared]))
|
||||
|
||||
(s/def ::account-set string?)
|
||||
(s/def ::numeric-code (s/or :numeric-string? (s/and string?
|
||||
#(re-matches shared/numeric-regex %))
|
||||
:numeric? int?))
|
||||
(s/def ::name string?)
|
||||
(s/def ::location (s/nilable (s/and string?
|
||||
#(re-matches shared/only-upper-case %))))
|
||||
(s/def ::type #{:dividend :expense :asset :liability :equity :revenue})
|
||||
|
||||
(s/def ::account (s/keys :req-un [::account-set ::numeric-code ::name ::type ::location]))
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
(ns auto-ap.entities.address
|
||||
(:require [clojure.spec.alpha :as s]
|
||||
[clojure.string :as str]))
|
||||
|
||||
(s/def ::street1 (s/nilable string?))
|
||||
(s/def ::street2 (s/nilable string?))
|
||||
(s/def ::city (s/nilable string?))
|
||||
(s/def ::state (s/nilable (s/or
|
||||
:empty (s/and string? #{""})
|
||||
:filled (s/and string?
|
||||
#(re-matches #"[a-zA-Z]{2}" %)))))
|
||||
(s/def ::zip (s/nilable string?))
|
||||
|
||||
(s/def ::address (s/keys :opt-un [::email
|
||||
::street1
|
||||
::street2
|
||||
::city
|
||||
::state
|
||||
::zip]))
|
||||
@@ -1,58 +0,0 @@
|
||||
(ns auto-ap.entities.clients
|
||||
(:require [clojure.spec.alpha :as s]
|
||||
[auto-ap.entities.shared :as shared]
|
||||
[clojure.string :as str]
|
||||
[auto-ap.entities.address :as address]))
|
||||
|
||||
(def email-regex #"^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,63}$")
|
||||
(s/def ::id int)
|
||||
|
||||
(s/def ::name ::shared/required-identifier)
|
||||
(s/def ::code (s/and ::shared/required-identifier
|
||||
#(re-matches #"[A-Z0-9\-]+" %)))
|
||||
(s/def ::address (s/nilable ::address/address))
|
||||
|
||||
(s/def ::bank-name ::shared/required-identifier)
|
||||
(s/def ::bank-code (s/nilable string?))
|
||||
(s/def ::routing (s/nilable string?))
|
||||
(s/def ::number ::shared/required-identifier)
|
||||
(s/def ::type keyword?)
|
||||
(s/def ::number string?)
|
||||
(s/def ::yodlee-account-id string?)
|
||||
|
||||
(s/def ::checking-bank-account (s/and (s/keys :req-un [::code ::name ::bank-name ::number ::type]
|
||||
:opt-un [::bank-code ::routing])
|
||||
#(= (:type %) :check)))
|
||||
|
||||
(s/def ::credit-account (s/and (s/keys :req-un [::code ::name ::bank-name ::number ::type]
|
||||
:opt-un [])
|
||||
#(= (:type %) :credit)))
|
||||
|
||||
(s/def ::cash-account (s/and (s/keys :req-un [::type ::code ::name])
|
||||
#(= (:type %) :cash)))
|
||||
(s/def ::bank-account (s/or :cash ::cash-account
|
||||
:checking ::checking-bank-account
|
||||
:credit ::credit-account))
|
||||
(s/def ::bank-accounts (s/coll-of ::bank-account))
|
||||
;; disabled because graphql defaults to string representation
|
||||
#_(s/def ::weekly-debits (s/nilable double?))
|
||||
#_(s/def ::weekly-credits (s/nilable double?))
|
||||
|
||||
(s/def ::location string?)
|
||||
(s/def ::locations (s/coll-of ::location :min-count 1))
|
||||
|
||||
(s/def ::email (s/nilable (s/and string? (s/or :is-email #(re-matches email-regex %)
|
||||
:is-empty #(= % "")))))
|
||||
|
||||
|
||||
(s/def ::client (s/keys :req-un [::name ::code ::locations]
|
||||
:opt-un [::email
|
||||
::address
|
||||
#_::weekly-debits
|
||||
#_::weekely-credits
|
||||
::bank-accounts
|
||||
::id]))
|
||||
|
||||
|
||||
(def client-spec (apply hash-map (drop 1 (s/form ::client))))
|
||||
(def all-keys (map #(keyword (name %)) (concat (:req-un client-spec) (:opt-un client-spec))))
|
||||
@@ -1,14 +0,0 @@
|
||||
(ns auto-ap.entities.contact
|
||||
(:require [clojure.spec.alpha :as s]
|
||||
[clojure.string :as str]
|
||||
[auto-ap.entities.address :as address]))
|
||||
|
||||
(def email-regex #"^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,63}$")
|
||||
|
||||
(s/def ::id (s/nilable string?))
|
||||
(s/def ::name (s/nilable string?))
|
||||
(s/def ::email (s/nilable (s/and string? (s/or :is-email #(re-matches email-regex %)
|
||||
:is-empty #(= % "")))))
|
||||
(s/def ::phone (s/nilable string?))
|
||||
|
||||
(s/def ::contact (s/keys :opt-un [::name ::email ::phone ::id]))
|
||||
@@ -1,5 +0,0 @@
|
||||
(ns auto-ap.entities.invoice
|
||||
(:require [clojure.spec.alpha :as s]
|
||||
[auto-ap.entities.shared :as shared]))
|
||||
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
(ns auto-ap.entities.invoices-expense-accounts
|
||||
(:require [clojure.spec.alpha :as s]
|
||||
[clojure.string :as str]
|
||||
[auto-ap.entities.shared :as shared]))
|
||||
|
||||
(s/def ::vendor-id string?)
|
||||
(s/def ::account-id string?)
|
||||
(s/def ::amount ::shared/money)
|
||||
(s/def ::location string?)
|
||||
|
||||
(s/def ::invoices-expense-account (s/keys :opt-un [::vendor-id ::account-id ::amount ::location]))
|
||||
@@ -1,31 +1,2 @@
|
||||
(ns auto-ap.entities.shared
|
||||
(:require [clojure.spec.alpha :as s]
|
||||
[clojure.string :as str]
|
||||
))
|
||||
(ns auto-ap.entities.shared)
|
||||
|
||||
(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 numeric-regex #"^[0-9]+$")
|
||||
(def only-upper-case #"^[A-Z]+$")
|
||||
|
||||
(s/def ::identifier (s/nilable string?))
|
||||
(s/def ::date
|
||||
#?(:cljs
|
||||
(s/or :dt? #(instance? goog.date.DateTime %)
|
||||
:d? #(instance? goog.date.Date %)
|
||||
:str? (s/and string? #(re-matches date-regex %)))
|
||||
:clj (s/or :dt? #(instance? org.joda.time.DateTime %)
|
||||
:ldt? #(instance? org.joda.time.LocalDateTime %)
|
||||
:ldt? #(instance? org.joda.time.LocalDate %)
|
||||
:str? (s/and string? #(re-matches date-regex %)))))
|
||||
|
||||
(s/def ::required some?)
|
||||
(s/def ::has-id (s/and map?
|
||||
#(:id %)))
|
||||
(s/def ::required-identifier (s/and string?
|
||||
#(not (str/blank? %))))
|
||||
|
||||
(s/def ::money (s/or :string (s/and string?
|
||||
#(re-matches money-regex %))
|
||||
:float float?
|
||||
:int int?))
|
||||
|
||||
@@ -1,43 +0,0 @@
|
||||
(ns auto-ap.entities.transaction-rule
|
||||
(:require [auto-ap.entities.transaction-rule-account :as transaction-rule-account]
|
||||
[clojure.spec.alpha :as s]
|
||||
[clojure.string :as str]))
|
||||
|
||||
(s/def ::client (s/nilable map?))
|
||||
(s/def ::description (s/nilable (s/and string?
|
||||
#( #?@(:clj (try
|
||||
(re-pattern %)
|
||||
true
|
||||
(catch Exception _
|
||||
false))
|
||||
:cljs (try
|
||||
(re-pattern %)
|
||||
true
|
||||
(catch js/Error _
|
||||
false)))))))
|
||||
(s/def ::amount-gte (s/or :double (s/nilable double?)
|
||||
:string (s/nilable string?)))
|
||||
(s/def ::amount-lte (s/or :double (s/nilable double?)
|
||||
:string (s/nilable string?)))
|
||||
(s/def ::dom-gte (s/nilable int?))
|
||||
(s/def ::dom-lte (s/nilable int?))
|
||||
(s/def ::note (s/nilable string?))
|
||||
(s/def ::bank-account (s/nilable map?))
|
||||
(s/def ::vendor (s/nilable map?))
|
||||
(s/def ::yodlee-merchant (s/nilable map?))
|
||||
(s/def ::accounts (s/coll-of ::transaction-rule-account/transaction-rule-account :min-count 1))
|
||||
|
||||
(s/def ::transaction-rule (s/and (s/keys :req-un [::client
|
||||
::description
|
||||
::amount-gte
|
||||
::amount-lte
|
||||
::dom-gte
|
||||
::dom-lte
|
||||
::note
|
||||
::bank-account
|
||||
::vendor
|
||||
::accounts]
|
||||
:opt-un [::yodlee-merchant])
|
||||
|
||||
(s/or :description-required #(not (str/blank? (:description %)))
|
||||
:merchant-required #(not (nil? (:yodlee-merchant %))))))
|
||||
@@ -1,13 +0,0 @@
|
||||
(ns auto-ap.entities.transaction-rule-account
|
||||
(:require [clojure.spec.alpha :as s]
|
||||
[clojure.string :as str]))
|
||||
|
||||
|
||||
|
||||
(s/def ::account map?)
|
||||
(s/def ::location (s/and string?
|
||||
not-empty))
|
||||
|
||||
(s/def ::transaction-rule-account (s/keys :req-un [::account
|
||||
::location]
|
||||
:opt-un []))
|
||||
@@ -1,43 +0,0 @@
|
||||
(ns auto-ap.entities.vendors
|
||||
(:require [clojure.spec.alpha :as s]
|
||||
[clojure.string :as str]
|
||||
[auto-ap.entities.contact :as contact]
|
||||
[auto-ap.entities.address :as address]))
|
||||
|
||||
(s/def ::id string?)
|
||||
(s/def ::identifier (s/nilable string?)) (s/def ::required-identifier (s/and string?
|
||||
#(not (str/blank? %))))
|
||||
|
||||
(s/def ::name ::required-identifier)
|
||||
(s/def ::hidden boolean?)
|
||||
(s/def ::print-as (s/nilable string?))
|
||||
(s/def ::terms (s/nilable int?))
|
||||
(s/def ::dom (s/nilable int?))
|
||||
|
||||
(s/def ::invoice-reminder-schedule (s/nilable #{"Weekly" "Never" nil}))
|
||||
|
||||
(s/def ::primary-contact (s/nilable ::contact/contact))
|
||||
(s/def ::secondary-contact (s/nilable ::contact/contact))
|
||||
(s/def ::address (s/nilable ::address/address))
|
||||
(s/def ::default-account-id (s/nilable string?))
|
||||
|
||||
(s/def ::code (s/nilable string?))
|
||||
|
||||
(s/def ::vendor (s/and
|
||||
(s/keys :req-un [::name]
|
||||
:opt-un [::code
|
||||
::default-account-id
|
||||
::terms
|
||||
::hidden
|
||||
::id
|
||||
::print-as
|
||||
::primary-contact
|
||||
::secondary-contact
|
||||
::address])
|
||||
|
||||
(s/or :hidden #(= (:hidden %) true)
|
||||
:has-expense-account #(not (nil? (:id (:default-account %)))))))
|
||||
|
||||
|
||||
(def vendor-spec (apply hash-map (drop 1 (s/form ::vendor))))
|
||||
(def all-keys (map #(keyword (name %)) (concat (:req-un vendor-spec) (:opt-un vendor-spec))))
|
||||
@@ -1,18 +1,20 @@
|
||||
(ns auto-ap.effects
|
||||
(:require-macros [cljs.core.async.macros :refer [go]])
|
||||
(:require [re-frame.core :as re-frame]
|
||||
[cljs-http.client :as http]
|
||||
[cljs-time.coerce :as c]
|
||||
[cljs-time.core :as time]
|
||||
[cljs-time.format :as format]
|
||||
[cljs.core.async :refer [<! ] :as async]
|
||||
[clojure.string :as str]
|
||||
[clojure.walk :as walk]
|
||||
[venia.core :as v]
|
||||
[auto-ap.history :as p]
|
||||
[auto-ap.views.utils :refer [date->str standard]]
|
||||
[auto-ap.status :as status]
|
||||
[pushy.core :as pushy]))
|
||||
(:require
|
||||
[auto-ap.history :as p]
|
||||
[auto-ap.status :as status]
|
||||
[auto-ap.views.utils :refer [date->str standard]]
|
||||
[cemerick.url :as url]
|
||||
[cljs-http.client :as http]
|
||||
[cljs-time.coerce :as c]
|
||||
[cljs-time.core :as time]
|
||||
[cljs-time.format :as format]
|
||||
[cljs.core.async :refer [<!] :as async]
|
||||
[clojure.string :as str]
|
||||
[clojure.walk :as walk]
|
||||
[pushy.core :as pushy]
|
||||
[re-frame.core :as re-frame]
|
||||
[venia.core :as v]))
|
||||
|
||||
(re-frame/reg-fx
|
||||
:redirect
|
||||
@@ -26,8 +28,8 @@
|
||||
(pushy/set-token! p/history
|
||||
(str (.-protocol (.-location js/window)) "//" (.-host (.-location js/window)) (.-pathname (.-location js/window))
|
||||
"?"
|
||||
(cemerick.url/map->query (->> uri-params
|
||||
(filter (fn [[k v]] (and v
|
||||
(url/map->query (->> uri-params
|
||||
(filter (fn [[_ v]] (and v
|
||||
(or (not (seqable? v))
|
||||
(not-empty v)))) )
|
||||
(map
|
||||
|
||||
@@ -7,17 +7,17 @@
|
||||
::register
|
||||
(let [process-one-entry (fn [{:as m :keys [id events event-fn]}]
|
||||
(let [_ (assert (map? m) (str "re-frame: effects handler for :forward-events expected a map or a list of maps. Got: " m))
|
||||
_ (assert (= #{:id :events :event-fn} (-> m keys set)) (str "re-frame: effects handler for :forward-events given wrong map keys" (-> m keys set)))]
|
||||
(let [post-event-callback-fn (fn [event-v _]
|
||||
(when (events (first event-v))
|
||||
(re-frame/dispatch (event-fn event-v))))]
|
||||
(re-frame/add-post-event-callback post-event-callback-fn)
|
||||
(swap! id->listen-fn assoc id post-event-callback-fn))))]
|
||||
_ (assert (= #{:id :events :event-fn} (-> m keys set)) (str "re-frame: effects handler for :forward-events given wrong map keys" (-> m keys set)))
|
||||
post-event-callback-fn (fn [event-v _]
|
||||
(when (events (first event-v))
|
||||
(re-frame/dispatch (event-fn event-v))))]
|
||||
(re-frame/add-post-event-callback post-event-callback-fn)
|
||||
(swap! id->listen-fn assoc id post-event-callback-fn)))]
|
||||
(fn [val]
|
||||
(cond
|
||||
(map? val) (process-one-entry val)
|
||||
(sequential? val) (doall (map process-one-entry val))
|
||||
:else (re-frame/console :error ":forward-events expected a map or a list of maps, but got: " val)))))
|
||||
:else (re-frame/console :error ":forward-events expected a map or a list of maps, but got: " val)))))
|
||||
|
||||
|
||||
|
||||
@@ -25,11 +25,11 @@
|
||||
::dispose
|
||||
(let [process-one-entry (fn [{:as m :keys [id]}]
|
||||
(let [_ (assert (map? m) (str "re-frame: effects handler for :forward-events expected a map or a list of maps. Got: " m))
|
||||
_ (assert (= #{:id} (-> m keys set)) (str "re-frame: effects handler for :forward-events given wrong map keys" (-> m keys set)))]
|
||||
(let [f (@id->listen-fn id)
|
||||
_ (assert (some? f) (str ":forward-events asked to unregister an unknown id: " id))]
|
||||
(re-frame/remove-post-event-callback f)
|
||||
(swap! id->listen-fn dissoc id))))]
|
||||
_ (assert (= #{:id} (-> m keys set)) (str "re-frame: effects handler for :forward-events given wrong map keys" (-> m keys set)))
|
||||
f (@id->listen-fn id)
|
||||
_ (assert (some? f) (str ":forward-events asked to unregister an unknown id: " id))]
|
||||
(re-frame/remove-post-event-callback f)
|
||||
(swap! id->listen-fn dissoc id)))]
|
||||
(fn [val]
|
||||
(cond
|
||||
(map? val) (process-one-entry val)
|
||||
|
||||
@@ -3,12 +3,12 @@
|
||||
[auto-ap.db :as db]
|
||||
[auto-ap.routes :as routes]
|
||||
[auto-ap.utils :refer [by]]
|
||||
[auto-ap.views.utils :refer [with-user parse-jwt]]
|
||||
[auto-ap.views.pages.data-page :as data-page]
|
||||
[auto-ap.views.utils :refer [parse-jwt with-user]]
|
||||
[bidi.bidi :as bidi]
|
||||
[clojure.string :as str]
|
||||
[goog.crypt.base64 :as b64]
|
||||
[re-frame.core :as re-frame]
|
||||
[goog.crypt.base64 :as base64]))
|
||||
[re-frame.core :as re-frame]))
|
||||
|
||||
(defn jwt->data [token]
|
||||
(js->clj (.parse js/JSON (b64/decodeString (second (str/split token #"\." ))))))
|
||||
@@ -131,14 +131,6 @@
|
||||
(.setItem js/localStorage "last-client-id" (:id client))
|
||||
(assoc db :client (:id client))))
|
||||
|
||||
(re-frame/reg-event-db
|
||||
::change-form
|
||||
(fn [db [_ location field value]]
|
||||
(if value
|
||||
(assoc-in db (into location field) value)
|
||||
(update-in db (into location (butlast field)) dissoc (last field)))))
|
||||
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::set-active-route
|
||||
(fn [{:keys [db]} [_ handler params route-params]]
|
||||
@@ -164,7 +156,7 @@
|
||||
:menu nil
|
||||
:query-params params
|
||||
:route-params route-params)
|
||||
(auto-ap.views.pages.data-page/dispose-all))})))
|
||||
(data-page/dispose-all))})))
|
||||
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
|
||||
@@ -105,7 +105,7 @@
|
||||
|
||||
(re-frame/reg-event-db
|
||||
::attempted-submit
|
||||
(fn [db [_ form & paths]]
|
||||
(fn [db [_ form ]]
|
||||
(assoc-in db [::forms form :attempted-submit?] true)))
|
||||
|
||||
(defn change-handler [form customize-fn]
|
||||
@@ -154,16 +154,17 @@
|
||||
|
||||
(defn triggers-loading [form]
|
||||
(re-frame/enrich
|
||||
(fn [db event]
|
||||
(fn [db _]
|
||||
(loading db form))))
|
||||
|
||||
(defn triggers-stop [form]
|
||||
(re-frame/enrich
|
||||
(fn [db event]
|
||||
(fn [db _]
|
||||
(stop-form db form))))
|
||||
|
||||
(defn triggers-stop-loading [form]
|
||||
(re-frame/enrich
|
||||
(fn [db event]
|
||||
(fn [db _]
|
||||
(assoc-in db [::forms form :status] nil))))
|
||||
|
||||
(defn save-succeeded [db id]
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
{:errors (merge (-> me/default-errors
|
||||
(assoc ::m/missing-key {:error/message "Required"}
|
||||
::m/invalid-type {:error/fn
|
||||
(fn [a b]
|
||||
(fn [a _]
|
||||
(if (nil? (:value a))
|
||||
"Required"
|
||||
"Invalid"))}))
|
||||
@@ -210,7 +210,7 @@
|
||||
(r/as-element (into [:<>]
|
||||
(r/children (r/current-component))))))
|
||||
|
||||
(defn vertical-control [{:keys [is-small? required?]}]
|
||||
(defn vertical-control [{:keys [required?]}]
|
||||
(let [[label & children] (r/children (r/current-component))]
|
||||
(consume Consumer
|
||||
["fullwidth?"]
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
[pushy.core :as pushy]
|
||||
[auto-ap.routes :as routes]
|
||||
[auto-ap.views.utils :as u]
|
||||
[cemerick.url :refer [url]]
|
||||
[re-frame.core :as re-frame]))
|
||||
|
||||
(defn parse-url [url]
|
||||
|
||||
@@ -109,7 +109,7 @@
|
||||
(re-frame/reg-event-db
|
||||
::completed
|
||||
[(re-frame/path [::status]) ]
|
||||
(fn [db [_ single which]]
|
||||
(fn [db [_ single _]]
|
||||
(assoc db single {:state nil
|
||||
:error nil})))
|
||||
|
||||
@@ -135,21 +135,19 @@
|
||||
info-states
|
||||
(->> states (filter #(:info %)))]
|
||||
[:<>
|
||||
(if (seq error-states)
|
||||
(when (seq error-states)
|
||||
[:div.notification.is-danger.is-light
|
||||
(for [state states
|
||||
state (:error state)]
|
||||
(do
|
||||
^{:key (:message state)}
|
||||
[:p (or (:message state)
|
||||
(:error state)
|
||||
"An unexpected error occured.")]))])
|
||||
(if (seq info-states)
|
||||
^{:key (:message state)}
|
||||
[:p (or (:message state)
|
||||
(:error state)
|
||||
"An unexpected error occured.")])])
|
||||
(when (seq info-states)
|
||||
[:div.notification.is-info.is-light
|
||||
(for [state states]
|
||||
(do
|
||||
^{:key (:info state)}
|
||||
[:p (:info state)]))])]))
|
||||
^{:key (:info state)}
|
||||
[:p (:info state)])])]))
|
||||
|
||||
(defn big-loader [status]
|
||||
(when (= :loading (:state status))
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
(ns auto-ap.views.components.address
|
||||
(:require
|
||||
[auto-ap.entities.address :as address]
|
||||
[auto-ap.forms.builder :as form-builder]
|
||||
[auto-ap.views.components.level :as level]))
|
||||
|
||||
@@ -20,8 +19,7 @@
|
||||
[:p.help "City"]
|
||||
[:input.input.is-expanded {:type "text"
|
||||
:placeholder "Cupertino"
|
||||
:field [:city]
|
||||
:spec ::address/city}]]
|
||||
:field [:city]}]]
|
||||
[form-builder/field-v2 {:field :state}
|
||||
[:p.help "State"]
|
||||
[:input.input {:type "text"
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
[re-frame.core :as re-frame]
|
||||
[reagent.core :as r]))
|
||||
|
||||
(defn admin-side-bar [params ]
|
||||
(defn admin-side-bar []
|
||||
(let [ap @(re-frame/subscribe [::subs/active-page])]
|
||||
[:div
|
||||
[:p.menu-label "General"]
|
||||
@@ -45,12 +45,6 @@
|
||||
[:a {:href (bidi/path-for routes/routes :admin-rules), :class (str "item" (active-when ap = :admin-rules))}
|
||||
[:span {:class "icon icon-cog-play-1" :style {:font-size "25px"}}]
|
||||
[:span {:class "name"} "Rules"]]]
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
[:ul ]]
|
||||
[:p.menu-label "Import"]
|
||||
[:ul.menu-list
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
(:require [auto-ap.views.utils :refer [dispatch-event]]
|
||||
[reagent.core :as r]))
|
||||
|
||||
(defn fa-icon [{:keys [event icon class on-click] :as params}]
|
||||
(defn fa-icon [{:keys [event icon on-click] :as params}]
|
||||
[:a.button (cond-> params
|
||||
true (dissoc :event :icon)
|
||||
(and (not on-click)
|
||||
@@ -15,7 +15,7 @@
|
||||
|
||||
|
||||
|
||||
(defn sl-icon [{:keys [event icon class on-click] :as params}]
|
||||
(defn sl-icon [{:keys [event icon on-click] :as params}]
|
||||
[:a.button (cond-> params
|
||||
true (dissoc :event :icon)
|
||||
(and (not on-click)
|
||||
@@ -28,7 +28,7 @@
|
||||
[:span.icon [:i.fa.fa-plus]]
|
||||
[:span name]])
|
||||
|
||||
(defn dropdown [{:keys [event icon class on-click] :as params}]
|
||||
(defn dropdown [{:keys [event on-click] :as params}]
|
||||
[:a.button (cond-> params
|
||||
true (dissoc :event :icon)
|
||||
(and (not on-click)
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
[re-frame.core :as re-frame]
|
||||
[auto-ap.subs :as subs]))
|
||||
|
||||
(defn drop-down-contents [{:keys [id]} children ]
|
||||
(defn drop-down-contents [{:keys [id]}]
|
||||
(let [toggle-fn (fn [] (re-frame/dispatch [::events/toggle-menu id]))]
|
||||
(r/create-class {:component-did-mount (fn [] (.addEventListener js/document "click" toggle-fn))
|
||||
:component-will-unmount (fn [] (.removeEventListener js/document "click" toggle-fn))
|
||||
@@ -13,8 +13,8 @@
|
||||
(fn [children]
|
||||
children)})))
|
||||
|
||||
(defn drop-down [{:keys [ header id is-right? class]} child]
|
||||
(let [menu-active? (re-frame/subscribe [::subs/menu-active? id])]
|
||||
(defn drop-down [{:keys [ id ]} _]
|
||||
(let [_ (re-frame/subscribe [::subs/menu-active? id])]
|
||||
(r/create-class
|
||||
{:reagent-render (fn [{:keys [header id is-right? class] :or {is-right? true}} child]
|
||||
(let [menu-active? @(re-frame/subscribe [::subs/menu-active? id])]
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
(ns auto-ap.views.components.grid
|
||||
(:require [reagent.core :as r]
|
||||
[auto-ap.views.utils :refer [appearing copy-to-clipboard]]
|
||||
[auto-ap.utils :refer [default-pagination-size]]
|
||||
[react :as react]
|
||||
[re-frame.core :as re-frame]
|
||||
[auto-ap.views.pages.data-page :as data-page]
|
||||
[auto-ap.views.components.buttons :as buttons]
|
||||
[auto-ap.subs :as subs]
|
||||
[react-dom :as react-dom]))
|
||||
(:require
|
||||
[auto-ap.subs :as subs]
|
||||
[auto-ap.utils :refer [default-pagination-size]]
|
||||
[auto-ap.views.pages.data-page :as data-page]
|
||||
[auto-ap.views.utils :refer [copy-to-clipboard]]
|
||||
[re-frame.core :as re-frame]
|
||||
[react :as react]
|
||||
[reagent.core :as r]))
|
||||
|
||||
(set! *warn-on-infer* true)
|
||||
|
||||
(defonce ^js/React.Context grid-context ( react/createContext "default"))
|
||||
@@ -60,7 +60,7 @@
|
||||
:else
|
||||
y))
|
||||
|
||||
(defn paginator [{:keys [start per-page end count total on-change] :as g}]
|
||||
(defn paginator [{:keys [start per-page end total on-change]}]
|
||||
(let [per-page (or per-page default-pagination-size)
|
||||
max-buttons 5
|
||||
buttons-before (Math/floor (/ max-buttons 2))
|
||||
@@ -72,7 +72,7 @@
|
||||
[:li
|
||||
[:a.pagination-link {:class (when (= current-page x)
|
||||
"is-current")
|
||||
:on-click (fn [e] (on-change {:start (* x per-page)
|
||||
:on-click (fn [_] (on-change {:start (* x per-page)
|
||||
:per-page per-page}))}
|
||||
(inc x)]]))
|
||||
|
||||
@@ -117,11 +117,11 @@
|
||||
[:a.tag.is-medium.is-delete {:on-click (fn []
|
||||
(on-change {:sort (filter #(not= sort-key (:sort-key %)) sort)}))}]]])])
|
||||
|
||||
(defn controls [{:keys [start end count total per-page action-buttons] :as para}]
|
||||
(defn controls [{:keys [start end count total action-buttons]}]
|
||||
(let [children (r/children (r/current-component))]
|
||||
[:> Consumer {}
|
||||
(fn [consume]
|
||||
(let [{:strs [on-params-change params] :as consume} (js->clj consume)]
|
||||
(let [{:strs [on-params-change params]} (js->clj consume)]
|
||||
(r/as-element (into
|
||||
[:div {:style {:margin-bottom "1rem"}}
|
||||
[:div.level
|
||||
@@ -174,8 +174,8 @@
|
||||
:checked (if (get checked id)
|
||||
"checked"
|
||||
"")
|
||||
:on-change (fn [x e]
|
||||
(if id
|
||||
:on-change (fn [_ _]
|
||||
(when id
|
||||
(let [checked (or checked #{})]
|
||||
;; TODO only map once everything is moved over to data-page
|
||||
(if (map? checked)
|
||||
@@ -199,7 +199,7 @@
|
||||
]])))
|
||||
(map r/as-element children))))]))
|
||||
|
||||
(defn button-cell [params]
|
||||
(defn button-cell []
|
||||
(apply r/create-element "td" #js {"style" #js {"overflow" "visible"}}
|
||||
(map r/as-element (r/children (r/current-component)))))
|
||||
|
||||
@@ -244,13 +244,13 @@
|
||||
|
||||
children)))))]))
|
||||
|
||||
(defn sortable-header-cell [{:keys [style class sort-key sort-name asc]}]
|
||||
(defn sortable-header-cell [{:keys [style class sort-key sort-name]}]
|
||||
(let [children (r/children (r/current-component))]
|
||||
[:> Consumer {}
|
||||
(fn [consume]
|
||||
(let [{:strs [on-params-change params] :as consume} (js->clj consume)]
|
||||
(let [{:strs [on-params-change params]} (js->clj consume)]
|
||||
(r/as-element (conj (into
|
||||
[:th {:on-click (fn [e]
|
||||
[:th {:on-click (fn [_]
|
||||
(on-params-change
|
||||
(toggle-sort-by {:sort (:sort params)} sort-key sort-name)))
|
||||
:style (assoc style
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
:ref (fn [n]
|
||||
(reset! !child n))
|
||||
:tab-index 0
|
||||
:onBlur (fn [e]
|
||||
:onBlur (fn [_]
|
||||
(js/setTimeout (fn []
|
||||
(println @!child)
|
||||
(println (.-activeElement js/document))
|
||||
@@ -120,7 +120,7 @@
|
||||
(re-frame/dispatch [::events/swap-client client]))
|
||||
} name])]]))
|
||||
|
||||
(defn navbar [ap]
|
||||
(defn navbar []
|
||||
(let [navbar-menu-shown? (r/atom false)]
|
||||
(fn [ap]
|
||||
(let [user (re-frame/subscribe [::subs/user])
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
(ns auto-ap.views.components.modal
|
||||
(:require [re-frame.core :as re-frame]
|
||||
[reagent.core :as r]
|
||||
[auto-ap.events :as events]
|
||||
[auto-ap.subs :as subs]
|
||||
[auto-ap.status :as status]
|
||||
[auto-ap.views.utils :refer [with-keys appearing dispatch-event]]))
|
||||
(:require
|
||||
[auto-ap.status :as status]
|
||||
[auto-ap.views.utils :refer [appearing dispatch-event]]
|
||||
[re-frame.core :as re-frame]))
|
||||
|
||||
(re-frame/reg-sub
|
||||
::modal-state
|
||||
@@ -18,7 +16,7 @@
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::modal-closed
|
||||
(fn [{:keys [db]} [_ state]]
|
||||
(fn [{:keys [db]} [_ _]]
|
||||
(let [[_ status-id] (some-> db ::state :confirm :status-from )]
|
||||
(cond-> {:db (dissoc db ::state)}
|
||||
status-id (assoc :dispatch [::status/completed status-id])))))
|
||||
@@ -27,7 +25,7 @@
|
||||
(defn global-modal []
|
||||
(let [state (re-frame/subscribe [::modal-state])]
|
||||
(fn []
|
||||
(if (:visible? @state)
|
||||
(when (:visible? @state)
|
||||
(let [{:keys [title body status-from foot class cancel? confirm]} @state]
|
||||
[:div.modal.is-active (cond-> {}
|
||||
class (assoc :class class))
|
||||
|
||||
@@ -1,16 +1,13 @@
|
||||
(ns auto-ap.views.components.multi
|
||||
(:require
|
||||
[cemerick.url]
|
||||
#_{:clj-kondo/ignore [:unused-namespace]}
|
||||
[reagent.core :as reagent]
|
||||
[react :as react]
|
||||
[auto-ap.entities.shared :as shared]
|
||||
[auto-ap.views.utils :refer [appearing-group]]
|
||||
[auto-ap.forms.builder :as form-builder]))
|
||||
|
||||
|
||||
;; TODO just embrace the fact that it will need to be remounted, and use index based keys
|
||||
(defn multi-field-v2-internal [{:keys [template key-fn allow-change? disable-new? disable-remove? schema on-change disabled new-text] prop-value :value :as props} ]
|
||||
(defn multi-field-v2-internal [{:keys [template key-fn allow-change? disable-new? disable-remove? schema on-change disabled new-text] prop-value :value } ]
|
||||
(let [prop-value (if (seq prop-value)
|
||||
(vec prop-value)
|
||||
[])]
|
||||
|
||||
@@ -1,55 +0,0 @@
|
||||
(ns auto-ap.views.components.paginator
|
||||
(:require [re-frame.core :as re-frame]
|
||||
[auto-ap.subs :as subs]
|
||||
[auto-ap.views.utils :refer [date->str]]
|
||||
[reagent.core :as reagent]
|
||||
[clojure.string :as str]
|
||||
[cljs-time.format :as format]))
|
||||
|
||||
|
||||
(defn bound [x y z]
|
||||
(cond
|
||||
(< z x)
|
||||
x
|
||||
(< y x)
|
||||
x
|
||||
(> y z)
|
||||
z
|
||||
:else
|
||||
y))
|
||||
|
||||
(defn paginator [{:keys [start end count total on-change]}]
|
||||
(let [per-page 100
|
||||
max-buttons 5
|
||||
buttons-before (Math/floor (/ max-buttons 2))
|
||||
total-pages (Math/ceil (/ total per-page))
|
||||
current-page (Math/floor (/ start per-page))
|
||||
first-page-button (bound 0 (- current-page buttons-before) (- total-pages max-buttons))
|
||||
all-buttons (into [] (for [x (range total-pages)]
|
||||
^{:key x}
|
||||
[:li
|
||||
[:a.pagination-link {:class (when (= current-page x)
|
||||
"is-current")
|
||||
:on-click (fn [e] (on-change {:start (* x per-page)}))}
|
||||
(inc x)]]))
|
||||
|
||||
|
||||
last-page-button (Math/min total-pages (+ max-buttons first-page-button))
|
||||
|
||||
extended-last-page-button (when (not= last-page-button total-pages)
|
||||
(list
|
||||
^ {:key -1} [:li [:span.pagination-ellipsis "…"]]
|
||||
^ {:key -2} (last all-buttons)))
|
||||
|
||||
extended-first-page-button (when (not= first-page-button 0)
|
||||
(list
|
||||
^{:key -1} (first all-buttons)
|
||||
^{:key -2} [:li [:span.pagination-ellipsis "…"]]))]
|
||||
|
||||
|
||||
[:nav.pagination {:role "pagination"}
|
||||
[:ul.pagination-list
|
||||
extended-first-page-button
|
||||
(apply list (subvec all-buttons first-page-button last-page-button))
|
||||
extended-last-page-button
|
||||
"Showing " (Math/min (inc start) total) "-" end "/" total]]))
|
||||
@@ -1,6 +1,5 @@
|
||||
(ns auto-ap.views.components.percentage-field
|
||||
(:require [reagent.core :as r]
|
||||
[auto-ap.views.utils :refer [->short$]]
|
||||
[clojure.string :as str]
|
||||
[react :as react]))
|
||||
(def good-% #"^\d{1,3}$")
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
(ns auto-ap.views.components.sort-by-list
|
||||
(:require [re-frame.core :as re-frame]
|
||||
[auto-ap.subs :as subs]
|
||||
[auto-ap.views.utils :refer [date->str]]
|
||||
[reagent.core :as reagent]
|
||||
[clojure.string :as str]
|
||||
[cljs-time.format :as format]))
|
||||
|
||||
(defn sort-by-list [{:keys [sort on-change]}]
|
||||
[:div.field.is-grouped.is-grouped-multiline
|
||||
(for [{:keys [sort-key sort-name asc]} sort]
|
||||
^{:key sort-key}
|
||||
[:div.control
|
||||
[:div.tags.has-addons
|
||||
[:div.tag.is-medium [:span.icon (if asc
|
||||
[:i.fa.fa-sort-up]
|
||||
[:i.fa.fa-sort-down])]
|
||||
[:span sort-name] ]
|
||||
[:a.tag.is-medium.is-delete {:on-click (fn []
|
||||
(on-change {:sort (filter #(not= sort-key (:sort-key %)) sort)}))}]]])])
|
||||
|
||||
@@ -1,49 +0,0 @@
|
||||
(ns auto-ap.views.components.sorter
|
||||
(:require [re-frame.core :as re-frame]
|
||||
[auto-ap.subs :as subs]
|
||||
[auto-ap.views.utils :refer [date->str]]
|
||||
[reagent.core :as reagent]
|
||||
[clojure.string :as str]
|
||||
[cljs-time.format :as format]))
|
||||
(defn toggle-sort-by [params sort-key sort-name asc]
|
||||
(let [[found? sort] (reduce
|
||||
(fn [[found? sort] sort-item]
|
||||
(if (= sort-key (:sort-key sort-item))
|
||||
[true (conj sort
|
||||
(update sort-item :asc not))]
|
||||
[found? (conj sort sort-item)]))
|
||||
[false []]
|
||||
(:sort params))
|
||||
sort (if found?
|
||||
sort
|
||||
(conj sort {:sort-key sort-key
|
||||
:sort-name sort-name
|
||||
:asc true}))]
|
||||
|
||||
(-> params
|
||||
(assoc :sort sort))))
|
||||
|
||||
(defn sort-icon [which sort asc]
|
||||
(let [sort-item (first (filter #(= which (:sort-key %)) sort))]
|
||||
(cond
|
||||
(and sort-item (:asc sort-item))
|
||||
[:span.icon
|
||||
[:i.fa.fa-sort-up]]
|
||||
|
||||
(and sort-item (not (:asc sort-item)))
|
||||
[:span.icon
|
||||
[:i.fa.fa-sort-down]]
|
||||
|
||||
:else
|
||||
[:span.icon
|
||||
[:i.fa.fa-sort]])))
|
||||
|
||||
|
||||
(defn sorted-column [{:keys [on-sort sort-key sort sort-name asc style class]} & rest]
|
||||
[:th {:on-click (fn [e]
|
||||
(on-sort
|
||||
(toggle-sort-by {:sort sort} sort-key sort-name asc)))
|
||||
:style style
|
||||
:class class}
|
||||
rest
|
||||
(sort-icon sort-key sort asc)])
|
||||
@@ -166,7 +166,7 @@
|
||||
|
||||
|
||||
|
||||
(defn form-content [{:keys [data]}]
|
||||
(defn form-content []
|
||||
(let [is-admin? @(re-frame/subscribe [::subs/is-admin?])
|
||||
clients @(re-frame/subscribe [::subs/client-refs])]
|
||||
[form-builder/builder {:submit-event [::save]
|
||||
|
||||
@@ -1,12 +1,7 @@
|
||||
(ns auto-ap.views.pages.admin
|
||||
(:require-macros [cljs.core.async.macros :refer [go]])
|
||||
(:require [re-frame.core :as re-frame]
|
||||
[reagent.core :as reagent]
|
||||
[auto-ap.subs :as subs]
|
||||
[auto-ap.events :as events]
|
||||
[auto-ap.views.components.admin.side-bar :refer [admin-side-bar]]
|
||||
[auto-ap.views.components.layouts :refer [side-bar-layout]]
|
||||
[auto-ap.views.utils :refer [login-url]]))
|
||||
(:require
|
||||
[auto-ap.views.components.admin.side-bar :refer [admin-side-bar]]
|
||||
[auto-ap.views.components.layouts :refer [side-bar-layout]]))
|
||||
|
||||
(defn admin-page []
|
||||
[side-bar-layout {:side-bar [admin-side-bar {}]
|
||||
|
||||
@@ -1,25 +1,20 @@
|
||||
(ns auto-ap.views.pages.admin.accounts
|
||||
(:require [auto-ap.forms :as forms]
|
||||
[auto-ap.subs :as subs]
|
||||
[auto-ap.utils :refer [replace-by]]
|
||||
[auto-ap.views.components.admin.side-bar :refer [admin-side-bar]]
|
||||
[auto-ap.views.pages.admin.accounts.side-bar :as side-bar]
|
||||
[auto-ap.views.pages.admin.accounts.table :as table]
|
||||
[auto-ap.views.utils :refer [dispatch-event action-cell-width with-user]]
|
||||
[auto-ap.views.components.layouts
|
||||
:refer
|
||||
[appearing-side-bar side-bar-layout]]
|
||||
[auto-ap.views.pages.admin.accounts.form :as account-form]
|
||||
[re-frame.core :as re-frame]
|
||||
[auto-ap.views.components.grid :as grid]
|
||||
[auto-ap.status :as status]
|
||||
[auto-ap.views.components.buttons :as buttons]
|
||||
[reagent.core :as reagent]
|
||||
[clojure.string :as str]
|
||||
[vimsical.re-frame.fx.track :as track]
|
||||
[auto-ap.views.pages.data-page :as data-page]
|
||||
[clojure.set :as set]
|
||||
[auto-ap.effects.forward :as forward]))
|
||||
(:require
|
||||
[auto-ap.effects.forward :as forward]
|
||||
[auto-ap.forms :as forms]
|
||||
[auto-ap.views.components.admin.side-bar :refer [admin-side-bar]]
|
||||
[auto-ap.views.components.buttons :as buttons]
|
||||
[auto-ap.views.components.layouts
|
||||
:refer [appearing-side-bar side-bar-layout]]
|
||||
[auto-ap.views.pages.admin.accounts.form :as account-form]
|
||||
[auto-ap.views.pages.admin.accounts.side-bar :as side-bar]
|
||||
[auto-ap.views.pages.admin.accounts.table :as table]
|
||||
[auto-ap.views.pages.data-page :as data-page]
|
||||
[auto-ap.views.utils :refer [with-user]]
|
||||
[clojure.set :as set]
|
||||
[re-frame.core :as re-frame]
|
||||
[reagent.core :as reagent]
|
||||
[vimsical.re-frame.fx.track :as track]))
|
||||
|
||||
(def default-read [:numeric-code :name :location :type :account_set :applicability :id [:client-overrides [:name [:client [:name :id]]]]])
|
||||
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
(ns auto-ap.views.pages.admin.accounts.side-bar
|
||||
(:require
|
||||
[re-frame.core :as re-frame]
|
||||
[auto-ap.subs :as subs]
|
||||
[auto-ap.views.pages.data-page :as data-page]
|
||||
[auto-ap.views.utils :refer [dispatch-value-change]]
|
||||
[auto-ap.views.pages.data-page :as data-page]))
|
||||
|
||||
[re-frame.core :as re-frame]))
|
||||
|
||||
(defn accounts-side-bar [{:keys [data-page]}]
|
||||
[:div
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
(ns auto-ap.views.pages.admin.accounts.table
|
||||
(:require
|
||||
[auto-ap.status :as status]
|
||||
[auto-ap.views.components.buttons :as buttons]
|
||||
[auto-ap.views.components.grid :as grid]
|
||||
[auto-ap.views.pages.admin.accounts.form :as account-form]
|
||||
[auto-ap.views.pages.data-page :as data-page]
|
||||
[auto-ap.views.utils :refer [action-cell-width]]
|
||||
[re-frame.core :as re-frame]
|
||||
[auto-ap.views.pages.data-page :as data-page]))
|
||||
[re-frame.core :as re-frame]))
|
||||
|
||||
(defn accounts-table [{:keys [data-page]}]
|
||||
(let [{:keys [data]} @(re-frame/subscribe [::data-page/page data-page])]
|
||||
@@ -24,7 +23,7 @@
|
||||
[grid/header-cell {} "Location"]
|
||||
[grid/header-cell {:style {:width (action-cell-width 1)}} ]]]
|
||||
[grid/body
|
||||
(for [{:keys [id numeric-code name type location class] :as account} (:data data)]
|
||||
(for [{:keys [id numeric-code name type location] :as account} (:data data)]
|
||||
^{:key id}
|
||||
[grid/row {:class (:class account) :id id}
|
||||
[grid/cell {} numeric-code]
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
(ns auto-ap.views.pages.admin.clients.form
|
||||
(:require
|
||||
[auto-ap.entities.clients :as entity]
|
||||
[auto-ap.events :as events]
|
||||
[auto-ap.forms :as forms]
|
||||
[auto-ap.forms.builder :as form-builder]
|
||||
@@ -21,7 +20,6 @@
|
||||
[cljs-time.core :as t]
|
||||
[re-frame.core :as re-frame]
|
||||
[reagent.core :as r]
|
||||
[react-signature-canvas]
|
||||
[vimsical.re-frame.cofx.inject :as inject]
|
||||
[auto-ap.schema :as schema]
|
||||
[malli.core :as m]))
|
||||
@@ -178,7 +176,7 @@
|
||||
:identifier identifier
|
||||
:amount amount})
|
||||
(:forecasted-transactions new-client-data))
|
||||
:bank-accounts (map-indexed (fn [i {:keys [number name check-number plaid-account intuit-bank-account include-in-reports type id code numeric-code start-date bank-name routing bank-code new? sort-order visible yodlee-account-id locations yodlee-account use-date-instead-of-post-date]}]
|
||||
:bank-accounts (map-indexed (fn [i {:keys [number name check-number plaid-account intuit-bank-account include-in-reports type id code numeric-code start-date bank-name routing bank-code new? visible locations yodlee-account use-date-instead-of-post-date]}]
|
||||
{:number number
|
||||
:name name
|
||||
:check-number check-number
|
||||
@@ -526,8 +524,7 @@
|
||||
"Client code"
|
||||
[:input.input {:type "code"
|
||||
:style {:width "5em"}
|
||||
:disabled (boolean (:id new-client))
|
||||
:spec ::entity/code}]]
|
||||
:disabled (boolean (:id new-client))}]]
|
||||
|
||||
[form-builder/field-v2 {:field :locations}
|
||||
"Locations"
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
::filters
|
||||
:<- [::specific-filters]
|
||||
:<- [::subs/query-params]
|
||||
(fn [[specific-filters vendors-by-id query-params] ]
|
||||
(fn [[specific-filters _ query-params] ]
|
||||
(let [url-filters (-> query-params
|
||||
(select-keys #{:name
|
||||
:code}))
|
||||
@@ -32,7 +32,7 @@
|
||||
:<- [::settled-filters]
|
||||
:<- [::filters]
|
||||
:<- [::subs/active-page]
|
||||
(fn [[settled-filters filters ap ]]
|
||||
(fn [[settled-filters filters _ ]]
|
||||
(let [filters (or settled-filters filters)]
|
||||
{:name (:name filters)
|
||||
:code (:code filters)})))
|
||||
@@ -44,7 +44,7 @@
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::filters-settled
|
||||
(fn [{:keys [db]} [_ & params]]
|
||||
(fn [{:keys [db]} _]
|
||||
{:db (assoc db ::settled-filters @(re-frame/subscribe [::filters]))}))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
|
||||
@@ -1,29 +1,22 @@
|
||||
(ns auto-ap.views.pages.admin.import-batches
|
||||
(:require [auto-ap.forms :as forms]
|
||||
[auto-ap.subs :as subs]
|
||||
[auto-ap.views.components.admin.side-bar :refer [admin-side-bar]]
|
||||
[auto-ap.views.components.layouts :refer [appearing-side-bar side-bar-layout]]
|
||||
[auto-ap.views.pages.admin.import-batches.table :as table]
|
||||
[auto-ap.views.utils :refer [dispatch-event with-user]]
|
||||
[vimsical.re-frame.cofx.inject :as inject]
|
||||
[vimsical.re-frame.fx.track :as track]
|
||||
[auto-ap.events :as events]
|
||||
[auto-ap.utils :refer [replace-by merge-by]]
|
||||
[re-frame.core :as re-frame]
|
||||
[auto-ap.status :as status]
|
||||
[auto-ap.effects.forward :as forward]
|
||||
[auto-ap.views.pages.data-page :as data-page]
|
||||
[clojure.set :as set]
|
||||
[auto-ap.views.components.buttons :as buttons]
|
||||
[clojure.string :as str]))
|
||||
|
||||
(:require
|
||||
[auto-ap.status :as status]
|
||||
[auto-ap.subs :as subs]
|
||||
[auto-ap.views.components.admin.side-bar :refer [admin-side-bar]]
|
||||
[auto-ap.views.components.layouts :refer [side-bar-layout]]
|
||||
[auto-ap.views.pages.admin.import-batches.table :as table]
|
||||
[auto-ap.views.pages.data-page :as data-page]
|
||||
[auto-ap.views.utils :refer [dispatch-event with-user]]
|
||||
[clojure.set :as set]
|
||||
[re-frame.core :as re-frame]
|
||||
[vimsical.re-frame.fx.track :as track]))
|
||||
|
||||
(def default-read [:user-name :date :source :status :id :imported :suppressed :extant])
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::params-change
|
||||
[with-user ]
|
||||
(fn [{:keys [db user] :as cofx} [_ params]]
|
||||
(fn [{:keys [user]} [_ params]]
|
||||
{:graphql {:token user
|
||||
:owns-state {:single [::data-page/page ::page]}
|
||||
:query-obj {:venia/queries [{:query/data [:import_batch_page
|
||||
@@ -54,30 +47,13 @@
|
||||
|
||||
(re-frame/reg-event-fx ::request-intuit
|
||||
[with-user ]
|
||||
(fn [{:keys [db user] :as cofx} [_ params]]
|
||||
(fn [{:keys [user]} [_ _]]
|
||||
{:graphql {:token user
|
||||
:owns-state {:single ::intuit}
|
||||
:query "mutation RequestIntuitImport{request_import(which: \":intuit\")}"
|
||||
:on-success [::success-intuit]
|
||||
}}))
|
||||
|
||||
|
||||
|
||||
(re-frame/reg-event-db
|
||||
::success-yodlee
|
||||
(fn [db [_ n]]
|
||||
(assoc db ::msg (str "Your job " (:request-import n) " has been scheduled." ))))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::request-yodlee
|
||||
[with-user ]
|
||||
(fn [{:keys [db user] :as cofx} [_ params]]
|
||||
{:graphql {:token user
|
||||
:owns-state {:single ::yodlee}
|
||||
:query "mutation RequestIntuitImport{request_import(which: \":yodlee\")}"
|
||||
:on-success [::success-yodlee]
|
||||
}}))
|
||||
|
||||
(re-frame/reg-event-db
|
||||
::success-yodlee2
|
||||
(fn [db [_ n]]
|
||||
@@ -86,7 +62,7 @@
|
||||
(re-frame/reg-event-fx
|
||||
::request-yodlee2
|
||||
[with-user ]
|
||||
(fn [{:keys [db user] :as cofx} [_ params]]
|
||||
(fn [{:keys [user]} [_ _]]
|
||||
{:graphql {:token user
|
||||
:owns-state {:single ::yodlee2}
|
||||
:query "mutation RequestIntuitImport{request_import(which: \":yodlee2\")}"
|
||||
@@ -103,7 +79,7 @@
|
||||
(re-frame/reg-event-fx
|
||||
::request-plaid
|
||||
[with-user ]
|
||||
(fn [{:keys [db user] :as cofx} [_ params]]
|
||||
(fn [{:keys [user]} [_ _]]
|
||||
{:graphql {:token user
|
||||
:owns-state {:single ::plaid}
|
||||
:query "mutation RequestIntuitImport{request_import(which: \":plaid\")}"
|
||||
@@ -112,7 +88,7 @@
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::mounted
|
||||
(fn [{:keys [db]}]
|
||||
(fn [_]
|
||||
{::track/register {:id ::params
|
||||
:subscription [::data-page/params ::page]
|
||||
:event-fn (fn [params]
|
||||
@@ -131,7 +107,6 @@
|
||||
(fn []
|
||||
(let [user @(re-frame/subscribe [::subs/user])
|
||||
intuit-request-import-status @(re-frame/subscribe [::status/single ::intuit])
|
||||
yodlee-request-import-status @(re-frame/subscribe [::status/single ::yodlee])
|
||||
yodlee2-request-import-status @(re-frame/subscribe [::status/single ::yodlee2])
|
||||
plaid-request-import-status @(re-frame/subscribe [::status/single ::plaid])
|
||||
message @(re-frame/subscribe [::msg])]
|
||||
@@ -143,13 +118,7 @@
|
||||
[:div
|
||||
[:div.is-pulled-right
|
||||
[:div.buttons
|
||||
[:button.button.is-primary-two {:aria-haspopup true
|
||||
:type "button"
|
||||
:on-click (dispatch-event [::request-yodlee])
|
||||
:disabled (status/disabled-for yodlee-request-import-status)
|
||||
:class (status/class-for yodlee-request-import-status)}
|
||||
|
||||
"Start Yodlee Import"]
|
||||
|
||||
[:button.button.is-primary-two {:aria-haspopup true
|
||||
:type "button"
|
||||
:on-click (dispatch-event [::request-yodlee2])
|
||||
|
||||
@@ -31,13 +31,7 @@
|
||||
(fn [[specific-table-params query-params]]
|
||||
(merge (select-keys query-params #{:start :sort}) specific-table-params )))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::params-changed
|
||||
[(re-frame/path [::table-params])]
|
||||
(fn [{table-params :db} [_ params :as z]]
|
||||
{:db (merge table-params params)}))
|
||||
|
||||
(defn table* [{:keys [id data-page]}]
|
||||
(defn table* [{:keys [data-page]}]
|
||||
(let [{:keys [data]} @(re-frame/subscribe [::data-page/page data-page])]
|
||||
[grid/grid {:data-page data-page
|
||||
:column-count 6}
|
||||
@@ -82,7 +76,7 @@
|
||||
:icon "fa-external-link"}]]
|
||||
])]]]))
|
||||
|
||||
(defn table [params]
|
||||
(defn table []
|
||||
(r/create-class {:component-will-unmount (dispatch-event [::unmounted])
|
||||
:reagent-render (fn [params]
|
||||
[table* params])}))
|
||||
|
||||
@@ -1,46 +1,24 @@
|
||||
(ns auto-ap.views.pages.admin.plaid.table
|
||||
(:require [auto-ap.status :as status]
|
||||
[auto-ap.subs :as subs]
|
||||
[auto-ap.views.components.buttons :as buttons]
|
||||
[auto-ap.views.components.grid :as grid]
|
||||
[auto-ap.views.components.modal :as modal]
|
||||
[auto-ap.views.pages.admin.users.form :as form]
|
||||
[auto-ap.views.utils :refer [->$ action-cell-width date->str with-user dispatch-event]]
|
||||
[re-frame.core :as re-frame]
|
||||
[auto-ap.forms :as forms]
|
||||
[auto-ap.views.pages.data-page :as data-page]))
|
||||
|
||||
|
||||
#_(re-frame/reg-event-fx
|
||||
::refreshed
|
||||
[with-user ]
|
||||
(fn [{:keys [user db]} [_ provider-account ]]
|
||||
;; this is tracked in yodlee main, for refreshing
|
||||
{}))
|
||||
|
||||
#_(re-frame/reg-event-fx
|
||||
::request-refresh
|
||||
[with-user ]
|
||||
(fn [{:keys [user db]} [_ provider-account client-id ]]
|
||||
{:http {:token user
|
||||
:method :post
|
||||
:headers {"Content-Type" "application/edn"}
|
||||
:uri (str "/api/yodlee2/provider-accounts/refresh/")
|
||||
:owns-state {:multi ::refresh
|
||||
:which provider-account}
|
||||
:body {:client-id client-id
|
||||
:provider-account-id provider-account}
|
||||
:on-success [::refreshed provider-account]}}))
|
||||
(:require
|
||||
[auto-ap.status :as status]
|
||||
[auto-ap.subs :as subs]
|
||||
[auto-ap.views.components.buttons :as buttons]
|
||||
[auto-ap.views.components.grid :as grid]
|
||||
[auto-ap.views.components.modal :as modal]
|
||||
[auto-ap.views.pages.data-page :as data-page]
|
||||
[auto-ap.views.utils
|
||||
:refer [->$ action-cell-width date->str dispatch-event with-user]]
|
||||
[re-frame.core :as re-frame]))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::plaid-item-deleted
|
||||
(fn [{:keys [db]} [_ i result]]
|
||||
(fn [_ _]
|
||||
{:dispatch [::modal/modal-closed ]}))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::delete-plaid-item
|
||||
[with-user ]
|
||||
(fn [{:keys [user db]} [_ id ]]
|
||||
(fn [{:keys [user]} [_ id ]]
|
||||
{:graphql {:token user
|
||||
:owns-state {:single ::delete-plaid-item}
|
||||
:query-obj
|
||||
@@ -55,7 +33,7 @@
|
||||
(re-frame/reg-event-fx
|
||||
::delete-requested
|
||||
[with-user]
|
||||
(fn [{:keys [user db]} [_ id]]
|
||||
(fn [_ [_ id]]
|
||||
{:dispatch
|
||||
[::modal/modal-requested {:title "Delete Provider account "
|
||||
:body [:div "Are you sure you want to delete " id "?"]
|
||||
@@ -66,21 +44,14 @@
|
||||
:close-event [::status/completed ::delete-plaid-item]}
|
||||
:cancel? true}]}))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::params-changed
|
||||
(fn [{:keys [db]} [_ p]]
|
||||
{:db (assoc db ::params p)}))
|
||||
|
||||
(re-frame/reg-sub
|
||||
::params
|
||||
(fn [db]
|
||||
(-> db ::params)))
|
||||
|
||||
(defn table [{:keys [status data-page]}]
|
||||
(defn table [{:keys [data-page]}]
|
||||
(let [{:keys [data]} @(re-frame/subscribe [::data-page/page data-page])
|
||||
params @(re-frame/subscribe [::params])
|
||||
is-admin? @(re-frame/subscribe [::subs/is-admin?])
|
||||
statuses @(re-frame/subscribe [::status/multi ::refresh])]
|
||||
is-admin? @(re-frame/subscribe [::subs/is-admin?])]
|
||||
[grid/grid {:data-page data-page
|
||||
:column-count 5}
|
||||
[grid/controls data]
|
||||
@@ -93,7 +64,7 @@
|
||||
[grid/header-cell {} "Accounts"]
|
||||
[grid/header-cell {:style {:width (action-cell-width 1)}} ]]]
|
||||
[grid/body
|
||||
(for [{:keys [id name accounts status last-updated clients] :as c} (:data data)]
|
||||
(for [{:keys [id name accounts status last-updated] :as c} (:data data)]
|
||||
^{:key (str name "-" id )}
|
||||
[grid/row {:class (:class c) :id id}
|
||||
[grid/cell {} id]
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
(ns auto-ap.views.pages.admin.rules.results-modal
|
||||
(:require [auto-ap.events :as events]
|
||||
[auto-ap.subs :as subs]
|
||||
[auto-ap.views.utils :refer [date->str dispatch-event with-user]]
|
||||
(:require [auto-ap.views.utils :refer [date->str dispatch-event with-user]]
|
||||
[auto-ap.views.pages.transactions.common :refer [transaction-read]]
|
||||
[re-frame.core :as re-frame]
|
||||
[auto-ap.views.components.modal :as modal]
|
||||
@@ -37,11 +35,10 @@
|
||||
(count checked)
|
||||
0)))
|
||||
|
||||
(defn results-body [params]
|
||||
(defn results-body []
|
||||
(let [runnable? @(re-frame/subscribe [::runnable?])
|
||||
checked @(re-frame/subscribe [::checked])
|
||||
all-checked @(re-frame/subscribe [::all-checked])
|
||||
checked-count @(re-frame/subscribe [::checked-count])]
|
||||
all-checked @(re-frame/subscribe [::all-checked])]
|
||||
[:table.table.is-fullwidth.compact
|
||||
[:tr
|
||||
(when runnable?
|
||||
@@ -71,7 +68,6 @@
|
||||
|
||||
(defn foot [params]
|
||||
(let [runnable? @(re-frame/subscribe [::runnable?])
|
||||
checked @(re-frame/subscribe [::checked])
|
||||
all-checked @(re-frame/subscribe [::all-checked])
|
||||
checked-count @(re-frame/subscribe [::checked-count])
|
||||
status @(re-frame/subscribe [::status/single ::apply])]
|
||||
@@ -115,8 +111,8 @@
|
||||
|
||||
(re-frame/reg-event-db
|
||||
::toggle-all
|
||||
(fn [db [_ which]]
|
||||
(let [{::keys [all-checked checked test-results]} db]
|
||||
(fn [db [_ _]]
|
||||
(let [{::keys [all-checked test-results]} db]
|
||||
(assoc db
|
||||
::all-checked (not all-checked)
|
||||
::checked (if all-checked
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
(re-frame/reg-event-fx
|
||||
::run-clicked
|
||||
[with-user]
|
||||
(fn [{:keys [user db]} [_ which]]
|
||||
(fn [{:keys [user]} [_ which]]
|
||||
{:graphql
|
||||
{:token user
|
||||
:owns-state {:multi ::run
|
||||
@@ -36,7 +36,7 @@
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::succeeded-run
|
||||
(fn [{:keys [db]} [_ transaction-rule-id result]]
|
||||
(fn [_ [_ transaction-rule-id result]]
|
||||
{:dispatch [::results-modal/opening (:run-transaction-rule result) transaction-rule-id true]}))
|
||||
|
||||
(re-frame/reg-sub
|
||||
@@ -56,13 +56,6 @@
|
||||
(fn [[specific-table-params query-params]]
|
||||
(merge (select-keys query-params #{:start :sort}) specific-table-params )))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::params-changed
|
||||
[(re-frame/path [::table-params])]
|
||||
(fn [{table-params :db} [_ params :as z]]
|
||||
{:db (merge table-params params)}))
|
||||
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::deleted-transaction-rule
|
||||
(fn []
|
||||
@@ -71,7 +64,7 @@
|
||||
(re-frame/reg-event-fx
|
||||
::delete-transaction-rule
|
||||
[with-user]
|
||||
(fn [{:keys [db user]} [_ id]]
|
||||
(fn [{:keys [user]} [_ id]]
|
||||
{:graphql
|
||||
{:token user
|
||||
:owns-state {:single ::delete-transaction-rule}
|
||||
@@ -97,9 +90,9 @@
|
||||
|
||||
|
||||
|
||||
(defn table* [{:keys [id data-page]}]
|
||||
(defn table* [{:keys [data-page]}]
|
||||
(let [{:keys [data]} @(re-frame/subscribe [::data-page/page data-page])
|
||||
selected-client @(re-frame/subscribe [::subs/client])
|
||||
_ @(re-frame/subscribe [::subs/client])
|
||||
states @(re-frame/subscribe [::status/multi ::run])]
|
||||
[grid/grid {:data-page data-page
|
||||
:column-count 6}
|
||||
@@ -152,7 +145,7 @@
|
||||
[buttons/sl-icon {:event [::request-delete r] :icon :icon-bin-2}]
|
||||
[buttons/fa-icon {:event [::form/editing r] :icon :fa-pencil}]]]])]]]))
|
||||
|
||||
(defn table [params]
|
||||
(defn table []
|
||||
(r/create-class {:component-will-unmount (dispatch-event [::unmounted])
|
||||
:reagent-render (fn [params]
|
||||
[table* params])}))
|
||||
|
||||
@@ -53,7 +53,7 @@
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::unmounted
|
||||
(fn [{:keys [db]} _]
|
||||
(fn [_ _]
|
||||
{::forward/dispose {:id ::edited-user}}))
|
||||
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user