bank accounts can now have locations.
This commit is contained in:
@@ -42,7 +42,7 @@
|
||||
:graphql {:token token
|
||||
:query-obj {:venia/queries [[:client
|
||||
|
||||
[:id :name :code :email :locations [:bank-accounts [:id :code :number :bank-name :bank-code :check-number :name :routing :type :sort-order :visible :yodlee-account-id] ]
|
||||
[:id :name :code :email :locations [:bank-accounts [:id :code :number :bank-name :bank-code :check-number :name :routing :type :sort-order :visible :yodlee-account-id :locations] ]
|
||||
[:address [:street1 :street2 :city :state :zip]]]]
|
||||
[:vendor
|
||||
[:id :name :hidden [:default-account [:name :id :location]] [:primary-contact [:name :phone :email :id]] [:secondary-contact [:id :name :phone :email]] :print-as :invoice-reminder-schedule :code]]
|
||||
@@ -65,7 +65,7 @@
|
||||
(fn [{:keys [db]} [_ token user]]
|
||||
{:graphql {:token token
|
||||
:query-obj {:venia/queries [[:client
|
||||
[:id :name :code [:address [:street1 :street2 :city :state :zip]] [:bank-accounts [:id :code :number :bank-name :bank-code :check-number :name :routing :type :sort-order :visible :yodlee-account-id] ]]]
|
||||
[:id :name :code [:address [:street1 :street2 :city :state :zip]] [:bank-accounts [:id :code :number :bank-name :bank-code :check-number :name :routing :type :sort-order :visible :yodlee-account-id :locations] ]]]
|
||||
[:vendor
|
||||
[:id :name :hidden [:default-account [:name :id :location]] [:primary-contact [:name :phone :email :id]] [:secondary-contact [:id :name :phone :email]] :print-as :invoice-reminder-schedule :code]]
|
||||
[:accounts [:numeric-code :name :location :type :account_set :id]]]}
|
||||
|
||||
@@ -74,6 +74,16 @@
|
||||
(fn [db [_ client]]
|
||||
(:locations (get (:clients db) (or client (:client db))))))
|
||||
|
||||
(re-frame/reg-sub
|
||||
::locations-for-client-or-bank-account
|
||||
(fn [db [_ client-id bank-account-id]]
|
||||
(let [client (get (:clients db) (or client (:client db)))
|
||||
client-locations (:locations client)
|
||||
bank-account-locations (-> (by :id (:bank-accounts client))
|
||||
(get bank-account-id)
|
||||
:locations)]
|
||||
(or bank-account-locations client-locations))))
|
||||
|
||||
(re-frame/reg-sub
|
||||
::clients-by-id
|
||||
(fn [db]
|
||||
|
||||
@@ -47,7 +47,7 @@
|
||||
:city (:city (:address new-client-data))
|
||||
:state (:state (:address new-client-data))
|
||||
:zip (:zip (:address new-client-data))}
|
||||
:bank-accounts (map (fn [{:keys [number name check-number type id code bank-name routing bank-code new? sort-order visible yodlee-account-id]}]
|
||||
:bank-accounts (map (fn [{:keys [number name check-number type id code bank-name routing bank-code new? sort-order visible yodlee-account-id locations]}]
|
||||
{:number number
|
||||
:name name
|
||||
:check-number check-number
|
||||
@@ -55,6 +55,7 @@
|
||||
:id id
|
||||
:sort-order sort-order
|
||||
:visible visible
|
||||
:locations (vec locations)
|
||||
:yodlee-account-id (when yodlee-account-id
|
||||
(js/parseInt yodlee-account-id))
|
||||
:code (if new?
|
||||
@@ -85,7 +86,7 @@
|
||||
:operation/name "EditClient"}
|
||||
:venia/queries [{:query/data [:edit-client
|
||||
{:edit-client new-client-req}
|
||||
[:id :name :code :email :locations [:address [:street1 :street2 :city :state :zip]] [:bank-accounts [:id :number :check-number :name :code :bank-code :bank-name :routing :type :visible :yodlee-account-id :sort-order]]]]}]}
|
||||
[:id :name :code :email :locations [:address [:street1 :street2 :city :state :zip]] [:bank-accounts [:id :number :check-number :name :code :bank-code :bank-name :routing :type :visible :yodlee-account-id :sort-order :locations]]]]}]}
|
||||
:on-success [::save-complete]
|
||||
:on-error [::forms/save-error ::new-client]}}
|
||||
{:db new-client-form}))))
|
||||
@@ -107,6 +108,15 @@
|
||||
(update :locations conj (:location client))
|
||||
(dissoc :location))))
|
||||
|
||||
(re-frame/reg-event-db
|
||||
::add-location-to-bank-account
|
||||
[(forms/in-form ::new-client) (re-frame/path [:data])]
|
||||
(fn [client [_ which-account]]
|
||||
(println client which-account)
|
||||
(-> client
|
||||
(update-in [:bank-accounts which-account :locations] #(conj (or % #{}) (get-in client [:bank-accounts which-account :location-select])))
|
||||
(update-in [:bank-accounts which-account] dissoc :location-select))))
|
||||
|
||||
(re-frame/reg-event-db
|
||||
::add-new-bank-account
|
||||
[(forms/in-form ::new-client) (re-frame/path [:data])]
|
||||
@@ -306,7 +316,9 @@
|
||||
:type "text"
|
||||
:field [:bank-accounts sort-order :yodlee-account-id]
|
||||
:event change-event
|
||||
:subscription new-client}]]]]])
|
||||
:subscription new-client}]]]]
|
||||
|
||||
])
|
||||
(when (#{:credit ":credit"} type )
|
||||
[:div
|
||||
|
||||
@@ -340,7 +352,30 @@
|
||||
:type "text"
|
||||
:field [:bank-accounts sort-order :yodlee-account-id]
|
||||
:event change-event
|
||||
:subscription new-client}]]]]])])
|
||||
:subscription new-client}]]]]])
|
||||
[:div.field
|
||||
[:label.label "Locations"]
|
||||
[:div.control
|
||||
[:p.help "If this account is location-specific, add the valid locations"]
|
||||
[:div.field.has-addons
|
||||
[:p.control
|
||||
[:div.select
|
||||
[bind-field
|
||||
[:select {:type "select"
|
||||
:style {:width "7em"}
|
||||
:field [:bank-accounts sort-order :location-select]
|
||||
:allow-nil? true
|
||||
:spec (set (get-in new-client [:locations]))
|
||||
:event change-event
|
||||
:subscription new-client}
|
||||
(map (fn [l] ^{:key l} [:option {:value l} l]) (get-in new-client [:locations]))]]]]
|
||||
[:p.control {:on-click (dispatch-event [::add-location-to-bank-account sort-order]) } [:a.button "Add"]]]]
|
||||
|
||||
(if-let [locations (seq (get-in new-client [:bank-accounts sort-order :locations]))]
|
||||
[:ul
|
||||
(for [location locations]
|
||||
^{:key location} [:li location ])]
|
||||
[:i "This account applies to all locations"])]])
|
||||
|
||||
(when active?
|
||||
[:footer.card-footer
|
||||
|
||||
@@ -289,7 +289,7 @@
|
||||
[expense-accounts-field {:type "expense-accounts"
|
||||
:descriptor "account asssignment"
|
||||
:percentage-only? true
|
||||
:locations (into ["Shared"] @(re-frame/subscribe [::subs/locations-for-client (:id (:client data))]))
|
||||
:locations (into ["Shared"] @(re-frame/subscribe [::subs/locations-for-client-or-bank-account (:id (:client data)) (:id (:bank-account data))]))
|
||||
:max 100
|
||||
:field [:accounts]}]]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user