a much better general ledger profit and loss.

This commit is contained in:
Bryce Covert
2020-07-16 22:20:35 -07:00
parent e0b636c2fa
commit 976cd1e7c3
9 changed files with 347 additions and 363 deletions

View File

@@ -82,7 +82,7 @@
'[(<= ?c ?to-numeric-code)]]}
:args [(:to-numeric-code args)]})
(:location args)
(not-empty (:location args))
(merge-query {:query {:in ['?location]
:where ['[?e :journal-entry/line-items ?li]
'[?li :journal-entry-line/location ?location]]}

View File

@@ -115,6 +115,12 @@
{:fields {:balance_sheet_accounts {:type '(list :balance_sheet_account)}
:comparable_balance_sheet_accounts {:type '(list :balance_sheet_account)}}}
:profit_and_loss_report_period
{:fields {:accounts {:type '(list :balance_sheet_account)}}}
:profit_and_loss_report
{:fields {:periods {:type '(list :profit_and_loss_report_period)}}}
:address
{:fields {:street1 {:type 'String}
:street2 {:type 'String}
@@ -404,9 +410,9 @@
:date {:type :iso_date}}
:resolve :get-balance-sheet}
:profit_and_loss {:type :balance_sheet
:profit_and_loss {:type :profit_and_loss_report
:args {:client_id {:type :id}
:date_range {:type :date_range}}
:periods {:type '(list :date_range)}}
:resolve :get-profit-and-loss}

View File

@@ -106,12 +106,15 @@
vals
(mapcat (fn [a]
(map (fn [o]
[[[(:db/id a) (:db/id (:account-client-override/client o))]]
#_(println "override" (:db/id a) (:db/id (:account-client-override/client o)))
#_(print [[(:db/id a) (:db/id (:account-client-override/client o))]])
[[(:db/id a) (:db/id (:account-client-override/client o))]
(:account-client-override/name o)])
(:account/client-overrides a))
) )
(into {} ))]
(fn [a]
#_(println a client-id (keys overrides-by-client))
{:name (or (:bank-account/name (bank-accounts a))
(overrides-by-client [a client-id])
(:account/name (accounts a)))
@@ -155,16 +158,16 @@
(defn get-profit-and-loss [context args value]
(let [client-id (:client_id args)
_ (assert-can-see-client (:id context) client-id)
start-date (coerce/to-date (:start (:date_range args)))
end-date (coerce/to-date (:end (:date_range args)))
comparable-start-date (coerce/to-date (time/minus (:start (:date_range args)) (time/years 1)))
comparable-end-date (coerce/to-date (time/minus (:end (:date_range args)) (time/years 1)))
_ (println args)
all-ledger-entries (full-ledger-for-client client-id)
lookup-account (build-account-lookup client-id)]
(->graphql
{:balance-sheet-accounts (roll-up-until lookup-account all-ledger-entries end-date start-date )
:comparable-balance-sheet-accounts (roll-up-until lookup-account all-ledger-entries comparable-end-date comparable-start-date )})))
{: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]