good s orting across the board.
This commit is contained in:
@@ -762,7 +762,6 @@
|
|||||||
|
|
||||||
|
|
||||||
(defn add-sorter-field [q sort-map args]
|
(defn add-sorter-field [q sort-map args]
|
||||||
(println sort-map)
|
|
||||||
(merge-query q
|
(merge-query q
|
||||||
{:query {:find ['?sorter]
|
{:query {:find ['?sorter]
|
||||||
:where (sort-map
|
:where (sort-map
|
||||||
@@ -774,19 +773,21 @@
|
|||||||
sort-fn (sort-by sort-fn)
|
sort-fn (sort-by sort-fn)
|
||||||
(= (:asc args) false) (reverse)))
|
(= (:asc args) false) (reverse)))
|
||||||
|
|
||||||
(defn apply-sort-2 [args results ]
|
(defn apply-sort-2 [args default-sort results ]
|
||||||
(let [comparator
|
(let [sort-bys (if (:sort-by args)
|
||||||
(if (:sort-by args)
|
(conj (seq default-sort) (if (:asc args)
|
||||||
(fn [[x & rest-x] [y & rest-y]]
|
:asc
|
||||||
(let [base-sort (if (:asc args)
|
:desc))
|
||||||
(compare x y)
|
(seq default-sort))
|
||||||
(compare y x))]
|
comparator (fn [xs ys]
|
||||||
|
(or (->> (map vector sort-bys xs ys)
|
||||||
(if (= 0 base-sort)
|
(map (fn [[asc x y]]
|
||||||
(compare (vec rest-y) (vec rest-x))
|
(if (= :asc asc)
|
||||||
base-sort)))
|
(compare x y)
|
||||||
(fn [x y]
|
(compare y x))))
|
||||||
(compare y x)))]
|
(drop-while #(= 0 %))
|
||||||
|
first)
|
||||||
|
0))]
|
||||||
(sort comparator results )))
|
(sort comparator results )))
|
||||||
|
|
||||||
(defn apply-pagination [args results]
|
(defn apply-pagination [args results]
|
||||||
|
|||||||
@@ -33,9 +33,7 @@
|
|||||||
'[?v :vendor/name ?sorter]]
|
'[?v :vendor/name ?sorter]]
|
||||||
"bank-account" ['[?e :payment/bank-account ?c]
|
"bank-account" ['[?e :payment/bank-account ?c]
|
||||||
'[?c :bank-account/name ?sorter]]
|
'[?c :bank-account/name ?sorter]]
|
||||||
"check-number" ['(or-join [?e ?sorter]
|
"check-number" ['[?e :payment/check-number ?sorter]]
|
||||||
[?e :payment/check-number ?sorter]
|
|
||||||
[(ground "" ?sorter)])]
|
|
||||||
"date" ['[?e :payment/date ?sorter]]
|
"date" ['[?e :payment/date ?sorter]]
|
||||||
"amount" ['[?e :payment/amount ?sorter]]
|
"amount" ['[?e :payment/amount ?sorter]]
|
||||||
"status" ['[?e :payment/status ?sorter]]}
|
"status" ['[?e :payment/status ?sorter]]}
|
||||||
@@ -113,7 +111,7 @@
|
|||||||
|
|
||||||
(cond->> query
|
(cond->> query
|
||||||
true (d/query)
|
true (d/query)
|
||||||
true (apply-sort-2 args)
|
true (apply-sort-2 args [:desc :asc])
|
||||||
true (apply-pagination args))))
|
true (apply-pagination args))))
|
||||||
|
|
||||||
(defn graphql-results [ids db args]
|
(defn graphql-results [ids db args]
|
||||||
|
|||||||
@@ -92,7 +92,7 @@
|
|||||||
(merge-query {:query {:find ['?base-date '?e]
|
(merge-query {:query {:find ['?base-date '?e]
|
||||||
:where ['[?e :invoice/date ?base-date]]}}) )
|
:where ['[?e :invoice/date ?base-date]]}}) )
|
||||||
(d/query)
|
(d/query)
|
||||||
(apply-sort-2 args)
|
(apply-sort-2 args [:asc :asc])
|
||||||
(apply-pagination args)))
|
(apply-pagination args)))
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -75,21 +75,24 @@
|
|||||||
:args [(:location args)]})
|
:args [(:location args)]})
|
||||||
|
|
||||||
true
|
true
|
||||||
(merge-query {:query {:find ['?e] :where ['[?e :journal-entry/date]]}}))]
|
(merge-query {:query {:find ['?base-date '?e] :where ['[?e :journal-entry/date ?base-date]]}}))]
|
||||||
(cond->> query
|
(->> query
|
||||||
true (d/query)
|
(d/query)
|
||||||
(:sort-by args) (apply-sort-2 args)
|
(apply-sort-2 args [:desc :asc])
|
||||||
true (apply-pagination args))))
|
(apply-pagination args))))
|
||||||
|
|
||||||
(defn graphql-results [ids db args]
|
(defn graphql-results [ids db args]
|
||||||
(->> (d/pull-many db '[* {:journal-entry/client [:client/name :client/code :db/id]
|
(let [results (->> (d/pull-many db '[* {:journal-entry/client [:client/name :client/code :db/id]
|
||||||
:journal-entry/vendor [:vendor/name :db/id]
|
:journal-entry/vendor [:vendor/name :db/id]
|
||||||
:journal-entry/line-items [* {:journal-entry-line/account [*
|
:journal-entry/line-items [* {:journal-entry-line/account [*
|
||||||
{:account/type [*]}
|
{:account/type [*]}
|
||||||
{:bank-account/type [*]}]}]}]
|
{:bank-account/type [*]}]}]}]
|
||||||
ids)
|
ids)
|
||||||
(map #(update % :journal-entry/date c/from-date))
|
(map #(update % :journal-entry/date c/from-date))
|
||||||
(apply-sort args (some-> (:sort-by args) sort-fn))))
|
(group-by :db/id))]
|
||||||
|
(->> ids
|
||||||
|
(map results)
|
||||||
|
(map first))))
|
||||||
|
|
||||||
(defn get-graphql [args]
|
(defn get-graphql [args]
|
||||||
(let [db (d/db (d/connect uri))
|
(let [db (d/db (d/connect uri))
|
||||||
|
|||||||
@@ -83,7 +83,7 @@
|
|||||||
'[?e :transaction/date ?base-date]]}}))]
|
'[?e :transaction/date ?base-date]]}}))]
|
||||||
(cond->> query
|
(cond->> query
|
||||||
true (d/query)
|
true (d/query)
|
||||||
true (apply-sort-2 args)
|
true (apply-sort-2 args [:desc :asc])
|
||||||
true (apply-pagination args))))
|
true (apply-pagination args))))
|
||||||
|
|
||||||
(defn graphql-results [ids db args]
|
(defn graphql-results [ids db args]
|
||||||
|
|||||||
@@ -262,7 +262,8 @@
|
|||||||
{{:keys [excel-rows]} :edn-params user :identity}
|
{{:keys [excel-rows]} :edn-params user :identity}
|
||||||
(assert-admin user)
|
(assert-admin user)
|
||||||
(let [parsed-invoice-rows (parse-invoice-rows excel-rows)
|
(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))))
|
(filter (fn [i] (not= :invoice-status/voided (:invoice/status i))))
|
||||||
(map (fn [{:keys [:invoice/vendor :invoice/client :invoice/invoice-number]}]
|
(map (fn [{:keys [:invoice/vendor :invoice/client :invoice/invoice-number]}]
|
||||||
[(:db/id vendor) (:db/id client) invoice-number]))
|
[(:db/id vendor) (:db/id client) invoice-number]))
|
||||||
|
|||||||
@@ -24,14 +24,15 @@
|
|||||||
:check-number check-number
|
:check-number check-number
|
||||||
:amount (- amount)
|
:amount (- amount)
|
||||||
:status :payment-status/pending})
|
:status :payment-status/pending})
|
||||||
|
first
|
||||||
first)
|
first)
|
||||||
|
|
||||||
(and client-id bank-account-id amount)
|
(and client-id bank-account-id amount)
|
||||||
|
|
||||||
(let [matching-checks (d-checks/get-graphql {:client-id client-id
|
(let [[matching-checks] (d-checks/get-graphql {:client-id client-id
|
||||||
:bank-account-id bank-account-id
|
:bank-account-id bank-account-id
|
||||||
:amount (- amount)
|
:amount (- amount)
|
||||||
:status :payment-status/pending})]
|
:status :payment-status/pending})]
|
||||||
(if (= 1 (count matching-checks))
|
(if (= 1 (count matching-checks))
|
||||||
(first matching-checks)
|
(first matching-checks)
|
||||||
nil))
|
nil))
|
||||||
|
|||||||
Reference in New Issue
Block a user