diff --git a/src/clj/auto_ap/datomic/checks.clj b/src/clj/auto_ap/datomic/checks.clj index 4afa7391..e10e1aff 100644 --- a/src/clj/auto_ap/datomic/checks.clj +++ b/src/clj/auto_ap/datomic/checks.clj @@ -130,6 +130,11 @@ '[(<= ?date ?end-date)]]} :args [(c/to-date (:end (:date-range args)))]}) + (:payment-type args) + (merge-query {:query {:in '[?payment-type] + :where ['[?e :payment/type ?payment-type]]} + :args [(:payment-type args)]}) + check-number-like (merge-query {:query {:in '[?check-number-like] :where ['[?e :payment/check-number ?check-number-like]]} diff --git a/src/clj/auto_ap/graphql.clj b/src/clj/auto_ap/graphql.clj index 57c662d3..49d6f4dd 100644 --- a/src/clj/auto_ap/graphql.clj +++ b/src/clj/auto_ap/graphql.clj @@ -634,6 +634,7 @@ :payment_page {:type '(list :payment_page) :args {:client_id {:type :id} :vendor_id {:type :id} + :payment_type {:type :payment_type} :exact_match_id {:type :id} :date_range {:type :date_range} :amount_lte {:type :money} diff --git a/src/clj/auto_ap/graphql/checks.clj b/src/clj/auto_ap/graphql/checks.clj index 414adb7f..897f5a0f 100644 --- a/src/clj/auto_ap/graphql/checks.clj +++ b/src/clj/auto_ap/graphql/checks.clj @@ -9,7 +9,7 @@ [auto-ap.datomic.vendors :as d-vendors] [auto-ap.graphql.utils :refer - [->graphql <-graphql assert-can-see-client]] + [->graphql <-graphql assert-can-see-client enum->keyword]] [auto-ap.numeric :refer [num->words]] [auto-ap.time :refer [iso-date local-now parse]] [auto-ap.utils :refer [by dollars-0?]] @@ -353,7 +353,7 @@ (defn get-payment-page [context args value] (let [args (assoc args :id (:id context)) - [payments checks-count] (d-checks/get-graphql (<-graphql args))] + [payments checks-count] (d-checks/get-graphql (update (<-graphql args) :payment-type enum->keyword "payment-type"))] [{:payments (->> payments (map (fn [payment] diff --git a/src/clj/auto_ap/routes/exports.clj b/src/clj/auto_ap/routes/exports.clj index e158f2f2..6e599a96 100644 --- a/src/clj/auto_ap/routes/exports.clj +++ b/src/clj/auto_ap/routes/exports.clj @@ -8,12 +8,14 @@ [auto-ap.graphql.utils :refer [->graphql <-graphql assert-admin]] [auto-ap.routes.utils :refer [wrap-secure]] [clojure.tools.logging :as log] + [auto-ap.logging :refer [error-event info-event warn-event]] [clj-time.coerce :as coerce :refer [to-date]] [clj-time.core :as time] [compojure.core :refer [context defroutes GET wrap-routes]] [datomic.api :as d] [ring.middleware.json :refer [wrap-json-response]] - [venia.core :as venia])) + [venia.core :as venia] + [yang.time :refer [time-it]])) (defroutes routes (wrap-routes @@ -125,14 +127,19 @@ (assert-admin identity) (map <-graphql (d-vendors/get-graphql {}))) (GET "/ledger/export" {:keys [query-params identity]} + (log/info "exporting for " (query-params "client-code")) (assert-admin identity) - (transduce (comp - (map #(update % :journal-entry/date to-date)) - (map <-graphql)) - conj - (list) - (first (d-ledger/get-graphql {:count Integer/MAX_VALUE - :client-code (query-params "client-code")})))) + (let [[result time] (time-it (transduce (comp + (map #(update % :journal-entry/date to-date)) + (map <-graphql)) + conj + (list) + (first (d-ledger/get-graphql {:count Integer/MAX_VALUE + :client-code (query-params "client-code")}))))] + (info-event "Export completed" + {:time (:time time) + :errors (seq (:errors result))}) + result)) (GET "/accounts/export" {:keys [query-params identity]} (assert-admin identity) diff --git a/src/cljs/auto_ap/views/pages/payments.cljs b/src/cljs/auto_ap/views/pages/payments.cljs index 6e8be9af..469a7e46 100644 --- a/src/cljs/auto_ap/views/pages/payments.cljs +++ b/src/cljs/auto_ap/views/pages/payments.cljs @@ -38,6 +38,7 @@ :sort (:sort params) :client-id (:id @(re-frame/subscribe [::subs/client])) :vendor-id (:id (:vendor params)) + :payment-type (:payment-type params) :exact-match-id (some-> (:exact-match-id params) str) :date-range (:date-range params) :amount-gte (:amount-gte (:amount-range params)) diff --git a/src/cljs/auto_ap/views/pages/payments/side_bar.cljs b/src/cljs/auto_ap/views/pages/payments/side_bar.cljs index 171ac5d2..cc2971a4 100644 --- a/src/cljs/auto_ap/views/pages/payments/side_bar.cljs +++ b/src/cljs/auto_ap/views/pages/payments/side_bar.cljs @@ -45,6 +45,27 @@ :value @(re-frame/subscribe [::data-page/filter data-page :invoice-number]) :on-change (dispatch-value-change [::data-page/filter-changed data-page :invoice-number])} ]]] + [:p.menu-label "Payment Type"] + [:div.field.has-addons + [:p.control [:a.button.is-small {:on-click + (dispatch-event [::data-page/filter-changed data-page :payment-type :cash]) + :class (when (= :cash @(re-frame/subscribe [::data-page/filter data-page :payment-type])) + ["is-selected" "is-success"])} + "Cash" ]] + [:p.control [:a.button.is-small {:on-click + (dispatch-event [::data-page/filter-changed data-page :payment-type :check]) + :class (when (= :check @(re-frame/subscribe [::data-page/filter data-page :payment-type])) + ["is-selected" "is-success"])} + "Check" ]] + [:p.control [:a.button.is-small {:on-click + (dispatch-event [::data-page/filter-changed data-page :payment-type :debit]) + :class (when (= :debit @(re-frame/subscribe [::data-page/filter data-page :payment-type])) + ["is-selected" "is-success"])} + "Debit"]] + [:p.control [:a.button.is-small {:on-click + (dispatch-event [::data-page/filter-changed data-page :payment-type nil])} + "All"]]] + (when-let [exact-match-id @(re-frame/subscribe [::data-page/filter data-page :exact-match-id])] [:div [:p.menu-label "Specific Payment"]