From 532e35bb5035e7348a169c2d97d55a48a6c7de9b Mon Sep 17 00:00:00 2001 From: Bryce Covert Date: Sat, 2 May 2020 07:12:26 -0700 Subject: [PATCH] other changes to make app more predictable. --- project.clj | 1 + src/clj/auto_ap/graphql/ledger.clj | 8 ++-- src/clj/auto_ap/ledger.clj | 2 +- .../views/components/invoice_table.cljs | 3 +- .../views/components/invoices/side_bar.cljs | 4 +- .../views/pages/ledger/balance_sheet.cljs | 30 +++++++------- .../views/pages/ledger/profit_and_loss.cljs | 10 ++--- src/cljs/auto_ap/views/pages/payments.cljs | 39 ++++++++++--------- .../views/pages/payments/side_bar.cljs | 3 +- .../auto_ap/views/pages/payments/table.cljs | 3 +- .../auto_ap/views/pages/transactions.cljs | 33 +++++++++------- .../views/pages/transactions/side_bar.cljs | 3 +- .../views/pages/transactions/table.cljs | 3 +- .../auto_ap/views/pages/unpaid_invoices.cljs | 28 ++++++------- 14 files changed, 85 insertions(+), 85 deletions(-) diff --git a/project.clj b/project.clj index 81f2e544..e99c1051 100644 --- a/project.clj +++ b/project.clj @@ -114,6 +114,7 @@ [cljsjs/react-datepicker "2.1.0-0"] [cljsjs/react-transition-group "2.4.0-0"] [re-frame "0.10.2"] + [re-frame-utils "0.1.0"] [com.andrewmcveigh/cljs-time "0.5.2"]]}} :cljsbuild diff --git a/src/clj/auto_ap/graphql/ledger.clj b/src/clj/auto_ap/graphql/ledger.clj index 0cbe25da..08f99d34 100644 --- a/src/clj/auto_ap/graphql/ledger.clj +++ b/src/clj/auto_ap/graphql/ledger.clj @@ -134,10 +134,10 @@ [] ending-accounts)))] (->graphql - {:balance-sheet-accounts (pnl (coerce/to-date-time (:start (:date_range args))) - (coerce/to-date-time (:end (:date_range args)))) - :comparable-balance-sheet-accounts (pnl (time/minus (coerce/to-date-time (:start (:date_range args))) (time/years 1)) - (time/minus (coerce/to-date-time (:end (:date_range args))) (time/years 1)))}))) + {:balance-sheet-accounts (pnl (:start (:date_range args)) + (:end (:date_range args))) + :comparable-balance-sheet-accounts (pnl (time/minus (:start (:date_range args)) (time/years 1)) + (time/minus (:end (:date_range args)) (time/years 1)))}))) #_(get-profit-and-loss nil {:client_id [:client/code "CBC"] :from_date "2018-01-01" diff --git a/src/clj/auto_ap/ledger.clj b/src/clj/auto_ap/ledger.clj index 2f8dd900..7569282b 100644 --- a/src/clj/auto_ap/ledger.clj +++ b/src/clj/auto_ap/ledger.clj @@ -43,7 +43,7 @@ :journal-entry/vendor (:db/id (:invoice/vendor entity)) :journal-entry/amount (:invoice/total entity) - :journal-entry/line-items (into [{:journal-entry-line/account (:db/id (a/get-account-by-numeric-code-and-sets 2110 ["default"])) + :journal-entry/line-items (into [{:journal-entry-line/account (:db/id (a/get-account-by-numeric-code-and-sets 21000 ["default"])) :journal-entry-line/location "A" :journal-entry-line/credit (:invoice/total entity)}] (map (fn [ea] diff --git a/src/cljs/auto_ap/views/components/invoice_table.cljs b/src/cljs/auto_ap/views/components/invoice_table.cljs index 5789607e..ade72f92 100644 --- a/src/cljs/auto_ap/views/components/invoice_table.cljs +++ b/src/cljs/auto_ap/views/components/invoice_table.cljs @@ -66,8 +66,7 @@ ::params-changed [(re-frame/path [::table-params])] (fn [{table-params :db} [_ params :as z]] - {:db (merge table-params params) - :dispatch [:auto-ap.views.pages.unpaid-invoices/params-change]})) + {:db (merge table-params params)})) (defn row [{:keys [invoice check-boxes checked on-check-changed selected-client overrides expense-event on-edit-invoice on-void-invoice on-unvoid-invoice]}] (let [{:keys [client payments expense-accounts invoice-number date due total outstanding-balance id vendor] :as i} invoice diff --git a/src/cljs/auto_ap/views/components/invoices/side_bar.cljs b/src/cljs/auto_ap/views/components/invoices/side_bar.cljs index 0b23916a..4217a6cf 100644 --- a/src/cljs/auto_ap/views/components/invoices/side_bar.cljs +++ b/src/cljs/auto_ap/views/components/invoices/side_bar.cljs @@ -30,7 +30,6 @@ :<- [::filters] :<- [::subs/active-page] (fn [[filters ap]] - (println (:invoice-number-like filters)) {:vendor-id (:id (:vendor filters)) :date-range (:date-range filters) :invoice-number-like (:settled (:invoice-number-like filters)) @@ -48,8 +47,7 @@ [which val] (if (= 3 (count params)) [(into [a] b) c] [[a] b])] - {:dispatch [:auto-ap.views.pages.unpaid-invoices/params-change] - :db (assoc-in db (into [::filters] which) val)}))) + {:db (assoc-in db (into [::filters] which) val)}))) (re-frame/reg-event-fx ::invoice-number-like-settled diff --git a/src/cljs/auto_ap/views/pages/ledger/balance_sheet.cljs b/src/cljs/auto_ap/views/pages/ledger/balance_sheet.cljs index 00d85ba1..6c8c3d6e 100644 --- a/src/cljs/auto_ap/views/pages/ledger/balance_sheet.cljs +++ b/src/cljs/auto_ap/views/pages/ledger/balance_sheet.cljs @@ -52,22 +52,22 @@ (-> db ::loading))) (def groupings - {:asset [["1100 Cash and Bank Accounts" 1100 1199] - ["1200 Accounts Receivable" 1200 1299] - ["1300 Inventory" 1300 1399] - ["1400 Prepaid Expenses" 1400 1499] - ["1500 Property and Equipment" 1500 1599] - ["1600 Intangible Assets" 1600 1699] - ["1700 Other Assets" 1700 1999]] - :liability [["2000 Accounts Payable" 2000 2399] - ["2400 Accrued Expenses" 2400 2499] - ["2500 Other Liabilities" 2500 2599] - ["2600 Split Accounts" 2600 2699] - ["2700 Current Portion of Long-Term Debt" 2700 2799] - ["2800 Notes Payable" 2800 3000] + {:asset [["1100 Cash and Bank Accounts" 11000 11999] + ["1200 Accounts Receivable" 12000 12999] + ["1300 Inventory" 13000 13999] + ["1400 Prepaid Expenses" 14000 14999] + ["1500 Property and Equipment" 15000 15999] + ["1600 Intangible Assets" 16000 16999] + ["1700 Other Assets" 17000 19999]] + :liability [["2000 Accounts Payable" 21000 23999] + ["2400 Accrued Expenses" 24000 24999] + ["2500 Other Liabilities" 25000 25999] + ["2600 Split Accounts" 26000 26999] + ["2700 Current Portion of Long-Term Debt" 27000 27999] + ["2800 Notes Payable" 28000 28999] ] - :equity [["3000 Owner's Equity" 3000 3999]] - :revenue [["Retained Earnings" 4000 9999]]}) + :equity [["3000 Owner's Equity" 30000 39999]] + :revenue [["Retained Earnings" 40000 49999]]}) (re-frame/reg-event-db ::received diff --git a/src/cljs/auto_ap/views/pages/ledger/profit_and_loss.cljs b/src/cljs/auto_ap/views/pages/ledger/profit_and_loss.cljs index 32640956..1ac61e06 100644 --- a/src/cljs/auto_ap/views/pages/ledger/profit_and_loss.cljs +++ b/src/cljs/auto_ap/views/pages/ledger/profit_and_loss.cljs @@ -9,11 +9,11 @@ [cljs-time.core :as t] [re-frame.core :as re-frame])) (def ranges - {:sales [4100 4899] - :cogs [5100 5999] - :payroll [6010 6299] - :controllable [7100 7999] - :noncontrollable [8100 9999]}) + {:sales [41000 48999] + :cogs [51000 59999] + :payroll [60100 62999] + :controllable [71000 79999] + :noncontrollable [81000 99999]}) ;; SUBS (re-frame/reg-sub diff --git a/src/cljs/auto_ap/views/pages/payments.cljs b/src/cljs/auto_ap/views/pages/payments.cljs index 3cc3f9bd..50dca6fe 100644 --- a/src/cljs/auto_ap/views/pages/payments.cljs +++ b/src/cljs/auto_ap/views/pages/payments.cljs @@ -5,6 +5,7 @@ [reagent.core :as reagent] [goog.string :as gstring] [clojure.spec.alpha :as s] + [vimsical.re-frame.cofx.inject :as inject] [auto-ap.views.components.sorter :refer [sorted-column]] [auto-ap.views.components.date-range-filter :refer [date-range-filter]] [auto-ap.views.components.layouts :refer [side-bar-layout]] @@ -33,6 +34,7 @@ :<- [::side-bar/filter-params] :<- [::table/table-params] (fn [[client filter-params table-params]] + (re-frame/dispatch [::params-change]) (cond-> {} client (assoc :client-id (:id client)) (seq filter-params) (merge filter-params) @@ -40,24 +42,23 @@ (re-frame/reg-event-fx ::params-change - [with-user] - (fn [{:keys [user db]}[_ ]] - (let [new-params @(re-frame/subscribe [::params])] - (when (not= (::last-params db) new-params) - {:db (-> db - (assoc-in [:status :loading] true) - (assoc-in [::last-params] new-params)) - :graphql {:token user - :query-obj {:venia/queries [[:payment_page - @(re-frame/subscribe [::params]) - [[:payments [:id :status :amount :type :check_number :s3_url - [:bank-account [:name]] - :date [:vendor [:name :id]] [:client [:name :id]]]] - :total - :start - :end]]]} - :on-success [::received] - :on-error [::events/page-failed]}})))) + [with-user (re-frame/inject-cofx ::inject/sub [::params])] + (fn [{:keys [user db ::params]}[_ ]] + (when (not= (::last-params db) params) + {:db (-> db + (assoc-in [:status :loading] true) + (assoc-in [::last-params] params)) + :graphql {:token user + :query-obj {:venia/queries [[:payment_page + params + [[:payments [:id :status :amount :type :check_number :s3_url + [:bank-account [:name]] + :date [:vendor [:name :id]] [:client [:name :id]]]] + :total + :start + :end]]]} + :on-success [::received] + :on-error [::events/page-failed]}}))) (re-frame/reg-event-fx ::void-check @@ -95,7 +96,7 @@ {:db (dissoc db ::last-params ::table/table-params ::side-bar/filters ::payment-page)})) (defn content [] - (let [current-client @(re-frame/subscribe [::subs/client])] + (let [params @(re-frame/subscribe [::params])] [:div [:h1.title "Payments"] [table/table {:id :payments diff --git a/src/cljs/auto_ap/views/pages/payments/side_bar.cljs b/src/cljs/auto_ap/views/pages/payments/side_bar.cljs index 8d81b789..a2674af5 100644 --- a/src/cljs/auto_ap/views/pages/payments/side_bar.cljs +++ b/src/cljs/auto_ap/views/pages/payments/side_bar.cljs @@ -36,8 +36,7 @@ [which val] (if (= 3 (count params)) [(into [a] b) c] [[a] b])] - {:dispatch [:auto-ap.views.pages.payments/params-change] - :db (assoc-in db (into [::filters] which) val)}))) + {:db (assoc-in db (into [::filters] which) val)}))) (re-frame/reg-event-fx ::check-number-like-settled diff --git a/src/cljs/auto_ap/views/pages/payments/table.cljs b/src/cljs/auto_ap/views/pages/payments/table.cljs index f1a88c39..040144d4 100644 --- a/src/cljs/auto_ap/views/pages/payments/table.cljs +++ b/src/cljs/auto_ap/views/pages/payments/table.cljs @@ -16,8 +16,7 @@ ::params-changed [(re-frame/path [::table-params])] (fn [{table-params :db} [_ params :as z]] - {:db (merge table-params params) - :dispatch [:auto-ap.views.pages.payments/params-change]})) + {:db (merge table-params params)})) (defn row [{check :check selected-client :selected-client diff --git a/src/cljs/auto_ap/views/pages/transactions.cljs b/src/cljs/auto_ap/views/pages/transactions.cljs index 9bf82eef..26ae5425 100644 --- a/src/cljs/auto_ap/views/pages/transactions.cljs +++ b/src/cljs/auto_ap/views/pages/transactions.cljs @@ -4,6 +4,7 @@ [auto-ap.subs :as subs] [bidi.bidi :as bidi] [auto-ap.routes :as routes] + [vimsical.re-frame.cofx.inject :as inject] [auto-ap.views.components.bank-account-filter :refer [bank-account-filter]] [auto-ap.views.components.date-range-filter :refer [date-range-filter]] [auto-ap.views.components.number-filter :refer [number-filter]] @@ -19,7 +20,7 @@ [auto-ap.views.pages.transactions.common :refer [transaction-read]] [auto-ap.utils :refer [replace-by]] [auto-ap.views.pages.transactions.manual :as manual] - [auto-ap.views.utils :refer [bind-field date->str dispatch-event nf date-picker active-when]] + [auto-ap.views.utils :refer [bind-field date->str dispatch-event nf date-picker active-when with-user]] [goog.string :as gstring] [re-frame.core :as re-frame] [auto-ap.views.pages.transactions.side-bar :as side-bar] @@ -53,6 +54,7 @@ :<- [::side-bar/filter-params] :<- [::table/table-params] (fn [[client filter-params table-params]] + (re-frame/dispatch [::params-change]) (cond-> {} client (assoc :client-id (:id client)) (seq filter-params) (merge filter-params) @@ -60,20 +62,20 @@ (re-frame/reg-event-fx ::params-change - (fn [cofx [_ params]] - (let [new-params @(re-frame/subscribe [::params])] - (when (not= (::last-params (:db cofx)) new-params) - {:db (-> (:db cofx) - (assoc-in [:status :loading] true) - (assoc-in [::last-params] new-params)) - :graphql {:token (-> cofx :db :user) - :query-obj {:venia/queries [[:transaction_page - new-params - [[:transactions transaction-read] - :total - :start - :end]]]} - :on-success [::received]}})))) + [with-user (re-frame/inject-cofx ::inject/sub [::params])] + (fn [{:keys [user db ] ::keys [params]} _] + (when (not= (::last-params db) params) + {:db (-> db + (assoc-in [:status :loading] true) + (assoc-in [::last-params] params)) + :graphql {:token user + :query-obj {:venia/queries [[:transaction_page + params + [[:transactions transaction-read] + :total + :start + :end]]]} + :on-success [::received]}}))) (re-frame/reg-event-fx ::unapprove-all @@ -151,6 +153,7 @@ :reagent-render (fn [] (let [{transaction-bar-active? :active?} @(re-frame/subscribe [::forms/form ::edit/form]) + params @(re-frame/subscribe [::params]) ;; Keep to make sure it doens'nt get disposed ap @(re-frame/subscribe [::subs/active-page])] [side-bar-layout {:side-bar [side-bar/side-bar] diff --git a/src/cljs/auto_ap/views/pages/transactions/side_bar.cljs b/src/cljs/auto_ap/views/pages/transactions/side_bar.cljs index d4183e97..b75f7d8d 100644 --- a/src/cljs/auto_ap/views/pages/transactions/side_bar.cljs +++ b/src/cljs/auto_ap/views/pages/transactions/side_bar.cljs @@ -45,8 +45,7 @@ [which val] (if (= 3 (count params)) [(into [a] b) c] [[a] b])] - {:dispatch [:auto-ap.views.pages.transactions/params-change] - :db (assoc-in db (into [::filters] which) val)}))) + {:db (assoc-in db (into [::filters] which) val)}))) (re-frame/reg-event-fx ::description-settled diff --git a/src/cljs/auto_ap/views/pages/transactions/table.cljs b/src/cljs/auto_ap/views/pages/transactions/table.cljs index cc1a5454..5f682c3b 100644 --- a/src/cljs/auto_ap/views/pages/transactions/table.cljs +++ b/src/cljs/auto_ap/views/pages/transactions/table.cljs @@ -45,8 +45,7 @@ ::params-changed [(re-frame/path [::table-params])] (fn [{table-params :db} [_ params :as z]] - {:db (merge table-params params) - :dispatch [:auto-ap.views.pages.transactions/params-change]})) + {:db (merge table-params params)})) (defn table [{:keys [id transaction-page status]}] (let [{:keys [sort]} @(re-frame/subscribe [::table-params]) diff --git a/src/cljs/auto_ap/views/pages/unpaid_invoices.cljs b/src/cljs/auto_ap/views/pages/unpaid_invoices.cljs index c75f6c85..cf2e1142 100644 --- a/src/cljs/auto_ap/views/pages/unpaid_invoices.cljs +++ b/src/cljs/auto_ap/views/pages/unpaid_invoices.cljs @@ -19,6 +19,7 @@ [clojure.spec.alpha :as s] [clojure.string :as str :refer [blank?]] [goog.string :as gstring] + [vimsical.re-frame.cofx.inject :as inject] [re-frame.core :as re-frame] [reagent.core :as r])) @@ -70,6 +71,7 @@ :<- [::side-bar/filter-params] :<- [::table/table-params] (fn [[client filter-params table-params]] + (re-frame/dispatch [::params-change]) (cond-> {:import-status "imported"} client (assoc :client-id (:id client)) (seq filter-params) (merge filter-params) @@ -84,17 +86,16 @@ (re-frame/reg-event-fx ::params-change - [with-user] - (fn [cofx _] - (let [new-params @(re-frame/subscribe [::params])] - (when (not= new-params (::last-params (:db cofx))) - {:db (-> (:db cofx) - (assoc-in [:status :loading] true) - (assoc-in [::last-params] new-params)) - :graphql {:token (-> cofx :db :user) - :query-obj (table/query new-params ) - :on-success [::received] - :on-error [::events/page-failed]}})))) + [with-user (re-frame/inject-cofx ::inject/sub [::params])] + (fn [{::keys [params] :as cofx} _] + (when (not= params (::last-params (:db cofx))) + {:db (-> (:db cofx) + (assoc-in [:status :loading] true) + (assoc-in [::last-params] params)) + :graphql {:token (-> cofx :db :user) + :query-obj (table/query params ) + :on-success [::received] + :on-error [::events/page-failed]}}))) @@ -605,7 +606,7 @@ (let [{:keys [checked print-checks-shown? print-checks-loading? advanced-print-shown? vendor-filter]} @(re-frame/subscribe [::invoice-page]) current-client @(re-frame/subscribe [::subs/client])] [:div - [:h1.title (str (str/capitalize (or status "all")) " invoices")] + #_[:h1.title (str (str/capitalize (or status "all")) " invoices")] (when (= status "unpaid") [pay-button {:print-checks-shown? print-checks-shown? :checked-invoices checked :print-checks-loading? print-checks-loading?}]) [table/invoice-table {:id :unpaid @@ -631,7 +632,8 @@ :component-will-unmount #(re-frame/dispatch [::unmounted]) :reagent-render (fn [] - (let [{invoice-bar-active? :active?} @(re-frame/subscribe [::forms/form ::form/form])] + (let [{invoice-bar-active? :active?} @(re-frame/subscribe [::forms/form ::form/form]) + params @(re-frame/subscribe [::params])] [side-bar-layout {:side-bar [invoices-side-bar {}] :main [unpaid-invoices-content params] :bottom [:div