More and more expressive.
This commit is contained in:
@@ -7,7 +7,8 @@
|
|||||||
[auto-ap.views.pages.transactions.common :refer [transaction-read]]
|
[auto-ap.views.pages.transactions.common :refer [transaction-read]]
|
||||||
[auto-ap.views.utils :refer [bind-field dispatch-event]]
|
[auto-ap.views.utils :refer [bind-field dispatch-event]]
|
||||||
[re-frame.core :as re-frame]
|
[re-frame.core :as re-frame]
|
||||||
[clojure.string :as str]))
|
[clojure.string :as str]
|
||||||
|
[clojure.set :as set]))
|
||||||
|
|
||||||
;; SUBS
|
;; SUBS
|
||||||
(re-frame/reg-sub
|
(re-frame/reg-sub
|
||||||
@@ -34,37 +35,36 @@
|
|||||||
|
|
||||||
|
|
||||||
;; EVENTS
|
;; EVENTS
|
||||||
(re-frame/reg-event-fx
|
|
||||||
::edited
|
|
||||||
(fn [{:keys [db]} [_ edit-completed {:keys [edit-transaction match-transaction]}]]
|
|
||||||
{:db (-> db
|
|
||||||
(forms/stop-form ::form))
|
|
||||||
|
|
||||||
:dispatch (conj edit-completed (or edit-transaction match-transaction))}))
|
|
||||||
|
|
||||||
(re-frame/reg-event-db
|
(re-frame/reg-event-db
|
||||||
::editing
|
::editing
|
||||||
(fn [db [_ which potential-payment-matches]]
|
(fn [db [_ which potential-payment-matches]]
|
||||||
(let [locations @(re-frame/subscribe [::subs/locations-for-client (:id (:client which))])]
|
(let [locations @(re-frame/subscribe [::subs/locations-for-client (:id (:client which))])]
|
||||||
(-> db
|
(forms/start-form db ::form
|
||||||
(forms/start-form ::form {:id (:id which)
|
(-> which
|
||||||
:yodlee-merchant (:yodlee-merchant which)
|
(select-keys [:vendor :amount :payment :client :description-original
|
||||||
:amount (:amount which)
|
:yodlee-merchant :id :potential-payment-matches
|
||||||
:potential-payment-matches potential-payment-matches
|
:exclude-from-ledger :location :accounts])
|
||||||
:description-original (:description-original which)
|
(assoc :potential-payment-matches potential-payment-matches)
|
||||||
:location (:location which)
|
(update :accounts expense-accounts-field/from-graphql (:amount which) locations))))))
|
||||||
:exclude-from-ledger (:exclude-from-ledger which)
|
|
||||||
:payment (:payment which)
|
|
||||||
:client-id (:id (:client which))
|
|
||||||
:vendor (:vendor which)
|
|
||||||
:accounts (expense-accounts-field/from-graphql (:accounts which)
|
|
||||||
(:amount which)
|
|
||||||
locations)})))))
|
|
||||||
|
|
||||||
|
(re-frame/reg-event-fx
|
||||||
|
::change-vendor
|
||||||
|
[(forms/in-form ::form)]
|
||||||
|
(fn [{{:keys [data]} :db} [_ field value]]
|
||||||
|
(let [locations @(re-frame/subscribe [::subs/locations-for-client (:id (:client data))])]
|
||||||
|
(if (and value (expense-accounts-field/can-replace-with-default? (:accounts data)))
|
||||||
|
{:dispatch [::forms/change ::form
|
||||||
|
field value
|
||||||
|
[:accounts] (expense-accounts-field/default-account (:accounts data)
|
||||||
|
@(re-frame/subscribe [::subs/vendor-default-account value])
|
||||||
|
(:amount data)
|
||||||
|
locations)]}
|
||||||
|
{:dispatch [::forms/change ::form field value]}))))
|
||||||
|
|
||||||
(re-frame/reg-event-fx
|
(re-frame/reg-event-fx
|
||||||
::saving
|
::saving
|
||||||
(fn [{:keys [db]} [_ {:keys [edit-completed]}]]
|
(fn [{:keys [db]} [_ params]]
|
||||||
(when @(re-frame/subscribe [::can-submit])
|
(when @(re-frame/subscribe [::can-submit])
|
||||||
(let [{{:keys [id vendor-id account-id location]} :data :as data} @(re-frame/subscribe [::forms/form ::form])]
|
(let [{{:keys [id vendor-id account-id location]} :data :as data} @(re-frame/subscribe [::forms/form ::form])]
|
||||||
{:db (forms/loading db ::form )
|
{:db (forms/loading db ::form )
|
||||||
@@ -75,12 +75,13 @@
|
|||||||
:venia/queries [{:query/data [:edit-transaction
|
:venia/queries [{:query/data [:edit-transaction
|
||||||
@(re-frame/subscribe [::request])
|
@(re-frame/subscribe [::request])
|
||||||
transaction-read]}]}
|
transaction-read]}]}
|
||||||
:on-success [::edited edit-completed]
|
:on-success [::edited params]
|
||||||
:on-error [::forms/save-error ::form]}}))))
|
:on-error [::forms/save-error ::form]}}))))
|
||||||
|
|
||||||
|
|
||||||
(re-frame/reg-event-fx
|
(re-frame/reg-event-fx
|
||||||
::matching
|
::matching
|
||||||
(fn [{:keys [db]} [_ edit-completed payment-id]]
|
(fn [{:keys [db]} [_ params payment-id]]
|
||||||
(let [{{:keys [id ]} :data :as data} @(re-frame/subscribe [::forms/form ::form])]
|
(let [{{:keys [id ]} :data :as data} @(re-frame/subscribe [::forms/form ::form])]
|
||||||
{:db (forms/loading db ::form )
|
{:db (forms/loading db ::form )
|
||||||
:graphql
|
:graphql
|
||||||
@@ -91,23 +92,14 @@
|
|||||||
{:transaction_id id
|
{:transaction_id id
|
||||||
:payment-id payment-id}
|
:payment-id payment-id}
|
||||||
transaction-read]}]}
|
transaction-read]}]}
|
||||||
:on-success [::edited edit-completed]
|
:on-success [::edited params]
|
||||||
:on-error [::forms/save-error ::form]}})))
|
:on-error [::forms/save-error ::form]}})))
|
||||||
|
|
||||||
(re-frame/reg-event-fx
|
(re-frame/reg-event-fx
|
||||||
::change-vendor
|
::edited
|
||||||
[(forms/in-form ::form)]
|
(fn [{:keys [db]} [_ {:keys [edit-completed]} {:keys [edit-transaction match-transaction]}]]
|
||||||
(fn [{{:keys [data]} :db} [_ field value]]
|
{:db (-> db (forms/stop-form ::form))
|
||||||
(let [locations @(re-frame/subscribe [::subs/locations-for-client (:client-id data)])]
|
:dispatch (conj edit-completed (or edit-transaction match-transaction))}))
|
||||||
(if (and value (expense-accounts-field/can-replace-with-default? (:accounts data)))
|
|
||||||
{:dispatch [::forms/change ::form
|
|
||||||
field value
|
|
||||||
[:accounts] (expense-accounts-field/default-account (:accounts data)
|
|
||||||
@(re-frame/subscribe [::subs/vendor-default-account value])
|
|
||||||
(:amount data)
|
|
||||||
locations)]}
|
|
||||||
{:dispatch [::forms/change ::form field value]}))))
|
|
||||||
|
|
||||||
|
|
||||||
(re-frame/reg-event-db
|
(re-frame/reg-event-db
|
||||||
::manual-match
|
::manual-match
|
||||||
@@ -123,11 +115,30 @@
|
|||||||
:id ::form}))
|
:id ::form}))
|
||||||
|
|
||||||
|
|
||||||
|
(defn potential-payment-matches-box [{:keys [potential-payment-matches] :as params}]
|
||||||
|
[:div.box
|
||||||
|
[:div.columns
|
||||||
|
[:div.column
|
||||||
|
[:h1.subtitle.is-5 "Potentially matching payments:"]]
|
||||||
|
[:div.column.is-narrow
|
||||||
|
[:a.delete {:on-click (dispatch-event [::manual-match])} ]]]
|
||||||
|
|
||||||
|
[:table.table.compact.is-borderless
|
||||||
|
(list
|
||||||
|
(for [{:keys [memo check-number vendor id]} potential-payment-matches]
|
||||||
|
[:tr
|
||||||
|
[:td.no-border (:name vendor)]
|
||||||
|
[:td.no-border (when check-number (str "Check " check-number " ")) memo]
|
||||||
|
[:td.no-border
|
||||||
|
[:a.button.is-primary.is-small {:on-click (dispatch-event [::matching params id])}
|
||||||
|
"Match"]]]))]])
|
||||||
|
|
||||||
|
|
||||||
(defn form [{:keys [edit-completed]}]
|
(defn form [{:keys [edit-completed]}]
|
||||||
[layouts/side-bar {:on-close (dispatch-event [::forms/form-closing ::form])}
|
[layouts/side-bar {:on-close (dispatch-event [::forms/form-closing ::form])}
|
||||||
(let [change-event [::forms/change ::form]
|
(let [change-event [::forms/change ::form]
|
||||||
{:keys [data] } @(re-frame/subscribe [::forms/form ::form])
|
{:keys [data] } @(re-frame/subscribe [::forms/form ::form])
|
||||||
locations @(re-frame/subscribe [::subs/locations-for-client (:client-id data)])
|
locations @(re-frame/subscribe [::subs/locations-for-client (:id (:client data))])
|
||||||
{:keys [form field error-notification submit-button ]} my-form]
|
{:keys [form field error-notification submit-button ]} my-form]
|
||||||
[form {:title "Hello" :edit-completed edit-completed}
|
[form {:title "Hello" :edit-completed edit-completed}
|
||||||
[field "Merchant"
|
[field "Merchant"
|
||||||
@@ -142,24 +153,11 @@
|
|||||||
[:input.input {:type "text"
|
[:input.input {:type "text"
|
||||||
:field [:description-original]
|
:field [:description-original]
|
||||||
:disabled "disabled"}]]
|
:disabled "disabled"}]]
|
||||||
|
|
||||||
(if (and (seq (:potential-payment-matches data))
|
(if (and (seq (:potential-payment-matches data))
|
||||||
(not (:payment data)))
|
(not (:payment data)))
|
||||||
[:div.box
|
[potential-payment-matches-box {:matches (:potential-payment-matches data)
|
||||||
[:div.columns
|
:edit-completed edit-completed}]
|
||||||
[:div.column
|
|
||||||
[:h1.subtitle.is-5 "Potentially matching payments:"]]
|
|
||||||
[:div.column.is-narrow
|
|
||||||
[:a.delete {:on-click (dispatch-event [::manual-match])} ]]]
|
|
||||||
|
|
||||||
[:table.table.compact.is-borderless
|
|
||||||
(list
|
|
||||||
(for [{:keys [memo check-number vendor id]} (:potential-payment-matches data)]
|
|
||||||
[:tr
|
|
||||||
[:td.no-border (:name vendor)]
|
|
||||||
[:td.no-border (when check-number (str "Check " check-number " ")) memo]
|
|
||||||
[:td.no-border
|
|
||||||
[:a.button.is-primary.is-small {:on-click (dispatch-event [::matching edit-completed id])}
|
|
||||||
"Match"]]]))]]
|
|
||||||
|
|
||||||
[:div
|
[:div
|
||||||
[field "Vendor"
|
[field "Vendor"
|
||||||
|
|||||||
Reference in New Issue
Block a user