From be44000b6a3a68cd5c1eb6738d0fd6393d1a83a9 Mon Sep 17 00:00:00 2001 From: Bryce Covert Date: Mon, 23 Jan 2023 13:59:16 -0800 Subject: [PATCH] Fixes a series of issues on the invoice import page, company 1099 dropdown, and ezcater warnings. --- src/clj/auto_ap/ezcater/core.clj | 128 +++++++++--------- src/clj/auto_ap/ssr/company/company_1099.clj | 18 +-- src/clj/auto_ap/yodlee/core2.clj | 2 +- .../auto_ap/views/pages/import_invoices.cljs | 7 +- 4 files changed, 80 insertions(+), 75 deletions(-) diff --git a/src/clj/auto_ap/ezcater/core.clj b/src/clj/auto_ap/ezcater/core.clj index 63d2b5b9..0a868d35 100644 --- a/src/clj/auto_ap/ezcater/core.clj +++ b/src/clj/auto_ap/ezcater/core.clj @@ -11,6 +11,7 @@ [clj-time.core :as time] [clojure.set :as set] [auto-ap.time :as atime] + [auto-ap.logging :as alog] [cemerick.url :as url])) (defn query [{:ezcater-integration/keys [api-key]} q] @@ -203,72 +204,72 @@ integration (:ezcater-integration/_caterers caterer) client (-> caterer :ezcater-location/_caterer first :client/_ezcater-locations :client/code) location (-> caterer :ezcater-location/_caterer first :ezcater-location/location)] - (doto - (-> (query - integration - {:venia/queries [[:order {:id (get json "entity_id")} - [:uuid - :orderSourceType - [:caterer - [:name - :uuid - [:address [:street]]]] - [:event - [:timestamp - :catererHandoffFoodTime - :orderType]] - [:catererCart [[:orderItems - [:name - :quantity - :posItemId - [:totalInSubunits - [:currency - :subunits]]]] - [:totals - [:catererTotalDue]] - [:feesAndDiscounts - {:type 'DELIVERY_FEE} - [[:cost - [:currency - :subunits]]]]]] - [:totals [[:customerTotalDue - [ - :currency - :subunits - ]] - [:pointOfSaleIntegrationFee - [ - :currency - :subunits - ]] - [:tip - [:currency - :subunits]] - [:salesTax - [ - :currency - :subunits - ]] - [:salesTaxRemittance - [:currency - :subunits - ]] - [:subTotal - [:currency - :subunits]]]]]]]}) - (:order) - (assoc :client-code client - :client-location location)) - log/info))) + (if (and client location) + (doto + (-> (query + integration + {:venia/queries [[:order {:id (get json "entity_id")} + [:uuid + :orderSourceType + [:caterer + [:name + :uuid + [:address [:street]]]] + [:event + [:timestamp + :catererHandoffFoodTime + :orderType]] + [:catererCart [[:orderItems + [:name + :quantity + :posItemId + [:totalInSubunits + [:currency + :subunits]]]] + [:totals + [:catererTotalDue]] + [:feesAndDiscounts + {:type 'DELIVERY_FEE} + [[:cost + [:currency + :subunits]]]]]] + [:totals [[:customerTotalDue + [ + :currency + :subunits + ]] + [:pointOfSaleIntegrationFee + [ + :currency + :subunits + ]] + [:tip + [:currency + :subunits]] + [:salesTax + [ + :currency + :subunits + ]] + [:salesTaxRemittance + [:currency + :subunits + ]] + [:subTotal + [:currency + :subunits]]]]]]]}) + (:order) + (assoc :client-code client + :client-location location)) + (#(alog/info ::order-details :detail %))) + (alog/warn ::caterer-no-longer-has-location :json json)))) (defn import-order [json] ;; {"id" "bf3dcf5c-a68f-42d9-9084-049133e03d3d", "parent_type" "Caterer", "parent_id" "91541331-d7ae-4634-9e8b-ccbbcfb2ce70", "entity_type" "Order", "entity_id" "9ab05fee-a9c5-483b-a7f2-14debde4b7a8", "key" "accepted", "occurred_at" "2022-07-21T19:21:07.549Z"} - (clojure.pprint/pprint [(-> json - (lookup-order) - (order->sales-order) - (update :sales-order/date coerce/to-date) - (update-in [:sales-order/charges 0 :charge/date] coerce/to-date))]) - @(d/transact conn [(-> json + (alog/info + ::try-import-order + :json json) + @(d/transact conn [(some-> json (lookup-order) (order->sales-order) (update :sales-order/date coerce/to-date) @@ -339,7 +340,6 @@ :when (not= updated-order extant-order)] updated-order))] - (log/info "Found these orders to update:" orders-to-update) @(d/transact conn orders-to-update))) diff --git a/src/clj/auto_ap/ssr/company/company_1099.clj b/src/clj/auto_ap/ssr/company/company_1099.clj index bbdec0bf..bd24476d 100644 --- a/src/clj/auto_ap/ssr/company/company_1099.clj +++ b/src/clj/auto_ap/ssr/company/company_1099.clj @@ -23,11 +23,12 @@ [(auto-ap.graphql.utils/can-see-client? ?user ?c)]] (d/db conn) user) (map first) - set)] - (cond + set) + results (cond (and (some-> session :client :db/id) (can-see-client? user (some-> session :client :db/id))) + :else (d/q '[:find (pull ?c [:client/code :db/id]) (pull ?v [:db/id @@ -115,12 +116,13 @@ [?p :payment/amount ?a] [?p :payment/vendor ?v]] (d/db conn) - clients) - (filter (fn [[_ _ a]] - (>= (or a 0.0) 600.0))) - (take 200) - (sort-by (fn [[client _ amount]] - [(:client/code client ) amount]) )))) + clients))] + (->> results + (filter (fn [[_ _ a]] + (>= (or a 0.0) 600.0))) + (take 200) + (sort-by (fn [[client _ amount]] + [(:client/code client ) amount]))))) (defn dialog [header content footer] [:div.modal.is-active diff --git a/src/clj/auto_ap/yodlee/core2.clj b/src/clj/auto_ap/yodlee/core2.clj index ae3aced1..d79cb173 100644 --- a/src/clj/auto_ap/yodlee/core2.clj +++ b/src/clj/auto_ap/yodlee/core2.clj @@ -304,7 +304,7 @@ (cond-> {:yodlee-provider-account/id (:id pa) :yodlee-provider-account/status (:status pa) - :yodlee-provider-account/detailed-status (-> pa :dataset first :additionalStatus) + :yodlee-provider-account/detailed-status (or (-> pa :dataset first :additionalStatus) "unknown") :yodlee-provider-account/client [:client/code client-code] :yodlee-provider-account/accounts (mapv diff --git a/src/cljs/auto_ap/views/pages/import_invoices.cljs b/src/cljs/auto_ap/views/pages/import_invoices.cljs index acc4d171..9c851405 100644 --- a/src/cljs/auto_ap/views/pages/import_invoices.cljs +++ b/src/cljs/auto_ap/views/pages/import_invoices.cljs @@ -177,7 +177,8 @@ (fn [] (let [page @(re-frame/subscribe [::data-page/page :import-invoices]) batch @(re-frame/subscribe [::batch]) - client (:id @(re-frame/subscribe [::subs/client]))] + client (:id @(re-frame/subscribe [::subs/client])) + checked-set (into #{} (:checked-set page))] ^{:key (str client "-" batch)} [:div [:h1.title "Upload invoices"] @@ -191,7 +192,9 @@ [:div {:class "card-header"} [:span {:class "card-header-title"} "Found Invoices"]] [:div {:class "card-content"} - [approve-reject-button (:checked-set page)] + [approve-reject-button (if (get checked-set "header") + (into #{} (map :id (:data (:data page)))) + checked-set)] (if (seq (:data (:data page))) [invoice-table {:id :approved :data-page :import-invoices