checking for existing invoices.
This commit is contained in:
@@ -63,7 +63,7 @@
|
||||
(defn get-all []
|
||||
(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
|
||||
(-> base-query
|
||||
(helpers/merge-where [:and [:not= :id id]
|
||||
|
||||
@@ -37,8 +37,14 @@
|
||||
(->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)
|
||||
_ (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))
|
||||
_ (assert-can-see-company (:id context) (:company-id invoice))
|
||||
updated-invoice (invoices/update (-> in
|
||||
|
||||
@@ -279,7 +279,8 @@
|
||||
[:expense_accounts [:amount :id :expense_account_id
|
||||
:location
|
||||
[: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
|
||||
@@ -361,6 +362,12 @@
|
||||
i)) is)))
|
||||
(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
|
||||
::invoice-voided
|
||||
(fn [{:keys [db]} [_ {:keys [void-invoice]}]]
|
||||
|
||||
Reference in New Issue
Block a user