Revert "Prep to select more than 1 client"
This reverts commit 085486043f.
This commit is contained in:
@@ -554,7 +554,6 @@
|
|||||||
|
|
||||||
:profit_and_loss {:type :profit_and_loss_report
|
:profit_and_loss {:type :profit_and_loss_report
|
||||||
:args {:client_id {:type :id}
|
:args {:client_id {:type :id}
|
||||||
:client_ids {:type '(list :id)}
|
|
||||||
:periods {:type '(list :date_range)}}
|
:periods {:type '(list :date_range)}}
|
||||||
:resolve :get-profit-and-loss}
|
:resolve :get-profit-and-loss}
|
||||||
|
|
||||||
|
|||||||
@@ -183,14 +183,9 @@
|
|||||||
|
|
||||||
(defn get-profit-and-loss [context args value]
|
(defn get-profit-and-loss [context args value]
|
||||||
(let [client-id (:client_id args)
|
(let [client-id (:client_id args)
|
||||||
client-ids (or (some-> client-id vector)
|
_ (assert-can-see-client (:id context) client-id)
|
||||||
(:client_ids args))
|
all-ledger-entries (full-ledger-for-client client-id)
|
||||||
_ (when (not (seq client-ids))
|
lookup-account (build-account-lookup client-id)]
|
||||||
(throw (ex-info "Please select a client." {:validation-error "Please select a client."})))
|
|
||||||
_ (doseq [client-id client-ids]
|
|
||||||
(assert-can-see-client (:id context) client-id))
|
|
||||||
all-ledger-entries (full-ledger-for-client (first client-ids))
|
|
||||||
lookup-account (build-account-lookup (first client-ids))]
|
|
||||||
(->graphql
|
(->graphql
|
||||||
{:periods (reduce (fn [acc {:keys [start end]}]
|
{:periods (reduce (fn [acc {:keys [start end]}]
|
||||||
(conj acc
|
(conj acc
|
||||||
|
|||||||
@@ -7,9 +7,8 @@
|
|||||||
[auto-ap.utils :refer [dollars-0? by ]]
|
[auto-ap.utils :refer [dollars-0? by ]]
|
||||||
[auto-ap.forms :as forms]
|
[auto-ap.forms :as forms]
|
||||||
[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.components.typeahead :refer [typeahead-v3]]
|
|
||||||
[auto-ap.views.components.modal :as modal]
|
[auto-ap.views.components.modal :as modal]
|
||||||
[auto-ap.views.utils :refer [date->str date-picker date-picker-friendly bind-field standard pretty dispatch-event local-today ->% ->$ str->date with-user dispatch-value-change query-params]]
|
[auto-ap.views.utils :refer [date->str date-picker bind-field standard pretty dispatch-event local-today ->% ->$ str->date with-user dispatch-value-change query-params]]
|
||||||
[cljs-time.core :as t]
|
[cljs-time.core :as t]
|
||||||
[re-frame.core :as re-frame]
|
[re-frame.core :as re-frame]
|
||||||
[auto-ap.status :as status]
|
[auto-ap.status :as status]
|
||||||
@@ -45,12 +44,9 @@
|
|||||||
;; SUBS
|
;; SUBS
|
||||||
(re-frame/reg-sub
|
(re-frame/reg-sub
|
||||||
::locations
|
::locations
|
||||||
|
|
||||||
:<- [::forms/form ::form]
|
|
||||||
|
|
||||||
(fn [db]
|
(fn [db]
|
||||||
(->> db
|
(->> db
|
||||||
:report
|
::report
|
||||||
:periods
|
:periods
|
||||||
(mapcat :accounts)
|
(mapcat :accounts)
|
||||||
(filter (comp in-range? :numeric-code))
|
(filter (comp in-range? :numeric-code))
|
||||||
@@ -67,6 +63,11 @@
|
|||||||
"ZZZZZZ"
|
"ZZZZZZ"
|
||||||
x))))))
|
x))))))
|
||||||
|
|
||||||
|
(re-frame/reg-sub
|
||||||
|
::report
|
||||||
|
(fn [db]
|
||||||
|
(-> db ::report)))
|
||||||
|
|
||||||
(re-frame/reg-sub
|
(re-frame/reg-sub
|
||||||
::error
|
::error
|
||||||
(fn [db]
|
(fn [db]
|
||||||
@@ -80,10 +81,9 @@
|
|||||||
|
|
||||||
(re-frame/reg-sub
|
(re-frame/reg-sub
|
||||||
::period-accounts
|
::period-accounts
|
||||||
:<- [::forms/form ::form]
|
|
||||||
(fn [db [_ which type only-location]]
|
(fn [db [_ which type only-location]]
|
||||||
|
|
||||||
(->> (get-in db [:report :periods which :accounts])
|
(->> (get-in db [::report :periods which :accounts])
|
||||||
(map #(update % :amount js/parseFloat))
|
(map #(update % :amount js/parseFloat))
|
||||||
(filter (fn [{:keys [account-type location numeric-code]}]
|
(filter (fn [{:keys [account-type location numeric-code]}]
|
||||||
(and (or (nil? only-location)
|
(and (or (nil? only-location)
|
||||||
@@ -93,10 +93,9 @@
|
|||||||
|
|
||||||
(re-frame/reg-sub
|
(re-frame/reg-sub
|
||||||
::uncategorized-accounts
|
::uncategorized-accounts
|
||||||
:<- [::forms/form ::form]
|
|
||||||
(fn [db [_ ]]
|
(fn [db [_ ]]
|
||||||
|
|
||||||
(->> (get-in db [:report :periods ])
|
(->> (get-in db [::report :periods ])
|
||||||
(mapcat :accounts)
|
(mapcat :accounts)
|
||||||
(map #(update % :amount js/parseFloat))
|
(map #(update % :amount js/parseFloat))
|
||||||
(filter (fn [{:keys [account-type location numeric-code]}]
|
(filter (fn [{:keys [account-type location numeric-code]}]
|
||||||
@@ -122,7 +121,6 @@
|
|||||||
|
|
||||||
(re-frame/reg-sub
|
(re-frame/reg-sub
|
||||||
::all-accounts
|
::all-accounts
|
||||||
:<- [::forms/form ::form]
|
|
||||||
(fn [db [_ which type only-location]]
|
(fn [db [_ which type only-location]]
|
||||||
(transduce
|
(transduce
|
||||||
(comp
|
(comp
|
||||||
@@ -131,13 +129,12 @@
|
|||||||
|
|
||||||
conj
|
conj
|
||||||
[]
|
[]
|
||||||
(get-in db [:report :periods]))))
|
(get-in db [::report :periods]))))
|
||||||
|
|
||||||
(re-frame/reg-event-db
|
(re-frame/reg-event-db
|
||||||
::received
|
::received
|
||||||
[(forms/in-form ::form)]
|
|
||||||
(fn [db [_ data]]
|
(fn [db [_ data]]
|
||||||
(-> db (assoc :report (:profit-and-loss data)))))
|
(-> db (assoc ::report (:profit-and-loss data)))))
|
||||||
|
|
||||||
(re-frame/reg-sub
|
(re-frame/reg-sub
|
||||||
::params
|
::params
|
||||||
@@ -162,53 +159,68 @@
|
|||||||
(assoc db ::ledger-list-active? false)))
|
(assoc db ::ledger-list-active? false)))
|
||||||
|
|
||||||
(re-frame/reg-event-fx
|
(re-frame/reg-event-fx
|
||||||
::params-change
|
::mounted
|
||||||
[with-user (forms/in-form ::form)]
|
(fn [{:keys [db]}]
|
||||||
(fn [{:keys [db user] :as cofx}]
|
(let [qp (query-params)]
|
||||||
(let [c @(re-frame/subscribe [::subs/client])]
|
(if (:periods qp)
|
||||||
(cond-> {:graphql {:token user
|
(let [periods (mapv (fn [[start end title]]
|
||||||
:owns-state {:single ::page}
|
[
|
||||||
:query-obj {:venia/queries [[:profit-and-loss
|
(str->date start standard)
|
||||||
{:client-ids (or (some-> (:id c) vector)
|
(str->date end standard)
|
||||||
(some-> (:id (:client (:data db)))
|
title])
|
||||||
vector))
|
(:periods qp))]
|
||||||
:periods (mapv (fn [[start end] ] {:start (date->str start standard) :end (date->str end standard)} )
|
{:dispatch [::range-selected periods (:include-deltas qp) nil]})
|
||||||
(:periods (:data db)))}
|
{:dispatch [::range-selected (and-last-year [(t/minus (local-today) (t/period :years 1)) (local-today)]) true nil]}))))
|
||||||
[[:periods [[:accounts [:name :amount :account-type :id :count :numeric-code :location]]]]]]]}
|
|
||||||
:on-success [::received]}
|
|
||||||
:set-uri-params {:periods (mapv (fn [[start end title]]
|
|
||||||
[(date->str start standard)
|
|
||||||
(date->str end standard)])
|
|
||||||
(:periods (:data db)))
|
|
||||||
:client (select-keys (:client (:data db))
|
|
||||||
[:name :id])}
|
|
||||||
:db (dissoc db :report)}))))
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
(re-frame/reg-event-db
|
(re-frame/reg-event-db
|
||||||
::change
|
::period-inputs-change
|
||||||
(forms/change-handler ::form
|
(fn [db [_ field value]]
|
||||||
(fn [data field value]
|
(assoc-in db (into [::period-inputs ] field) value)))
|
||||||
(cond
|
|
||||||
(= [:periods] field)
|
|
||||||
[field (mapv (fn [period]
|
|
||||||
(mapv
|
|
||||||
(fn [dt]
|
|
||||||
(str->date dt standard))
|
|
||||||
period))
|
|
||||||
value)]
|
|
||||||
|
|
||||||
(and (= :periods (first field))
|
(re-frame/reg-event-fx
|
||||||
(= 2 (count field)))
|
::params-change
|
||||||
[field value] ;;already serialized
|
(fn [cofx [_ params]]
|
||||||
|
(let [c @(re-frame/subscribe [::subs/client])]
|
||||||
|
(cond-> {:db (-> (:db cofx)
|
||||||
|
(assoc-in [::params] params)
|
||||||
|
(dissoc ::report))
|
||||||
|
:set-uri-params (update params
|
||||||
|
:periods
|
||||||
|
(fn [p]
|
||||||
|
(mapv (fn [[start end title]]
|
||||||
|
[(date->str start standard)
|
||||||
|
(date->str end standard)
|
||||||
|
title]
|
||||||
|
) p)))}
|
||||||
|
c (assoc :graphql (when @(re-frame/subscribe [::subs/client])
|
||||||
|
{:token (-> cofx :db :user)
|
||||||
|
:owns-state {:single ::page}
|
||||||
|
:query-obj {:venia/queries [[:profit-and-loss
|
||||||
|
{:client-id (:id c)
|
||||||
|
:periods (mapv (fn [[start end] ] {:start (date->str start standard) :end (date->str end standard)} )
|
||||||
|
(:periods params))}
|
||||||
|
[[:periods [[:accounts [:name :amount :account-type :id :count :numeric-code :location]]]]]]]}
|
||||||
|
:on-success [::received]}))))))
|
||||||
|
|
||||||
(= :periods (first field)) [field (str->date value standard) ]
|
|
||||||
|
|
||||||
:else nil)
|
|
||||||
)))
|
|
||||||
|
|
||||||
|
(re-frame/reg-event-fx
|
||||||
|
::date-picked
|
||||||
|
(fn [cofx [_ [_ period which] date]]
|
||||||
|
{:dispatch [::range-selected (assoc-in @(re-frame/subscribe [::periods]) [period which] (str->date date standard)) nil nil]}))
|
||||||
|
|
||||||
|
(re-frame/reg-event-fx
|
||||||
|
::range-selected
|
||||||
|
(fn [{:keys [db]} [_ periods include-deltas selected]]
|
||||||
|
{:dispatch [::params-change (cond-> @(re-frame/subscribe [::params])
|
||||||
|
true (assoc
|
||||||
|
:periods periods
|
||||||
|
:include-deltas include-deltas
|
||||||
|
:selected selected)
|
||||||
|
(not (nil? include-deltas)) (assoc :include-deltas include-deltas))]
|
||||||
|
:db (assoc db ::periods periods)}))
|
||||||
|
|
||||||
|
|
||||||
(defn data-params->query-params [params]
|
(defn data-params->query-params [params]
|
||||||
@@ -276,7 +288,6 @@
|
|||||||
:can-submit [::can-submit-period-form]
|
:can-submit [::can-submit-period-form]
|
||||||
:id ::period-form}))
|
:id ::period-form}))
|
||||||
|
|
||||||
;; 877 w fremont ave suite i4
|
|
||||||
(defn change-period-body [idx which]
|
(defn change-period-body [idx which]
|
||||||
(let [{:keys [data active? error id]} @(re-frame/subscribe [::forms/form ::period-form])
|
(let [{:keys [data active? error id]} @(re-frame/subscribe [::forms/form ::period-form])
|
||||||
{:keys [form-inline horizontal-field field raw-field error-notification submit-button]} change-period-form]
|
{:keys [form-inline horizontal-field field raw-field error-notification submit-button]} change-period-form]
|
||||||
@@ -308,23 +319,23 @@
|
|||||||
}] )])))
|
}] )])))
|
||||||
(re-frame/reg-event-fx
|
(re-frame/reg-event-fx
|
||||||
::period-change-submitted
|
::period-change-submitted
|
||||||
(fn [{:keys [db]} [_ idx [start end] :as z]]
|
(fn [{:keys [db]} [_ idx which]]
|
||||||
{ :db (-> db (forms/stop-form ::period-form))
|
{ :db (-> db (forms/stop-form ::period-form)
|
||||||
|
(assoc-in [::periods idx] which))
|
||||||
:dispatch-n [[::modal/modal-closed ]
|
:dispatch-n [[::modal/modal-closed ]
|
||||||
[::change [:periods idx ] [start end]]]}))
|
[::range-selected (assoc (::periods db) idx which) nil nil]]}))
|
||||||
|
|
||||||
(re-frame/reg-event-fx
|
(re-frame/reg-event-fx
|
||||||
::period-removed
|
::period-removed
|
||||||
(fn [{:keys [db]} [_ idx which]]
|
(fn [{:keys [db]} [_ idx which]]
|
||||||
{ :db (-> db (forms/stop-form ::period-form)
|
{ :db (-> db (forms/stop-form ::period-form)
|
||||||
(update-in [::forms/forms ::form :data :periods]
|
(update ::periods (fn [ps]
|
||||||
(fn [ps]
|
(->> ps
|
||||||
(->> ps
|
(map vector (range) )
|
||||||
(map vector (range) )
|
(filter (fn [[i _]]
|
||||||
(filter (fn [[i _]]
|
(not= i idx)))
|
||||||
(not= i idx)))
|
(map second)
|
||||||
(map second)
|
(into [])))))
|
||||||
(into [])))))
|
|
||||||
:dispatch [::modal/modal-closed ]}))
|
:dispatch [::modal/modal-closed ]}))
|
||||||
|
|
||||||
(defn change-period-foot [idx which]
|
(defn change-period-foot [idx which]
|
||||||
@@ -598,223 +609,249 @@
|
|||||||
|
|
||||||
]))
|
]))
|
||||||
|
|
||||||
(re-frame/reg-sub
|
|
||||||
::can-submit
|
|
||||||
(fn [db]
|
|
||||||
true))
|
|
||||||
|
|
||||||
(def pnl-form (forms/vertical-form {:can-submit [::can-submit]
|
|
||||||
:change-event [::change]
|
|
||||||
:submit-event [::params-change]
|
|
||||||
:id ::form}))
|
|
||||||
|
|
||||||
(defn profit-and-loss-content []
|
(def profit-and-loss-content
|
||||||
(let [current-client @(re-frame/subscribe [::subs/client])
|
(with-meta
|
||||||
clients @(re-frame/subscribe [::subs/clients])
|
(fn []
|
||||||
user @(re-frame/subscribe [::subs/user])
|
(let [current-client @(re-frame/subscribe [::subs/client])
|
||||||
status @(re-frame/subscribe [::status/single ::page])
|
user @(re-frame/subscribe [::subs/user])
|
||||||
params @(re-frame/subscribe [::params])
|
status @(re-frame/subscribe [::status/single ::page])
|
||||||
unresolved-accounts @(re-frame/subscribe [::uncategorized-accounts])
|
params @(re-frame/subscribe [::params])
|
||||||
{:keys [data report active? error id]} @(re-frame/subscribe [::forms/form ::form])
|
period-inputs @(re-frame/subscribe [::period-inputs])
|
||||||
{:keys [form-inline field raw-field error-notification submit-button ]} pnl-form
|
periods @(re-frame/subscribe [::periods])
|
||||||
periods (:periods data)]
|
unresolved-accounts @(re-frame/subscribe [::uncategorized-accounts]) ]
|
||||||
(when data
|
|
||||||
(form-inline {}
|
|
||||||
[:div
|
|
||||||
[:h1.title "Profit and Loss - " (:name current-client)]
|
|
||||||
[status/status-notification {:statuses [[::status/single ::page]]}]
|
|
||||||
[:div.report-controls
|
|
||||||
(when-not current-client
|
|
||||||
[:<>
|
|
||||||
[:h2.title.is-4 "Entities"]
|
|
||||||
(raw-field
|
|
||||||
[typeahead-v3 {:entities @(re-frame/subscribe [::subs/clients])
|
|
||||||
:entity->text :name
|
|
||||||
:type "typeahead-v3"
|
|
||||||
:field [:client]}])])
|
|
||||||
[:h2.title.is-4 "Range"]
|
|
||||||
[:div
|
|
||||||
[:div.field.is-grouped
|
|
||||||
[:div.control
|
|
||||||
[:div.field.has-addons
|
|
||||||
[:div.control
|
|
||||||
(raw-field
|
|
||||||
[date-picker-friendly {:placeholder "End date"
|
|
||||||
:type "date"
|
|
||||||
:field [:thirteen-periods-end]}])]
|
|
||||||
[:div.control
|
|
||||||
[:a.button
|
|
||||||
{:class (when (= (:selected params) "13 periods") "is-active")
|
|
||||||
:on-click (dispatch-event
|
|
||||||
[::forms/change ::form
|
|
||||||
[:periods]
|
|
||||||
(let [today (or (some-> (:thirteen-periods-end data) (str->date standard))
|
|
||||||
(local-today))]
|
|
||||||
(into
|
|
||||||
[[(t/plus (t/minus today (t/weeks (* 13 4)))
|
|
||||||
(t/days 1))
|
|
||||||
today
|
|
||||||
"Total"]]
|
|
||||||
(for [i (range 13)]
|
|
||||||
[(t/plus (t/minus today (t/weeks (* (inc i) 4)))
|
|
||||||
(t/days 1))
|
|
||||||
(t/minus today (t/weeks (* i 4)))])))])}
|
|
||||||
"13 periods"]]]]
|
|
||||||
|
|
||||||
[:div.control
|
(if-not current-client
|
||||||
[:div.field.has-addons
|
[:div
|
||||||
[:div.control
|
[:h1.title "Profit and Loss " ]
|
||||||
(raw-field
|
[:h2.title.is-4 "Please choose a client first"]]
|
||||||
[date-picker-friendly {:placeholder "End date"
|
|
||||||
:type "date"
|
|
||||||
:field [:twelve-periods-end]}])
|
|
||||||
]
|
|
||||||
[:div.control
|
|
||||||
[:a.button
|
|
||||||
{:class (when (= (:selected params) "13 periods") "is-active")
|
|
||||||
:on-click (dispatch-event
|
|
||||||
[::forms/change ::form
|
|
||||||
[:periods]
|
|
||||||
(let [end-date (or (some-> (:twelve-periods-end data) (str->date standard))
|
|
||||||
(local-today))
|
|
||||||
this-month (t/local-date (t/year end-date)
|
|
||||||
(t/month end-date)
|
|
||||||
1)
|
|
||||||
]
|
|
||||||
(into
|
|
||||||
[[(t/minus this-month (t/months 11))
|
|
||||||
(t/minus (t/plus this-month (t/months 1))
|
|
||||||
(t/days 1))
|
|
||||||
"Total"]]
|
|
||||||
(for [i (range 12)]
|
|
||||||
[(t/minus this-month (t/months (- 11 i)))
|
|
||||||
(t/minus (t/minus this-month (t/months (- 10 i)))
|
|
||||||
(t/days 1))])))])}
|
|
||||||
"12 months"]]]]
|
|
||||||
|
|
||||||
[:div.control
|
[:div
|
||||||
[:a.button
|
[:h1.title "Profit and Loss - " (:name current-client)]
|
||||||
{:class (when (= (:selected params) "Last week") "is-active")
|
[status/status-notification {:statuses [[::status/single ::page]]}]
|
||||||
:on-click (dispatch-event
|
[:div.report-controls
|
||||||
[::forms/change ::form
|
[:h2.title.is-4 "Range"]
|
||||||
[:periods]
|
[:div
|
||||||
(let [last-sunday (loop [current (local-today)]
|
[:div.field.is-grouped
|
||||||
(if (= 7 (t/day-of-week current))
|
[:div.control
|
||||||
current
|
[:div.field.has-addons
|
||||||
(recur (t/minus current (t/period :days 1)))))]
|
[:div.control
|
||||||
|
[bind-field
|
||||||
|
[date-picker {:class-name "input"
|
||||||
|
:class "input"
|
||||||
|
:format-week-number (fn [] "")
|
||||||
|
:previous-month-button-label ""
|
||||||
|
:placeholder "End date"
|
||||||
|
:next-month-button-label ""
|
||||||
|
:next-month-label ""
|
||||||
|
:type "date"
|
||||||
|
:field [:thirteen-periods-end]
|
||||||
|
:subscription period-inputs
|
||||||
|
:event [::period-inputs-change]}]]]
|
||||||
|
[:div.control
|
||||||
|
[:a.button
|
||||||
|
{:class (when (= (:selected params) "13 periods") "is-active")
|
||||||
|
:on-click (dispatch-event
|
||||||
|
[::range-selected
|
||||||
|
(let [today (or (some-> (:thirteen-periods-end period-inputs) (str->date standard))
|
||||||
|
(local-today))]
|
||||||
|
(into
|
||||||
|
[[(t/plus (t/minus today (t/weeks (* 13 4)))
|
||||||
|
(t/days 1))
|
||||||
|
today
|
||||||
|
"Total"]]
|
||||||
|
(for [i (range 13)]
|
||||||
|
[(t/plus (t/minus today (t/weeks (* (inc i) 4)))
|
||||||
|
(t/days 1))
|
||||||
|
(t/minus today (t/weeks (* i 4)))])))
|
||||||
|
|
||||||
(and-last-year [(t/minus last-sunday (t/period :days 6)) last-sunday]))])}
|
false
|
||||||
"Last week"]]
|
"13 periods"])}
|
||||||
[:div.control
|
"13 periods"]]]]
|
||||||
[:a.button
|
|
||||||
{:class (when (= (:selected params) "Week to date") "is-active")
|
|
||||||
:on-click (dispatch-event
|
|
||||||
[::forms/change ::form
|
|
||||||
[:periods]
|
|
||||||
(and-last-year [(loop [current (local-today)]
|
|
||||||
(if (= 1 (t/day-of-week current))
|
|
||||||
current
|
|
||||||
(recur (t/minus current (t/period :days 1)))))
|
|
||||||
(local-today)])])}
|
|
||||||
"Week to date"]]
|
|
||||||
[:div.control
|
|
||||||
[:a.button
|
|
||||||
{:class (when (= (:selected params) "Last Month") "is-active")
|
|
||||||
:on-click (dispatch-event
|
|
||||||
|
|
||||||
[::forms/change ::form
|
[:div.control
|
||||||
[:periods]
|
[:div.field.has-addons
|
||||||
(and-last-year [(t/minus (t/local-date (t/year (local-today))
|
[:div.control
|
||||||
(t/month (local-today))
|
[bind-field
|
||||||
1)
|
[date-picker {:class-name "input"
|
||||||
(t/period :months 1))
|
:class "input"
|
||||||
(t/minus (t/local-date (t/year (local-today))
|
:format-week-number (fn [] "")
|
||||||
(t/month (local-today))
|
:previous-month-button-label ""
|
||||||
1)
|
:placeholder "End date"
|
||||||
(t/period :days 1))])])}
|
:next-month-button-label ""
|
||||||
"Last Month"]]
|
:next-month-label ""
|
||||||
[:div.control
|
:type "date"
|
||||||
[:a.button
|
:field [:twelve-periods-end]
|
||||||
{:class (when (= (:selected params) "Month to date") "is-active")
|
:subscription period-inputs
|
||||||
:on-click (dispatch-event
|
:event [::period-inputs-change]}]]]
|
||||||
[::forms/change ::form
|
[:div.control
|
||||||
[:periods]
|
[:a.button
|
||||||
(and-last-year [(t/local-date (t/year (local-today))
|
{:class (when (= (:selected params) "13 periods") "is-active")
|
||||||
(t/month (local-today))
|
:on-click (dispatch-event
|
||||||
1)
|
[::range-selected
|
||||||
(local-today)])]
|
(let [end-date (or (some-> (:twelve-periods-end period-inputs) (str->date standard))
|
||||||
)}
|
(local-today))
|
||||||
"Month to date"]]
|
this-month (t/local-date (t/year end-date)
|
||||||
[:div.control
|
(t/month end-date)
|
||||||
[:a.button
|
1)
|
||||||
{:class (when (= (:selected params) "Year to date") "is-active")
|
]
|
||||||
:on-click (dispatch-event
|
(into
|
||||||
[::forms/change ::form
|
[[(t/minus this-month (t/months 11))
|
||||||
[:periods]
|
(t/minus (t/plus this-month (t/months 1))
|
||||||
(and-last-year [(t/local-date (t/year (local-today)) 1 1)
|
(t/days 1))
|
||||||
(local-today)])])}
|
"Total"]]
|
||||||
"Year to date"]]
|
(for [i (range 12)]
|
||||||
[:div.control
|
[(t/minus this-month (t/months (- 11 i)))
|
||||||
[:a.button
|
(t/minus (t/minus this-month (t/months (- 10 i)))
|
||||||
{:class (when (= (:selected params) "Full year") "is-active")
|
(t/days 1))])))
|
||||||
:on-click (dispatch-event
|
|
||||||
[::forms/change ::form
|
|
||||||
[:periods]
|
|
||||||
(and-last-year [(t/plus (t/minus (local-today) (t/period :years 1))
|
|
||||||
(t/period :days 1))
|
|
||||||
(local-today)])])}
|
|
||||||
"Full year"]]]]
|
|
||||||
[:div
|
|
||||||
[:div.field
|
|
||||||
[:label.checkbox
|
|
||||||
(raw-field
|
|
||||||
[:input {:type "checkbox"
|
|
||||||
:field [:show-advanced?]}])
|
|
||||||
" Show Advanced"]]]
|
|
||||||
(when (:show-advanced? data)
|
|
||||||
(doall
|
|
||||||
(for [[_ i] (map vector periods (range))]
|
|
||||||
^{:key i}
|
|
||||||
[:div.field.is-grouped
|
|
||||||
[:div.control
|
|
||||||
[:p.help "From"]
|
|
||||||
(raw-field
|
|
||||||
[date-picker-friendly {:type "date"
|
|
||||||
:field [:periods i 0]}])]
|
|
||||||
|
|
||||||
[:div.control
|
false
|
||||||
[:p.help "To"]
|
"12 months"]
|
||||||
(raw-field
|
)}
|
||||||
[date-picker-friendly {:type "date"
|
"12 months"]]]]
|
||||||
:field [:periods i 1]}])]])))
|
|
||||||
(submit-button "Run")]
|
|
||||||
[status/big-loader status]
|
|
||||||
(when (and (not= :loading (:state status))
|
|
||||||
report)
|
|
||||||
|
|
||||||
[:div
|
[:div.control
|
||||||
(when (seq unresolved-accounts)
|
[:a.button
|
||||||
[:div.notification.is-warning.is-light
|
{:class (when (= (:selected params) "Last week") "is-active")
|
||||||
"This report does not include " (str/join ", "
|
:on-click (dispatch-event
|
||||||
(map #(str (:count %) " unresolved ledger entries for " (if (str/blank? (:location %))
|
(let [last-sunday (loop [current (local-today)]
|
||||||
" all locations"
|
(if (= 7 (t/day-of-week current))
|
||||||
(:location %)))
|
current
|
||||||
unresolved-accounts))])
|
(recur (t/minus current (t/period :days 1)))))]
|
||||||
[:<>
|
[::range-selected
|
||||||
(for [location @(re-frame/subscribe [::locations])]
|
(and-last-year [(t/minus last-sunday (t/period :days 6)) last-sunday])
|
||||||
^{:key (str location "-summary")}
|
true
|
||||||
[location-summary location params]
|
"Last week"]))}
|
||||||
)]
|
"Last week"]]
|
||||||
[:h2.title.is-4 {:style {:margin-bottom "1rem"}} "Detail"]
|
[:div.control
|
||||||
[:table.table.compact.balance-sheet
|
[:a.button
|
||||||
[:tbody
|
{:class (when (= (:selected params) "Week to date") "is-active")
|
||||||
[period-header {:include-deltas (:include-deltas params)
|
:on-click (dispatch-event [::range-selected
|
||||||
:periods periods}]
|
(and-last-year [(loop [current (local-today)]
|
||||||
|
(if (= 1 (t/day-of-week current))
|
||||||
|
current
|
||||||
|
(recur (t/minus current (t/period :days 1)))))
|
||||||
|
(local-today)])
|
||||||
|
true
|
||||||
|
"Week to date"])}
|
||||||
|
"Week to date"]]
|
||||||
|
[:div.control
|
||||||
|
[:a.button
|
||||||
|
{:class (when (= (:selected params) "Last Month") "is-active")
|
||||||
|
:on-click (dispatch-event [::range-selected
|
||||||
|
(and-last-year [(t/minus (t/local-date (t/year (local-today))
|
||||||
|
(t/month (local-today))
|
||||||
|
1)
|
||||||
|
(t/period :months 1))
|
||||||
|
(t/minus (t/local-date (t/year (local-today))
|
||||||
|
(t/month (local-today))
|
||||||
|
1)
|
||||||
|
(t/period :days 1))])
|
||||||
|
true
|
||||||
|
"Last Month"])}
|
||||||
|
"Last Month"]]
|
||||||
|
[:div.control
|
||||||
|
[:a.button
|
||||||
|
{:class (when (= (:selected params) "Month to date") "is-active")
|
||||||
|
:on-click (dispatch-event [::range-selected
|
||||||
|
(and-last-year [(t/local-date (t/year (local-today))
|
||||||
|
(t/month (local-today))
|
||||||
|
1)
|
||||||
|
(local-today)])
|
||||||
|
true
|
||||||
|
"Month to date"])}
|
||||||
|
"Month to date"]]
|
||||||
|
[:div.control
|
||||||
|
[:a.button
|
||||||
|
{:class (when (= (:selected params) "Year to date") "is-active")
|
||||||
|
:on-click (dispatch-event [::range-selected
|
||||||
|
(and-last-year [(t/local-date (t/year (local-today)) 1 1)
|
||||||
|
(local-today)])
|
||||||
|
true
|
||||||
|
"Year to date"])}
|
||||||
|
"Year to date"]]
|
||||||
|
[:div.control
|
||||||
|
[:a.button
|
||||||
|
{:class (when (= (:selected params) "Full year") "is-active")
|
||||||
|
:on-click (dispatch-event [::range-selected
|
||||||
|
(and-last-year [(t/plus (t/minus (local-today) (t/period :years 1))
|
||||||
|
(t/period :days 1))
|
||||||
|
(local-today)])
|
||||||
|
true
|
||||||
|
"Full year"])}
|
||||||
|
"Full year"]]]]
|
||||||
|
[:div
|
||||||
|
[:div.field
|
||||||
|
[:label.checkbox
|
||||||
|
[bind-field
|
||||||
|
[:input {:type "checkbox"
|
||||||
|
:field [:show-advanced?]
|
||||||
|
:event [::period-inputs-change]
|
||||||
|
:subscription period-inputs}]]
|
||||||
|
" Show Advanced"]]]
|
||||||
|
(when (:show-advanced? period-inputs)
|
||||||
|
(for [[_ i] (map vector periods (range))]
|
||||||
|
^{:key i}
|
||||||
|
[:div.field.is-grouped
|
||||||
|
[:div.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 [:periods i 0]
|
||||||
|
:event [::date-picked]
|
||||||
|
:popper-props (clj->js {:placement "right"})
|
||||||
|
:subscription params}]]]
|
||||||
|
|
||||||
[:<>
|
[:div.control
|
||||||
(for [location @(re-frame/subscribe [::locations])]
|
[:p.help "To"]
|
||||||
^{:key location}
|
[bind-field
|
||||||
[location-rows location])]]]])]))))
|
[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 [:periods i 1]
|
||||||
|
:event [::date-picked]
|
||||||
|
:popper-props (clj->js {:placement "right"})
|
||||||
|
:subscription params}]]]]))]
|
||||||
|
[status/big-loader status]
|
||||||
|
(when (not= :loading (:state status))
|
||||||
|
[:div
|
||||||
|
(when (seq unresolved-accounts)
|
||||||
|
[:div.notification.is-warning.is-light
|
||||||
|
"This report does not include " (str/join ", "
|
||||||
|
(map #(str (:count %) " unresolved ledger entries for " (if (str/blank? (:location %))
|
||||||
|
" all locations"
|
||||||
|
(:location %)))
|
||||||
|
unresolved-accounts))])
|
||||||
|
[:<>
|
||||||
|
(for [location @(re-frame/subscribe [::locations])]
|
||||||
|
^{:key (str location "-summary")}
|
||||||
|
[location-summary location params]
|
||||||
|
)]
|
||||||
|
[:h2.title.is-4 {:style {:margin-bottom "1rem"}} "Detail"]
|
||||||
|
[:table.table.compact.balance-sheet
|
||||||
|
[:tbody
|
||||||
|
[period-header {:include-deltas (:include-deltas params)
|
||||||
|
:periods periods}]
|
||||||
|
|
||||||
|
[:<>
|
||||||
|
(for [location @(re-frame/subscribe [::locations])]
|
||||||
|
^{:key location}
|
||||||
|
[location-rows location]
|
||||||
|
)]]]])])))
|
||||||
|
{:component-will-mount #(re-frame/dispatch [::mounted]) }))
|
||||||
|
|
||||||
(re-frame/reg-event-fx
|
(re-frame/reg-event-fx
|
||||||
::unmounted-pnl
|
::unmounted-pnl
|
||||||
@@ -825,18 +862,9 @@
|
|||||||
(re-frame/reg-event-fx
|
(re-frame/reg-event-fx
|
||||||
::mounted-pnl
|
::mounted-pnl
|
||||||
(fn [{:keys [db]} _]
|
(fn [{:keys [db]} _]
|
||||||
(let [qp (query-params)]
|
{::track/register {:id ::ledger-params
|
||||||
{:db (forms/start-form db ::form {:periods (->> qp
|
:subscription [::data-page/params ::ledger]
|
||||||
:periods
|
:event-fn (fn [params] [::ledger-params-change params])}}))
|
||||||
(mapv (fn [period]
|
|
||||||
(mapv
|
|
||||||
(fn [dt]
|
|
||||||
(str->date dt standard))
|
|
||||||
period))))
|
|
||||||
:client (:client qp)})
|
|
||||||
::track/register {:id ::ledger-params
|
|
||||||
:subscription [::data-page/params ::ledger]
|
|
||||||
:event-fn (fn [params] [::ledger-params-change params])}})))
|
|
||||||
|
|
||||||
(defn ledger-list [_ ]
|
(defn ledger-list [_ ]
|
||||||
[:div [:a.delete.is-pulled-right {:on-click (dispatch-event [::ledger-list-closing])}]
|
[:div [:a.delete.is-pulled-right {:on-click (dispatch-event [::ledger-list-closing])}]
|
||||||
|
|||||||
@@ -435,17 +435,6 @@
|
|||||||
(do
|
(do
|
||||||
(reagent/adapt-react-class (.-default react-datepicker))))
|
(reagent/adapt-react-class (.-default react-datepicker))))
|
||||||
|
|
||||||
(defn date-picker-friendly [params]
|
|
||||||
[date-picker (assoc params
|
|
||||||
:class-name "input"
|
|
||||||
:class "input"
|
|
||||||
:format-week-number (fn [] "")
|
|
||||||
:previous-month-button-label ""
|
|
||||||
:next-month-button-label ""
|
|
||||||
:next-month-label ""
|
|
||||||
:type "date")])
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
(defn local-now []
|
(defn local-now []
|
||||||
(t/to-default-time-zone (t/now)))
|
(t/to-default-time-zone (t/now)))
|
||||||
|
|||||||
Reference in New Issue
Block a user