You can import transactions for more than one bank account at the same time.
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)
|
||||
|
||||
Reference in New Issue
Block a user