Prevents saving unless it's recommended.
This commit is contained in:
71
scratch-sessions/fix_incorrect_locations.clj
Normal file
71
scratch-sessions/fix_incorrect_locations.clj
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
(ns fix-incorrect-locations)
|
||||||
|
|
||||||
|
|
||||||
|
(count
|
||||||
|
(d/query {:query {:find ['?e]
|
||||||
|
:in ['$]
|
||||||
|
:where ['[?e :journal-entry/line-items ?jel]
|
||||||
|
'[?jel :journal-entry-line/account ?a]
|
||||||
|
'[?a :account/location "A"]
|
||||||
|
'(not [?jel :journal-entry-line/location "A"])
|
||||||
|
]}
|
||||||
|
:args [(d/db auto-ap.datomic/conn)]}))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#_(->> (d/query {:query {:find ['?ea]
|
||||||
|
:in ['$]
|
||||||
|
:where ['[?e :journal-entry/line-items ?jel]
|
||||||
|
'[?jel :journal-entry-line/account ?a]
|
||||||
|
'[?a :account/location "A"]
|
||||||
|
'(not [?jel :journal-entry-line/location "A"])
|
||||||
|
'[?e :journal-entry/original-entity ?i]
|
||||||
|
'[?i :invoice/invoice-number]
|
||||||
|
'[?i :invoice/expense-accounts ?ea]
|
||||||
|
'[?ea :invoice-expense-account/account ?a]
|
||||||
|
'(not [?ea :invoice-expense-account/location "A"])
|
||||||
|
]}
|
||||||
|
:args [(d/db auto-ap.datomic/conn)]})
|
||||||
|
(map (fn [[ea]]
|
||||||
|
{:db/id ea
|
||||||
|
:invoice-expense-account/location "A"}))
|
||||||
|
(d/transact auto-ap.datomic/conn)
|
||||||
|
deref)
|
||||||
|
|
||||||
|
|
||||||
|
#_(count
|
||||||
|
(->>
|
||||||
|
(d/query {:query {:find ['?ta]
|
||||||
|
:in ['$]
|
||||||
|
:where ['[?e :journal-entry/line-items ?jel]
|
||||||
|
'[?jel :journal-entry-line/account ?a]
|
||||||
|
'[?a :account/location "A"]
|
||||||
|
'(not [?jel :journal-entry-line/location "A"])
|
||||||
|
'[?e :journal-entry/original-entity ?t]
|
||||||
|
'[?t :transaction/accounts ?ta]
|
||||||
|
'[?ta :transaction-account/account ?a]
|
||||||
|
'(not [?ta :transaction-account/location "A"])
|
||||||
|
]}
|
||||||
|
:args [(d/db auto-ap.datomic/conn)]})
|
||||||
|
(map (fn [[ea]]
|
||||||
|
{:db/id ea
|
||||||
|
:transaction-account/location "A"}))
|
||||||
|
(d/transact auto-ap.datomic/conn)
|
||||||
|
deref))
|
||||||
|
|
||||||
|
#_(count
|
||||||
|
(->>
|
||||||
|
(d/query {:query {:find ['?jel]
|
||||||
|
:in ['$]
|
||||||
|
:where ['[?e :journal-entry/line-items ?jel]
|
||||||
|
'[?jel :journal-entry-line/account ?a]
|
||||||
|
'[?a :account/location "A"]
|
||||||
|
'(not [?jel :journal-entry-line/location "A"])
|
||||||
|
'[?e :journal-entry/external-id]
|
||||||
|
]}
|
||||||
|
:args [(d/db auto-ap.datomic/conn)]})
|
||||||
|
(map (fn [[ea]]
|
||||||
|
{:db/id ea
|
||||||
|
:journal-entry-line/location "A"}))
|
||||||
|
(d/transact auto-ap.datomic/conn)
|
||||||
|
deref))
|
||||||
@@ -4,22 +4,23 @@
|
|||||||
[auto-ap.forms :as forms]
|
[auto-ap.forms :as forms]
|
||||||
[auto-ap.status :as status]
|
[auto-ap.status :as status]
|
||||||
[auto-ap.subs :as subs]
|
[auto-ap.subs :as subs]
|
||||||
|
[auto-ap.time-utils :refer [next-dom]]
|
||||||
[auto-ap.utils :refer [by dollars=]]
|
[auto-ap.utils :refer [by dollars=]]
|
||||||
[auto-ap.views.components.dropdown :refer [drop-down]]
|
[auto-ap.views.components.dropdown :refer [drop-down]]
|
||||||
[auto-ap.time-utils :refer [next-dom]]
|
|
||||||
[auto-ap.views.components.expense-accounts-field
|
[auto-ap.views.components.expense-accounts-field
|
||||||
:as
|
:as
|
||||||
expense-accounts-field
|
expense-accounts-field
|
||||||
:refer
|
:refer
|
||||||
[expense-accounts-field recalculate-amounts]]
|
[expense-accounts-field recalculate-amounts]]
|
||||||
[auto-ap.views.components.layouts :as layouts]
|
[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.money-field :refer [money-field]]
|
||||||
[auto-ap.views.components.switch-field :refer [switch-field]]
|
[auto-ap.views.components.switch-field :refer [switch-field]]
|
||||||
[auto-ap.views.components.typeahead :refer [typeahead-entity]]
|
[auto-ap.views.components.typeahead :refer [typeahead-entity]]
|
||||||
[auto-ap.views.pages.invoices.common :refer [invoice-read]]
|
[auto-ap.views.pages.invoices.common :refer [invoice-read]]
|
||||||
[auto-ap.views.utils
|
[auto-ap.views.utils
|
||||||
:refer
|
: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]
|
[cljs-time.core :as c]
|
||||||
[clojure.spec.alpha :as s]
|
[clojure.spec.alpha :as s]
|
||||||
[clojure.string :as str]
|
[clojure.string :as str]
|
||||||
@@ -175,6 +176,7 @@
|
|||||||
(let [schedule-payment-dom (get (by (comp :id :client ) :dom (:schedule-payment-dom value))
|
(let [schedule-payment-dom (get (by (comp :id :client ) :dom (:schedule-payment-dom value))
|
||||||
(:id (:client data)))]
|
(:id (:client data)))]
|
||||||
(cond-> []
|
(cond-> []
|
||||||
|
|
||||||
(expense-accounts-field/can-replace-with-default? (:expense-accounts data))
|
(expense-accounts-field/can-replace-with-default? (:expense-accounts data))
|
||||||
(into [[:expense-accounts] (expense-accounts-field/default-account (:expense-accounts data)
|
(into [[:expense-accounts] (expense-accounts-field/default-account (:expense-accounts data)
|
||||||
@(re-frame/subscribe [::subs/vendor-default-account value (:client 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))))
|
(boolean ((set (map :id (:automatically-paid-when-due value))) (:id (:client data))))
|
||||||
(into [[:scheduled-payment] (:due data)
|
(into [[:scheduled-payment] (:due data)
|
||||||
[:schedule-when-due] true])
|
[:schedule-when-due] true
|
||||||
|
[:vendor-autopay? ] true])
|
||||||
|
|
||||||
|
|
||||||
schedule-payment-dom
|
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
|
true
|
||||||
(into [[:schedule-payment-dom] schedule-payment-dom])))
|
(into [[:schedule-payment-dom] schedule-payment-dom])))
|
||||||
@@ -248,6 +252,26 @@
|
|||||||
:create)])
|
:create)])
|
||||||
:on-error [::forms/save-error ::form]}}))
|
: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
|
(re-frame/reg-event-fx
|
||||||
::added-and-printed
|
::added-and-printed
|
||||||
(fn [{:keys [db]} [_ result]]
|
(fn [{:keys [db]} [_ result]]
|
||||||
@@ -266,7 +290,7 @@
|
|||||||
|
|
||||||
(def invoice-form (forms/vertical-form {:can-submit [::can-submit]
|
(def invoice-form (forms/vertical-form {:can-submit [::can-submit]
|
||||||
:change-event [::changed]
|
:change-event [::changed]
|
||||||
:submit-event [::saving ]
|
:submit-event [::save-requested [::saving ]]
|
||||||
:id ::form}))
|
:id ::form}))
|
||||||
|
|
||||||
(re-frame/reg-event-fx
|
(re-frame/reg-event-fx
|
||||||
@@ -412,10 +436,10 @@
|
|||||||
(list
|
(list
|
||||||
(for [{:keys [id number name type]} (->> (:bank-accounts (:client data)) (filter :visible) (sort-by :sort-order))]
|
(for [{:keys [id number name type]} (->> (:bank-accounts (:client data)) (filter :visible) (sort-by :sort-order))]
|
||||||
(if (= :cash type)
|
(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
|
(list
|
||||||
^{:key (str id "-check")} [:a.dropdown-item {:on-click (dispatch-event [::add-and-print id :check])} "Print checks 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 [::add-and-print id :debit])} "Debit 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
|
[:div.column
|
||||||
|
|
||||||
(submit-button "Save")]]])
|
(submit-button "Save")]]])
|
||||||
|
|||||||
Reference in New Issue
Block a user