Undoes old way of doing forms in favor of context version. Much easier

This commit is contained in:
2022-07-17 17:32:47 -07:00
parent a17f587ff3
commit b6962c5bfa
17 changed files with 782 additions and 1393 deletions

View File

@@ -23,7 +23,8 @@
[reagent.core :as reagent]
[vimsical.re-frame.fx.track :as track]
[vimsical.re-frame.cofx.inject :as inject]
[auto-ap.views.pages.ledger.report-table :as rtable]))
[auto-ap.views.pages.ledger.report-table :as rtable]
[auto-ap.forms.builder :as form-builder]))
(defn data-params->query-params [params]
(when params
@@ -36,11 +37,6 @@
:to-numeric-code (:to-numeric-code params)
:date-range (:date-range params)}))
(re-frame/reg-sub
::can-submit
(fn [_]
true))
(re-frame/reg-sub
::ledger-list-active?
@@ -183,53 +179,46 @@ NOTE: Please review the transactions we may have question for you here: https://
:event-fn (fn [params] [::ledger-params-change params])}}))
(def balance-sheet-form (forms/vertical-form {:can-submit [::can-submit]
:change-event [::change]
:submit-event [::report-requested]
:id ::form}))
(defn report-form []
(let [{:keys [form-inline raw-field]} balance-sheet-form
{:keys [data]} @(re-frame/subscribe [::forms/form ::form])]
(form-inline {}
[:div
[:div.report-controls
[:div.level
[:div.level-left
[:div.level-item
[:div.control
[:p.help "Date"]
(raw-field
[date-picker {:output :cljs-date
:type "date"
:field [:date]}])]]
[:div.level-item
[:div.control
[:div.mt-3]
[switch-field {:id "include-comparison"
:checked (:include-comparison data)
:on-change (fn [e]
(re-frame/dispatch [::change [:include-comparison] (.-checked (.-target e))]))
:label "Include comparison"
:type "checkbox"}]]]
[:div.level-item
(let [{:keys [data]} @(re-frame/subscribe [::forms/form ::form])]
[form-builder/builder {:change-event [::change]
:submit-event [::report-requested]
:id ::form}
[:div
[:div.report-controls
[:div.level
[:div.level-left
[:div.level-item
[:div.control
[form-builder/field
"Date"
[date-picker {:output :cljs-date
:type "date"
:field [:date]}]]]]
[:div.level-item
[form-builder/field
[:div.mt-5]
[switch-field {:id "include-comparison"
:field [:include-comparison]
:label "Include compariison"
:type "checkbox"}]]]
[:div.level-item
(when (boolean (:include-comparison data))
[:div.control
[:p.help "Comparison Date"]
(raw-field
[date-picker {:output :cljs-date
:type "date"
:field [:comparison-date]}])])]]
[:div.level-right
[:div.buttons
(when (boolean (:include-comparison data))
[form-builder/field
"Comparison Date"
[date-picker {:output :cljs-date
:type "date"
:field [:comparison-date]}]])]]
[:div.level-right
[:div.buttons
(when @(re-frame/subscribe [::subs/is-admin?])
[:button.button.is-secondary {:on-click (dispatch-event [::export-pdf])} "Export"])
[:button.button.is-primary "Run"]]]]]])))
(when @(re-frame/subscribe [::subs/is-admin?])
[:button.button.is-secondary {:on-click (dispatch-event [::export-pdf])} "Export"])
[:button.button.is-primary "Run"]]]]]]]))
(defn balance-sheet-report [{:keys [args report-data]}]
(let [pnl-data (concat (->> (:balance-sheet-accounts report-data)
(let [pnl-data (concat (->> (:balance-sheet-accounts report-data)
(map (fn [b]
(assoc b
:period (:date args)

View File

@@ -31,7 +31,8 @@
[react-dom :as react-dom]
[reagent.core :as reagent]
[vimsical.re-frame.cofx.inject :as inject]
[vimsical.re-frame.fx.track :as track]))
[vimsical.re-frame.fx.track :as track]
[auto-ap.forms.builder :as form-builder]))
@@ -223,14 +224,11 @@ NOTE: Please review the transactions we may have question for you here: https://
(fn [_]
true))
(def pnl-form (forms/vertical-form {:can-submit [::can-submit]
:change-event [::change]
:submit-event [::report-requested]
:id ::form}))
(defn report-control-detail [{:keys [active box which]} children]
(when (and @box
(= which @active))
(println @box)
(react-dom/createPortal (reagent/as-element
[:div.notification.is-light
[:a.delete {:on-click (fn [] (reset! active nil))}]
@@ -243,191 +241,189 @@ NOTE: Please review the transactions we may have question for you here: https://
[:div.control
[:a.button
{:class (when (= selected-preset title) "is-active")
:on-click (dispatch-event
[::change
[:periods]
periods
[:selected-preset] title])}
:on-click (fn []
(re-frame/dispatch-sync [::change
[:periods]
periods
[:selected-preset] title])
(re-frame/dispatch-sync [::change
[:show-advanced?]
false]))}
title]]))
(defn report-controls [_]
(let [!box (reagent/atom nil)
(defn report-controls []
(let [!box (atom nil)
active (reagent/atom nil)]
(fn [pnl-form]
(let [{:keys [raw-field]} pnl-form
{:keys [data]} @(re-frame/subscribe [::forms/form ::form])
(fn []
(let [{: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
[:div.level-item
[buttons/dropdown {:on-click (fn [] (reset! active :clients))}
[:span (str "Companies"
(when-let [clients (:clients data)]
(str " (" (str/join ", " (map :name clients)) ")")))]]
[report-control-detail {:active active :box !box :which :clients}
[:div {:style {:width "20em"}}
[:h4.subtitle "Companies"]
[raw-field
[multi-field {:type "multi-field"
:field [:clients]
:template [[typeahead-v3 {:entities @(re-frame/subscribe [::subs/clients])
:entity->text :name
:type "typeahead-v3"}]]}]]
]]]
[:div.level-item
[buttons/dropdown {:on-click (fn [] (reset! active :range))}
[:span (str "Range"
(when selected-preset
(str " (" selected-preset ")")))]]
[report-control-detail {:active active :box !box :which :range}
[:div
[:h4.subtitle "Range"]
[:div.field.is-grouped
[:div.control
[:div.field.has-addons
[:div.control
(raw-field
[form-builder/builder {:can-submit [::can-submit]
:change-event [::change]
:submit-event [::report-requested]
:id ::form}
[:div.report-controls
[:div.level.mb-2
[:div.level-left
[:div.level-item
[buttons/dropdown {:on-click (fn [] (reset! active :clients))}
[:span (str "Companies"
(when-let [clients (:clients data)]
(str " (" (str/join ", " (map :name clients)) ")")))]]
[report-control-detail {:active active :box !box :which :clients}
[:div {:style {:width "20em"}}
[:h4.subtitle "Companies"]
[form-builder/raw-field
[multi-field {:type "multi-field"
:field [:clients]
:template [[typeahead-v3 {:entities @(re-frame/subscribe [::subs/clients])
:style {:width "18em"}
:entity->text :name
:type "typeahead-v3"}]]}]]]]]
[:div.level-item
[buttons/dropdown {:on-click (fn [] (reset! active :range))}
[:span (str "Range"
(when selected-preset
(str " (" selected-preset ")")))]]
[report-control-detail {:active active :box !box :which :range}
[:div
[:h4.subtitle "Range"]
[:div.field.is-grouped
[:div.control
[:div.field.has-addons
[:div.control
[form-builder/raw-field
[date-picker {:placeholder "End date"
:type "date"
:output :cljs-date
:field [:thirteen-periods-end]}])]
[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)))
:field [:thirteen-periods-end]}]]]
[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 (t/minus today (t/weeks (* i 4)))})))}]]]
: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 {:placeholder "End date"
:output :cljs-date
:type "date"
:field [:twelve-periods-end]}])]
[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
[:div.field.has-addons
[:div.control
[form-builder/raw-field
[date-picker {:placeholder "End date"
:output :cljs-date
:type "date"
:field [:twelve-periods-end]}]]]
[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))})))}]]]
[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"}]
[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"}]
[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 (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/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))
(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 (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 [{: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
(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 {:type "date"
:output :cljs-date
:field [:periods i :start]}])]
[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
[form-builder/raw-field
[:input {:type "checkbox"
:field [:show-advanced?]}]]
" Show Advanced"]]]
(when (:show-advanced? data)
[form-builder/raw-field
[multi-field {:type "multi-field"
:field [:periods]
:template [[date-picker {:type "date"
:output :cljs-date
:field [:start]}]
[date-picker {:type "date"
:output :cljs-date
:field [:end]}]]}]])]]]
[:div.control
[:p.help "To"]
(raw-field
[date-picker {:type "date"
:output :cljs-date
:field [:periods i :end]}])]])))]]]
[:div.level-item
[:div
[switch-field {:id "include-deltas"
:checked (boolean include-deltas)
:on-change (fn [e]
(re-frame/dispatch [::change
[:include-deltas] (.-checked (.-target e))]))
:label "Include deltas"
: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
[:div.level-item
[:div
[switch-field {:id "include-deltas"
:checked (boolean include-deltas)
:on-change (fn [e]
(re-frame/dispatch [::change
[:include-deltas] (.-checked (.-target e))]))
:label "Include deltas"
: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
(when @(re-frame/subscribe [::subs/is-admin?])
[:button.button.is-secondary {:on-click (dispatch-event [::export-pdf])} "Export"])
[:button.button.is-primary "Run"]]
(when @(re-frame/subscribe [::subs/is-admin?])
[:button.button.is-secondary {:on-click (dispatch-event [::export-pdf])} "Export"])
[:button.button.is-primary "Run"]]
]]
[:div.report-control-detail {:ref (fn [el]
(when-not @!box
(reset! !box el)))}]]))))
]]
[:div.report-control-detail {:ref (fn [el]
(when (not= @!box el)
(reset! !box el)))}]]]))))
@@ -466,13 +462,11 @@ NOTE: Please review the transactions we may have question for you here: https://
(defn profit-and-loss-content []
(let [status @(re-frame/subscribe [::status/single ::page])
{:keys [data report]} @(re-frame/subscribe [::forms/form ::form])
{:keys [form-inline]} pnl-form]
{:keys [data report]} @(re-frame/subscribe [::forms/form ::form])]
[:div
(form-inline {}
[:div
[status/status-notification {:statuses [[::status/single ::page]]}]
[report-controls pnl-form]])
[:div
[status/status-notification {:statuses [[::status/single ::page]]}]
[report-controls]]
[status/big-loader status]
(when (and (not= :loading (:state status))
report)