Adding vendor import stuff.
This commit is contained in:
@@ -36,7 +36,10 @@
|
||||
[:and
|
||||
[:= :exist.invoice-number :v.invoice-number]
|
||||
[:= :exist.company-id :v.company-id]
|
||||
[:= :exist.vendor-id :v.vendor-id]]]
|
||||
[:or [:= :exist.vendor-id :v.vendor-id]
|
||||
[:and
|
||||
[:= :exist.vendor-id nil]
|
||||
[:= :v.vendor-id nil]]]]]
|
||||
:where [:= :exist.id nil] }] })))))
|
||||
0
|
||||
(partition-all 2000 rows))))
|
||||
|
||||
@@ -40,6 +40,7 @@
|
||||
(let [[id] (-> (sql/build :insert-into :vendors
|
||||
:values [(unparse data)])
|
||||
execute!)]
|
||||
(println "inserted vendor: " data ", id " id)
|
||||
(get-by-id id)))
|
||||
|
||||
(defn find-with-reminders []
|
||||
|
||||
@@ -27,10 +27,16 @@
|
||||
(defn parse-invoice-number [{:keys [invoice-number]}]
|
||||
(or invoice-number ""))
|
||||
|
||||
(defn parse-vendor [{:keys [vendor-name]} vendors]
|
||||
(if-let [id (:id (vendors vendor-name))]
|
||||
id
|
||||
(throw (Exception. (str "Vendor '" vendor-name "' not found.")))))
|
||||
(defn parse-vendor [{:keys [vendor-name check]} vendors]
|
||||
(let [id (:id (vendors vendor-name))]
|
||||
(cond id
|
||||
id
|
||||
|
||||
(= "Cash" check)
|
||||
nil
|
||||
|
||||
:else
|
||||
(throw (Exception. (str "Vendor '" vendor-name "' not found."))))))
|
||||
|
||||
(defn parse-amount [i]
|
||||
(try
|
||||
@@ -127,6 +133,11 @@
|
||||
(map (parse-or-error :total parse-amount))
|
||||
(map (parse-or-error :date parse-date)))
|
||||
error-rows (filter :errors rows)
|
||||
vendors-not-found (->> rows
|
||||
(filter #(and (nil? (:vendor-id %))
|
||||
(not= "Cash" (:check %))))
|
||||
(map :vendor-name)
|
||||
set)
|
||||
insert-rows (vec (->> (filter #(not (seq (:errors %))) rows)
|
||||
(map (fn [{:keys [vendor-id total company-id amount date invoice-number]}]
|
||||
{:vendor-id vendor-id
|
||||
@@ -138,13 +149,15 @@
|
||||
:date date}))))
|
||||
|
||||
inserted-row-count (invoices/upsert-multi! insert-rows)
|
||||
already-imported-count (- (count insert-rows) inserted-row-count)]
|
||||
already-imported-count (- (count insert-rows) inserted-row-count)
|
||||
]
|
||||
|
||||
|
||||
|
||||
{:status 200
|
||||
:body (pr-str {:imported inserted-row-count
|
||||
:already-imported already-imported-count
|
||||
:vendors-not-found vendors-not-found
|
||||
:errors (map #(dissoc % :date) error-rows)})
|
||||
:headers {"Content-Type" "application/edn"}}))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user