Migrates back to datomic on-prem
This commit is contained in:
@@ -19,7 +19,7 @@
|
||||
[clojure.tools.logging :as log]
|
||||
[com.unbounce.dogstatsd.core :as statsd]
|
||||
[config.core :refer [env]]
|
||||
[datomic.client.api :as dc]
|
||||
[datomic.api :as dc]
|
||||
[ring.middleware.json :refer [wrap-json-response]]
|
||||
[venia.core :as venia]))
|
||||
|
||||
@@ -35,18 +35,18 @@
|
||||
identity (jwt/unsign (get query-params "key") (:jwt-secret env) {:alg :hs512})]
|
||||
(assert-can-see-client identity client-id)
|
||||
(into (list)
|
||||
(dc/q {:query {:find '[?d4 (sum ?total) (sum ?tax) (sum ?tip) (sum ?service-charge)]
|
||||
:in '[$ ?c]
|
||||
:where '[[?s :sales-order/client ?c]
|
||||
[?s :sales-order/date ?d]
|
||||
[?s :sales-order/total ?total]
|
||||
[?s :sales-order/tax ?tax]
|
||||
[?s :sales-order/tip ?tip]
|
||||
[?s :sales-order/service-charge ?service-charge]
|
||||
[(clj-time.coerce/to-date-time ?d) ?d2]
|
||||
[(auto-ap.time/localize ?d2) ?d3]
|
||||
[(auto-ap.time/unparse ?d3 auto-ap.time/normal-date) ?d4]]}
|
||||
:args [(dc/db conn) client-id]}))))
|
||||
(dc/q {:find '[?d4 (sum ?total) (sum ?tax) (sum ?tip) (sum ?service-charge)]
|
||||
:in '[$ ?c]
|
||||
:where '[[?s :sales-order/client ?c]
|
||||
[?s :sales-order/date ?d]
|
||||
[?s :sales-order/total ?total]
|
||||
[?s :sales-order/tax ?tax]
|
||||
[?s :sales-order/tip ?tip]
|
||||
[?s :sales-order/service-charge ?service-charge]
|
||||
[(clj-time.coerce/to-date-time ?d) ?d2]
|
||||
[(auto-ap.time/localize ?d2) ?d3]
|
||||
[(auto-ap.time/unparse ?d3 auto-ap.time/normal-date) ?d4]]}
|
||||
(dc/db conn) client-id))))
|
||||
|
||||
(defn client-tag [params]
|
||||
(when-let [code (or (params "client-code")
|
||||
@@ -369,10 +369,10 @@
|
||||
"export:transactions2"}}]
|
||||
{:body (let [db (dc/db conn)]
|
||||
(->>
|
||||
(dc/q {:query {:find ['?e]
|
||||
:in ['$ '?client-code]
|
||||
:where ['[?e :transaction/client ?client-code]]}
|
||||
:args [db [:client/code (query-params "client-code")]]})
|
||||
(dc/q {:find ['?e]
|
||||
:in ['$ '?client-code]
|
||||
:where ['[?e :transaction/client ?client-code]]}
|
||||
db [:client/code (query-params "client-code")])
|
||||
(map first)
|
||||
;; TODO
|
||||
#_(map (fn [e]
|
||||
|
||||
@@ -18,9 +18,9 @@
|
||||
[clojure.string :as str]
|
||||
[clojure.tools.logging :as log]
|
||||
[config.core :refer [env]]
|
||||
[datomic.client.api :as dc]
|
||||
[datomic.api :as dc]
|
||||
[digest]
|
||||
[iol-ion.tx :refer [propose-invoice random-tempid]]
|
||||
[iol-ion.tx :refer [random-tempid]]
|
||||
[ring.middleware.json :refer [wrap-json-response]]
|
||||
[unilog.context :as lc])
|
||||
(:import
|
||||
@@ -114,10 +114,10 @@
|
||||
{:vendor-code vendor-code})))
|
||||
(let [vendor-id (or forced-vendor
|
||||
(->> (dc/q
|
||||
{:query {:find ['?vendor]
|
||||
:in ['$ '?vendor-name]
|
||||
:where ['[?vendor :vendor/name ?vendor-name]]}
|
||||
:args [(dc/db conn) vendor-code]})
|
||||
{:find ['?vendor]
|
||||
:in ['$ '?vendor-name]
|
||||
:where ['[?vendor :vendor/name ?vendor-name]]}
|
||||
(dc/db conn) vendor-code)
|
||||
first
|
||||
first))]
|
||||
(when-not vendor-id
|
||||
@@ -125,9 +125,9 @@
|
||||
{:vendor-code vendor-code})))
|
||||
|
||||
(if-let [matching-vendor (->> (dc/q
|
||||
{:query {:find [(list 'pull '?vendor-id d-vendors/default-read)]
|
||||
:in ['$ '?vendor-id]}
|
||||
:args [(dc/db conn) vendor-id]})
|
||||
{:find [(list 'pull '?vendor-id d-vendors/default-read)]
|
||||
:in ['$ '?vendor-id]}
|
||||
(dc/db conn) vendor-id)
|
||||
first
|
||||
first)]
|
||||
matching-vendor
|
||||
@@ -231,8 +231,8 @@
|
||||
:transaction-account/location "A"
|
||||
:transaction-account/amount (Math/abs (:invoice/total invoice))}]}))
|
||||
]
|
||||
[`(propose-invoice ~(d-invoices/code-invoice (validate-invoice (remove-nils invoice)
|
||||
user)))
|
||||
[[:propose-invoice (d-invoices/code-invoice (validate-invoice (remove-nils invoice)
|
||||
user))]
|
||||
(some-> payment remove-nils)
|
||||
transaction])))
|
||||
(filter identity)))
|
||||
@@ -252,7 +252,7 @@
|
||||
(map #(validate-invoice % user))
|
||||
admin-only-if-multiple-clients
|
||||
(mapv d-invoices/code-invoice)
|
||||
(mapv (fn [i] `(propose-invoice ~i))))]
|
||||
(mapv (fn [i] [:propose-invoice i])))]
|
||||
|
||||
(log/info "creating invoice" potential-invoices)
|
||||
(let [tx (audit-transact potential-invoices user)]
|
||||
@@ -288,21 +288,23 @@
|
||||
|
||||
(defn import-account-overrides [customer filename]
|
||||
(let [[_ & rows] (-> filename (io/reader) csv/read-csv)
|
||||
[client-id] (first (dc/q (-> {:query {:find ['?e]
|
||||
:in ['$ '?z]
|
||||
:where [['?e :client/code '?z]]}
|
||||
:args [(dc/db conn) customer]})))
|
||||
code->existing-account (by :account/numeric-code (map first (dc/q {:query {:find ['(pull ?e [:account/numeric-code
|
||||
{:account/applicability [:db/ident]}
|
||||
:db/id])]
|
||||
:in ['$]
|
||||
:where ['[?e :account/name]]}
|
||||
:args [(dc/db conn)]})))
|
||||
[client-id] (first (dc/q (-> {:find ['?e]
|
||||
:in ['$ '?z]
|
||||
:where [['?e :client/code '?z]]}
|
||||
(dc/db conn)
|
||||
customer)))
|
||||
code->existing-account (by :account/numeric-code (map first (dc/q {:find ['(pull ?e [:account/numeric-code
|
||||
{:account/applicability [:db/ident]}
|
||||
:db/id])]
|
||||
:in ['$]
|
||||
:where ['[?e :account/name]]}
|
||||
(dc/db conn))))
|
||||
|
||||
existing-account-overrides (dc/q (-> {:query {:find ['?e]
|
||||
:in ['$ '?client-id]
|
||||
:where [['?e :account-client-override/client '?client-id]]}
|
||||
:args [(dc/db conn) client-id]}))
|
||||
existing-account-overrides (dc/q (-> {:find ['?e]
|
||||
:in ['$ '?client-id]
|
||||
:where [['?e :account-client-override/client '?client-id]]}
|
||||
(dc/db conn)
|
||||
client-id))
|
||||
rows (transduce (comp
|
||||
(map (fn [[_ account account-name override-name _ type]]
|
||||
[account account-name override-name type]))
|
||||
@@ -357,7 +359,7 @@
|
||||
existing-account-overrides)
|
||||
rows)]
|
||||
|
||||
(dc/transact conn {:tx-data txes})
|
||||
@(dc/transact conn txes)
|
||||
txes))
|
||||
|
||||
(defn import-transactions-cleared-against [file]
|
||||
|
||||
@@ -10,8 +10,8 @@
|
||||
[clojure.tools.logging :as log]
|
||||
[com.unbounce.dogstatsd.core :as statsd]
|
||||
[config.core :refer [env]]
|
||||
[datomic.client.api :as dc]
|
||||
[iol-ion.tx :refer [random-tempid upsert-entity]]
|
||||
[datomic.api :as dc]
|
||||
[iol-ion.tx :refer [random-tempid]]
|
||||
[ring.middleware.json :refer [wrap-json-response]]
|
||||
[ring.util.request :refer [body-string]]
|
||||
[unilog.context :as lc])
|
||||
@@ -45,12 +45,12 @@
|
||||
(or (pull-attr (dc/db conn) :saved-query/guid [:saved-query/lookup-key lookup-key])
|
||||
guid)
|
||||
guid)]
|
||||
(dc/transact conn {:tx-data [`(upsert-entity ~{:db/id (or id (random-tempid))
|
||||
:saved-query/guid guid
|
||||
:saved-query/description note
|
||||
:saved-query/key (str "queries/" guid)
|
||||
:saved-query/client client
|
||||
:saved-query/lookup-key lookup-key})]})
|
||||
@(dc/transact conn [[:upsert-entity {:db/id (or id (random-tempid))
|
||||
:saved-query/guid guid
|
||||
:saved-query/description note
|
||||
:saved-query/key (str "queries/" guid)
|
||||
:saved-query/client client
|
||||
:saved-query/lookup-key lookup-key}]])
|
||||
(s3/put-object :bucket-name (:data-bucket env)
|
||||
:key (str "queries/" guid)
|
||||
:input-stream (io/make-input-stream (.getBytes body) {})
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
[auto-ap.yodlee.core2 :as yodlee]
|
||||
[clojure.tools.logging :as log]
|
||||
[config.core :refer [env]]
|
||||
[datomic.client.api :as dc]))
|
||||
[datomic.api :as dc]))
|
||||
|
||||
(defn fastlink [{:keys [query-params identity]}]
|
||||
(assert-can-see-client identity (pull-attr (dc/db conn) :db/id [:client/code (get query-params "client")]))
|
||||
|
||||
Reference in New Issue
Block a user