now invoices are by vendor and company
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
(:require [auto-ap.db.utils :refer [clj->db db->clj get-conn]]
|
||||
[auto-ap.parse :as parse]
|
||||
[auto-ap.entities.companies :as company]
|
||||
[auto-ap.entities.vendors :as vendor]
|
||||
[clojure.java.jdbc :as j]))
|
||||
|
||||
(defn insert-multi! [rows]
|
||||
@@ -29,12 +30,16 @@
|
||||
(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]
|
||||
(defn import [parsed-invoices companies vendors]
|
||||
(insert-multi!
|
||||
(for [{:keys [total date invoice-number customer-identifier vendor] :as row} parsed-invoices]
|
||||
(for [{:keys [total date invoice-number customer-identifier vendor-code] :as row} parsed-invoices]
|
||||
(do
|
||||
(println "VENDORS" vendors)
|
||||
(println "VENDOR" (::vendor-id (first (filter #(= (::vendor/code %) vendor-code) vendors))))
|
||||
|
||||
(assoc row
|
||||
:company-id (::company/id (parse/best-match companies customer-identifier))
|
||||
:imported false
|
||||
:potential-duplicate false)))))
|
||||
(dissoc (assoc row
|
||||
:company-id (::company/id (parse/best-match companies customer-identifier))
|
||||
:vendor-id (::vendor/id (first (filter #(= (::vendor/code %) vendor-code) vendors)))
|
||||
:imported false
|
||||
:potential-duplicate false)
|
||||
:vendor-code)))))
|
||||
|
||||
Reference in New Issue
Block a user