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

View File

@@ -103,7 +103,7 @@
{:headers {"Square-Version" "2020-08-12"
"Authorization" "Bearer EAAAEO2xSqesDutZz71hz3eulKmrlKTiEqG3uZ4j25x5GYlOluQ2cj2JxNUXqXD7"
"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))))
:as :json})
:body
@@ -127,6 +127,20 @@
"4X8T65741AEPS" ["NGVZ" "NP"]
"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]
(->> (locations)
(map :id)

View File

@@ -8,7 +8,8 @@
[cljs-time.coerce :as coerce]
[cljs-time.core :as t]
[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
::can-submit
@@ -63,7 +64,7 @@
:sort-order sort-order
:visible visible
: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))
:code (if new?
(str (:code new-client-data) "-" code)