reimplemented import
This commit is contained in:
@@ -72,12 +72,7 @@
|
||||
(catch Exception e
|
||||
(throw (Exception. (str "Could not parse account from value '" (:bank-account-id i) "'") e)))))
|
||||
|
||||
(defn parse-client-id [i]
|
||||
(try
|
||||
(Long/parseLong (second
|
||||
(re-matches #"[^0-9,\\-]*([0-9,\\-]+)[^0-9,]*" (:client-id i))))
|
||||
(catch Exception e
|
||||
(throw (Exception. (str "Could not parse client from value '" (:client-id i) "'") e)))))
|
||||
|
||||
|
||||
(defn parse-date [{:keys [raw-date]}]
|
||||
(try
|
||||
@@ -94,7 +89,7 @@
|
||||
:details (str e)})))))
|
||||
|
||||
(defn parse-invoice-rows [excel-rows]
|
||||
(let [columns [:raw-date :vendor-name :check :location :invoice-number :amount :client :bill-entered :bill-rejected :added-on :exported-on :default-expense-account]
|
||||
(let [columns [:raw-date :vendor-name :check :location :invoice-number :amount :client-name :bill-entered :bill-rejected :added-on :exported-on :default-expense-account]
|
||||
all-vendors (by :vendor/name (d-vendors/get-graphql {}))
|
||||
all-clients (d-clients/get-all)
|
||||
all-clients (merge (by :client/code all-clients) (by :client/name all-clients))
|
||||
@@ -154,29 +149,31 @@
|
||||
(POST "/batch-upload"
|
||||
{{: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 :bank-account-id :client-id]
|
||||
(let [columns [:status :raw-date :description-original :high-level-category nil nil :amount nil nil nil nil nil :bank-account-code :client-code]
|
||||
all-clients (d-clients/get-all)
|
||||
all-bank-accounts (mapcat :client/bank-accounts all-clients)
|
||||
all-clients (merge (by :client/code all-clients) (by :client/name all-clients))
|
||||
all-bank-accounts (merge (by :bank-account/code all-bank-accounts))
|
||||
rows (->> (str/split data #"\n" )
|
||||
(drop 1)
|
||||
(map #(str/split % #"\t"))
|
||||
(map #(into {} (filter identity (map (fn [c k] [k c] ) % columns))))
|
||||
|
||||
(map (parse-or-error :amount parse-amount))
|
||||
(map (parse-or-error :bank-account-id parse-account-id))
|
||||
(map (parse-or-error :client-id parse-client-id))
|
||||
(map (parse-or-error :date parse-date)))
|
||||
error-rows (filter :errors rows)
|
||||
_ (println "importing raw transactions" rows)
|
||||
|
||||
raw-transactions (vec (->> rows
|
||||
(filter #(not (seq (:errors %))) )
|
||||
(map (fn [{:keys [description-original client-id status high-level-category amount bank-account-id date]}]
|
||||
(map (fn [{:keys [description-original client-code status high-level-category amount bank-account-code date]}]
|
||||
{:description-original description-original
|
||||
:date date
|
||||
:status status
|
||||
:high-level-category high-level-category
|
||||
:amount amount
|
||||
:client-id client-id
|
||||
:bank-account-id bank-account-id}))))]
|
||||
:client-id (:db/id (all-clients client-code))
|
||||
:bank-account-id (:db/id (all-bank-accounts bank-account-code))}))))]
|
||||
|
||||
(manual-import raw-transactions)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user