From 8bb35d70c051129a48699365e8bfc4f716b33dc3 Mon Sep 17 00:00:00 2001 From: Bryce Covert Date: Wed, 25 Jul 2018 19:35:26 -0700 Subject: [PATCH] you can void checks now. --- src/clj/auto_ap/graphql.clj | 4 ++++ src/clj/auto_ap/graphql/checks.clj | 11 ++++++++-- src/cljs/auto_ap/views/pages/checks.cljs | 26 ++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 2 deletions(-) diff --git a/src/clj/auto_ap/graphql.clj b/src/clj/auto_ap/graphql.clj index 265b39ae..385f83b8 100644 --- a/src/clj/auto_ap/graphql.clj +++ b/src/clj/auto_ap/graphql.clj @@ -293,6 +293,9 @@ :void_invoice {:type :invoice :args {:invoice_id {:type 'Int}} :resolve :mutation/void-invoice} + :void_check {:type :check + :args {:check_id {:type 'Int}} + :resolve :mutation/void-check} :edit_expense_accounts {:type :invoice :args {:invoice_id {:type 'Int} :expense_accounts {:type '(list :edit_expense_account)}} @@ -508,6 +511,7 @@ :mutation/add-invoice gq-invoices/add-invoice :mutation/edit-invoice gq-invoices/edit-invoice :mutation/void-invoice gq-invoices/void-invoice + :mutation/void-check gq-checks/void-check :mutation/edit-expense-accounts gq-invoices/edit-expense-accounts :get-vendor get-vendor :get-expense-account expense-accounts/get-expense-account diff --git a/src/clj/auto_ap/graphql/checks.clj b/src/clj/auto_ap/graphql/checks.clj index 4cd96bb8..22dd5cf0 100644 --- a/src/clj/auto_ap/graphql/checks.clj +++ b/src/clj/auto_ap/graphql/checks.clj @@ -64,5 +64,12 @@ :invoices [(invoices/get-by-id (:invoice_id args))]}))) - - +(defn void-check [context {id :check_id} value] + (let [check (checks/get-by-id id)] + (assert-can-see-company (:id context) (:company-id check)) + (assert (= "pending" (:status check))) + (checks/update! {:id id + :amount 0 + :status "voided"}) + (-> (checks/get-by-id id) + (->graphql)))) diff --git a/src/cljs/auto_ap/views/pages/checks.cljs b/src/cljs/auto_ap/views/pages/checks.cljs index f46a43e7..f7fc2116 100644 --- a/src/cljs/auto_ap/views/pages/checks.cljs +++ b/src/cljs/auto_ap/views/pages/checks.cljs @@ -42,6 +42,30 @@ :end]]]} :on-success [::received]}})) +(re-frame/reg-event-fx + ::void-check + (fn [{:keys [db]} [_ check]] + {:graphql + {:token (-> db :user) + :query-obj {:venia/operation {:operation/type :mutation + :operation/name "VoidCheck"} + + :venia/queries [{:query/data [:void-check + {:check-id (:id check)} + [:id :status :amount :check_number :s3_url :date [:vendor [:name :id]] [:company [:name :id]]]]}]} + :on-success [::check-voided]}})) + +(re-frame/reg-event-db + ::check-voided + (fn [db [_ {:keys [void-check]}]] + (-> db + (update-in [::check-page :checks] (fn [checks] + (mapv (fn [c] + (if (= (:id c) (:id void-check)) + (assoc void-check :class "live-removed") + c)) + checks)) )))) + (re-frame/reg-event-db ::received (fn [db [_ data]] @@ -134,6 +158,8 @@ [:td (gstring/format "$%.2f" amount )] [:td status] [:td + (when (= "pending" status) + [:button.button.is-warning.is-outlined {:on-click (dispatch-event [::void-check i])} [:span [:span.icon [:i.fa.fa-undo]]]]) (if s3-url [:a.tag {:href s3-url :target "_new"} [:i.fa.fa-money-check] [:span.icon [:i.fa.fa-money]] (str " " check-number " (" (gstring/format "$%.2f" amount ) ")")] [:span.tag [:i.fa.fa-money-check] [:span.icon [:i.fa.fa-money]] (str " " check-number " (" (gstring/format "$%.2f" amount ) ")")])