so many bug fixes.

This commit is contained in:
Bryce Covert
2020-07-03 17:50:37 -07:00
parent 3de59d3fdc
commit 86f51f93e4
22 changed files with 1447 additions and 521 deletions

View File

@@ -1,37 +1,37 @@
(ns auto-ap.graphql
(:require
[com.walmartlabs.lacinia.util :refer [attach-resolvers]]
[com.walmartlabs.lacinia.schema :as schema]
[com.walmartlabs.lacinia :refer [execute]]
[com.walmartlabs.lacinia.executor :as executor]
[com.walmartlabs.lacinia.resolve :as resolve]
[buddy.auth :refer [throw-unauthorized]]
[auto-ap.utils :refer [by]]
[auto-ap.graphql.utils :refer [assert-admin can-see-client? assert-can-see-client]]
[auto-ap.datomic :refer [uri merge-query]]
[datomic.api :as d]
[clj-time.coerce :as coerce]
[clj-time.core :as t]
[auto-ap.datomic.clients :as d-clients]
[auto-ap.datomic.checks :as d-checks]
[auto-ap.datomic.users :as d-users]
[auto-ap.datomic.invoices :as d-invoices]
[auto-ap.datomic.vendors :as d-vendors]
[auto-ap.graphql.users :as gq-users]
[auto-ap.graphql.yodlee-merchants :as ym]
[auto-ap.graphql.ledger :as gq-ledger]
[auto-ap.graphql.accounts :as gq-accounts]
[auto-ap.graphql.clients :as gq-clients]
[auto-ap.graphql.vendors :as gq-vendors]
[auto-ap.graphql.checks :as gq-checks]
[auto-ap.graphql.invoices :as gq-invoices]
[auto-ap.graphql.transactions :as gq-transactions]
[auto-ap.graphql.transaction-rules :as gq-transaction-rules]
[auto-ap.time :as time]
[clojure.walk :as walk]
[clojure.string :as str])
[com.walmartlabs.lacinia.util :refer [attach-resolvers]]
[com.walmartlabs.lacinia.schema :as schema]
[com.walmartlabs.lacinia :refer [execute]]
[com.walmartlabs.lacinia.executor :as executor]
[com.walmartlabs.lacinia.resolve :as resolve]
[buddy.auth :refer [throw-unauthorized]]
[auto-ap.utils :refer [by]]
[auto-ap.graphql.utils :refer [assert-admin can-see-client? assert-can-see-client]]
[auto-ap.datomic :refer [uri merge-query]]
[datomic.api :as d]
[clj-time.coerce :as coerce]
[clj-time.core :as t]
[auto-ap.datomic.clients :as d-clients]
[auto-ap.datomic.checks :as d-checks]
[auto-ap.datomic.users :as d-users]
[auto-ap.datomic.invoices :as d-invoices]
[auto-ap.datomic.vendors :as d-vendors]
[auto-ap.graphql.users :as gq-users]
[auto-ap.graphql.yodlee-merchants :as ym]
[auto-ap.graphql.ledger :as gq-ledger]
[auto-ap.graphql.accounts :as gq-accounts]
[auto-ap.graphql.clients :as gq-clients]
[auto-ap.graphql.vendors :as gq-vendors]
[auto-ap.graphql.checks :as gq-checks]
[auto-ap.graphql.invoices :as gq-invoices]
[auto-ap.graphql.transactions :as gq-transactions]
[auto-ap.graphql.transaction-rules :as gq-transaction-rules]
[auto-ap.time :as time]
[clojure.walk :as walk]
[clojure.string :as str])
(:import
(clojure.lang IPersistentMap)))
(clojure.lang IPersistentMap)))
(def integreat-schema
@@ -922,6 +922,20 @@
0
(- total outstanding-balance))})))
(defn has-fulfilled? [id date recent-fulfillments]
(seq (transduce
(filter (fn [[potential-id potential-date]]
(let [date (coerce/to-date-time date)
potential-date (coerce/to-date-time potential-date)]
#_(println "HERE" id potential-id potential-date date)
(and (= id potential-id)
(<= (t/in-days (apply t/interval (sort [date potential-date]))) 10)))))
conj
[]
recent-fulfillments))
)
(defn get-cash-flow [context {:keys [client_id]} value]
(when client_id
(let [{:client/keys [weekly-credits weekly-debits forecasted-transactions ]} (d/pull (d/db (d/connect uri)) '[*] client_id )
@@ -959,14 +973,25 @@
[?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 31)))]})))
forecasted-transactions (->> forecasted-transactions
(filter (fn [{:forecasted-transaction/keys [day-of-month]}]
(>= day-of-month (t/day (time/local-now)))))
(mapv (fn [{:forecasted-transaction/keys [amount identifier day-of-month]}]
{:identifier identifier
:amount amount
:date (coerce/to-date-time (t/local-date (t/year (time/local-now)) (t/month (time/local-now)) day-of-month ))}
)))]
recent-fulfillments (d/query {: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)))]})
forecasted-transactions (for [{:forecasted-transaction/keys [amount identifier day-of-month]
:db/keys [id]} forecasted-transactions
month (range -1 2)
:let [next (t/plus (t/local-date (t/year (time/local-now))
(t/month (time/local-now))
day-of-month )
(t/months month))]
:when (not (has-fulfilled? id next recent-fulfillments))]
{:identifier identifier
:amount amount
:date (coerce/to-date-time next)})]
(println "RECENT" forecasted-transactions)
{:beginning_balance total-cash
:outstanding_payments outstanding-checks
:invoices_due_soon (mapv (fn [[due outstanding]]
@@ -979,13 +1004,12 @@
:date (coerce/to-date-time date)})
(take 5 (time/day-of-week-seq 1)))
(filter #(>= (:amount %) 0) forecasted-transactions))
:upcoming_debits (doto (into (mapv
(fn [date]
{:amount (- (or weekly-debits 0))
:date (coerce/to-date-time date)})
(take 5 (time/day-of-week-seq 1)))
(filter #(< (:amount %) 0) forecasted-transactions))
println)
:upcoming_debits (into (mapv
(fn [date]
{:amount (- (or weekly-debits 0))
:date (coerce/to-date-time date)})
(take 5 (time/day-of-week-seq 1)))
(filter #(< (:amount %) 0) forecasted-transactions))
})))
(def schema