From 4a6aeaab8f22da38194f70c07e5a701584b8c6cd Mon Sep 17 00:00:00 2001 From: Bryce Covert Date: Thu, 30 Apr 2020 07:22:39 -0700 Subject: [PATCH] customized transactions. --- src/clj/auto_ap/graphql/ledger.clj | 28 ++++-- src/clj/auto_ap/ledger.clj | 4 +- src/cljs/auto_ap/subs.cljs | 91 +++++++++++++------ .../components/expense_accounts_dialog.cljs | 7 +- .../components/expense_accounts_field.cljs | 17 ++-- .../views/components/invoice_table.cljs | 8 +- src/cljs/auto_ap/views/components/modal.cljs | 2 +- .../views/components/vendor_dialog.cljs | 6 +- .../auto_ap/views/pages/admin/accounts.cljs | 2 +- .../views/pages/admin/excel_import.cljs | 2 +- .../auto_ap/views/pages/admin/rules/form.cljs | 42 +++++---- .../auto_ap/views/pages/invoices/form.cljs | 13 ++- src/cljs/auto_ap/views/pages/ledger.cljs | 2 +- .../views/pages/ledger/balance_sheet.cljs | 72 ++++++++------- .../views/pages/ledger/profit_and_loss.cljs | 2 - .../auto_ap/views/pages/ledger/table.cljs | 4 +- .../auto_ap/views/pages/transactions.cljs | 3 +- .../views/pages/transactions/form.cljs | 5 +- 18 files changed, 184 insertions(+), 126 deletions(-) diff --git a/src/clj/auto_ap/graphql/ledger.clj b/src/clj/auto_ap/graphql/ledger.clj index e71d4d4a..0cbe25da 100644 --- a/src/clj/auto_ap/graphql/ledger.clj +++ b/src/clj/auto_ap/graphql/ledger.clj @@ -41,8 +41,17 @@ (defn expense-account? [account] (= :account-type/expense (:db/ident (:account/type account)))) +(defn account-name [account client] + (let [overriden-name (->> + (:account/client-overrides account) + (filter (fn [co] + (= (:db/id (:account-client-override/client co)) (:db/id client)))) + (map :account-client-override/name) + first)] -(defn roll-up [results] + (or overriden-name (:account/name account)))) + +(defn roll-up [client results] (->> results (mapcat :journal-entry/line-items) (group-by (juxt :journal-entry-line/account :journal-entry-line/location)) @@ -51,9 +60,10 @@ #_(when-not (or (:bank-account/name account) (:account/name account)) (println "WARNING " account line-items)) (conj result - {:name (str (or (:bank-account/name account) (:account/name account)) (when-not (#{"A" } location) - (str - "-" location))) + {:name (str (or (:bank-account/name account) (account-name account client)) + (when-not (#{"A" } location) + (str + "-" location))) :location location :id (str (:db/id account) "-" location) :numeric-code (or (:account/numeric-code account) @@ -87,6 +97,7 @@ (defn get-balance-sheet [context args value] (let [args (assoc args :id (:id context)) + client (d-clients/get-by-id (:client_id args)) [results] (l/get-graphql {:client-id (:client_id args) :date-range {:end (coerce/to-date (:date args))} :count Integer/MAX_VALUE}) @@ -96,12 +107,13 @@ :to-date (coerce/to-date (time/minus (:date args) (time/years 1))) :count Integer/MAX_VALUE})] (->graphql - {:balance-sheet-accounts (roll-up results) - :comparable-balance-sheet-accounts (roll-up comparable-results)}))) + {:balance-sheet-accounts (roll-up client results) + :comparable-balance-sheet-accounts (roll-up client comparable-results)}))) (defn get-profit-and-loss [context args value] (let [args (assoc args :id (:id context)) + client (d-clients/get-by-id (:client_id args)) pnl (fn [from-date to-date] (println "FROM" from-date to-date) (let [[starting-results] (l/get-graphql {:client-id (:client_id args) @@ -112,8 +124,8 @@ [ending-results] (l/get-graphql {:client-id (:client_id args) :date-range {:end (coerce/to-date to-date)} :count Integer/MAX_VALUE}) - starting-accounts (by :id (roll-up starting-results)) - ending-accounts (by :id (roll-up ending-results))] + starting-accounts (by :id (roll-up client starting-results)) + ending-accounts (by :id (roll-up client ending-results))] (reduce-kv (fn [results k v] (conj results (update v :amount (fn [amt] diff --git a/src/clj/auto_ap/ledger.clj b/src/clj/auto_ap/ledger.clj index 48af28fa..5d146cb8 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 (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 2110 ["default"])) :journal-entry-line/location "A" :journal-entry-line/credit (:invoice/total entity)}] (map (fn [ea] @@ -138,7 +138,7 @@ (doseq [d-tx d-txs] - #_(println "updating general-ledger " d-tx) + (println "updating general-ledger " d-tx) @(d/transact (d/connect uri) [d-tx])))) (def break (atom false)) diff --git a/src/cljs/auto_ap/subs.cljs b/src/cljs/auto_ap/subs.cljs index a8cbbdad..dbfe89dc 100644 --- a/src/cljs/auto_ap/subs.cljs +++ b/src/cljs/auto_ap/subs.cljs @@ -16,33 +16,71 @@ (sort-by :name (vals (:clients db)))))) (re-frame/reg-sub - ::accounts + ::all-accounts (fn [db] (:accounts db))) +(re-frame/reg-sub + ::all-accounts-by-id + (fn [db] + (by :id (:accounts db)))) + +(defn clientize-account [account client] + (let [override (->> + (:client-overrides account) + (filter (fn [co] + (= (:id (:client co)) (:id client)))) + first)] + (condp = (:applicability account) + nil + (assoc account :name (or (:name override) (:name account))) + + :global + (assoc account :name (or (:name override) (:name account))) + + :optional + (when override + (assoc account :name (or (:name override) (:name account)))) + + :customized + (when override + (assoc account :name (or (:name override) (:name account))))))) + +(re-frame/reg-sub + ::accounts + :<- [::all-accounts] + :<- [::client] + (fn [[accounts client] [_ client-override]] + (transduce + (comp + (map + #(clientize-account % (or client-override client))) + (filter identity)) + conj + [] + accounts))) + (re-frame/reg-sub ::account + (fn [[_ client]] + [(re-frame/subscribe [::accounts-by-id client])]) + (fn [[as] [_ _ i]] + (as i))) + +(defn accounts-by-id [accounts client] + (by :id + (map + #(clientize-account % client) + + accounts))) + +(re-frame/reg-sub + ::accounts-by-id :<- [::accounts] - (fn [as [_ i]] - (first (filter - #(= (:id %) i) - as)))) - -(re-frame/reg-sub - ::accounts-for-client - (fn [db client] - (:accounts db))) - -(re-frame/reg-sub - ::accounts-for-client-by-id - (fn [db client] - (by :id (:accounts db)))) - -(re-frame/reg-sub - ::accounts-for-current-client - (fn [db] - (:accounts db))) + :<- [::client] + (fn [[accounts client] [_ client-override]] + (accounts-by-id accounts (or client-override client)))) (re-frame/reg-sub ::bank-accounts @@ -132,7 +170,8 @@ (re-frame/reg-sub ::vendor-default-account (fn [db [_ v client]] - (let [vendor (if (:default-account v) + (let [accounts (accounts-by-id (:accounts db) client) + vendor (if (:default-account v) v (-> (:vendors db) (get v))) client-override (->> (:account-overrides vendor) @@ -143,9 +182,7 @@ :id) default-id (:id (:default-account v)) i (or client-override default-id)] - (first (filter - #(= (:id %) i) - (:accounts db)))))) + (accounts i)))) (re-frame/reg-sub ::sorted-vendors @@ -202,12 +239,6 @@ (fn [db] (:query-params db))) -(re-frame/reg-sub - ::chooseable-expense-accounts - :<- [::accounts-for-current-client] - (fn [accounts] - accounts)) - (re-frame/reg-sub ::page-failure (fn [db] diff --git a/src/cljs/auto_ap/views/components/expense_accounts_dialog.cljs b/src/cljs/auto_ap/views/components/expense_accounts_dialog.cljs index 8b7f214a..cc959c23 100644 --- a/src/cljs/auto_ap/views/components/expense_accounts_dialog.cljs +++ b/src/cljs/auto_ap/views/components/expense_accounts_dialog.cljs @@ -113,7 +113,7 @@ (let [{{:keys [expense-accounts total] :or {expense-accounts [] total 0} {:keys [locations]} :client} :invoice error :error :as data} @(re-frame/subscribe [::change-expense-accounts]) multi-location? (> (count locations) 1) change-event [::change] - chooseable-expense-accounts @(re-frame/subscribe [::subs/chooseable-expense-accounts]) + chooseable-expense-accounts @(re-frame/subscribe [::subs/accounts (:client (:invoice data))]) expense-accounts-total (->> expense-accounts (map :new-amount) (map js/parseFloat) @@ -143,8 +143,7 @@ [:th {:style {:width "5em"}}]]] [:tbody (doall (for [{:keys [id] :as expense-account} expense-accounts - :let [sub @(re-frame/subscribe [::expense-account (:id expense-account)]) - _ (println "SUBB" sub)]] + :let [sub @(re-frame/subscribe [::expense-account (:id expense-account)])]] ^{:key id} [:tr [:td.expandable [:div.control @@ -158,7 +157,7 @@ (when multi-location? [:td - (if-let [forced-location (:location @(re-frame/subscribe [::subs/account (-> sub :account :id )]))] + (if-let [forced-location (:location @(re-frame/subscribe [::subs/account (:client (:invoice data)) (-> sub :account :id )]))] [:div.select [:select {:disabled "disabled" :value forced-location} [:option {:value forced-location} forced-location]]] [:div.select diff --git a/src/cljs/auto_ap/views/components/expense_accounts_field.cljs b/src/cljs/auto_ap/views/components/expense_accounts_field.cljs index ec191a90..009d8374 100644 --- a/src/cljs/auto_ap/views/components/expense_accounts_field.cljs +++ b/src/cljs/auto_ap/views/components/expense_accounts_field.cljs @@ -27,11 +27,14 @@ :account default-account}]) -(defn from-graphql [accounts total locations] +(defn from-graphql [accounts accounts-by-id total locations] (if (seq accounts) (vec (map (fn [a] (-> a + (update :account (fn [a] + (accounts-by-id (:id a)))) + (update :amount js/parseFloat) (assoc :amount-percentage (* 100 (/ (js/parseFloat (:amount a)) (Math/abs (js/parseFloat total))))) @@ -93,7 +96,7 @@ (fn [_ [_ event expense-accounts max-value field value]] (let [updated-accounts (cond-> expense-accounts true (assoc-in field value) - (= (list :account :id) (drop 1 field)) (assoc-in [(first field) :account] @(re-frame/subscribe [::subs/account value])) + (= (list :account :id) (drop 1 field)) (assoc-in [(first field) :account] @(re-frame/subscribe [::subs/account nil value])) (= (list :amount-percentage) (drop 1 field)) (assoc-in [(first field) :amount] (js/parseFloat (goog.string/format "%.2f" @@ -108,9 +111,9 @@ ;; VIEWS -(defn expense-accounts-field [{expense-accounts :value max-value :max locations :locations event :event descriptor :descriptor disabled :disabled percentage-only? :percentage-only? :or {percentage-only? false}}] - (let [chooseable-expense-accounts @(re-frame/subscribe [::subs/chooseable-expense-accounts]) - accounts-by-id @(re-frame/subscribe [::subs/accounts-for-client-by-id])] +(defn expense-accounts-field [{expense-accounts :value client :client max-value :max locations :locations event :event descriptor :descriptor disabled :disabled percentage-only? :percentage-only? :or {percentage-only? false}}] + (let [chooseable-expense-accounts @(re-frame/subscribe [::subs/accounts client]) + accounts-by-id @(re-frame/subscribe [::subs/accounts-by-id client])] [:div [:div.columns [:div.column @@ -151,8 +154,10 @@ [:p.help "Account"] [:div.control.is-fullwidth [bind-field + ^{:key (:id client)} [typeahead-entity {:matches chooseable-expense-accounts - :match->text (fn [x ] (str (:numeric-code x) " - " (:name x))) + :match->text (fn [x ] + (str (:numeric-code x) " - " (:name x))) :disabled disabled :type "typeahead-entity" :field [index :account] diff --git a/src/cljs/auto_ap/views/components/invoice_table.cljs b/src/cljs/auto_ap/views/components/invoice_table.cljs index 57433061..5789607e 100644 --- a/src/cljs/auto_ap/views/components/invoice_table.cljs +++ b/src/cljs/auto_ap/views/components/invoice_table.cljs @@ -49,7 +49,7 @@ [[:invoices [:id :total :outstanding-balance :invoice-number :date :due :status :client-identifier [:vendor [:name :id]] [:expense_accounts [:amount :id :location - [:account [:id :name :numeric-code :location ]]]] + [:account [:id ]]]] [:client [:name :id :locations]] [:payments [:amount :id [:payment [:id :status :amount :s3_url :check_number [:transaction [:post_date]]]]]]]] @@ -70,7 +70,9 @@ :dispatch [:auto-ap.views.pages.unpaid-invoices/params-change]})) (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] + (let [{:keys [client payments expense-accounts invoice-number date due total outstanding-balance id vendor] :as i} invoice + accounts-by-id @(re-frame/subscribe [::subs/accounts-by-id client]) + account->name #(:name (accounts-by-id (:id %)))] [:tr {:class (:class i)} (when check-boxes [:td [:input.checkbox {:type "checkbox" @@ -104,7 +106,7 @@ [:div (for [e expense-accounts] ^{:key (:id e)} - [:span.dropdown-item (:name (:account e)) " " (gstring/format "$%.2f" (:amount e) ) ]) + [:span.dropdown-item (account->name (:account e)) " " (gstring/format "$%.2f" (:amount e) ) ]) [:hr.dropdown-divider] diff --git a/src/cljs/auto_ap/views/components/modal.cljs b/src/cljs/auto_ap/views/components/modal.cljs index f30ebb1e..16ea46e0 100644 --- a/src/cljs/auto_ap/views/components/modal.cljs +++ b/src/cljs/auto_ap/views/components/modal.cljs @@ -42,7 +42,7 @@ (not can-submit?) (assoc :disabled "disabled")) ] :id id - :hide-event [::events/modal-status id {:visible? false}]} + :hide-event [::events/modal-status id {:visible? false :error-message nil}]} [appearing {:visible? error-message :timeout 200 :enter-class "appear" diff --git a/src/cljs/auto_ap/views/components/vendor_dialog.cljs b/src/cljs/auto_ap/views/components/vendor_dialog.cljs index e39de9d1..fcb83000 100644 --- a/src/cljs/auto_ap/views/components/vendor_dialog.cljs +++ b/src/cljs/auto_ap/views/components/vendor_dialog.cljs @@ -78,7 +78,7 @@ %)) (update :default-account (fn [da] - @(re-frame/subscribe [::subs/account (:id da)])))))) + @(re-frame/subscribe [::subs/account nil (:id da)])))))) :dispatch [::events/modal-status ::dialog {:visible? true}]})) (re-frame/reg-event-db @@ -170,7 +170,7 @@ [:a.button {:on-click (dispatch-event [::removed-override override-key i])} [:span.icon [:span.icon-remove]]]]])])])) (defn form-content [{:keys [data change-event]}] - (let [chooseable-expense-accounts @(re-frame/subscribe [::subs/chooseable-expense-accounts]) + (let [accounts @(re-frame/subscribe [::subs/accounts]) clients @(re-frame/subscribe [::subs/clients])] [:div [horizontal-field @@ -219,7 +219,7 @@ [default-with-overrides {:data data :change-event change-event :default-key :default-account :override-key :account-overrides} - [typeahead-entity {:matches chooseable-expense-accounts + [typeahead-entity {:matches accounts :match->text (fn [x ] (str (:numeric-code x) " - " (:name x))) :type "typeahead-entity" :event change-event diff --git a/src/cljs/auto_ap/views/pages/admin/accounts.cljs b/src/cljs/auto_ap/views/pages/admin/accounts.cljs index b6699de5..cf17a5e7 100644 --- a/src/cljs/auto_ap/views/pages/admin/accounts.cljs +++ b/src/cljs/auto_ap/views/pages/admin/accounts.cljs @@ -44,7 +44,7 @@ (defn admin-accounts-content [] [:div - (let [accounts @(re-frame/subscribe [::subs/accounts])] + (let [accounts @(re-frame/subscribe [::subs/all-accounts])] [:div [:h1.title "Accounts"] [:div.is-pulled-right diff --git a/src/cljs/auto_ap/views/pages/admin/excel_import.cljs b/src/cljs/auto_ap/views/pages/admin/excel_import.cljs index de5d2050..3dbcb2bf 100644 --- a/src/cljs/auto_ap/views/pages/admin/excel_import.cljs +++ b/src/cljs/auto_ap/views/pages/admin/excel_import.cljs @@ -115,7 +115,7 @@ form @(re-frame/subscribe [::forms/form ::excel-import]) - chooseable-expense-accounts @(re-frame/subscribe [::subs/chooseable-expense-accounts]) + chooseable-expense-accounts @(re-frame/subscribe [::subs/all-accounts]) change-event [::all-events/change-form [::expense-accounts]]] (println form) [:div diff --git a/src/cljs/auto_ap/views/pages/admin/rules/form.cljs b/src/cljs/auto_ap/views/pages/admin/rules/form.cljs index 2f29e533..59fb1d5c 100644 --- a/src/cljs/auto_ap/views/pages/admin/rules/form.cljs +++ b/src/cljs/auto_ap/views/pages/admin/rules/form.cljs @@ -135,23 +135,26 @@ (re-frame/reg-event-db ::editing (fn [db [_ which]] - (-> db (forms/start-form ::form (-> which - (select-keys [:description - :id - :client - :bank-account - :note - :amount-lte - :amount-gte - :dom-lte - :dom-gte - :vendor - :accounts - :yodlee-merchant - :transaction-approval-status]) - (update :accounts (fn [xs] - (mapv #(assoc % :amount-percentage (* (:percentage %) 100.0)) - xs)))))))) + (let [accounts-by-id @(re-frame/subscribe [::subs/accounts-by-id (:client which)])] + (-> db (forms/start-form ::form (-> which + (select-keys [:description + :id + :client + :bank-account + :note + :amount-lte + :amount-gte + :dom-lte + :dom-gte + :vendor + :accounts + :yodlee-merchant + :transaction-approval-status]) + (update :accounts (fn [xs] + (mapv #(-> % + (assoc :amount-percentage (* (:percentage %) 100.0)) + (update :account (fn [a] (accounts-by-id (:id a))))) + xs))))))))) (re-frame/reg-event-db @@ -219,9 +222,7 @@ (let [{:keys [data active? error id]} @(re-frame/subscribe [::forms/form ::form]) {:keys [form field raw-field error-notification submit-button ]} rule-form default-note @(re-frame/subscribe [::default-note]) - exists? (:id data) - chooseable-expense-accounts @(re-frame/subscribe [::subs/chooseable-expense-accounts]) - accounts-by-id @(re-frame/subscribe [::subs/accounts-for-client-by-id])] + exists? (:id data)] ^{:key id} [form (assoc params :title "New Transaction Rule") @@ -307,6 +308,7 @@ [expense-accounts-field {:type "expense-accounts" :descriptor "account asssignment" :percentage-only? true + :client (:client data) :locations (into ["Shared"] @(re-frame/subscribe [::subs/locations-for-client-or-bank-account (:id (:client data)) (:id (:bank-account data))])) :max 100 :field [:accounts]}]] diff --git a/src/cljs/auto_ap/views/pages/invoices/form.cljs b/src/cljs/auto_ap/views/pages/invoices/form.cljs index 09db8d23..176a40e6 100644 --- a/src/cljs/auto_ap/views/pages/invoices/form.cljs +++ b/src/cljs/auto_ap/views/pages/invoices/form.cljs @@ -106,15 +106,18 @@ (re-frame/reg-event-db ::adding (fn [db [_ new]] - (let [locations @(re-frame/subscribe [::subs/locations-for-client (:client new)])] + (let [locations @(re-frame/subscribe [::subs/locations-for-client (:client new)]) + accounts-by-id @(re-frame/subscribe [::subs/accounts-by-id (:client new)])] (-> db (forms/start-form ::form (assoc new :expense-accounts (expense-accounts-field/from-graphql (:expense-accounts new) + accounts-by-id 0.0 locations))))))) (re-frame/reg-event-db ::editing (fn [db [_ which]] - (let [edit-invoice (update which :date #(date->str % standard)) + (let [accounts-by-id @(re-frame/subscribe [::subs/accounts-by-id (:client which)]) + edit-invoice (update which :date #(date->str % standard)) edit-invoice (update edit-invoice :due #(date->str % standard)) edit-invoice (assoc edit-invoice :original edit-invoice) locations @(re-frame/subscribe [::subs/locations-for-client (:id (:client which))])] @@ -129,6 +132,7 @@ :vendor (:vendor edit-invoice) :client (:client edit-invoice) :expense-accounts (expense-accounts-field/from-graphql (:expense-accounts which) + accounts-by-id (:amount which) locations)}))))) @@ -212,9 +216,7 @@ can-change-amount? (#{:unpaid ":unpaid"} (:status data)) min-total (if (= (:total (:original data)) (:outstanding-balance (:original data))) nil - (- (:total (:original data)) (:outstanding-balance (:original data)))) - chooseable-expense-accounts @(re-frame/subscribe [::subs/chooseable-expense-accounts]) - accounts-by-id @(re-frame/subscribe [::subs/accounts-for-client-by-id])] + (- (:total (:original data)) (:outstanding-balance (:original data))))] ^{:key id} [form (assoc params :title "New Invoice") (when-not @(re-frame/subscribe [::subs/client]) @@ -278,6 +280,7 @@ :descriptor "expense account" :locations (:locations (:client data)) :max (:total data) + :client (or (:client data) @(re-frame/subscribe [::subs/client])) :field [:expense-accounts]}]] diff --git a/src/cljs/auto_ap/views/pages/ledger.cljs b/src/cljs/auto_ap/views/pages/ledger.cljs index ce316a58..444c3ea0 100644 --- a/src/cljs/auto_ap/views/pages/ledger.cljs +++ b/src/cljs/auto_ap/views/pages/ledger.cljs @@ -59,7 +59,7 @@ [:name :id]] [:line-items [:id :debit :credit :location - [:account [:id :name]]]] + [:account [:id]]]] :date]] :total :start 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 79bbb917..00d85ba1 100644 --- a/src/cljs/auto_ap/views/pages/ledger/balance_sheet.cljs +++ b/src/cljs/auto_ap/views/pages/ledger/balance_sheet.cljs @@ -173,40 +173,44 @@ (let [current-client @(re-frame/subscribe [::subs/client]) user @(re-frame/subscribe [::subs/user]) params @(re-frame/subscribe [::params])] - [:div.is-inline - [:h1.title "Balance Sheet"] - [:div.report-controls - [:p.help "Date"] - [bind-field - [date-picker {:class-name "input" - :class "input" - :format-week-number (fn [] "") - :previous-month-button-label "" - :placeholder "mm/dd/yyyy" - :next-month-button-label "" - :next-month-label "" - :type "date" - :field [:date] - :event [::date-picked] - :popper-props (clj->js {:placement "right"}) - :subscription params}]]] - (if @(re-frame/subscribe [::loading]) - [:div [:i.icon.fa.fa-spin.fa-spinner]] - [:table.table.compact.balance-sheet - [:tr - [:td.has-text-right "Period ending"] - [:td.has-text-right (date->str (str->date (:date params) standard))] - [:td.has-text-right (when (:date params) - (date->str (t/minus (str->date (:date params) standard) (t/years 1))))] - [:td]] - (list - (overall-grouping :asset "Assets") - (overall-grouping :liability "Liabilities" ) - (overall-grouping :equity "Owner's Equity" ) - (retained-earnings))]) - - - ])) + (if current-client + [:div.is-inline + [:h1.title "Balance Sheet"] + [:div.report-controls + [:p.help "Date"] + [bind-field + [date-picker {:class-name "input" + :class "input" + :format-week-number (fn [] "") + :previous-month-button-label "" + :placeholder "mm/dd/yyyy" + :next-month-button-label "" + :next-month-label "" + :type "date" + :field [:date] + :event [::date-picked] + :popper-props (clj->js {:placement "right"}) + :subscription params}]]] + (if @(re-frame/subscribe [::loading]) + [:div [:i.icon.fa.fa-spin.fa-spinner]] + [:table.table.compact.balance-sheet + [:tr + [:td.has-text-right "Period ending"] + [:td.has-text-right (date->str (str->date (:date params) standard))] + [:td.has-text-right (when (:date params) + (date->str (t/minus (str->date (:date params) standard) (t/years 1))))] + [:td]] + (list + (overall-grouping :asset "Assets") + (overall-grouping :liability "Liabilities" ) + (overall-grouping :equity "Owner's Equity" ) + (retained-earnings))]) + + + ] + [:div + [:h1.title "Balance sheet"] + [:h2.subtitle "Please choose a client first"]]))) {:component-will-mount #(re-frame/dispatch-sync [::params-change {:date (date->str (local-now) standard)}]) })) (defn balance-sheet-page [] 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 338b9041..32640956 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 @@ -132,7 +132,6 @@ (re-frame/reg-event-db ::error (fn [db [_ [error]]] - (println (:message error)) (assoc db ::error (:message error) ::loading false))) @@ -209,7 +208,6 @@ (re-frame/reg-event-fx ::investigate-clicked (fn [{:keys [db] } [_ location from-numeric-code to-numeric-code which]] - (println from-numeric-code to-numeric-code) {:db (assoc db ::ledger-list-active? true ::ledger-list-loading true) diff --git a/src/cljs/auto_ap/views/pages/ledger/table.cljs b/src/cljs/auto_ap/views/pages/ledger/table.cljs index ec4ac53e..27f72756 100644 --- a/src/cljs/auto_ap/views/pages/ledger/table.cljs +++ b/src/cljs/auto_ap/views/pages/ledger/table.cljs @@ -25,6 +25,7 @@ (let [{:keys [sort]} @(re-frame/subscribe [::table-params]) {:keys [journal-entries start end count total]} @ledger-page selected-client @(re-frame/subscribe [::subs/client]) + accounts-by-id @(re-frame/subscribe [::subs/accounts-by-id selected-client]) percentage-size (if selected-client "25%" "33%") opc (fn [e] (re-frame/dispatch [::params-changed e]))] @@ -114,7 +115,8 @@ (when status? [:td status])]] - (for [{:keys [debit credit location account id]} line-items] + (for [{:keys [debit credit location account id]} line-items + :let [account (accounts-by-id (:id account))]] ^{:key id} [:tr {:class (:class i)} (when-not selected-client diff --git a/src/cljs/auto_ap/views/pages/transactions.cljs b/src/cljs/auto_ap/views/pages/transactions.cljs index c0b33a5e..9bf82eef 100644 --- a/src/cljs/auto_ap/views/pages/transactions.cljs +++ b/src/cljs/auto_ap/views/pages/transactions.cljs @@ -160,6 +160,5 @@ [manual/modal {:import-completed [::manual-import-completed ]}]] :right-side-bar [appearing-side-bar {:visible? transaction-bar-active?} - [edit/form {:edit-completed [::edit-completed]}]]}]))}) - ) + [edit/form {:edit-completed [::edit-completed]}]]}]))})) diff --git a/src/cljs/auto_ap/views/pages/transactions/form.cljs b/src/cljs/auto_ap/views/pages/transactions/form.cljs index 7cf38d87..3a73de42 100644 --- a/src/cljs/auto_ap/views/pages/transactions/form.cljs +++ b/src/cljs/auto_ap/views/pages/transactions/form.cljs @@ -45,7 +45,8 @@ (re-frame/reg-event-db ::editing (fn [db [_ which potential-payment-matches potential-transaction-rule-matches]] - (let [locations @(re-frame/subscribe [::subs/locations-for-client (:id (:client which))])] + (let [locations @(re-frame/subscribe [::subs/locations-for-client (:id (:client which))]) + accounts-by-id @(re-frame/subscribe [::subs/accounts-by-id (:client which)])] (forms/start-form db ::form (-> which (select-keys [:vendor :amount :payment :client :description-original @@ -59,7 +60,7 @@ (assoc :potential-transaction-rule-matches (if (:matched-rule which) nil potential-transaction-rule-matches)) - (update :accounts expense-accounts-field/from-graphql (:amount which) locations)))))) + (update :accounts expense-accounts-field/from-graphql accounts-by-id (:amount which) locations)))))) (re-frame/reg-event-db ::changed