Supports assigning vendors to transactions
This commit is contained in:
@@ -17,6 +17,18 @@
|
||||
[auto-ap.views.components.invoice-table :refer [invoice-table] :as invoice-table]
|
||||
[auto-ap.subs :as subs]))
|
||||
|
||||
(def transaction-read
|
||||
[:id
|
||||
:amount
|
||||
[:vendor [:name :id]]
|
||||
:date
|
||||
:post_date
|
||||
:status
|
||||
:description_original
|
||||
[:payment [:check_number :s3_url]]
|
||||
[:client [:name :id]]
|
||||
[:bank-account [:name :yodlee-account-id]]])
|
||||
|
||||
|
||||
(re-frame/reg-sub
|
||||
::transaction-page
|
||||
@@ -38,16 +50,7 @@
|
||||
:graphql {:token (-> cofx :db :user)
|
||||
:query-obj {:venia/queries [[:transaction_page
|
||||
(assoc params :client-id (:id @(re-frame/subscribe [::subs/client])))
|
||||
[[:transactions [:id
|
||||
:amount
|
||||
[:vendor [:name :id]]
|
||||
:date
|
||||
:post_date
|
||||
:status
|
||||
:description_original
|
||||
[:payment [:check_number :s3_url]]
|
||||
[:client [:name :id]]
|
||||
[:bank-account [:name :yodlee-account-id]]]]
|
||||
[[:transactions transaction-read]
|
||||
:total
|
||||
:start
|
||||
:end]]]}
|
||||
@@ -63,14 +66,56 @@
|
||||
(re-frame/reg-event-db
|
||||
::transaction-editing
|
||||
(fn [db [_ which]]
|
||||
(println (:vendor which))
|
||||
(-> db
|
||||
(forms/start-form ::edit-transaction {}))))
|
||||
(forms/start-form ::edit-transaction {:id (:id which)
|
||||
:vendor-id (:id (:vendor which))
|
||||
:vendor-name (:name (:vendor which))}))))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::invalidated
|
||||
(fn [cofx [_ params]]
|
||||
{:dispatch [::params-change @(re-frame/subscribe [::params])]}))
|
||||
|
||||
(re-frame/reg-sub
|
||||
::can-submit-edit-transaction
|
||||
:<- [::forms/form ::edit-transaction]
|
||||
(fn [{:keys [data status]} _]
|
||||
(not= :loading status)))
|
||||
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::transaction-edited
|
||||
(fn [{:keys [db]} [_ {:keys [edit-transaction]}]]
|
||||
{:db (-> db
|
||||
(forms/stop-form ::edit-transaction)
|
||||
(update-in [::transaction-page :transactions]
|
||||
(fn [ts]
|
||||
(mapv (fn [t]
|
||||
(if (= (:id t) (:id edit-transaction))
|
||||
(assoc edit-transaction :class "live-added")
|
||||
t))
|
||||
ts))))}))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::edit-transaction-saving
|
||||
(fn [{:keys [db]} _]
|
||||
(when @(re-frame/subscribe [::can-submit-edit-transaction])
|
||||
(let [{{:keys [id vendor-id]} :data :as data} @(re-frame/subscribe [::forms/form ::edit-transaction])]
|
||||
|
||||
{:db (forms/loading db ::edit-transaction )
|
||||
:graphql
|
||||
{:token (-> db :user)
|
||||
:query-obj {:venia/operation {:operation/type :mutation
|
||||
:operation/name "EditTransaction"}
|
||||
|
||||
:venia/queries [{:query/data [:edit-transaction
|
||||
{:transaction {:id id :vendor-id vendor-id}}
|
||||
|
||||
transaction-read]}]}
|
||||
:on-success [::transaction-edited]
|
||||
:on-error [::forms/save-error ::edit-transaction]}}))))
|
||||
|
||||
(re-frame/reg-event-db
|
||||
::change-selected-bank-account
|
||||
(fn [db [_ key value]]
|
||||
@@ -164,7 +209,7 @@
|
||||
[:td status]
|
||||
[:td (:name bank-account )]
|
||||
[:td
|
||||
[:a.button {:on-click (dispatch-event [::transaction-editing id])} [:span [:span.icon [:i.fa.fa-pencil]]]]
|
||||
[:a.button {:on-click (dispatch-event [::transaction-editing i])} [:span [:span.icon [:i.fa.fa-pencil]]]]
|
||||
(when check
|
||||
[:a.tag {:href (:s3-url check) :target "_new"} [:i.fa.fa-money-check] [:span.icon [:i.fa.fa-money]] (str " " (:check-number check) " (" (gstring/format "$%.2f" amount ) ")")])]
|
||||
]))]]]))))
|
||||
@@ -297,7 +342,7 @@
|
||||
[bind-field
|
||||
[typeahead {:matches (map (fn [x] [(:id x) (:name x)]) @(re-frame/subscribe [::subs/vendors]))
|
||||
:type "typeahead"
|
||||
:auto-focus (if @(re-frame/subscribe [::subs/client]) true false)
|
||||
:auto-focus true
|
||||
:field [:vendor-id]
|
||||
:text-field [:vendor-name]
|
||||
:event change-event
|
||||
@@ -326,7 +371,7 @@
|
||||
^{:key error} [:div.notification.is-warning.animated.fadeInUp
|
||||
error])
|
||||
|
||||
[:button.button.is-medium.is-primary.is-fullwidth {#_#_:disabled (if @(re-frame/subscribe [::can-submit-edit-invoice])
|
||||
[:button.button.is-medium.is-primary.is-fullwidth {:disabled (if @(re-frame/subscribe [::can-submit-edit-transaction])
|
||||
""
|
||||
"disabled")
|
||||
:class (str @(re-frame/subscribe [::forms/loading-class ::edit-transaction])
|
||||
|
||||
Reference in New Issue
Block a user