forces expense account A or HQ.

This commit is contained in:
Bryce Covert
2018-07-27 08:08:55 -07:00
parent 47d26e9b21
commit 2cb0dd2c70
4 changed files with 26 additions and 19 deletions

View File

@@ -127,6 +127,7 @@
:resolve :get-user-companies}}}
:expense_account {:fields {:id {:type 'Int}
:location {:type 'String}
:name {:type 'String}
:parent {:type :expense_account
:resolve :get-expense-account-parent}}}

View File

@@ -4,6 +4,7 @@
[auto-ap.db.vendors :as vendors]
[auto-ap.db.companies :as companies]
[auto-ap.db.invoices-expense-accounts :as invoices-expense-accounts]
[auto-ap.expense-accounts :as expense-accounts]
[auto-ap.time :refer [parse iso-date]]))
(defn -create-or-get-vendor [vendor-id vendor-name]
@@ -61,10 +62,11 @@
(defn edit-expense-accounts [context args value]
(assert-can-see-company (:id context) (:company-id (invoices/get-by-id (:invoice_id args))))
(invoices-expense-accounts/replace-for-invoice (:invoice_id args) (map (fn [{:keys [id expense_account_id amount location]}]
{
:expense-account-id expense_account_id
:location location
:amount (Double/parseDouble amount)} )
(let [forced-location (get-in expense-accounts/expense-accounts [expense_account_id :location])]
{
:expense-account-id expense_account_id
:location (or forced-location location)
:amount (Double/parseDouble amount)}) )
(:expense_accounts args)))
(->graphql
(invoices/get-by-id (:invoice_id args))))

View File

@@ -45,7 +45,7 @@
[[:invoices [:id :total :outstanding-balance :invoice-number :date
[:vendor [:name :id]]
[:expense_accounts [:amount :id :expense_account_id :location
[:expense_account [:id :name [:parent [:id :name]]]]]]
[:expense_account [:id :name :location [:parent [:id :name]]]]]]
[:company [:name :id :locations]]
[:checks [:amount [:check [:amount :s3_url :check_number ]]]]
]]

View File

@@ -8,6 +8,7 @@
[auto-ap.entities.companies :as company]
[auto-ap.entities.invoice :as invoice]
[auto-ap.entities.vendors :as vendor]
[auto-ap.expense-accounts :as expense-accounts]
[auto-ap.entities.invoices-expense-accounts :as invoices-expense-accounts]
[auto-ap.views.utils :refer [dispatch-event bind-field horizontal-field date->str str->date pretty standard]]
[auto-ap.utils :refer [by replace-if]]
@@ -412,8 +413,9 @@
(re-frame/reg-event-db
::add-expense-account-split
(fn [db _]
(update-in db [::change-expense-accounts :invoice :expense-accounts]
conj {:amount 0 :expense-account-id nil})))
(let [{{{:keys [locations]} :company} :invoice} @(re-frame/subscribe [::change-expense-accounts])]
(update-in db [::change-expense-accounts :invoice :expense-accounts]
conj {:amount 0 :expense-account-id nil :location (first locations)}))))
(re-frame/reg-event-db
::remove-expense-account-split
@@ -425,7 +427,7 @@
(defn change-expense-accounts-modal []
(let [{{:keys [expense-accounts total ] :or {expense-accounts [] total 0} {:keys [locations]} :company} :invoice :as data} @(re-frame/subscribe [::change-expense-accounts])
should-select-location? (> (count locations) 1)
multi-location? (> (count locations) 1)
change-event [::events/change-form [::change-expense-accounts]]
expense-accounts-total (->> expense-accounts
(map :amount)
@@ -446,7 +448,7 @@
[:thead
[:tr
[:th {:style {:width "500px"}} "Expense Account"]
(when should-select-location?
(when multi-location?
[:th {:style {:width "500px"}} "Location"])
[:th {:style {:width "300px"}} "Amount"]
[:th {:style {:width "5em"}}]]]
@@ -462,17 +464,19 @@
:spec ::invoice/vendor-id
:subscription data}]]]]
(when should-select-location?
(when multi-location?
[:td
[:div.select
[bind-field
[:select {:type "select"
:field [:invoice :expense-accounts index :location]
:spec (set locations)
:event change-event
:subscription data}
(map (fn [l] [:option {:value l} l]) locations)]]]
])
(if-let [forced-location (-> expense-account :expense-account-id expense-accounts/expense-accounts :location)]
[:div.select
[:select {:disabled "disabled" :value forced-location} [:option {:value forced-location} forced-location]]]
[:div.select
[bind-field
[:select {:type "select"
:field [:invoice :expense-accounts index :location]
:spec (set locations)
:event change-event
:subscription data}
(map (fn [l] [:option {:value l} l]) locations)]]])])
[:td
[:div.control