diff --git a/project.clj b/project.clj index 418621b5..ed88e828 100644 --- a/project.clj +++ b/project.clj @@ -78,7 +78,7 @@ :plugins [[lein-figwheel "0.5.13"] [lein-pdo "0.1.1"] [cider/cider-nrepl "0.16.0"]] - :jvm-opts ["-Dconfig=config/dev.edn" #_#_"--add-modules" "java.xml.bind"]} + :jvm-opts ["-Dconfig=config/dev.edn" "--add-modules" "java.xml.bind"]} :uberjar {:prep-tasks [["cljsbuild" "once" "min"] "compile"]} :provided {:dependencies [[org.clojure/clojurescript "1.10.238"] [reagent "0.7.0"] diff --git a/resources/BellaSaratoga.jpg b/resources/BellaSaratoga.jpg new file mode 100644 index 00000000..5a75346e Binary files /dev/null and b/resources/BellaSaratoga.jpg differ diff --git a/resources/Dan_Sig.1.jpg b/resources/Dan_Sig.1.jpg new file mode 100644 index 00000000..44a34117 Binary files /dev/null and b/resources/Dan_Sig.1.jpg differ diff --git a/resources/MioVicino.jpg b/resources/MioVicino.jpg new file mode 100644 index 00000000..ed1c0e21 Binary files /dev/null and b/resources/MioVicino.jpg differ diff --git a/resources/iguanas.jpg b/resources/iguanas.jpg new file mode 100644 index 00000000..2b9ccc66 Binary files /dev/null and b/resources/iguanas.jpg differ diff --git a/scratch-sessions/fix-account-id.sql b/scratch-sessions/fix-account-id.sql new file mode 100644 index 00000000..1e41da23 --- /dev/null +++ b/scratch-sessions/fix-account-id.sql @@ -0,0 +1,18 @@ + + +(defn original-base-id [{:keys [date bank-account-id description-original company-id amount]} index] + (str (t/to-time-zone date (t/time-zone-for-offset -7)) "-" description-original "-" (double amount) "-" index "-" company-id)) + +(defn new-base-id [{:keys [date bank-account-id description-original company-id amount]} index] + (str (t/to-time-zone date (t/time-zone-for-offset -7)) "-" bank-account-id "-" description-original "-" (double amount) "-" index "-" company-id)) + +(defn replacements [] + (loop [rows (get-graphql {:limit 100000}) + replacements [] + i 0] + (let [result (->> rows + (filter #(= (:id %) (sha-256 (original-base-id % i)))) + (map #(assoc % :new-id (sha-256 (new-base-id % i)))))] + (if (= 10 i) + (into replacements result) + (recur rows (into replacements result ) (inc i)))))) diff --git a/src/clj/auto_ap/graphql.clj b/src/clj/auto_ap/graphql.clj index c81bbb90..df492f21 100644 --- a/src/clj/auto_ap/graphql.clj +++ b/src/clj/auto_ap/graphql.clj @@ -307,11 +307,11 @@ :resolve :mutation/print-checks} :add_handwritten_check {:type :check_result - :args {:invoice_id {:type 'Int} + :args {:invoice_id {:type 'String} :amount {:type 'Float} :date {:type 'String} :check_number {:type 'Int} - :bank_account_id {:type 'Int}} + :bank_account_id {:type 'String}} :resolve :mutation/add-handwritten-check} :edit_user {:type :user :args {:edit_user {:type :edit_user}} diff --git a/src/clj/auto_ap/graphql/checks.clj b/src/clj/auto_ap/graphql/checks.clj index 7ccf46cd..986cec4e 100644 --- a/src/clj/auto_ap/graphql/checks.clj +++ b/src/clj/auto_ap/graphql/checks.clj @@ -6,22 +6,16 @@ [com.walmartlabs.lacinia :refer [execute]] [com.walmartlabs.lacinia.executor :as executor] [com.walmartlabs.lacinia.resolve :as resolve] - [auto-ap.db.invoices-checks :as invoices-checks] - [auto-ap.db.checks :as checks] + [auto-ap.datomic.checks :as d-checks] [auto-ap.datomic.invoices :as d-invoices] [auto-ap.datomic.vendors :as d-vendors] [auto-ap.datomic.clients :as d-clients] [auto-ap.datomic.bank-accounts :as d-bank-accounts] - [auto-ap.db.invoices-checks :as invoices-checks] - [auto-ap.db.vendors :as vendors] - [auto-ap.db.invoices :as invoices] - [auto-ap.db.utils :refer [query]] [auto-ap.datomic :refer [uri]] [auto-ap.utils :refer [by]] [auto-ap.numeric :refer [num->words]] [config.core :refer [env]] - [auto-ap.db.companies :as companies] [auto-ap.time :refer [parse normal-date iso-date local-now]] [amazonica.aws.s3 :as s3] [clojure.string :as str] @@ -265,6 +259,7 @@ (conj [:inc (:db/id bank-account) :bank-account/check-number 1]) (into (invoice-payments invoices invoice-amounts))))) + (defmethod invoices->entities :payment-type/debit [invoices vendor client bank-account type index invoice-amounts] (let [payment (assoc (base-payment invoices vendor client bank-account type index invoice-amounts) :payment/type :payment-type/debit @@ -323,26 +318,22 @@ :end (+ (:start args 0) (count payments))}])) (defn add-handwritten-check [context args value] - (let [invoice (invoices/get-by-id (:invoice_id args)) + (let [invoice (d-invoices/get-by-id (:invoice_id args)) + bank-account-id (Long/parseLong (:bank_account_id args)) + bank-account (d-bank-accounts/get-by-id bank-account-id) _ (assert-can-see-company (:id context) (:company-id invoice)) - check (checks/insert! {:s3-uuid nil - :s3-key nil - :s3-url nil - :check-number (:check_number args) - :date (parse (:date args) iso-date) - :amount (:amount args) - :bank-account-id (:bank_account_id args) - :vendor-id (:vendor-id invoice) - :company-id (:company-id invoice) - :invoices [(:invoice_id args)]})] - - (invoices-checks/insert-multi! [{:invoice-id (:invoice_id args) - :check-id (:id check) - :amount (:amount args)}]) - (invoices/apply-payment (:invoice_id args) (:amount args)) + base-payment (base-payment [invoice] (:invoice/vendor invoice) + (:invoice/client invoice) + bank-account :payment-type/check 0 {(Long/parseLong (:invoice_id args)) (:amount args)})] + @(d/transact (d/connect uri) + [(assoc base-payment + :payment/check-number (:check_number args) + :payment/date (c/to-date (parse (:date args) iso-date)) + :payment/amount (:amount args)) + [:pay (:db/id invoice) (:amount args)]]) (->graphql {:s3-url nil - :invoices [(invoices/get-by-id (:invoice_id args))]}))) + :invoices [(d-invoices/get-by-id (:invoice_id args))]}))) (defn void-check [context {id :payment_id} value] diff --git a/src/clj/auto_ap/graphql/invoices.clj b/src/clj/auto_ap/graphql/invoices.clj index 7d46c361..949bd26f 100644 --- a/src/clj/auto_ap/graphql/invoices.clj +++ b/src/clj/auto_ap/graphql/invoices.clj @@ -70,14 +70,16 @@ (->graphql)))) (defn void-invoice [context {id :invoice_id} value] - (let [invoice (d-invoices/get-by-id id) - _ (assert-can-see-company (:id context) (:company-id invoice)) - updated-invoice (d-invoices/update {:db/id (Long/parseLong id) - :invoice/total 0.0 - :invoice/outstanding-balance 0.0 - :invoice/status :invoice-status/voided})] - (-> updated-invoice - (->graphql)))) + (let [invoice (d-invoices/get-by-id id) + _ (assert-can-see-company (:id context) (:company-id invoice)) + updated-invoice (d-invoices/update {:db/id (Long/parseLong id) + :invoice/total 0.0 + :invoice/outstanding-balance 0.0 + :invoice/status :invoice-status/voided})] + ;; TODO void out all expense accounts + + (-> updated-invoice + (->graphql)))) diff --git a/src/clj/auto_ap/graphql/utils.clj b/src/clj/auto_ap/graphql/utils.clj index d1f6bacb..a9f7afbb 100644 --- a/src/clj/auto_ap/graphql/utils.clj +++ b/src/clj/auto_ap/graphql/utils.clj @@ -47,7 +47,8 @@ (defn can-see-company? [identity company] (or (= "admin" (:role identity)) - ((set (map :db/id (:user/companies identity))) (:db/id company)))) + ((set (map :db/id (:user/companies identity))) (:db/id company)) + ((set (map :db/id (:user/companies identity))) company))) (defn assert-can-see-company [identity company] (when-not (can-see-company? identity company) diff --git a/src/clj/auto_ap/routes/checks.clj b/src/clj/auto_ap/routes/checks.clj index d8c3c422..9bab0b8c 100644 --- a/src/clj/auto_ap/routes/checks.clj +++ b/src/clj/auto_ap/routes/checks.clj @@ -2,8 +2,7 @@ (:require [hiccup.core :refer [html]] [auto-ap.routes.utils :refer [wrap-secure]] -[compojure.core :refer [GET POST context defroutes - wrap-routes]])) + [compojure.core :refer [GET POST context defroutes wrap-routes]])) (defroutes routes (wrap-routes (context "/checks" []) diff --git a/src/clj/auto_ap/routes/exports.clj b/src/clj/auto_ap/routes/exports.clj index 6062b572..7abd65e5 100644 --- a/src/clj/auto_ap/routes/exports.clj +++ b/src/clj/auto_ap/routes/exports.clj @@ -43,7 +43,7 @@ (let [query [[:all_payments {:client-id (query-params "client") :original-id (query-params "original")} - [:id :check-number :amount :memo :date :status + [:id :check-number :amount :memo :date :status :type [:invoices [[:invoice [:id]] :amount]] [:bank-account [:number :bank-name :bank-code :id]] [:vendor [:name :id [:primary-contact [:name :email :phone]] :default-expense-account [:address [:street1 :city :state :zip]]]] diff --git a/src/clj/auto_ap/yodlee/core.clj b/src/clj/auto_ap/yodlee/core.clj index 636f78ca..225bc415 100644 --- a/src/clj/auto_ap/yodlee/core.clj +++ b/src/clj/auto_ap/yodlee/core.clj @@ -47,12 +47,24 @@ :body :account))) +(defn get-account [i] + (let [cob-session (login-cobrand) + user-session (login-user cob-session)] + (-> (str (:yodlee-base-url env) (str "/accounts/" i)) + (client/get {:headers (merge base-headers {"Authorization" (auth-header cob-session user-session)}) + :as :json}) + :body + :account))) + (defn get-provider-accounts [] (let [cob-session (login-cobrand) user-session (login-user cob-session)] (-> (str (:yodlee-base-url env) "/providerAccounts") - (client/get {:headers (merge base-headers {"Authorization" (auth-header cob-session user-session)}) - :as :json})))) + (-> (client/get {:headers (merge base-headers {"Authorization" (auth-header cob-session user-session)}) + :as :json}) + :body + :providerAccount) + ))) (defn get-transactions [] (let [cob-session (login-cobrand) @@ -77,6 +89,58 @@ (recur (concat transactions transaction-batch) (+ batch-size skip)) transactions))))) +(defn get-provider-accounts [] + (let [cob-session (login-cobrand) + user-session (login-user cob-session) + batch-size 100 + get-transaction-batch (fn [] + (-> (str (:yodlee-base-url env) "/providerAccounts") + + (client/get {:headers (doto + (merge base-headers {"Authorization" (auth-header cob-session user-session)}) + println) + :as :json}) + :body + ))] + + (get-transaction-batch))) + +(defn update-provider-account [pa] + (let [cob-session (login-cobrand) + user-session (login-user cob-session) + batch-size 100] + + (-> (str (:yodlee-base-url env) "/providerAccounts?providerAccountIds=" pa) + + (client/put {:headers (doto + (merge base-headers {"Authorization" (auth-header cob-session user-session)}) + println) + :body "{\"dataSetName\": [\"BASIC_AGG_DATA\"]}" + :as :json})))) + +(defn get-specific-transactions [] + (let [cob-session (login-cobrand) + user-session (login-user cob-session) + batch-size 100 + get-transaction-batch (fn [skip] + (-> (str (:yodlee-base-url env) "/transactions?top=" batch-size "&skip=" skip "&accountId=16422358") + (doto println) + + (client/get {:headers (doto + (merge base-headers {"Authorization" (auth-header cob-session user-session)}) + println) + :as :json}) + :body + :transaction + ))] + + (loop [transactions [] + skip 0] + (let [transaction-batch (get-transaction-batch skip)] + (if (seq transaction-batch) + (recur (concat transactions transaction-batch) (+ batch-size skip)) + transactions))))) + (defn get-access-token [] (let [cob-session (login-cobrand) user-session (login-user cob-session) diff --git a/src/clj/auto_ap/yodlee/import.clj b/src/clj/auto_ap/yodlee/import.clj index b36ed7d6..31e9112c 100644 --- a/src/clj/auto_ap/yodlee/import.clj +++ b/src/clj/auto_ap/yodlee/import.clj @@ -100,7 +100,7 @@ (mapcat (fn [transaction-group] (map (fn [index {:keys [date description-original high-level-category amount account-id] :as transaction}] - {:id (str date "-" description-original "-" amount "-" index "-" company-id) + {:id (str date "-" account-id "-" description-original "-" amount "-" index "-" company-id) :bank-account-id account-id :date (time/unparse date "YYYY-MM-dd") :amount {:amount amount} diff --git a/src/cljs/auto_ap/views/pages/unpaid_invoices.cljs b/src/cljs/auto_ap/views/pages/unpaid_invoices.cljs index 01be6216..642155e3 100644 --- a/src/cljs/auto_ap/views/pages/unpaid_invoices.cljs +++ b/src/cljs/auto_ap/views/pages/unpaid_invoices.cljs @@ -332,7 +332,7 @@ :bank-account-id bank-account-id :invoice_id (:id invoice) } - [[:invoices [:id :outstanding-balance [:checks [:amount [:check [:amount :s3_url :check_number ]]]]]]]]}]} + [[:invoices [:id :outstanding-balance [:payments [:amount [:payment [:amount :s3_url :check_number ]]]]]]]]}]} :on-success [::handwrite-checks-succeeded]}}))) (re-frame/reg-event-fx @@ -491,7 +491,7 @@ [:tr [:td.expandable [:div.control [bind-field - [typeahead {:matches (map (fn [x] [(:id x) (:name x)]) chooseable-expense-accounts) + [typeahead {:matches (map (fn [x] [(:id x) (str (:id x) " - " (:name x))]) chooseable-expense-accounts) :type "typeahead" :field [:invoice :expense-accounts index :expense-account-id] :event change-event