Fixed UI bug with transactions unable to autochoose accounts, added new locations

This commit is contained in:
2021-08-18 20:51:22 -07:00
parent 85df01e4bc
commit cbe0e77434
2 changed files with 53 additions and 39 deletions

View File

@@ -152,7 +152,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
@@ -262,10 +263,12 @@
(recur xs (conj result n))
(conj result 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)]]
@@ -273,13 +276,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)
@@ -328,24 +333,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)]

View File

@@ -80,7 +80,7 @@
value
(expense-accounts-field/can-replace-with-default? (:accounts data)))
[[:accounts] (expense-accounts-field/default-account (:accounts data)
@(re-frame/subscribe [::subs/vendor-default-account value (:client data)])
@(re-frame/subscribe [::subs/vendor-default-account (:id value) (:client data)])
(:amount data)
locations)]
[])))))
@@ -414,15 +414,20 @@
:field [:vendor]
:disabled (or (boolean (:payment data))
should-disable-for-client?)}])
(field nil
[expense-accounts-field
{:type "expense-accounts"
:field [:accounts]
:max (Math/abs (js/parseFloat (:amount data)))
:descriptor "credit account"
:disabled (or (boolean (:payment data))
should-disable-for-client?)
:locations locations}])
(with-meta
(field nil
[expense-accounts-field
{:type "expense-accounts"
:field [:accounts]
:max (Math/abs (js/parseFloat (:amount data)))
:descriptor "credit account"
:disabled (or (boolean (:payment data))
should-disable-for-client?)
:locations locations}])
{:key (str (:id (:vendor data)))})