Migrates back to datomic on-prem
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
(ns auto-ap.graphql
|
||||
(:require
|
||||
[auto-ap.datomic :refer [merge-query conn]]
|
||||
[auto-ap.datomic :refer [conn merge-query query2]]
|
||||
[auto-ap.datomic.users :as d-users]
|
||||
[auto-ap.graphql.accounts :as gq-accounts]
|
||||
[auto-ap.graphql.checks :as gq-checks]
|
||||
@@ -34,8 +34,7 @@
|
||||
[com.walmartlabs.lacinia :refer [execute]]
|
||||
[com.walmartlabs.lacinia.parser :as p]
|
||||
[com.walmartlabs.lacinia.schema :as schema]
|
||||
[com.walmartlabs.lacinia.util :refer [attach-resolvers]]
|
||||
[datomic.client.api :as dc]
|
||||
[datomic.api :as dc]
|
||||
[unilog.context :as lc]
|
||||
[yang.time :refer [time-it]])
|
||||
(:import
|
||||
@@ -622,7 +621,7 @@
|
||||
|
||||
|
||||
(defn get-expense-account-stats [_ {:keys [client_id] } _]
|
||||
(let [result (cond-> {:query {:find ['?account '?account-name '(sum ?amount)]
|
||||
(let [query (cond-> {:query {:find ['?account '?account-name '(sum ?amount)]
|
||||
:in ['$]
|
||||
:where []}
|
||||
:args [(dc/db conn) client_id]}
|
||||
@@ -635,14 +634,13 @@
|
||||
'[?i :invoice/expense-accounts ?expense-account]
|
||||
'[?expense-account :invoice-expense-account/account ?account]
|
||||
'[?account :account/name ?account-name]
|
||||
'[?expense-account :invoice-expense-account/amount ?amount]]}})
|
||||
|
||||
true (dc/q))]
|
||||
'[?expense-account :invoice-expense-account/amount ?amount]]}}))
|
||||
result (query2 query)]
|
||||
(for [[account-id account-name total] result]
|
||||
{:account {:id account-id :name account-name} :total total})))
|
||||
|
||||
(defn get-invoice-stats [_ {:keys [client_id] } _]
|
||||
(let [result (cond-> {:query {:find ['?name '(sum ?outstanding-balance) '(sum ?total)]
|
||||
(let [query (cond-> {:query {:find ['?name '(sum ?outstanding-balance) '(sum ?total)]
|
||||
:in ['$]
|
||||
:where []}
|
||||
:args [(dc/db conn) client_id]}
|
||||
@@ -664,10 +662,9 @@
|
||||
(and [(<= ?d3 60)]
|
||||
[(ground :due-30) ?name])
|
||||
(and [(> ?d3 60)]
|
||||
[(ground :due-later) ?name]))]}})
|
||||
|
||||
true (dc/q))
|
||||
result (group-by first result)]
|
||||
[(ground :due-later) ?name]))]}}))
|
||||
result (->> (query2 query)
|
||||
(group-by first))]
|
||||
|
||||
(for [[id name] [[:due "Due"] [:due-30 "0-30 days"] [:due-60 "31-60 days"] [:due-later ">60 days"]]
|
||||
:let [[[_ outstanding-balance total] ] (id result nil)
|
||||
@@ -699,44 +696,44 @@
|
||||
(- (+ total credit)
|
||||
debit))
|
||||
0.0
|
||||
(dc/q {:query {:find '[?debit ?credit]
|
||||
:in '[$ ?client]
|
||||
:where ['[?client :client/bank-accounts ?ba]
|
||||
'[?ba :bank-account/type :bank-account-type/check]
|
||||
'[?je :journal-entry-line/account ?ba]
|
||||
'[(get-else $ ?je :journal-entry-line/debit 0.0) ?debit]
|
||||
'[(get-else $ ?je :journal-entry-line/credit 0.0) ?credit]]}
|
||||
:args [(dc/db conn) client_id]}))
|
||||
bills-due-soon (dc/q {:query {:find '[?due ?outstanding ?invoice-number ?vendor-id ?vendor-name]
|
||||
:in '[$ ?client ?due-before]
|
||||
:where ['[?i :invoice/client ?client]
|
||||
'[?i :invoice/status :invoice-status/unpaid]
|
||||
'[?i :invoice/due ?due]
|
||||
'[(<= ?due ?due-before)]
|
||||
'[?i :invoice/outstanding-balance ?outstanding]
|
||||
'[?i :invoice/invoice-number ?invoice-number]
|
||||
'[?i :invoice/vendor ?vendor-id]
|
||||
'[?vendor-id :vendor/name ?vendor-name]]}
|
||||
:args [(dc/db conn) client_id (coerce/to-date (t/plus (time/local-now) (t/days 180)))]})
|
||||
(dc/q {:find '[?debit ?credit]
|
||||
:in '[$ ?client]
|
||||
:where ['[?client :client/bank-accounts ?ba]
|
||||
'[?ba :bank-account/type :bank-account-type/check]
|
||||
'[?je :journal-entry-line/account ?ba]
|
||||
'[(get-else $ ?je :journal-entry-line/debit 0.0) ?debit]
|
||||
'[(get-else $ ?je :journal-entry-line/credit 0.0) ?credit]]}
|
||||
(dc/db conn) client_id))
|
||||
bills-due-soon (dc/q {:find '[?due ?outstanding ?invoice-number ?vendor-id ?vendor-name]
|
||||
:in '[$ ?client ?due-before]
|
||||
:where ['[?i :invoice/client ?client]
|
||||
'[?i :invoice/status :invoice-status/unpaid]
|
||||
'[?i :invoice/due ?due]
|
||||
'[(<= ?due ?due-before)]
|
||||
'[?i :invoice/outstanding-balance ?outstanding]
|
||||
'[?i :invoice/invoice-number ?invoice-number]
|
||||
'[?i :invoice/vendor ?vendor-id]
|
||||
'[?vendor-id :vendor/name ?vendor-name]]}
|
||||
(dc/db conn) client_id (coerce/to-date (t/plus (time/local-now) (t/days 180))))
|
||||
outstanding-checks (reduce
|
||||
+
|
||||
0.0
|
||||
(map first (dc/q {:query {:find '[?amount]
|
||||
:in '[$ ?client ?due-before]
|
||||
:where ['[?p :payment/client ?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 [(dc/db conn) client_id (coerce/to-date (t/plus (time/local-now) (t/days 180)))]})))
|
||||
recent-fulfillments (dc/q {:query {:find '[?f ?d]
|
||||
:in '[$ ?client ?min-date]
|
||||
:where ['[?t :transaction/forecast-match ?f]
|
||||
'[?t :transaction/client ?client]
|
||||
'[?t :transaction/date ?d]
|
||||
'[(>= ?d ?min-date)]]}
|
||||
:args [(dc/db conn) client_id (coerce/to-date (t/plus (time/local-now) (t/months -2)))]})
|
||||
(map first (dc/q {:find '[?amount]
|
||||
:in '[$ ?client ?due-before]
|
||||
:where ['[?p :payment/client ?client]
|
||||
'[?p :payment/status :payment-status/pending]
|
||||
'[?p :payment/amount ?amount]
|
||||
'(or
|
||||
[?p :payment/type :payment-type/debit]
|
||||
[?p :payment/type :payment-type/check])]}
|
||||
(dc/db conn) client_id (coerce/to-date (t/plus (time/local-now) (t/days 180))))))
|
||||
recent-fulfillments (dc/q {:find '[?f ?d]
|
||||
:in '[$ ?client ?min-date]
|
||||
:where ['[?t :transaction/forecast-match ?f]
|
||||
'[?t :transaction/client ?client]
|
||||
'[?t :transaction/date ?d]
|
||||
'[(>= ?d ?min-date)]]}
|
||||
(dc/db conn) client_id (coerce/to-date (t/plus (time/local-now) (t/months -2))))
|
||||
forecasted-transactions (for [{:forecasted-transaction/keys [amount identifier day-of-month]
|
||||
:db/keys [id]} forecasted-transactions
|
||||
month (range -1 7)
|
||||
|
||||
Reference in New Issue
Block a user