make it possible to revert yodlee account id.

This commit is contained in:
Bryce Covert
2020-12-15 08:39:51 -08:00
parent d7e99205fc
commit c2407a73c6
3 changed files with 72 additions and 52 deletions

View File

@@ -26,59 +26,64 @@
(mapv (fn [lm] [:db/retractEntity (:db/id lm)]) (:client/location-matches client)) (mapv (fn [lm] [:db/retractEntity (:db/id lm)]) (:client/location-matches client))
(mapv (fn [m] [:db/retract (:db/id client) :client/matches m]) (:client/matches client))) (mapv (fn [m] [:db/retract (:db/id client) :client/matches m]) (:client/matches client)))
(:id context))) (:id context)))
transactions [(remove-nils {:db/id id reverts (->> (:bank_accounts edit_client)
:client/code (if (str/blank? (:client/code client)) (filter #(nil? (:yodlee_account_id %)))
(:code edit_client) (filter #(:bank-account/yodlee-account-id (d/entity (d/db conn) (:id %))))
(:client/code client)) (map (fn [ba] [:db/retract (:id ba) :bank-account/yodlee-account-id (:bank-account/yodlee-account-id (d/entity (d/db conn) (:id ba)))])))
:client/name (:name edit_client) transactions (into [(remove-nils {:db/id id
:client/matches (:matches edit_client) :client/code (if (str/blank? (:client/code client))
:client/email (:email edit_client) (:code edit_client)
:client/locations (filter identity (:locations edit_client)) (:client/code client))
:client/week-a-debits (:week_a_debits edit_client) :client/name (:name edit_client)
:client/week-a-credits (:week_a_credits edit_client) :client/matches (:matches edit_client)
:client/week-b-debits (:week_b_debits edit_client) :client/email (:email edit_client)
:client/week-b-credits (:week_b_credits edit_client) :client/locations (filter identity (:locations edit_client))
:client/location-matches (->> (:location_matches edit_client) :client/week-a-debits (:week_a_debits edit_client)
(filter (fn [lm] (and (:location lm) (:match lm)))) :client/week-a-credits (:week_a_credits edit_client)
(map (fn [lm] {:location-match/location (:location lm) :client/week-b-debits (:week_b_debits edit_client)
:location-match/matches [(:match lm)]}))) :client/week-b-credits (:week_b_credits edit_client)
:client/address (remove-nils { :client/location-matches (->> (:location_matches edit_client)
:address/street1 (:street1 (:address edit_client)) (filter (fn [lm] (and (:location lm) (:match lm))))
:address/street2 (:street2 (:address edit_client)) (map (fn [lm] {:location-match/location (:location lm)
:address/city (:city (:address edit_client)) :location-match/matches [(:match lm)]})))
:address/state (:state (:address edit_client)) :client/address (remove-nils {
:address/zip (:zip (:address edit_client))}) :address/street1 (:street1 (:address edit_client))
:address/street2 (:street2 (:address edit_client))
:address/city (:city (:address edit_client))
:address/state (:state (:address edit_client))
:address/zip (:zip (:address edit_client))})
:client/bank-accounts (map #(remove-nils :client/bank-accounts (map #(remove-nils
{:db/id (:id %) {:db/id (:id %)
:bank-account/code (:code %) :bank-account/code (:code %)
:bank-account/bank-name (:bank_name %) :bank-account/bank-name (:bank_name %)
:bank-account/bank-code (:bank_code %) :bank-account/bank-code (:bank_code %)
:bank-account/start-date (-> (:start_date %) (coerce/to-date)) :bank-account/start-date (-> (:start_date %) (coerce/to-date))
:bank-account/routing (:routing %) :bank-account/routing (:routing %)
:bank-account/include-in-reports (:include_in_reports %) :bank-account/include-in-reports (:include_in_reports %)
:bank-account/name (:name %) :bank-account/name (:name %)
:bank-account/visible (:visible %) :bank-account/visible (:visible %)
:bank-account/number (:number %) :bank-account/number (:number %)
:bank-account/check-number (:check_number %) :bank-account/check-number (:check_number %)
:bank-account/sort-order (:sort_order %) :bank-account/sort-order (:sort_order %)
:bank-account/locations (:locations %) :bank-account/locations (:locations %)
:bank-account/yodlee-account-id (:yodlee_account_id %) :bank-account/yodlee-account-id (:yodlee_account_id %)
:bank-account/type (keyword "bank-account-type" (name (:type %))) :bank-account/type (keyword "bank-account-type" (name (:type %)))
} }
) (:bank_accounts edit_client)) ) (:bank_accounts edit_client))
}) })
[:reset id :client/forecasted-transactions (map #(remove-nils [:reset id :client/forecasted-transactions (map #(remove-nils
{:db/id (:id %) {:db/id (:id %)
:forecasted-transaction/day-of-month (:day_of_month %) :forecasted-transaction/day-of-month (:day_of_month %)
:forecasted-transaction/identifier (:identifier %) :forecasted-transaction/identifier (:identifier %)
:forecasted-transaction/amount (:amount %)} :forecasted-transaction/amount (:amount %)}
) )
(:forecasted_transactions edit_client))]] (:forecasted_transactions edit_client))]]
reverts)
_ (log/info "upserting client" transactions) _ (log/info "upserting client" transactions)
result (audit-transact transactions (:id context))] result (audit-transact transactions (:id context))]
(-> result :tempids (get id) (or id) d-clients/get-by-id (-> result :tempids (get id) (or id) d-clients/get-by-id

View File

@@ -103,7 +103,7 @@
{:headers {"Square-Version" "2020-08-12" {:headers {"Square-Version" "2020-08-12"
"Authorization" "Bearer EAAAEO2xSqesDutZz71hz3eulKmrlKTiEqG3uZ4j25x5GYlOluQ2cj2JxNUXqXD7" "Authorization" "Bearer EAAAEO2xSqesDutZz71hz3eulKmrlKTiEqG3uZ4j25x5GYlOluQ2cj2JxNUXqXD7"
"Content-Type" "application/json"} "Content-Type" "application/json"}
:body (json/write-str (cond-> {"location_ids" [l] "limit" 4000} :body (json/write-str (cond-> {"location_ids" [l] "limit" 10000}
d (merge (pc d)))) d (merge (pc d))))
:as :json}) :as :json})
:body :body
@@ -127,6 +127,20 @@
"4X8T65741AEPS" ["NGVZ" "NP"] "4X8T65741AEPS" ["NGVZ" "NP"]
"KMVFQ9CRCXJ10" ["NGZO" "VT"]} location)) "KMVFQ9CRCXJ10" ["NGZO" "VT"]} location))
;; to get totals:
(comment
(reduce
(fn [total i]
(+ total (+ (- (:sales-order/total i)
(:sales-order/tax i)
(:sales-order/tip i)
(:sales-order/service-charge i))
(:sales-order/returns i)
(:sales-order/discount i)
)))
0.0))
(defn daily-results [d] (defn daily-results [d]
(->> (locations) (->> (locations)
(map :id) (map :id)

View File

@@ -8,7 +8,8 @@
[cljs-time.coerce :as coerce] [cljs-time.coerce :as coerce]
[cljs-time.core :as t] [cljs-time.core :as t]
[clojure.spec.alpha :as s] [clojure.spec.alpha :as s]
[re-frame.core :as re-frame])) [re-frame.core :as re-frame]
[clojure.string :as str]))
(re-frame/reg-sub (re-frame/reg-sub
::can-submit ::can-submit
@@ -63,7 +64,7 @@
:sort-order sort-order :sort-order sort-order
:visible visible :visible visible
:locations (mapv :location locations) :locations (mapv :location locations)
:yodlee-account-id (when yodlee-account-id :yodlee-account-id (when-not (str/blank? yodlee-account-id)
(js/parseInt yodlee-account-id)) (js/parseInt yodlee-account-id))
:code (if new? :code (if new?
(str (:code new-client-data) "-" code) (str (:code new-client-data) "-" code)