Balance sheet has correct data, needs formatting.
This commit is contained in:
@@ -2,8 +2,9 @@
|
||||
(:require [auto-ap.subs :as subs]
|
||||
[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]]
|
||||
[auto-ap.views.utils :refer [date->str date-picker bind-field local-now standard]]
|
||||
[cljs-time.core :as t]
|
||||
[re-frame.core :as re-frame]))
|
||||
|
||||
@@ -13,14 +14,59 @@
|
||||
(-> db ::report)))
|
||||
|
||||
(re-frame/reg-sub
|
||||
::assets
|
||||
(fn [db]
|
||||
(->> db ::report :balance-sheet-groupings (filter (fn [{:keys [grouping-type]}] (= "Assets" grouping-type))))))
|
||||
::accounts
|
||||
(fn [db [_ type]]
|
||||
(->> db
|
||||
::report
|
||||
:balance-sheet-accounts
|
||||
(map #(update % :amount js/parseFloat))
|
||||
(filter (fn [{:keys [account-type]}]
|
||||
(= type account-type)))
|
||||
(sort-by :numeric-code))))
|
||||
|
||||
(re-frame/reg-sub
|
||||
::accounts-by-id
|
||||
(fn [db [_ type]]
|
||||
(->> db
|
||||
::report
|
||||
:balance-sheet-accounts
|
||||
(map #(update % :amount js/parseFloat))
|
||||
(filter (fn [{:keys [account-type]}]
|
||||
(= type account-type)))
|
||||
(by :id))))
|
||||
|
||||
(re-frame/reg-sub
|
||||
::comparable-accounts-by-id
|
||||
(fn [db [_ type]]
|
||||
(->> db
|
||||
::report
|
||||
:comparable-balance-sheet-accounts
|
||||
(map #(update % :amount js/parseFloat))
|
||||
(filter (fn [{:keys [account-type]}]
|
||||
(= type account-type)))
|
||||
(by :id))))
|
||||
|
||||
|
||||
(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-groupings (filter (fn [{:keys [grouping-type]}] (= "Liabilities" grouping-type))))))
|
||||
(->> db ::report :balance-sheet-accounts (filter (fn [{:keys [account-type]}] :liability)))))
|
||||
|
||||
(re-frame/reg-event-db
|
||||
::received
|
||||
@@ -44,40 +90,46 @@
|
||||
:query-obj {:venia/queries [[:balance-sheet
|
||||
(assoc params
|
||||
:client-id (:id @(re-frame/subscribe [::subs/client])))
|
||||
[[:balance-sheet-groupings [:grouping-type :name [:accounts [:name :amount]]]]]]]}
|
||||
[[:balance-sheet-accounts [:name :amount :account-type :id :numeric-code]]
|
||||
[:comparable-balance-sheet-accounts [:name :amount :account-type :id :numeric-code]]]]]}
|
||||
:on-success [::received]}}))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::date-picked
|
||||
(fn [cofx [_ _ date]]
|
||||
(println "DATE" date)
|
||||
|
||||
{:dispatch [::params-change (assoc @(re-frame/subscribe [::params])
|
||||
:date
|
||||
date)]}))
|
||||
|
||||
(defn grouping [groupings]
|
||||
(defn grouping [{:keys [header accounts comparable-accounts groupings]}]
|
||||
|
||||
[:table.table
|
||||
(for [grouping groupings]
|
||||
(list
|
||||
[:tr [:td {:col-span "2"} "----" (:name grouping) "----"]]
|
||||
(for [account (:accounts grouping)]
|
||||
|
||||
[:tr
|
||||
[:td (:name account) ]
|
||||
[:td.has-text-right (gstring/format "$%.2f" (:amount account))]]
|
||||
|
||||
)
|
||||
|
||||
[:tr [:td "----" (:name grouping) "----"]
|
||||
[:td.has-text-right
|
||||
(->> grouping
|
||||
:accounts
|
||||
(map :amount)
|
||||
(map #(js/parseFloat %))
|
||||
(reduce + 0)
|
||||
(gstring/format "$%.2f" ))]]))])
|
||||
(for [[grouping-name from to] groupings
|
||||
:let [matching-accounts (filter
|
||||
#(<= from (:numeric-code %) to)
|
||||
accounts)]
|
||||
:when (seq matching-accounts)
|
||||
]
|
||||
(list
|
||||
[:tr [:td "---" 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
|
||||
matching-accounts))) ]
|
||||
[:td.has-text-right (gstring/format "$%.2f" (reduce + 0 (map #(:amount (get comparable-accounts (:id %)) 0)
|
||||
matching-accounts)))]
|
||||
[:td.has-text-right (gstring/format "$%.2f" (reduce + 0
|
||||
(map #(- (:amount % ) (:amount (get comparable-accounts (:id %)) 0))
|
||||
matching-accounts)))]
|
||||
[:td]
|
||||
])))
|
||||
|
||||
(def balance-sheet-content
|
||||
(with-meta
|
||||
@@ -100,12 +152,28 @@
|
||||
:event [::date-picked]
|
||||
:popper-props (clj->js {:placement "right"})
|
||||
:subscription params}]]
|
||||
[:h2.title "Assets"]
|
||||
[grouping @(re-frame/subscribe [::assets])]
|
||||
[:h2.title "Liabilities"]
|
||||
[grouping @(re-frame/subscribe [::liabilities])]
|
||||
[:table.table
|
||||
(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])]
|
||||
]))
|
||||
{:component-will-mount #(re-frame/dispatch-sync [::params-change {}]) }))
|
||||
{:component-will-mount #(re-frame/dispatch-sync [::params-change {:date (date->str (local-now) standard)}]) }))
|
||||
|
||||
(defn balance-sheet-page []
|
||||
[side-bar-layout
|
||||
|
||||
Reference in New Issue
Block a user