started on expense accounts.
This commit is contained in:
31
src/clj/auto_ap/db/invoices_expense_accounts.clj
Normal file
31
src/clj/auto_ap/db/invoices_expense_accounts.clj
Normal file
@@ -0,0 +1,31 @@
|
||||
(ns auto-ap.db.invoices-expense-accounts
|
||||
(:require [honeysql.core :as sql]
|
||||
[clojure.java.jdbc :as j]
|
||||
[auto-ap.db.utils :refer [clj->db kebab->snake db->clj get-conn query] :as utils]
|
||||
[honeysql.helpers :as helpers]))
|
||||
(defn get-missing []
|
||||
(query {:select [:i.id :v.default-expense-account :i.total]
|
||||
:from [[:invoices :i]]
|
||||
:join [[:vendors :v]
|
||||
[:= :v.id :i.vendor-id]]
|
||||
:left-join [[:invoices-expense-accounts :nonexist]
|
||||
[:= :i.id :nonexist.invoice-id]]
|
||||
:where [:and [:= :nonexist.id nil]
|
||||
[:not= :v.default-expense-account nil]] }))
|
||||
|
||||
(defn get-for-invoice [id]
|
||||
(query {:select [:*]
|
||||
:from [:invoices-expense-accounts]
|
||||
:where [:= :invoice-id id]}))
|
||||
|
||||
(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]
|
||||
:from [[:invoices :i]]
|
||||
:join [[:vendors :v]
|
||||
[:= :v.id :i.vendor-id]]
|
||||
:left-join [[:invoices-expense-accounts :nonexist]
|
||||
[:= :i.id :nonexist.invoice-id]]
|
||||
:where [:and [:= :nonexist.id nil]
|
||||
[:not= :v.default-expense-account nil]] }] })))
|
||||
@@ -22,6 +22,7 @@
|
||||
:secondary-contact
|
||||
:secondary-email
|
||||
:secondary-phone
|
||||
:default-expense-account
|
||||
:data])
|
||||
|
||||
(defn unparse [x]
|
||||
|
||||
Reference in New Issue
Block a user