From bf3ca6384034c54b2e5dd0aabe6eaa206db17c2b Mon Sep 17 00:00:00 2001 From: Bryce Covert Date: Tue, 1 Oct 2019 07:12:56 -0700 Subject: [PATCH] more fixes. --- src/clj/auto_ap/datomic/ledger.clj | 2 +- src/clj/auto_ap/graphql/ledger.clj | 16 ++++--- .../views/pages/ledger/profit_and_loss.cljs | 43 ++++++++++--------- 3 files changed, 33 insertions(+), 28 deletions(-) diff --git a/src/clj/auto_ap/datomic/ledger.clj b/src/clj/auto_ap/datomic/ledger.clj index 43ab2aa3..6c955210 100644 --- a/src/clj/auto_ap/datomic/ledger.clj +++ b/src/clj/auto_ap/datomic/ledger.clj @@ -57,7 +57,7 @@ (merge-query {:query {:in ['?from-date] :where ['[?e :journal-entry/date ?d] '[(>= ?d ?from-date)]]} - :args [(c/to-date (time/minus (:from-date args) (time/days 1)))]}) + :args [(c/to-date (:from-date args))]}) (:from-numeric-code args) (merge-query {:query {:in ['?from-numeric-code] diff --git a/src/clj/auto_ap/graphql/ledger.clj b/src/clj/auto_ap/graphql/ledger.clj index d8a0ff9d..f256a449 100644 --- a/src/clj/auto_ap/graphql/ledger.clj +++ b/src/clj/auto_ap/graphql/ledger.clj @@ -103,12 +103,14 @@ (defn get-profit-and-loss [context args value] (let [args (assoc args :id (:id context)) pnl (fn [from-date to-date] - (println from-date to-date) + (println "FROM" from-date to-date) (let [[starting-results] (l/get-graphql {:client-id (:client_id args) - :to-date from-date + :to-date (-> from-date + (time/minus (time/seconds 1)) + coerce/to-date) :count Integer/MAX_VALUE}) [ending-results] (l/get-graphql {:client-id (:client_id args) - :to-date to-date + :to-date (coerce/to-date to-date) :count Integer/MAX_VALUE}) starting-accounts (by :id (roll-up starting-results)) ending-accounts (by :id (roll-up ending-results))] @@ -120,10 +122,10 @@ [] ending-accounts)))] (->graphql - {:balance-sheet-accounts (pnl (coerce/to-date (time/minus (:from_date args) (time/days 1))) - (coerce/to-date (:to_date args))) - :comparable-balance-sheet-accounts (pnl (coerce/to-date (coerce/to-date (time/minus (coerce/to-date-time (:from_date args)) (time/years 1)))) - (coerce/to-date (coerce/to-date (time/minus (coerce/to-date-time (:to_date args)) (time/years 1)))))}))) + {:balance-sheet-accounts (pnl (coerce/to-date-time (:from_date args)) + (coerce/to-date-time (:to_date args))) + :comparable-balance-sheet-accounts (pnl (time/minus (coerce/to-date-time (:from_date args)) (time/years 1)) + (time/minus (coerce/to-date-time (:to_date args)) (time/years 1)))}))) #_(get-profit-and-loss nil {:client_id [:client/code "CBC"] :from_date "2018-01-01" 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 de88947d..651c8c58 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 @@ -204,7 +204,7 @@ (re-frame/reg-event-fx ::investigate-clicked (fn [{:keys [db] } [_ location from-numeric-code to-numeric-code which]] - + (println from-numeric-code to-numeric-code) {:db (assoc db ::ledger-list-active? true ::ledger-list-loading true) @@ -298,25 +298,28 @@ ]))) (defn overall-grouping [type title location] - (list - [:tr [:th.has-text-centered title] - [:td] - [:td] - [:td]] - (grouping {:accounts @(re-frame/subscribe [::accounts type location]) - :location location - :groupings (type groupings) - :comparable-accounts @(re-frame/subscribe [::comparable-accounts-by-id type location]) - }) - [:tr [:th.has-text-centered title] - [:th.has-text-right [:a - {:on-click (dispatch-event [::investigate-clicked location nil nil :current])} - (->$ (reduce + 0 (map :amount @(re-frame/subscribe [::accounts type location]))))]] - [:th.has-text-right [:a - {:on-click (dispatch-event [::investigate-clicked location nil nil :comparable])} - (->$ (reduce + 0 (map :amount (vals @(re-frame/subscribe [::comparable-accounts-by-id type location])))))]] - [:th.has-text-right (->$ (- (reduce + 0 (map :amount @(re-frame/subscribe [::accounts type location]))) - (reduce + 0 (map :amount (vals @(re-frame/subscribe [::comparable-accounts-by-id type location]))))))]])) + (let [accounts @(re-frame/subscribe [::accounts type location]) + min-numeric-code (or (first (map :numeric-code accounts)) 0) + max-numeric-code (or (last (map :numeric-code accounts)) 0)] + (list + [:tr [:th.has-text-centered title] + [:td] + [:td] + [:td]] + (grouping {:accounts accounts + :location location + :groupings (type groupings) + :comparable-accounts @(re-frame/subscribe [::comparable-accounts-by-id type location]) + }) + [:tr [:th.has-text-centered title] + [:th.has-text-right [:a + {:on-click (dispatch-event [::investigate-clicked location min-numeric-code max-numeric-code :current])} + (->$ (reduce + 0 (map :amount @(re-frame/subscribe [::accounts type location]))))]] + [:th.has-text-right [:a + {:on-click (dispatch-event [::investigate-clicked location min-numeric-code max-numeric-code :comparable])} + (->$ (reduce + 0 (map :amount (vals @(re-frame/subscribe [::comparable-accounts-by-id type location])))))]] + [:th.has-text-right (->$ (- (reduce + 0 (map :amount @(re-frame/subscribe [::accounts type location]))) + (reduce + 0 (map :amount (vals @(re-frame/subscribe [::comparable-accounts-by-id type location]))))))]]))) (def profit-and-loss-content (with-meta