From 0081d0aaed44c6dd2cc25d3f528e3552ff88ef44 Mon Sep 17 00:00:00 2001 From: Bryce Covert Date: Wed, 17 Apr 2019 12:08:10 -0700 Subject: [PATCH] started adjusting the transaction form to support splits. --- src/clj/auto_ap/graphql/transactions.clj | 1 - .../components/expense_accounts_field.cljs | 13 +++--- .../auto_ap/views/pages/invoices/form.cljs | 4 +- .../views/pages/transactions/form.cljs | 43 +++++++------------ 4 files changed, 23 insertions(+), 38 deletions(-) diff --git a/src/clj/auto_ap/graphql/transactions.clj b/src/clj/auto_ap/graphql/transactions.clj index bd8ae440..aed4da08 100644 --- a/src/clj/auto_ap/graphql/transactions.clj +++ b/src/clj/auto_ap/graphql/transactions.clj @@ -15,7 +15,6 @@ (let [args (assoc args :id (:id context)) [transactions transactions-count] (d-transactions/get-graphql (<-graphql args)) transactions (map ->graphql transactions)] - (println transactions) [{:transactions transactions :total transactions-count :count (count transactions) diff --git a/src/cljs/auto_ap/views/components/expense_accounts_field.cljs b/src/cljs/auto_ap/views/components/expense_accounts_field.cljs index 85928998..faa8d58a 100644 --- a/src/cljs/auto_ap/views/components/expense_accounts_field.cljs +++ b/src/cljs/auto_ap/views/components/expense_accounts_field.cljs @@ -4,7 +4,8 @@ [auto-ap.views.components.typeahead :refer [typeahead]] [auto-ap.views.utils :refer [bind-field dispatch-event]] [goog.string :as gstring] - [re-frame.core :as re-frame])) + [re-frame.core :as re-frame] + [clojure.string :as str])) ;; EVENTS @@ -35,13 +36,14 @@ ;; VIEWS -(defn expense-accounts-field [{expense-accounts :value max-value :max locations :locations event :event}] +(defn expense-accounts-field [{expense-accounts :value max-value :max locations :locations event :event descriptor :descriptor}] (let [chooseable-expense-accounts @(re-frame/subscribe [::subs/chooseable-expense-accounts]) accounts-by-id @(re-frame/subscribe [::subs/accounts-for-client-by-id])] + [:div [:div.columns [:div.column - [:h1.subtitle.is-4.is-inline "Expense Accounts"]] + [:h1.subtitle.is-4.is-inline (str/capitalize descriptor) "s"]] [:div.column.is-narrow [:p.buttons [:a.button {:on-click (dispatch-event [::add-expense-account event expense-accounts])} "Add"]]]] @@ -56,19 +58,18 @@ (str (:name account) " - " location ": " (gstring/format "$%.2f" (or amount 0) )) - [:i "New expense account"])]] + [:i "New " descriptor])]] [:div.column.is-narrow [:a.button {:on-click (dispatch-event [::remove-expense-account event expense-accounts id])} [:span.icon [:i.fa.fa-times]]]]] [:div.field [:div.columns [:div.column - [:p.help "Expense Account"] + [:p.help "Account"] [:div.control.is-fullwidth [bind-field [typeahead {:matches (map (fn [x] [(:id x) (str (:numeric-code x) " - " (:name x))]) chooseable-expense-accounts) :type "typeahead" :field [index :account :id] - :text-field [index :account :name] :event [::expense-account-changed event expense-accounts] :subscription expense-accounts}]]]] [:div.column.is-narrow diff --git a/src/cljs/auto_ap/views/pages/invoices/form.cljs b/src/cljs/auto_ap/views/pages/invoices/form.cljs index 48fb0fb2..91e03cdc 100644 --- a/src/cljs/auto_ap/views/pages/invoices/form.cljs +++ b/src/cljs/auto_ap/views/pages/invoices/form.cljs @@ -139,13 +139,10 @@ ::change-vendor [(forms/in-form ::form)] (fn [{{:keys [data]} :db} [_ location field value]] - (println "data" data) (let [has-only-one-expense-account? (and value (or (not (seq (:expense-accounts data))) (<= 1 (count (:expense-accounts data)))) (not (get-in data [:expense-accounts 0 :account :id])))] - (println "has only one?" has-only-one-expense-account?) - (if has-only-one-expense-account? {:dispatch [::forms/change ::form field value @@ -296,6 +293,7 @@ [bind-field [expense-accounts-field {:subscription data :type "expense-accounts" + :descriptor "expense account" :event change-event :locations locations :max-value (:total data) diff --git a/src/cljs/auto_ap/views/pages/transactions/form.cljs b/src/cljs/auto_ap/views/pages/transactions/form.cljs index d640eb2d..4a4ff199 100644 --- a/src/cljs/auto_ap/views/pages/transactions/form.cljs +++ b/src/cljs/auto_ap/views/pages/transactions/form.cljs @@ -2,6 +2,7 @@ (:require [auto-ap.forms :as forms] [auto-ap.subs :as subs] [auto-ap.views.components.typeahead :refer [typeahead]] + [auto-ap.views.components.expense-accounts-field :refer [expense-accounts-field]] [auto-ap.views.pages.transactions.common :refer [transaction-read]] [auto-ap.views.utils :refer [bind-field]] [re-frame.core :as re-frame])) @@ -9,7 +10,6 @@ (re-frame/reg-event-db ::editing (fn [db [_ which]] - (println which) (-> db (forms/start-form ::edit-transaction {:id (:id which) :yodlee-merchant (:yodlee-merchant which) @@ -19,7 +19,10 @@ :account-id (:id (:account which)) :account-name (:name (:account which)) :vendor-id (:id (:vendor which)) - :vendor-name (:name (:vendor which))})))) + :vendor-name (:name (:vendor which)) + :expense-accounts (or (:expense-accounts which) + [{:id (str "new-" (random-uuid)) + :amount (Math/abs (:amount which))}])})))) (re-frame/reg-sub ::request :<- [::forms/form ::edit-transaction] @@ -80,7 +83,6 @@ (.stopPropagation e) (.preventDefault e)) (re-frame/dispatch-sync [::saving edit-completed]))} - (println data) [:h1.title.is-2 "Edit Transaction"] (comment @@ -119,6 +121,15 @@ :event change-event :subscription data}]]]] + [bind-field + [expense-accounts-field + {:type "expense-accounts" + :field [:expense-accounts] + :descriptor "credit account" + :locations locations + :event change-event + :subscription data}]] + (comment [:div.field [:p.control @@ -128,32 +139,8 @@ :subscription data}] " Always match Merchant '" (:merchant-name data) "' to '" (:vendor-name data) "'" ]]]) - [:div.field - [:p.help "Credit Account"] - [:div.control - [bind-field - [typeahead {:matches (map (fn [x] [(:id x) (str (:numeric-code x) " - " (:name x))]) @(re-frame/subscribe [::subs/accounts-for-client (:id (:client data))])) - :type "typeahead" - :field [:account-id] - :text-field [:account-name] - :event [::change-account] - :subscription data}]]]] - [:div.field - [:p.help "Location"] - [:div.control - (if-let [forced-location (:location @(re-frame/subscribe [::subs/account (-> data :account-id )]))] - [:div.select - [:select {:disabled "disabled" :value forced-location} [:option {:value forced-location} forced-location]]] - [:div.select - [bind-field - [:select {:type "select" - :allow-nil? true - :field [:location] - :spec (set locations) - :event change-event - :subscription data} - (map (fn [l] ^{:key l} [:option {:value l} l]) locations)]]])]] + (when error