started adjusting the transaction form to support splits.

This commit is contained in:
Bryce Covert
2019-04-17 12:08:10 -07:00
parent d30b0948d4
commit 0081d0aaed
4 changed files with 23 additions and 38 deletions

View File

@@ -15,7 +15,6 @@
(let [args (assoc args :id (:id context)) (let [args (assoc args :id (:id context))
[transactions transactions-count] (d-transactions/get-graphql (<-graphql args)) [transactions transactions-count] (d-transactions/get-graphql (<-graphql args))
transactions (map ->graphql transactions)] transactions (map ->graphql transactions)]
(println transactions)
[{:transactions transactions [{:transactions transactions
:total transactions-count :total transactions-count
:count (count transactions) :count (count transactions)

View File

@@ -4,7 +4,8 @@
[auto-ap.views.components.typeahead :refer [typeahead]] [auto-ap.views.components.typeahead :refer [typeahead]]
[auto-ap.views.utils :refer [bind-field dispatch-event]] [auto-ap.views.utils :refer [bind-field dispatch-event]]
[goog.string :as gstring] [goog.string :as gstring]
[re-frame.core :as re-frame])) [re-frame.core :as re-frame]
[clojure.string :as str]))
;; EVENTS ;; EVENTS
@@ -35,13 +36,14 @@
;; VIEWS ;; 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]) (let [chooseable-expense-accounts @(re-frame/subscribe [::subs/chooseable-expense-accounts])
accounts-by-id @(re-frame/subscribe [::subs/accounts-for-client-by-id])] accounts-by-id @(re-frame/subscribe [::subs/accounts-for-client-by-id])]
[:div [:div
[:div.columns [:div.columns
[:div.column [:div.column
[:h1.subtitle.is-4.is-inline "Expense Accounts"]] [:h1.subtitle.is-4.is-inline (str/capitalize descriptor) "s"]]
[:div.column.is-narrow [:div.column.is-narrow
[:p.buttons [:p.buttons
[:a.button {:on-click (dispatch-event [::add-expense-account event expense-accounts])} "Add"]]]] [:a.button {:on-click (dispatch-event [::add-expense-account event expense-accounts])} "Add"]]]]
@@ -56,19 +58,18 @@
(str (:name account) " - " (str (:name account) " - "
location ": " location ": "
(gstring/format "$%.2f" (or amount 0) )) (gstring/format "$%.2f" (or amount 0) ))
[:i "New expense account"])]] [:i "New " descriptor])]]
[:div.column.is-narrow [:div.column.is-narrow
[:a.button {:on-click (dispatch-event [::remove-expense-account event expense-accounts id])} [:span.icon [:i.fa.fa-times]]]]] [:a.button {:on-click (dispatch-event [::remove-expense-account event expense-accounts id])} [:span.icon [:i.fa.fa-times]]]]]
[:div.field [:div.field
[:div.columns [:div.columns
[:div.column [:div.column
[:p.help "Expense Account"] [:p.help "Account"]
[:div.control.is-fullwidth [:div.control.is-fullwidth
[bind-field [bind-field
[typeahead {:matches (map (fn [x] [(:id x) (str (:numeric-code x) " - " (:name x))]) chooseable-expense-accounts) [typeahead {:matches (map (fn [x] [(:id x) (str (:numeric-code x) " - " (:name x))]) chooseable-expense-accounts)
:type "typeahead" :type "typeahead"
:field [index :account :id] :field [index :account :id]
:text-field [index :account :name]
:event [::expense-account-changed event expense-accounts] :event [::expense-account-changed event expense-accounts]
:subscription expense-accounts}]]]] :subscription expense-accounts}]]]]
[:div.column.is-narrow [:div.column.is-narrow

View File

@@ -139,13 +139,10 @@
::change-vendor ::change-vendor
[(forms/in-form ::form)] [(forms/in-form ::form)]
(fn [{{:keys [data]} :db} [_ location field value]] (fn [{{:keys [data]} :db} [_ location field value]]
(println "data" data)
(let [has-only-one-expense-account? (and value (let [has-only-one-expense-account? (and value
(or (not (seq (:expense-accounts data))) (or (not (seq (:expense-accounts data)))
(<= 1 (count (:expense-accounts data)))) (<= 1 (count (:expense-accounts data))))
(not (get-in data [:expense-accounts 0 :account :id])))] (not (get-in data [:expense-accounts 0 :account :id])))]
(println "has only one?" has-only-one-expense-account?)
(if has-only-one-expense-account? (if has-only-one-expense-account?
{:dispatch [::forms/change ::form {:dispatch [::forms/change ::form
field value field value
@@ -296,6 +293,7 @@
[bind-field [bind-field
[expense-accounts-field {:subscription data [expense-accounts-field {:subscription data
:type "expense-accounts" :type "expense-accounts"
:descriptor "expense account"
:event change-event :event change-event
:locations locations :locations locations
:max-value (:total data) :max-value (:total data)

View File

@@ -2,6 +2,7 @@
(:require [auto-ap.forms :as forms] (:require [auto-ap.forms :as forms]
[auto-ap.subs :as subs] [auto-ap.subs :as subs]
[auto-ap.views.components.typeahead :refer [typeahead]] [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.pages.transactions.common :refer [transaction-read]]
[auto-ap.views.utils :refer [bind-field]] [auto-ap.views.utils :refer [bind-field]]
[re-frame.core :as re-frame])) [re-frame.core :as re-frame]))
@@ -9,7 +10,6 @@
(re-frame/reg-event-db (re-frame/reg-event-db
::editing ::editing
(fn [db [_ which]] (fn [db [_ which]]
(println which)
(-> db (-> db
(forms/start-form ::edit-transaction {:id (:id which) (forms/start-form ::edit-transaction {:id (:id which)
:yodlee-merchant (:yodlee-merchant which) :yodlee-merchant (:yodlee-merchant which)
@@ -19,7 +19,10 @@
:account-id (:id (:account which)) :account-id (:id (:account which))
:account-name (:name (:account which)) :account-name (:name (:account which))
:vendor-id (:id (:vendor 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 (re-frame/reg-sub
::request ::request
:<- [::forms/form ::edit-transaction] :<- [::forms/form ::edit-transaction]
@@ -80,7 +83,6 @@
(.stopPropagation e) (.stopPropagation e)
(.preventDefault e)) (.preventDefault e))
(re-frame/dispatch-sync [::saving edit-completed]))} (re-frame/dispatch-sync [::saving edit-completed]))}
(println data)
[:h1.title.is-2 "Edit Transaction"] [:h1.title.is-2 "Edit Transaction"]
(comment (comment
@@ -119,6 +121,15 @@
:event change-event :event change-event
:subscription data}]]]] :subscription data}]]]]
[bind-field
[expense-accounts-field
{:type "expense-accounts"
:field [:expense-accounts]
:descriptor "credit account"
:locations locations
:event change-event
:subscription data}]]
(comment (comment
[:div.field [:div.field
[:p.control [:p.control
@@ -128,32 +139,8 @@
:subscription data}] :subscription data}]
" Always match Merchant '" (:merchant-name data) "' to '" (:vendor-name 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 (when error