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)

View File

@@ -100,8 +100,7 @@
}
"state_filter" {"states" ["COMPLETED"]}}
}}
"sort" {
"sort_field" "CREATED_AT"
@@ -235,7 +234,9 @@
(filter location_id->client-location)
(mapcat #(search % d))
(filter (fn [order]
(and (= "COMPLETED" (:state order))
;; sometimes orders stay open in square. At least one payment
;; is needed to import, in order to avoid importing orders in-progress.
(and (> (count (:tenders order)) 0)
(not= #{"FAILED"}
(set (map #(:status (:card_details %)) (:tenders order)))))))
(map order->sales-order)))
@@ -488,7 +489,9 @@
(comment
(daily-results)
(mount/stop (mount/only #{'auto-ap.square.core/square-settlement-loader}))
(mount/stop (mount/only #{'auto-ap.square.core/square-refund-loader}))
(mount/stop (mount/only #{'auto-ap.square.core/square-loader}))
(mount/start (mount/only #{'auto-ap.square.core/square-settlement-loader}))

View File

@@ -1,7 +1,8 @@
(ns user
(:require [auto-ap.datomic :refer [uri]]
[config.core :refer [env]]
[auto-ap.utils :refer [by]]
[clojure.core.async :as async]
#_[auto-ap.ledger :as l]
[mount.core :as mount]
[auto-ap.server ]
@@ -10,7 +11,8 @@
[clj-time.coerce :as c]
[clj-time.core :as t]
[clojure.java.io :as io]
[clojure.string :as str])
[clojure.string :as str]
[amazonica.aws.s3 :as s3])
(:import [org.apache.commons.io.input BOMInputStream]))
(defn mark-until-date [client end]
@@ -444,3 +446,29 @@
(for [r data]
((apply juxt columns) r )))))
(defn find-queries [words]
(let [obj (s3/list-objects-v2 :bucket-name (:data-bucket env)
:prefix (str "queries/"))]
(let [concurrent 30
output-chan (async/chan)]
(async/pipeline-blocking concurrent
output-chan
(comp
(map #(do
(println "looking up " (:key %))
[(:key %)
(str (slurp (:object-content (s3/get-object
:bucket-name (:data-bucket env)
:key (:key %)))))]))
(filter #(->> words
(every? (fn [w] (str/includes? (second %) w)))))
(map first)
(map #(str/replace % #"queries/" ""))
)
(async/to-chan (:object-summaries obj))
true
(fn [e]
(println "failed " e)))
(async/<!! (async/into [] output-chan)))))