simple change to get accounts auto-populating.
This commit is contained in:
@@ -100,12 +100,24 @@
|
|||||||
(fn [db]
|
(fn [db]
|
||||||
(vals (:vendors db))))
|
(vals (:vendors db))))
|
||||||
|
|
||||||
|
(re-frame/reg-sub
|
||||||
|
::vendors-by-id
|
||||||
|
(fn [db]
|
||||||
|
(:vendors db)))
|
||||||
|
|
||||||
|
(re-frame/reg-sub
|
||||||
|
::vendor-default-account
|
||||||
|
(fn [db [_ z]]
|
||||||
|
(let [i (-> (:vendors db) (get z) :default-account :id)]
|
||||||
|
(first (filter
|
||||||
|
#(= (:id %) i)
|
||||||
|
(:accounts db))))))
|
||||||
|
|
||||||
(re-frame/reg-sub
|
(re-frame/reg-sub
|
||||||
::sorted-vendors
|
::sorted-vendors
|
||||||
:<- [::vendors]
|
:<- [::vendors]
|
||||||
(fn [vendors]
|
(fn [vendors]
|
||||||
(sort-by :name vendors)))
|
(sort-by :name vendors)))
|
||||||
|
|
||||||
(re-frame/reg-sub
|
(re-frame/reg-sub
|
||||||
::admin
|
::admin
|
||||||
(fn [db]
|
(fn [db]
|
||||||
|
|||||||
@@ -68,6 +68,7 @@
|
|||||||
[typeahead {:matches (map (fn [x] [(:id x) (str (:numeric-code x) " - " (:name x))]) chooseable-expense-accounts)
|
[typeahead {:matches (map (fn [x] [(:id x) (str (:numeric-code x) " - " (:name x))]) chooseable-expense-accounts)
|
||||||
:type "typeahead"
|
:type "typeahead"
|
||||||
:field [index :account :id]
|
:field [index :account :id]
|
||||||
|
:text-field [index :account :name]
|
||||||
:event [::expense-account-changed event expense-accounts]
|
:event [::expense-account-changed event expense-accounts]
|
||||||
:subscription expense-accounts}]]]]
|
:subscription expense-accounts}]]]]
|
||||||
[:div.column.is-narrow
|
[:div.column.is-narrow
|
||||||
|
|||||||
@@ -135,6 +135,26 @@
|
|||||||
[:client-id] value
|
[:client-id] value
|
||||||
[:location] first-location]})))
|
[:location] first-location]})))
|
||||||
|
|
||||||
|
(re-frame/reg-event-fx
|
||||||
|
::change-vendor
|
||||||
|
[(forms/in-form ::form)]
|
||||||
|
(fn [{{:keys [data]} :db} [_ location field value]]
|
||||||
|
(println "data" data)
|
||||||
|
(let [has-only-one-expense-account? (and value
|
||||||
|
(or (not (seq (:expense-accounts data)))
|
||||||
|
(<= 1 (count (:expense-accounts data))))
|
||||||
|
(not (get-in data [:expense-accounts 0 :account :id])))]
|
||||||
|
(println "has only one?" has-only-one-expense-account?)
|
||||||
|
|
||||||
|
(if has-only-one-expense-account?
|
||||||
|
{:dispatch [::forms/change ::form
|
||||||
|
field value
|
||||||
|
[:expense-accounts] [{:id (str "new-" (random-uuid))
|
||||||
|
:amount (:total data)
|
||||||
|
:account @(re-frame/subscribe [::subs/vendor-default-account value])}]]}
|
||||||
|
{:dispatch [::forms/change ::form
|
||||||
|
field value]}))))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
(re-frame/reg-event-fx
|
(re-frame/reg-event-fx
|
||||||
@@ -214,19 +234,7 @@
|
|||||||
:event [::change-new-invoice-client [::form]]
|
:event [::change-new-invoice-client [::form]]
|
||||||
:spec ::invoice/client-id
|
:spec ::invoice/client-id
|
||||||
:subscription data}]]]])
|
:subscription data}]]]])
|
||||||
|
|
||||||
(when (and should-select-location? (not exists?))
|
|
||||||
[:div.field
|
|
||||||
[:p.help "Location"]
|
|
||||||
[:div.control
|
|
||||||
[:div.select
|
|
||||||
[bind-field
|
|
||||||
[:select {:type "select"
|
|
||||||
:field [:location]
|
|
||||||
:spec (set locations)
|
|
||||||
:event change-event
|
|
||||||
:subscription data}
|
|
||||||
(map (fn [l] [:option {:value l} l]) locations)]]]]])
|
|
||||||
[:div.field
|
[:div.field
|
||||||
[:p.help "Vendor"]
|
[:p.help "Vendor"]
|
||||||
[:div.control
|
[:div.control
|
||||||
@@ -237,7 +245,8 @@
|
|||||||
:auto-focus (if @(re-frame/subscribe [::subs/client]) true false)
|
:auto-focus (if @(re-frame/subscribe [::subs/client]) true false)
|
||||||
:field [:vendor-id]
|
:field [:vendor-id]
|
||||||
:text-field [:vendor-name]
|
:text-field [:vendor-name]
|
||||||
:event change-event
|
:text-event change-event
|
||||||
|
:event [::change-vendor [::form]]
|
||||||
:spec (s/nilable ::invoice/vendor-id)
|
:spec (s/nilable ::invoice/vendor-id)
|
||||||
:subscription data}]]]]
|
:subscription data}]]]]
|
||||||
|
|
||||||
|
|||||||
@@ -87,7 +87,7 @@
|
|||||||
keys (assoc keys
|
keys (assoc keys
|
||||||
:on-change (dispatch-value-change (conj event field))
|
:on-change (dispatch-value-change (conj event field))
|
||||||
|
|
||||||
:value (get-in subscription field)
|
:value (or (get-in subscription field) "")
|
||||||
: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")))
|
||||||
@@ -95,7 +95,7 @@
|
|||||||
options (if allow-nil?
|
options (if allow-nil?
|
||||||
(with-keys (conj rest [:option {:value nil}]))
|
(with-keys (conj rest [:option {:value nil}]))
|
||||||
(with-keys rest))]
|
(with-keys rest))]
|
||||||
(into [dom keys] options)))
|
(into [dom (dissoc keys :allow-nil?)] 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]
|
||||||
|
|||||||
Reference in New Issue
Block a user