diff --git a/src/clj/auto_ap/datomic/invoices.clj b/src/clj/auto_ap/datomic/invoices.clj index a1edd0f9..85a15d22 100644 --- a/src/clj/auto_ap/datomic/invoices.clj +++ b/src/clj/auto_ap/datomic/invoices.clj @@ -44,7 +44,9 @@ '[?e :invoice/client ?c] '[?c :client/original-id ?original-id]) (:status args) (add-arg '?status (keyword "invoice-status" (:status args)) - '[?e :invoice/status ?status]))) + '[?e :invoice/status ?status]) + (:vendor-id args) (add-arg '?vendor-id (:vendor-id args) + '[?e :invoice/vendor ?vendor-id]))) (map first) (<-datomic))) diff --git a/src/clj/auto_ap/graphql.clj b/src/clj/auto_ap/graphql.clj index 0ee47ac3..d3dd1230 100644 --- a/src/clj/auto_ap/graphql.clj +++ b/src/clj/auto_ap/graphql.clj @@ -200,6 +200,7 @@ :args {:imported {:type 'Boolean} :status {:type 'String} :client_id {:type :id} + :vendor_id {:type :id} :start {:type 'Int} :sort_by {:type 'String} :asc {:type 'Boolean}} diff --git a/src/cljs/auto_ap/views/pages/unpaid_invoices.cljs b/src/cljs/auto_ap/views/pages/unpaid_invoices.cljs index 763f187e..50c5fa33 100644 --- a/src/cljs/auto_ap/views/pages/unpaid_invoices.cljs +++ b/src/cljs/auto_ap/views/pages/unpaid_invoices.cljs @@ -663,17 +663,41 @@ :step "0.01"}]]]]] ])) +(re-frame/reg-event-db + ::change-selected-vendor + (fn [db [_ key value]] + (let [[key] key + updated (assoc-in db [::invoice-page :vendor-filter key] value)] + (if (and (= key :vendor-id) + (not= value (get-in db [::params :vendor-id]))) + (do + (re-frame/dispatch [::params-change (assoc (::params updated) :vendor-id value)]) + (assoc-in updated [::params :vendor-id] value)) + updated)))) (def unpaid-invoices-page (with-meta (fn [] - (let [{:keys [checked print-checks-shown? print-checks-loading? advanced-print-shown?]} @(re-frame/subscribe [::invoice-page]) + (let [{:keys [checked print-checks-shown? print-checks-loading? advanced-print-shown? vendor-filter]} @(re-frame/subscribe [::invoice-page]) current-client @(re-frame/subscribe [::subs/client]) {check-results-shown? :shown? pdf-url :pdf-url} @(re-frame/subscribe [::check-results])] [:div [:h1.title "Unpaid invoices"] + [:div.field.has-addons.is-extended + [:p.control [:a.button.is-static "Filter Vendor"]] + [:div.control {:style {:width "500px"}} + [bind-field + [typeahead {:matches (map (fn [x] [(:id x) (:name x)]) @(re-frame/subscribe [::subs/vendors])) + :type "typeahead" + :auto-focus true + :field [:vendor-id] + :text-field [:vendor-name] + :event [::change-selected-vendor] + :spec (s/nilable ::invoice/vendor-id) + :subscription vendor-filter}]]]] + [:div.is-pulled-right [:button.button.is-danger {:on-click (dispatch-event [::new-invoice])} "New Invoice"] (when current-client