Revert "Revert "pnl""

This reverts commit 53fba14831.
This commit is contained in:
Bryce Covert
2021-10-18 06:34:23 -07:00
parent d81096b8bc
commit 2d52c2b6a7
3 changed files with 28 additions and 13 deletions

View File

@@ -153,6 +153,7 @@
{: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}

View File

@@ -96,13 +96,14 @@
(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)))
)
@@ -142,7 +143,8 @@
: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)))})))
(:bank-account/numeric-code (bank-accounts a)))
:client_id client-id})))
(defn full-ledger-for-client [client-id]
(->> (d/query
@@ -189,14 +191,22 @@
(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 (full-ledger-for-client (first client-ids))
lookup-account (build-account-lookup (first client-ids))]
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)]
(->graphql
{: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))})))
{: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)})))})))
(defn assoc-error [f]