From f40d1f4fb84d3b6fc390bad8df757e499b5f1e12 Mon Sep 17 00:00:00 2001 From: Bryce Covert Date: Fri, 18 Jun 2021 07:09:48 -0700 Subject: [PATCH] Allows you to filter down to ccp-processor --- src/clj/auto_ap/datomic/sales_orders.clj | 24 ++- src/clj/auto_ap/graphql.clj | 159 +++++++++--------- src/clj/auto_ap/graphql/sales_orders.clj | 6 +- .../auto_ap/views/pages/pos/sales_orders.cljs | 6 +- .../auto_ap/views/pages/pos/side_bar.cljs | 25 ++- src/cljs/auto_ap/views/pages/pos/table.cljs | 29 ++-- 6 files changed, 150 insertions(+), 99 deletions(-) diff --git a/src/clj/auto_ap/datomic/sales_orders.clj b/src/clj/auto_ap/datomic/sales_orders.clj index 10417642..d0d8c411 100644 --- a/src/clj/auto_ap/datomic/sales_orders.clj +++ b/src/clj/auto_ap/datomic/sales_orders.clj @@ -46,6 +46,13 @@ :where ['[?e :sales-order/client ?client-id] '[?client-id :client/code ?client-code]]} :args [(:client-code args)]}) + + (:processor args) + (merge-query {:query {:in ['?processor] + :where ['[?e :sales-order/charges ?chg] + '[?chg :charge/processor ?processor]]} + :args [(keyword "ccp-processor" + (name (:processor args)))]}) (:total-gte args) (merge-query {:query {:in ['?total-gte] @@ -96,13 +103,28 @@ (mapv <-datomic))] payments)) +(defn summarize-orders [ids] + + (let [[total tax] (->> + (d/query {:query {:find ['(sum ?t) '(sum ?tax)] + :with ['?id] + :in ['$ '[?id ...]] + :where ['[?id :sales-order/total ?t] + '[?id :sales-order/tax ?tax]]} + :args [(d/db (d/connect uri)) + ids]}) + first)] + {:total total + :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])) + matching-count + (summarize-orders ids-to-retrieve)])) (defn get-by-id [id] (->> diff --git a/src/clj/auto_ap/graphql.clj b/src/clj/auto_ap/graphql.clj index 877e8b0d..45a56c8f 100644 --- a/src/clj/auto_ap/graphql.clj +++ b/src/clj/auto_ap/graphql.clj @@ -63,8 +63,8 @@ (str %) :else - %) - } + %)} + :percentage {:parse #(cond (and (string? %) (not (str/blank? %))) (Double/parseDouble %) @@ -126,7 +126,7 @@ :phone {:type 'String}}} :bank_account - {:fields {:id {:type :id } + {:fields {:id {:type :id} :type {:type :ident} :start_date {:type :iso_date} :number {:type 'String} @@ -177,8 +177,8 @@ :terms_override {:fields {:id {:type :id} :client {:type :client} - :terms {:type 'Int} - }} + :terms {:type 'Int}}} + :schedule_payment_dom {:fields {:id {:type :id} @@ -218,9 +218,9 @@ :legal_entity_last_name {:type 'String} :legal_entity_tin {:type 'String} :legal_entity_tin_type {:type :tin_type} - :legal_entity_1099_type {:type :type_1099} + :legal_entity_1099_type {:type :type_1099}}} - }} + :reminder {:fields {:id {:type 'Int} :email {:type 'String} @@ -228,8 +228,8 @@ :body {:type 'String} :scheduled {:type 'String} :sent {:type 'String} - :vendor {:type :vendor} - }} + :vendor {:type :vendor}}} + :journal_entry_line {:fields {:id {:type :id} @@ -301,24 +301,24 @@ :s3_url {:type 'String} :check_number {:type 'Int} :status {:type 'String} - :invoices {:type '(list :invoice_payment)} - }} + :invoices {:type '(list :invoice_payment)}}} + :payment {:fields {:id {:type :id} - :type {:type :payment_type} + :type {:type :payment_type} :original_id {:type 'Int} - :amount {:type 'String} - :vendor {:type :vendor} - :client {:type :client} - :date {:type 'String} - :bank_account {:type :bank_account} - :memo {:type 'String} - :s3_url {:type 'String} - :check_number {:type 'Int} - :status {:type :ident} + :amount {:type 'String} + :vendor {:type :vendor} + :client {:type :client} + :date {:type 'String} + :bank_account {:type :bank_account} + :memo {:type 'String} + :s3_url {:type 'String} + :check_number {:type 'Int} + :status {:type :ident} :transaction {:type :transaction} - :invoices {:type '(list :invoice_payment)} - }} + :invoices {:type '(list :invoice_payment)}}} + :yodlee_merchant {:fields {:id {:type :id} :yodlee_id {:type 'String} @@ -432,10 +432,10 @@ :end {:type 'Int}}} :payment_page {:fields {:payments {:type '(list :payment)} - :count {:type 'Int} - :total {:type 'Int} - :start {:type 'Int} - :end {:type 'Int}}} + :count {:type 'Int} + :total {:type 'Int} + :start {:type 'Int} + :end {:type 'Int}}} :transaction_page {:fields {:data {:type '(list :transaction)} :count {:type 'Int} @@ -454,12 +454,16 @@ :total {:type 'Int} :start {:type 'Int} :end {:type 'Int}}} - + :sales_order_page {:fields {:sales_orders {:type '(list :sales_order)} - :count {:type 'Int} - :total {:type 'Int} - :start {:type 'Int} - :end {:type 'Int}}} + :count {:type 'Int} + :total {:type 'Int} + :start {:type 'Int} + :end {:type 'Int} + :sales_order_total {:type :money} + :sales_order_tax {:type :money}}} + + :expected_deposit_page {:fields {:expected_deposits {:type '(list :expected_deposit)} :count {:type 'Int} @@ -489,8 +493,8 @@ :import_ledger_result {:fields {:successful {:type '(list :import_ledger_entry_result)} :existing {:type '(list :import_ledger_entry_result)} :ignored {:type '(list :import_ledger_entry_result)} - :errors {:type '(list :import_ledger_entry_result)} - }} + :errors {:type '(list :import_ledger_entry_result)}}} + :upcoming_transaction {:fields {:amount {:type :money} :identifier {:type 'String} @@ -500,8 +504,8 @@ :invoices_due_soon {:type '(list :invoice)} :outstanding_payments {:type :money} :upcoming_credits {:type '(list :upcoming_transaction)} - :upcoming_debits {:type '(list :upcoming_transaction)}}} - } + :upcoming_debits {:type '(list :upcoming_transaction)}}}} + @@ -600,10 +604,10 @@ :resolve :get-all-expected-deposits} :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} + :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 {} @@ -612,16 +616,16 @@ :transaction_page {:type :transaction_page :args {:filters {:type :transaction_filters}} - :resolve :get-transaction-page} + :resolve :get-transaction-page} :transaction_rule_page {:type :transaction_rule_page - :args {:client_id {:type :id} - :vendor_id {:type :id} - :start {:type 'Int} - :per_page {:type 'Int} - :sort {:type '(list :sort_item)} - :asc {:type 'Boolean}} - :resolve :get-transaction-rule-page} + :args {:client_id {:type :id} + :vendor_id {:type :id} + :start {:type 'Int} + :per_page {:type 'Int} + :sort {:type '(list :sort_item)} + :asc {:type 'Boolean}} + :resolve :get-transaction-rule-page} :ledger_page {:type :ledger_page :args {:filters {:type :ledger_filters}} @@ -632,6 +636,7 @@ :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)}} @@ -670,9 +675,9 @@ :vendor {:type '(list :vendor) :resolve :get-vendor} :user {:type '(list :user) - :resolve :get-user} + :resolve :get-user}} - } + :input-objects { @@ -756,10 +761,10 @@ :matches {:type '(list String)} :location_matches {:type '(list :edit_location_match)} :bank_accounts {:type '(list :edit_bank_account)} - :forecasted_transactions {:type '(list :edit_forecasted_transaction)} - }} + :forecasted_transactions {:type '(list :edit_forecasted_transaction)}}} + :edit_bank_account - {:fields {:id {:type :id } + {:fields {:id {:type :id} :code {:type 'String} :type {:type :bank_account_type} :start_date {:type :iso_date} @@ -796,8 +801,8 @@ :add_terms_override {:fields {:id {:type :id} :client_id {:type :id} - :terms {:type 'Int} - }} + :terms {:type 'Int}}} + :add_account_override {:fields {:id {:type :id} @@ -833,8 +838,8 @@ :legal_entity_last_name {:type 'String} :legal_entity_tin {:type 'String} :legal_entity_tin_type {:type :tin_type} - :legal_entity_1099_type {:type :type_1099} - }} + :legal_entity_1099_type {:type :type_1099}}} + :edit_expense_account {:fields {:id {:type :id} @@ -944,8 +949,8 @@ :resolve :mutation/reject-invoices} :approve_invoices {:type '(list :id) - :args {:invoices {:type '(list :id)}} - :resolve :mutation/approve-invoices} + :args {:invoices {:type '(list :id)}} + :resolve :mutation/approve-invoices} :bulk_change_transaction_status {:type :message :args {:filters {:type :transaction_filters} @@ -987,7 +992,7 @@ :date {:type 'String} :check_number {:type 'Int} :bank_account_id {:type :id}} - :resolve :mutation/add-handwritten-check} + :resolve :mutation/add-handwritten-check} :edit_user {:type :user :args {:edit_user {:type :edit_user}} :resolve :mutation/edit-user} @@ -1026,9 +1031,9 @@ :resolve :mutation/match-transaction} :match_transaction_autopay_invoices {:type :transaction - :args {:transaction_id {:type :id} - :autopay_invoice_ids {:type '(list :id)}} - :resolve :mutation/match-transaction-autopay-invoices} + :args {:transaction_id {:type :id} + :autopay_invoice_ids {:type '(list :id)}} + :resolve :mutation/match-transaction-autopay-invoices} :match_transaction_unpaid_invoices {:type :transaction :args {:transaction_id {:type :id} @@ -1052,8 +1057,8 @@ :resolve :mutation/unvoid-invoice} :void_payment {:type :payment - :args {:payment_id {:type :id}} - :resolve :mutation/void-payment} + :args {:payment_id {:type :id}} + :resolve :mutation/void-payment} :edit_expense_accounts {:type :invoice :args {:invoice_id {:type :id} :expense_accounts {:type '(list :edit_expense_account)}} @@ -1122,7 +1127,7 @@ (assert-can-see-client (:id context) (:client_id args)) (->graphql (gq-checks/print-checks (map (fn [i] {:invoice-id (:invoice_id i) - :amount (:amount i)}) + :amount (:amount i)}) (:invoice_payments args)) (:client_id args) (:bank_account_id args) @@ -1145,9 +1150,9 @@ '[?account :account/name ?account-name] '[?expense-account :invoice-expense-account/amount ?amount]]}}) - true (d/query ))] + true (d/query))] (for [[account-id account-name total] result] - {:account {:id account-id :name account-name} :total total }))) + {:account {:id account-id :name account-name} :total total}))) (defn categorize [x] (cond (<= x 0) :due @@ -1172,10 +1177,10 @@ '[(.between java.time.temporal.ChronoUnit/DAYS (java.time.Instant/now) ?d2 ) ?d3] '[(auto-ap.graphql/categorize ?d3) ?name]]}}) - true (d/query )) + true (d/query)) result (group-by first result)] - (for [[id name] [[:due "Due"] [:due-30 "0-30 days"] [:due-60 "31-60 days"] [:due-later ">60 days"] ] + (for [[id name] [[:due "Due"] [:due-30 "0-30 days"] [:due-60 "31-60 days"] [:due-later ">60 days"]] :let [[[_ outstanding-balance total] ] (id result nil) outstanding-balance (or outstanding-balance 0) total (or total 0)]] @@ -1199,7 +1204,7 @@ (defn get-cash-flow [context {:keys [client_id]} value] (when client_id - (let [{:client/keys [week-a-credits week-a-debits week-b-credits week-b-debits forecasted-transactions ]} (d/pull (d/db (d/connect uri)) '[*] client_id ) + (let [{:client/keys [week-a-credits week-a-debits week-b-credits week-b-debits forecasted-transactions ]} (d/pull (d/db (d/connect uri)) '[*] client_id) total-cash (reduce (fn [total [credit debit]] (- (+ total credit) @@ -1249,7 +1254,7 @@ :let [next (t/plus (t/local-date (t/year (time/local-now)) (t/month (time/local-now)) (Math/min (Math/max day-of-month 1) - 30) ) + 30)) (t/months month))] :when (not (has-fulfilled? id next recent-fulfillments))] {:identifier identifier @@ -1281,8 +1286,8 @@ (or week-b-debits 0))) :date (coerce/to-date-time date)}) (take (* 7 4) (time/day-of-week-seq 1))) - (filter #(< (:amount %) 0) forecasted-transactions)) - }))) + (filter #(< (:amount %) 0) forecasted-transactions))}))) + (def schema (-> integreat-schema @@ -1368,7 +1373,7 @@ (defn query ([id q] - (query id q nil )) + (query id q nil)) ([id q v] (lc/with-context {:query q} (log/info "Executing query" q) @@ -1383,8 +1388,8 @@ (catch Exception e (if-let [v (or (:validation-error (ex-data e)) - (:validation-error (ex-data (.getCause e))) - )] + (:validation-error (ex-data (.getCause e))))] + (do (warn-event "validation error" {:validation-error v :data (ex-data e)}) diff --git a/src/clj/auto_ap/graphql/sales_orders.clj b/src/clj/auto_ap/graphql/sales_orders.clj index 4aa7be9a..85b02b2c 100644 --- a/src/clj/auto_ap/graphql/sales_orders.clj +++ b/src/clj/auto_ap/graphql/sales_orders.clj @@ -4,5 +4,7 @@ (defn get-sales-orders-page [context args value] (let [args (assoc args :id (:id context)) - [sales-orders sales-orders-count] (d-sales-orders2/get-graphql (<-graphql args))] - (result->page sales-orders sales-orders-count :sales_orders args ))) + [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))) 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 1e528b39..8114fee2 100644 --- a/src/cljs/auto_ap/views/pages/pos/sales_orders.cljs +++ b/src/cljs/auto_ap/views/pages/pos/sales_orders.cljs @@ -25,6 +25,7 @@ :total-gte (:amount-gte (:total-range params)) :total-lte (:amount-lte (:total-range params)) :date-range (:date-range params) + :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]] @@ -32,7 +33,9 @@ [:client [:name :id]]]] :total :start - :end]]]} + :end + :sales_order_total + :sales_order_tax]]]} :on-success (fn [result] (let [result (set/rename-keys (:sales-order-page result) {:sales-orders :data})] @@ -67,7 +70,6 @@ :reagent-render (fn [] (let [{form-active? :active?} @(re-frame/subscribe [::forms/form ::form/form])] - (println form-active?) [side-bar-layout {:side-bar [side-bar/side-bar {:data-page ::page}] :main [content] :right-side-bar [appearing-side-bar {:visible? form-active?} diff --git a/src/cljs/auto_ap/views/pages/pos/side_bar.cljs b/src/cljs/auto_ap/views/pages/pos/side_bar.cljs index 5474ea2b..05dedf94 100644 --- a/src/cljs/auto_ap/views/pages/pos/side_bar.cljs +++ b/src/cljs/auto_ap/views/pages/pos/side_bar.cljs @@ -1,17 +1,15 @@ (ns auto-ap.views.pages.pos.side-bar (:require [auto-ap.routes :as routes] [auto-ap.subs :as subs] - [auto-ap.views.utils :refer [active-when dispatch-value-change]] + [auto-ap.views.utils :refer [active-when dispatch-event]] [auto-ap.views.components.date-range-filter :refer [date-range-filter]] [auto-ap.views.components.number-filter :refer [number-filter]] - [auto-ap.views.components.bank-account-filter :refer [bank-account-filter]] [bidi.bidi :as bidi] [re-frame.core :as re-frame] [auto-ap.views.pages.data-page :as data-page])) (defn side-bar [{:keys [data-page]}] - (let [ap @(re-frame/subscribe [::subs/active-page]) - user @(re-frame/subscribe [::subs/user])] + (let [ap @(re-frame/subscribe [::subs/active-page])] [:div [:div [:p.menu-label "Type"] [:ul.menu-list @@ -37,4 +35,21 @@ [:div [number-filter {:on-change-event [::data-page/filter-changed data-page :total-range] - :value @(re-frame/subscribe [::data-page/filter data-page :total-range])}]]]])) + :value @(re-frame/subscribe [::data-page/filter data-page :total-range])}]] + + (when (= :sales-orders ap) + [:<> + [:p.menu-label "Processor"] + [:div + [:nav.panel + [:a.panel-block {:on-click (dispatch-event [::data-page/filter-changed data-page :processor "doordash"])} + [:span.panel-icon [:img.level-item {:src "/img/doordash.png"}]] + "Doordash"] + + [:a.panel-block {:on-click (dispatch-event [::data-page/filter-changed data-page :processor "uber-eats"])} + [:span.panel-icon [:img.level-item {:src "/img/ubereats.png" }]] + "Uber Eats"] + [:a.panel-block {:on-click (dispatch-event [::data-page/filter-changed data-page :processor "grubhub"])} + [:span.panel-icon [:img.level-item {:src "/img/grubhub.png"}]] + "Grubhub"]]]])]])) + diff --git a/src/cljs/auto_ap/views/pages/pos/table.cljs b/src/cljs/auto_ap/views/pages/pos/table.cljs index af23bc47..cc868d5b 100644 --- a/src/cljs/auto_ap/views/pages/pos/table.cljs +++ b/src/cljs/auto_ap/views/pages/pos/table.cljs @@ -13,10 +13,10 @@ [grid/row {:class (:class sales-order) :id id} (when-not selected-client [grid/cell {} (:name client)]) - [grid/cell {} (date->str date) ] - [grid/cell {:class "has-text-right"} (nf total )] - [grid/cell {:class "has-text-right"} (nf tax )] - [grid/cell {:class "has-text-right"} (nf tip )] + [grid/cell {} (date->str date)] + [grid/cell {:class "has-text-right"} (nf total)] + [grid/cell {:class "has-text-right"} (nf tax)] + [grid/cell {:class "has-text-right"} (nf tip)] [grid/cell {} [:div.level [:div.level-left @@ -43,22 +43,27 @@ "SQUARE_GIFT_CARD" [:span.icon.level-item {:style {:font-size "24px"}} [:span {:class "icon-gift-box" :style {:font-weight "400"}}]] - [:span.level-item "Other (" (:type-name charge) ")"] - )) - {:key (:id charge)}))]] + [:span.level-item "Other (" (:type-name charge) ")"])) + + {:key (:id charge)}))]]] + - ] [grid/cell {} (str/join ", " (map :item-name line-items))] -[grid/button-cell {} - [:div.buttons - [buttons/fa-icon {:event [::form/editing sales-order] :icon "fa-pencil"}]]]])) + [grid/button-cell {} + [:div.buttons + [buttons/fa-icon {:event [::form/editing sales-order] :icon "fa-pencil"}]]]])) (defn table [{:keys [data-page]}] (let [selected-client @(re-frame/subscribe [::subs/client]) {:keys [data status]} @(re-frame/subscribe [::data-page/page data-page])] [grid/grid {:data-page data-page :column-count (if selected-client 7 8)} - [grid/controls data] + [grid/controls data + [:div.level-item + [:div.tag "Total: " (nf (:sales-order-total data))] + ] + [:div.level-item + [:div.tag " Tax: " (nf (:sales-order-tax data))]]] [grid/table {:fullwidth true} [grid/header {} [grid/row {}