minor fixes.

This commit is contained in:
Bryce Covert
2020-07-17 12:46:44 -07:00
parent 976cd1e7c3
commit 3737cfa628
6 changed files with 348 additions and 148 deletions

View File

@@ -58,53 +58,58 @@
(or (:db/ident (:account/type (accounts a)))
({:bank-account-type/check :account-type/asset
:bank-account-type/credit :account-type/liability}
(:db/ident (:bank-account/type (bank-accounts a))))))]
(->> (d/query
{:query {:find ['?d '?jel '?account '?location '?debit '?credit ]
:in ['$ '?client-id]
:where ['[?e :journal-entry/client ?client-id]
'[?e :journal-entry/date ?d]
'[(<= ?d #inst "2020-09-01")]
'[?e :journal-entry/line-items ?jel]
'[(get-else $ ?jel :journal-entry-line/account :account/unknown) ?account]
'[(get-else $ ?jel :journal-entry-line/debit 0.0) ?debit]
'[(get-else $ ?jel :journal-entry-line/credit 0.0) ?credit]
'[(get-else $ ?jel :journal-entry-line/location "") ?location]]
}
:args [(d/db (d/connect uri)) client-id]})
(sort-by first)
(:db/ident (:bank-account/type (bank-accounts a))))))
all-ledger-entries (->> (d/query
{:query {:find ['?d '?jel '?account '?location '?debit '?credit ]
:in ['$ '?client-id]
:where ['[?e :journal-entry/client ?client-id]
'[?e :journal-entry/date ?d]
'[(<= ?d #inst "2020-09-01")]
'[?e :journal-entry/line-items ?jel]
'[(get-else $ ?jel :journal-entry-line/account :account/unknown) ?account]
'[(get-else $ ?jel :journal-entry-line/debit 0.0) ?debit]
'[(get-else $ ?jel :journal-entry-line/credit 0.0) ?credit]
'[(get-else $ ?jel :journal-entry-line/location "") ?location]]
}
:args [(d/db (d/connect uri)) client-id]})
(sort-by first))]
(reduce
(fn [acc [_ _ account location debit credit]]
(-> acc
(update-in [[location account] :debit] (fnil + 0.0) debit)
(update-in [[location account] :credit] (fnil + 0.0) credit)
(update-in [[location account] :count] (fnil + 0) 1))
)
{})
(reduce-kv
(fn [acc [location account] {:keys [debit credit count]}]
(let [account-type (account->type account)]
(conj acc {:name (if-not (= "A" location)
(str (account->name account) "-" location)
(account->name account))
:id (str account "-" location)
:numeric_code (account->numeric-code account)
:location (or location "")
:amount (if account-type (if (#{:account-type/asset
:account-type/dividend
:account-type/expense} account-type)
(- debit credit)
(- credit debit)
)
0.0)
:account_type account-type}))
)
(reduce
(fn [acc bracket]
(println (first all-ledger-entries))
(assoc acc bracket (->> all-ledger-entries
(filter (fn [[d]]
(<= (compare d bracket) 0)))
(reduce
(fn [acc [_ _ account location debit credit]]
(-> acc
(update-in [[location account] :debit] (fnil + 0.0) debit)
(update-in [[location account] :credit] (fnil + 0.0) credit)
(update-in [[location account] :count] (fnil + 0) 1))
)
{})
(reduce-kv
(fn [acc [location account] {:keys [debit credit count]}]
(let [account-type (account->type account)]
(conj acc {:name (if-not (= "A" location)
(str (account->name account) "-" location)
(account->name account))
:id (str account "-" location)
:numeric_code (account->numeric-code account)
:location (or location "")
:amount (if account-type (if (#{:account-type/asset
:account-type/dividend
:account-type/expense} account-type)
(- debit credit)
(- credit debit)
)
0.0)
:account_type account-type}))
)
[])
#_(map (juxt :name :count (comp int :amount)))
#_(sort-by first)
))
[]))))
{}
brackets))
)
;; 9804