you can kind of set up more than one account in an invoice.
This commit is contained in:
@@ -50,7 +50,7 @@
|
||||
(re-frame/reg-event-db
|
||||
::change
|
||||
(fn [db [_ form & path-pairs]]
|
||||
(println path-pairs)
|
||||
(println "CHANGED" path-pairs)
|
||||
(reduce
|
||||
(fn [db [path value]]
|
||||
(assoc-in db (into [::forms form :data] path) value))
|
||||
|
||||
@@ -40,7 +40,13 @@
|
||||
:client-id client-id
|
||||
:invoice-number invoice-number
|
||||
:location location
|
||||
:total total}}
|
||||
:total total
|
||||
:expense-accounts (map (fn [ea]
|
||||
{:id (:id ea)
|
||||
:account_id (:id (:account ea))
|
||||
:location (:location ea)
|
||||
:amount (:amount ea)})
|
||||
expense-accounts)}}
|
||||
invoice-read]}]}))
|
||||
|
||||
(defmethod submit-query :edit [db]
|
||||
@@ -54,6 +60,8 @@
|
||||
:total total
|
||||
:expense-accounts (map (fn [ea]
|
||||
{:id (:id ea)
|
||||
:account_id (:id (:account ea))
|
||||
:location (:location ea)
|
||||
:amount (:amount ea)})
|
||||
expense-accounts)}}
|
||||
invoice-read]}]}))
|
||||
@@ -68,7 +76,13 @@
|
||||
:client-id client-id
|
||||
:invoice-number invoice-number
|
||||
:location location
|
||||
:total total}
|
||||
:total total
|
||||
:expense-accounts (map (fn [ea]
|
||||
{:id (:id ea)
|
||||
:account_id (:id (:account ea))
|
||||
:location (:location ea)
|
||||
:amount (:amount ea)})
|
||||
expense-accounts)}
|
||||
:bank-account-id bank-account-id
|
||||
:type type}
|
||||
[:pdf-url [:invoices invoice-read]]]}]}))
|
||||
@@ -81,7 +95,7 @@
|
||||
(re-frame/reg-event-db
|
||||
::adding
|
||||
(fn [db [_ new]]
|
||||
(-> db (forms/start-form ::form new))))
|
||||
(-> db (forms/start-form ::form (assoc new :expense-accounts [{}])))))
|
||||
|
||||
(re-frame/reg-event-db
|
||||
::editing
|
||||
@@ -112,6 +126,12 @@
|
||||
[:client-id] value
|
||||
[:location] first-location]})))
|
||||
|
||||
(re-frame/reg-event-db
|
||||
::add-expense-account
|
||||
[(forms/in-form ::form) (re-frame/path [:data])]
|
||||
(fn [form]
|
||||
(update form :expense-accounts conj {:amount 0})))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::submitted
|
||||
(fn [{:keys [db]} [_ params command bank-account-id type]]
|
||||
@@ -257,32 +277,57 @@
|
||||
:spec ::invoice/total
|
||||
:step "0.01"}]]]]]]
|
||||
|
||||
(when exists?
|
||||
[:div
|
||||
[:h2.subtitle "Expense Accounts"]
|
||||
[:div
|
||||
[:div.columns
|
||||
[:div.column
|
||||
[:h1.subtitle.is-4.is-inline "Expense Accounts"]]
|
||||
[:div.column.is-narrow
|
||||
[:p.buttons
|
||||
[:a.button {:on-click (dispatch-event [::add-expense-account])} "Add"]]]]
|
||||
|
||||
(for [[index {:keys [id location] :as expense-account {account-id :id account-numeric-code :numeric-code account-name :name} :account}] (map vector (range) (:expense-accounts data))]
|
||||
^{:key id}
|
||||
[:div.columns
|
||||
[:div.column account-numeric-code " - " account-name]
|
||||
|
||||
|
||||
(when multi-location?
|
||||
[:div.column location])
|
||||
(for [[index {:keys [id location] :as expense-account {account-id :id account-numeric-code :numeric-code account-name :name} :account}] (map vector (range) (:expense-accounts data))]
|
||||
^{:key id}
|
||||
[:div.columns
|
||||
[:div.column
|
||||
[bind-field
|
||||
[typeahead {:matches (map (fn [x] [(:id x) (str (:numeric-code x) " - " (:name x))]) @(re-frame/subscribe [::subs/chooseable-expense-accounts]))
|
||||
:type "typeahead"
|
||||
:field [:expense-accounts index :account :id]
|
||||
:event [::forms/change ::form ]
|
||||
:subscription data}]]]
|
||||
|
||||
[:div.column
|
||||
[:div.control
|
||||
[:div.field.has-addons.is-extended
|
||||
[:p.control [:a.button.is-static "$"]]
|
||||
[:p.control
|
||||
(when multi-location?
|
||||
|
||||
[:div.column.is-narrow
|
||||
(if-let [forced-location (:location @(re-frame/subscribe [::subs/account (get-in data [:expense-accounts index :account :id])]))]
|
||||
[:div.select
|
||||
[:select {:disabled "disabled" :value forced-location} [:option {:value forced-location} forced-location]]]
|
||||
[:div.select
|
||||
[bind-field
|
||||
[:input.input {:type "number"
|
||||
:field [:expense-accounts index :amount]
|
||||
:style {:text-align "right"}
|
||||
:event [::forms/change ::form]
|
||||
:subscription data
|
||||
:value (get-in expense-account [:amount])
|
||||
:max (:total data)
|
||||
:step "0.01"}]]]]]]])])
|
||||
[:select {:type "select"
|
||||
:field [:expense-accounts index :location]
|
||||
:allow-nil? true
|
||||
:spec (set locations)
|
||||
:event [::forms/change ::form]
|
||||
:subscription data}
|
||||
(map (fn [l] ^{:key l} [:option {:value l} l]) locations)]]])])
|
||||
|
||||
[:div.column.is-narrow
|
||||
[:div.control
|
||||
[:div.field.has-addons.is-extended
|
||||
[:p.control [:a.button.is-static "$"]]
|
||||
[:p.control
|
||||
[bind-field
|
||||
[:input.input {:type "number"
|
||||
:field [:expense-accounts index :amount]
|
||||
:style {:text-align "right" :width "7em"}
|
||||
:event [::forms/change ::form]
|
||||
:subscription data
|
||||
:value (get-in expense-account [:amount])
|
||||
:max (:total data)
|
||||
:step "0.01"}]]]]]]])]
|
||||
|
||||
(when error
|
||||
^{:key error} [:div.notification.is-warning.animated.fadeInUp
|
||||
|
||||
Reference in New Issue
Block a user