major switch to support import from excel.

This commit is contained in:
Bryce Covert
2018-05-03 22:43:08 -07:00
parent ea1e43d981
commit a526d2da1b
5 changed files with 206 additions and 51 deletions

View File

@@ -1,5 +1,5 @@
(ns auto-ap.db.invoices
(:require [auto-ap.db.utils :refer [clj->db db->clj get-conn query] :as utils]
(:require [auto-ap.db.utils :refer [clj->db kebab->snake db->clj get-conn query] :as utils]
[auto-ap.parse :as parse]
[auto-ap.db.companies :as companies]
[auto-ap.db.vendors :as vendors]
@@ -17,6 +17,26 @@
:invoices
(map clj->db rows)))
(defn upsert-multi! [rows]
(let [k (vec (map #(keyword (kebab->snake (name %))) [:company-id :vendor-id :invoice-number :total :date :imported]))
column-names (str/join "," (map name k))]
(doseq [rows (partition-all 2000 rows)]
(j/db-do-prepared (get-conn)
(sql/format {:with [[[:v (str "(" column-names ")")]
(helpers/values (->> rows
(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 ]
:from [:v]
:left-join [[:invoices :exist]
[:and
[:= :exist.invoice-number :v.invoice-number]
[:= :exist.company-id :v.company-id]
[:= :exist.vendor-id :v.vendor-id]]]
:where [:= :exist.id nil] }] })))))
(def base-query (sql/build :select :invoices.*
:from :invoices))
@@ -75,8 +95,7 @@
(defn base-graphql [{:keys [imported company-id]}]
(cond-> base-query
(not (nil? imported)) (helpers/merge-where [:= :imported imported])
(not (nil? company-id)) (helpers/merge-where [:= :company-id company-id])
))
(not (nil? company-id)) (helpers/merge-where [:= :company-id company-id])))
(defn get-graphql [{:keys [start sort-by asc] :as args}]
(query

View File

@@ -98,7 +98,7 @@
(doseq [{:keys [vendor-name id email subject body]} reminders]
(when email
(println "Sending email to" email)
(ses/send-email :destination {:to-addresses [email]}
#_(ses/send-email :destination {:to-addresses [email]}
:source (:invoice-email env)
:message {:subject subject
:body {:html (str "<h1>Hello " vendor-name ",</h1><p>" body "</p> <p> - Integreat. </p>")