More grouping.

This commit is contained in:
Bryce Covert
2019-04-17 23:45:00 -07:00
parent 1b56d7ff0f
commit 4c7cd1ff3e
2 changed files with 38 additions and 36 deletions

View File

@@ -44,14 +44,16 @@
(defn roll-up [results]
(->> results
(mapcat :journal-entry/line-items)
(group-by :journal-entry-line/account)
(reduce-kv (fn [result account line-items]
(group-by (juxt :journal-entry-line/account :journal-entry-line/location))
(reduce-kv (fn [result [account location] line-items]
;; TODO fix
(when-not (or (:bank-account/name account) (:account/name account))
(println "WARNING " account line-items))
(conj result
{:name (or (:bank-account/name account) (:account/name account))
:id (:db/id account)
{:name (str (or (:bank-account/name account) (:account/name account)) (when-not (#{"A" } location)
(str
"-" location)))
:id (str (:db/id account) "-" location)
:numeric-code (or (:account/numeric-code account)
(and (:bank-account/type account)
1100))

View File

@@ -46,34 +46,31 @@
(= type account-type)))
(by :id))))
(re-frame/reg-sub
::loading
(fn [db]
(-> 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]]
:liability
[["2100 Accounts Payable" 2100 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]]})
#_(re-frame/reg-sub
::liabilities
(fn [db]
(->> db ::report :balance-sheet-accounts (filter (fn [{:keys [account-type]}] :liability)))))
{: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]]
:liability [["2100 Accounts Payable" 2100 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]]})
(re-frame/reg-event-db
::received
(fn [db [_ data]]
(-> db
(assoc ::report (:balance-sheet data))
(assoc-in [:status :loading] false))))
(assoc-in [::loading] false))))
(re-frame/reg-sub
::params
@@ -84,7 +81,7 @@
::params-change
(fn [cofx [_ params]]
{:db (-> (:db cofx)
(assoc-in [:status :loading] true)
(assoc-in [::loading] true)
(assoc-in [::params] params))
:graphql {:token (-> cofx :db :user)
:query-obj {:venia/queries [[:balance-sheet
@@ -169,17 +166,20 @@
:event [::date-picked]
:popper-props (clj->js {:placement "right"})
:subscription params}]]
[: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" ))]
(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" ))])
]))
{:component-will-mount #(re-frame/dispatch-sync [::params-change {:date (date->str (local-now) standard)}]) }))