profit and loss screen.

This commit is contained in:
Bryce Covert
2019-04-13 22:04:29 -07:00
parent e79c0e1575
commit 7f6df3865c
4 changed files with 146 additions and 77 deletions

View File

@@ -296,13 +296,7 @@ nav.navbar .navbar-item.is-active {
color: #AAAAAA; color: #AAAAAA;
text-decoration: none; text-decoration: none;
} }
.is-grouped .button {
background-image: linear-gradient(#F8F8F8, #F1F1F1);
}
.is-grouped .button .fa {
font-size: 15px;
color: #AAAAAA;
}
.inbox-messages .card { .inbox-messages .card {
width: 100%; width: 100%;
} }

View File

@@ -150,12 +150,9 @@
:where ['[?e :invoice/total]]} :where ['[?e :invoice/total]]}
:args [(d/db conn)]})) :args [(d/db conn)]}))
z (->> invoice-ids z (->> invoice-ids
(mapv #(ledger/entity-change->ledger (d/db conn) [:invoice %])))] (mapv #(vector (ledger/entity-change->ledger (d/db conn) [:invoice %]))))]
z)) z))
#_(do @(d/transact (d/connect auto-ap.datomic/uri)
(bulk-load-invoice-ledger (d/connect auto-ap.datomic/uri)))
(println "test"))
(defn bulk-load-transaction-ledger [conn] (defn bulk-load-transaction-ledger [conn]
(let [transaction-ids (map first (d/query {:query {:find '[?e] (let [transaction-ids (map first (d/query {:query {:find '[?e]

View File

@@ -4,7 +4,7 @@
[goog.string :as gstring] [goog.string :as gstring]
[auto-ap.utils :refer [dollars-0?]] [auto-ap.utils :refer [dollars-0?]]
[auto-ap.views.pages.ledger.side-bar :refer [ledger-side-bar]] [auto-ap.views.pages.ledger.side-bar :refer [ledger-side-bar]]
[auto-ap.views.utils :refer [date->str date-picker bind-field standard]] [auto-ap.views.utils :refer [date->str date-picker bind-field standard dispatch-event local-now]]
[cljs-time.core :as t] [cljs-time.core :as t]
[re-frame.core :as re-frame])) [re-frame.core :as re-frame]))
@@ -14,6 +14,11 @@
(fn [db] (fn [db]
(-> db ::report))) (-> db ::report)))
(re-frame/reg-sub
::loading
(fn [db]
(-> db ::loading)))
(re-frame/reg-sub (re-frame/reg-sub
::assets ::assets
(fn [db] (fn [db]
@@ -32,10 +37,9 @@
(re-frame/reg-event-db (re-frame/reg-event-db
::received ::received
(fn [db [_ data]] (fn [db [_ data]]
(println (:profit-and-loss data))
(-> db (-> db
(assoc ::report (:profit-and-loss data)) (assoc ::report (:profit-and-loss data))
(assoc-in [:status :loading] false)))) (assoc-in [::loading] false))))
(re-frame/reg-sub (re-frame/reg-sub
::params ::params
@@ -46,45 +50,57 @@
::params-change ::params-change
(fn [cofx [_ params]] (fn [cofx [_ params]]
{:db (-> (:db cofx) {:db (-> (:db cofx)
(assoc-in [:status :loading] true) (assoc-in [::loading] true)
(assoc-in [::params] params)) (assoc-in [::params] params))
:graphql {:token (-> cofx :db :user) :graphql {:token (-> cofx :db :user)
:query-obj {:venia/queries [[:profit-and-loss :query-obj {:venia/queries [[:profit-and-loss
(assoc params {:client-id (:id @(re-frame/subscribe [::subs/client]))
:client-id (:id @(re-frame/subscribe [::subs/client]))) :from-date (:from-date params)
:to-date (:to-date params)}
[[:balance-sheet-groupings [:grouping-type :name [:accounts [:name :amount]]]]]]]} [[:balance-sheet-groupings [:grouping-type :name [:accounts [:name :amount]]]]]]]}
:on-success [::received]}})) :on-success [::received]}}))
(re-frame/reg-event-fx (re-frame/reg-event-fx
::date-picked ::date-picked
(fn [cofx [_ f date]] (fn [cofx [_ f date]]
(println date)
{:dispatch [::params-change (assoc-in @(re-frame/subscribe [::params]) {:dispatch [::params-change (assoc-in @(re-frame/subscribe [::params])
f f
date)]})) date)]}))
(re-frame/reg-event-fx
::range-selected
(fn [cofx [_ from to selected]]
{:dispatch [::params-change (assoc @(re-frame/subscribe [::params])
:from-date from
:to-date to
:selected selected)]}))
(defn grouping [groupings] (defn grouping [groupings]
[:table.table [:table.table
(for [grouping groupings] [:tbody
(list (for [grouping groupings]
[:tr [:td {:col-span "2"} "----" (:name grouping) "----"]] ^{:key "items"}
(for [account (:accounts grouping) (list
^{:key "heading"}
:when [(not (dollars-0? (js/parseFloat (:amount account))))]] [:tr [:td {:col-span "2"} "----" (:name grouping) "----"]]
(for [account (:accounts grouping)]
[:tr
[:td (:name account) ] (when (not (dollars-0? (js/parseFloat (:amount account))))
[:td.has-text-right (gstring/format "$%.2f" (:amount account))]]) ^{:key (:name account)}
[:tr
[:tr [:td "----" (:name grouping) "----"] [:td (:name account) ]
[:td.has-text-right [:td.has-text-right (gstring/format "$%.2f" (:amount account))]]))
(->> grouping
:accounts ^{:key "footing"}
(map :amount) [:tr [:td "----" (:name grouping) "----"]
(map #(js/parseFloat %)) [:td.has-text-right
(reduce + 0) (->> grouping
(gstring/format "$%.2f" ))]]))]) :accounts
(map :amount)
(map #(js/parseFloat %))
(reduce + 0)
(gstring/format "$%.2f" ))]]))]])
(def profit-and-loss-content (def profit-and-loss-content
(with-meta (with-meta
@@ -92,49 +108,107 @@
(let [current-client @(re-frame/subscribe [::subs/client]) (let [current-client @(re-frame/subscribe [::subs/client])
user @(re-frame/subscribe [::subs/user]) user @(re-frame/subscribe [::subs/user])
params @(re-frame/subscribe [::params])] params @(re-frame/subscribe [::params])]
[:div [:div
[:h1.title "Profit and Loss"] [:h1.title "Profit and Loss"]
[:div.field [:h2.title.is-4 "Range"]
[:p.help "From"] [:div
[bind-field [:div.field.is-grouped
[date-picker {:class-name "input" [:p.control
:class "input" [:a.button
:format-week-number (fn [] "") {:class (when (= (:selected params) "Last week") "is-active")
:previous-month-button-label "" :on-click (dispatch-event [::range-selected
:placeholder "mm/dd/yyyy" (date->str (t/minus (local-now) (t/period :days 7)) standard)
:next-month-button-label "" (date->str (local-now) standard)
:next-month-label "" "Last week"])}
:type "date" "Last week"]]
:field [:from-date] [:p.control
:event [::date-picked] [:a.button
:popper-props (clj->js {:placement "right"}) {:class (when (= (:selected params) "Week to date") "is-active")
:subscription params}]]] :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}]]]
[:div.field [:p.control
[:p.help "To"] [:p.help "To"]
[bind-field [bind-field
[date-picker {:class-name "input" [date-picker {:class-name "input"
:class "input" :class "input"
:format-week-number (fn [] "") :format-week-number (fn [] "")
:previous-month-button-label "" :previous-month-button-label ""
:placeholder "mm/dd/yyyy" :placeholder "mm/dd/yyyy"
:next-month-button-label "" :next-month-button-label ""
:next-month-label "" :next-month-label ""
:type "date" :type "date"
:field [:to-date] :field [:to-date]
:event [::date-picked] :event [::date-picked]
:popper-props (clj->js {:placement "right"}) :popper-props (clj->js {:placement "right"})
:subscription params}]]] :subscription params}]]]]
(if @(re-frame/subscribe [::loading])
[:h2.title "Assets"] [:div [:i.icon.fa.fa-spin.fa-spinner]]
[grouping @(re-frame/subscribe [::assets])] [:div
[:h2.title "Expenses"] [:h2.title "Assets"]
[grouping @(re-frame/subscribe [::expenses])] [grouping @(re-frame/subscribe [::assets])]
[:h2.title "Liabilities"] [:h2.title "Expenses"]
[grouping @(re-frame/subscribe [::liabilities])] [grouping @(re-frame/subscribe [::expenses])]
[:h2.title "Liabilities"]
[grouping @(re-frame/subscribe [::liabilities])]])
])) ]))
{:component-will-mount #(re-frame/dispatch-sync [::params-change {:from-date (date->str (t/minus (t/now) (t/period :years 1)) standard) {:component-will-mount #(re-frame/dispatch-sync [::params-change {:from-date (date->str (t/minus (local-now) (t/period :years 1)) standard)
:to-date (date->str (t/now) standard)}]) })) :to-date (date->str (local-now) standard)}]) }))
(defn profit-and-loss-page [] (defn profit-and-loss-page []
[side-bar-layout [side-bar-layout

View File

@@ -9,7 +9,8 @@
[auto-ap.events :as events] [auto-ap.events :as events]
[auto-ap.subs :as subs] [auto-ap.subs :as subs]
[cljs-time.format :as format] [cljs-time.format :as format]
[goog.i18n.NumberFormat.Format]) [goog.i18n.NumberFormat.Format]
[cljs-time.core :as t])
(:import (:import
(goog.i18n NumberFormat) (goog.i18n NumberFormat)
(goog.i18n.NumberFormat Format))) (goog.i18n.NumberFormat Format)))
@@ -184,3 +185,6 @@
(if (or @final-state visible?) (if (or @final-state visible?)
(first children) (first children)
[:span])]))) [:span])])))
(defn local-now []
(t/to-default-time-zone (t/now)))