You can now type accounts.

This commit is contained in:
Bryce Covert
2019-04-11 13:59:20 -07:00
parent a9975c8a10
commit 0eedc8908d
10 changed files with 54 additions and 12 deletions

View File

@@ -82,6 +82,7 @@
:auto-ap/add-general-ledger6 {:txes add-general-ledger/add-general-ledger :requires [:auto-ap/make-every-account-visible]}
:auto-ap/add-general-ledger-fns2 {:txes-fn 'auto-ap.datomic.migrate.add-general-ledger/add-general-ledger-fns :requires [:auto-ap/add-general-ledger6]}
:auto-ap/add-accounts {:txes auto-ap.datomic.migrate.add-general-ledger/add-accounts :requires [:auto-ap/add-general-ledger-fns2]}
:auto-ap/add-transaction-account {:txes auto-ap.datomic.migrate.add-general-ledger/add-transaction-account :requires [:auto-ap/add-general-ledger-fns2]}
#_#_:auto-ap/bulk-load-invoice-ledger2 {:txes-fn 'auto-ap.datomic.migrate.add-general-ledger/bulk-load-invoice-ledger :requires [:auto-ap/make-entity-not-unique]}
}]

View File

@@ -64,6 +64,12 @@
:db/doc "Location of the entry"}]
]
)
(def add-transaction-account
[[{:db/ident :transaction/account
:db/valueType :db.type/ref
:db/cardinality :db.cardinality/one
:db/doc "The debit/credit for this transaction"}]])
(def add-accounts
[[
{:db/ident :account/code

View File

@@ -9,6 +9,9 @@
(= "client" sort-by)
#(-> % :transaction/client :client/name)
(= "account" sort-by)
#(-> % :transaction/account :account/name)
:else
(keyword "transaction" sort-by)))
@@ -64,6 +67,13 @@
(:sort-by args) (add-sorter-field {"client" ['[?e :transaction/client ?c]
'[?c :client/name ?sorter]]
"account" #_['[(get-else $ ?e :transaction/account 0) ?sorter]]
['(or (and [?e :transaction/account ?c]
[?c :account/name ?sorter])
(and
[?e :transaction/client]
[(ground 0) ?c]
[(ground "") ?sorter]))]
"description-original" ['[?e :transaction/description-original ?sorter]]
"date" ['[?e :transaction/date ?sorter]]
"amount" ['[?e :transaction/amount ?sorter]]
@@ -107,7 +117,8 @@
(defn graphql-results [ids db args]
(->> (d/pull-many db '[* {:transaction/client [:client/name :db/id :client/code]
:transaction/bank-account [:bank-account/name :bank-account/code :bank-account/yodlee-account-id :db/id]
:transaction/vendor [:db/id :vendor/name]}]
:transaction/vendor [:db/id :vendor/name]
:transaction/account [:db/id :account/name :account/numeric-code]}]
ids)
(map #(update % :transaction/date c/from-date))
(map #(update % :transaction/post-date c/from-date))
@@ -126,7 +137,8 @@
(d/pull (d/db (d/connect uri))
'[* {:transaction/client [:client/name :db/id :client/code]
:transaction/bank-account [:bank-account/name :bank-account/code :bank-account/yodlee-account-id :db/id]
:transaction/vendor [:db/id :vendor/name]}]
:transaction/vendor [:db/id :vendor/name]
:transaction/account [:db/id :account/name :account/numeric-code]}]
id)
(update :transaction/date c/from-date)
(update :transaction/post-date c/from-date)

View File

@@ -133,6 +133,7 @@
:status {:type 'String}
:merchant_name {:type 'String}
:client {:type :client}
:account {:type :account}
:payment {:type :payment}
:vendor {:type :vendor}
:bank_account {:type :bank_account}
@@ -371,7 +372,8 @@
:total {:type 'Float}}}
:edit_transaction
{:fields {:id {:type :id}
:vendor_id {:type :id}}}}
:vendor_id {:type :id}
:account_id {:type :id}}}}
:enums {:payment_type {:values [{:enum-value :check}
{:enum-value :cash}

View File

@@ -24,11 +24,12 @@
(defn edit-transaction [context {{:keys [id vendor_id] :as transaction} :transaction} value]
(defn edit-transaction [context {{:keys [id account_id vendor_id] :as transaction} :transaction} value]
(assert-can-see-client (:id context) (:db/id (d-transactions/get-by-id id)))
@(d/transact (d/connect uri)
[{:db/id id
:transaction/vendor vendor_id}])
:transaction/vendor vendor_id
:transaction/account account_id}])
(->graphql (d-transactions/get-by-id id))
#_(->graphql {:id id
:vendor (d-vendors/get-by-id vendor_id) }))

