Resets the database, now using real locations for each vendor, and matching against those locations.

This commit is contained in:
BC
2018-06-22 12:12:03 -07:00
parent 1ac76d4ad1
commit e738349cec
9 changed files with 277 additions and 8 deletions

View File

@@ -11,7 +11,7 @@
[honeysql.core :as sql]
[honeysql.helpers :as helpers]))
(def all-keys #{:company-id :vendor-id :imported :potential-duplicate :total :invoice-number :date :outstanding-balance})
(def all-keys #{:company-id :vendor-id :imported :potential-duplicate :total :invoice-number :date :outstanding-balance :default-location})
(defn insert-multi! [rows]
(j/insert-multi! (get-conn)
@@ -20,7 +20,7 @@
(defn upsert-multi! [rows]
(let [k (vec (map #(keyword (kebab->snake (name %))) [:company-id :vendor-id :invoice-number :total :date :imported :status :outstanding-balance]))
(let [k (vec (map #(keyword (kebab->snake (name %))) [:company-id :vendor-id :invoice-number :total :date :imported :status :outstanding-balance :default-location]))
column-names (str/join "," (map name k))]
(reduce
(fn [affected rows]
@@ -31,7 +31,7 @@
(map clj->db )
(map (apply juxt k))))]]
:insert-into [[:invoices k]
{:select [:v.company-id :v.vendor-id :v.invoice-number :v.total (sql/raw "cast(v.date as timestamp)") :v.imported :v.status :v.outstanding-balance]
{:select [:v.company-id :v.vendor-id :v.invoice-number :v.total (sql/raw "cast(v.date as timestamp)") :v.imported :v.status :v.outstanding-balance :v.default-location]
:from [:v]
:left-join [[:invoices :exist]
[:and

View File

@@ -20,8 +20,8 @@
(defn assign-defaults! []
(j/db-do-prepared (get-conn)
(sql/format {:insert-into [[:invoices-expense-accounts [:invoice-id :expense-account-id :amount]]
{:select [:i.id :v.default-expense-account :i.total]
(sql/format {:insert-into [[:invoices-expense-accounts [:invoice-id :expense-account-id :amount :location]]
{:select [:i.id :v.default-expense-account :i.total :i.default_location]
:from [[:invoices :i]]
:join [[:vendors :v]
[:= :v.id :i.vendor-id]]

View File

@@ -20,7 +20,9 @@
n))))
(defn assoc-company-code [i]
(assoc i :company-code (first (str/split (:location i) #"-" ))))
(-> i
(assoc :company-code (first (str/split (:location i) #"-" )))
(assoc :default-location (second (str/split (:location i) #"-" )))))
(defn parse-company [{:keys [company-code company]} companies]
(if-let [id (:id (or (companies company-code)
@@ -111,12 +113,14 @@
all-companies (companies/get-all)
all-companies (merge (by :code all-companies) (by :name all-companies))
rows (->> (str/split excel-rows #"\n" )
(map #(str/split % #"\t"))
(map #(into {} (map (fn [c k] [k c] ) % columns)))
(map reset-id)
(map assoc-company-code)
(map (parse-or-error :company-id #(parse-company % all-companies)))
(map (parse-or-error :vendor-id #(parse-vendor % all-vendors)))
(map (parse-or-error :invoice-number parse-invoice-number))
@@ -129,9 +133,10 @@
(map :vendor-name)
set)
insert-rows (vec (->> (filter #(not (seq (:errors %))) rows)
(map (fn [{:keys [vendor-id total company-id amount date invoice-number]}]
(map (fn [{:keys [vendor-id total company-id amount date invoice-number default-location]}]
{:vendor-id vendor-id
:company-id company-id
:default-location default-location
:total total
:outstanding-balance total
:imported true