improved import
This commit is contained in:
@@ -43,16 +43,7 @@
|
||||
(filter #(re-find #"application/pdf" (:content-type %)) ))]
|
||||
(let [filename (str "/tmp/" (UUID/randomUUID) ".pdf")]
|
||||
(io/copy (:body pdf-stream) (io/file filename))
|
||||
(invoices/insert-multi!
|
||||
(for [{:keys [total date invoice-number customer-identifier vendor] :as row}
|
||||
(parse/parse-file filename filename)]
|
||||
(do
|
||||
(println row)
|
||||
(assoc row
|
||||
:company (:name (parse/best-match companies customer-identifier))
|
||||
:imported false
|
||||
:potential-duplicate false))))
|
||||
|
||||
(invoices/import (parse/parse-file filename filename) companies)
|
||||
(io/delete-file filename))))))
|
||||
(sqs/delete-message (assoc message :queue-url queue-url )))))
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
(ns auto-ap.db.invoices
|
||||
(:require [clojure.java.jdbc :as j]
|
||||
[auto-ap.parse :as parse]
|
||||
[auto-ap.db.utils :refer [clj->db db->clj get-conn]]))
|
||||
|
||||
(defn insert-multi! [rows]
|
||||
@@ -26,3 +27,13 @@
|
||||
(if company
|
||||
(map db->clj (j/query (get-conn) ["SELECT * FROM invoices WHERE (imported=false or imported is null) AND company_id = ?" (Integer/parseInt company)]))
|
||||
(map db->clj (j/query (get-conn) "SELECT * FROM invoices WHERE imported=false or imported is null"))))
|
||||
|
||||
(defn import [parsed-invoices companies]
|
||||
(insert-multi!
|
||||
(for [{:keys [total date invoice-number customer-identifier vendor] :as row} parsed-invoices]
|
||||
(do
|
||||
(println row)
|
||||
(assoc row
|
||||
:company (:name (parse/best-match companies customer-identifier))
|
||||
:imported false
|
||||
:potential-duplicate false)))))
|
||||
|
||||
@@ -40,19 +40,8 @@
|
||||
(POST "/upload"
|
||||
{{ files "file"} :params :as params}
|
||||
(let [{:keys [filename tempfile]} files
|
||||
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-id (:id (parse/best-match companies customer-identifier))
|
||||
|
||||
:imported false
|
||||
:potential-duplicate (boolean (seq (filter #(and (= vendor (:vendor %))
|
||||
(= invoice-number (:invoice-number %)))
|
||||
existing-invoices)))
|
||||
)))
|
||||
(invoices/import (parse/parse-file (.getPath tempfile) filename) companies)
|
||||
{:status 200
|
||||
:body (pr-str (invoices/get-pending ((:query-params params ) "company")))
|
||||
:headers {"Content-Type" "application/edn"}}))
|
||||
|
||||
Reference in New Issue
Block a user