From 3e0f6e2a0a2f1b642b73d55ae01f064275fa1e2c Mon Sep 17 00:00:00 2001 From: Bryce Covert Date: Wed, 20 May 2020 06:49:20 -0700 Subject: [PATCH] removed bad cash flow --- src/clj/user.clj | 66 ------------------------------------------------ 1 file changed, 66 deletions(-) diff --git a/src/clj/user.clj b/src/clj/user.clj index e4d2a000..361f7a43 100644 --- a/src/clj/user.clj +++ b/src/clj/user.clj @@ -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)