From e2ae7a6d4f3ad075e60b9a24ce2d9c6334f4cac6 Mon Sep 17 00:00:00 2001 From: Bryce Covert Date: Fri, 11 Dec 2020 11:40:17 -0800 Subject: [PATCH] Sales orders works correctly now. --- src/clj/auto_ap/datomic/migrate/sales.clj | 12 ++++++- src/clj/auto_ap/graphql.clj | 2 ++ src/clj/auto_ap/routes/exports.clj | 2 ++ src/clj/auto_ap/square/core.clj | 22 +++++++----- src/clj/auto_ap/yodlee/core.clj | 35 +++++++++++-------- .../auto_ap/views/pages/admin/yodlee.cljs | 9 ++++- .../auto_ap/views/pages/sales_orders.cljs | 4 +-- .../views/pages/sales_orders/form.cljs | 17 ++++++++- 8 files changed, 75 insertions(+), 28 deletions(-) diff --git a/src/clj/auto_ap/datomic/migrate/sales.clj b/src/clj/auto_ap/datomic/migrate/sales.clj index a6cc1a56..49d7b0b2 100644 --- a/src/clj/auto_ap/datomic/migrate/sales.clj +++ b/src/clj/auto_ap/datomic/migrate/sales.clj @@ -135,7 +135,17 @@ :add-category {:txes [[{:db/ident :order-line-item/category :db/doc "The item category" :db/valueType :db.type/string - :db/cardinality :db.cardinality/one}]]}}) + :db/cardinality :db.cardinality/one}]]} + + :add-other-types {:txes [[{:db/ident :sales-order/returns + :db/doc "The returned amount on the sale" + :db/valueType :db.type/double + :db/cardinality :db.cardinality/one} + + {:db/ident :sales-order/service-charge + :db/doc "The total cost on the item" + :db/valueType :db.type/double + :db/cardinality :db.cardinality/one}]]}}) diff --git a/src/clj/auto_ap/graphql.clj b/src/clj/auto_ap/graphql.clj index c90607a4..10574bd8 100644 --- a/src/clj/auto_ap/graphql.clj +++ b/src/clj/auto_ap/graphql.clj @@ -220,6 +220,8 @@ :tip {:type :money} :tax {:type :money} :discount {:type :money} + :service_charge {:type :money} + :returns {:type :money} :client {:type :client} :date {:type 'String} :charges {:type '(list :charge)} diff --git a/src/clj/auto_ap/routes/exports.clj b/src/clj/auto_ap/routes/exports.clj index dd30b7b6..1a9bf9cb 100644 --- a/src/clj/auto_ap/routes/exports.clj +++ b/src/clj/auto_ap/routes/exports.clj @@ -64,6 +64,8 @@ :tip :tax :discount + :returns + :service_charge :date [:charges [:type_name :total :tip]] [:line_items [:item_name :total :tax :discount :category]] diff --git a/src/clj/auto_ap/square/core.clj b/src/clj/auto_ap/square/core.clj index 23a8d75f..9cdbcb74 100644 --- a/src/clj/auto_ap/square/core.clj +++ b/src/clj/auto_ap/square/core.clj @@ -120,7 +120,7 @@ (defn location_id->client-location [location] ({"2RVBYER6QSV7W" ["NGAK" "MH"] - #_#_"8JT71V8XGYAT3" ["NGKG" "NB"] + "8JT71V8XGYAT3" ["NGKG" "NB"] "SCX0Y8CTGM1S0" ["NGE1" "UC"] "FNH5VRT890WK8" ["NGMJ" "SC"] "AMQ0NPA8FGDEF" ["NGPG" "SZ"] @@ -132,6 +132,9 @@ (map :id) (filter location_id->client-location) (mapcat #(search % d)) + (filter (fn [order] + (not= #{"FAILED"} + (set (map #(:status (:card_details %)) (:tenders order)))))) (map (fn [order] (let [[client loc] (location_id->client-location (:location_id order))] (remove-nils @@ -140,13 +143,16 @@ :client [:client/code client] :location loc :external-id (str "square/order/" client "-" loc "-" (:id order)) - :total (- (-> order :total_money amount->money) - (or (some-> order :return_amounts :total_money amount->money) 0.0)) - :tax (- (-> order :total_tax_money amount->money) - (or (some-> order :return_amounts :tax_money amount->money) 0.0)) - :tip (- (-> order :net_amounts :tip_money amount->money) - (or (some-> order :return_amounts :tip_money amount->money) 0.0)) - :discount (-> order :total_discount_money amount->money) + :total (-> order :net_amounts :total_money amount->money) + :tax (-> order :net_amounts :tax_money amount->money) + :tip (-> order :net_amounts :tip_money amount->money) + :discount (-> order :net_amounts :discount_money amount->money) + :service-charge (-> order :net_amounts :service_charge_money amount->money) + :returns (+ (- (-> order :return_amounts :total_money amount->money) + (-> order :return_amounts :tax_money amount->money) + (-> order :return_amounts :tip_money amount->money) + (-> order :return_amounts :service_charge_money amount->money) + (-> order :return_amounts :discount_money amount->money))) :charges (->> (:tenders order) (map (fn [t] (remove-nils diff --git a/src/clj/auto_ap/yodlee/core.clj b/src/clj/auto_ap/yodlee/core.clj index 8013ae6a..7ea2e704 100644 --- a/src/clj/auto_ap/yodlee/core.clj +++ b/src/clj/auto_ap/yodlee/core.clj @@ -243,22 +243,27 @@ ))) (defn get-access-token [] - (let [cob-session (login-cobrand) - user-session (login-user cob-session) - token (-> - (str (:yodlee-base-url env) "/user/accessTokens?appIds=" 10003600) + (try + (let [cob-session (login-cobrand) + user-session (login-user cob-session) + token (-> + (str (:yodlee-base-url env) "/user/accessTokens?appIds=" 10003600) - (client/get - (merge {:headers (merge base-headers {"Authorization" (auth-header cob-session user-session)}) - :as :json} - other-config)) - :body - :user - :accessTokens - first - :value - )] - [user-session token])) + (client/get + (merge {:headers (merge base-headers {"Authorization" (auth-header cob-session user-session)}) + :as :json} + other-config)) + (doto log/info) + :body + :user + :accessTokens + first + :value + )] + [user-session token]) + (catch Exception e + (log/error e) + (throw e)))) (defn create-user [] (let [cob-session (login-cobrand)] diff --git a/src/cljs/auto_ap/views/pages/admin/yodlee.cljs b/src/cljs/auto_ap/views/pages/admin/yodlee.cljs index 0cdeb5af..5091c7b1 100644 --- a/src/cljs/auto_ap/views/pages/admin/yodlee.cljs +++ b/src/cljs/auto_ap/views/pages/admin/yodlee.cljs @@ -117,6 +117,13 @@ (re-frame/reg-event-fx ::authenticated + (fn [{:keys [db]} [_ authentication]] + {:db (-> db + (assoc-in [::yodlee :authentication] authentication) + (assoc-in [::yodlee :loading?] false))})) + +(re-frame/reg-event-fx + ::authenticated-mfa (fn [{:keys [db]} [_ provider-account-id authentication]] {:db (-> db (assoc-in [::yodlee :authentication] authentication) @@ -221,7 +228,7 @@ "value" v}) (:mfa (:data (get-in db [::forms/forms [::mfa-form provider-account-id]]))))} - :on-success [::authenticated provider-account-id] + :on-success [::authenticated-mfa provider-account-id] :on-error [::forms/save-error [::mfa-form provider-account-id] ]}})) (re-frame/reg-event-fx diff --git a/src/cljs/auto_ap/views/pages/sales_orders.cljs b/src/cljs/auto_ap/views/pages/sales_orders.cljs index 8a5c36ba..9a277f8c 100644 --- a/src/cljs/auto_ap/views/pages/sales_orders.cljs +++ b/src/cljs/auto_ap/views/pages/sales_orders.cljs @@ -26,9 +26,9 @@ :total-lte (:amount-lte (:total-range params)) :date-range (:date-range params) :client-id (:id @(re-frame/subscribe [::subs/client]))} - [[:sales-orders [:id :total :tax :tip :date + [[:sales-orders [:id :total :tax :tip :discount :service-charge :returns :date [:charges [:type-name :total]] - [:line-items [:item-name :total]] + [:line-items [:item-name :total :category]] [:client [:name :id]]]] :total :start diff --git a/src/cljs/auto_ap/views/pages/sales_orders/form.cljs b/src/cljs/auto_ap/views/pages/sales_orders/form.cljs index e7ca430e..3fb01309 100644 --- a/src/cljs/auto_ap/views/pages/sales_orders/form.cljs +++ b/src/cljs/auto_ap/views/pages/sales_orders/form.cljs @@ -63,6 +63,21 @@ [money-field {:type "money" :field [:tax] :disabled true}]) + (field "Discount" + [money-field {:type "money" + :field [:discount] + :disabled true}]) + + (field "Returns" + [money-field {:type "money" + :field [:returns] + :disabled true}]) + + (field "Service Charge" + [money-field {:type "money" + :field [:service-charge] + :disabled true}]) + (field "Tip" [money-field {:type "money" :field [:tip] @@ -76,6 +91,6 @@ [:h1.subtitle.is-4 "Line Items"] [:ul (for [line-item (:line-items data)] - [:li (:item-name line-item) ": " (:total line-item)])]]) + [:li (:item-name line-item) ": " (:total line-item) [:span.tag (:category line-item)]])]]) {:key (:id data)}))])