links deposits to charges.

This commit is contained in:
2022-06-24 16:36:17 -07:00
parent 616798cebf
commit ecb12b712c
2 changed files with 29 additions and 10 deletions

View File

@@ -246,6 +246,15 @@
:add-sales-date
:add-vendor-for-sales-stuff
:add-orders]}
:add-charge-id2 {:txes [[{:db/ident :charge/external-id
:db/doc "The client for the sale"
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one
:db/unique :db.unique/identity}]]}
:add-expected-depsoit-link {:txes [[{:db/ident :expected-deposit/charges
:db/doc "charges for the deposit"
:db/valueType :db.type/ref
:db/cardinality :db.cardinality/many}]]}
:add-refund-type {:txes [[{:db/ident :sales-refund/type
:db/doc "The type of refund"
:db/valueType :db.type/string

View File

@@ -178,6 +178,7 @@
(remove-nils
#:charge
{:type-name (:type t)
:external-id (str "square/charge/" (:id t))
:processor (condp = (some-> (:note t) str/lower-case)
"doordash" :ccp-processor/doordash
"dd" :ccp-processor/doordash
@@ -344,7 +345,10 @@
(coerce/to-date))
:sales-date (or (:sales-date settlement)
(-> (:initiated_at settlement)
(coerce/to-date)))})
(coerce/to-date)))
:charges (->> (:entries settlement)
(filter :payment_id)
(map (fn [p] {:charge/external-id (str "square/charge/" (:payment_id p))})))})
(filter :expected-deposit/date))))
@@ -453,13 +457,18 @@
:client/square-auth-token
{:client/square-locations [:db/id :square-location/name :square-location/square-id :square-location/client-location]}])
(defn get-square-clients []
(d/q '[:find [(pull ?c [:db/id
:client/code
:client/square-auth-token
{:client/square-locations [:db/id :square-location/name :square-location/square-id :square-location/client-location]}]) ...]
:where [?c :client/square-auth-token]]
(d/db conn)))
(defn get-square-clients
([] (get-square-clients nil))
([code]
(d/q '[:find [(pull ?c [:db/id
:client/code
:client/square-auth-token
{:client/square-locations [:db/id :square-location/name :square-location/square-id :square-location/client-location]}]) ...]
:in $ ?code
:where [?c :client/square-auth-token]
[?c :client/code ?code]]
(d/db conn)
code)))
(defn upsert-locations
([] (doseq [client (get-square-clients)]
@@ -483,13 +492,14 @@
(->>
(d/query {:query {:find ['?e]
:in ['$]
:where ['[?e :sales-order/date]]}
:where ['(or [?e :sales-order/date]
[?e :expected-deposit/date])]}
:args [(d/db conn)]})
(map first)
(map (fn [x] [:db/retractEntity x]))))
(defn upsert-all []
(doseq [client (get-square-clients)
(doseq [client ((get-square-clients))
:when (seq (filter :square-location/client-location (:client/square-locations client)))]
(lc/with-context {:client (:client/code client)}
(upsert-locations client)