setup for clients moving much faster

This commit is contained in:
2023-04-05 14:42:25 -07:00
parent d59059fee2
commit 406cddf6e6
3 changed files with 53 additions and 32 deletions

View File

@@ -225,8 +225,8 @@
:with ?s
:in $
:where
[(ground (iol-ion.query/recent-date)) ?min-d]
[?s :sales-order/client [:client/code \"%s\"]]
[(ground (clj-time.coerce/to-date (clj-time.core/minus (auto-ap.time/local-now) (clj-time.core/days 90)))) ?min-d]
[?s :sales-order/date ?d]
[(>= ?d ?min-d)]
[?s :sales-order/total ?total]
@@ -235,9 +235,7 @@
[?s :sales-order/service-charge ?service-charge]
[?s :sales-order/returns ?returns]
[?s :sales-order/discount ?discount]
[(clj-time.coerce/to-date-time ?d) ?d2]
[(auto-ap.time/localize ?d2) ?d3]
[(auto-ap.time/unparse-local ?d3 auto-ap.time/normal-date) ?d4]
[(iol-ion.query/excel-date ?d) ?d4]
]")
(def sales-category-query
@@ -245,8 +243,8 @@
:with ?s ?li
:in $
:where
[(ground (iol-ion.query/recent-date)) ?min-d]
[?s :sales-order/client [:client/code \"%s\"]]
[(ground (clj-time.coerce/to-date (clj-time.core/minus (auto-ap.time/local-now) (clj-time.core/days 90)))) ?min-d]
[?s :sales-order/date ?d]
[(>= ?d ?min-d)]
[?s :sales-order/line-items ?li]
@@ -255,23 +253,22 @@
[?li :order-line-item/total ?total]
[?li :order-line-item/tax ?tax]
[?li :order-line-item/discount ?discount]
[(clj-time.coerce/to-date-time ?d) ?d2]
[(auto-ap.time/localize ?d2) ?d3]
[(auto-ap.time/unparse-local ?d3 auto-ap.time/normal-date) ?d4]
[(iol-ion.query/excel-date ?d) ?d4]
]")
(def expected-deposits-query
"[:find ?d4 ?t ?f
:in $
:where
[(ground (iol-ion.query/recent-date)) ?min-d]
[?c :client/code \"%s\"]
[?s :expected-deposit/client ?c]
[?s :expected-deposit/sales-date ?date]
[(>= ?date ?min-d)]
[?s :expected-deposit/total ?t]
[?s :expected-deposit/fee ?f]
[?s :expected-deposit/sales-date ?date]
[(clj-time.coerce/to-date-time ?date) ?d2]
[(auto-ap.time/localize ?d2) ?d3]
[(auto-ap.time/unparse-local ?d3 auto-ap.time/normal-date) ?d4]
[(iol-ion.query/excel-date ?date) ?d4]
]")
(def tenders-query
@@ -279,9 +276,9 @@
:with ?charge
:in $
:where
[?c :client/code \"%s\"]
[(ground (iol-ion.query/recent-date)) ?min-d]
[?c :client/code \"%s\"]
[?s :sales-order/client ?c]
[(ground (clj-time.coerce/to-date (clj-time.core/minus (auto-ap.time/local-now) (clj-time.core/days 90)))) ?min-d]
[?s :sales-order/date ?date]
[(>= ?date ?min-d)]
[?s :sales-order/charges ?charge]
@@ -291,9 +288,7 @@
[(get-else $ ?charge :charge/processor :na) ?ccp]
[(get-else $ ?ccp :db/ident :na) ?p]
[(name ?p) ?p2]
[(clj-time.coerce/to-date-time ?date) ?d2]
[(auto-ap.time/localize ?d2) ?d3]
[(auto-ap.time/unparse-local ?d3 auto-ap.time/normal-date) ?d4]
[(iol-ion.query/excel-date ?date) ?d4]
]")
(def tenders2-query
@@ -301,8 +296,8 @@
:with ?charge
:in $
:where
[(ground (iol-ion.query/recent-date)) ?min-d]
[?charge :charge/date ?date]
[(ground (clj-time.coerce/to-date (clj-time.core/minus (auto-ap.time/local-now) (clj-time.core/days 90)))) ?min-d]
[(>= ?date ?min-d)]
[?charge :charge/client ?c]
[?c :client/code \"%s\"]
@@ -320,30 +315,28 @@
[(get-else $ ?ccp :db/ident :na) ?p]
))
[(name ?p) ?p2]
[(clj-time.coerce/to-date-time ?date) ?d2]
[(auto-ap.time/localize ?d2) ?d3]
[(auto-ap.time/unparse-local ?d3 auto-ap.time/normal-date) ?d4]]" )
[(iol-ion.query/excel-date ?date) ?d4]
" )
(def refunds-query
"[:find ?d4 ?t (sum ?total) (sum ?fee)
:with ?r
:in $
:where
[(ground (iol-ion.query/recent-date)) ?min-d]
[?r :sales-refund/client [:client/code \"%s\"]]
[?r :sales-refund/date ?date]
[(>= ?date ?min-d)]
[?r :sales-refund/total ?total]
[?r :sales-refund/fee ?fee]
[?r :sales-refund/date ?date]
[?r :sales-refund/type ?t]
[(clj-time.coerce/to-date-time ?date) ?d2]
[(auto-ap.time/localize ?d2) ?d3]
[(auto-ap.time/unparse-local ?d3 auto-ap.time/normal-date) ?d4]]")
[(iol-ion.query/excel-date ?date) ?d4]
]")
(defn setup-sales-queries [context args _]
(assert-admin (:id context))
(let [{client-code :client/code feature-flags :client/feature-flags} (dc/pull (dc/db conn) '[:client/code :client/feature-flags] (:client_id args))
is-new-square? ((set feature-flags) "new-square")]
(defn setup-sales-queries-impl [client-id]
(let [{client-code :client/code feature-flags :client/feature-flags} (dc/pull (dc/db conn) '[:client/code :client/feature-flags] client-id)
is-new-square? ((set feature-flags) "new-square")]
(q/put-query (str (UUID/randomUUID))
(format sales-summary-query client-code)
(str "sales query for " client-code)
@@ -389,6 +382,16 @@
(str "Refund: " "https://app.integreatconsult.com/api/queries/" refund-id "/results/json")])})))
(defn setup-sales-queries [context args _]
(assert-admin (:id context))
(setup-sales-queries-impl (:client_id args)))
(defn reset-all-queries []
(doseq [[c] (dc/q '[:find ?c :where [?c :client/code]] (dc/db conn))]
(setup-sales-queries-impl c)))
(def objects
{:location_match
{:fields {:location {:type 'String}