locations.
This commit is contained in:
@@ -50,12 +50,18 @@
|
||||
[]
|
||||
clients))))
|
||||
|
||||
;; Bank accounts only, not including cash
|
||||
(re-frame/reg-sub
|
||||
::real-bank-accounts
|
||||
::real-bank-accounts
|
||||
:<- [::client]
|
||||
(fn [client]
|
||||
(->> client :bank-accounts (filter #(= (:type %) :check)) (sort-by :sort-order))))
|
||||
|
||||
(re-frame/reg-sub
|
||||
::locations-for-client
|
||||
|
||||
(fn [db [_ client]]
|
||||
(:locations (get (:clients db) (or client (:client db))))))
|
||||
|
||||
(re-frame/reg-sub
|
||||
::clients-by-id
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
true))
|
||||
|
||||
(re-frame/reg-sub
|
||||
::account-request
|
||||
::request
|
||||
:<- [::forms/form ::form]
|
||||
(fn [{{:keys [id location type numeric-code name account-set]} :data}]
|
||||
{:id id
|
||||
@@ -49,7 +49,7 @@
|
||||
:query-obj {:venia/operation {:operation/type :mutation
|
||||
:operation/name "UpsertAccount"}
|
||||
:venia/queries [{:query/data [:upsert-account
|
||||
{:account @(re-frame/subscribe [::account-request])}
|
||||
{:account @(re-frame/subscribe [::request])}
|
||||
[:id :type :name :account-set :numeric-code :location]]}]}
|
||||
:on-success [::edited edit-completed]
|
||||
:on-error [::forms/save-error ::form]}}))))
|
||||
@@ -130,7 +130,7 @@
|
||||
[:div.notification.is-warning.animated.fadeInUp
|
||||
error])
|
||||
|
||||
[:button.button.is-large.is-primary {:disabled (if (s/valid? ::entity/account @(re-frame/subscribe [::account-request]))
|
||||
[:button.button.is-large.is-primary {:disabled (if (s/valid? ::entity/account @(re-frame/subscribe [::request]))
|
||||
""
|
||||
"disabled")
|
||||
:on-click (dispatch-event [::saving edit-completed])
|
||||
|
||||
@@ -99,14 +99,14 @@
|
||||
[:td.has-text-right (nf amount )]
|
||||
|
||||
[:td status]]]
|
||||
(for [{:keys [debit credit account]} line-items]
|
||||
(for [{:keys [debit credit location account]} line-items]
|
||||
[:tr {:class (:class i)}
|
||||
(when-not selected-client
|
||||
[:td ])
|
||||
[:td ]
|
||||
#_[:td description-original]
|
||||
[:td ]
|
||||
[:td (:name account)]
|
||||
[:td location ": " (:name account)]
|
||||
[:td.has-text-right (when debit (nf debit ))]
|
||||
[:td.has-text-right (when credit (nf credit ))]
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
(def transaction-read
|
||||
[:id
|
||||
:amount
|
||||
:location
|
||||
[:vendor [:name :id]]
|
||||
[:account [:id :name]]
|
||||
:date
|
||||
|
||||
@@ -11,10 +11,20 @@
|
||||
(fn [db [_ which]]
|
||||
(-> db
|
||||
(forms/start-form ::edit-transaction {:id (:id which)
|
||||
:location (:location which)
|
||||
:client-id (:id (:client which))
|
||||
:account-id (:id (:account which))
|
||||
:account-name (:name (:account which))
|
||||
:vendor-id (:id (:vendor which))
|
||||
:vendor-name (:name (:vendor which))}))))
|
||||
(re-frame/reg-sub
|
||||
::request
|
||||
:<- [::forms/form ::edit-transaction]
|
||||
(fn [{{:keys [id vendor-id account-id location]} :data}]
|
||||
{:transaction {:id id
|
||||
:location location
|
||||
:vendor-id vendor-id
|
||||
:account-id account-id}}))
|
||||
|
||||
(re-frame/reg-sub
|
||||
::can-submit
|
||||
@@ -34,26 +44,33 @@
|
||||
::saving
|
||||
(fn [{:keys [db]} [_ edit-completed]]
|
||||
(when @(re-frame/subscribe [::can-submit])
|
||||
(let [{{:keys [id vendor-id account-id]} :data :as data} @(re-frame/subscribe [::forms/form ::edit-transaction])]
|
||||
(let [{{:keys [id vendor-id account-id location]} :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
|
||||
:account-id account-id}}
|
||||
@(re-frame/subscribe [::request])
|
||||
transaction-read]}]}
|
||||
:on-success [::edited edit-completed]
|
||||
:on-error [::forms/save-error ::edit-transaction]}}))))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::change-account
|
||||
(fn [{:keys [db]} [_ f a]]
|
||||
(if-let [forced-location (and (= f [:account-id])
|
||||
(:location @(re-frame/subscribe [::subs/account a])))]
|
||||
{:dispatch-n [[::forms/change ::edit-transaction f a]
|
||||
[::forms/change ::edit-transaction [:location] forced-location]]}
|
||||
{:dispatch [::forms/change ::edit-transaction f a]})))
|
||||
|
||||
|
||||
(defn form [{:keys [edit-completed]}]
|
||||
[forms/side-bar-form {:form ::edit-transaction }
|
||||
(let [{:keys [data active? error id]} @(re-frame/subscribe [::forms/form ::edit-transaction])
|
||||
data (assoc data :merchant-name "Hello") ;; TODO - just until merchant is added
|
||||
current-client @(re-frame/subscribe [::subs/client])
|
||||
locations @(re-frame/subscribe [::subs/locations-for-client (:client-id data)])
|
||||
change-event [::forms/change ::edit-transaction]]
|
||||
^{:key id}
|
||||
[:form { :on-submit (fn [e]
|
||||
@@ -98,7 +115,7 @@
|
||||
:field [:always-map]
|
||||
:subscription data}]
|
||||
" Always match Merchant '" (:merchant-name data) "' to '" (:vendor-name data) "'" ]]])
|
||||
|
||||
|
||||
[:div.field
|
||||
[:p.help "Credit Account"]
|
||||
[:div.control
|
||||
@@ -107,9 +124,26 @@
|
||||
:type "typeahead"
|
||||
:field [:account-id]
|
||||
:text-field [:account-name]
|
||||
:event change-event
|
||||
:event [::change-account]
|
||||
:subscription data}]]]]
|
||||
|
||||
[:div.field
|
||||
[:p.help "Location"]
|
||||
[:div.control
|
||||
(if-let [forced-location (:location @(re-frame/subscribe [::subs/account (-> data :account-id )]))]
|
||||
[:div.select
|
||||
[:select {:disabled "disabled" :value forced-location} [:option {:value forced-location} forced-location]]]
|
||||
[:div.select
|
||||
[bind-field
|
||||
[:select {:type "select"
|
||||
:allow-nil? true
|
||||
:field [:location]
|
||||
:spec (set locations)
|
||||
:event change-event
|
||||
:subscription data}
|
||||
(map (fn [l] ^{:key l} [:option {:value l} l]) locations)]]])]]
|
||||
|
||||
|
||||
(when error
|
||||
^{:key error} [:div.notification.is-warning.animated.fadeInUp
|
||||
error])
|
||||
|
||||
@@ -81,7 +81,7 @@
|
||||
(defn with-keys [children]
|
||||
(map-indexed (fn [i c] ^{:key i} c) children))
|
||||
|
||||
(defmethod do-bind "select" [dom {:keys [field subscription event class value spec] :as keys} & rest]
|
||||
(defmethod do-bind "select" [dom {:keys [field allow-nil? subscription event class value spec] :as keys} & rest]
|
||||
(let [field (if (keyword? field) [field] field)
|
||||
event (if (keyword? event) [event] event)
|
||||
keys (assoc keys
|
||||
@@ -91,8 +91,11 @@
|
||||
:class (str class
|
||||
(when (and spec (not (s/valid? spec (get-in subscription field))))
|
||||
" is-danger")))
|
||||
keys (dissoc keys :field :subscription :event :spec)]
|
||||
(into [dom keys] (with-keys rest))))
|
||||
keys (dissoc keys :field :subscription :event :spec)
|
||||
options (if allow-nil?
|
||||
(with-keys (conj rest [:option {:value nil}]))
|
||||
(with-keys rest))]
|
||||
(into [dom keys] options)))
|
||||
|
||||
|
||||
(defmethod do-bind "radio" [dom {:keys [field subscription event class value spec] :as keys} & rest]
|
||||
|
||||
Reference in New Issue
Block a user