From 2d8483f2e3e0e355ee70e9cfbcf4dd57d4e3b459 Mon Sep 17 00:00:00 2001 From: Bryce Covert Date: Sat, 23 Jan 2021 12:26:55 -0800 Subject: [PATCH] Progress on payment matching --- src/clj/auto_ap/datomic/checks.clj | 3 +- .../views/components/invoice_table.cljs | 39 ++++++++--------- .../views/pages/transactions/form.cljs | 43 +++++++++---------- 3 files changed, 42 insertions(+), 43 deletions(-) diff --git a/src/clj/auto_ap/datomic/checks.clj b/src/clj/auto_ap/datomic/checks.clj index e38ebbae..abd02576 100644 --- a/src/clj/auto_ap/datomic/checks.clj +++ b/src/clj/auto_ap/datomic/checks.clj @@ -1,6 +1,6 @@ (ns auto-ap.datomic.checks (:require [datomic.api :as d] - [auto-ap.datomic :refer [uri merge-query apply-sort-3 apply-pagination add-sorter-fields]] + [auto-ap.datomic :refer [uri merge-query apply-sort-3 apply-pagination add-sorter-fields conn]] [auto-ap.graphql.utils :refer [limited-clients]] [auto-ap.utils :refer [dollars=]] [clojure.set :refer [rename-keys]] @@ -135,6 +135,7 @@ :where ['[?e :payment/date ?sort-default]]}}))] + (log/info query) (cond->> query true (d/query) true (apply-sort-3 args) diff --git a/src/cljs/auto_ap/views/components/invoice_table.cljs b/src/cljs/auto_ap/views/components/invoice_table.cljs index fa0232fb..b99778a7 100644 --- a/src/cljs/auto_ap/views/components/invoice_table.cljs +++ b/src/cljs/auto_ap/views/components/invoice_table.cljs @@ -152,28 +152,27 @@ :icon "icon-accounting-bill"}]} [:div (for [payment payments] - (if (:check-number (:payment payment)) - ^{:key (:id payment)} - [:a.dropdown-item {:href (str (bidi/path-for routes/routes :payments ) - "?" - (url/map->query {:exact-match-id (:id (:payment payment))})) - :target "_new"} - [:i.fa.fa-money-check] - [:span.icon {:class [(when (= :cleared (:status (:payment payment))) - "has-text-success")]} - [:i.fa.fa-money]] + ^{:key (:id payment)} + [:a.dropdown-item {:href (str (bidi/path-for routes/routes :payments ) + "?" + (url/map->query {:exact-match-id (:id (:payment payment))})) + :target "_new"} + [:i.fa.fa-money-check] + [:span.icon {:class [(when (= :cleared (:status (:payment payment))) + "has-text-success")]} + [:i.fa.fa-money]] - (if (:check-number (:payment payment)) - (str "Check " (:check-number (:payment payment)) - " (" (gstring/format "$%.2f" (:amount payment) ) ")" - (when (= :cleared (:status (:payment payment))) - (str " - " (:post-date (:transaction (:payment payment)))))) + (if (:check-number (:payment payment)) + (str "Check " (:check-number (:payment payment)) + " (" (gstring/format "$%.2f" (:amount payment) ) ")" + (when (= :cleared (:status (:payment payment))) + (str " - " (:post-date (:transaction (:payment payment)))))) - (str "Debit (" (gstring/format "$%.2f" (:amount payment) ) ") " - (when (= :cleared (:status (:payment payment))) - (str " - " (:post-date (:transaction (:payment payment))))) - (when (= :cleared (:status (:payment payment))) - (str " - " (:post-date (:transaction (:payment payment))))))) ]))]] + (str "Debit (" (gstring/format "$%.2f" (:amount payment) ) ") " + (when (= :cleared (:status (:payment payment))) + (str " - " (:post-date (:transaction (:payment payment))))) + (when (= :cleared (:status (:payment payment))) + (str " - " (:post-date (:transaction (:payment payment))))))) ])]] [:span {:style {:margin-right "1em"}}]]) (when (and (get actions :edit) (not= ":voided" (:status i))) diff --git a/src/cljs/auto_ap/views/pages/transactions/form.cljs b/src/cljs/auto_ap/views/pages/transactions/form.cljs index 7b2b55c4..4aa7e3a3 100644 --- a/src/cljs/auto_ap/views/pages/transactions/form.cljs +++ b/src/cljs/auto_ap/views/pages/transactions/form.cljs @@ -1,5 +1,6 @@ (ns auto-ap.views.pages.transactions.form (:require [auto-ap.forms :as forms] + [auto-ap.status :as status] [auto-ap.subs :as subs] [auto-ap.views.components.button-radio :refer [button-radio]] [auto-ap.views.components.expense-accounts-field @@ -10,13 +11,13 @@ [auto-ap.views.components.layouts :as layouts] [auto-ap.views.components.typeahead :refer [typeahead-entity]] [auto-ap.views.pages.transactions.common :refer [transaction-read]] - [auto-ap.views.utils :refer [->$ date->str dispatch-event with-user]] + [auto-ap.views.utils + :refer + [->$ date->str dispatch-event pretty with-user]] [clojure.string :as str] [re-frame.core :as re-frame] - [auto-ap.status :as status] - [reagent.core :as r] [react :as react] - [reagent.core :as reagent])) + [reagent.core :as r])) ;; SUBS (re-frame/reg-sub @@ -59,19 +60,14 @@ (-> which (select-keys [:vendor :amount :payment :client :description-original :yodlee-merchant :id :potential-payment-matches - :forecast-match + :forecast-match :date :location :accounts :approval-status :matched-rule]) + (update :date #(date->str % pretty)) (assoc :original-status (:approval-status which)) - (assoc :potential-payment-matches (if (:matched-rule which) - nil - potential-payment-matches)) - (assoc :potential-transaction-rule-matches (if (:matched-rule which) - nil - potential-transaction-rule-matches)) - (assoc :potential-autopay-invoices-matches (if (:matched-rule which) - nil - potential-autopay-invoices-matches)) + (assoc :potential-payment-matches potential-payment-matches) + (assoc :potential-transaction-rule-matches potential-transaction-rule-matches) + (assoc :potential-autopay-invoices-matches potential-autopay-invoices-matches) (update :accounts expense-accounts-field/from-graphql accounts-by-id (:amount which) locations)))))) (re-frame/reg-event-db @@ -295,8 +291,7 @@ is-admin? @(re-frame/subscribe [::subs/is-admin?]) should-disable-for-client? (and (not is-admin?) (not= :requires-feedback (:original-status data))) - is-already-matched? (or (:matched-rule data) - (:payment data))] + is-already-matched? (:payment data)] (form-inline {:title "Transaction"} [:<> @@ -324,17 +319,21 @@ :field [:description-original] :disabled "disabled"}]) - + (field "Date" + [:input.input {:type "text" + :field [:date] + :disabled "disabled"}]) + + (when (and (:payment data) is-admin?) [:p.notification.is-info.is-light>div.level>div.level-left [:div.level-item "This transaction is linked to a payment "] [:div.level-item [:button.button.is-warning {:on-click (dispatch-event [::unlink])} "Unlink"]]]) - [tabs {:default-tab :details} (when (and (seq (:potential-transaction-rule-matches data)) - (not is-already-matched?) + (not (:matched-rule data)) is-admin?) [tab {:title "Transaction Rule" :key :transaction-rule} [potential-transaction-rule-matches-box {:potential-transaction-rule-matches (:potential-transaction-rule-matches data)}]]) @@ -349,9 +348,9 @@ (when (and (seq (:potential-payment-matches data)) (not is-already-matched?) - - [tab {:title "Payment" :key :payment} - [potential-payment-matches-box {:potential-payment-matches (:potential-payment-matches data)}]])) + ) + [tab {:title "Payment" :key :payment} + [potential-payment-matches-box {:potential-payment-matches (:potential-payment-matches data)}]]) [tab {:title "Details" :key :details} [:div