From 002c3d868845eeb72c538aa222bee06bfc21284d Mon Sep 17 00:00:00 2001 From: Bryce Date: Wed, 1 May 2024 16:02:15 -0700 Subject: [PATCH] Adds refresh button --- .../auto_ap/jobs/load_historical_sales.clj | 2 +- src/clj/auto_ap/square/core3.clj | 24 ++++++++++----- src/clj/auto_ap/ssr/admin/clients.clj | 30 +++++++++++-------- 3 files changed, 34 insertions(+), 22 deletions(-) diff --git a/src/clj/auto_ap/jobs/load_historical_sales.clj b/src/clj/auto_ap/jobs/load_historical_sales.clj index f7b7286b..ab5f9fb0 100644 --- a/src/clj/auto_ap/jobs/load_historical_sales.clj +++ b/src/clj/auto_ap/jobs/load_historical_sales.clj @@ -22,7 +22,7 @@ (println "orders") (doseq [d (per/periodic-seq (time/plus (time/today) (time/days (- days))) - (time/today) + (time/plus (time/today) (time/days 2)) (time/days 1))] (println d) @(square3/upsert client square-location (coerce/to-date-time d) (coerce/to-date-time (time/plus d (time/days 1))))) diff --git a/src/clj/auto_ap/square/core3.clj b/src/clj/auto_ap/square/core3.clj index 2392ff0e..9aa8278e 100644 --- a/src/clj/auto_ap/square/core3.clj +++ b/src/clj/auto_ap/square/core3.clj @@ -53,6 +53,7 @@ #_#_:connection-request-timeout 5000 :as :json)) (catch Throwable e + (println e) (log/warn ::raw-request-failed :exception e) (throw e))))) @@ -789,13 +790,17 @@ :square-location/square-id (:id square-location)}))))))) #_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]} -(defn reset [] +(defn reset [client] (->> (dc/q {:find ['?e] - :in ['$] - :where ['(or [?e :sales-order/date] - [?e :expected-deposit/date])]} - (dc/db conn)) + :in ['$ '?c] + :where ['(or [?e :sales-order/client ?c] + [?e :expected-deposit/client ?c] + [?e :sales-refund/client ?c] + [?e :charge/client ?c] + [?e :cash-drawer-shift/client ?c])]} + (dc/db conn) + client) (map first) (map (fn [x] [:db/retractEntity x])))) @@ -1008,12 +1013,15 @@ (require 'auto-ap.time-reader) + @(upsert-all "NGPG") - (clojure.pprint/pprint (let [[c [l]] (get-square-client-and-location "NGHW")] + (clojure.pprint/pprint (let [[c [l]] (get-square-client-and-location "NGVT")] + l - (def z @(search c l #clj-time/date-time "2024-04-10T00:00:00-08:00" - #clj-time/date-time "2024-04-13T00:00:00-08:00")))) + + (def z @(search c l #clj-time/date-time "2024-04-25T00:00:00-08:00" + #clj-time/date-time "2024-04-28T00:00:00-08:00")))) (->> z (filter (fn [o] diff --git a/src/clj/auto_ap/ssr/admin/clients.clj b/src/clj/auto_ap/ssr/admin/clients.clj index eea5db8f..98cbed86 100644 --- a/src/clj/auto_ap/ssr/admin/clients.clj +++ b/src/clj/auto_ap/ssr/admin/clients.clj @@ -1324,19 +1324,23 @@ :body (mm/default-step-body {} [:div - (fc/with-field :client/square-auth-token - (com/validated-field - {:errors (fc/field-errors) - :label "Square Auth Token"} - (com/text-input {:name (fc/field-name) - :error? (fc/error?) - :hx-get (bidi/path-for ssr-routes/only-routes ::route/refresh-square-locations) - :hx-trigger "keyup changed delay:1s queue:none" - :hx-indicator "#square-locations" - :hx-target "#square-locations" - :placeholder "Token from square" - :class "w-64" - :value (fc/field-value)}))) + [:div.flex.gap-2.items-center + (fc/with-field :client/square-auth-token + (com/validated-field + {:errors (fc/field-errors) + :label "Square Auth Token"} + (com/text-input {:name (fc/field-name) + :id "square-token" + :error? (fc/error?) + :placeholder "Token from square" + :class "w-64" + :value (fc/field-value)}))) + (com/button {:hx-get (bidi/path-for ssr-routes/only-routes ::route/refresh-square-locations) + :hx-include "#square-token" + :hx-trigger "click" + :hx-indicator "#square-locations" + :hx-target "#square-locations" } + "Refresh")] (fc/with-field :client/square-locations (square-location-table))])