Able to shohw ledger entries.
This commit is contained in:
@@ -39,14 +39,43 @@
|
||||
:where ['[?e :journal-entry/client ?client-id]]}
|
||||
:args [(:client-id args)]})
|
||||
|
||||
(:date-before args)
|
||||
(merge-query {:query {:in ['?date-before]
|
||||
(:to-date args)
|
||||
(merge-query {:query {:in ['?to-date]
|
||||
:where ['[?e :journal-entry/date ?d]
|
||||
'[(<= ?d ?date-before)]]}
|
||||
:args [(:date-before args)]})
|
||||
'[(<= ?d ?to-date)]]}
|
||||
:args [(c/to-date (:to-date args))]})
|
||||
|
||||
(:from-date args)
|
||||
(merge-query {:query {:in ['?from-date]
|
||||
:where ['[?e :journal-entry/date ?d]
|
||||
'[(>= ?d ?from-date)]]}
|
||||
:args [(c/to-date (:from-date args))]})
|
||||
|
||||
(:from-numeric-code args)
|
||||
(merge-query {:query {:in ['?from-numeric-code]
|
||||
:where ['[?e :journal-entry/line-items ?li]
|
||||
'[?li :journal-entry-line/account ?a]
|
||||
'[?a :account/numeric-code ?c]
|
||||
'[(>= ?c ?from-numeric-code)]]}
|
||||
:args [(:from-numeric-code args)]})
|
||||
|
||||
(:to-numeric-code args)
|
||||
(merge-query {:query {:in ['?to-numeric-code]
|
||||
:where ['[?e :journal-entry/line-items ?li]
|
||||
'[?li :journal-entry-line/account ?a]
|
||||
'[?a :account/numeric-code ?c]
|
||||
'[(<= ?c ?to-numeric-code)]]}
|
||||
:args [(:to-numeric-code args)]})
|
||||
|
||||
(:location args)
|
||||
(merge-query {:query {:in ['?location]
|
||||
:where ['[?e :journal-entry/line-items ?li]
|
||||
'[?li :journal-entry-line/location ?location]]}
|
||||
:args [(:location args)]})
|
||||
|
||||
true
|
||||
(merge-query {:query {:find ['?e] :where ['[?e :journal-entry/date]]}}))]
|
||||
(println query)
|
||||
(cond->> query
|
||||
true (d/query)
|
||||
(:sort-by args) (apply-sort-2 args)
|
||||
@@ -57,9 +86,7 @@
|
||||
:journal-entry/vendor [:vendor/name :db/id]
|
||||
:journal-entry/line-items [* {:journal-entry-line/account [*
|
||||
{:account/type [*]}
|
||||
{:bank-account/type [*]}]}]
|
||||
|
||||
}]
|
||||
{:bank-account/type [*]}]}]}]
|
||||
ids)
|
||||
(map #(update % :journal-entry/date c/from-date))
|
||||
(apply-sort args (some-> (:sort-by args) sort-fn))))
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
[auto-ap.graphql.utils :refer [assert-admin can-see-client? assert-can-see-client]]
|
||||
[auto-ap.datomic :refer [uri merge-query]]
|
||||
[datomic.api :as d]
|
||||
[clj-time.coerce :as coerce]
|
||||
[auto-ap.datomic.clients :as d-clients]
|
||||
[auto-ap.datomic.checks :as d-checks]
|
||||
[auto-ap.datomic.users :as d-users]
|
||||
@@ -23,6 +24,7 @@
|
||||
[auto-ap.graphql.checks :as gq-checks]
|
||||
[auto-ap.graphql.invoices :as gq-invoices]
|
||||
[auto-ap.graphql.transactions :as gq-transactions]
|
||||
[auto-ap.time :as time]
|
||||
[clojure.walk :as walk]
|
||||
[clojure.string :as str])
|
||||
(:import
|
||||
@@ -31,11 +33,12 @@
|
||||
|
||||
(def integreat-schema
|
||||
{
|
||||
:scalars {:id {
|
||||
:parse (schema/as-conformer #(when % (Long/parseLong %)))
|
||||
:scalars {:id {:parse (schema/as-conformer #(when % (Long/parseLong %)))
|
||||
:serialize (schema/as-conformer #(.toString %))}
|
||||
:ident {:parse (schema/as-conformer (fn [x] {:db/ident x}))
|
||||
:serialize (schema/as-conformer #(or (:ident %) (:db/ident %) %))}}
|
||||
:serialize (schema/as-conformer #(or (:ident %) (:db/ident %) %))}
|
||||
:iso_date {:parse (schema/as-conformer #(coerce/to-date-time %))
|
||||
:serialize (schema/as-conformer #(time/unparse % time/iso-date))}}
|
||||
:objects
|
||||
{
|
||||
:client
|
||||
@@ -331,6 +334,11 @@
|
||||
:ledger_page {:type :ledger_page
|
||||
:args {:client_id {:type :id}
|
||||
:bank_account_id {:type :id}
|
||||
:from_date {:type :iso_date}
|
||||
:to_date {:type :iso_date}
|
||||
:location {:type 'String}
|
||||
:from_numeric_code {:type 'Int}
|
||||
:to_numeric_code {:type 'Int}
|
||||
:start {:type 'Int}
|
||||
:sort_by {:type 'String}
|
||||
:asc {:type 'Boolean}}
|
||||
|
||||
@@ -72,35 +72,33 @@
|
||||
(:db/ident (:bank-account/type account))))
|
||||
:amount (reduce + 0 (map
|
||||
(fn [line-item]
|
||||
(doto
|
||||
(cond
|
||||
(and (credit-account? account) (:journal-entry-line/debit line-item))
|
||||
(- (:journal-entry-line/debit line-item))
|
||||
(cond
|
||||
(and (credit-account? account) (:journal-entry-line/debit line-item))
|
||||
(- (:journal-entry-line/debit line-item))
|
||||
|
||||
(and (credit-account? account) (:journal-entry-line/credit line-item))
|
||||
(:journal-entry-line/credit line-item)
|
||||
(and (credit-account? account) (:journal-entry-line/credit line-item))
|
||||
(:journal-entry-line/credit line-item)
|
||||
|
||||
(and (debit-account? account) (:journal-entry-line/debit line-item))
|
||||
(:journal-entry-line/debit line-item)
|
||||
(and (debit-account? account) (:journal-entry-line/debit line-item))
|
||||
(:journal-entry-line/debit line-item)
|
||||
|
||||
(and (debit-account? account) (:journal-entry-line/credit line-item))
|
||||
(- (:journal-entry-line/credit line-item))
|
||||
(and (debit-account? account) (:journal-entry-line/credit line-item))
|
||||
(- (:journal-entry-line/credit line-item))
|
||||
|
||||
:else
|
||||
0.0)
|
||||
println))
|
||||
:else
|
||||
0.0))
|
||||
line-items))}))
|
||||
[])))
|
||||
|
||||
(defn get-balance-sheet [context args value]
|
||||
(let [args (assoc args :id (:id context))
|
||||
[results] (l/get-graphql {:client-id (:client_id args)
|
||||
:date-before (coerce/to-date (:date args))
|
||||
:to-date (coerce/to-date (:date args))
|
||||
:count Integer/MAX_VALUE})
|
||||
_ (println (roll-up results))
|
||||
|
||||
|
||||
[comparable-results] (l/get-graphql {:client-id (:client_id args)
|
||||
:date-before (coerce/to-date (time/minus (parse (:date args) iso-date) (time/years 1)))
|
||||
:to-date (coerce/to-date (time/minus (parse (:date args) iso-date) (time/years 1)))
|
||||
:count Integer/MAX_VALUE})]
|
||||
(->graphql
|
||||
{:balance-sheet-accounts (roll-up results)
|
||||
@@ -111,10 +109,10 @@
|
||||
(let [args (assoc args :id (:id context))
|
||||
pnl (fn [from-date to-date]
|
||||
(let [[starting-results] (l/get-graphql {:client-id (:client_id args)
|
||||
:date-before from-date
|
||||
:to-date from-date
|
||||
:count Integer/MAX_VALUE})
|
||||
[ending-results] (l/get-graphql {:client-id (:client_id args)
|
||||
:date-before to-date
|
||||
:to-date to-date
|
||||
:count Integer/MAX_VALUE})
|
||||
starting-accounts (by :id (roll-up starting-results))
|
||||
ending-accounts (by :id (roll-up ending-results))]
|
||||
|
||||
Reference in New Issue
Block a user