forces expense account A or HQ.
This commit is contained in:
@@ -127,6 +127,7 @@
|
|||||||
:resolve :get-user-companies}}}
|
:resolve :get-user-companies}}}
|
||||||
|
|
||||||
:expense_account {:fields {:id {:type 'Int}
|
:expense_account {:fields {:id {:type 'Int}
|
||||||
|
:location {:type 'String}
|
||||||
:name {:type 'String}
|
:name {:type 'String}
|
||||||
:parent {:type :expense_account
|
:parent {:type :expense_account
|
||||||
:resolve :get-expense-account-parent}}}
|
:resolve :get-expense-account-parent}}}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
[auto-ap.db.vendors :as vendors]
|
[auto-ap.db.vendors :as vendors]
|
||||||
[auto-ap.db.companies :as companies]
|
[auto-ap.db.companies :as companies]
|
||||||
[auto-ap.db.invoices-expense-accounts :as invoices-expense-accounts]
|
[auto-ap.db.invoices-expense-accounts :as invoices-expense-accounts]
|
||||||
|
[auto-ap.expense-accounts :as expense-accounts]
|
||||||
[auto-ap.time :refer [parse iso-date]]))
|
[auto-ap.time :refer [parse iso-date]]))
|
||||||
|
|
||||||
(defn -create-or-get-vendor [vendor-id vendor-name]
|
(defn -create-or-get-vendor [vendor-id vendor-name]
|
||||||
@@ -61,10 +62,11 @@
|
|||||||
(defn edit-expense-accounts [context args value]
|
(defn edit-expense-accounts [context args value]
|
||||||
(assert-can-see-company (:id context) (:company-id (invoices/get-by-id (:invoice_id args))))
|
(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]}]
|
(invoices-expense-accounts/replace-for-invoice (:invoice_id args) (map (fn [{:keys [id expense_account_id amount location]}]
|
||||||
{
|
(let [forced-location (get-in expense-accounts/expense-accounts [expense_account_id :location])]
|
||||||
:expense-account-id expense_account_id
|
{
|
||||||
:location location
|
:expense-account-id expense_account_id
|
||||||
:amount (Double/parseDouble amount)} )
|
:location (or forced-location location)
|
||||||
|
:amount (Double/parseDouble amount)}) )
|
||||||
(:expense_accounts args)))
|
(:expense_accounts args)))
|
||||||
(->graphql
|
(->graphql
|
||||||
(invoices/get-by-id (:invoice_id args))))
|
(invoices/get-by-id (:invoice_id args))))
|
||||||
|
|||||||
@@ -45,7 +45,7 @@
|
|||||||
[[:invoices [:id :total :outstanding-balance :invoice-number :date
|
[[:invoices [:id :total :outstanding-balance :invoice-number :date
|
||||||
[:vendor [:name :id]]
|
[:vendor [:name :id]]
|
||||||
[:expense_accounts [:amount :id :expense_account_id :location
|
[: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]]
|
[:company [:name :id :locations]]
|
||||||
[:checks [:amount [:check [:amount :s3_url :check_number ]]]]
|
[:checks [:amount [:check [:amount :s3_url :check_number ]]]]
|
||||||
]]
|
]]
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
[auto-ap.entities.companies :as company]
|
[auto-ap.entities.companies :as company]
|
||||||
[auto-ap.entities.invoice :as invoice]
|
[auto-ap.entities.invoice :as invoice]
|
||||||
[auto-ap.entities.vendors :as vendor]
|
[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.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.views.utils :refer [dispatch-event bind-field horizontal-field date->str str->date pretty standard]]
|
||||||
[auto-ap.utils :refer [by replace-if]]
|
[auto-ap.utils :refer [by replace-if]]
|
||||||
@@ -412,8 +413,9 @@
|
|||||||
(re-frame/reg-event-db
|
(re-frame/reg-event-db
|
||||||
::add-expense-account-split
|
::add-expense-account-split
|
||||||
(fn [db _]
|
(fn [db _]
|
||||||
(update-in db [::change-expense-accounts :invoice :expense-accounts]
|
(let [{{{:keys [locations]} :company} :invoice} @(re-frame/subscribe [::change-expense-accounts])]
|
||||||
conj {:amount 0 :expense-account-id nil})))
|
(update-in db [::change-expense-accounts :invoice :expense-accounts]
|
||||||
|
conj {:amount 0 :expense-account-id nil :location (first locations)}))))
|
||||||
|
|
||||||
(re-frame/reg-event-db
|
(re-frame/reg-event-db
|
||||||
::remove-expense-account-split
|
::remove-expense-account-split
|
||||||
@@ -425,7 +427,7 @@
|
|||||||
|
|
||||||
(defn change-expense-accounts-modal []
|
(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])
|
(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]]
|
change-event [::events/change-form [::change-expense-accounts]]
|
||||||
expense-accounts-total (->> expense-accounts
|
expense-accounts-total (->> expense-accounts
|
||||||
(map :amount)
|
(map :amount)
|
||||||
@@ -446,7 +448,7 @@
|
|||||||
[:thead
|
[:thead
|
||||||
[:tr
|
[:tr
|
||||||
[:th {:style {:width "500px"}} "Expense Account"]
|
[:th {:style {:width "500px"}} "Expense Account"]
|
||||||
(when should-select-location?
|
(when multi-location?
|
||||||
[:th {:style {:width "500px"}} "Location"])
|
[:th {:style {:width "500px"}} "Location"])
|
||||||
[:th {:style {:width "300px"}} "Amount"]
|
[:th {:style {:width "300px"}} "Amount"]
|
||||||
[:th {:style {:width "5em"}}]]]
|
[:th {:style {:width "5em"}}]]]
|
||||||
@@ -462,17 +464,19 @@
|
|||||||
:spec ::invoice/vendor-id
|
:spec ::invoice/vendor-id
|
||||||
:subscription data}]]]]
|
:subscription data}]]]]
|
||||||
|
|
||||||
(when should-select-location?
|
(when multi-location?
|
||||||
[:td
|
[:td
|
||||||
[:div.select
|
(if-let [forced-location (-> expense-account :expense-account-id expense-accounts/expense-accounts :location)]
|
||||||
[bind-field
|
[:div.select
|
||||||
[:select {:type "select"
|
[:select {:disabled "disabled" :value forced-location} [:option {:value forced-location} forced-location]]]
|
||||||
:field [:invoice :expense-accounts index :location]
|
[:div.select
|
||||||
:spec (set locations)
|
[bind-field
|
||||||
:event change-event
|
[:select {:type "select"
|
||||||
:subscription data}
|
:field [:invoice :expense-accounts index :location]
|
||||||
(map (fn [l] [:option {:value l} l]) locations)]]]
|
:spec (set locations)
|
||||||
])
|
:event change-event
|
||||||
|
:subscription data}
|
||||||
|
(map (fn [l] [:option {:value l} l]) locations)]]])])
|
||||||
|
|
||||||
[:td
|
[:td
|
||||||
[:div.control
|
[:div.control
|
||||||
|
|||||||
Reference in New Issue
Block a user