From 0eedc8908d71b3443ff31b432b37fa80335f0a71 Mon Sep 17 00:00:00 2001 From: Bryce Covert Date: Thu, 11 Apr 2019 13:59:20 -0700 Subject: [PATCH] You can now type accounts. --- src/clj/auto_ap/datomic/migrate.clj | 1 + .../datomic/migrate/add_general_ledger.clj | 6 ++++++ src/clj/auto_ap/datomic/transactions.clj | 16 ++++++++++++++-- src/clj/auto_ap/graphql.clj | 4 +++- src/clj/auto_ap/graphql/transactions.clj | 5 +++-- src/clj/auto_ap/routes/graphql.clj | 1 - src/cljs/auto_ap/subs.cljs | 5 +++++ .../auto_ap/views/pages/transactions/common.cljs | 1 + .../auto_ap/views/pages/transactions/form.cljs | 16 +++++++++++----- .../auto_ap/views/pages/transactions/table.cljs | 11 ++++++++++- 10 files changed, 54 insertions(+), 12 deletions(-) diff --git a/src/clj/auto_ap/datomic/migrate.clj b/src/clj/auto_ap/datomic/migrate.clj index 9c47112c..865bb240 100644 --- a/src/clj/auto_ap/datomic/migrate.clj +++ b/src/clj/auto_ap/datomic/migrate.clj @@ -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]} }] diff --git a/src/clj/auto_ap/datomic/migrate/add_general_ledger.clj b/src/clj/auto_ap/datomic/migrate/add_general_ledger.clj index c503012d..377b1f32 100644 --- a/src/clj/auto_ap/datomic/migrate/add_general_ledger.clj +++ b/src/clj/auto_ap/datomic/migrate/add_general_ledger.clj @@ -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 diff --git a/src/clj/auto_ap/datomic/transactions.clj b/src/clj/auto_ap/datomic/transactions.clj index a619fb1e..568aba2e 100644 --- a/src/clj/auto_ap/datomic/transactions.clj +++ b/src/clj/auto_ap/datomic/transactions.clj @@ -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) diff --git a/src/clj/auto_ap/graphql.clj b/src/clj/auto_ap/graphql.clj index dfde0569..d9e5cc63 100644 --- a/src/clj/auto_ap/graphql.clj +++ b/src/clj/auto_ap/graphql.clj @@ -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} diff --git a/src/clj/auto_ap/graphql/transactions.clj b/src/clj/auto_ap/graphql/transactions.clj index 05cb7d52..d13225f6 100644 --- a/src/clj/auto_ap/graphql/transactions.clj +++ b/src/clj/auto_ap/graphql/transactions.clj @@ -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) })) diff --git a/src/clj/auto_ap/routes/graphql.clj b/src/clj/auto_ap/routes/graphql.clj index 586839ad..c1968507 100644 --- a/src/clj/auto_ap/routes/graphql.clj +++ b/src/clj/auto_ap/routes/graphql.clj @@ -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"}}) diff --git a/src/cljs/auto_ap/subs.cljs b/src/cljs/auto_ap/subs.cljs index eaec6bbb..d6b658bc 100644 --- a/src/cljs/auto_ap/subs.cljs +++ b/src/cljs/auto_ap/subs.cljs @@ -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] diff --git a/src/cljs/auto_ap/views/pages/transactions/common.cljs b/src/cljs/auto_ap/views/pages/transactions/common.cljs index fe2869b4..928d9cb2 100644 --- a/src/cljs/auto_ap/views/pages/transactions/common.cljs +++ b/src/cljs/auto_ap/views/pages/transactions/common.cljs @@ -4,6 +4,7 @@ [:id :amount [:vendor [:name :id]] + [:account [:id :name]] :date :post_date :status diff --git a/src/cljs/auto_ap/views/pages/transactions/form.cljs b/src/cljs/auto_ap/views/pages/transactions/form.cljs index 028eb164..5419b834 100644 --- a/src/cljs/auto_ap/views/pages/transactions/form.cljs +++ b/src/cljs/auto_ap/views/pages/transactions/form.cljs @@ -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 diff --git a/src/cljs/auto_ap/views/pages/transactions/table.cljs b/src/cljs/auto_ap/views/pages/transactions/table.cljs index a7f355cf..e79ed54f 100644 --- a/src/cljs/auto_ap/views/pages/transactions/table.cljs +++ b/src/cljs/auto_ap/views/pages/transactions/table.cljs @@ -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