Adds the ability to do a column per location

This commit is contained in:
2022-04-03 07:46:15 -07:00
parent 72a97532ee
commit 7739c18bc2
3 changed files with 303 additions and 259 deletions

View File

@@ -73,7 +73,9 @@
:owns-state {:single ::page}
:query-obj {:venia/queries [[:profit-and-loss
{:client-ids (map :id (:clients (:data db)))
:periods (mapv encode-period (:periods (:data db)))}
:periods (mapv encode-period (:periods (:data db)))
:include-deltas (:include-deltas (:data db))
:column-per-location (:column-per-location (:data db))}
[[:periods [[:accounts [:name :amount :client_id :account-type :id :count :numeric-code :location]]]]]]]}
:on-success [::received]}
:set-uri-params {:periods (mapv
@@ -123,7 +125,8 @@ NOTE: Please review the transactions we may have question for you here: https://
:owns-state {:single ::page}
:query-obj {:venia/queries [[:profit-and-loss-pdf
{:client-ids (map :id (:clients (:data db)))
:include-deltas (:include-deltas (:data db))
:include-deltas (:include-deltas (:data db))
:column-per-location (:column-per-location (:data db))
:periods (mapv encode-period (:periods (:data db)))}
[:url :name]]]}
:on-success [::received-pdf]}
@@ -144,7 +147,7 @@ NOTE: Please review the transactions we may have question for you here: https://
(= 2 (count field)))
[field value] ;;already serialized
(= :periods (first field)) [field (str->date value standard) ]
(= :periods (first field)) [field value ]
:else nil)
)))
@@ -233,13 +236,25 @@ NOTE: Please review the transactions we may have question for you here: https://
])
@box)))
(defn period-preset-button [{:keys [title periods]}]
(let [{{:keys [selected-preset]} :data} @(re-frame/subscribe [::forms/form ::form])]
[:div.control
[:a.button
{:class (when (= selected-preset title) "is-active")
:on-click (dispatch-event
[::change
[:periods]
periods
[:selected-preset] title])}
title]]))
(defn report-controls [_]
(let [!box (reagent/atom nil)
(let [!box (reagent/atom nil)
active (reagent/atom nil)]
(fn [pnl-form]
(let [{:keys [raw-field]} pnl-form
{:keys [data]} @(re-frame/subscribe [::forms/form ::form])
{:keys [periods selected-period include-deltas]} data]
(let [{:keys [raw-field]} pnl-form
{:keys [data]} @(re-frame/subscribe [::forms/form ::form])
{:keys [periods selected-preset include-deltas column-per-location]} data]
[:div.report-controls
[:div.level.mb-2
[:div.level-left
@@ -261,8 +276,8 @@ NOTE: Please review the transactions we may have question for you here: https://
[:div.level-item
[buttons/dropdown {:on-click (fn [] (reset! active :range))}
[:span (str "Range"
(when selected-period
(str " (" selected-period ")")))]]
(when selected-preset
(str " (" selected-preset ")")))]]
[report-control-detail {:active active :box !box :which :range}
[:div
[:h4.subtitle "Range"]
@@ -273,146 +288,89 @@ NOTE: Please review the transactions we may have question for you here: https://
(raw-field
[date-picker-friendly {:placeholder "End date"
:type "date"
:cljs-date? true
:field [:thirteen-periods-end]}])]
[:div.control
[:a.button
{:class (when (= selected-period "13 periods") "is-active")
:on-click (dispatch-event
[::change
[:periods]
(let [today (or (some-> (:thirteen-periods-end data) (str->date standard))
(local-today))]
(into
[{:start (t/plus (t/minus today (t/weeks (* 13 4)))
(t/days 1))
:end today
:title "Total"}]
(for [i (range 13)]
{:start (t/plus (t/minus today (t/weeks (* (inc i) 4)))
(t/days 1))
:end (t/minus today (t/weeks (* i 4)))})))
[:selected-period] "13 periods"])}
"13 periods"]]]]
[period-preset-button {:title "13 periods"
:periods (let [today (or (some-> (:thirteen-periods-end data))
(local-today))]
(into
[{:start (t/plus (t/minus today (t/weeks (* 13 4)))
(t/days 1))
:end today
:title "Total"}]
(for [i (range 13)]
{:start (t/plus (t/minus today (t/weeks (* (inc i) 4)))
(t/days 1))
:end (t/minus today (t/weeks (* i 4)))})))}]]]
[:div.control
[:div.field.has-addons
[:div.control
(raw-field
[date-picker-friendly {:placeholder "End date"
:cljs-date? true
:type "date"
:field [:twelve-periods-end]}])]
[:div.control
[:a.button
{:class (when (= selected-period "12 months") "is-active")
:on-click (dispatch-event
[::change
[: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
[{:start (t/minus this-month (t/months 11))
:end (t/minus (t/plus this-month (t/months 1))
(t/days 1))
:title "Total"}]
(for [i (range 12)]
{:start (t/minus this-month (t/months (- 11 i)))
:end (t/minus (t/minus this-month (t/months (- 10 i)))
(t/days 1))})))
[:selected-period] "12 months"])}
"12 months"]]]]
[period-preset-button {:title "12 months"
:periods (let [end-date (or (some-> (:twelve-periods-end data))
(local-today))
this-month (t/local-date (t/year end-date)
(t/month end-date)
1)]
(into
[{:start (t/minus this-month (t/months 11))
:end (t/minus (t/plus this-month (t/months 1))
(t/days 1))
:title "Total"}]
(for [i (range 12)]
{:start (t/minus this-month (t/months (- 11 i)))
:end (t/minus (t/minus this-month (t/months (- 10 i)))
(t/days 1))})))}]]]
[:div.control
[:a.button
{:class (when (= selected-period "Last week") "is-active")
:on-click (dispatch-event
[::change
[:periods]
(let [last-sunday (loop [current (local-today)]
(if (= 7 (t/day-of-week current))
current
(recur (t/minus current (t/period :days 1)))))]
(and-last-year {:start (t/minus last-sunday (t/period :days 6))
:end last-sunday}))
[:selected-period] "Last week"])}
"Last week"]]
[:div.control
[:a.button
{:class (when (= selected-period "Week to date") "is-active")
:on-click (dispatch-event
[::change
[:periods]
(and-last-year {:start (loop [current (local-today)]
(if (= 1 (t/day-of-week current))
current
(recur (t/minus current (t/period :days 1)))))
:end (local-today)})
[:selected-period] "Week to date"])}
"Week to date"]]
[:div.control
[:a.button
{:class (when (= selected-period "Last Month") "is-active")
:on-click (dispatch-event
[period-preset-button {:periods (let [last-sunday (loop [current (local-today)]
(if (= 7 (t/day-of-week current))
current
(recur (t/minus current (t/period :days 1)))))]
(and-last-year {:start (t/minus last-sunday (t/period :days 6))
:end last-sunday}))
:title "Last week"}]
[::change
[:periods]
(and-last-year {:start (t/minus (t/local-date (t/year (local-today))
(t/month (local-today))
1)
(t/period :months 1))
:end (t/minus (t/local-date (t/year (local-today))
(t/month (local-today))
1)
(t/period :days 1))})
[:selected-period] "Last Month"])}
"Last Month"]]
[:div.control
[:a.button
{:class (when (= selected-period "Month to date") "is-active")
:on-click (dispatch-event
[::change
[:periods]
(and-last-year {:start (t/local-date (t/year (local-today))
(t/month (local-today))
1)
:end (local-today)})
[:selected-period] "Month to date"]
)}
"Month to date"]]
[:div.control
[:a.button
{:class (when (= selected-period "Year to date") "is-active")
:on-click (dispatch-event
[::change
[:periods]
(and-last-year {:start (t/local-date (t/year (local-today)) 1 1)
:end
(local-today)})
[:selected-period] "Year to date"])}
"Year to date"]]
[:div.control
[:a.button
{:class (when (= selected-period "Full year") "is-active")
:on-click (dispatch-event
[::change
[:periods]
[{:start (t/local-date (dec (t/year (local-today))) 1 1)
:end (t/local-date (dec (t/year (local-today))) 12 31)}]
[:selected-period] "Last Calendar year"])}
"Last calendar year"]]
[:div.control
[:a.button
{:class (when (= selected-period "Full year") "is-active")
:on-click (dispatch-event
[::change
[:periods]
(and-last-year {:start (t/plus (t/minus (local-today) (t/period :years 1))
(t/period :days 1))
:end (local-today)})
[:selected-period] "Full year"])}
"Full year"]]]
[period-preset-button {:periods (and-last-year {:start (loop [current (local-today)]
(if (= 1 (t/day-of-week current))
current
(recur (t/minus current (t/period :days 1)))))
:end (local-today)})
:title "Week to date"}]
[period-preset-button {:periods (and-last-year {:start (t/minus (t/local-date (t/year (local-today))
(t/month (local-today))
1)
(t/period :months 1))
:end (t/minus (t/local-date (t/year (local-today))
(t/month (local-today))
1)
(t/period :days 1))})
:title "Last month"}]
[period-preset-button {:periods (and-last-year {:start (t/local-date (t/year (local-today))
(t/month (local-today))
1)
:end (local-today)})
:title "Month to date"}]
[period-preset-button {:periods (and-last-year {:start (t/local-date (t/year (local-today)) 1 1)
:end
(local-today)})
:title "Year to date"}]
[period-preset-button {:periods [{:start (t/local-date (dec (t/year (local-today))) 1 1)
:end (t/local-date (dec (t/year (local-today))) 12 31)}]
:title "Last calendar year"}]
[period-preset-button {:periods (and-last-year {:start (t/plus (t/minus (local-today) (t/period :years 1))
(t/period :days 1))
:end (local-today)})
:title "Full year"}]]
[:div
[:div.field
[:label.checkbox
@@ -429,12 +387,14 @@ NOTE: Please review the transactions we may have question for you here: https://
[:p.help "From"]
(raw-field
[date-picker-friendly {:type "date"
:cljs-date? true
:field [:periods i :start]}])]
[:div.control
[:p.help "To"]
(raw-field
[date-picker-friendly {:type "date"
:cljs-date? true
:field [:periods i :end]}])]])))]]]
[:div.level-item
@@ -445,7 +405,16 @@ NOTE: Please review the transactions we may have question for you here: https://
(re-frame/dispatch [::change
[:include-deltas] (.-checked (.-target e))]))
:label "Include deltas"
:type "checkbox"}]]]]
:type "checkbox"}]]]
[:div.level-item
[:div
[switch-field {:id "column-per-location"
:checked (boolean column-per-location)
:on-change (fn [e]
(re-frame/dispatch [::change
[:column-per-location] (.-checked (.-target e))]))
:label "Column per location"
:type "checkbox"}]]]]
[:div.level-right
[:div.buttons