Supports adding and updating bank accounts

This commit is contained in:
BC
2019-02-12 11:57:59 -08:00
parent b85ba810b3
commit ef7b505337
4 changed files with 24 additions and 16 deletions

View File

@@ -56,7 +56,8 @@
})]
result @(d/transact (d/connect uri) transactions)]
(-> result :tempids (get id) d-clients/get-by-id ->graphql)))
(println result "ID" id)
(-> result :tempids (get id) (or id) d-clients/get-by-id ->graphql)))
(defn get-client [context args value]

View File

@@ -20,7 +20,11 @@
(s/def ::number string?)
(s/def ::yodlee-account-id string?)
(s/def ::bank-account (s/keys :req-un [::code ::name ::bank-name ::bank-code ::routing ::number]))
(s/def ::checking-bank-account (s/and (s/keys :req-un [::code ::name ::bank-name ::bank-code ::routing ::number ::type])
#(= (:type %) :check)))
(s/def ::cash-account (s/and (s/keys :req-un [::type])
#(= (:type %) :cash)))
(s/def ::bank-account (s/or :cash ::cash-account :checking ::checking-bank-account))
(s/def ::bank-accounts (s/coll-of ::bank-account))
(s/def ::location string?)

View File

@@ -41,7 +41,7 @@
:graphql {:token token
:query-obj {:venia/queries [[:client
[:id :name :code :email :locations [:bank-accounts [:id :code :number :check-number :name :type] ]
[:id :name :code :email :locations [:bank-accounts [:id :code :number :bank-name :bank-code :check-number :name :routing :type] ]
[:address [:street1 :street2 :city :state :zip]]]]
[:vendor
[:id :name :default-expense-account [:primary-contact [:name :phone :email :id]] [:secondary-contact [:id :name :phone :email]] :print-as :invoice-reminder-schedule :code]]]}
@@ -64,7 +64,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 :check-number :name :type]]]]
[:id :name :code [:address [:street1 :street2 :city :state :zip]] [:bank-accounts [:id :code :number :bank-name :bank-code :check-number :name :routing :type] ]]]
[:vendor
[:id :name :default-expense-account [:primary-contact [:name :phone :email :id]] [:secondary-contact [:id :name :phone :email]] :print-as :invoice-reminder-schedule :code]]]}

View File

@@ -20,14 +20,15 @@
(re-frame/reg-event-fx
::new
(fn [{:keys [db]} [_ client-id]]
{:db (assoc-in db [:admin :adding-client?] true)}))
{:db (-> db (assoc-in [:admin :adding-client?] true)
(assoc-in [:admin :new-client] {:new-account {:type :check}}))}))
(re-frame/reg-event-fx
::edit
::edit-client-clicked
(fn [{:keys [db]} [_ client-id]]
{:dispatch [::events/modal-status :auto-ap.views.pages.admin.clients/edit {:visible? true}]
:db (assoc-in db [:admin :client]
(get (:clients db) client-id))}))
{:db (-> db
(assoc-in [:admin :new-client] (assoc (get (:clients db) client-id) :new-account {:type :check}))
(assoc-in [:admin :adding-client? ] true))}))
(re-frame/reg-event-fx
::save
@@ -41,9 +42,9 @@
:operation/name "EditClient"}
:venia/queries [{:query/data [:edit-client
{:edit-client
;; TODO - hard code fields we want
(-> edited-client
(update :bank-accounts #(seq (into % (map (fn [ba] (dissoc ba :is-new?)) (:new-bank-accounts edited-client)))))
(dissoc :new-account)
(dissoc :new-bank-accounts)
)}
[:id :name :code :email [:address [:street1 :street2 :city :state :zip]] [:bank-accounts [:id :number :check-number :name :code :bank-code :bank-name :routing]]]]}]}
@@ -75,7 +76,7 @@
(re-frame/reg-event-fx
::save-complete
(fn [{:keys [db]} [_ client]]
(println client)
{:dispatch [::events/modal-completed :auto-ap.views.pages.admin.clients/edit]
:db (-> db
@@ -127,7 +128,7 @@
::add-new-bank-account
(fn [{:keys [db]} _]
(let [client (:client @(re-frame/subscribe [::subs/admin]))
_ (println (s/explain-data ::entity/bank-account (:new-account client)))
_ (prn (s/explain-data ::entity/bank-account (:new-account client)))
new-bank-account (:new-account client)
new-bank-account (-> new-bank-account
(update :code #(str (:code client) "-" %))
@@ -137,7 +138,7 @@
{:db (-> db
(update-in [:admin :client :new-bank-accounts] (fn [bank-accounts]
(conj bank-accounts new-bank-account)))
(update-in [:admin :client] dissoc :new-account))})))
(update-in [:admin :client :new-account] {:type :check}))})))
(re-frame/reg-event-fx
::add-new-new-bank-account
@@ -174,7 +175,7 @@
[:th {:style {:width "20%"}} "Email"]]]
[:tbody (for [{:keys [id name email code locations] :as c} @clients]
^{:key (str name "-" id )}
[:tr {:on-click (fn [] (re-frame/dispatch [::edit id]))
[:tr {:on-click (fn [] (re-frame/dispatch [::edit-client-clicked id]))
:style {"cursor" "pointer"}}
[:td name]
[:td code]
@@ -494,8 +495,9 @@
]
[:div.field
[:div.control
[:button.button.is-primary {:disabled (if (and (s/valid? ::entity/bank-account (:new-account new-client))
(not ((doto (set (map :code (:new-bank-accounts new-client))) println)
(println (s/explain-data ::entity/bank-account (:new-account new-client)))
[:button.button.is-primary {:disabled (if (and (doto (s/valid? ::entity/bank-account (:new-account new-client)) println)
(not ((set (map :code (:new-bank-accounts new-client)))
(str (:code new-client) "-" (-> new-client :new-account :code)))))
""
"disabled")
@@ -514,6 +516,7 @@
^{:key index} [:li [:strong "* " code ": " name] [:button.button {:on-click (dispatch-event [::remove-new-bank-account index])} [:span.icon [:i.fa.fa-times]]]])]]]]
#_(when (:saving? new-client) [:div.is-overlay {:style {"backgroundColor" "rgba(150,150,150, 0.5)"}}])
(println (s/explain-data ::entity/client new-client))
[:submit.button.is-large.is-primary {:disabled (if (s/valid? ::entity/client new-client)
""
"disabled")