tells you about potential matches.

This commit is contained in:
Bryce Covert
2019-04-24 07:35:19 -07:00
parent deef4eb4a4
commit f547911c5b
6 changed files with 104 additions and 34 deletions

View File

@@ -4,7 +4,7 @@
[auto-ap.views.components.typeahead :refer [typeahead]]
[auto-ap.views.components.expense-accounts-field :refer [expense-accounts-field]]
[auto-ap.views.pages.transactions.common :refer [transaction-read]]
[auto-ap.views.utils :refer [bind-field]]
[auto-ap.views.utils :refer [bind-field dispatch-event]]
[re-frame.core :as re-frame]
[clojure.string :as str]))
@@ -43,14 +43,16 @@
(re-frame/reg-event-db
::editing
(fn [db [_ which]]
(fn [db [_ which potential-payment-matches]]
(-> db
(forms/start-form ::edit-transaction {:id (:id which)
:yodlee-merchant (:yodlee-merchant which)
:amount (:amount which)
:potential-payment-matches potential-payment-matches
:description-original (:description-original which)
:location (:location which)
:exclude-from-ledger (:exclude-from-ledger which)
:payment (:payment which)
:client-id (:id (:client which))
:vendor-id (:id (:vendor which))
:vendor-name (:name (:vendor which))
@@ -94,6 +96,11 @@
[::forms/change ::edit-transaction [:location] forced-location]]}
{:dispatch [::forms/change ::edit-transaction f a]})))
(re-frame/reg-event-db
::manual-match
[(forms/in-form ::edit-transaction)]
(fn [edit-transaction]
(update-in edit-transaction [:data] dissoc :potential-payment-matches)))
;; VIEWS
@@ -143,30 +150,48 @@
:subscription data}]]]]
[:div.field
[:p.help "Vendor"]
[:div.control
[bind-field
[typeahead {:matches (map (fn [x] [(:id x) (:name x)]) @(re-frame/subscribe [::subs/vendors]))
:type "typeahead"
:auto-focus true
:field [:vendor-id]
:text-field [:vendor-name]
:event change-event
:subscription data}]]]]
(if (seq (:potential-payment-matches data))
[:div.box
[:div.columns
[:div.column
[:h1.subtitle.is-5 "Potentially matching payments:"]]
[:div.column.is-narrow
[:a.button {:on-click (dispatch-event [::manual-match])} [:i.fa.fa-times]]]]
[:ul
(list
(for [{:keys [memo vendor]} (:potential-payment-matches data)]
[:li (:name vendor) " - " memo " " [:a.button.is-primary.is-small "Match"]]
))]
]
[:div
[:div.field
[:p.help "Vendor"]
[:div.control
[bind-field
[typeahead {:matches (map (fn [x] [(:id x) (:name x)]) @(re-frame/subscribe [::subs/vendors]))
:type "typeahead"
:auto-focus true
:field [:vendor-id]
:text-field [:vendor-name]
:disabled (boolean (:payment data))
:event change-event
:subscription data}]]]]
[:div.field
[bind-field
[expense-accounts-field
{:type "expense-accounts"
:field [:accounts]
:max (Math/abs (js/parseFloat (:amount data)))
:descriptor "credit account"
:locations locations
:event change-event
:subscription data}]]]
[:div.field
[bind-field
[expense-accounts-field
{:type "expense-accounts"
:field [:accounts]
:max (Math/abs (js/parseFloat (:amount data)))
:descriptor "credit account"
:disabled (boolean (:payment data))
:locations locations
:event change-event
:subscription data}]]]])
[:div.field
[:div.control

View File

@@ -6,6 +6,32 @@
[auto-ap.views.utils :refer [date->str dispatch-event nf]]
[goog.string :as gstring]
[re-frame.core :as re-frame]))
(re-frame/reg-event-fx
::editing-matches-found
(fn [{:keys [db]} [_ which payment-matches]]
(println "FOUND" payment-matches)
{:dispatch
[::edit/editing which (:potential-payment-matches payment-matches)]}))
(re-frame/reg-event-fx
::editing-matches-failed
(fn [{:keys [db]} [_ which payment-matches]]
(println "FAILED" payment-matches)
{:dispatch
[::edit/editing which payment-matches]}))
(re-frame/reg-event-fx
::intend-to-edit
(fn [{:keys [db]} [_ which]]
{:graphql
{:token (-> db :user)
:query-obj {:venia/queries [{:query/data [:potential-payment-matches
{:transaction_id (:id which)}
[:id :memo [:vendor [:name]]]]}]}
:on-success [::editing-matches-found which]
:on-error [::editing-matches-failed which]}} ))
(defn table [{:keys [id transaction-page status on-params-change vendors params check-boxes checked on-check-changed expense-event]}]
(let [opc (fn [p]
@@ -96,7 +122,7 @@
[:td status]
[:td (:name bank-account )]
[:td
[:a.button {:on-click (dispatch-event [::edit/editing i])} [:span [:span.icon [:i.fa.fa-pencil]]]]
[:a.button {:on-click (dispatch-event [::intend-to-edit i])} [:span [:span.icon [:i.fa.fa-pencil]]]]
(when payment
[:a.tag {:href (:s3-url payment) :target "_new"}
#_[:i.fa.fa-money-check]