start of cash flow

This commit is contained in:
Bryce Covert
2020-05-16 16:08:17 -07:00
parent d5dc62cc6a
commit a7a3966f1b
6 changed files with 170 additions and 22 deletions

View File

@@ -227,7 +227,47 @@
@(d/transact conn txes)))
(defn cash-flow-simple []
(->> (d/query {:query {:find '[?account-type-ident ?date ?debit ?credit]
(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]
@@ -253,3 +293,9 @@
credit)))
(update-in [year-month account-type :count] #(inc (or % 0)))))))
{})))
(defn attach-signature [client-code filename]
@(d/transact (d/connect uri)
[{:db/id [:client/code client-code]
:client/signature-file (str "https://s3.amazonaws.com/integreat-signature-images/" filename)}]))