View File

@@ -13,7 +13,6 @@
(let [variables (some-> (query-params "variables")
edn/read-string)
body (some-> r :body slurp)]
(println "BODY" body)
{:status 200
:body (pr-str (ql/query (:identity r) (doto (if (= request-method :get) (query-params "query") body) println) variables ))
:headers {"Content-Type" "application/edn"}})

View File

@@ -20,6 +20,11 @@
(fn [db]
(:accounts db)))
(re-frame/reg-sub
::accounts-for-client
(fn [db client]
(:accounts db)))
(re-frame/reg-sub
::bank-accounts
:<- [::clients]

View File

@@ -4,6 +4,7 @@
[:id
:amount
[:vendor [:name :id]]
[:account [:id :name]]
:date
:post_date
:status

View File

@@ -11,6 +11,8 @@
(fn [db [_ which]]
(-> db
(forms/start-form ::edit-transaction {:id (:id which)
:account-id (:id (:account which))
:account-name (:name (:account which))
:vendor-id (:id (:vendor which))
:vendor-name (:name (:vendor which))}))))
@@ -32,14 +34,17 @@
::saving
(fn [{:keys [db]} [_ edit-completed]]
(when @(re-frame/subscribe [::can-submit])
(let [{{:keys [id vendor-id]} :data :as data} @(re-frame/subscribe [::forms/form ::edit-transaction])]
(let [{{:keys [id vendor-id account-id]} :data :as data} @(re-frame/subscribe [::forms/form ::edit-transaction])]
(println "DATA" data)
{:db (forms/loading db ::edit-transaction )
:graphql
{:token (-> db :user)
:query-obj {:venia/operation {:operation/type :mutation
:operation/name "EditTransaction"}
:venia/queries [{:query/data [:edit-transaction
{:transaction {:id id :vendor-id vendor-id}}
{:transaction {:id id
:vendor-id vendor-id
:account-id account-id}}
transaction-read]}]}
:on-success [::edited edit-completed]
:on-error [::forms/save-error ::edit-transaction]}}))))
@@ -99,10 +104,11 @@
[:p.help "Credit Account"]
[:div.control
[bind-field
[typeahead {:matches (map (fn [x] [(:id x) (str (:id x) " - " (:name x))]) @(re-frame/subscribe [::subs/chooseable-expense-accounts]))
[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 [:expense-account-id]
:event [::change id]
:field [:account-id]
:text-field [:account-name]
:event change-event
:subscription data}]]]]
(when error

View File

@@ -61,6 +61,14 @@
:asc asc}
"Amount"]
[sorted-column {:on-sort opc
:style {:width "8em" :cursor "pointer"}
:sort-key "account"
:class "has-text-right"
:sort-by sort-by
:asc asc}
"Account"]
[sorted-column {:on-sort opc
:style {:width "8em" :cursor "pointer"}
:sort-key "status"
@@ -74,7 +82,7 @@
[:tr
[:td {:col-span 5}
[:i.fa.fa-spin.fa-spinner]]]
(for [{:keys [client vendor check status bank-account description-original date amount id ] :as i} (:transactions @transaction-page)]
(for [{:keys [client account vendor check status bank-account description-original date amount id ] :as i} (:transactions @transaction-page)]
^{:key id}
[:tr {:class (:class i)}
(when-not selected-client
@@ -85,6 +93,7 @@
[:td description-original]
[:td (date->str date) ]
[:td.has-text-right (nf amount )]
[:td (:name account)]
[:td status]
[:td (:name bank-account )]
[:td