From c2407a73c633d52828060b9aa28c55a3a42f488e Mon Sep 17 00:00:00 2001 From: Bryce Covert Date: Tue, 15 Dec 2020 08:39:51 -0800 Subject: [PATCH] make it possible to revert yodlee account id. --- src/clj/auto_ap/graphql/clients.clj | 103 +++++++++--------- src/clj/auto_ap/square/core.clj | 16 ++- .../views/pages/admin/clients/form.cljs | 5 +- 3 files changed, 72 insertions(+), 52 deletions(-) diff --git a/src/clj/auto_ap/graphql/clients.clj b/src/clj/auto_ap/graphql/clients.clj index 192c9349..08b3d398 100644 --- a/src/clj/auto_ap/graphql/clients.clj +++ b/src/clj/auto_ap/graphql/clients.clj @@ -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 diff --git a/src/clj/auto_ap/square/core.clj b/src/clj/auto_ap/square/core.clj index 9cdbcb74..4a857f46 100644 --- a/src/clj/auto_ap/square/core.clj +++ b/src/clj/auto_ap/square/core.clj @@ -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) diff --git a/src/cljs/auto_ap/views/pages/admin/clients/form.cljs b/src/cljs/auto_ap/views/pages/admin/clients/form.cljs index eed55059..0269b0c0 100644 --- a/src/cljs/auto_ap/views/pages/admin/clients/form.cljs +++ b/src/cljs/auto_ap/views/pages/admin/clients/form.cljs @@ -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)