From cdf9aa571ff5600a50aadda897a97539176e28d2 Mon Sep 17 00:00:00 2001 From: Bryce Covert Date: Fri, 10 Mar 2023 14:56:58 -0800 Subject: [PATCH] Fixes P&L page to allow for specific locatiosn --- src/clj/auto_ap/datomic/ledger.clj | 5 +++++ src/clj/auto_ap/graphql/ledger.clj | 1 + src/cljc/auto_ap/ledger/reports.cljc | 10 +++++++++- .../auto_ap/views/pages/ledger/profit_and_loss.cljs | 4 +++- 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/clj/auto_ap/datomic/ledger.clj b/src/clj/auto_ap/datomic/ledger.clj index 9af322d2..5965e56d 100644 --- a/src/clj/auto_ap/datomic/ledger.clj +++ b/src/clj/auto_ap/datomic/ledger.clj @@ -98,6 +98,11 @@ :where ['[?li :journal-entry-line/location ?location]]} :args [(:location args)]}) + (not-empty (:locations args)) + (merge-query {:query {:in ['[?location ...]] + :where ['[?li :journal-entry-line/location ?location]]} + :args [(:locations args)]}) + (limited-clients (:id args)) (merge-query {:query {:in ['[?xx ...]] :where ['[?e :journal-entry/client ?xx]]} diff --git a/src/clj/auto_ap/graphql/ledger.clj b/src/clj/auto_ap/graphql/ledger.clj index 201175ac..3d1c3f9e 100644 --- a/src/clj/auto_ap/graphql/ledger.clj +++ b/src/clj/auto_ap/graphql/ledger.clj @@ -821,6 +821,7 @@ :bank_account_id {:type :id} :date_range {:type :date_range} :location {:type 'String} + :locations {:type '(list String)} :numeric_code {:type '(list :numeric_code_range)} :start {:type 'Int} :per_page {:type 'Int} diff --git a/src/cljc/auto_ap/ledger/reports.cljc b/src/cljc/auto_ap/ledger/reports.cljc index 34558200..063d1501 100644 --- a/src/cljc/auto_ap/ledger/reports.cljc +++ b/src/cljc/auto_ap/ledger/reports.cljc @@ -212,6 +212,11 @@ (update :filters (fn [f] (assoc f :location location))))) +(defn filter-locations [pnl-data locations] + (-> pnl-data + (update :filters (fn [f] + (assoc f :locations locations))))) + (defn filter-numeric-code [pnl-data from to] (-> pnl-data (update :data (fn [data] @@ -706,7 +711,8 @@ (filter-location location) (filter-period period) (zebra i))) - [(zebra (filter-period pnl-data period) i)]))) + [(zebra (filter-locations (filter-period pnl-data period) + (map second (client-locations pnl-data))) i)]))) "All location Summary")] (for [[client-id location] (client-locations pnl-data)] (location-summary-table (for [[period i] (map vector (-> pnl-data :args :periods ) (range))] @@ -728,6 +734,7 @@ (zebra i))) [(-> pnl-data (filter-period period) + (filter-locations (map second (client-locations pnl-data))) (zebra i))]))) nil "All location Detail" @@ -743,6 +750,7 @@ (-> pnl-data (filter-client client-id) (filter-period period) + (filter-locations (map second (client-locations pnl-data))) (zebra i))) (str (-> pnl-data :clients-by-id (get client-id)) " (" location ") Detail") location))))}) 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 4f79666c..46b952d8 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 @@ -172,6 +172,7 @@ NOTE: Please review the transactions we may have question for you here: https:// :client-id (:client-id params) :numeric-code (:numeric-code params) :location (:location params) + :locations (:locations params) :date-range (:date-range params)})) (re-frame/reg-event-fx @@ -206,12 +207,13 @@ NOTE: Please review the transactions we may have question for you here: https:// (re-frame/reg-event-fx ::investigate-clicked - (fn [{:keys [db]} [_ {:keys [location numeric-code client-id] + (fn [{:keys [db]} [_ {:keys [location numeric-code client-id locations] {:keys [start end]} :date-range}]] {:db (-> db (assoc ::ledger-list-active? true)) :dispatch [::data-page/additional-params-changed ::ledger {:client-id client-id :numeric-code numeric-code :location location + :locations locations :date-range {:start (date->str start standard) :end (date->str end standard)}}]}))