From 1b56d7ff0fbcac5dac357a9273ffc938e3963c9b Mon Sep 17 00:00:00 2001 From: Bryce Covert Date: Wed, 17 Apr 2019 23:10:14 -0700 Subject: [PATCH] Makes balance sheet work correctly --- resources/public/css/main.css | 16 +++++ src/clj/auto_ap/graphql/ledger.clj | 2 +- .../views/pages/ledger/balance_sheet.cljs | 69 +++++++++++-------- src/cljs/auto_ap/views/utils.cljs | 3 + 4 files changed, 59 insertions(+), 31 deletions(-) diff --git a/resources/public/css/main.css b/resources/public/css/main.css index 22deb221..838ae25d 100644 --- a/resources/public/css/main.css +++ b/resources/public/css/main.css @@ -456,3 +456,19 @@ nav.navbar .navbar-item.is-active { width: 5em; } + + +table.balance-sheet th, table.balance-sheet td { + border: 0px; + +} + +table.balance-sheet th.total { + border-top: 1px solid black; + +} + +@media print { + /* All your print styles go here */ + #header, #footer, #nav, .menu, .aside ,.nav, .navbar{ display: none !important; } +} diff --git a/src/clj/auto_ap/graphql/ledger.clj b/src/clj/auto_ap/graphql/ledger.clj index 0a75694c..173096d5 100644 --- a/src/clj/auto_ap/graphql/ledger.clj +++ b/src/clj/auto_ap/graphql/ledger.clj @@ -86,7 +86,7 @@ :count Integer/MAX_VALUE}) [comparable-results] (l/get-graphql {:client-id (:client_id args) - :date-before (coerce/to-date (time/minus (parse (:date args) iso-date) (time/months 1))) + :date-before (coerce/to-date (time/minus (parse (:date args) iso-date) (time/years 1))) :count Integer/MAX_VALUE})] (->graphql {:balance-sheet-accounts (roll-up results) 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 12750225..86589a2e 100644 --- a/src/cljs/auto_ap/views/pages/ledger/balance_sheet.cljs +++ b/src/cljs/auto_ap/views/pages/ledger/balance_sheet.cljs @@ -3,8 +3,8 @@ [auto-ap.views.components.layouts :refer [side-bar-layout]] [goog.string :as gstring] [auto-ap.utils :refer [by]] - [auto-ap.views.pages.ledger.side-bar :refer [ledger-side-bar]] - [auto-ap.views.utils :refer [date->str date-picker bind-field local-now standard]] + [auto-ap.views.pages.ledger.side-bar :refer [ledger-side-bar]] + [auto-ap.views.utils :refer [date->str date-picker bind-field local-now standard ->$ str->date]] [cljs-time.core :as t] [re-frame.core :as re-frame])) @@ -110,35 +110,52 @@ :when (seq matching-accounts) ] (list - [:tr [:td "---" grouping-name "---"] + [:tr [:th "---" grouping-name "---"] [:td] [:td] [:td] ] (for [account matching-accounts] [:tr [:td (:name account)] - [:td.has-text-right (gstring/format "$%.2f" (:amount account))] - [:td.has-text-right (gstring/format "$%.2f" (:amount (get comparable-accounts (:id account)) 0))] - [:td.has-text-right (gstring/format "$%.2f" (- (:amount account ) (:amount (get comparable-accounts (:id account)) 0)))]]) - [:tr [:td "---" grouping-name "---"] - [:td.has-text-right (gstring/format "$%.2f" (reduce + 0 (map :amount + [:td.has-text-right (->$ (:amount account))] + [:td.has-text-right (->$ (:amount (get comparable-accounts (:id account)) 0))] + [:td.has-text-right (->$ (- (:amount account ) (:amount (get comparable-accounts (:id account)) 0)))]]) + [:tr [:th "---" grouping-name "---"] + [:th.has-text-right.total (->$ (reduce + 0 (map :amount matching-accounts))) ] - [:td.has-text-right (gstring/format "$%.2f" (reduce + 0 (map #(:amount (get comparable-accounts (:id %)) 0) + [:th.has-text-right.total (->$ (reduce + 0 (map #(:amount (get comparable-accounts (:id %)) 0) matching-accounts)))] - [:td.has-text-right (gstring/format "$%.2f" (reduce + 0 + [:th.has-text-right.total (->$ (reduce + 0 (map #(- (:amount % ) (:amount (get comparable-accounts (:id %)) 0)) matching-accounts)))] [:td] ]))) +(defn overall-grouping [type title] + (list + [:tr [:th.has-text-centered title] + [:td] + [:td] + [:td]] + (grouping {:accounts @(re-frame/subscribe [::accounts type]) + :groupings (type groupings) + :comparable-accounts @(re-frame/subscribe [::comparable-accounts-by-id type]) + }) + [:tr [:th.has-text-centered title] + [:th.has-text-right (->$ (reduce + 0 (map :amount @(re-frame/subscribe [::accounts type]))))] + [:th.has-text-right (->$ (reduce + 0 (map :amount (vals @(re-frame/subscribe [::comparable-accounts-by-id type])))))] + [:th.has-text-right (->$ (- (reduce + 0 (map :amount @(re-frame/subscribe [::accounts type]))) + (reduce + 0 (map :amount (vals @(re-frame/subscribe [::comparable-accounts-by-id type]))))))]])) + (def balance-sheet-content (with-meta (fn [] (let [current-client @(re-frame/subscribe [::subs/client]) user @(re-frame/subscribe [::subs/user]) params @(re-frame/subscribe [::params])] - [:div + [:div.is-inline [:h1.title "Balance Sheet"] + [:p.help "Date"] [bind-field [date-picker {:class-name "input" :class "input" @@ -152,26 +169,18 @@ :event [::date-picked] :popper-props (clj->js {:placement "right"}) :subscription params}]] - [:table.table + [: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 - [:tr [:td "Assets"] - [:td] - [:td] - [:td]] - (grouping {:accounts @(re-frame/subscribe [::accounts :asset]) - :groupings (:asset groupings) - :comparable-accounts @(re-frame/subscribe [::comparable-accounts-by-id :asset]) - :header "Assets"}) - [:tr [:td "Liabilities"] - [:td] - [:td] - [:td]] - (grouping {:accounts @(re-frame/subscribe [::accounts :liability]) - :groupings (:liability groupings) - :comparable-accounts @(re-frame/subscribe [::comparable-accounts-by-id :liability]) - :header "Liabilities"}))] - #_[:h2.title "Liabilities"] - #_[grouping @(re-frame/subscribe [::liabilities])] + (overall-grouping :asset "Assets") + (overall-grouping :liability "Liabilities" ) + (overall-grouping :equity "Owner's Equity" ))] + ])) {:component-will-mount #(re-frame/dispatch-sync [::params-change {:date (date->str (local-now) standard)}]) })) diff --git a/src/cljs/auto_ap/views/utils.cljs b/src/cljs/auto_ap/views/utils.cljs index 78fc98d5..96eb37f1 100644 --- a/src/cljs/auto_ap/views/utils.cljs +++ b/src/cljs/auto_ap/views/utils.cljs @@ -21,6 +21,9 @@ [num] (.format nff (str num))) +(defn ->$ [x] + (nf x)) + (defn active-when= [active-page candidate]