This commit is contained in:
Bryce Covert
2021-08-24 09:52:30 -07:00
7 changed files with 119 additions and 46 deletions

View File

@@ -1056,6 +1056,10 @@
:args {:invoice_id {:type :id}}
:resolve :mutation/unvoid-invoice}
:unautopay_invoice {:type :invoice
:args {:invoice_id {:type :id}}
:resolve :mutation/unautopay-invoice}
:void_payment {:type :payment
:args {:payment_id {:type :id}}
:resolve :mutation/void-payment}
@@ -1343,6 +1347,7 @@
:mutation/merge-vendors gq-vendors/merge-vendors
:mutation/void-invoice gq-invoices/void-invoice
:mutation/unvoid-invoice gq-invoices/unvoid-invoice
:mutation/unautopay-invoice gq-invoices/unautopay-invoice
:mutation/void-payment gq-checks/void-check
:mutation/edit-expense-accounts gq-invoices/edit-expense-accounts
:mutation/import-ledger gq-ledger/import-ledger

View File

@@ -239,6 +239,18 @@
(-> (d-invoices/get-by-id id)
(->graphql))))
(defn unautopay-invoice [context {id :invoice_id} value]
(let [invoice (d/entity (d/db conn) id)
_ (assert (:invoice/client invoice))
_ (assert-can-see-client (:id context) (:db/id (:invoice/client invoice)))]
(audit-transact [[:db/add id :invoice/status :invoice-status/unpaid]
[:db/add id :invoice/outstanding-balance (:invoice/total invoice)]
[:db/retract id :invoice/scheduled-payment (:invoice/scheduled-payment invoice)]]
(:id context))
(-> (d-invoices/get-by-id id)
(->graphql))))
(defn edit-expense-accounts [context args value]
(assert-can-see-client (:id context) (:db/id (:invoice/client (d-invoices/get-by-id (:invoice_id args)))))
(let [invoice-id (:invoice_id args)

View File

@@ -128,6 +128,19 @@
result)))
(defn order
([o]
(log/info "Searching for" o)
(let [result (->> (client/get (str "https://connect.squareup.com/v2/orders/" o)
{:headers {"Square-Version" "2020-08-12"
"Authorization" "Bearer EAAAEO2xSqesDutZz71hz3eulKmrlKTiEqG3uZ4j25x5GYlOluQ2cj2JxNUXqXD7"
"Content-Type" "application/json"}
:as :json})
:body)]
(log/info "found " (count result))
result)))
(defn amount->money [amt]
(* 0.01 (or (:amount amt) 0.0)))
@@ -150,7 +163,8 @@
"LQTHXQY69MYB6" ["NGDG" "DB"]
"L7S9MXZBJ00HY" ["NGGG" "LM"]
"LRC7WVD77ZM81" ["NGLK" "SM"]
"FZ3ZYC77T3W1T" ["NGA1" "KA"]} location))
"FZ3ZYC77T3W1T" ["NGA1" "KA"]
"LG5X0MHA4NZDM" ["NGSM" "SM"]} location))
;; to get totals:
(comment
@@ -190,8 +204,8 @@
:returns (+ (- (-> order :return_amounts :total_money amount->money)
(-> order :return_amounts :tax_money amount->money)
(-> order :return_amounts :tip_money amount->money)
(-> order :return_amounts :service_charge_money amount->money)
(-> order :return_amounts :discount_money amount->money)))
(-> order :return_amounts :service_charge_money amount->money))
(-> order :return_amounts :discount_money amount->money))
:charges (->> (:tenders order)
(map (fn [t]
(remove-nils
@@ -217,7 +231,9 @@
(remove-nils
#:order-line-item
{:item-name (:name li)
:category (item-id->category-name (:catalog_object_id li))
:category (if (= "GIFT_CARD" (:item_type li))
"Gift Card"
(item-id->category-name (:catalog_object_id li)))
:total (amount->money (:total_money li))
:tax (amount->money (:total_tax_money li))
:discount (amount->money (:total_discount_money li))}))))}))))))
@@ -263,10 +279,12 @@
(if (> try-count 4) false true))})))]
n))))))
(defn daily-settlements []
(->> (locations)
(map :id)
(filter location_id->client-location)
(defn daily-settlements
([] (daily-settlements (->> (locations)
(map :id)
(filter location_id->client-location))))
([location-ids]
(->> location-ids
(mapcat (fn [l]
(for [settlement (settlements l)
:let [[client loc] (location_id->client-location l)]]
@@ -274,13 +292,15 @@
:total (amount->money (:total_money settlement))
:client [:client/code client]
:location loc
:fee (- (reduce + 0 (map (fn [entry]
(if (= (:type entry) "REFUND")
(- (amount->money (:fee_money entry)))
(amount->money (:fee_money entry))))
(:entries settlement))))
:fee (- (reduce + 0.0 (map (fn [entry]
(if (= (:type entry) "REFUND")
(- (amount->money (:fee_money entry)))
(amount->money (:fee_money entry))))
(:entries settlement))))
:date (-> (:initiated_at settlement)
(coerce/to-date))})))))
(coerce/to-date))})))
(filter :expected-deposit/date)))
)
(defn refunds [l]
(let [refunds (:refunds (:body (client/get (str "https://connect.squareup.com/v2/refunds?location_id=" l)
@@ -329,24 +349,28 @@
(catch Exception e
(log/error e))))))
(defn upsert-settlements []
(lc/with-context {:source "Square settlements loading "}
(try
(let [existing (->> (d/query {:query {:find ['?external-id]
:in ['$]
:where ['[_ :expected-deposit/external-id ?external-id]]}
:args [(d/db conn)]})
(map first)
set)
_ (log/info (count existing) "settlements already exist")
to-create (filter #(not (existing (:expected-deposit/external-id %)))
(daily-settlements))]
(doseq [x (partition-all 20 to-create)]
(log/info "Loading expected deposit" (count x))
@(d/transact conn x)))
(catch Exception e
(log/error e)))
(log/info "Done loading settlements")))
(defn upsert-settlements
([] (upsert-settlements nil))
([location-ids]
(lc/with-context {:source "Square settlements loading "}
(try
(let [existing (->> (d/query {:query {:find ['?external-id]
:in ['$]
:where ['[_ :expected-deposit/external-id ?external-id]]}
:args [(d/db conn)]})
(map first)
set)
_ (log/info (count existing) "settlements already exist")
to-create (filter #(not (existing (:expected-deposit/external-id %)))
(if location-ids
(daily-settlements location-ids)
(daily-settlements)))]
(doseq [x (partition-all 20 to-create)]
(log/info "Loading expected deposit" (count x))
@(d/transact conn x)))
(catch Exception e
(log/error e)))
(log/info "Done loading settlements"))))
(defn upsert-refunds []
(doseq [{location :id} (locations)]