making sysco and mama lus work.
This commit is contained in:
@@ -159,9 +159,8 @@
|
||||
))
|
||||
|
||||
|
||||
(defn import-uploaded-invoice [imports]
|
||||
(defn import-uploaded-invoice [client forced-location imports]
|
||||
(let [clients (d-clients/get-all)
|
||||
|
||||
transactions (reduce (fn [result {:keys [invoice-number customer-identifier total date vendor-code text full-text] :as info}]
|
||||
(println "searching for" vendor-code)
|
||||
(let [[matching-vendor default-expense-account] (->> (d/query
|
||||
@@ -177,9 +176,21 @@
|
||||
:customer-identifier customer-identifier
|
||||
:vendor-code vendor-code})))
|
||||
_ (println "matching" customer-identifier "-" matching-vendor)
|
||||
matching-client (parse/best-match clients customer-identifier)
|
||||
_ (println "invoice \"" invoice-number "\"matches client" (:client/name matching-client))
|
||||
matching-location (parse/best-location-match matching-client text full-text)
|
||||
matching-client (or (and customer-identifier
|
||||
(parse/best-match clients customer-identifier))
|
||||
(if client
|
||||
(first (filter (fn [c]
|
||||
(= (:db/id c) (Long/parseLong client)))
|
||||
clients))))
|
||||
_ (when-not matching-client
|
||||
(throw (ex-info (str "No client found in file. Select a client first.")
|
||||
{:invoice-number invoice-number
|
||||
:customer-identifier customer-identifier
|
||||
:vendor-code vendor-code})))
|
||||
_ (println "invoice \"" invoice-number "\"matches client " (:client/name matching-client) " (" (:db/id matching-client) ")")
|
||||
matching-location (or (when-not (str/blank? forced-location)
|
||||
forced-location)
|
||||
(parse/best-location-match matching-client text full-text))
|
||||
[existing-id existing-outstanding-balance existing-status import-status] (when (and matching-client matching-location)
|
||||
(try
|
||||
(->> (d/query
|
||||
@@ -277,16 +288,20 @@
|
||||
|
||||
(context "/invoices" []
|
||||
(POST "/upload"
|
||||
{{ files "file"} :params :as params}
|
||||
{{ files "file"
|
||||
client "client"
|
||||
location "location"} :params :as params}
|
||||
(let [{:keys [filename tempfile]} files]
|
||||
(println params)
|
||||
(try
|
||||
(import-uploaded-invoice (parse/parse-file (.getPath tempfile) filename))
|
||||
(import-uploaded-invoice client location (parse/parse-file (.getPath tempfile) filename))
|
||||
{:status 200
|
||||
:body (pr-str {})
|
||||
:headers {"Content-Type" "application/edn"}}
|
||||
(catch Exception e
|
||||
{:status 500
|
||||
:body (pr-str {:message (.getMessage e)
|
||||
:error (.toString e)
|
||||
:data (ex-data e)})
|
||||
:headers {"Content-Type" "application/edn"}}))
|
||||
))
|
||||
|
||||
Reference in New Issue
Block a user