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