adding default expense account to export
This commit is contained in:
@@ -0,0 +1,2 @@
|
|||||||
|
-- 1532706413 DOWN add-default-expense-account
|
||||||
|
ALTER table invoices drop column default_expense_account;
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
-- 1532706413 UP add-default-expense-account
|
||||||
|
ALTER table invoices add column default_expense_account int;
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
6/16/17 Acme Bread NMKT-CB 3/26/56 12:00 AM $54.00 Naschmarkt X 7/31/17 8:26 AM 8/1/17 3:57 PM
|
6/16/17 Acme Bread NMKT-CB 3/26/56 12:00 AM $54.00 Naschmarkt X 7/31/17 8:26 AM 8/1/17 3:57 PM 3100
|
||||||
6/20/17 Acme Bread NMKT-CB 3/19/58 12:00 AM $54.00 Naschmarkt X 7/31/17 8:26 AM 8/1/17 3:57 PM
|
6/20/17 Acme Bread NMKT-CB 3/19/58 12:00 AM $54.00 Naschmarkt X 7/31/17 8:26 AM 8/1/17 3:57 PM
|
||||||
6/21/17 Acme Bread NMKT-CB 11/13/58 12:00 AM $54.00 Naschmarkt X 7/31/17 8:26 AM 8/1/17 3:57 PM
|
6/21/17 Acme Bread NMKT-CB 11/13/58 12:00 AM $54.00 Naschmarkt X 7/31/17 8:26 AM 8/1/17 3:57 PM
|
||||||
6/27/17 Acme Bread NMKT-CB 12/7/61 12:00 AM $54.00 Naschmarkt X 8/1/17 11:55 AM 8/1/17 3:57 PM
|
6/27/17 Acme Bread NMKT-CB 12/7/61 12:00 AM $54.00 Naschmarkt X 8/1/17 11:55 AM 8/1/17 3:57 PM
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
[honeysql.core :as sql]
|
[honeysql.core :as sql]
|
||||||
[honeysql.helpers :as helpers]))
|
[honeysql.helpers :as helpers]))
|
||||||
|
|
||||||
(def all-keys #{:company-id :vendor-id :imported :potential-duplicate :total :invoice-number :date :outstanding-balance :default-location})
|
(def all-keys #{:company-id :vendor-id :imported :potential-duplicate :total :invoice-number :date :outstanding-balance :default-location :default-expense-account})
|
||||||
|
|
||||||
(defn insert-multi! [rows]
|
(defn insert-multi! [rows]
|
||||||
(j/insert-multi! (get-conn)
|
(j/insert-multi! (get-conn)
|
||||||
@@ -20,7 +20,7 @@
|
|||||||
|
|
||||||
|
|
||||||
(defn upsert-multi! [rows]
|
(defn upsert-multi! [rows]
|
||||||
(let [k (vec (map #(keyword (kebab->snake (name %))) [:company-id :vendor-id :invoice-number :total :date :imported :status :outstanding-balance :default-location]))
|
(let [k (vec (map #(keyword (kebab->snake (name %))) [:company-id :vendor-id :invoice-number :total :date :imported :status :outstanding-balance :default-location :default-expense-account]))
|
||||||
column-names (str/join "," (map name k))]
|
column-names (str/join "," (map name k))]
|
||||||
(reduce
|
(reduce
|
||||||
(fn [affected rows]
|
(fn [affected rows]
|
||||||
@@ -31,7 +31,7 @@
|
|||||||
(map clj->db )
|
(map clj->db )
|
||||||
(map (apply juxt k))))]]
|
(map (apply juxt k))))]]
|
||||||
:insert-into [[:invoices 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 :v.default-location]
|
{: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 :v.default-expense-account]
|
||||||
:from [:v]
|
:from [:v]
|
||||||
:left-join [[:invoices :exist]
|
:left-join [[:invoices :exist]
|
||||||
[:and
|
[:and
|
||||||
|
|||||||
@@ -21,7 +21,7 @@
|
|||||||
(defn assign-defaults! []
|
(defn assign-defaults! []
|
||||||
(j/db-do-prepared (get-conn)
|
(j/db-do-prepared (get-conn)
|
||||||
(sql/format {:insert-into [[:invoices-expense-accounts [:invoice-id :expense-account-id :amount :location]]
|
(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]
|
{:select [:i.id (sql/raw "COALESCE (i.default_expense_account, v.default_expense_account)") :i.total :i.default_location]
|
||||||
:from [[:invoices :i]]
|
:from [[:invoices :i]]
|
||||||
:join [[:vendors :v]
|
:join [[:vendors :v]
|
||||||
[:= :v.id :i.vendor-id]]
|
[:= :v.id :i.vendor-id]]
|
||||||
|
|||||||
@@ -55,6 +55,13 @@
|
|||||||
(catch Exception e
|
(catch Exception e
|
||||||
(throw (Exception. (str "Could not parse total from value '" (:amount i) "'") e)))))
|
(throw (Exception. (str "Could not parse total from value '" (:amount i) "'") e)))))
|
||||||
|
|
||||||
|
(defn parse-default-expense-account [i]
|
||||||
|
(try
|
||||||
|
(when-let [default-expense-account (:default-expense-account i)]
|
||||||
|
(Integer/parseInt default-expense-account))
|
||||||
|
(catch Exception e
|
||||||
|
(throw (Exception. (str "Could not parse expense account from value '" (:default-expense-account i) "'") e)))))
|
||||||
|
|
||||||
(defn parse-account-id [i]
|
(defn parse-account-id [i]
|
||||||
(try
|
(try
|
||||||
(Integer/parseInt (second
|
(Integer/parseInt (second
|
||||||
@@ -125,7 +132,7 @@
|
|||||||
(POST "/upload-integreat"
|
(POST "/upload-integreat"
|
||||||
{{:keys [excel-rows]} :edn-params user :identity}
|
{{:keys [excel-rows]} :edn-params user :identity}
|
||||||
(assert-admin user)
|
(assert-admin user)
|
||||||
(let [columns [:raw-date :vendor-name :check :location :invoice-number :amount :company :bill-entered :bill-rejected :added-on :exported-on]
|
(let [columns [:raw-date :vendor-name :check :location :invoice-number :amount :company :bill-entered :bill-rejected :added-on :exported-on :default-expense-account]
|
||||||
|
|
||||||
all-vendors (by :name (vendors/get-all))
|
all-vendors (by :name (vendors/get-all))
|
||||||
|
|
||||||
@@ -141,6 +148,7 @@
|
|||||||
|
|
||||||
(map (parse-or-error :company-id #(parse-company % all-companies)))
|
(map (parse-or-error :company-id #(parse-company % all-companies)))
|
||||||
(map (parse-or-error :vendor-id #(parse-vendor % all-vendors)))
|
(map (parse-or-error :vendor-id #(parse-vendor % all-vendors)))
|
||||||
|
(map (parse-or-error :default-expense-account parse-default-expense-account))
|
||||||
(map (parse-or-error :invoice-number parse-invoice-number))
|
(map (parse-or-error :invoice-number parse-invoice-number))
|
||||||
(map (parse-or-error :total parse-amount))
|
(map (parse-or-error :total parse-amount))
|
||||||
(map (parse-or-error :date parse-date)))
|
(map (parse-or-error :date parse-date)))
|
||||||
@@ -151,10 +159,11 @@
|
|||||||
(map :vendor-name)
|
(map :vendor-name)
|
||||||
set)
|
set)
|
||||||
insert-rows (vec (->> (filter #(not (seq (:errors %))) rows)
|
insert-rows (vec (->> (filter #(not (seq (:errors %))) rows)
|
||||||
(map (fn [{:keys [vendor-id total company-id amount date invoice-number default-location]}]
|
(map (fn [{:keys [vendor-id total company-id amount date invoice-number default-location default-expense-account]}]
|
||||||
{:vendor-id vendor-id
|
{:vendor-id vendor-id
|
||||||
:company-id company-id
|
:company-id company-id
|
||||||
:default-location default-location
|
:default-location default-location
|
||||||
|
:default-expense-account default-expense-account
|
||||||
:total total
|
:total total
|
||||||
:outstanding-balance total
|
:outstanding-balance total
|
||||||
:imported true
|
:imported true
|
||||||
|
|||||||
Reference in New Issue
Block a user