From e749b3eb2375667518f86ac89a0121f880e3d2b5 Mon Sep 17 00:00:00 2001 From: Bryce Covert Date: Fri, 15 Jun 2018 17:21:45 -0700 Subject: [PATCH] You can update locations --- ...2-DOWN-add-location-to-expense-account.sql | 3 +++ ...932-UP-add-location-to-expense-account.sql | 2 ++ src/clj/auto_ap/graphql.clj | 2 ++ src/clj/auto_ap/graphql/invoices.clj | 3 ++- .../entities/invoices_expense_accounts.cljc | 3 ++- .../views/components/invoice_table.cljs | 4 ++-- .../auto_ap/views/pages/unpaid_invoices.cljs | 21 ++++++++++++++++--- 7 files changed, 31 insertions(+), 7 deletions(-) create mode 100644 migrator/migrations/1529091932-DOWN-add-location-to-expense-account.sql create mode 100644 migrator/migrations/1529091932-UP-add-location-to-expense-account.sql diff --git a/migrator/migrations/1529091932-DOWN-add-location-to-expense-account.sql b/migrator/migrations/1529091932-DOWN-add-location-to-expense-account.sql new file mode 100644 index 00000000..e21d74e3 --- /dev/null +++ b/migrator/migrations/1529091932-DOWN-add-location-to-expense-account.sql @@ -0,0 +1,3 @@ +-- 1529091932 DOWN add-location-to-expense-account + +ALTER TABLE invoices_expense_accounts drop COLUMN location ; diff --git a/migrator/migrations/1529091932-UP-add-location-to-expense-account.sql b/migrator/migrations/1529091932-UP-add-location-to-expense-account.sql new file mode 100644 index 00000000..4d3bdda1 --- /dev/null +++ b/migrator/migrations/1529091932-UP-add-location-to-expense-account.sql @@ -0,0 +1,2 @@ +-- 1529091932 UP add-location-to-expense-account +ALTER TABLE invoices_expense_accounts ADD COLUMN location varchar(255); diff --git a/src/clj/auto_ap/graphql.clj b/src/clj/auto_ap/graphql.clj index 02202f2a..6a8574eb 100644 --- a/src/clj/auto_ap/graphql.clj +++ b/src/clj/auto_ap/graphql.clj @@ -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 diff --git a/src/clj/auto_ap/graphql/invoices.clj b/src/clj/auto_ap/graphql/invoices.clj index f97bf96d..01383701 100644 --- a/src/clj/auto_ap/graphql/invoices.clj +++ b/src/clj/auto_ap/graphql/invoices.clj @@ -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 diff --git a/src/cljc/auto_ap/entities/invoices_expense_accounts.cljc b/src/cljc/auto_ap/entities/invoices_expense_accounts.cljc index ce19ef31..3ea392fc 100644 --- a/src/cljc/auto_ap/entities/invoices_expense_accounts.cljc +++ b/src/cljc/auto_ap/entities/invoices_expense_accounts.cljc @@ -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])) diff --git a/src/cljs/auto_ap/views/components/invoice_table.cljs b/src/cljs/auto_ap/views/components/invoice_table.cljs index d0ac94c5..1332fd5a 100644 --- a/src/cljs/auto_ap/views/components/invoice_table.cljs +++ b/src/cljs/auto_ap/views/components/invoice_table.cljs @@ -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 diff --git a/src/cljs/auto_ap/views/pages/unpaid_invoices.cljs b/src/cljs/auto_ap/views/pages/unpaid_invoices.cljs index 313da504..5c3ab476 100644 --- a/src/cljs/auto_ap/views/pages/unpaid_invoices.cljs +++ b/src/cljs/auto_ap/views/pages/unpaid_invoices.cljs @@ -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