allows manually matching rules.
This commit is contained in:
@@ -43,7 +43,7 @@
|
||||
|
||||
(re-frame/reg-event-db
|
||||
::editing
|
||||
(fn [db [_ which potential-payment-matches]]
|
||||
(fn [db [_ which potential-payment-matches potential-transaction-rule-matches]]
|
||||
(let [locations @(re-frame/subscribe [::subs/locations-for-client (:id (:client which))])]
|
||||
(forms/start-form db ::form
|
||||
(-> which
|
||||
@@ -51,7 +51,12 @@
|
||||
:yodlee-merchant :id :potential-payment-matches
|
||||
:exclude-from-ledger :location :accounts :transaction-approval-status
|
||||
:matched-rule])
|
||||
(assoc :potential-payment-matches potential-payment-matches)
|
||||
(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))
|
||||
(update :accounts expense-accounts-field/from-graphql (:amount which) locations))))))
|
||||
|
||||
(re-frame/reg-event-db
|
||||
@@ -94,11 +99,26 @@
|
||||
:on-success [::edited params]
|
||||
:on-error [::forms/save-error ::form]}}))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::matching-rule
|
||||
[with-user (forms/triggers-loading ::form) (forms/in-form ::form)]
|
||||
(fn [{{{:keys [id]} :data} :db user :user} [_ params transaction-rule-id]]
|
||||
{:graphql
|
||||
{:token user
|
||||
:query-obj {:venia/operation {:operation/type :mutation
|
||||
:operation/name "MatchTransactionRule"}
|
||||
:venia/queries [{:query/data [:match-transaction-rule
|
||||
{:transaction-id id
|
||||
:transaction-rule-id transaction-rule-id}
|
||||
transaction-read]}]}
|
||||
:on-success [::edited params]
|
||||
:on-error [::forms/save-error ::form]}}))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::edited
|
||||
[(forms/triggers-stop ::form)]
|
||||
(fn [{:keys [db]} [_ {:keys [edit-completed]} {:keys [edit-transaction match-transaction]}]]
|
||||
{:dispatch (conj edit-completed (or edit-transaction match-transaction))}))
|
||||
(fn [{:keys [db]} [_ {:keys [edit-completed]} {:keys [edit-transaction match-transaction match-transaction-rule]}]]
|
||||
{:dispatch (conj edit-completed (or edit-transaction match-transaction match-transaction-rule))}))
|
||||
|
||||
(re-frame/reg-event-db
|
||||
::manual-match
|
||||
@@ -106,6 +126,12 @@
|
||||
(fn [edit-transaction]
|
||||
(update-in edit-transaction [:data] dissoc :potential-payment-matches)))
|
||||
|
||||
(re-frame/reg-event-db
|
||||
::transaction-rule-closed
|
||||
[(forms/in-form ::form)]
|
||||
(fn [edit-transaction]
|
||||
(update-in edit-transaction [:data] dissoc :potential-transaction-rule-matches)))
|
||||
|
||||
;; VIEWS
|
||||
|
||||
(def transaction-form (forms/vertical-form {:can-submit [::can-submit]
|
||||
@@ -113,6 +139,23 @@
|
||||
:submit-event [::saving ]
|
||||
:id ::form}))
|
||||
|
||||
(defn potential-transaction-rule-matches-box [{:keys [potential-transaction-rule-matches] :as params}]
|
||||
[:div.box
|
||||
[:div.columns
|
||||
[:div.column
|
||||
[:h1.subtitle.is-5 "Matching Rules:"]]
|
||||
[:div.column.is-narrow
|
||||
[:a.delete {:on-click (dispatch-event [::transaction-rule-closed])} ]]]
|
||||
|
||||
[:table.table.compact.is-borderless
|
||||
(for [{:keys [note id]} potential-transaction-rule-matches]
|
||||
^{:key id}
|
||||
[:tr
|
||||
[:td.no-border note]
|
||||
[:td.no-border
|
||||
[:a.button.is-primary.is-small {:on-click (dispatch-event [::matching-rule params id])}
|
||||
"Use this rule"]]])]])
|
||||
|
||||
|
||||
(defn potential-payment-matches-box [{:keys [potential-payment-matches] :as params}]
|
||||
[:div.box
|
||||
@@ -165,11 +208,21 @@
|
||||
:field [:description-original]
|
||||
:disabled "disabled"}]]
|
||||
|
||||
(if (and (seq (:potential-payment-matches data))
|
||||
(not (:payment data)))
|
||||
[potential-payment-matches-box {:potential-payment-matches (:potential-payment-matches data)
|
||||
:edit-completed edit-completed}]
|
||||
|
||||
(when (and (seq (:potential-transaction-rule-matches data))
|
||||
(not (:matched-rule data))
|
||||
(not (:payment data)))
|
||||
[potential-transaction-rule-matches-box {:potential-transaction-rule-matches (:potential-transaction-rule-matches data)
|
||||
:edit-completed edit-completed}])
|
||||
|
||||
|
||||
(when (and (seq (:potential-payment-matches data))
|
||||
(not (:payment data)))
|
||||
[potential-payment-matches-box {:potential-payment-matches (:potential-payment-matches data)
|
||||
:edit-completed edit-completed}])
|
||||
|
||||
(when (and (not (seq (:potential-payment-matches data)))
|
||||
(not (seq (:potential-transaction-rule-matches data))))
|
||||
[:div
|
||||
[field "Vendor"
|
||||
[typeahead-entity {:matches @(re-frame/subscribe [::subs/vendors])
|
||||
|
||||
@@ -10,9 +10,9 @@
|
||||
[re-frame.core :as re-frame]))
|
||||
(re-frame/reg-event-fx
|
||||
::editing-matches-found
|
||||
(fn [{:keys [db]} [_ which payment-matches]]
|
||||
(fn [{:keys [db]} [_ which matches]]
|
||||
{:dispatch
|
||||
[::edit/editing which (:potential-payment-matches payment-matches)]}))
|
||||
[::edit/editing which (:potential-payment-matches matches) (:potential-transaction-rule-matches matches)]}))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::editing-matches-failed
|
||||
@@ -25,9 +25,13 @@
|
||||
(fn [{:keys [db]} [_ which]]
|
||||
{:graphql
|
||||
{:token (-> db :user)
|
||||
:query-obj {:venia/queries [{:query/data [:potential-payment-matches
|
||||
{:transaction_id (:id which)}
|
||||
[:id :memo :check-number [:vendor [:name]]]]}]}
|
||||
:query-obj {:venia/queries (into [{:query/data [:potential-payment-matches
|
||||
{:transaction_id (:id which)}
|
||||
[:id :memo :check-number [:vendor [:name]]]]}]
|
||||
(when @(re-frame/subscribe [::subs/is-admin?])
|
||||
[{:query/data [:potential-transaction-rule-matches
|
||||
{:transaction_id (:id which)}
|
||||
[:id :note]]}]))}
|
||||
:on-success [::editing-matches-found which]
|
||||
:on-error [::editing-matches-failed which]}} ))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user