adding default expense account to export
This commit is contained in:
@@ -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 :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]
|
||||
(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 :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))]
|
||||
(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 :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]
|
||||
:left-join [[:invoices :exist]
|
||||
[:and
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
(defn assign-defaults! []
|
||||
(j/db-do-prepared (get-conn)
|
||||
(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]]
|
||||
:join [[:vendors :v]
|
||||
[:= :v.id :i.vendor-id]]
|
||||
|
||||
Reference in New Issue
Block a user