improved import

This commit is contained in:
Bryce Covert
2018-04-06 17:54:05 -07:00
parent 401ac6c149
commit 6e573a0a57
3 changed files with 13 additions and 22 deletions

View File

@@ -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)))))