slightly improved excel import.

This commit is contained in:
Bryce Covert
2019-03-20 22:35:43 -07:00
parent 2727573a96
commit a55e6d890f
3 changed files with 56 additions and 35 deletions

View File

@@ -22,9 +22,12 @@
n))))
(defn assoc-client-code [i]
(-> i
(assoc :client-code (first (str/split (:location i) #"-" )))
(assoc :default-location (second (str/split (:location i) #"-" )))))
(let [[client-code default-location] (str/split (:location i) #"-" )]
(cond-> i
client-code (assoc :client-code client-code)
default-location (assoc :default-location default-location)
(not client-code) (update :errors conj {:info "No client code found"})
(not default-location) (update :errors conj {:info "No default location found"}))))
(defn parse-client [{:keys [client-code client]} clients]
(if-let [id (:db/id (or (clients client-code)
@@ -105,6 +108,8 @@
(map (parse-or-error :invoice-number parse-invoice-number))
(map (parse-or-error :total parse-amount))
(map (parse-or-error :date parse-date)))]
(println "ROWS" rows)
rows))
(defn invoice-rows->transaction [rows]
@@ -229,6 +234,7 @@
:bank-account-id (:db/id (all-bank-accounts bank-account-code))}))))]
(manual-import raw-transactions)
{:status 200
:body (pr-str {:imported (count raw-transactions)
@@ -272,10 +278,11 @@
set)
inserted-rows @(d/transact (d/connect uri) (invoice-rows->transaction (:new grouped-rows)))]
{:status 200
:body (pr-str {:imported (count (:new grouped-rows))
:already-imported (count (:exists grouped-rows))
:vendors-not-found vendors-not-found
:errors (:error grouped-rows)})
:errors (map #(dissoc % :date) (:error grouped-rows))})
:headers {"Content-Type" "application/edn"}}))))
wrap-secure))