tons of small fixes.
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
[auto-ap.datomic.migrate.add-bank-account-codes :refer [add-bank-account-codes]]
|
||||
[auto-ap.datomic.migrate.invoice-converter :refer [add-import-status-existing-invoices]]
|
||||
[auto-ap.datomic.migrate.add-general-ledger :as add-general-ledger]
|
||||
[auto-ap.datomic.migrate.ledger :as ledger]
|
||||
[auto-ap.datomic.migrate.sales :as sales]
|
||||
[auto-ap.datomic.migrate.clients :as clients]
|
||||
[auto-ap.datomic.migrate.audit :as audit]
|
||||
@@ -316,11 +317,12 @@
|
||||
:auto-ap/fix-reset-rels {:txes-fn `reset-function}}
|
||||
sales/norms-map
|
||||
clients/norms-map
|
||||
ledger/norms-map
|
||||
audit/norms-map)
|
||||
]
|
||||
(println "Conforming database...")
|
||||
(c/ensure-conforms conn norms-map)
|
||||
(when (not (seq args))
|
||||
#_(when (not (seq args))
|
||||
(d/release conn))
|
||||
(println "Done")))
|
||||
#_(-main false)
|
||||
|
||||
6
src/clj/auto_ap/datomic/migrate/ledger.clj
Normal file
6
src/clj/auto_ap/datomic/migrate/ledger.clj
Normal file
@@ -0,0 +1,6 @@
|
||||
(ns auto-ap.datomic.migrate.ledger)
|
||||
|
||||
(def norms-map {::add-alternat-description {:txes [[{:db/ident :journal-entry/alternate-description
|
||||
:db/doc "The description if there is no vendor"
|
||||
:db/valueType :db.type/string
|
||||
:db/cardinality :db.cardinality/one}]]}})
|
||||
@@ -116,7 +116,6 @@
|
||||
args)
|
||||
true
|
||||
(merge-query {:query {:find ['?e] :where ['[?e :transaction/id]]}}))]
|
||||
(println query)
|
||||
(cond->> query
|
||||
true (d/query)
|
||||
true (apply-sort-3 args)
|
||||
@@ -179,18 +178,3 @@
|
||||
(update :transaction/post-date c/from-date)
|
||||
(dissoc :transaction/id)))
|
||||
|
||||
(defn unapprove [ids]
|
||||
(doseq [x (partition-all 100 ids)]
|
||||
@(d/transact (d/connect uri)
|
||||
(mapv (fn [i]
|
||||
{:db/id i
|
||||
:transaction/approval-status :transaction-approval-status/unapproved})
|
||||
x))))
|
||||
|
||||
(defn delete [ids]
|
||||
(doseq [x (partition-all 100 ids)]
|
||||
@(d/transact (d/connect uri)
|
||||
(mapcat (fn [i]
|
||||
[[:db/retractEntity i]
|
||||
[:db/retractEntity [:journal-entry/original-entity i]]])
|
||||
x))))
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
(ns auto-ap.datomic.vendors
|
||||
(:require [datomic.api :as d]
|
||||
[auto-ap.graphql.utils :refer [limited-clients]]
|
||||
[auto-ap.datomic :refer [uri]]))
|
||||
[auto-ap.graphql.utils :refer [limited-clients ]]
|
||||
|
||||
[auto-ap.datomic :refer [uri conn merge-query]]))
|
||||
(defn cleanse [id vendor]
|
||||
(let [clients (if-let [clients (limited-clients id)]
|
||||
(set (map :db/id clients))
|
||||
@@ -18,14 +19,42 @@
|
||||
:vendor/terms-overrides [* {:vendor-terms-override/client [:client/name :client/code :db/id]}]
|
||||
:vendor/automatically-paid-when-due [:db/id :client/name]}])
|
||||
|
||||
(defn get-graphql [args]
|
||||
(->> (cond-> {:query {:find [(list 'pull '?e default-read)]
|
||||
(defn get-usages [args]
|
||||
(->> (cond-> {:query {:find ['?v '?c '(count ?e)]
|
||||
:in ['$]
|
||||
:where ['[?e :vendor/name]]}
|
||||
:args [(d/db (d/connect uri))]})
|
||||
:where ['[?v :vendor/name]
|
||||
'(or-join [?v ?c ?e]
|
||||
(and
|
||||
[?e :invoice/vendor ?v]
|
||||
[?e :invoice/client ?c])
|
||||
(and
|
||||
[?e :transaction/vendor ?v]
|
||||
[?e :transaction/client ?c])
|
||||
(and
|
||||
[?e :journal-entry/vendor ?v]
|
||||
[?e :journal-entry/client ?c]))]}
|
||||
:args [(d/db conn)]}
|
||||
|
||||
(limited-clients (:id args))
|
||||
(merge-query {:query {:in ['?xx]
|
||||
:where [['(get ?xx ?c)]]}
|
||||
:args [(set (map :db/id (limited-clients (:id args))))]}))
|
||||
(d/query)
|
||||
(map first)
|
||||
(map #(cleanse (:id args) %))))
|
||||
(reduce
|
||||
(fn [usages [v c cnt]]
|
||||
(update usages v (fnil conj []) {:client-id c :count cnt}))
|
||||
{})))
|
||||
|
||||
(defn get-graphql [args]
|
||||
(let [usages (time (get-usages args))]
|
||||
(->> (cond-> {:query {:find [(list 'pull '?e default-read)]
|
||||
:in ['$]
|
||||
:where ['[?e :vendor/name]]}
|
||||
:args [(d/db (d/connect uri))]})
|
||||
(d/query)
|
||||
(map first)
|
||||
(map #(cleanse (:id args) %))
|
||||
(map #(assoc % :usage (get usages (:db/id %)))))))
|
||||
|
||||
(defn get-by-id [id]
|
||||
|
||||
|
||||
@@ -148,6 +148,9 @@
|
||||
:client {:type :client}
|
||||
:account {:type :account}}}
|
||||
|
||||
:usage {:fields {:client_id {:type :id}
|
||||
:count {:type 'Int}}}
|
||||
|
||||
:vendor
|
||||
{:fields {:id {:type :id}
|
||||
:name {:type 'String}
|
||||
@@ -157,6 +160,7 @@
|
||||
:automatically_paid_when_due {:type '(list :client)}
|
||||
:terms_overrides {:type '(list :terms_override)}
|
||||
:account_overrides {:type '(list :vendor_account_override)}
|
||||
:usage {:type '(list :usage)}
|
||||
|
||||
:print_as {:type 'String}
|
||||
:primary_contact {:type :contact}
|
||||
@@ -189,6 +193,7 @@
|
||||
:cleared_against {:type 'String}
|
||||
:client {:type :client}
|
||||
:vendor {:type :vendor}
|
||||
:alternate_description {:type 'String}
|
||||
:date {:type 'String}
|
||||
:line_items {:type '(list :journal_entry_line)}}}
|
||||
|
||||
@@ -928,9 +933,7 @@
|
||||
(let [users (d-users/get-graphql args)]
|
||||
(->graphql users)))
|
||||
|
||||
(defn get-vendor [context args value]
|
||||
(->graphql
|
||||
(d-vendors/get-graphql (assoc args :id (:id context)))))
|
||||
|
||||
|
||||
(defn print-checks [context args value]
|
||||
|
||||
@@ -1145,7 +1148,7 @@
|
||||
:mutation/void-payment gq-checks/void-check
|
||||
:mutation/edit-expense-accounts gq-invoices/edit-expense-accounts
|
||||
:mutation/import-ledger gq-ledger/import-ledger
|
||||
:get-vendor get-vendor})
|
||||
:get-vendor gq-vendors/get-graphql})
|
||||
schema/compile))
|
||||
|
||||
|
||||
|
||||
@@ -76,6 +76,8 @@
|
||||
(fn [acc [location account-id] {:keys [debit credit count]}]
|
||||
(let [account (lookup-account account-id)
|
||||
account-type (:account_type account)]
|
||||
|
||||
|
||||
(conj acc (merge {:id (str account-id "-" location)
|
||||
:location (or location "")
|
||||
:amount (if account-type (if (#{:account-type/asset
|
||||
@@ -129,17 +131,26 @@
|
||||
|
||||
(defn full-ledger-for-client [client-id]
|
||||
(->> (d/query
|
||||
{:query {:find ['?d '?jel '?account '?location '?debit '?credit ]
|
||||
:in ['$ '?client-id]
|
||||
:where ['[?e :journal-entry/client ?client-id]
|
||||
'[?e :journal-entry/date ?d]
|
||||
'[?e :journal-entry/line-items ?jel]
|
||||
'[(get-else $ ?jel :journal-entry-line/account :account/unknown) ?account]
|
||||
'[(get-else $ ?jel :journal-entry-line/debit 0.0) ?debit ]
|
||||
'[(get-else $ ?jel :journal-entry-line/credit 0.0) ?credit]
|
||||
'[(get-else $ ?jel :journal-entry-line/location "") ?location]]
|
||||
}
|
||||
:args [(d/db (d/connect uri)) client-id]})
|
||||
{:query {:find ['?d '?jel '?account '?location '?debit '?credit]
|
||||
:in ['$ '?client-id]
|
||||
:where '[[?e :journal-entry/client ?client-id]
|
||||
[?e :journal-entry/date ?d]
|
||||
[?e :journal-entry/line-items ?jel]
|
||||
(or-join [?e]
|
||||
(and [?e :journal-entry/original-entity ?i]
|
||||
(or-join [?e ?i]
|
||||
(and
|
||||
[?i :transaction/bank-account ?b]
|
||||
(or [?b :bank-account/include-in-reports true]
|
||||
(not [?b :bank-account/include-in-reports])))
|
||||
(not [?i :transaction/bank-account])))
|
||||
(not [?e :journal-entry/original-entity ]))
|
||||
[(get-else $ ?jel :journal-entry-line/account :account/unknown) ?account]
|
||||
[(get-else $ ?jel :journal-entry-line/debit 0.0) ?debit ]
|
||||
[(get-else $ ?jel :journal-entry-line/credit 0.0) ?credit]
|
||||
[(get-else $ ?jel :journal-entry-line/location "") ?location]]
|
||||
}
|
||||
:args [(d/db (d/connect uri)) client-id]})
|
||||
(sort-by first)))
|
||||
|
||||
(defn get-balance-sheet [context args value]
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
[auto-ap.datomic.vendors :as d-vendors]
|
||||
[auto-ap.time :refer [parse iso-date]]
|
||||
[datomic.api :as d]
|
||||
[auto-ap.datomic :refer [uri remove-nils]]
|
||||
[auto-ap.datomic :refer [uri remove-nils audit-transact]]
|
||||
[clj-time.coerce :as coerce]
|
||||
[clojure.set :as set]))
|
||||
|
||||
@@ -79,7 +79,7 @@
|
||||
{:db/id apwd})
|
||||
(:automatically_paid_when_due in))]))
|
||||
|
||||
transaction-result @(d/transact (d/connect uri) transaction)]
|
||||
transaction-result (audit-transact transaction (:id context))]
|
||||
|
||||
(-> (d-vendors/get-by-id (or (-> transaction-result :tempids (get "vendor"))
|
||||
id))
|
||||
@@ -100,3 +100,7 @@
|
||||
transaction (conj transaction [:db/retractEntity from])]
|
||||
@(d/transact conn transaction)
|
||||
to))
|
||||
|
||||
(defn get-graphql [context args value]
|
||||
(->graphql
|
||||
(d-vendors/get-graphql (assoc args :id (:id context)))))
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
[yang.scheduler :as scheduler]
|
||||
[mount.core :as mount]
|
||||
[auto-ap.datomic.accounts :as a]
|
||||
[auto-ap.datomic :refer [uri remove-nils]]
|
||||
[auto-ap.datomic :refer [uri remove-nils conn]]
|
||||
[clojure.spec.alpha :as s]
|
||||
[clojure.tools.logging :as log]
|
||||
[auto-ap.logging :refer [info-event]]
|
||||
@@ -84,6 +84,7 @@
|
||||
:journal-entry/client (:db/id (:transaction/client entity))
|
||||
:journal-entry/date (:transaction/date entity)
|
||||
:journal-entry/original-entity (:db/id entity)
|
||||
:journal-entry/alternate-description (:transaction/description-original entity)
|
||||
:journal-entry/vendor (:db/id (:transaction/vendor entity))
|
||||
:journal-entry/amount (Math/abs (:transaction/amount entity))
|
||||
:journal-entry/cleared-against (:transaction/cleared-against entity)
|
||||
@@ -122,9 +123,7 @@
|
||||
(into [[:replace-general-ledger (:journal-entry/original-entity (first entries))]]
|
||||
entries))
|
||||
|
||||
(mount/defstate conn
|
||||
:start (d/connect uri)
|
||||
:stop (d/release conn))
|
||||
|
||||
|
||||
(mount/defstate tx-report-queue
|
||||
:start (d/tx-report-queue conn)
|
||||
|
||||
@@ -512,7 +512,7 @@
|
||||
:date [#"Date" 0 0 #"Date: (.*)"]
|
||||
:invoice-number [#"Invoice #" 0 0 #"Invoice #: (.*)"]
|
||||
:account-number [#"Customer #" 0 0 #"Customer #: (.*)"]}
|
||||
:parser { :total [:trim-commas-and-remove-dollars nil]
|
||||
:parser { :total [:trim-commas-and-remove-dollars-and-invert-parentheses nil]
|
||||
:date [:clj-time "MM/dd/yyyy"]}}
|
||||
{:vendor "Mama Lu's Foods"
|
||||
:keywords [#"Mama Lu's Foods"]
|
||||
|
||||
@@ -18,6 +18,13 @@
|
||||
[_ _ value]
|
||||
(str/replace (str/replace value #"," "") #"\$" ""))
|
||||
|
||||
(defmethod parse-value :trim-commas-and-remove-dollars-and-invert-parentheses
|
||||
[_ _ value]
|
||||
(let [v (str/replace (str/replace value #"," "") #"\$" "")]
|
||||
(if-let [[_ a ] (re-find #"\((.*)\)" v)]
|
||||
(str "-" a)
|
||||
v)))
|
||||
|
||||
(defmethod parse-value :trim-commas-and-negate
|
||||
[_ _ value]
|
||||
(let [[_ raw-value] (re-find #"([\d\.]+)"
|
||||
|
||||
@@ -58,13 +58,18 @@
|
||||
:account)))
|
||||
|
||||
(defn get-accounts-for-provider-account [provider-account-id]
|
||||
(let [cob-session (login-cobrand)
|
||||
user-session (login-user cob-session)]
|
||||
(-> (str (:yodlee-base-url env) "/accounts?providerAccountId=" provider-account-id)
|
||||
(client/get {:headers (merge base-headers {"Authorization" (auth-header cob-session user-session)})
|
||||
:as :json})
|
||||
:body
|
||||
:account)))
|
||||
(try
|
||||
(let [cob-session (login-cobrand)
|
||||
user-session (login-user cob-session)]
|
||||
(-> (str (:yodlee-base-url env) "/accounts?providerAccountId=" provider-account-id)
|
||||
(client/get {:headers (merge base-headers {"Authorization" (auth-header cob-session user-session)})
|
||||
:as :json})
|
||||
:body
|
||||
:account))
|
||||
(catch Exception e
|
||||
(log/error (str "Couldn't get accounts for provider account '" provider-account-id "'")
|
||||
e)
|
||||
[])))
|
||||
|
||||
(defn get-account [i]
|
||||
(let [cob-session (login-cobrand)
|
||||
@@ -234,7 +239,6 @@
|
||||
output-chan
|
||||
(map (fn [provider-account]
|
||||
(lc/with-context {:provider-account-id (:id provider-account)}
|
||||
(log/info "fetching details for provider" (:id provider-account))
|
||||
(get-provider-account-detail (:id provider-account)))))
|
||||
(async/to-chan provider-accounts))
|
||||
(async/<!! (async/into [] output-chan)))))
|
||||
|
||||
Reference in New Issue
Block a user