customized transactions.

This commit is contained in:
Bryce Covert
2020-04-30 07:22:39 -07:00
parent 8043fb0b81
commit 4a6aeaab8f
18 changed files with 184 additions and 126 deletions

View File

@@ -41,8 +41,17 @@
(defn expense-account? [account]
(= :account-type/expense (:db/ident (:account/type account))))
(defn account-name [account client]
(let [overriden-name (->>
(:account/client-overrides account)
(filter (fn [co]
(= (:db/id (:account-client-override/client co)) (:db/id client))))
(map :account-client-override/name)
first)]
(defn roll-up [results]
(or overriden-name (:account/name account))))
(defn roll-up [client results]
(->> results
(mapcat :journal-entry/line-items)
(group-by (juxt :journal-entry-line/account :journal-entry-line/location))
@@ -51,9 +60,10 @@
#_(when-not (or (:bank-account/name account) (:account/name account))
(println "WARNING " account line-items))
(conj result
{:name (str (or (:bank-account/name account) (:account/name account)) (when-not (#{"A" } location)
(str
"-" location)))
{:name (str (or (:bank-account/name account) (account-name account client))
(when-not (#{"A" } location)
(str
"-" location)))
:location location
:id (str (:db/id account) "-" location)
:numeric-code (or (:account/numeric-code account)
@@ -87,6 +97,7 @@
(defn get-balance-sheet [context args value]
(let [args (assoc args :id (:id context))
client (d-clients/get-by-id (:client_id args))
[results] (l/get-graphql {:client-id (:client_id args)
:date-range {:end (coerce/to-date (:date args))}
:count Integer/MAX_VALUE})
@@ -96,12 +107,13 @@
:to-date (coerce/to-date (time/minus (:date args) (time/years 1)))
:count Integer/MAX_VALUE})]
(->graphql
{:balance-sheet-accounts (roll-up results)
:comparable-balance-sheet-accounts (roll-up comparable-results)})))
{:balance-sheet-accounts (roll-up client results)
:comparable-balance-sheet-accounts (roll-up client comparable-results)})))
(defn get-profit-and-loss [context args value]
(let [args (assoc args :id (:id context))
client (d-clients/get-by-id (:client_id args))
pnl (fn [from-date to-date]
(println "FROM" from-date to-date)
(let [[starting-results] (l/get-graphql {:client-id (:client_id args)
@@ -112,8 +124,8 @@
[ending-results] (l/get-graphql {:client-id (:client_id args)
:date-range {:end (coerce/to-date to-date)}
:count Integer/MAX_VALUE})
starting-accounts (by :id (roll-up starting-results))
ending-accounts (by :id (roll-up ending-results))]
starting-accounts (by :id (roll-up client starting-results))
ending-accounts (by :id (roll-up client ending-results))]
(reduce-kv
(fn [results k v]
(conj results (update v :amount (fn [amt]

View File

@@ -43,7 +43,7 @@
:journal-entry/vendor (:db/id (:invoice/vendor entity))
:journal-entry/amount (:invoice/total entity)
:journal-entry/line-items (into [{:journal-entry-line/account (a/get-account-by-numeric-code-and-sets 2110 ["default"])
:journal-entry/line-items (into [{:journal-entry-line/account (:db/id (a/get-account-by-numeric-code-and-sets 2110 ["default"]))
:journal-entry-line/location "A"
:journal-entry-line/credit (:invoice/total entity)}]
(map (fn [ea]
@@ -138,7 +138,7 @@
(doseq [d-tx d-txs]
#_(println "updating general-ledger " d-tx)
(println "updating general-ledger " d-tx)
@(d/transact (d/connect uri) [d-tx]))))
(def break (atom false))