adds profit and loss snapshot.
This commit is contained in:
@@ -190,6 +190,22 @@
|
||||
client-ids))
|
||||
true ->graphql)))
|
||||
|
||||
(defn get-profit-and-loss-raw [client-ids periods]
|
||||
(let [ 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 {}))]
|
||||
(->graphql {:periods
|
||||
(->> periods
|
||||
(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)})))})))
|
||||
|
||||
(defn get-profit-and-loss [context args _]
|
||||
(let [client-id (:client_id args)
|
||||
client-ids (or (some-> client-id vector)
|
||||
@@ -200,22 +216,10 @@
|
||||
(assert-can-see-client (:id context) client-id))
|
||||
_ (when (and (:include_deltas args)
|
||||
(:column_per_location args))
|
||||
(throw (ex-info "Please select one of 'Include deltas' or 'Column per location'" {:validation-error "Please select one of 'Include deltas' or 'Column per location'"})))
|
||||
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 {}))]
|
||||
(->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)})))})))
|
||||
(throw (ex-info "Please select one of 'Include deltas' or 'Column per location'" {:validation-error "Please select one of 'Include deltas' or 'Column per location'"}))) ]
|
||||
(get-profit-and-loss-raw client-ids (:periods args))))
|
||||
|
||||
|
||||
|
||||
|
||||
;; profit and loss based off of index
|
||||
|
||||
Reference in New Issue
Block a user