adding most simple balance sheet report.
This commit is contained in:
113
src/cljs/auto_ap/views/pages/ledger/balance_sheet.cljs
Normal file
113
src/cljs/auto_ap/views/pages/ledger/balance_sheet.cljs
Normal file
@@ -0,0 +1,113 @@
|
||||
(ns auto-ap.views.pages.ledger.balance-sheet
|
||||
(:require [auto-ap.subs :as subs]
|
||||
[auto-ap.views.components.layouts :refer [side-bar-layout]]
|
||||
[goog.string :as gstring]
|
||||
[auto-ap.views.pages.ledger.side-bar :refer [ledger-side-bar]]
|
||||
[auto-ap.views.utils :refer [date->str date-picker bind-field]]
|
||||
[cljs-time.core :as t]
|
||||
[re-frame.core :as re-frame]))
|
||||
|
||||
(re-frame/reg-sub
|
||||
::report
|
||||
(fn [db]
|
||||
(-> db ::report)))
|
||||
|
||||
(re-frame/reg-sub
|
||||
::assets
|
||||
(fn [db]
|
||||
(->> db ::report :balance-sheet-groupings (filter (fn [{:keys [grouping-type]}] (= "Assets" grouping-type))))))
|
||||
|
||||
(re-frame/reg-sub
|
||||
::liabilities
|
||||
(fn [db]
|
||||
(->> db ::report :balance-sheet-groupings (filter (fn [{:keys [grouping-type]}] (= "Liabilities" grouping-type))))))
|
||||
|
||||
(re-frame/reg-event-db
|
||||
::received
|
||||
(fn [db [_ data]]
|
||||
(-> db
|
||||
(assoc ::report (:balance-sheet data))
|
||||
(assoc-in [:status :loading] false))))
|
||||
|
||||
(re-frame/reg-sub
|
||||
::params
|
||||
(fn [db]
|
||||
(-> db ::params)))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::params-change
|
||||
(fn [cofx [_ params]]
|
||||
{:db (-> (:db cofx)
|
||||
(assoc-in [:status :loading] true)
|
||||
(assoc-in [::params] params))
|
||||
:graphql {:token (-> cofx :db :user)
|
||||
: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]]]]]]]}
|
||||
: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]
|
||||
|
||||
[: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" ))]]))])
|
||||
|
||||
(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
|
||||
[:h1.title "Balance Sheet"]
|
||||
[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}]]
|
||||
[:h2.title "Assets"]
|
||||
[grouping @(re-frame/subscribe [::assets])]
|
||||
[:h2.title "Liabilities"]
|
||||
[grouping @(re-frame/subscribe [::liabilities])]
|
||||
]))
|
||||
{:component-will-mount #(re-frame/dispatch-sync [::params-change {}]) }))
|
||||
|
||||
(defn balance-sheet-page []
|
||||
[side-bar-layout
|
||||
{:side-bar [ledger-side-bar]
|
||||
:main [balance-sheet-content]}])
|
||||
Reference in New Issue
Block a user