diff --git a/resources/schema.edn b/resources/schema.edn index 1c5e1156..deaf672b 100644 --- a/resources/schema.edn +++ b/resources/schema.edn @@ -654,6 +654,14 @@ :db/cardinality #:db{:ident :db.cardinality/one}, :db/doc "Name of intuit bank", :db/ident :intuit-bank-account/name} +{ :db/valueType :db.type/double, + :db/cardinality :db.cardinality/one + :db/doc "Quickbook's view of the balance of the account", + :db/ident :intuit-bank-account/current-balance} +{ :db/valueType :db.type/instant + :db/cardinality :db.cardinality/one + :db/doc "Last time Quickbooks updated", + :db/ident :intuit-bank-account/last-synced} {:db/unique #:db{:ident :db.unique/identity}, :db/valueType #:db{:ident :db.type/long}, diff --git a/src/clj/auto_ap/import/intuit.clj b/src/clj/auto_ap/import/intuit.clj index 6a00f090..fd908291 100644 --- a/src/clj/auto_ap/import/intuit.clj +++ b/src/clj/auto_ap/import/intuit.clj @@ -1,16 +1,16 @@ (ns auto-ap.import.intuit - (:require - [auto-ap.datomic :refer [conn pull-attr]] - [auto-ap.import.common :refer [wrap-integration]] - [auto-ap.import.transactions :as t] - [auto-ap.intuit.core :as i] - [auto-ap.logging :as alog] - [auto-ap.time :as atime] - [clj-time.coerce :as coerce] - [clj-time.core :as time] - [clojure.string :as str] - [com.unbounce.dogstatsd.core :as statsd] - [datomic.api :as dc])) + (:require [auto-ap.datomic :refer [conn]] + [auto-ap.import.common :refer [wrap-integration]] + [auto-ap.import.transactions :as t] + [auto-ap.intuit.core :as i] + [auto-ap.logging :as alog] + [auto-ap.time :as atime] + [clj-time.coerce :as coerce] + [clj-time.core :as time] + [clojure.string :as str] + [com.unbounce.dogstatsd.core :as statsd] + [datomic.api :as dc] + [iol-ion.utils :refer [remove-nils]])) (defn get-intuit-bank-accounts ( [db] @@ -90,6 +90,10 @@ bank-accounts (i/get-bank-accounts token)] @(dc/transact conn (mapv (fn [ba] - {:intuit-bank-account/external-id (:name ba) - :intuit-bank-account/name (:name ba)}) + (remove-nils + {:intuit-bank-account/external-id (:name ba) + :intuit-bank-account/name (:name ba) + :intuit-bank-account/last-synced (coerce/to-date (:last-updated ba)) + :intuit-bank-account/current-balance (:current-balance ba)})) bank-accounts)))) + diff --git a/src/clj/auto_ap/intuit/core.clj b/src/clj/auto_ap/intuit/core.clj index 19fa6a97..9dc0def8 100644 --- a/src/clj/auto_ap/intuit/core.clj +++ b/src/clj/auto_ap/intuit/core.clj @@ -1,13 +1,12 @@ (ns auto-ap.intuit.core - (:require - [amazonica.aws.s3 :as s3] - [clj-http.client :as client] - [clojure.core.memoize :as m] - [clojure.java.io :as io] - [clojure.string :as str] - [config.core :as cfg :refer [env]]) - (:import - (org.apache.commons.codec.binary Base64))) + (:require [amazonica.aws.s3 :as s3] + [clj-http.client :as client] + [clj-time.coerce :as c] + [clojure.core.memoize :as m] + [clojure.java.io :as io] + [clojure.string :as str] + [config.core :as cfg :refer [env]]) + (:import (org.apache.commons.codec.binary Base64))) ;; (def authorization-code "AB11638463964I0tYPR3A1inog2HL407u2bZBXHg6LEqCbILRO") ;; (def realm-id "4620816365202617680") @@ -98,6 +97,13 @@ {:headers base-headers :as :json}) +(defn get-bank-accounts-raw [token] + (->> (:body (client/get (str prod-base-url "/company/" prod-company-id "/query" ) + {:headers + (with-auth prod-base-headers token) + :as :json + :query-params {"query" "SELECT * From Account maxresults 1000"}})) + :QueryResponse)) (defn get-bank-accounts [token] @@ -110,10 +116,13 @@ :Account #_(filter #(#{"Bank" "Credit Card"} (:AccountType %))) - (map (juxt :Id :Name)) - (map (fn [[id name]] + (map (juxt :Id :Name :CurrentBalance :MetaData)) + (map (fn [[id name current-balance metadata]] {:id id - :name name})))) + :name name + :last-updated (c/to-date-time (-> metadata :LastUpdatedTime)) + :current-balance current-balance})))) + (defn get-all-transactions [start end] (let [token (get-fresh-access-token)] diff --git a/src/clj/auto_ap/ssr/company.clj b/src/clj/auto_ap/ssr/company.clj index eba9fa59..e2ef057c 100644 --- a/src/clj/auto_ap/ssr/company.clj +++ b/src/clj/auto_ap/ssr/company.clj @@ -132,6 +132,7 @@ request (com/page {:nav com/company-aside-nav :client-selection (:client-selection request) + :request request :client (:client request) :clients (:clients request) :identity (:identity request)