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))
[transactions transactions-count] (d-transactions/get-graphql (<-graphql args))
transactions (map ->graphql transactions)]
(println transactions)
[{:transactions transactions
:total transactions-count
:count (count transactions)

View File

@@ -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

View File

@@ -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)

View File

@@ -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