ledger fixes

This commit is contained in:
Bryce Covert
2019-12-21 14:16:50 -08:00
parent cb2d71c6c0
commit 2df3c429e7
4 changed files with 169 additions and 106 deletions

View File

@@ -464,4 +464,14 @@ table.balance-sheet th.total {
@media print {
/* All your print styles go here */
#header, #footer, #nav, .menu, .aside ,.nav, .navbar{ display: none !important; }
.report-controls {
display: none !important;
}
#message-feed {
overflow: inherit !important;
}
}

View File

@@ -24,17 +24,20 @@
{:redirect "/login"
:db (assoc db/default-db
:active-page :login
:last-client-id (.getItem js/localStorage "last-client-id")
:user token)}
(and token (= "none" (or (get (jwt->data token) "role") (get (jwt->data token) "user/role")) ))
{:redirect "/needs-activation"
:db (assoc db/default-db
:active-page :needs-activation
:last-client-id (.getItem js/localStorage "last-client-id")
:user token)}
:else
{:db (assoc db/default-db
:active-page handler
:last-client-id (.getItem js/localStorage "last-client-id")
:query-params (->> (:query (url (.-location js/window)))
(map (fn [[k v]] [(keyword k) v]))
(into {}))
@@ -81,11 +84,16 @@
(assoc :clients (by :id clients) )
(assoc :vendors (by :id vendors) )
(assoc :accounts accounts )
(assoc :client (when (= 1 (count clients)) (->> clients first :id ))))))
(assoc :client (or (when (= 1 (count clients)) (->> clients first :id ))
(->> clients
(map :id)
(filter #(= % (:last-client-id db)))
first))))))
(re-frame/reg-event-db
::swap-client
(fn [db [_ client]]
(.setItem js/localStorage "last-client-id" (:id client))
(assoc db :client (:id client))))
(re-frame/reg-event-db

View File

@@ -57,14 +57,17 @@
["1300 Inventory" 1300 1399]
["1400 Prepaid Expenses" 1400 1499]
["1500 Property and Equipment" 1500 1599]
["1600 Intangible Assets" 1600 1699]]
:liability [["2100 Accounts Payable" 2100 2399]
["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]
]})
]
:equity [["3000 Owner's Equity" 3000 3999]]
:revenue [["Retained Earnings" 4000 9999]]})
(re-frame/reg-event-db
::received
@@ -82,6 +85,7 @@
::params-change
(fn [cofx [_ params]]
{:db (-> (:db cofx)
(assoc-in [::error] nil)
(assoc-in [::loading] true)
(assoc-in [::params] params))
:graphql {:token (-> cofx :db :user)
@@ -145,6 +149,24 @@
[: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]))))))]]))
(defn retained-earnings []
(list
#_(grouping {:accounts @(re-frame/subscribe [::accounts type])
:comparable-accounts @(re-frame/subscribe [::comparable-accounts-by-id type])
})
[:tr [:th.has-text-centered "Retained Earnings"]
[:th.has-text-right (->$ (- (reduce + 0 (map :amount @(re-frame/subscribe [::accounts :revenue])))
(reduce + 0 (map :amount @(re-frame/subscribe [::accounts :expense])))))]
[:th.has-text-right (->$ (- (reduce + 0 (map :amount (vals @(re-frame/subscribe [::comparable-accounts-by-id :revenue]))))
(reduce + 0 (map :amount (vals @(re-frame/subscribe [::comparable-accounts-by-id :expense]))))))]
[:th.has-text-right (->$ (- (- (reduce + 0 (map :amount @(re-frame/subscribe [::accounts :revenue])))
(reduce + 0 (map :amount @(re-frame/subscribe [::accounts :expense]))))
(- (reduce + 0 (map :amount (vals @(re-frame/subscribe [::comparable-accounts-by-id :revenue]))))
(reduce + 0 (map :amount (vals @(re-frame/subscribe [::comparable-accounts-by-id :expense])))))))]]))
(def balance-sheet-content
(with-meta
(fn []
@@ -153,20 +175,21 @@
params @(re-frame/subscribe [::params])]
[:div.is-inline
[:h1.title "Balance Sheet"]
[: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}]]
[: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
@@ -179,7 +202,8 @@
(list
(overall-grouping :asset "Assets")
(overall-grouping :liability "Liabilities" )
(overall-grouping :equity "Owner's Equity" ))])
(overall-grouping :equity "Owner's Equity" )
(retained-earnings))])
]))

View File

