From c3bea4709348a581feebdb2884a72261f28166e1 Mon Sep 17 00:00:00 2001 From: Bryce Covert Date: Tue, 26 Jan 2021 08:19:48 -0800 Subject: [PATCH] fixes --- src/clj/auto_ap/graphql/checks.clj | 4 ++++ src/clj/auto_ap/graphql/transactions.clj | 2 +- src/clj/auto_ap/yodlee/import.clj | 18 +++++++++++------- src/cljs/auto_ap/events.cljs | 2 +- src/cljs/auto_ap/history.cljs | 2 +- .../auto_ap/views/pages/invoices/common.cljs | 2 +- 6 files changed, 19 insertions(+), 11 deletions(-) diff --git a/src/clj/auto_ap/graphql/checks.clj b/src/clj/auto_ap/graphql/checks.clj index d75526d3..cd184a45 100644 --- a/src/clj/auto_ap/graphql/checks.clj +++ b/src/clj/auto_ap/graphql/checks.clj @@ -316,6 +316,10 @@ invoices-grouped-by-vendor (group-by (comp :db/id :invoice/vendor) invoices) bank-account (d-bank-accounts/get-by-id bank-account-id) _ (validate-belonging client-id invoices bank-account) + _ (when (nil? (:bank-account/check-number bank-account)) + (let [message (str "The bank account " (:bank-account/name bank-account) " does not have a starting check number. Please ask the integreat staff to initialize it.")] + (throw (ex-info message + {:validation-error message})))) _ (if (dollars-0? (reduce + 0.0 (filter #(>= % 0.0) (map :amount invoice-payments)))) diff --git a/src/clj/auto_ap/graphql/transactions.clj b/src/clj/auto_ap/graphql/transactions.clj index 2cf6cbf3..79012012 100644 --- a/src/clj/auto_ap/graphql/transactions.clj +++ b/src/clj/auto_ap/graphql/transactions.clj @@ -339,7 +339,7 @@ _ (assert-can-see-client (:id context) (:transaction/client transaction) ) db (d/db conn) invoice-clients (set (map (comp :db/id :invoice/client #(d/entity db %)) unpaid_invoice_ids)) - invoice-amount (reduce + 0.0 (map (comp :invoice/total #(d/entity db %)) unpaid_invoice_ids))] + invoice-amount (reduce + 0.0 (map (comp :invoice/outstanding-balance #(d/entity db %)) unpaid_invoice_ids))] (when (or (> (count invoice-clients) 1) (not= (:db/id (:transaction/client transaction)) (first invoice-clients))) diff --git a/src/clj/auto_ap/yodlee/import.clj b/src/clj/auto_ap/yodlee/import.clj index fda747a2..c7843b4e 100644 --- a/src/clj/auto_ap/yodlee/import.clj +++ b/src/clj/auto_ap/yodlee/import.clj @@ -86,13 +86,13 @@ (defn match-transaction-to-unpaid-invoices [amount client-id] (log/info "trying to find unpaid invoices for " client-id amount) - (let [candidate-invoices-vendor-groups (->> (d/query {:query {:find ['?vendor-id '?e '?total '?d] + (let [candidate-invoices-vendor-groups (->> (d/query {:query {:find ['?vendor-id '?e '?outstanding-balance '?d] :in ['$ '?client-id] :where ['[?e :invoice/client ?client-id] '[?e :invoice/status :invoice-status/unpaid] '(not [_ :invoice-payment/invoice ?e]) '[?e :invoice/vendor ?vendor-id] - '[?e :invoice/total ?total] + '[?e :invoice/outstanding-balance ?outstanding-balance] '[?e :invoice/date ?d]]} :args [(d/db conn) client-id]}) (sort-by last) ;; sort by scheduled payment date @@ -118,6 +118,7 @@ (log/info "Adding a new payment for transaction " (:transaction/id transaction) " and invoices " invoice-payments) (let [payment-id (d/tempid :db.part/user)] (-> tx + (conj {:payment/bank-account bank-account-id :payment/client client-id :payment/amount (- (:transaction/amount transaction)) @@ -126,11 +127,14 @@ :payment/type :payment-type/debit :payment/status :payment-status/cleared :db/id payment-id}) - (into (map (fn [[vendor invoice-id invoice-amount]] - {:invoice-payment/invoice invoice-id - :invoice-payment/payment payment-id - :invoice-payment/amount invoice-amount}) - invoice-payments)) + (into (mapcat (fn [[vendor invoice-id invoice-amount]] + [{:invoice-payment/invoice invoice-id + :invoice-payment/payment payment-id + :invoice-payment/amount invoice-amount} + {:db/id invoice-id + :invoice/outstanding-balance 0.0 + :invoice/status :invoice-status/paid}]) + invoice-payments)) (update 0 assoc :transaction/payment payment-id :transaction/approval-status :transaction-approval-status/approved diff --git a/src/cljs/auto_ap/events.cljs b/src/cljs/auto_ap/events.cljs index f2425d25..e58c0e82 100644 --- a/src/cljs/auto_ap/events.cljs +++ b/src/cljs/auto_ap/events.cljs @@ -135,7 +135,7 @@ (re-frame/reg-event-fx ::set-active-page (fn [{:keys [db]} [_ handler params]] - + (if (and (not= :login handler) (not (:user db))) {:redirect "/login" :db (assoc db :active-page :login diff --git a/src/cljs/auto_ap/history.cljs b/src/cljs/auto_ap/history.cljs index 6bea77a5..684a0167 100644 --- a/src/cljs/auto_ap/history.cljs +++ b/src/cljs/auto_ap/history.cljs @@ -6,7 +6,7 @@ [re-frame.core :as re-frame])) (defn- parse-url [url] - (println url) + (println "parsing url" url) (bidi/match-route routes/routes url)) (defn- dispatch-route [matched-route] diff --git a/src/cljs/auto_ap/views/pages/invoices/common.cljs b/src/cljs/auto_ap/views/pages/invoices/common.cljs index e8211706..2121e78a 100644 --- a/src/cljs/auto_ap/views/pages/invoices/common.cljs +++ b/src/cljs/auto_ap/views/pages/invoices/common.cljs @@ -15,7 +15,7 @@ (def invoice-read [:id :total :outstanding-balance :date :due :invoice-number :status :scheduled-payment [:client [:id :name :locations]] - [:payments [:amount [:payment [:amount :s3_url :check_number ]]]] + [:payments [:amount [:payment [:id :amount :s3_url :check_number ]]]] [:vendor [:id :name]] [:expense_accounts [:amount :id :location