locations.

This commit is contained in:
Bryce Covert
2019-04-14 22:08:36 -07:00
parent c44a36c815
commit b05b2244a0
13 changed files with 170 additions and 67 deletions

View File

@@ -53,44 +53,81 @@
(let [ (let [
conn (d/connect uri) conn (d/connect uri)
norms-map {:auto-ap/base-schema {:txes auto-ap.datomic/base-schema} norms-map {:auto-ap/base-schema {:txes auto-ap.datomic/base-schema}
:auto-ap/functions {:txes-fn 'auto-ap.datomic.migrate/functions :requires [:auto-ap/base-schema]} :auto-ap/functions {:txes-fn 'auto-ap.datomic.migrate/functions
:auto-ap/fx-pay-function-2 {:txes-fn 'auto-ap.datomic.migrate/fix-pay-function :requires [:auto-ap/functions]} :requires [:auto-ap/base-schema]}
:auto-ap/migrate-vendors {:txes-fn 'auto-ap.datomic/migrate-vendors :requires [:auto-ap/base-schema]} :auto-ap/fx-pay-function-2 {:txes-fn 'auto-ap.datomic.migrate/fix-pay-function
:auto-ap/migrate-clients {:txes-fn 'auto-ap.datomic/migrate-clients :requires [:auto-ap/migrate-vendors]} :requires [:auto-ap/functions]}
:auto-ap/migrate-users {:txes-fn 'auto-ap.datomic/migrate-users :requires [:auto-ap/migrate-clients]} :auto-ap/migrate-vendors {:txes-fn 'auto-ap.datomic/migrate-vendors
:auto-ap/migrate-invoices {:txes-fn 'auto-ap.datomic/migrate-invoices :requires [:auto-ap/migrate-vendors :auto-ap/migrate-clients]} :requires [:auto-ap/base-schema]}
:auto-ap/migrate-payments {:txes-fn 'auto-ap.datomic/migrate-payments :requires [:auto-ap/migrate-invoices]} :auto-ap/migrate-clients {:txes-fn 'auto-ap.datomic/migrate-clients
:auto-ap/migrate-invoices-payments {:txes-fn 'auto-ap.datomic/migrate-invoices-payments :requires [:auto-ap/migrate-payments :auto-ap/migrate-invoices]} :requires [:auto-ap/migrate-vendors]}
:auto-ap/migrate-invoices-expense-accounts {:txes-fn 'auto-ap.datomic/migrate-invoices-expense-accounts :requires [:auto-ap/migrate-invoices-payments]} :auto-ap/migrate-users {:txes-fn 'auto-ap.datomic/migrate-users
:auto-ap/migrate-transactions {:txes-fn 'auto-ap.datomic/migrate-transactions :requires [:auto-ap/migrate-invoices-expense-accounts]} :requires [:auto-ap/migrate-clients]}
:auto-ap/add-client-codes {:txes-fn 'auto-ap.datomic.migrate.add-client-codes/add-client-codes :requires [:auto-ap/migrate-transactions]} :auto-ap/migrate-invoices {:txes-fn 'auto-ap.datomic/migrate-invoices
:auto-ap/add-bank-account-codes-schema {:txes-fn 'auto-ap.datomic.migrate.add-bank-account-codes/add-bank-account-codes-schema :requires [:auto-ap/add-client-codes]} :requires [:auto-ap/migrate-vendors :auto-ap/migrate-clients]}
:auto-ap/add-bank-account-codes {:txes-fn 'auto-ap.datomic.migrate.add-bank-account-codes/add-bank-account-codes :requires [:auto-ap/add-bank-account-codes-schema]} :auto-ap/migrate-payments {:txes-fn 'auto-ap.datomic/migrate-payments
:auto-ap/add-nick-the-greek {:txes [[{:client/name "Nick the Greek" :client/code "NGAK" :client/locations ["MH"] :client/bank-accounts [{:bank-account/code "NGAK-0" :bank-account/type :bank-account-type/cash :bank-account/name "Cash"}]}]] :requires [:auto-ap/add-bank-account-codes]} :requires [:auto-ap/migrate-invoices]}
:auto-ap/rename-codes-1 {:txes-fn 'auto-ap.datomic.migrate.rename-codes/rename-codes-1 :requires [:auto-ap/add-nick-the-greek]} :auto-ap/migrate-invoices-payments {:txes-fn 'auto-ap.datomic/migrate-invoices-payments
:auto-ap/invoice-converter {:txes auto-ap.datomic.migrate.invoice-converter/add-matches :requires [:auto-ap/rename-codes-1]} :requires [:auto-ap/migrate-payments :auto-ap/migrate-invoices]}
:auto-ap/starter {:txes-fn 'auto-ap.datomic.migrate.invoice-converter/add-starter :requires [:auto-ap/invoice-converter]} :auto-ap/migrate-invoices-expense-accounts {:txes-fn 'auto-ap.datomic/migrate-invoices-expense-accounts
:auto-ap/add-default-location {:txes-fn 'auto-ap.datomic.migrate.invoice-converter/add-default-location :requires [:auto-ap/invoice-converter]} :requires [:auto-ap/migrate-invoices-payments]}
:auto-ap/add-default-location-2 {:txes-fn 'auto-ap.datomic.migrate.invoice-converter/add-default-location-2 :requires [:auto-ap/add-default-location]} :auto-ap/migrate-transactions {:txes-fn 'auto-ap.datomic/migrate-transactions
:auto-ap/add-import-status {:txes auto-ap.datomic.migrate.invoice-converter/add-import-status :requires [:auto-ap/add-default-location-2]} :requires [:auto-ap/migrate-invoices-expense-accounts]}
:auto-ap/add-import-status-existing-invoices {:txes-fn 'auto-ap.datomic.migrate.invoice-converter/add-import-status-existing-invoices :requires [:auto-ap/add-import-status]} :auto-ap/add-client-codes {:txes-fn 'auto-ap.datomic.migrate.add-client-codes/add-client-codes
:auto-ap/fix-check-numbers {:txes-fn 'auto-ap.datomic.migrate.check-numbers/fix-check-numbers :requires [:auto-ap/add-import-status-existing-invoices]} :requires [:auto-ap/migrate-transactions]}
:auto-ap/add-new-vendors {:txes-fn 'auto-ap.datomic.migrate.add-new-vendors/add-new-vendors :requires [:auto-ap/fix-check-numbers]} :auto-ap/add-bank-account-codes-schema {:txes-fn 'auto-ap.datomic.migrate.add-bank-account-codes/add-bank-account-codes-schema
:auto-ap/add-account-visibility-fields {:txes-fn 'auto-ap.datomic.migrate.account-sorting/add-account-visibility-fields :requires [:auto-ap/add-new-vendors]} :requires [:auto-ap/add-client-codes]}
:auto-ap/make-every-account-visible {:txes-fn 'auto-ap.datomic.migrate.account-sorting/make-every-account-visible :requires [:auto-ap/add-account-visibility-fields]} :auto-ap/add-bank-account-codes {:txes-fn 'auto-ap.datomic.migrate.add-bank-account-codes/add-bank-account-codes
:auto-ap/add-general-ledger6 {:txes add-general-ledger/add-general-ledger :requires [:auto-ap/make-every-account-visible]} :requires [:auto-ap/add-bank-account-codes-schema]}
:auto-ap/add-general-ledger-fns2 {:txes-fn 'auto-ap.datomic.migrate.add-general-ledger/add-general-ledger-fns :requires [:auto-ap/add-general-ledger6]} :auto-ap/add-nick-the-greek {:txes [[{:client/name "Nick the Greek" :client/code "NGAK" :client/locations ["MH"] :client/bank-accounts [{:bank-account/code "NGAK-0" :bank-account/type :bank-account-type/cash :bank-account/name "Cash"}]}]]
:auto-ap/add-accounts {:txes auto-ap.datomic.migrate.add-general-ledger/add-accounts :requires [:auto-ap/add-general-ledger-fns2]} :requires [:auto-ap/add-bank-account-codes]}
:auto-ap/add-transaction-account {:txes auto-ap.datomic.migrate.add-general-ledger/add-transaction-account :requires [:auto-ap/add-accounts]} :auto-ap/rename-codes-1 {:txes-fn 'auto-ap.datomic.migrate.rename-codes/rename-codes-1
:auto-ap/change-expense-account-to-entity {:txes auto-ap.datomic.migrate.add-general-ledger/change-expense-account-to-entity :requires [:auto-ap/add-transaction-account]} :requires [:auto-ap/add-nick-the-greek]}
:auto-ap/add-account-to-vendor {:txes auto-ap.datomic.migrate.add-general-ledger/add-account-to-vendor :requires [:auto-ap/change-expense-account-to-entity]} :auto-ap/invoice-converter {:txes auto-ap.datomic.migrate.invoice-converter/add-matches
:auto-ap/convert-vendors {:txes-fn `add-general-ledger/convert-vendors :requires [:auto-ap/add-account-to-vendor]} :requires [:auto-ap/rename-codes-1]}
:auto-ap/convert-invoices {:txes-fn `add-general-ledger/convert-invoices :requires [:auto-ap/add-account-to-vendor]} :auto-ap/starter {:txes-fn 'auto-ap.datomic.migrate.invoice-converter/add-starter
:auto-ap/convert-transactions {:txes-fn `add-general-ledger/convert-transactions :requires [:auto-ap/convert-invoices]} :requires [:auto-ap/invoice-converter]}
#_#_:auto-ap/bulk-load-invoice-ledger2 {:txes-fn 'auto-ap.datomic.migrate.add-general-ledger/bulk-load-invoice-ledger :requires [:auto-ap/make-entity-not-unique]} :auto-ap/add-default-location {:txes-fn 'auto-ap.datomic.migrate.invoice-converter/add-default-location
:requires [:auto-ap/invoice-converter]}
:auto-ap/add-default-location-2 {:txes-fn 'auto-ap.datomic.migrate.invoice-converter/add-default-location-2
:requires [:auto-ap/add-default-location]}
:auto-ap/add-import-status {:txes auto-ap.datomic.migrate.invoice-converter/add-import-status
:requires [:auto-ap/add-default-location-2]}
:auto-ap/add-import-status-existing-invoices {:txes-fn 'auto-ap.datomic.migrate.invoice-converter/add-import-status-existing-invoices
:requires [:auto-ap/add-import-status]}
:auto-ap/fix-check-numbers {:txes-fn 'auto-ap.datomic.migrate.check-numbers/fix-check-numbers
:requires [:auto-ap/add-import-status-existing-invoices]}
:auto-ap/add-new-vendors {:txes-fn 'auto-ap.datomic.migrate.add-new-vendors/add-new-vendors
:requires [:auto-ap/fix-check-numbers]}
:auto-ap/add-account-visibility-fields {:txes-fn 'auto-ap.datomic.migrate.account-sorting/add-account-visibility-fields
:requires [:auto-ap/add-new-vendors]}
:auto-ap/make-every-account-visible {:txes-fn 'auto-ap.datomic.migrate.account-sorting/make-every-account-visible
:requires [:auto-ap/add-account-visibility-fields]}
:auto-ap/add-general-ledger6 {:txes add-general-ledger/add-general-ledger
:requires [:auto-ap/make-every-account-visible]}
:auto-ap/add-general-ledger-fns2 {:txes-fn 'auto-ap.datomic.migrate.add-general-ledger/add-general-ledger-fns
:requires [:auto-ap/add-general-ledger6]}
:auto-ap/add-accounts {:txes auto-ap.datomic.migrate.add-general-ledger/add-accounts
:requires [:auto-ap/add-general-ledger-fns2]}
:auto-ap/add-transaction-account {:txes auto-ap.datomic.migrate.add-general-ledger/add-transaction-account
:requires [:auto-ap/add-accounts]}
:auto-ap/change-expense-account-to-entity {:txes auto-ap.datomic.migrate.add-general-ledger/change-expense-account-to-entity
:requires [:auto-ap/add-transaction-account]}
:auto-ap/add-account-to-vendor {:txes auto-ap.datomic.migrate.add-general-ledger/add-account-to-vendor
:requires [:auto-ap/change-expense-account-to-entity]}
:auto-ap/add-location-to-transaction {:txes add-general-ledger/add-location-to-transaction
:requires [:auto-ap/add-account-to-vendor]}
:auto-ap/convert-vendors {:txes-fn `add-general-ledger/convert-vendors
:requires [:auto-ap/add-location-to-transaction]}
:auto-ap/convert-invoices {:txes-fn `add-general-ledger/convert-invoices
:requires [:auto-ap/convert-vendors]}
:auto-ap/convert-transactions {:txes-fn `add-general-ledger/convert-transactions
:requires [:auto-ap/convert-invoices]}
#_#_:auto-ap/bulk-load-invoice-ledger2 {:txes-fn 'auto-ap.datomic.migrate.add-general-ledger/bulk-load-invoice-ledger :requires [:auto-ap/convert-transactions]}
}] }]
(println "Conforming database...") (println "Conforming database...")
(println (c/ensure-conforms conn norms-map)) (println (c/ensure-conforms conn norms-map))
(d/release conn) (d/release conn)

View File

@@ -225,10 +225,17 @@
(fn [[transaction-id vendor-id]] (fn [[transaction-id vendor-id]]
(remove-nils {:db/id transaction-id (remove-nils {:db/id transaction-id
:transaction/vendor vendor-id :transaction/vendor vendor-id
:transaction/location "A"
:transaction/account (:db/id (accounts/get-account-by-numeric-code-and-sets 2110 ["default"])) :transaction/account (:db/id (accounts/get-account-by-numeric-code-and-sets 2110 ["default"]))
})) }))
matched-transactions)])) matched-transactions)]))
(def add-location-to-transaction
[[{:db/ident :transaction/location
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one
:db/doc "Location of the transaction's target"}]])
#_(do (doseq [tran (convert-transactions (d/connect auto-ap.datomic/uri))] #_(do (doseq [tran (convert-transactions (d/connect auto-ap.datomic/uri))]
@(d/transact (d/connect auto-ap.datomic/uri) tran)) @(d/transact (d/connect auto-ap.datomic/uri) tran))

View File

@@ -92,7 +92,7 @@
(defn get-by-id [id] (defn get-by-id [id]
(-> (->
(d/pull (d/db (d/connect uri)) (d/pull (d/db (d/connect uri))
'[* {:transaction/client [:client/name :db/id :client/code] '[* {:transaction/client [:client/name :db/id :client/code :client/locations]
:transaction/bank-account [:bank-account/name :bank-account/code :bank-account/yodlee-account-id :db/id] :transaction/bank-account [:bank-account/name :bank-account/code :bank-account/yodlee-account-id :db/id]
:transaction/vendor [:db/id :vendor/name] :transaction/vendor [:db/id :vendor/name]
:transaction/account [:db/id :account/name :account/numeric-code]}] :transaction/account [:db/id :account/name :account/numeric-code]}]

View File

@@ -155,6 +155,7 @@
:amount {:type 'String} :amount {:type 'String}
:description_original {:type 'String} :description_original {:type 'String}
:description_simple {:type 'String} :description_simple {:type 'String}
:location {:type 'String}
:status {:type 'String} :status {:type 'String}
:merchant_name {:type 'String} :merchant_name {:type 'String}
:client {:type :client} :client {:type :client}
@@ -417,6 +418,7 @@
:edit_transaction :edit_transaction
{:fields {:id {:type :id} {:fields {:id {:type :id}
:vendor_id {:type :id} :vendor_id {:type :id}
:location {:type 'String}
:account_id {:type :id}}} :account_id {:type :id}}}
:edit_account :edit_account

View File

@@ -8,7 +8,8 @@
[com.walmartlabs.lacinia.executor :as executor] [com.walmartlabs.lacinia.executor :as executor]
[com.walmartlabs.lacinia.resolve :as resolve] [com.walmartlabs.lacinia.resolve :as resolve]
[auto-ap.utils :refer [by]] [auto-ap.utils :refer [by]]
[auto-ap.time :refer [parse normal-date]])) [auto-ap.time :refer [parse normal-date]]
[auto-ap.datomic.clients :as d-clients]))
(defn get-transaction-page [context args value] (defn get-transaction-page [context args value]
(let [args (assoc args :id (:id context)) (let [args (assoc args :id (:id context))
@@ -24,13 +25,23 @@
(defn edit-transaction [context {{:keys [id account_id vendor_id] :as transaction} :transaction} value] (defn edit-transaction [context {{:keys [id location account_id vendor_id] :as transaction} :transaction} value]
(assert-can-see-client (:id context) (:db/id (d-transactions/get-by-id id))) (let [transaction (d-transactions/get-by-id id)]
(println transaction) (assert-can-see-client (:id context) (:transaction/client transaction) )
@(d/transact (d/connect uri) (when-not (-> (:transaction/client transaction)
[{:db/id id :client/locations
:transaction/vendor vendor_id set
:transaction/account account_id}]) (conj "A")
(->graphql (d-transactions/get-by-id id)) (conj "HQ")
(get location))
(throw (ex-info (str "Location '" location "' not found on client.") {}))
)
@(d/transact (d/connect uri)
[{:db/id id
:transaction/vendor vendor_id
:transaction/location location
:transaction/account account_id}])
(->graphql (d-transactions/get-by-id id)))
#_(->graphql {:id id #_(->graphql {:id id
:vendor (d-vendors/get-by-id vendor_id) })) :vendor (d-vendors/get-by-id vendor_id) }))

View File

@@ -43,6 +43,7 @@
:journal-entry/amount (:invoice/total entity) :journal-entry/amount (:invoice/total entity)
:journal-entry/line-items (into [{:journal-entry-line/account (a/get-account-by-numeric-code-and-sets 2110 ["default"]) :journal-entry/line-items (into [{:journal-entry-line/account (a/get-account-by-numeric-code-and-sets 2110 ["default"])
:journal-entry-line/location "A"
:journal-entry-line/credit (:invoice/total entity)}] :journal-entry-line/credit (:invoice/total entity)}]
(map (fn [ea] (map (fn [ea]
(remove-nils {:journal-entry-line/account (:db/id (:invoice-expense-account/account ea)) (remove-nils {:journal-entry-line/account (:db/id (:invoice-expense-account/account ea))
@@ -67,14 +68,14 @@
:journal-entry/amount (Math/abs (:transaction/amount entity)) :journal-entry/amount (Math/abs (:transaction/amount entity))
:journal-entry/line-items [(remove-nils{:journal-entry-line/account (:db/id (:transaction/account entity)) :journal-entry/line-items [(remove-nils{:journal-entry-line/account (:db/id (:transaction/account entity))
:journal-entry-line/location "HQ" :journal-entry-line/location (:transaction/location entity)
:journal-entry-line/debit (when (< (:transaction/amount entity) 0.0) :journal-entry-line/debit (when (< (:transaction/amount entity) 0.0)
(Math/abs (:transaction/amount entity))) (Math/abs (:transaction/amount entity)))
:journal-entry-line/credit (when (>= (:transaction/amount entity) 0.0) :journal-entry-line/credit (when (>= (:transaction/amount entity) 0.0)
(Math/abs (:transaction/amount entity)))}) (Math/abs (:transaction/amount entity)))})
(remove-nils {:journal-entry-line/account (:db/id (:transaction/bank-account entity)) (remove-nils {:journal-entry-line/account (:db/id (:transaction/bank-account entity))
:journal-entry-line/location "HQ" :journal-entry-line/location "A"
:journal-entry-line/credit (when (< (:transaction/amount entity) 0.0) :journal-entry-line/credit (when (< (:transaction/amount entity) 0.0)
(Math/abs (:transaction/amount entity))) (Math/abs (:transaction/amount entity)))
:journal-entry-line/debit (when (>= (:transaction/amount entity) 0.0) :journal-entry-line/debit (when (>= (:transaction/amount entity) 0.0)

View File

@@ -88,9 +88,10 @@
:vendor (when check :vendor (when check
(:db/id (:payment/vendor check))) (:db/id (:payment/vendor check)))
:location (when check
"A")
:account (when check :account (when check
(:db/id (a/get-account-by-numeric-code-and-sets 2110 ["default"])) (:db/id (a/get-account-by-numeric-code-and-sets 2110 ["default"])))
#_(:db/id (:payment/vendor check)))
})] })]

View File

@@ -50,12 +50,18 @@
[] []
clients)))) clients))))
;; Bank accounts only, not including cash
(re-frame/reg-sub (re-frame/reg-sub
::real-bank-accounts ::real-bank-accounts
:<- [::client] :<- [::client]
(fn [client] (fn [client]
(->> client :bank-accounts (filter #(= (:type %) :check)) (sort-by :sort-order)))) (->> 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 (re-frame/reg-sub
::clients-by-id ::clients-by-id

View File

@@ -14,7 +14,7 @@
true)) true))
(re-frame/reg-sub (re-frame/reg-sub
::account-request ::request
:<- [::forms/form ::form] :<- [::forms/form ::form]
(fn [{{:keys [id location type numeric-code name account-set]} :data}] (fn [{{:keys [id location type numeric-code name account-set]} :data}]
{:id id {:id id
@@ -49,7 +49,7 @@
:query-obj {:venia/operation {:operation/type :mutation :query-obj {:venia/operation {:operation/type :mutation
:operation/name "UpsertAccount"} :operation/name "UpsertAccount"}
:venia/queries [{:query/data [:upsert-account :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]]}]} [:id :type :name :account-set :numeric-code :location]]}]}
:on-success [::edited edit-completed] :on-success [::edited edit-completed]
:on-error [::forms/save-error ::form]}})))) :on-error [::forms/save-error ::form]}}))))
@@ -130,7 +130,7 @@
[:div.notification.is-warning.animated.fadeInUp [:div.notification.is-warning.animated.fadeInUp
error]) 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") "disabled")
:on-click (dispatch-event [::saving edit-completed]) :on-click (dispatch-event [::saving edit-completed])

View File

@@ -99,14 +99,14 @@
[:td.has-text-right (nf amount )] [:td.has-text-right (nf amount )]
[:td status]]] [:td status]]]
(for [{:keys [debit credit account]} line-items] (for [{:keys [debit credit location account]} line-items]
[:tr {:class (:class i)} [:tr {:class (:class i)}
(when-not selected-client (when-not selected-client
[:td ]) [:td ])
[:td ] [:td ]
#_[:td description-original] #_[:td description-original]
[:td ] [:td ]
[:td (:name account)] [:td location ": " (:name account)]
[:td.has-text-right (when debit (nf debit ))] [:td.has-text-right (when debit (nf debit ))]
[:td.has-text-right (when credit (nf credit ))] [:td.has-text-right (when credit (nf credit ))]

View File

@@ -3,6 +3,7 @@
(def transaction-read (def transaction-read
[:id [:id
:amount :amount
:location
[:vendor [:name :id]] [:vendor [:name :id]]
[:account [:id :name]] [:account [:id :name]]
:date :date

View File

@@ -11,10 +11,20 @@
(fn [db [_ which]] (fn [db [_ which]]
(-> db (-> db
(forms/start-form ::edit-transaction {:id (:id which) (forms/start-form ::edit-transaction {:id (:id which)
:location (:location which)
:client-id (:id (:client which))
:account-id (:id (:account which)) :account-id (:id (:account which))
:account-name (:name (:account which)) :account-name (:name (:account which))
:vendor-id (:id (:vendor which)) :vendor-id (:id (:vendor which))
:vendor-name (:name (: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 (re-frame/reg-sub
::can-submit ::can-submit
@@ -34,26 +44,33 @@
::saving ::saving
(fn [{:keys [db]} [_ edit-completed]] (fn [{:keys [db]} [_ edit-completed]]
(when @(re-frame/subscribe [::can-submit]) (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 ) {:db (forms/loading db ::edit-transaction )
:graphql :graphql
{:token (-> db :user) {:token (-> db :user)
:query-obj {:venia/operation {:operation/type :mutation :query-obj {:venia/operation {:operation/type :mutation
:operation/name "EditTransaction"} :operation/name "EditTransaction"}
:venia/queries [{:query/data [:edit-transaction :venia/queries [{:query/data [:edit-transaction
{:transaction {:id id @(re-frame/subscribe [::request])
:vendor-id vendor-id
:account-id account-id}}
transaction-read]}]} transaction-read]}]}
:on-success [::edited edit-completed] :on-success [::edited edit-completed]
:on-error [::forms/save-error ::edit-transaction]}})))) :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]}] (defn form [{:keys [edit-completed]}]
[forms/side-bar-form {:form ::edit-transaction } [forms/side-bar-form {:form ::edit-transaction }
(let [{:keys [data active? error id]} @(re-frame/subscribe [::forms/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 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]] change-event [::forms/change ::edit-transaction]]
^{:key id} ^{:key id}
[:form { :on-submit (fn [e] [:form { :on-submit (fn [e]
@@ -98,7 +115,7 @@
:field [:always-map] :field [:always-map]
:subscription data}] :subscription data}]
" Always match Merchant '" (:merchant-name data) "' to '" (:vendor-name data) "'" ]]]) " Always match Merchant '" (:merchant-name data) "' to '" (:vendor-name data) "'" ]]])
[:div.field [:div.field
[:p.help "Credit Account"] [:p.help "Credit Account"]
[:div.control [:div.control
@@ -107,9 +124,26 @@
:type "typeahead" :type "typeahead"
:field [:account-id] :field [:account-id]
:text-field [:account-name] :text-field [:account-name]
:event change-event :event [::change-account]
:subscription data}]]]] :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 (when error
^{:key error} [:div.notification.is-warning.animated.fadeInUp ^{:key error} [:div.notification.is-warning.animated.fadeInUp
error]) error])

View File

@@ -81,7 +81,7 @@
(defn with-keys [children] (defn with-keys [children]
(map-indexed (fn [i c] ^{:key i} c) 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) (let [field (if (keyword? field) [field] field)
event (if (keyword? event) [event] event) event (if (keyword? event) [event] event)
keys (assoc keys keys (assoc keys
@@ -91,8 +91,11 @@
:class (str class :class (str class
(when (and spec (not (s/valid? spec (get-in subscription field)))) (when (and spec (not (s/valid? spec (get-in subscription field))))
" is-danger"))) " is-danger")))
keys (dissoc keys :field :subscription :event :spec)] keys (dissoc keys :field :subscription :event :spec)
(into [dom keys] (with-keys rest)))) 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] (defmethod do-bind "radio" [dom {:keys [field subscription event class value spec] :as keys} & rest]