checking for existing invoices.
This commit is contained in:
@@ -63,7 +63,7 @@
|
|||||||
(defn get-all []
|
(defn get-all []
|
||||||
(query base-query))
|
(query base-query))
|
||||||
|
|
||||||
(defn find-conflicting [{:keys [id invoice-number company-id vendor-id]}]
|
(defn find-conflicting [{:keys [id invoice-number company-id vendor-id] :as i}]
|
||||||
(query
|
(query
|
||||||
(-> base-query
|
(-> base-query
|
||||||
(helpers/merge-where [:and [:not= :id id]
|
(helpers/merge-where [:and [:not= :id id]
|
||||||
|
|||||||
@@ -37,8 +37,14 @@
|
|||||||
(->graphql))))
|
(->graphql))))
|
||||||
|
|
||||||
|
|
||||||
(defn edit-invoice [context {{:keys [id] :as in} :invoice} value]
|
(defn edit-invoice [context {{:keys [id invoice_number vendor_id company_id] :as in} :invoice} value]
|
||||||
|
|
||||||
(let [invoice (invoices/get-by-id id)
|
(let [invoice (invoices/get-by-id id)
|
||||||
|
_ (when (seq (invoices/find-conflicting {:id id
|
||||||
|
:invoice-number invoice_number
|
||||||
|
:vendor-id (:vendor-id invoice)
|
||||||
|
:company-id (:company-id invoice)}))
|
||||||
|
(throw (ex-info "that invoice already exists" {:invoice-number invoice_number})))
|
||||||
paid-amount (- (:total invoice) (:outstanding-balance invoice))
|
paid-amount (- (:total invoice) (:outstanding-balance invoice))
|
||||||
_ (assert-can-see-company (:id context) (:company-id invoice))
|
_ (assert-can-see-company (:id context) (:company-id invoice))
|
||||||
updated-invoice (invoices/update (-> in
|
updated-invoice (invoices/update (-> in
|
||||||
|
|||||||
@@ -279,7 +279,8 @@
|
|||||||
[:expense_accounts [:amount :id :expense_account_id
|
[:expense_accounts [:amount :id :expense_account_id
|
||||||
:location
|
:location
|
||||||
[:expense_account [:id :name [:parent [:id :name]]]]]]]]}]}
|
[:expense_account [:id :name [:parent [:id :name]]]]]]]]}]}
|
||||||
:on-success [::invoice-edited]}})))
|
:on-success [::invoice-edited]
|
||||||
|
:on-error [::invoice-edit-failed]}})))
|
||||||
|
|
||||||
|
|
||||||
(re-frame/reg-event-fx
|
(re-frame/reg-event-fx
|
||||||
@@ -361,6 +362,12 @@
|
|||||||
i)) is)))
|
i)) is)))
|
||||||
(dissoc ::edit-invoice))}))
|
(dissoc ::edit-invoice))}))
|
||||||
|
|
||||||
|
|
||||||
|
(re-frame/reg-event-fx
|
||||||
|
::invoice-edit-failed
|
||||||
|
(fn [{:keys [db]} [_ data]]
|
||||||
|
{:dispatch [::events/modal-failed ::edit-invoice "That invoice already exists."]}))
|
||||||
|
|
||||||
(re-frame/reg-event-fx
|
(re-frame/reg-event-fx
|
||||||
::invoice-voided
|
::invoice-voided
|
||||||
(fn [{:keys [db]} [_ {:keys [void-invoice]}]]
|
(fn [{:keys [db]} [_ {:keys [void-invoice]}]]
|
||||||
|
|||||||
Reference in New Issue
Block a user