added ability to void invoices.
This commit is contained in:
@@ -53,6 +53,16 @@
|
||||
translateY(-100%); }
|
||||
}
|
||||
|
||||
@keyframes flashWarning {
|
||||
from {
|
||||
|
||||
}
|
||||
to {
|
||||
|
||||
background-color: #00d1b2;
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes flashPrimary {
|
||||
from {
|
||||
transform: translateY(100%);
|
||||
@@ -65,6 +75,9 @@
|
||||
}
|
||||
}
|
||||
|
||||
tbody tr.live-removed {
|
||||
animation: flashWarning 1.0s ease both;
|
||||
}
|
||||
tbody tr.live-added {
|
||||
animation: flashPrimary 1.0s ease both;
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@
|
||||
(j/update! (get-conn) :invoices {:imported true} [] ))
|
||||
|
||||
(defn update [v]
|
||||
(j/update! (get-conn) :invoices v ["id = ?" (:id v)])
|
||||
(j/update! (get-conn) :invoices (clj->db v) ["id = ?" (:id v)])
|
||||
(get-by-id (:id v)))
|
||||
|
||||
(defn reject []
|
||||
|
||||
@@ -290,6 +290,9 @@
|
||||
:edit_invoice {:type :invoice
|
||||
:args {:invoice {:type :edit_invoice}}
|
||||
:resolve :mutation/edit-invoice}
|
||||
:void_invoice {:type :invoice
|
||||
:args {:invoice_id {:type 'Int}}
|
||||
:resolve :mutation/void-invoice}
|
||||
:edit_expense_accounts {:type :invoice
|
||||
:args {:invoice_id {:type 'Int}
|
||||
:expense_accounts {:type '(list :edit_expense_account)}}
|
||||
@@ -504,6 +507,7 @@
|
||||
:mutation/edit-user gq-users/edit-user
|
||||
:mutation/add-invoice gq-invoices/add-invoice
|
||||
:mutation/edit-invoice gq-invoices/edit-invoice
|
||||
:mutation/void-invoice gq-invoices/void-invoice
|
||||
:mutation/edit-expense-accounts gq-invoices/edit-expense-accounts
|
||||
:get-vendor get-vendor
|
||||
:get-expense-account expense-accounts/get-expense-account
|
||||
|
||||
@@ -39,7 +39,17 @@
|
||||
_ (assert-can-see-company (:id context) (:company-id invoice))
|
||||
updated-invoice (invoices/update (-> in
|
||||
(update :date parse iso-date)
|
||||
(assoc :outstanding_balance (- (:total in) paid-amount))))]
|
||||
(assoc :outstanding-balance (- (:total in) paid-amount))))]
|
||||
(-> updated-invoice
|
||||
(->graphql))))
|
||||
|
||||
(defn void-invoice [context {id :invoice_id} value]
|
||||
(let [invoice (invoices/get-by-id id)
|
||||
_ (assert-can-see-company (:id context) (:company-id invoice))
|
||||
updated-invoice (invoices/update {:id id
|
||||
:total 0
|
||||
:outstanding-balance 0
|
||||
:status "voided"})]
|
||||
(-> updated-invoice
|
||||
(->graphql))))
|
||||
|
||||
|
||||
@@ -55,7 +55,7 @@
|
||||
|
||||
|
||||
|
||||
(defn invoice-table [{:keys [id invoice-page status on-params-change vendors params check-boxes checked on-check-changed on-edit-invoice expense-event]}]
|
||||
(defn invoice-table [{:keys [id invoice-page status on-params-change vendors params check-boxes checked on-check-changed on-edit-invoice on-void-invoice expense-event]}]
|
||||
(let [state (reagent/atom (or @params {}))
|
||||
visible-checks @(re-frame/subscribe [::visible-checks])
|
||||
visible-expense-accounts @(re-frame/subscribe [::visible-expense-accounts])
|
||||
@@ -180,9 +180,13 @@
|
||||
|
||||
[:hr.dropdown-divider]
|
||||
|
||||
[:a.dropdown-item.is-primary {:on-click (dispatch-event (conj expense-event id))} "Change"]]]])
|
||||
(when expense-event
|
||||
[:a.dropdown-item.is-primary {:on-click (dispatch-event (conj expense-event id))} "Change"])]]])
|
||||
[:span {:style {:margin-left "1em"}}]
|
||||
[:button.button {:on-click (fn [] (on-edit-invoice i))} [:span [:span.icon [:i.fa.fa-pencil]] " Edit"]]
|
||||
(when on-edit-invoice
|
||||
[:button.button {:on-click (fn [] (on-edit-invoice i))} [:span.icon [:i.fa.fa-pencil]]])
|
||||
(when (and on-void-invoice (= (:outstanding-balance i) (:total i)))
|
||||
[:button.button.is-warning.is-outlined {:on-click (fn [] (on-void-invoice i))} [:span [:span.icon [:i.fa.fa-undo]]]])
|
||||
(when (seq checks)
|
||||
|
||||
[:div.dropdown.is-right {:class (if (= id visible-checks)
|
||||
|
||||
@@ -278,6 +278,25 @@
|
||||
[:expense_account [:id :name [:parent [:id :name]]]]]]]]}]}
|
||||
:on-success [::invoice-edited]}})))
|
||||
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::void-invoice
|
||||
(fn [{:keys [db]} [_ {id :id}]]
|
||||
{:graphql
|
||||
{:token (-> db :user)
|
||||
:query-obj {:venia/operation {:operation/type :mutation
|
||||
:operation/name "VoidInvoice"}
|
||||
|
||||
:venia/queries [{:query/data [:void-invoice
|
||||
{:invoice-id id}
|
||||
[:id :total :outstanding-balance :date :invoice-number
|
||||
[:company [:id :name :locations]]
|
||||
[:vendor [:id :name]]
|
||||
[:expense_accounts [:amount :id :expense_account_id
|
||||
:location
|
||||
[:expense_account [:id :name [:parent [:id :name]]]]]]]]}]}
|
||||
:on-success [::invoice-voided]}}))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::handwrite-checks-save
|
||||
(fn [{:keys [db]} _]
|
||||
@@ -334,6 +353,17 @@
|
||||
i)) is)))
|
||||
(dissoc ::edit-invoice))}))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::invoice-voided
|
||||
(fn [{:keys [db]} [_ {:keys [void-invoice]}]]
|
||||
{:db (-> db
|
||||
(update-in [::invoice-page :invoices]
|
||||
(fn [is]
|
||||
(mapv (fn [i]
|
||||
(if (= (:id i) (:id void-invoice))
|
||||
(assoc void-invoice :class "live-removed")
|
||||
i)) is))))}))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::change-expense-accounts
|
||||
(fn [{:keys [db]} [_ id]]
|
||||
@@ -755,6 +785,9 @@
|
||||
:status (re-frame/subscribe [::subs/status])
|
||||
:on-edit-invoice (fn [which]
|
||||
(re-frame/dispatch [::edit-invoice which]))
|
||||
|
||||
:on-void-invoice (fn [which]
|
||||
(re-frame/dispatch [::void-invoice which]))
|
||||
:on-params-change (fn [params]
|
||||
(re-frame/dispatch [::params-change params]))
|
||||
:check-boxes true
|
||||
|
||||
Reference in New Issue
Block a user