Makes it so vendors and invoices respect allowances.

This commit is contained in:
2023-02-03 20:59:52 -08:00
parent 1ecd076ba1
commit afa6b79fcc
7 changed files with 82 additions and 33 deletions

View File

@@ -111,16 +111,20 @@
[:th {:style {:width "300px"}} "Amount"]
[:th {:style {:width "5em"}}]]]
[:tbody
(doall (for [[id _] expense-accounts]
(doall (for [[id a] expense-accounts]
^{:key id}
[:tr
[:tr {:class (when (:warning (:account a))
"has-background-warning-light")}
[:td.expandable [:div.control
(println a)
[form-builder/raw-field-v2 {:field [:expense-accounts id :account]}
[search-backed-typeahead {:search-query (fn [i]
[:search_account
{:query i
:client-id (:id client)}
[:name :id :location]])}]]]]
:client-id (:id client)
:allowance :invoice}
[:name :id :location :warning]])
:class "is-warn"}]]]]
(when multi-location?
[:td

View File

@@ -74,7 +74,7 @@
(defn expense-accounts-field-v2 [{value :value on-change :on-change expense-accounts :value client :client max-value :max locations :locations disabled :disabled percentage-only? :percentage-only? :or {percentage-only? false}}]
(defn expense-accounts-field-v2 [{value :value on-change :on-change allowance :allowance expense-accounts :value client :client max-value :max locations :locations disabled :disabled percentage-only? :percentage-only? :or {percentage-only? false}}]
[form-builder/virtual-builder {:value value
:schema schema
:on-change (fn [expense-accounts original-expense-accounts]
@@ -129,8 +129,9 @@
[search-backed-typeahead {:search-query (fn [i]
[:search_account
{:query i
:allowance allowance
:client-id (:id client)}
[:name :id :location]])
[:name :id :location :warning]])
:disabled disabled}]]]]
[:div.column.is-narrow
[form-builder/field-v2 {:required? true
@@ -142,6 +143,9 @@
locations))
:disabled (boolean (:location account))
:allow-nil? true}]]]]]
(when-let [warning (:warning account)]
[:div.notification.is-warning.is-small.is-light {:style {:padding "0.5rem 1.25rem"}}
warning])
(if percentage-only?
[form-builder/raw-field-v2 {:field [index :amount-percentage]}
[percentage-field {}]]

View File

@@ -162,7 +162,8 @@
(defn form-content []
(let [is-admin? @(re-frame/subscribe [::subs/is-admin?])
clients @(re-frame/subscribe [::subs/client-refs])]
clients @(re-frame/subscribe [::subs/client-refs])
{vendor :data} @(re-frame/subscribe [::forms/form ::vendor-form])]
[form-builder/builder {:submit-event [::save]
:id ::vendor-form
:schema schema}
@@ -231,10 +232,14 @@
"Default"
[search-backed-typeahead {:search-query (fn [i]
[:search_account
{:query i}
[:name :id]])
:style {:width "19em"}}]]
{:query i
:allowance :vendor}
[:name :id :warning]])
:style {:width "19em"}}]
]
(when (:warning (:default-account vendor))
[:div.notification.is-warning.is-light
(:warning (:default-account vendor))])
(when is-admin?
[form-builder/field-v2 {:field [:account-overrides]}
"Overrides"
@@ -248,8 +253,9 @@
[search-backed-typeahead {:search-query (fn [i]
[:search_account
{:query i
:client_id (:id (:client entity))}
[:name :id]])
:client_id (:id (:client entity))
:allowance :vendor}
[:name :id :warning]])
:style {:width "15em"}}]]])
:schema [:sequential account-override-schema]
:key-fn :id

View File

@@ -415,6 +415,7 @@
[form-builder/field-v2 {:field :expense-accounts}
"Expense Accounts"
[expense-accounts-field-v2 {:descriptor "expense account"
:allowance :invoice
:locations (:locations (:client data))
:max (:total data)
:client (or (:client data) active-client)}]]