Prevents saving unless it's recommended.

This commit is contained in:
Bryce Covert
2020-10-23 19:12:49 -07:00
parent 7603263ba4
commit 5b459cd6f9
2 changed files with 103 additions and 8 deletions

View File

@@ -4,22 +4,23 @@
[auto-ap.forms :as forms]
[auto-ap.status :as status]
[auto-ap.subs :as subs]
[auto-ap.time-utils :refer [next-dom]]
[auto-ap.utils :refer [by dollars=]]
[auto-ap.views.components.dropdown :refer [drop-down]]
[auto-ap.time-utils :refer [next-dom]]
[auto-ap.views.components.expense-accounts-field
:as
expense-accounts-field
:refer
[expense-accounts-field recalculate-amounts]]
[auto-ap.views.components.layouts :as layouts]
[auto-ap.views.components.modal :as modal]
[auto-ap.views.components.money-field :refer [money-field]]
[auto-ap.views.components.switch-field :refer [switch-field]]
[auto-ap.views.components.typeahead :refer [typeahead-entity]]
[auto-ap.views.pages.invoices.common :refer [invoice-read]]
[auto-ap.views.utils
:refer
[date->str date-picker dispatch-event standard with-user str->date]]
[date->str date-picker dispatch-event standard str->date with-user]]
[cljs-time.core :as c]
[clojure.spec.alpha :as s]
[clojure.string :as str]
@@ -175,6 +176,7 @@
(let [schedule-payment-dom (get (by (comp :id :client ) :dom (:schedule-payment-dom value))
(:id (:client data)))]
(cond-> []
(expense-accounts-field/can-replace-with-default? (:expense-accounts data))
(into [[:expense-accounts] (expense-accounts-field/default-account (:expense-accounts data)
@(re-frame/subscribe [::subs/vendor-default-account value (:client data)])
@@ -184,11 +186,13 @@
(boolean ((set (map :id (:automatically-paid-when-due value))) (:id (:client data))))
(into [[:scheduled-payment] (:due data)
[:schedule-when-due] true])
[:schedule-when-due] true
[:vendor-autopay? ] true])
schedule-payment-dom
(into [[:scheduled-payment] (date->str (next-dom (str->date (:date data) standard) schedule-payment-dom) standard)])
(into [[:scheduled-payment] (date->str (next-dom (str->date (:date data) standard) schedule-payment-dom) standard)
[:vendor-autopay?] true])
true
(into [[:schedule-payment-dom] schedule-payment-dom])))
@@ -248,6 +252,26 @@
:create)])
:on-error [::forms/save-error ::form]}}))
(re-frame/reg-event-fx
::save-requested
[with-user (forms/in-form ::form)]
(fn [{:keys [user db]} [_ fwd-event]]
(if (and (:scheduled-payment (:data db))
(not (:vendor-autopay? (:data db))))
{:dispatch
[::modal/modal-requested {:title "Scheduled payment date"
:body [:div "This vendor isn't set up to be automatically paid. On "
(:scheduled-payment (:data db))
" the invoice will be marked as paid, but no payment will be made the vendor. "
"Are you sure you want to continue?"]
:confirm {:value "Save"
:class "is-warning"
:on-click #(do (re-frame/dispatch [::modal/modal-closed])
(re-frame/dispatch fwd-event))}
:cancel? true}]}
{:dispatch fwd-event})))
(re-frame/reg-event-fx
::added-and-printed
(fn [{:keys [db]} [_ result]]
@@ -266,7 +290,7 @@
(def invoice-form (forms/vertical-form {:can-submit [::can-submit]
:change-event [::changed]
:submit-event [::saving ]
:submit-event [::save-requested [::saving ]]
:id ::form}))
(re-frame/reg-event-fx
@@ -412,10 +436,10 @@
(list
(for [{:keys [id number name type]} (->> (:bank-accounts (:client data)) (filter :visible) (sort-by :sort-order))]
(if (= :cash type)
^{:key id} [:a.dropdown-item {:on-click (dispatch-event [::add-and-print id :cash])} "With cash"]
^{:key id} [:a.dropdown-item {:on-click (dispatch-event [::save-requested [::add-and-print id :cash]])} "With cash"]
(list
^{:key (str id "-check")} [:a.dropdown-item {:on-click (dispatch-event [::add-and-print id :check])} "Print checks from " name]
^{:key (str id "-debit")} [:a.dropdown-item {:on-click (dispatch-event [::add-and-print id :debit])} "Debit from " name]))))]]])
^{:key (str id "-check")} [:a.dropdown-item {:on-click (dispatch-event [::save-requested [::add-and-print id :check]])} "Print checks from " name]
^{:key (str id "-debit")} [:a.dropdown-item {:on-click (dispatch-event [::save-requested [::add-and-print id :debit]])} "Debit from " name]))))]]])
[:div.column
(submit-button "Save")]]])