adding ability to choose location
This commit is contained in:
@@ -75,10 +75,9 @@
|
||||
(re-frame/reg-event-db
|
||||
::change-form
|
||||
(fn [db [_ location field value]]
|
||||
(println location field value)
|
||||
(if value
|
||||
(assoc-in db (into location field) value)
|
||||
(update-in db location dissoc field))))
|
||||
(update-in db (into location (butlast field)) dissoc (last field)))))
|
||||
|
||||
(re-frame/reg-event-db
|
||||
::modal-status
|
||||
|
||||
@@ -239,6 +239,7 @@
|
||||
[:company [:id :name :locations]]
|
||||
[:vendor [:id :name]]
|
||||
[:expense_accounts [:amount :id :expense_account_id
|
||||
:location
|
||||
[:expense_account [:id :name [:parent [:id :name]]]]]]
|
||||
]]}]}
|
||||
:on-success [::invoice-created]}})))
|
||||
@@ -519,15 +520,28 @@
|
||||
#_#_:spec ::check/date
|
||||
:subscription handwrite-checks}]]]]))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::change-new-invoice-company
|
||||
(fn [{:keys [db ]} [_ location field value]]
|
||||
(let [first-location (-> @(re-frame/subscribe [::subs/companies-by-id])
|
||||
(get-in [value :locations])
|
||||
first)]
|
||||
{:dispatch [::events/change-form location field value]
|
||||
:db (-> db
|
||||
(assoc-in [::new-invoice :location] first-location))})))
|
||||
|
||||
(defn new-invoice-modal []
|
||||
(let [data @(re-frame/subscribe [::new-invoice])
|
||||
change-event [::events/change-form [::new-invoice]]]
|
||||
change-event [::events/change-form [::new-invoice]]
|
||||
locations (get-in @(re-frame/subscribe [::subs/companies-by-id]) [(:company-id data) :locations])
|
||||
should-select-location? (and locations
|
||||
(> (count locations) 1))]
|
||||
[action-modal {:id ::new-invoice
|
||||
:title "New Invoice"
|
||||
:action-text "Create"
|
||||
:save-event [::create-invoice]
|
||||
:can-submit? (s/valid? ::invoice/invoice data)}
|
||||
|
||||
(when-not @(re-frame/subscribe [::subs/company])
|
||||
[horizontal-field
|
||||
[:label.label "Company"]
|
||||
@@ -535,9 +549,20 @@
|
||||
[typeahead {:matches (map (fn [x] [(:id x) (:name x)]) @(re-frame/subscribe [::subs/companies]))
|
||||
:type "typeahead"
|
||||
:field [:company-id]
|
||||
:event change-event
|
||||
:event [::change-new-invoice-company [::new-invoice]]
|
||||
:spec ::invoice/company-id
|
||||
:subscription data}]]])
|
||||
(when should-select-location?
|
||||
[horizontal-field
|
||||
[:label.label "Location"]
|
||||
[: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)]]]])
|
||||
|
||||
[horizontal-field
|
||||
[:label.label "Vendor"]
|
||||
|
||||
Reference in New Issue
Block a user