adding most simple balance sheet report.
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
(ns auto-ap.datomic.ledger
|
||||
(:require [datomic.api :as d]
|
||||
[auto-ap.graphql.utils :refer [->graphql limited-clients]]
|
||||
[auto-ap.datomic :refer [merge-query ]]
|
||||
[auto-ap.datomic :refer [merge-query apply-sort-2 apply-sort apply-pagination add-sorter-field]]
|
||||
[auto-ap.datomic :refer [uri]]
|
||||
[clj-time.coerce :as c]))
|
||||
|
||||
@@ -16,33 +16,8 @@
|
||||
:else
|
||||
(keyword "transaction" sort-by)))
|
||||
|
||||
(defn add-sorter-field [q sort-map args]
|
||||
(merge-query q
|
||||
{:query {:find ['?sorter]
|
||||
:where (sort-map
|
||||
(:sort-by args)
|
||||
(println "Warning, trying to sort by unsupported field" (:sort-by args)))}}))
|
||||
|
||||
(defn apply-sort [args sort-fn results ]
|
||||
(cond->> results
|
||||
sort-fn (sort-by sort-fn)
|
||||
(= (:asc args) false) (reverse)))
|
||||
|
||||
(defn apply-sort-2 [args results ]
|
||||
(let [comparator (if (= (:asc args) false)
|
||||
(fn [x y] (compare y x))
|
||||
(fn [x y] (compare x y)))]
|
||||
(sort comparator results )))
|
||||
|
||||
(defn apply-pagination [args results]
|
||||
|
||||
{:ids (->> results
|
||||
(drop (:start args 0))
|
||||
(take (:count args 100))
|
||||
(map last))
|
||||
:count (count results)})
|
||||
|
||||
(defn raw-graphql-ids [db args]
|
||||
(println args)
|
||||
(let [query (cond-> {:query {:find []
|
||||
:in ['$ ]
|
||||
:where []}
|
||||
@@ -59,16 +34,17 @@
|
||||
:where ['[?e :journal-entry/client ?xx]]}
|
||||
:args [(set (map :db/id (limited-clients (:id args))))]})
|
||||
|
||||
#_(:bank-account-id args)
|
||||
#_(merge-query {:query {:in ['?bank-account-id]
|
||||
:where ['[?e :transaction/bank-account ?bank-account-id]]}
|
||||
:args [(:bank-account-id args)]})
|
||||
|
||||
(:client-id args)
|
||||
(merge-query {:query {:in ['?client-id]
|
||||
:where ['[?e :journal-entry/client ?client-id]]}
|
||||
:args [(:client-id args)]})
|
||||
|
||||
(:date-before args)
|
||||
(merge-query {:query {:in ['?date-before]
|
||||
:where ['[?e :journal-entry/date ?d]
|
||||
'[(<= ?d ?date-before)]]}
|
||||
:args [(:date-before args)]})
|
||||
|
||||
true
|
||||
(merge-query {:query {:find ['?e] :where ['[?e :journal-entry/original-entity]]}}))]
|
||||
(cond->> query
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
(ns auto-ap.datomic.transactions
|
||||
(:require [datomic.api :as d]
|
||||
[auto-ap.datomic :refer [uri merge-query]]
|
||||
[auto-ap.datomic :refer [uri merge-query apply-sort-2 apply-sort apply-pagination add-sorter-field]]
|
||||
[auto-ap.graphql.utils :refer [limited-clients]]
|
||||
[clj-time.coerce :as c]))
|
||||
|
||||
@@ -15,31 +15,6 @@
|
||||
:else
|
||||
(keyword "transaction" sort-by)))
|
||||
|
||||
(defn add-sorter-field [q sort-map args]
|
||||
(merge-query q
|
||||
{:query {:find ['?sorter]
|
||||
:where (sort-map
|
||||
(:sort-by args)
|
||||
(println "Warning, trying to sort by unsupported field" (:sort-by args)))}}))
|
||||
|
||||
(defn apply-sort [args sort-fn results ]
|
||||
(cond->> results
|
||||
sort-fn (sort-by sort-fn)
|
||||
(= (:asc args) false) (reverse)))
|
||||
|
||||
(defn apply-sort-2 [args results ]
|
||||
(let [comparator (if (= (:asc args) false)
|
||||
(fn [x y] (compare y x))
|
||||
(fn [x y] (compare x y)))]
|
||||
(sort comparator results )))
|
||||
|
||||
(defn apply-pagination [args results]
|
||||
|
||||
{:ids (->> results
|
||||
(drop (:start args 0))
|
||||
(take (:count args 100))
|
||||
(map last))
|
||||
:count (count results)})
|
||||
|
||||
(defn raw-graphql-ids [db args]
|
||||
(let [query (cond-> {:query {:find []
|
||||
|
||||
Reference in New Issue
Block a user