Merge branch 'master' into datomic
This commit is contained in:
@@ -71,6 +71,13 @@
|
||||
(catch Exception e
|
||||
(throw (Exception. (str "Could not parse account from value '" (:account-id i) "'") e)))))
|
||||
|
||||
(defn parse-company-id [i]
|
||||
(try
|
||||
(Integer/parseInt (second
|
||||
(re-matches #"[^0-9,\\-]*([0-9,\\-]+)[^0-9,]*" (:company-id i))))
|
||||
(catch Exception e
|
||||
(throw (Exception. (str "Could not parse company from value '" (:company-id i) "'") e)))))
|
||||
|
||||
(defn parse-date [{:keys [raw-date]}]
|
||||
(try
|
||||
(parse/parse-value :clj-time "MM/dd/yyyy" raw-date)
|
||||
@@ -90,9 +97,9 @@
|
||||
(context "/" []
|
||||
(context "/transactions" []
|
||||
(POST "/batch-upload"
|
||||
{{:keys [data company-id]} :edn-params user :identity}
|
||||
{{:keys [data]} :edn-params user :identity}
|
||||
(assert-admin user)
|
||||
(let [columns [:status :raw-date :description-original :high-level-category nil nil :amount nil nil nil nil nil :account-id]
|
||||
(let [columns [:status :raw-date :description-original :high-level-category nil nil :amount nil nil nil nil nil :account-id :company-id]
|
||||
rows (->> (str/split data #"\n" )
|
||||
(drop 1)
|
||||
(map #(str/split % #"\t"))
|
||||
@@ -100,20 +107,22 @@
|
||||
|
||||
(map (parse-or-error :amount parse-amount))
|
||||
(map (parse-or-error :account-id parse-account-id))
|
||||
(map (parse-or-error :company-id parse-company-id))
|
||||
(map (parse-or-error :date parse-date)))
|
||||
error-rows (filter :errors rows)
|
||||
|
||||
raw-transactions (vec (->> rows
|
||||
(filter #(not (seq (:errors %))) )
|
||||
(map (fn [{:keys [description-original status high-level-category amount account-id date]}]
|
||||
(map (fn [{:keys [description-original company-id status high-level-category amount account-id date]}]
|
||||
{:description-original description-original
|
||||
:date date
|
||||
:status status
|
||||
:high-level-category high-level-category
|
||||
:amount amount
|
||||
:company-id company-id
|
||||
:account-id account-id}))))]
|
||||
|
||||
(manual-import raw-transactions company-id)
|
||||
(manual-import raw-transactions)
|
||||
|
||||
{:status 200
|
||||
:body (pr-str {:imported (count raw-transactions)
|
||||
|
||||
@@ -90,7 +90,7 @@
|
||||
(catch Exception e
|
||||
(println e)))))
|
||||
|
||||
(defn manual-import [manual-transactions company-id]
|
||||
(defn manual-import [manual-transactions]
|
||||
(let [transformed-transactions (->> manual-transactions
|
||||
(filter #(= "posted" (:status %)))
|
||||
(group-by #(select-keys % [:date :description-original :amount]))
|
||||
@@ -99,8 +99,9 @@
|
||||
|
||||
(mapcat (fn [transaction-group]
|
||||
(map
|
||||
(fn [index {:keys [date description-original high-level-category amount account-id] :as transaction}]
|
||||
(fn [index {:keys [date description-original high-level-category amount account-id company-id] :as transaction}]
|
||||
{:id (str date "-" account-id "-" description-original "-" amount "-" index "-" company-id)
|
||||
:company-id company-id
|
||||
:bank-account-id account-id
|
||||
:date (time/unparse date "YYYY-MM-dd")
|
||||
:amount {:amount amount}
|
||||
@@ -111,7 +112,7 @@
|
||||
|
||||
transaction-group))))]
|
||||
(println "importing manual transactions" transformed-transactions)
|
||||
(import-transactions transformed-transactions (constantly company-id) :bank-account-id)))
|
||||
(import-transactions transformed-transactions :company-id :bank-account-id)))
|
||||
|
||||
(defn do-import []
|
||||
(let [transactions (client/get-transactions)
|
||||
|
||||
@@ -225,10 +225,7 @@
|
||||
]])))
|
||||
|
||||
[:div.is-pulled-right
|
||||
[:button.button.is-danger {:disabled (if current-company
|
||||
""
|
||||
"disabled")
|
||||
:on-click (dispatch-event [::manual-yodlee-import])}
|
||||
[:button.button.is-danger {:on-click (dispatch-event [::manual-yodlee-import])}
|
||||
"Manual Yodlee Import"]]))
|
||||
[transaction-table {:id :transactions
|
||||
:params (re-frame/subscribe [::params])
|
||||
|
||||
Reference in New Issue
Block a user