Makes integreat run on datomic cloud

This commit is contained in:
2022-08-23 12:13:12 -07:00
parent 58b9dcf272
commit d02fba2b44
58 changed files with 2163 additions and 1257 deletions

View File

@@ -1,6 +1,6 @@
(ns auto-ap.graphql
(:require
[auto-ap.datomic :refer [merge-query uri]]
[auto-ap.datomic :refer [merge-query conn]]
[auto-ap.datomic.users :as d-users]
[auto-ap.graphql.accounts :as gq-accounts]
[auto-ap.graphql.checks :as gq-checks]
@@ -34,7 +34,8 @@
[com.walmartlabs.lacinia :refer [execute]]
[com.walmartlabs.lacinia.parser :as p]
[com.walmartlabs.lacinia.schema :as schema]
[datomic.api :as d]
[com.walmartlabs.lacinia.util :refer [attach-resolvers]]
[datomic.client.api :as dc]
[unilog.context :as lc]
[yang.time :refer [time-it]])
(:import
@@ -137,7 +138,8 @@
:address
{:fields {:street1 {:type 'String}
{:fields {:id {:type :id}
:street1 {:type 'String}
:street2 {:type 'String}
:city {:type 'String}
:state {:type 'String}
@@ -432,7 +434,8 @@
:email {:type 'String}
:phone {:type 'String}}}
:add_address
{:fields {:street1 {:type 'String}
{:fields {:id {:type :id}
:street1 {:type 'String}
:street2 {:type 'String}
:city {:type 'String}
:state {:type 'String}
@@ -629,7 +632,7 @@
(let [result (cond-> {:query {:find ['?account '?account-name '(sum ?amount)]
:in ['$]
:where []}
:args [(d/db (d/connect uri)) client_id]}
:args [(dc/db conn) client_id]}
client_id (merge-query {:query {:in ['?c]}
:args [client_id]})
@@ -641,7 +644,7 @@
'[?account :account/name ?account-name]
'[?expense-account :invoice-expense-account/amount ?amount]]}})
true (d/query))]
true (dc/q))]
(for [[account-id account-name total] result]
{:account {:id account-id :name account-name} :total total})))
@@ -649,7 +652,7 @@
(let [result (cond-> {:query {:find ['?name '(sum ?outstanding-balance) '(sum ?total)]
:in ['$]
:where []}
:args [(d/db (d/connect uri)) client_id]}
:args [(dc/db conn) client_id]}
client_id (merge-query {:query {:in ['?c]}
:args [client_id]})
(not client_id) (merge-query {:query {:where ['[?c :client/name]]}})
@@ -662,7 +665,7 @@
'[(.between java.time.temporal.ChronoUnit/DAYS (java.time.Instant/now) ?d2 ) ?d3]
'[(auto-ap.graphql/categorize ?d3) ?name]]}})
true (d/query))
true (dc/q))
result (group-by first result)]
(for [[id name] [[:due "Due"] [:due-30 "0-30 days"] [:due-60 "31-60 days"] [:due-later ">60 days"]]
@@ -689,13 +692,13 @@
(defn get-cash-flow [_ {:keys [client_id]} _]
(when client_id
(let [{:client/keys [week-a-credits week-a-debits week-b-credits week-b-debits forecasted-transactions ]} (d/pull (d/db (d/connect uri)) '[*] client_id)
(let [{:client/keys [week-a-credits week-a-debits week-b-credits week-b-debits forecasted-transactions ]} (dc/pull (dc/db conn) '[*] client_id)
total-cash (reduce
(fn [total [credit debit]]
(- (+ total credit)
debit))
0.0
(d/query {:query {:find '[?debit ?credit]
(dc/q {:query {:find '[?debit ?credit]
:in '[$ ?client]
:where ['[?j :journal-entry/client ?client]
'[?j :journal-entry/line-items ?je]
@@ -703,8 +706,8 @@
'[?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)) client_id]}))
bills-due-soon (d/query {:query {:find '[?due ?outstanding ?invoice-number ?vendor-id ?vendor-name]
: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]
@@ -714,11 +717,11 @@
'[?i :invoice/invoice-number ?invoice-number]
'[?i :invoice/vendor ?vendor-id]
'[?vendor-id :vendor/name ?vendor-name]]}
:args [(d/db (d/connect uri)) client_id (coerce/to-date (t/plus (time/local-now) (t/days 180)))]})
:args [(dc/db conn) client_id (coerce/to-date (t/plus (time/local-now) (t/days 180)))]})
outstanding-checks (reduce
+
0.0
(map first (d/query {:query {:find '[?amount]
(map first (dc/q {:query {:find '[?amount]
:in '[$ ?client ?due-before]
:where ['[?p :payment/client ?client]
'[?p :payment/status :payment-status/pending]
@@ -726,14 +729,14 @@
'(or
[?p :payment/type :payment-type/debit]
[?p :payment/type :payment-type/check])]}
:args [(d/db (d/connect uri)) client_id (coerce/to-date (t/plus (time/local-now) (t/days 180)))]})))
recent-fulfillments (d/query {:query {:find '[?f ?d]
: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/date ?d]
'[?t :transaction/client ?client]
'[(>= ?d ?min-date)]]}
:args [(d/db (d/connect uri)) client_id (coerce/to-date (t/plus (time/local-now) (t/months -2)))]})
:args [(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)