several fixes.

This commit is contained in:
Bryce Covert
2020-05-14 07:00:59 -07:00
parent 55960888cf
commit aa6ed8355b
9 changed files with 100 additions and 15 deletions

View File

@@ -225,3 +225,31 @@
[]
rows)]
@(d/transact conn txes)))
(defn cash-flow-simple []
(->> (d/query {:query {:find '[?account-type-ident ?date ?debit ?credit]
:in '[$ ?client]
:where ['[?j :journal-entry/line-items ?je]
'[?j :journal-entry/date ?date]
'[?je :journal-entry-line/account ?a]
'[(get-else $ ?je :journal-entry-line/debit 0.0) ?debit]
'[(get-else $ ?je :journal-entry-line/credit 0.0) ?credit]
'[?a :account/type ?account-type]
'[?account-type :db/ident ?account-type-ident]]}
:args [(d/db (d/connect uri)) "CBC"]})
(reduce
(fn [result [account-type date debit credit]]
(let [date (clj-time.coerce/from-date date)]
(let [year-month (str (clj-time.core/year date) "-" (clj-time.core/month date))]
(-> result
(update-in [year-month account-type :debit]
(fn [existing-debit]
(+ (or existing-debit 0.0)
debit)))
(update-in [year-month account-type :credit]
(fn [existing-credit]
(+ (or existing-credit 0.0)
credit)))
(update-in [year-month account-type :count] #(inc (or % 0)))))))
{})))