@@ -76,7 +76,6 @@
:balance-sheet-accounts
(map #(update % :amount js/parseFloat))
(filter (fn [{:keys [account-type location numeric-code]}]
(and (or (nil? only-location)
(= only-location location))
(< (get-in ranges [type 0]) numeric-code (get-in ranges [type 1])))))
@@ -149,6 +148,7 @@
(fn [cofx [_ params]]
(let [c @(re-frame/subscribe [::subs/client])]
(cond-> {:db (-> (:db cofx)
(assoc-in [::error] nil)
(assoc-in [::loading] true)
(assoc-in [::params] params))}
c (assoc :graphql (when @(re-frame/subscribe [::subs/client])
@@ -267,8 +267,7 @@
["9700 Taxes" 9700 9799]
["9800 Other Expenses" 9800 9899]
;; ["9900 Tax Only Expenses" 9900 9999] Excluded from Profit and loss
]
})
]})
@@ -379,92 +378,114 @@
[:div
[:h1.title "Profit and Loss"]
[:h2.title.is-4 "Range"]
[:div
[:div.report-controls
[:h2.title.is-4 "Range"]
[:div
[:div.field.is-grouped
[:p.control
[:a.button
{:class (when (= (:selected params) "Last week") "is-active")
:on-click (dispatch-event
(let [last-sunday (loop [current (local-now)]
(if (= 7 (t/day-of-week current))
current
(recur (t/minus current (t/period :days 1)))))]
[::range-selected
(date->str (t/minus last-sunday (t/period :days 6)) standard)
(date->str last-sunday standard)
"Last week"]))}
"Last week"]]
[:p.control
[:a.button
{:class (when (= (:selected params) "Week to date") "is-active")
:on-click (dispatch-event [::range-selected
(date->str (loop [current (local-now)]
(if (= 1 (t/day-of-week current))
current
(recur (t/minus current (t/period :days 1)))))
standard)
(date->str (local-now) standard)
"Week to date"])}
"Week to date"]]
[:p.control
[:a.button
{:class (when (= (:selected params) "Last Month") "is-active")
:on-click (dispatch-event [::range-selected
(date->str (t/minus (t/local-date (t/year (local-now))
(t/month (local-now))
1)
(t/period :months 1))
standard)
(date->str (t/minus (t/local-date (t/year (local-now))
(t/month (local-now))
1)
(t/period :days 1)) standard)
"Last Month"])}
"Last Month"]]
[:p.control
[:a.button
{:class (when (= (:selected params) "Month to date") "is-active")
:on-click (dispatch-event [::range-selected
(date->str (t/local-date (t/year (local-now))
(t/month (local-now))
1)
standard)
(date->str (local-now) standard)
"Month to date"])}
"Month to date"]]
[:p.control
[:a.button
{:class (when (= (:selected params) "Year to date") "is-active")
:on-click (dispatch-event [::range-selected
(date->str (t/local-date (t/year (local-now))
1
1)
standard)
(date->str (local-now) standard)
"Year to date"])}
"Year to date"]]
[:p.control
[:a.button
{:class (when (= (:selected params) "Full year") "is-active")
:on-click (dispatch-event [::range-selected
(date->str (t/plus (t/minus (local-now) (t/period :years 1))
(t/period :days 1))
standard)
(date->str (local-now) standard)
"Full year"])}
"Full year"]]]]
[:div.field.is-grouped
[:p.control
[:a.button
{:class (when (= (:selected params) "Last week") "is-active")
:on-click (dispatch-event [::range-selected
(date->str (t/minus (local-now) (t/period :days 7)) standard)
(date->str (local-now) standard)
"Last week"])}
"Last week"]]
[:p.control
[:a.button
{:class (when (= (:selected params) "Week to date") "is-active")
:on-click (dispatch-event [::range-selected
(date->str (loop [current (local-now)]
(if (= 7 (t/day-of-week current))
current
(recur (t/minus current (t/period :days 1)))))
standard)
(date->str (local-now) standard)
"Week to date"])}
"Week to date"]]
[:p.control
[:a.button
{:class (when (= (:selected params) "Month to date") "is-active")
:on-click (dispatch-event [::range-selected
(date->str (t/local-date (t/year (local-now))
(t/month (local-now))
1)
standard)
(date->str (local-now) standard)
"Month to date"])}
"Month to date"]]
[:p.control
[:a.button
{:class (when (= (:selected params) "Year to date") "is-active")
:on-click (dispatch-event [::range-selected
(date->str (t/local-date (t/year (local-now))
1
1)
standard)
(date->str (local-now) standard)
"Year to date"])}
"Year to date"]]
[:p.control
[:a.button
{:class (when (= (:selected params) "Full year") "is-active")
:on-click (dispatch-event [::range-selected
(date->str (t/minus (local-now) (t/period :years 1))
standard)
(date->str (local-now) standard)
"Full year"])}
"Full year"]]]]
[:div.field.is-grouped
[:p.control
[:p.help "From"]
[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 [:from-date]
:event [::date-picked]
:popper-props (clj->js {:placement "right"})
:subscription params}]]]
[:p.control
[:p.help "From"]
[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 [:from-date]
:event [::date-picked]
:popper-props (clj->js {:placement "right"})
:subscription params}]]]
[:p.control
[:p.help "To"]
[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 [:to-date]
:event [::date-picked]
:popper-props (clj->js {:placement "right"})
:subscription params}]]]]
[:p.control
[:p.help "To"]
[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 [:to-date]
:event [::date-picked]
:popper-props (clj->js {:placement "right"})
:subscription params}]]]]]
(cond
error
[:div.notification.is-warning error]