good s orting across the board.

This commit is contained in:
Bryce Covert
2019-05-04 20:05:35 -07:00
parent 1232033160
commit d63bb566dc
7 changed files with 42 additions and 38 deletions

View File

@@ -762,7 +762,6 @@
(defn add-sorter-field [q sort-map args]
(println sort-map)
(merge-query q
{:query {:find ['?sorter]
:where (sort-map
@@ -774,19 +773,21 @@
sort-fn (sort-by sort-fn)
(= (:asc args) false) (reverse)))
(defn apply-sort-2 [args results ]
(let [comparator
(if (:sort-by args)
(fn [[x & rest-x] [y & rest-y]]
(let [base-sort (if (:asc args)
(compare x y)
(compare y x))]
(if (= 0 base-sort)
(compare (vec rest-y) (vec rest-x))
base-sort)))
(fn [x y]
(compare y x)))]
(defn apply-sort-2 [args default-sort results ]
(let [sort-bys (if (:sort-by args)
(conj (seq default-sort) (if (:asc args)
:asc
:desc))
(seq default-sort))
comparator (fn [xs ys]
(or (->> (map vector sort-bys xs ys)
(map (fn [[asc x y]]
(if (= :asc asc)
(compare x y)
(compare y x))))
(drop-while #(= 0 %))
first)
0))]
(sort comparator results )))
(defn apply-pagination [args results]

View File

@@ -33,9 +33,7 @@
'[?v :vendor/name ?sorter]]
"bank-account" ['[?e :payment/bank-account ?c]
'[?c :bank-account/name ?sorter]]
"check-number" ['(or-join [?e ?sorter]
[?e :payment/check-number ?sorter]
[(ground "" ?sorter)])]
"check-number" ['[?e :payment/check-number ?sorter]]
"date" ['[?e :payment/date ?sorter]]
"amount" ['[?e :payment/amount ?sorter]]
"status" ['[?e :payment/status ?sorter]]}
@@ -113,7 +111,7 @@
(cond->> query
true (d/query)
true (apply-sort-2 args)
true (apply-sort-2 args [:desc :asc])
true (apply-pagination args))))
(defn graphql-results [ids db args]

View File

@@ -92,7 +92,7 @@
(merge-query {:query {:find ['?base-date '?e]
:where ['[?e :invoice/date ?base-date]]}}) )
(d/query)
(apply-sort-2 args)
(apply-sort-2 args [:asc :asc])
(apply-pagination args)))

View File

@@ -75,21 +75,24 @@
:args [(:location args)]})
true
(merge-query {:query {:find ['?e] :where ['[?e :journal-entry/date]]}}))]
(cond->> query
true (d/query)
(:sort-by args) (apply-sort-2 args)
true (apply-pagination args))))
(merge-query {:query {:find ['?base-date '?e] :where ['[?e :journal-entry/date ?base-date]]}}))]
(->> query
(d/query)
(apply-sort-2 args [:desc :asc])
(apply-pagination args))))
(defn graphql-results [ids db args]
(->> (d/pull-many db '[* {:journal-entry/client [:client/name :client/code :db/id]
:journal-entry/vendor [:vendor/name :db/id]
:journal-entry/line-items [* {:journal-entry-line/account [*
{:account/type [*]}
{:bank-account/type [*]}]}]}]
ids)
(map #(update % :journal-entry/date c/from-date))
(apply-sort args (some-> (:sort-by args) sort-fn))))
(let [results (->> (d/pull-many db '[* {:journal-entry/client [:client/name :client/code :db/id]
:journal-entry/vendor [:vendor/name :db/id]
:journal-entry/line-items [* {:journal-entry-line/account [*
{:account/type [*]}
{:bank-account/type [*]}]}]}]
ids)
(map #(update % :journal-entry/date c/from-date))
(group-by :db/id))]
(->> ids
(map results)
(map first))))
(defn get-graphql [args]
(let [db (d/db (d/connect uri))

View File

@@ -83,7 +83,7 @@
'[?e :transaction/date ?base-date]]}}))]
(cond->> query
true (d/query)
true (apply-sort-2 args)
true (apply-sort-2 args [:desc :asc])
true (apply-pagination args))))
(defn graphql-results [ids db args]

View File

@@ -262,7 +262,8 @@
{{:keys [excel-rows]} :edn-params user :identity}
(assert-admin user)
(let [parsed-invoice-rows (parse-invoice-rows excel-rows)
existing-rows (->> (d-invoices/raw-graphql {})
existing-rows (->> (d-invoices/get-graphql {:count Integer/MAX_VALUE})
first
(filter (fn [i] (not= :invoice-status/voided (:invoice/status i))))
(map (fn [{:keys [:invoice/vendor :invoice/client :invoice/invoice-number]}]
[(:db/id vendor) (:db/id client) invoice-number]))

View File

@@ -24,14 +24,15 @@
:check-number check-number
:amount (- amount)
:status :payment-status/pending})
first
first)
(and client-id bank-account-id amount)
(let [matching-checks (d-checks/get-graphql {:client-id client-id
:bank-account-id bank-account-id
:amount (- amount)
:status :payment-status/pending})]
(let [[matching-checks] (d-checks/get-graphql {:client-id client-id
:bank-account-id bank-account-id
:amount (- amount)
:status :payment-status/pending})]
(if (= 1 (count matching-checks))
(first matching-checks)
nil))