updates to prevent in-progress orders

This commit is contained in:
2021-09-14 07:18:39 -07:00
parent a007b04685
commit e9c752fb3c
3 changed files with 143 additions and 5 deletions

View File

@@ -360,3 +360,110 @@ sx
(get-settlement-details )
;; working on determing if there are still uncompleted orders
(with-redefs [location_id->client-location (fn location_id->client-location [location]
({"L7S9MXZBJ00HY" ["NGGG" "LM"]} location))
pc (fn [d] {"query" {"filter" {"date_time_filter"
{
"created_at" {
"start_at" (f/unparse (f/formatter "YYYY-MM-dd'T'HH:mm:ssZZ") (time/to-time-zone (coerce/to-date-time d) (time/time-zone-for-id "America/Los_Angeles")))
"end_at" (f/unparse (f/formatter "YYYY-MM-dd'T'HH:mm:ssZZ") (time/to-time-zone (time/plus (coerce/to-date-time d) (time/days 1)) (time/time-zone-for-id "America/Los_Angeles")))
}
}
"state_filter" {"states" ["COMPLETED"]}}
"sort" {
"sort_field" "CREATED_AT"
"sort_order" "DESC"
}}})
daily-results (fn daily-results [d]
(->> (locations)
(map :id)
(filter location_id->client-location)
(mapcat #(search % d))
(filter (fn [order]
(and (not= #{"FAILED"}
(set (map #(:status (:card_details %)) (:tenders order)))))))
(map order->sales-order)))]
(->> (-> []
(into (daily-results #inst "2021-09-05T00:00:00-08:00"))
(into (daily-results #inst "2021-09-06T00:00:00-08:00"))
(into (daily-results #inst "2021-09-07T00:00:00-08:00")))
(filter #(= "09/06/2021" (auto-ap.time/unparse-local (auto-ap.time/localize (coerce/to-date-time (:sales-order/date %))) auto-ap.time/normal-date)))
(mapcat :sales-order/charges)
(group-by :charge/type-name)
(map (fn [[x y]]
[x (count y)]))))
(with-redefs [location_id->client-location (fn location_id->client-location [location]
({"L7S9MXZBJ00HY" ["NGGG" "LM"]} location))
pc (fn [d] {"query" {"filter" {"date_time_filter"
{
"created_at" {
"start_at" (f/unparse (f/formatter "YYYY-MM-dd'T'HH:mm:ssZZ") (time/to-time-zone (coerce/to-date-time d) (time/time-zone-for-id "America/Los_Angeles")))
"end_at" (f/unparse (f/formatter "YYYY-MM-dd'T'HH:mm:ssZZ") (time/to-time-zone (time/plus (coerce/to-date-time d) (time/days 1)) (time/time-zone-for-id "America/Los_Angeles")))
}
}
}
"sort" {
"sort_field" "CREATED_AT"
"sort_order" "DESC"
}}})]
(->> (-> []
(into (search "L7S9MXZBJ00HY" #inst "2021-09-05T00:00:00-08:00"))
(into (search "L7S9MXZBJ00HY" #inst "2021-09-06T00:00:00-08:00"))
(into (search "L7S9MXZBJ00HY" #inst "2021-09-07T00:00:00-08:00")))
(filter #(= "09/06/2021" (auto-ap.time/unparse-local (auto-ap.time/localize (coerce/to-date-time (:created_at %))) auto-ap.time/normal-date)))
(filter (fn [order]
(and (not= #{"FAILED"}
(set (map #(:status (:card_details %)) (:tenders order))))
(> (count (:tenders order)) 0))
))
count))
;; 145 if you only do completed, 117 if you don't
(->> (d/q '[:find ?d4 ?type ?p2 (sum ?total) (sum ?tip)
:with ?charge
:in $
:where
[?c :client/code "NGGG"]
[?s :sales-order/client ?c]
[?s :sales-order/charges ?charge]
[?charge :charge/type-name ?type]
[?charge :charge/total ?total]
[?charge :charge/tip ?tip]
[(get-else $ ?charge :charge/processor :na) ?ccp]
[(get-else $ ?ccp :db/ident :na) ?p]
[(name ?p) ?p2]
[?s :sales-order/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]
[(= "09/06/2021" ?d4)]]
(d/db conn))
(sort-by first))
(doseq [d (clj-time.periodic/periodic-seq (time/plus (time/now) (time/days -15))
(time/now)
(time/days 1))]
(upsert d))
(d/pull (d/db conn) '[* {:invoice/status [:db/ident]} ] 17592240679462)