you can't add an existing invoice.
This commit is contained in:
@@ -63,6 +63,15 @@
|
|||||||
(defn get-all []
|
(defn get-all []
|
||||||
(query base-query))
|
(query base-query))
|
||||||
|
|
||||||
|
(defn find-conflicting [{:keys [id invoice-number company-id vendor-id]}]
|
||||||
|
(query
|
||||||
|
(-> base-query
|
||||||
|
(helpers/merge-where [:and [:not= :id id]
|
||||||
|
[:= :invoice-number invoice-number]
|
||||||
|
[:= :company-id company-id]
|
||||||
|
[:= :vendor-id vendor-id]
|
||||||
|
[:not= :status "voided"]]))))
|
||||||
|
|
||||||
(defn get-multi [ids]
|
(defn get-multi [ids]
|
||||||
(query (-> base-query
|
(query (-> base-query
|
||||||
(helpers/merge-where [:in :id ids]))))
|
(helpers/merge-where [:in :id ids]))))
|
||||||
|
|||||||
@@ -13,6 +13,10 @@
|
|||||||
(vendors/insert {:name vendor-name :default-expense-account 0})))
|
(vendors/insert {:name vendor-name :default-expense-account 0})))
|
||||||
|
|
||||||
(defn add-invoice [context {{:keys [total invoice_number location company_id vendor_id vendor_name date] :as in} :invoice} value]
|
(defn add-invoice [context {{:keys [total invoice_number location company_id vendor_id vendor_name date] :as in} :invoice} value]
|
||||||
|
(when (seq (invoices/find-conflicting {:invoice-number invoice_number
|
||||||
|
:vendor-id vendor_id
|
||||||
|
:company-id company_id}))
|
||||||
|
(throw (ex-info "that invoice already exists" {:invoice-number invoice_number})))
|
||||||
(let [vendor (-create-or-get-vendor vendor_id vendor_name)
|
(let [vendor (-create-or-get-vendor vendor_id vendor_name)
|
||||||
_ (assert-can-see-company (:id context) company_id)
|
_ (assert-can-see-company (:id context) company_id)
|
||||||
company (companies/get-by-id company_id)
|
company (companies/get-by-id company_id)
|
||||||
|
|||||||
@@ -85,6 +85,14 @@
|
|||||||
(println "changing modal status" id "to")
|
(println "changing modal status" id "to")
|
||||||
(update-in db [:modal-state id] #(merge % state))))
|
(update-in db [:modal-state id] #(merge % state))))
|
||||||
|
|
||||||
|
(re-frame/reg-event-db
|
||||||
|
::modal-failed
|
||||||
|
(fn [db [_ id message]]
|
||||||
|
(println "CURRENT" (get-in db [:modal-state]))
|
||||||
|
(-> db
|
||||||
|
(assoc-in [:modal-state id :saving?] false)
|
||||||
|
(assoc-in [:modal-state id :error-message] message))))
|
||||||
|
|
||||||
(re-frame/reg-event-db
|
(re-frame/reg-event-db
|
||||||
::modal-completed
|
::modal-completed
|
||||||
(fn [db [_ id state]]
|
(fn [db [_ id state]]
|
||||||
|
|||||||
@@ -22,9 +22,10 @@
|
|||||||
foot])]])
|
foot])]])
|
||||||
|
|
||||||
(defn action-modal [{:keys [title action-text id save-event can-submit?] :or {can-submit? true}} & rest]
|
(defn action-modal [{:keys [title action-text id save-event can-submit?] :or {can-submit? true}} & rest]
|
||||||
(let [{:keys [visible? saving?]} @(re-frame/subscribe [::subs/modal-state id])]
|
(let [{:keys [visible? saving? error-message]} @(re-frame/subscribe [::subs/modal-state id])]
|
||||||
(when visible?
|
(when visible?
|
||||||
(-> [modal {:title title
|
(-> [modal {:title [:span title
|
||||||
|
]
|
||||||
:foot [:input.button.is-primary {:type "submit"
|
:foot [:input.button.is-primary {:type "submit"
|
||||||
:tab-index "0"
|
:tab-index "0"
|
||||||
:form id
|
:form id
|
||||||
@@ -45,7 +46,10 @@
|
|||||||
(into [:form {:id id
|
(into [:form {:id id
|
||||||
:on-submit (fn [e]
|
:on-submit (fn [e]
|
||||||
(.preventDefault e)
|
(.preventDefault e)
|
||||||
(re-frame/dispatch [::events/modal-status id {:saving? true}])
|
(re-frame/dispatch [::events/modal-status id {:saving? true :error-message nil}])
|
||||||
(re-frame/dispatch save-event))}]
|
(re-frame/dispatch save-event))}
|
||||||
|
(when error-message
|
||||||
|
[:div.notification.is-warning error-message])]
|
||||||
|
|
||||||
(r/children (r/current-component)) )]
|
(r/children (r/current-component)) )]
|
||||||
(into [(when saving? [:div.is-overlay {:style {"backgroundColor" "rgba(150,150,150, 0.5)"}}])])))))
|
(into [(when saving? [:div.is-overlay {:style {"backgroundColor" "rgba(150,150,150, 0.5)"}}])])))))
|
||||||
|
|||||||
@@ -259,7 +259,8 @@
|
|||||||
:location
|
:location
|
||||||
[:expense_account [:id :name [:parent [:id :name]]]]]]
|
[:expense_account [:id :name [:parent [:id :name]]]]]]
|
||||||
]]}]}
|
]]}]}
|
||||||
:on-success [::invoice-created]}})))
|
:on-success [::invoice-created]
|
||||||
|
:on-error [::invoice-create-failed]}})))
|
||||||
|
|
||||||
(re-frame/reg-event-fx
|
(re-frame/reg-event-fx
|
||||||
::edit-invoice-save
|
::edit-invoice-save
|
||||||
@@ -331,6 +332,11 @@
|
|||||||
invoices)))
|
invoices)))
|
||||||
(dissoc ::handwrite-checks))})))
|
(dissoc ::handwrite-checks))})))
|
||||||
|
|
||||||
|
(re-frame/reg-event-fx
|
||||||
|
::invoice-create-failed
|
||||||
|
(fn [{:keys [db]} [_ data]]
|
||||||
|
{:dispatch [::events/modal-failed ::new-invoice "That invoice already exists."]}))
|
||||||
|
|
||||||
(re-frame/reg-event-fx
|
(re-frame/reg-event-fx
|
||||||
::invoice-created
|
::invoice-created
|
||||||
(fn [{:keys [db]} [_ {:keys [add-invoice]}]]
|
(fn [{:keys [db]} [_ {:keys [add-invoice]}]]
|
||||||
|
|||||||
Reference in New Issue
Block a user