fixed warnings.
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user