From 8a74f4a4e235d1b68bd61d45f994e54c697f6137 Mon Sep 17 00:00:00 2001 From: Bryce Covert Date: Thu, 23 Aug 2018 18:46:08 -0700 Subject: [PATCH] filtering down to just active invoices/etc. --- src/clj/auto_ap/db/checks.clj | 5 +++-- src/clj/auto_ap/db/invoices.clj | 4 +++- src/clj/auto_ap/graphql.clj | 6 ++++-- src/clj/auto_ap/routes/exports.clj | 7 +++++-- 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/clj/auto_ap/db/checks.clj b/src/clj/auto_ap/db/checks.clj index a2e612c2..afca5202 100644 --- a/src/clj/auto_ap/db/checks.clj +++ b/src/clj/auto_ap/db/checks.clj @@ -80,7 +80,7 @@ :else q))) -(defn base-graphql [{:keys [company-id vendor-id check-number bank-account-id status amount id]}] +(defn base-graphql [{:keys [company-id vendor-id check-number bank-account-id status amount id statuses]}] (cond-> base-query (limited-companies id) (helpers/merge-where [:in :company-id (limited-companies id)]) @@ -89,7 +89,8 @@ (not (nil? vendor-id)) (helpers/merge-where [:= :vendor-id vendor-id]) (not (nil? check-number)) (helpers/merge-where [:= :check-number check-number]) (not (nil? status)) (helpers/merge-where [:= :status status]) - (not (nil? amount)) (helpers/merge-where [:= :amount amount]))) + (not (nil? amount)) (helpers/merge-where [:= :amount amount]) + (seq statuses ) (helpers/merge-where [:in :status statuses]))) (defn get-graphql [{:keys [start sort-by asc id limit] :as args :or {limit 20}}] (query diff --git a/src/clj/auto_ap/db/invoices.clj b/src/clj/auto_ap/db/invoices.clj index 53062c44..a68f6bfd 100644 --- a/src/clj/auto_ap/db/invoices.clj +++ b/src/clj/auto_ap/db/invoices.clj @@ -142,9 +142,10 @@ -(defn base-graphql [{:keys [imported company-id status id]}] +(defn base-graphql [{:keys [imported company-id status id statuses]}] (cond-> base-query (limited-companies id) (helpers/merge-where [:in :company-id (limited-companies id)]) + (seq statuses ) (helpers/merge-where [:in :status statuses]) (not (nil? imported)) (helpers/merge-where [:= :imported imported]) (not (nil? status)) (helpers/merge-where [:= :status status]) (not (nil? company-id)) (helpers/merge-where [:= :company-id company-id]))) @@ -152,6 +153,7 @@ (defn get-graphql [{:keys [start sort-by asc limit] :as args :or {limit 20}}] (query (cond-> (base-graphql args) + true (add-sort-by sort-by asc) true (assoc :limit limit) start (assoc :offset start)))) diff --git a/src/clj/auto_ap/graphql.clj b/src/clj/auto_ap/graphql.clj index 02c88bcf..50b28313 100644 --- a/src/clj/auto_ap/graphql.clj +++ b/src/clj/auto_ap/graphql.clj @@ -203,11 +203,13 @@ :resolve :get-invoice-page} :all_invoices {:type '(list :invoice) - :args {:company_id {:type 'Int}} + :args {:company_id {:type 'Int} + :statuses {:type '(list String)}} :resolve :get-all-invoices} :all_checks {:type '(list :check) - :args {:company_id {:type 'Int}} + :args {:company_id {:type 'Int} + :statuses {:type '(list String)}} :resolve :get-all-checks} :transaction_page {:type '(list :transaction_page) diff --git a/src/clj/auto_ap/routes/exports.clj b/src/clj/auto_ap/routes/exports.clj index 994b8834..30823ab1 100644 --- a/src/clj/auto_ap/routes/exports.clj +++ b/src/clj/auto_ap/routes/exports.clj @@ -25,7 +25,9 @@ (GET "/invoices/export" {:keys [query-params identity] :as request} (assert-admin identity) (let [query [[:all_invoices - {:company-id (query-params "company")} + {:company-id (query-params "company") + :statuses ["unpaid" "paid"]} + [:id :total :outstanding-balance :invoice-number :date [:checks [:amount [:check [:check-number :memo [:bank_account [:id :number :bank-name :bank-code]]]]]] [:vendor [:name :id :primary_contact [:address [:street1 :city :state :zip]]]] @@ -37,7 +39,8 @@ (GET "/checks/export" {:keys [query-params identity]} (assert-admin identity) (let [query [[:all_checks - {:company-id (query-params "company")} + {:company-id (query-params "company") + :statuses ["pending" "cleared"]} [:id :check-number :amount :memo :date [:invoices [:invoice-id :amount]] [:bank-account [:number :bank-name :bank-code :id]]