you can void checks now.

This commit is contained in:
Bryce Covert
2018-07-25 19:35:26 -07:00
parent 581e5e8798
commit 8bb35d70c0
3 changed files with 39 additions and 2 deletions

View File

@@ -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

View File

@@ -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))))

View File

@@ -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 ) ")")])