From 53fba1483154e11a6e590ad8431749cfbc772780 Mon Sep 17 00:00:00 2001 From: Bryce Covert Date: Mon, 18 Oct 2021 06:33:39 -0700 Subject: [PATCH] Revert "pnl" This reverts commit 944f4f8572b32229ff192e90e0e57befc21ab786. --- src/clj/auto_ap/graphql.clj | 1 - src/clj/auto_ap/graphql/ledger.clj | 32 +++++++------------ .../views/pages/ledger/profit_and_loss.cljs | 8 ++--- 3 files changed, 13 insertions(+), 28 deletions(-) diff --git a/src/clj/auto_ap/graphql.clj b/src/clj/auto_ap/graphql.clj index 6fe35cdb..f8025f6c 100644 --- a/src/clj/auto_ap/graphql.clj +++ b/src/clj/auto_ap/graphql.clj @@ -153,7 +153,6 @@ {:fields {:id {:type 'String} :amount {:type 'String} :location {:type 'String} - :client_id {:type :id} :count {:type 'Int} :numeric_code {:type 'Int} :account_type {:type :account_type} diff --git a/src/clj/auto_ap/graphql/ledger.clj b/src/clj/auto_ap/graphql/ledger.clj index 7786f3a2..12a4e2ad 100644 --- a/src/clj/auto_ap/graphql/ledger.clj +++ b/src/clj/auto_ap/graphql/ledger.clj @@ -96,14 +96,13 @@ (let [account (lookup-account account-id) account-type (:account_type account)] - (conj acc (merge {:id (str account-id "-" location) - :location (or location "") - :count count +(conj acc (merge {:id (str account-id "-" location) :location (or location "") :count count :amount (if account-type (if (#{:account-type/asset :account-type/dividend :account-type/expense} account-type) (- debit credit) - (- credit debit)) + (- credit debit) + ) 0.0)} account))) ) @@ -143,8 +142,7 @@ :bank-account-type/credit :account-type/liability} (:db/ident (:bank-account/type (bank-accounts a))))) :numeric_code (or (:account/numeric-code (accounts a)) - (:bank-account/numeric-code (bank-accounts a))) - :client_id client-id}))) + (:bank-account/numeric-code (bank-accounts a)))}))) (defn full-ledger-for-client [client-id] (->> (d/query @@ -191,22 +189,14 @@ (throw (ex-info "Please select a client." {:validation-error "Please select a client."}))) _ (doseq [client-id client-ids] (assert-can-see-client (:id context) client-id)) - all-ledger-entries (->> client-ids - (map (fn [client-id] - [client-id (full-ledger-for-client client-id)])) - (into {})) - lookup-account (->> client-ids - (map (fn [client-id] - [client-id (build-account-lookup client-id)])) - (into {})) - client-id (first client-ids)] + all-ledger-entries (full-ledger-for-client (first client-ids)) + lookup-account (build-account-lookup (first client-ids))] (->graphql - {:periods - (->> (:periods args) - (mapv (fn [{:keys [start end]}] - {:accounts (mapcat - #(roll-up-until (lookup-account %) (all-ledger-entries %) (coerce/to-date end) (coerce/to-date start) ) - client-ids)})))}))) + {:periods (reduce (fn [acc {:keys [start end]}] + (conj acc + {:accounts (roll-up-until lookup-account all-ledger-entries (coerce/to-date end) (coerce/to-date start) )})) + [] + (:periods args))}))) (defn assoc-error [f] 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 23b53ae3..79e8610f 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 @@ -174,7 +174,7 @@ vector)) :periods (mapv (fn [[start end] ] {:start (date->str start standard) :end (date->str end standard)} ) (:periods (:data db)))} - [[:periods [[:accounts [:name :amount :client_id :account-type :id :count :numeric-code :location]]]]]]]} + [[:periods [[:accounts [:name :amount :account-type :id :count :numeric-code :location]]]]]]]} :on-success [::received]} :set-uri-params {:periods (mapv (fn [[start end title]] [(date->str start standard) @@ -424,10 +424,7 @@ {:key (str "between-" i)}))])) -;; reimplement include-deltas. Are numbers even correct? support actually using more than 1 client. - (defn grouping [{:keys [header type groupings location periods all-accounts]}] - (let [params @(re-frame/subscribe [::params])] [:<> (doall @@ -836,8 +833,7 @@ (fn [dt] (str->date dt standard)) period)))) - :client (:client qp) - :include-deltas true}) + :client (:client qp)}) ::track/register {:id ::ledger-params :subscription [::data-page/params ::ledger] :event-fn (fn [params] [::ledger-params-change params])}})))