company identification.
This commit is contained in:
@@ -11,7 +11,17 @@
|
||||
[ring.middleware.reload :refer [wrap-reload]]
|
||||
[ring.middleware.json :refer [wrap-json-response]]
|
||||
[ring.middleware.edn :refer [wrap-edn-params]]
|
||||
[clojure.java.jdbc :as j]))
|
||||
[clojure.java.jdbc :as j]
|
||||
[clj-fuzzy.metrics :as m]
|
||||
[auto-ap.db.companies :as companies]))
|
||||
(defn best-match [companies company-identifier]
|
||||
(->> companies
|
||||
(map (fn [company]
|
||||
[company (apply min (map #(m/jaccard (.toLowerCase company-identifier) %) (:matches company)))]))
|
||||
(filter #(< (second %) 0.25))
|
||||
(sort-by second)
|
||||
|
||||
ffirst))
|
||||
|
||||
(defroutes app-routes
|
||||
(GET "/" [] (response/resource-response "index.html" {:root "public"}))
|
||||
@@ -37,25 +47,25 @@
|
||||
:headers {"Content-Type" "application/edn"}})
|
||||
(POST "/api/invoices/approve" []
|
||||
(invoices/approve)
|
||||
(println (invoices/get-pending))
|
||||
{:status 200
|
||||
:body (pr-str (invoices/get-pending))
|
||||
:headers {"Content-Type" "application/edn"}})
|
||||
(POST "/api/invoices/reject" []
|
||||
(invoices/reject)
|
||||
(println (invoices/get-pending))
|
||||
{:status 200
|
||||
:body (pr-str (invoices/get-pending))
|
||||
:headers {"Content-Type" "application/edn"}})
|
||||
(POST "/pdf-upload"
|
||||
{{ files "file"} :params :as params}
|
||||
(let [{:keys [filename tempfile]} files
|
||||
existing-invoices (invoices/get-all)]
|
||||
(println existing-invoices)
|
||||
existing-invoices (invoices/get-all)
|
||||
companies (companies/get-all)]
|
||||
(invoices/insert-multi!
|
||||
(for [{:keys [total date invoice-number customer-identifier vendor] :as row}
|
||||
(parse/parse-file (.getPath tempfile) filename)]
|
||||
(assoc row
|
||||
:company (:name (best-match companies customer-identifier))
|
||||
|
||||
:imported false
|
||||
:potential-duplicate (boolean (seq (filter #(and (= vendor (:vendor %))
|
||||
(= invoice-number (:invoice-number %)))
|
||||
|
||||
Reference in New Issue
Block a user