From 71e19ee66e5b24d2414f6f09cef63efb3a69ab75 Mon Sep 17 00:00:00 2001 From: Bryce Covert Date: Sat, 5 Oct 2019 18:50:14 -0700 Subject: [PATCH] Prevents loading all data --- .../views/pages/ledger/profit_and_loss.cljs | 173 +++++++++--------- 1 file changed, 89 insertions(+), 84 deletions(-) diff --git a/src/cljs/auto_ap/views/pages/ledger/profit_and_loss.cljs b/src/cljs/auto_ap/views/pages/ledger/profit_and_loss.cljs index fbf323f6..37f953c1 100644 --- a/src/cljs/auto_ap/views/pages/ledger/profit_and_loss.cljs +++ b/src/cljs/auto_ap/views/pages/ledger/profit_and_loss.cljs @@ -365,63 +365,68 @@ error @(re-frame/subscribe [::error]) params @(re-frame/subscribe [::params])] - [:div - [:h1.title "Profit and Loss"] - [:h2.title.is-4 "Range"] - [:div - [:div.field.is-grouped - [:p.control - [:a.button - {:class (when (= (:selected params) "Last week") "is-active") - :on-click (dispatch-event [::range-selected - (date->str (t/minus (local-now) (t/period :days 7)) standard) - (date->str (local-now) standard) - "Last week"])} - "Last week"]] - [:p.control - [:a.button - {:class (when (= (:selected params) "Week to date") "is-active") - :on-click (dispatch-event [::range-selected - (date->str (loop [current (local-now)] - (if (= 7 (t/day-of-week current)) - current - (recur (t/minus current (t/period :days 1))))) - standard) - (date->str (local-now) standard) - "Week to date"])} - "Week to date"]] - [:p.control - [:a.button - {:class (when (= (:selected params) "Month to date") "is-active") - :on-click (dispatch-event [::range-selected - (date->str (t/local-date (t/year (local-now)) - (t/month (local-now)) - 1) - standard) - (date->str (local-now) standard) - "Month to date"])} - "Month to date"]] - [:p.control - [:a.button - {:class (when (= (:selected params) "Year to date") "is-active") - :on-click (dispatch-event [::range-selected - (date->str (t/local-date (t/year (local-now)) - 1 - 1) - standard) - (date->str (local-now) standard) - "Year to date"])} - "Year to date"]] - [:p.control - [:a.button - {:class (when (= (:selected params) "Full year") "is-active") - :on-click (dispatch-event [::range-selected - (date->str (t/minus (local-now) (t/period :years 1)) - standard) - (date->str (local-now) standard) - "Full year"])} - "Full year"]]]] -[:div.field.is-grouped + (if-not current-client + [:div + [:h1.title "Profit and Loss"] + [:h2.title.is-4 "Please choose a client first"]] + + [:div + [:h1.title "Profit and Loss"] + [:h2.title.is-4 "Range"] + [:div + [:div.field.is-grouped + [:p.control + [:a.button + {:class (when (= (:selected params) "Last week") "is-active") + :on-click (dispatch-event [::range-selected + (date->str (t/minus (local-now) (t/period :days 7)) standard) + (date->str (local-now) standard) + "Last week"])} + "Last week"]] + [:p.control + [:a.button + {:class (when (= (:selected params) "Week to date") "is-active") + :on-click (dispatch-event [::range-selected + (date->str (loop [current (local-now)] + (if (= 7 (t/day-of-week current)) + current + (recur (t/minus current (t/period :days 1))))) + standard) + (date->str (local-now) standard) + "Week to date"])} + "Week to date"]] + [:p.control + [:a.button + {:class (when (= (:selected params) "Month to date") "is-active") + :on-click (dispatch-event [::range-selected + (date->str (t/local-date (t/year (local-now)) + (t/month (local-now)) + 1) + standard) + (date->str (local-now) standard) + "Month to date"])} + "Month to date"]] + [:p.control + [:a.button + {:class (when (= (:selected params) "Year to date") "is-active") + :on-click (dispatch-event [::range-selected + (date->str (t/local-date (t/year (local-now)) + 1 + 1) + standard) + (date->str (local-now) standard) + "Year to date"])} + "Year to date"]] + [:p.control + [:a.button + {:class (when (= (:selected params) "Full year") "is-active") + :on-click (dispatch-event [::range-selected + (date->str (t/minus (local-now) (t/period :years 1)) + standard) + (date->str (local-now) standard) + "Full year"])} + "Full year"]]]] + [:div.field.is-grouped [:p.control [:p.help "From"] [bind-field @@ -453,35 +458,35 @@ :event [::date-picked] :popper-props (clj->js {:placement "right"}) :subscription params}]]]] - (cond - error - [:div.notification.is-warning error] + (cond + error + [:div.notification.is-warning error] - @(re-frame/subscribe [::loading]) - [:div [:i.icon.fa.fa-spin.fa-spinner]] + @(re-frame/subscribe [::loading]) + [:div [:i.icon.fa.fa-spin.fa-spinner]] - :else - [:div - [:table.table.compact.balance-sheet - (list - [:tr - [:td.has-text-right "Period ending"] - [:td.has-text-right (date->str (str->date (:to-date params) standard))] - [:td.has-text-right (when (:to-date params) - (date->str (t/minus (str->date (:to-date params) standard) (t/years 1))))] - [:td]] - (for [location @(re-frame/subscribe [::locations])] - (list - (overall-grouping :sales (str location " Sales") location) - (overall-grouping :cogs (str location " COGS") location) - (overall-grouping :payroll (str location " Payroll") location) - (subtotal [:payroll :cogs] #{} (str location " Prime Costs") location) - (subtotal [:sales :payroll :cogs] #{:payroll :cogs} (str location " Gross Profits") location) - (overall-grouping :controllable (str location " Controllable Expenses") location) - (overall-grouping :noncontrollable (str location " Noncontrallable Expenses") location) - (subtotal [:controllable :noncontrollable] #{} (str location " Overhead") location) - (subtotal [:sales :cogs :payroll :controllable :noncontrollable] #{:cogs :payroll :controllable :noncontrollable} (str location " Net Income") location) - (subtotal [:sales :cogs :payroll :controllable :noncontrollable] #{:cogs :payroll :controllable :noncontrollable} "Net Income" nil))))]])])) + :else + [:div + [:table.table.compact.balance-sheet + (list + [:tr + [:td.has-text-right "Period ending"] + [:td.has-text-right (date->str (str->date (:to-date params) standard))] + [:td.has-text-right (when (:to-date params) + (date->str (t/minus (str->date (:to-date params) standard) (t/years 1))))] + [:td]] + (for [location @(re-frame/subscribe [::locations])] + (list + (overall-grouping :sales (str location " Sales") location) + (overall-grouping :cogs (str location " COGS") location) + (overall-grouping :payroll (str location " Payroll") location) + (subtotal [:payroll :cogs] #{} (str location " Prime Costs") location) + (subtotal [:sales :payroll :cogs] #{:payroll :cogs} (str location " Gross Profits") location) + (overall-grouping :controllable (str location " Controllable Expenses") location) + (overall-grouping :noncontrollable (str location " Noncontrallable Expenses") location) + (subtotal [:controllable :noncontrollable] #{} (str location " Overhead") location) + (subtotal [:sales :cogs :payroll :controllable :noncontrollable] #{:cogs :payroll :controllable :noncontrollable} (str location " Net Income") location) + (subtotal [:sales :cogs :payroll :controllable :noncontrollable] #{:cogs :payroll :controllable :noncontrollable} "Net Income" nil))))]])]))) {:component-will-mount #(re-frame/dispatch-sync [::params-change {:from-date (date->str (t/minus (local-now) (t/period :years 1)) standard) :to-date (date->str (local-now) standard)}]) }))