started on expense accounts.

This commit is contained in:
Bryce Covert
2018-05-31 18:43:12 -07:00
parent d38059cb1d
commit b98d00a196
14 changed files with 128 additions and 12 deletions

View 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]] }] })))

View File

@@ -22,6 +22,7 @@
:secondary-contact
:secondary-email
:secondary-phone
:default-expense-account
:data])
(defn unparse [x]