Adding ability to choose comparison date for balance sheet
This commit is contained in:
@@ -547,7 +547,8 @@
|
||||
:balance_sheet {:type :balance_sheet
|
||||
:args {:client_id {:type :id}
|
||||
:include_comparison {:type 'Boolean}
|
||||
:date {:type :iso_date}}
|
||||
:date {:type :iso_date}
|
||||
:comparison_date {:type :iso_date}}
|
||||
:resolve :get-balance-sheet}
|
||||
|
||||
:profit_and_loss {:type :profit_and_loss_report
|
||||
|
||||
@@ -175,7 +175,7 @@
|
||||
(let [client-id (:client_id args)
|
||||
_ (assert-can-see-client (:id context) client-id)
|
||||
end-date (coerce/to-date (:date args))
|
||||
comparable-date (coerce/to-date (time/minus (:date args) (time/years 1)))
|
||||
comparable-date (coerce/to-date (:comparison_date args))
|
||||
all-ledger-entries (full-ledger-for-client client-id)
|
||||
lookup-account (build-account-lookup client-id)]
|
||||
(log/info "Running balance sheet with " args)
|
||||
|
||||
@@ -126,6 +126,13 @@
|
||||
:date
|
||||
date)]}))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::comparison-date-picked
|
||||
(fn [cofx [_ _ date]]
|
||||
{:dispatch [::params-change (assoc @(re-frame/subscribe [::params])
|
||||
:comparison-date
|
||||
date)]}))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::include-comparison-changed
|
||||
(fn [cofx [_ include-comparison]]
|
||||
@@ -138,7 +145,7 @@
|
||||
(fn [{:keys [db]} [_ from-numeric-code to-numeric-code which]]
|
||||
(let [date (if (= :current which)
|
||||
(get @(re-frame/subscribe [::params]) :date)
|
||||
(date->str (t/minus (str->date (get @(re-frame/subscribe [::params]) :date) standard) (t/years 1)) standard))]
|
||||
(get @(re-frame/subscribe [::params]) :comparison-date))]
|
||||
{:db (-> db (assoc ::ledger-list-active? true))
|
||||
:dispatch [::data-page/additional-params-changed ::ledger {:client-id (:id @(re-frame/subscribe [::subs/client]))
|
||||
:from-numeric-code from-numeric-code
|
||||
@@ -286,27 +293,56 @@
|
||||
[status/status-notification {:statuses [[::status/single ::page]]}]
|
||||
|
||||
[:div.report-controls
|
||||
[:p.help "Date"]
|
||||
[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 [:date]
|
||||
:event [::date-picked]
|
||||
:popper-props (clj->js {:placement "right"})
|
||||
:subscription params}]]
|
||||
|
||||
[:div.level
|
||||
[:div.level-left
|
||||
[:div.level-item
|
||||
[:div.control
|
||||
[:p.help "Date"]
|
||||
[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 [:date]
|
||||
:event [::date-picked]
|
||||
:popper-props (clj->js {:placement "right"})
|
||||
:subscription params}]]]]
|
||||
[:div.level-item
|
||||
|
||||
|
||||
[switch-field {:id "include-comparison"
|
||||
:checked (boolean (:include-comparison params))
|
||||
:on-change (fn [e]
|
||||
(re-frame/dispatch [::include-comparison-changed (.-checked (.-target e))]))
|
||||
:label "Include comparison"
|
||||
:type "checkbox"}]]
|
||||
[:div.control
|
||||
[:div.mt-3]
|
||||
[switch-field {:id "include-comparison"
|
||||
:checked (boolean (:include-comparison params))
|
||||
:on-change (fn [e]
|
||||
(re-frame/dispatch [::include-comparison-changed (.-checked (.-target e))]))
|
||||
:label "Include comparison"
|
||||
:type "checkbox"}]]]
|
||||
[:div.level-item
|
||||
|
||||
(when (boolean (:include-comparison params))
|
||||
[:div.control
|
||||
|
||||
[:p.help "Comparison Date"]
|
||||
[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 [:comparison-date]
|
||||
:event [::comparison-date-picked]
|
||||
:popper-props (clj->js {:placement "right"})
|
||||
:subscription params}]]])
|
||||
]]]]
|
||||
[status/big-loader status]
|
||||
(when (not= :loading (:state status))
|
||||
[:table.table.compact.balance-sheet
|
||||
@@ -316,7 +352,7 @@
|
||||
[:td.has-text-right (date->str (str->date (:date params) standard))])
|
||||
(when (:include-comparison params)
|
||||
[:td.has-text-right (when (:date params)
|
||||
(date->str (t/minus (str->date (:date params) standard) (t/years 1))))])
|
||||
(date->str (str->date (:comparison-date params) standard)))])
|
||||
[:td]]
|
||||
(list
|
||||
(overall-grouping :asset "Assets")
|
||||
@@ -327,6 +363,7 @@
|
||||
[:h1.title "Balance sheet"]
|
||||
[:h2.subtitle "Please choose a client first"]])))
|
||||
{:component-will-mount #(re-frame/dispatch-sync [::params-change {:date (date->str (local-now) standard)
|
||||
:comparison-date (date->str (t/minus (local-now) (t/years 1)) standard)
|
||||
:include-comparison true}]) }))
|
||||
|
||||
(defn ledger-list [_ ]
|
||||
|
||||
Reference in New Issue
Block a user