several fixes.
This commit is contained in:
@@ -17,7 +17,9 @@
|
||||
[ring.middleware.json :refer [wrap-json-response]]
|
||||
[compojure.core :refer [GET POST context defroutes
|
||||
wrap-routes]]
|
||||
[clojure.string :as str]))
|
||||
[clojure.string :as str]
|
||||
[clojure.java.io :as io]
|
||||
[clojure.data.csv :as csv]))
|
||||
|
||||
(defn reset-id [i]
|
||||
(update i :invoice-number
|
||||
@@ -273,6 +275,20 @@
|
||||
|
||||
|
||||
|
||||
(defn import-transactions-cleared-against [file]
|
||||
(let [[header & rows] (-> file (io/reader) csv/read-csv)
|
||||
txes (transduce
|
||||
(comp
|
||||
(filter (fn [[transaction-id cleared-against]]
|
||||
(d/pull (d/db (d/connect uri)) '[:transaction/amount] (Long/parseLong transaction-id))))
|
||||
(map (fn [[transaction-id cleared-against]]
|
||||
{:db/id (Long/parseLong transaction-id)
|
||||
:transaction/cleared-against cleared-against})))
|
||||
conj
|
||||
[]
|
||||
rows)]
|
||||
@(d/transact (d/connect uri) txes)))
|
||||
|
||||
(defroutes routes
|
||||
(wrap-routes
|
||||
(context "/" []
|
||||
@@ -346,8 +362,8 @@
|
||||
:body (pr-str {:message (.getMessage e)
|
||||
:error (.toString e)
|
||||
:data (ex-data e)})
|
||||
:headers {"Content-Type" "application/edn"}}))
|
||||
))
|
||||
:headers {"Content-Type" "application/edn"}}))))
|
||||
|
||||
(POST "/upload-integreat"
|
||||
{{:keys [excel-rows]} :edn-params user :identity}
|
||||
(assert-admin user)
|
||||
@@ -369,20 +385,36 @@
|
||||
:else
|
||||
:new))
|
||||
parsed-invoice-rows)
|
||||
|
||||
|
||||
vendors-not-found (->> parsed-invoice-rows
|
||||
(filter #(and (nil? (:vendor-id %))
|
||||
(not= "Cash" (:check %))))
|
||||
(map :vendor-name)
|
||||
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 (map #(dissoc % :date) (:error grouped-rows))})
|
||||
:headers {"Content-Type" "application/edn"}}))))
|
||||
:headers {"Content-Type" "application/edn"}})))
|
||||
(POST "/transactions/cleared-against"
|
||||
{{files :file
|
||||
files-2 "file"} :params :as params
|
||||
user :identity}
|
||||
(let [files (or files files-2)
|
||||
_ (println files)
|
||||
{:keys [filename tempfile]} files]
|
||||
(assert-admin user)
|
||||
(try
|
||||
(import-transactions-cleared-against (.getPath tempfile))
|
||||
{:status 200
|
||||
:body (pr-str {})
|
||||
:headers {"Content-Type" "application/edn"}}
|
||||
(catch Exception e
|
||||
(println e)
|
||||
{:status 500
|
||||
:body (pr-str {:message (.getMessage e)
|
||||
:error (.toString e)
|
||||
:data (ex-data e)})
|
||||
:headers {"Content-Type" "application/edn"}})))))
|
||||
wrap-secure))
|
||||
|
||||
Reference in New Issue
Block a user