From c9943bbae1b1a4d5bfa1e117aed64b65139be489 Mon Sep 17 00:00:00 2001 From: Bryce Covert Date: Tue, 29 Mar 2022 13:22:44 -0700 Subject: [PATCH] nnull fix... --- src/cljc/auto_ap/ledger/reports.cljc | 3 +- .../views/pages/ledger/profit_and_loss.cljs | 139 ++++-------------- 2 files changed, 30 insertions(+), 112 deletions(-) diff --git a/src/cljc/auto_ap/ledger/reports.cljc b/src/cljc/auto_ap/ledger/reports.cljc index 6c09629c..3a12bbd0 100644 --- a/src/cljc/auto_ap/ledger/reports.cljc +++ b/src/cljc/auto_ap/ledger/reports.cljc @@ -95,7 +95,8 @@ (defn best-category [a] (->> ranges (filter (fn [[_ [start end]]] - (<= start (:numeric-code a) end))) + (and (:numeric-code a) + (<= start (:numeric-code a) end)))) first first)) 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 7a2134a9..ecedb570 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 @@ -35,54 +35,20 @@ [vimsical.re-frame.cofx.inject :as inject] [vimsical.re-frame.fx.track :as track])) -(def ranges - {:sales [40000 49999] - :cogs [50000 59999] - :payroll [60000 69999] - :controllable [70000 79999] - :fixed-overhead [80000 89999] - :ownership-controllable [90000 99999]}) + (defn and-last-year [[from to]] [[from to] [(t/minus from (t/years 1)) (t/minus to (t/years 1))]]) -(defn in-range? [code] - (reduce - (fn [acc [start end]] - (if (<= start code end) - (reduced true) - acc)) - false - (vals ranges))) - - ;; SUBS -(re-frame/reg-sub - ::error - (fn [db] - (-> db ::error))) - (re-frame/reg-sub ::ledger-list-active? (fn [db] (-> db ::ledger-list-active?))) -(re-frame/reg-sub - ::period-accounts - :<- [::forms/form ::form] - (fn [db [_ which type only-location]] - - (->> (get-in db [:report :periods which :accounts]) - (map #(update % :amount js/parseFloat)) - (filter (fn [{:keys [account-type location numeric-code]}] - (and (or (nil? only-location) - (= only-location location)) - (<= (get-in ranges [type 0]) numeric-code (get-in ranges [type 1]))))) - (sort-by :numeric-code)))) - (re-frame/reg-sub ::uncategorized-accounts :<- [::forms/form ::form] @@ -94,35 +60,6 @@ (filter (fn [{:keys [account-type location numeric-code]}] (nil? numeric-code)))))) -(defn parse-amounts [period] - (update period :accounts (fn [a] - (map #(update % :amount js/parseFloat) a)))) - - - -(re-frame/reg-sub - ::all-accounts - :<- [::forms/form ::form] - (fn [db [_ which type only-location]] - (transduce - (comp - (map parse-amounts) - (map #(->> (:accounts %) - (group-by (juxt :numeric-code :client-id :location)) - (map (fn [[k v]] - [k - (reduce (fn [a n] - (-> a - (update :count (fn [z] (+ z (:count n)))) - (update :amount (fn [z] (+ z (:amount n)))))) - (first v) - (rest v))])) - - (into {})))) - - conj - [] - (get-in db [:report :periods])))) (re-frame/reg-event-db ::received @@ -130,21 +67,6 @@ (fn [db [_ data]] (-> db (assoc :report (:profit-and-loss data))))) -(re-frame/reg-sub - ::period-inputs - (fn [db] - (-> db ::period-inputs))) - -(re-frame/reg-sub - ::periods - (fn [db] - (-> db ::forms/forms ::form :data :periods))) - -(re-frame/reg-sub - ::include-deltas - (fn [db] - (-> db ::forms/forms ::form :data :include-deltas))) - ;; EVENTS (re-frame/reg-event-db @@ -188,8 +110,6 @@ Please download it by clicking this link: " report-url))) (-> clients-by-id (get (:id (first selected-clients))) :emails))] - - {:dispatch [::modal/modal-requested {:title "Your report is ready" :body [:div [:div "Click " @@ -203,7 +123,7 @@ Please download it by clicking this link: " report-url))) (re-frame/reg-event-fx ::export-pdf [with-user (forms/in-form ::form)] - (fn [{:keys [db user] :as cofx}] + (fn [{:keys [db user]}] (cond-> {:graphql {:token user :owns-state {:single ::page} :query-obj {:venia/queries [[:profit-and-loss-pdf @@ -243,7 +163,8 @@ Please download it by clicking this link: " report-url))) [with-user (forms/in-form ::form)] (fn [{:keys [db]} [_ & event]] {:db (dissoc db :report) - :dispatch (into [::change-internal] event)})) + :dispatch-n [(into [::change-internal] event) + [::ledger-list-closing]]})) (defn data-params->query-params [params] @@ -261,29 +182,29 @@ Please download it by clicking this link: " report-url))) (re-frame/reg-event-fx ::ledger-params-change [with-user] - (fn [{:keys [user db]} [_ ledger-params]] - (if (seq ledger-params) - {:graphql {:token user + (fn [{:keys [user]} [_ ledger-params]] + (when (seq ledger-params) + {:graphql {:token user :owns-state {:single [::data-page/page ::ledger]} - :query-obj {:venia/queries [[:ledger-page - {:filters (data-params->query-params ledger-params)} - [[:journal-entries [:id - :source - :original-entity - :note - :amount - :alternate-description - [:vendor - [:name :id]] - [:client - [:name :id]] - [:line-items - [:id :debit :credit :location :running-balance - [:account [:id :name]]]] - :date]] - :total - :start - :end]]]} + :query-obj {:venia/queries [[:ledger-page + {:filters (data-params->query-params ledger-params)} + [[:journal-entries [:id + :source + :original-entity + :note + :amount + :alternate-description + [:vendor + [:name :id]] + [:client + [:name :id]] + [:line-items + [:id :debit :credit :location :running-balance + [:account [:id :name]]]] + :date]] + :total + :start + :end]]]} :on-success (fn [result] [::data-page/received ::ledger (set/rename-keys (:ledger-page result) {:journal-entries :data})])}}))) @@ -291,8 +212,7 @@ Please download it by clicking this link: " report-url))) (re-frame/reg-event-fx ::investigate-clicked (fn [{:keys [db]} [_ {:keys [location from-numeric-code to-numeric-code client-id] - {:keys [start end]} :date-range - :as filters}]] + {:keys [start end]} :date-range}]] {:db (-> db (assoc ::ledger-list-active? true)) :dispatch [::data-page/additional-params-changed ::ledger {:client-id client-id :from-numeric-code from-numeric-code @@ -311,11 +231,9 @@ Please download it by clicking this link: " report-url))) (= :dollar (:format c)) (->$ (:value c)) - #_(.format (DecimalFormat. "$###,##0.00") (:value cell)) (= :percent (:format c)) (->% (:value c)) - #_(.format (DecimalFormat. "0%") (:value cell)) :else (str (:value c))) @@ -344,8 +262,7 @@ Please download it by clicking this link: " report-url))) (:color c)) ")"))) - cell-contents - ])) + cell-contents])) (defn cell-count [table] (let [counts (map count (:rows table))]