Merge branch 'master' into add-general-ledger

This commit is contained in:
BC
2019-03-23 12:03:50 -07:00
9 changed files with 260 additions and 117 deletions

View File

@@ -22,14 +22,25 @@
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]
(defn parse-client [{:keys [client-code client default-location]} clients]
(if-let [id (:db/id (or (clients client-code)
(clients client)))]
id
(do
(println "FOUND CLIENT" (or (clients client-code)
(clients client)))
(when (not ((set (:client/locations (or (clients client-code)
(clients client))))
default-location))
(throw (Exception. (str "Location '" default-location "' not found for client '" client-code "'.")))
)
id)
(throw (Exception. (str "Client code '" client-code "' and client named '" client "' not found.")))))
(defn parse-invoice-number [{:keys [invoice-number]}]
@@ -105,6 +116,8 @@
(map (parse-or-error :invoice-number parse-invoice-number))
(map (parse-or-error :total parse-amount))
(map (parse-or-error :date parse-date)))]
rows))
(defn invoice-rows->transaction [rows]
@@ -229,6 +242,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 +286,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))