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