Balance sheets work multiple clients
This commit is contained in:
@@ -162,15 +162,32 @@
|
||||
|
||||
(defn get-balance-sheet [context args _]
|
||||
(let [client-id (:client_id args)
|
||||
client-ids (or (some-> client-id vector)
|
||||
(filter identity (:client_ids args)))
|
||||
_ (assert-can-see-client (:id context) client-id)
|
||||
_ (when (not (seq client-ids))
|
||||
(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))
|
||||
end-date (coerce/to-date (:date args))
|
||||
comparable-date (coerce/to-date (:comparison_date args))
|
||||
all-ledger-entries (full-ledger-for-client client-id)
|
||||
lookup-account (build-account-lookup 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 {}))]
|
||||
(log/info "Running balance sheet with " args)
|
||||
|
||||
(cond-> {:balance-sheet-accounts (roll-up-until lookup-account all-ledger-entries end-date)}
|
||||
(:include_comparison args) (assoc :comparable-balance-sheet-accounts (roll-up-until lookup-account all-ledger-entries comparable-date))
|
||||
(cond-> {:balance-sheet-accounts (mapcat
|
||||
#(roll-up-until (lookup-account %) (all-ledger-entries %) end-date )
|
||||
client-ids)
|
||||
}
|
||||
(:include_comparison args) (assoc :comparable-balance-sheet-accounts (mapcat
|
||||
#(roll-up-until (lookup-account %) (all-ledger-entries %) comparable-date )
|
||||
client-ids))
|
||||
true ->graphql)))
|
||||
|
||||
(defn get-profit-and-loss [context args _]
|
||||
@@ -747,7 +764,7 @@
|
||||
|
||||
(def queries
|
||||
{:balance_sheet {:type :balance_sheet
|
||||
:args {:client_id {:type :id}
|
||||
:args {:client_ids {:type '(list :id)}
|
||||
:include_comparison {:type 'Boolean}
|
||||
:date {:type :iso_date}
|
||||
:comparison_date {:type :iso_date}}
|
||||
@@ -792,7 +809,7 @@
|
||||
:resolve :cash-flows-pdf}
|
||||
|
||||
:balance_sheet_pdf {:type :report_pdf
|
||||
:args {:client_id {:type :id}
|
||||
:args {:client_ids {:type '(list :id)}
|
||||
:include_comparison {:type 'Boolean}
|
||||
:date {:type :iso_date}
|
||||
:comparison_date {:type :iso_date}}
|
||||
|
||||
Reference in New Issue
Block a user