From 2d5b8eded4006cd5fd299b160d0b6c2ae3b575f3 Mon Sep 17 00:00:00 2001 From: Bryce Covert Date: Mon, 4 Jul 2022 07:19:14 -0700 Subject: [PATCH] Makes sales orders link to their deposits --- src/clj/auto_ap/datomic/sales_orders.clj | 12 ++- src/clj/auto_ap/graphql.clj | 64 ++----------- src/clj/auto_ap/graphql/expected_deposit.clj | 1 - src/clj/auto_ap/graphql/sales_orders.clj | 94 ++++++++++++++++++- .../auto_ap/views/pages/pos/sales_orders.cljs | 2 +- src/cljs/auto_ap/views/pages/pos/table.cljs | 43 ++++++++- 6 files changed, 146 insertions(+), 70 deletions(-) diff --git a/src/clj/auto_ap/datomic/sales_orders.clj b/src/clj/auto_ap/datomic/sales_orders.clj index d0d8c411..5027f588 100644 --- a/src/clj/auto_ap/datomic/sales_orders.clj +++ b/src/clj/auto_ap/datomic/sales_orders.clj @@ -4,19 +4,23 @@ [auto-ap.utils :refer [dollars=]] [clj-time.coerce :as c] [datomic.api :as d] - [clojure.tools.logging :as log])) + [clojure.tools.logging :as log] + [clojure.set :as set])) (defn <-datomic [result] (-> result (update :sales-order/date c/from-date) (update :sales-order/charges (fn [cs] (map (fn [c] - (update c :charge/processor :db/ident)) + (-> c + (update :charge/processor :db/ident) + (set/rename-keys {:expected-deposit/_charges :expected-deposit}) + (update :expected-deposit first))) cs))))) (def default-read '[* {:sales-order/client [:client/name :db/id :client/code] - :sales-order/charges [* {:charge/processor [:db/ident]}]}]) + :sales-order/charges [* {:charge/processor [:db/ident]} {:expected-deposit/_charges [:db/id]}]}]) (defn raw-graphql-ids [db args] (let [query (cond-> {:query {:find [] @@ -118,10 +122,8 @@ :tax tax})) (defn get-graphql [args] - (log/info "ARGS" args) (let [db (d/db (d/connect uri)) {ids-to-retrieve :ids matching-count :count} (raw-graphql-ids db args)] - [(->> (graphql-results ids-to-retrieve db args)) matching-count (summarize-orders ids-to-retrieve)])) diff --git a/src/clj/auto_ap/graphql.clj b/src/clj/auto_ap/graphql.clj index 4bb80e34..c1b68d20 100644 --- a/src/clj/auto_ap/graphql.clj +++ b/src/clj/auto_ap/graphql.clj @@ -2,7 +2,6 @@ (:require [auto-ap.datomic :refer [merge-query uri]] [auto-ap.datomic.checks :as d-checks] - [auto-ap.datomic.sales-orders :as d-sales-orders] [auto-ap.datomic.users :as d-users] [auto-ap.graphql.accounts :as gq-accounts] [auto-ap.graphql.checks :as gq-checks] @@ -194,34 +193,9 @@ - :order_line_item - {:fields {:id {:type :id} - :item_name {:type 'String} - :total {:type :money} - :tax {:type :money} - :category {:type 'String} - :discount {:type :money}}} - :charge - {:fields {:id {:type :id} - :processor {:type :processor} - :type_name {:type 'String} - :total {:type :money} - :tip {:type :money}}} + - :sales_order - {:fields {:id {:type :id} - :location {:type 'String} - :external_id {:type 'String} - :total {:type :money} - :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)} - :line_items {:type '(list :order_line_item)}}} + :yodlee_merchant {:fields {:id {:type :id} :yodlee_id {:type 'String} :name {:type 'String}}} @@ -291,13 +265,7 @@ - :sales_order_page {:fields {:sales_orders {:type '(list :sales_order)} - :count {:type 'Int} - :total {:type 'Int} - :start {:type 'Int} - :end {:type 'Int} - :sales_order_total {:type :money} - :sales_order_tax {:type :money}}} + :vendor_page {:fields {:vendors {:type '(list :vendor)} :count {:type 'Int} @@ -386,11 +354,7 @@ - :all_sales_orders {:type '(list :sales_order) - :args {:client_id {:type :id} - :date_range {:type :date_range} - :client_code {:type 'String}} - :resolve :get-all-sales-orders} + :yodlee_merchants {:type '(list :yodlee_merchant) :args {} @@ -413,16 +377,7 @@ - :sales_order_page {:type :sales_order_page - :args {:client_id {:type :id} - :date_range {:type :date_range} - :total_lte {:type :money} - :total_gte {:type :money} - :processor {:type :processor} - :start {:type 'Int} - :per_page {:type 'Int} - :sort {:type '(list :sort_item)}} - :resolve :get-sales-order-page} + :vendor {:type :vendor_page :args {:name_like {:type 'String} :start {:type 'Int} @@ -636,11 +591,7 @@ -(defn get-all-sales-orders [context args value] - (assert-admin (:id context)) - (map - ->graphql - (first (d-sales-orders/get-graphql (assoc (<-graphql args) :count Integer/MAX_VALUE))))) + (defn get-user [context args value] (assert-admin (:id context)) @@ -812,10 +763,8 @@ (-> integreat-schema (attach-resolvers { :get-yodlee-provider-account-page gq-yodlee2/get-yodlee-provider-account-page - :get-all-sales-orders get-all-sales-orders :get-accounts gq-accounts/get-graphql :get-all-accounts gq-accounts/get-all-graphql - :get-sales-order-page gq-sales-orders/get-sales-orders-page :get-transaction-rule-page gq-transaction-rules/get-transaction-rule-page :get-transaction-rule-matches gq-transaction-rules/get-transaction-rule-matches :get-expense-account-stats get-expense-account-stats @@ -847,6 +796,7 @@ gq-expected-deposit/attach gq-invoices/attach gq-clients/attach + gq-sales-orders/attach schema/compile)) diff --git a/src/clj/auto_ap/graphql/expected_deposit.clj b/src/clj/auto_ap/graphql/expected_deposit.clj index a5976834..7b8889ed 100644 --- a/src/clj/auto_ap/graphql/expected_deposit.clj +++ b/src/clj/auto_ap/graphql/expected_deposit.clj @@ -22,7 +22,6 @@ (defn get-expected-deposit-page [context args value] (let [args (assoc args :id (:id context)) [expected-deposits expected-deposit-count] (d-expected-deposit/get-graphql (<-graphql args)) - _ (log/info expected-deposits) expected-deposits (map status->graphql expected-deposits)] (result->page expected-deposits expected-deposit-count :expected_deposits args))) diff --git a/src/clj/auto_ap/graphql/sales_orders.clj b/src/clj/auto_ap/graphql/sales_orders.clj index 85b02b2c..da260b08 100644 --- a/src/clj/auto_ap/graphql/sales_orders.clj +++ b/src/clj/auto_ap/graphql/sales_orders.clj @@ -1,10 +1,100 @@ (ns auto-ap.graphql.sales-orders (:require [auto-ap.datomic.sales-orders :as d-sales-orders2] - [auto-ap.graphql.utils :refer [->graphql <-graphql result->page]])) + [auto-ap.graphql.utils :refer [->graphql <-graphql result->page assert-admin] ] + [com.walmartlabs.lacinia.util :refer [attach-resolvers]])) -(defn get-sales-orders-page [context args value] +(defn get-sales-orders-page [context args _] (let [args (assoc args :id (:id context)) [sales-orders sales-orders-count {:keys [total tax]}] (d-sales-orders2/get-graphql (<-graphql args))] (assoc (result->page sales-orders sales-orders-count :sales_orders args) :sales_order_total total :sales_order_tax tax))) + +(defn get-all-sales-orders [context args _] + (assert-admin (:id context)) + (map + ->graphql + (first (d-sales-orders2/get-graphql (assoc (<-graphql args) :count Integer/MAX_VALUE))))) + + +(def objects + {:sales_order_page + {:fields {:sales_orders {:type '(list :sales_order)} + :count {:type 'Int} + :total {:type 'Int} + :start {:type 'Int} + :end {:type 'Int} + :sales_order_total {:type :money} + :sales_order_tax {:type :money}}} + + :sales_order + {:fields {:id {:type :id} + :location {:type 'String} + :external_id {:type 'String} + :total {:type :money} + :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)} + :line_items {:type '(list :order_line_item)}}} + + :order_line_item + {:fields {:id {:type :id} + :item_name {:type 'String} + :total {:type :money} + :tax {:type :money} + :category {:type 'String} + :discount {:type :money}}} + :charge + {:fields {:id {:type :id} + :processor {:type :processor} + :type_name {:type 'String} + :total {:type :money} + :tip {:type :money} + :expected_deposit {:type :expected_deposit}}}}) + +(def queries + {:all_sales_orders {:type '(list :sales_order) + :args {:client_id {:type :id} + :date_range {:type :date_range} + :client_code {:type 'String}} + :resolve :get-all-sales-orders} + + :sales_order_page {:type :sales_order_page + :args {:client_id {:type :id} + :date_range {:type :date_range} + :total_lte {:type :money} + :total_gte {:type :money} + :processor {:type :processor} + :start {:type 'Int} + :per_page {:type 'Int} + :sort {:type '(list :sort_item)}} + :resolve :get-sales-order-page}}) + +(def mutations + {}) + +(def input-objects + {}) + +(def enums + {}) + +(def resolvers + {:get-all-sales-orders get-all-sales-orders + :get-sales-order-page get-sales-orders-page + }) + +(defn attach [schema] + (-> + (merge-with merge schema + {:objects objects + :queries queries + :mutations mutations + :input-objects input-objects + :enums enums}) + (attach-resolvers resolvers))) diff --git a/src/cljs/auto_ap/views/pages/pos/sales_orders.cljs b/src/cljs/auto_ap/views/pages/pos/sales_orders.cljs index 8114fee2..0c244f5f 100644 --- a/src/cljs/auto_ap/views/pages/pos/sales_orders.cljs +++ b/src/cljs/auto_ap/views/pages/pos/sales_orders.cljs @@ -28,7 +28,7 @@ :processor (some-> (:processor params) keyword) :client-id (:id @(re-frame/subscribe [::subs/client]))} [[:sales-orders [:id :total :tax :tip :discount :service-charge :returns :date - [:charges [:type-name :total :processor :id]] + [:charges [:type-name :total :processor :id [:expected-deposit [:id]] ]] [:line-items [:item-name :total :category]] [:client [:name :id]]]] :total diff --git a/src/cljs/auto_ap/views/pages/pos/table.cljs b/src/cljs/auto_ap/views/pages/pos/table.cljs index cc868d5b..7355baad 100644 --- a/src/cljs/auto_ap/views/pages/pos/table.cljs +++ b/src/cljs/auto_ap/views/pages/pos/table.cljs @@ -1,15 +1,24 @@ (ns auto-ap.views.pages.pos.table (:require [auto-ap.subs :as subs] - [auto-ap.views.components.buttons :as buttons] [auto-ap.views.components.grid :as grid] + [auto-ap.routes :as routes] + [auto-ap.events :as events] + [auto-ap.views.components.buttons :as buttons] + [auto-ap.views.components.grid :as grid] [auto-ap.views.pages.data-page :as data-page] [auto-ap.views.pages.pos.form :as form] - [auto-ap.views.utils :refer [date->str nf]] + [bidi.bidi :as bidi] + [cemerick.url :as url] + [auto-ap.views.components.dropdown + :refer + [drop-down drop-down-contents]] + [auto-ap.views.utils :refer [date->str nf dispatch-event-with-propagation]] [clojure.string :as str] [re-frame.core :as re-frame])) (defn row [{sales-order :sales-order selected-client :selected-client}] - (let [{:keys [client date total tax tip charges line-items id]} sales-order] + (let [{:keys [client date total tax tip charges line-items id]} sales-order + expected-deposits (->> charges (filter :expected-deposit) (map :expected-deposit))] [grid/row {:class (:class sales-order) :id id} (when-not selected-client [grid/cell {} (:name client)]) @@ -51,6 +60,32 @@ [grid/cell {} (str/join ", " (map :item-name line-items))] [grid/button-cell {} [:div.buttons + (when (seq expected-deposits) + [:<> + [drop-down {:id [::links id] + :is-right? true + :header [buttons/fa-icon {:class "badge" + :on-click (dispatch-event-with-propagation [::events/toggle-menu [::links id]]) + :data-badge (str (clojure.core/count expected-deposits)) + :icon "fa-paperclip"}]} + [drop-down-contents + [:div.dropdown-item + [:table.table.grid.compact + [:tbody + (for [ed expected-deposits] + ^{:key (:id ed)} + [:tr + [:td + "Expected Deposit " (:id ed) + ] + [:td + [buttons/fa-icon {:icon "fa-external-link" + :href (str (bidi/path-for routes/routes :expected-deposits ) + "?" + (url/map->query {:exact-match-id (:id ed)}))}]]])]]]]] + [:span {:style {:margin-left "1em"}}]]) + + [buttons/fa-icon {:event [::form/editing sales-order] :icon "fa-pencil"}]]]])) (defn table [{:keys [data-page]}] @@ -75,7 +110,7 @@ [grid/sortable-header-cell {:sort-key "tip" :sort-name "Tip" :class "has-text-right" :style {:width "7em"}} "Tip"] [grid/header-cell {} "Payment Methods"] [grid/header-cell {} "Line Items"] - [grid/header-cell {:style {:width "4em"}}]]] + [grid/header-cell {:style {:width "8em"}}]]] [grid/body (for [sales-order (:data data)] ^{:key (:id sales-order)}