You can update locations

This commit is contained in:
Bryce Covert
2018-06-15 17:21:45 -07:00
parent b06a6651ca
commit e749b3eb23
7 changed files with 31 additions and 7 deletions

View File

@@ -0,0 +1,3 @@
-- 1529091932 DOWN add-location-to-expense-account
ALTER TABLE invoices_expense_accounts drop COLUMN location ;

View File

@@ -0,0 +1,2 @@
-- 1529091932 UP add-location-to-expense-account
ALTER TABLE invoices_expense_accounts ADD COLUMN location varchar(255);

View File

@@ -107,6 +107,7 @@
{:fields {:id {:type 'Int}
:invoice_id {:type 'Int}
:expense_account_id {:type 'Int}
:location {:type 'String}
:expense_account {:type :expense_account
:resolve :get-expense-account}
:amount {:type 'String}}}
@@ -213,6 +214,7 @@
:edit_expense_account
{:fields {:id {:type 'Int}
:expense_account_id {:type 'Int}
:location {:type 'String}
:amount {:type 'String}}}
:add_invoice

View File

@@ -29,9 +29,10 @@
(invoices-expense-accounts/get-for-invoice (:id value))))
(defn edit-expense-accounts [context args value]
(invoices-expense-accounts/replace-for-invoice (:invoice_id args) (map (fn [{:keys [id expense_account_id amount]}]
(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)} )
(:expense_accounts args)))
(->graphql

View File

@@ -6,5 +6,6 @@
(s/def ::vendor-id int?)
(s/def ::expense-account-id int?)
(s/def ::amount ::shared/money)
(s/def ::location string?)
(s/def ::invoices-expense-account (s/keys :opt-un [::vendor-id ::expense-account-id ::amount]))
(s/def ::invoices-expense-account (s/keys :opt-un [::vendor-id ::expense-account-id ::amount ::location]))

View File

@@ -22,9 +22,9 @@
:company-id (:id @(re-frame/subscribe [::subs/company])))
[[:invoices [:id :total :outstanding-balance :invoice-number :date
[:vendor [:name :id]]
[:expense_accounts [:amount :id :expense_account_id
[:expense_accounts [:amount :id :expense_account_id :location
[:expense_account [:id :name [:parent [:id :name]]]]]]
[:company [:name :id]]
[:company [:name :id :locations]]
[:checks [:amount [:check [:amount :s3_url :check_number ]]]]
]]
:total

View File

@@ -250,13 +250,14 @@
{:invoice-id id
:expense-accounts (map (fn [ea] {:id (:id ea)
:amount (:amount ea)
:location (:location ea)
:expense-account-id (:expense-account-id ea)})
expense-accounts)}
[:id :total :outstanding-balance :invoice-number :date
[:vendor [:name :id]]
[:expense_accounts [:amount :id :expense_account_id
[:expense_accounts [:amount :id :location :expense_account_id
[:expense_account [:id :name [:parent [:id :name]]]]]]
[:company [:name :id]]
[:company [:name :id :locations]]
[:checks [:amount [:check [:amount :s3_url :check_number ]]]]
]]}]}
:on-success [::expense-accounts-updated]}})))
@@ -290,7 +291,8 @@
(drop (inc index) expense-accounts))))))
(defn change-expense-accounts-modal []
(let [{{:keys [expense-accounts total] :or {expense-accounts [] total 0}} :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)
change-event [::events/change-form [::change-expense-accounts]]
expense-accounts-total (->> expense-accounts
(map :amount)
@@ -311,6 +313,8 @@
[:thead
[:tr
[:th {:style {:width "500px"}} "Expense Account"]
(when should-select-location?
[:th {:style {:width "500px"}} "Location"])
[:th {:style {:width "300px"}} "Amount"]
[:th {:style {:width "5em"}}]]]
[:tbody
@@ -325,6 +329,17 @@
:spec ::invoice/vendor-id
:subscription data}]]]]
(when should-select-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)]]]
])
[:td
[:div.control