idea for cash flow linkage. makes invoices use uri parameters.
This commit is contained in:
@@ -1,10 +1,13 @@
|
||||
(ns auto-ap.views.pages.home
|
||||
(:require [auto-ap.views.components.layouts :refer [side-bar-layout]]
|
||||
[re-frame.core :as re-frame]
|
||||
[bidi.bidi :as bidi]
|
||||
[auto-ap.routes :as routes]
|
||||
[auto-ap.subs :as subs]
|
||||
[cljs-time.core :as t]
|
||||
[auto-ap.views.utils :refer [local-now date->str]]
|
||||
[reagent.core :as r]))
|
||||
[auto-ap.views.utils :refer [local-now date->str standard]]
|
||||
[reagent.core :as r]
|
||||
[pushy.core :as pushy]))
|
||||
|
||||
|
||||
(def pie-chart (r/adapt-react-class js/Recharts.PieChart))
|
||||
@@ -47,16 +50,21 @@
|
||||
)
|
||||
|
||||
(defn make-cash-flow-chart [{:keys [width height data] }]
|
||||
(println data)
|
||||
[bar-chart {:width width :height height :data data :fill "#FFFFFF" :stackOffset "sign"}
|
||||
[tool-tip]
|
||||
[bar {:dataKey "effective-balance" :fill (get colors 1) :stackId "a" :name "Effective Balance"}]
|
||||
[bar {:dataKey "outstanding-payments" :fill (get colors 0) :stackId "a" :name "Outstanding Payments"}]
|
||||
[bar {:dataKey "invoices" :fill (get colors 3) :stackId "a" :name "Invoices"}]
|
||||
|
||||
[x-axis {:dataKey "name"}]
|
||||
[y-axis]
|
||||
[legend]]
|
||||
(let [redirect-fn (fn [x]
|
||||
(pushy/set-token! auto-ap.history/history (str (bidi/path-for routes/routes :unpaid-invoices) "?" (get (js->clj x) "query-params")))
|
||||
)]
|
||||
[bar-chart {:width width :height height :data data :fill "#FFFFFF" :stackOffset "sign"}
|
||||
[tool-tip]
|
||||
[bar {:dataKey "effective-balance" :fill (get colors 1) :stackId "a" :name "Effective Balance"
|
||||
:on-click redirect-fn}]
|
||||
[bar {:dataKey "outstanding-payments" :fill (get colors 0) :stackId "a" :name "Outstanding Payments"
|
||||
:on-click redirect-fn}]
|
||||
[bar {:dataKey "invoices" :fill (get colors 3) :stackId "a" :name "Invoices"
|
||||
:on-click redirect-fn}]
|
||||
|
||||
[x-axis {:dataKey "name"}]
|
||||
[y-axis]
|
||||
[legend]])
|
||||
)
|
||||
|
||||
(re-frame/reg-event-db
|
||||
@@ -99,8 +107,6 @@
|
||||
(let [due (if (t/before? (:due invoice) (local-now))
|
||||
(local-now)
|
||||
(:due invoice))]
|
||||
(println due)
|
||||
|
||||
(update result (date->str due)
|
||||
(fn [r] (+ (or r 0.0) (:outstanding-balance invoice))))))
|
||||
{}
|
||||
@@ -113,14 +119,18 @@
|
||||
(reduce
|
||||
(fn [[{:keys [effective-balance] } :as acc] day]
|
||||
(let [invoices-due-today (invoices-due-soon (date->str (t/plus start-date (t/days day))) 0.0)]
|
||||
(conj acc
|
||||
{:name (date->str (t/plus start-date (t/days day)))
|
||||
:effective-balance (- effective-balance invoices-due-today)
|
||||
:invoices (- invoices-due-today)})))
|
||||
(let [today (t/plus start-date (t/days day))]
|
||||
(conj acc
|
||||
{:name (date->str today)
|
||||
:effective-balance (- effective-balance invoices-due-today)
|
||||
:invoices (- invoices-due-today)
|
||||
:query-params (cemerick.url/map->query {:due-range {:start (date->str today standard)
|
||||
:end (date->str today standard)}})}))))
|
||||
(list {:name (date->str start-date)
|
||||
:effective-balance effective-balance
|
||||
:invoices (- (invoices-due-soon (date->str start-date) 0.0))
|
||||
:outstanding-payments (- outstanding-payments)})
|
||||
:outstanding-payments (- outstanding-payments)
|
||||
:query-params (cemerick.url/map->query {:due-range {:end (date->str start-date standard)}})})
|
||||
(range 1 7))))))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
|
||||
@@ -98,14 +98,17 @@
|
||||
::params-change
|
||||
[with-user (re-frame/inject-cofx ::inject/sub [::params])]
|
||||
(fn [{::keys [params] :as cofx} _]
|
||||
(println "params" params)
|
||||
{:db (-> (:db cofx)
|
||||
(assoc-in [:status :loading] true)
|
||||
(assoc-in [::last-params] params))
|
||||
:graphql {:token (-> cofx :db :user)
|
||||
:query-obj (table/query params )
|
||||
:on-success [::received]
|
||||
:on-error [::events/page-failed]}}))
|
||||
:on-error [::events/page-failed]}
|
||||
:set-uri-params (dissoc params
|
||||
:status
|
||||
:client-id
|
||||
:import-status)}))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::unmounted
|
||||
|
||||
Reference in New Issue
Block a user