removed bad cash flow

This commit is contained in:
Bryce Covert
2020-05-20 06:49:20 -07:00
parent 700d78fc75
commit 3e0f6e2a0a

View File

@@ -226,73 +226,7 @@
rows)]
@(d/transact conn txes)))
(defn cash-flow-simple []
(let [total-cash (reduce
(fn [total [credit debit]]
(- (+ total credit)
debit))
0.0
(d/query {:query {:find '[?debit ?credit]
:in '[$ ?client]
:where ['[?j :journal-entry/client ?c]
'[?c :client/code ?client]
'[?j :journal-entry/line-items ?je]
'[?je :journal-entry-line/account ?ba]
'[?ba :bank-account/type :bank-account-type/check]
'[(get-else $ ?je :journal-entry-line/debit 0.0) ?debit]
'[(get-else $ ?je :journal-entry-line/credit 0.0) ?credit]]}
:args [(d/db (d/connect uri)) "CBC"]}))
bills-due-soon (d/query {:query {:find '[?due ?outstanding]
:in '[$ ?client ?due-before]
:where ['[?i :invoice/client ?c]
'[?c :client/code ?client]
'[?i :invoice/status :invoice-status/unpaid]
'[?i :invoice/due ?due]
'[(<= ?due ?due-before)]
'[?i :invoice/outstanding-balance ?outstanding]]}
:args [(d/db (d/connect uri)) "CBC" (c/to-date (t/plus (auto-ap.time/local-now) (t/days 7)))]})
outstanding-checks (reduce
+
0.0
(map first (d/query {:query {:find '[?amount]
:in '[$ ?client ?due-before]
:where ['[?p :payment/client ?c]
'[?c :client/code ?client]
'[?p :payment/status :payment-status/pending]
'[?p :payment/amount ?amount]
'(or
[?p :payment/type :payment-type/debit]
[?p :payment/type :payment-type/check])]}
:args [(d/db (d/connect uri)) "CBC" (c/to-date (t/plus (auto-ap.time/local-now) (t/days 7)))]})))]
[total-cash bills-due-soon outstanding-checks])
#_(->> (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)))))))
{})))
(defn attach-signature [client-code filename]
@(d/transact (d/connect uri)