weekly debits/credits.
This commit is contained in:
@@ -5,9 +5,10 @@
|
||||
[auto-ap.routes :as routes]
|
||||
[auto-ap.subs :as subs]
|
||||
[cljs-time.core :as t]
|
||||
[auto-ap.views.utils :refer [local-now date->str standard]]
|
||||
[auto-ap.views.utils :refer [local-now date->str standard dispatch-event]]
|
||||
[reagent.core :as r]
|
||||
[pushy.core :as pushy]))
|
||||
[pushy.core :as pushy]
|
||||
))
|
||||
|
||||
|
||||
(def pie-chart (r/adapt-react-class js/Recharts.PieChart))
|
||||
@@ -91,11 +92,22 @@
|
||||
(seq cash-flow)
|
||||
(assoc ::cash-flow cash-flow)))))
|
||||
|
||||
(re-frame/reg-event-db
|
||||
::select-cash-flow-range
|
||||
[(re-frame/path ::chart-options)]
|
||||
(fn [chart-options [_ which]]
|
||||
(assoc chart-options :cash-flow-range which)))
|
||||
|
||||
(re-frame/reg-sub
|
||||
::invoice-stats
|
||||
(fn [db]
|
||||
(::invoice-stats db)))
|
||||
|
||||
(re-frame/reg-sub
|
||||
::chart-options
|
||||
(fn [db]
|
||||
(merge {:cash-flow-range :seven-days} (::chart-options db))))
|
||||
|
||||
(re-frame/reg-sub
|
||||
::top-expense-categories
|
||||
(fn [db]
|
||||
@@ -113,9 +125,16 @@
|
||||
pairs))
|
||||
|
||||
(re-frame/reg-sub
|
||||
::cash-flow
|
||||
::cash-flow-data
|
||||
(fn [db]
|
||||
(let [{:keys [outstanding-payments beginning-balance invoices-due-soon upcoming-credits upcoming-debits]} (::cash-flow db)
|
||||
(::cash-flow db)))
|
||||
|
||||
(re-frame/reg-sub
|
||||
::cash-flow
|
||||
:<- [::chart-options]
|
||||
:<- [::cash-flow-data]
|
||||
(fn [[chart-options cash-flow-data]]
|
||||
(let [{:keys [outstanding-payments beginning-balance invoices-due-soon upcoming-credits upcoming-debits]} cash-flow-data
|
||||
invoices-due-soon (sum-by-date (map (fn [i] [(:due i) (:outstanding-balance i)]) invoices-due-soon))
|
||||
upcoming-credits (sum-by-date (map (fn [i] [(:date i) (:amount i)]) upcoming-credits))
|
||||
upcoming-debits (sum-by-date (map (fn [i] [(:date i) (:amount i)]) upcoming-debits))
|
||||
@@ -148,7 +167,9 @@
|
||||
:debits (upcoming-debits (date->str start-date) 0.0)
|
||||
:outstanding-payments (- outstanding-payments)
|
||||
:query-params (cemerick.url/map->query {:due-range {:end (date->str start-date standard)}})})
|
||||
(range 1 7))))))
|
||||
(if (= :seven-days (:cash-flow-range chart-options))
|
||||
(range 1 7)
|
||||
(range 1 31)))))))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::mounted
|
||||
@@ -171,7 +192,8 @@
|
||||
:on-success [::received]}}))
|
||||
|
||||
(defn home-content []
|
||||
(let [client-id (-> @(re-frame/subscribe [::subs/client]) :id)]
|
||||
(let [client-id (-> @(re-frame/subscribe [::subs/client]) :id)
|
||||
chart-options @(re-frame/subscribe [::chart-options])]
|
||||
^{:key client-id}
|
||||
[side-bar-layout {:side-bar [:div]
|
||||
:main [:div [:h1.title "Home"]
|
||||
@@ -184,6 +206,17 @@
|
||||
@(re-frame/subscribe [::invoice-stats]))})
|
||||
|
||||
[:h1.title.is-4 "Cash Flow"]
|
||||
[:div.buttons.has-addons
|
||||
[:a.button {:class (when (= :seven-days (:cash-flow-range chart-options))
|
||||
["is-info" "is-selected"])
|
||||
:on-click (dispatch-event [::select-cash-flow-range :seven-days])}
|
||||
"7 days"]
|
||||
[:a.button {:class (when (= :thirty-days (:cash-flow-range chart-options))
|
||||
["is-info" "is-selected"])
|
||||
:on-click (dispatch-event [::select-cash-flow-range :thirty-days])}
|
||||
"30 days"]]
|
||||
|
||||
|
||||
(make-cash-flow-chart {:width 800 :height 500
|
||||
:data (clj->js @(re-frame/subscribe [::cash-flow]))})]}]))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user