a good experience for dates.
This commit is contained in:
@@ -9,12 +9,12 @@
|
||||
[auto-ap.time-utils :refer [next-dom]]
|
||||
[auto-ap.utils :refer [dollars=]]
|
||||
[auto-ap.views.components.expense-accounts-field
|
||||
:as expense-accounts-field
|
||||
:refer [recalculate-amounts]]
|
||||
:as eaf
|
||||
:refer [recalculate-amounts
|
||||
expense-accounts-field]]
|
||||
[auto-ap.views.components.layouts :as layouts]
|
||||
[auto-ap.views.components.level :refer [left-stack]]
|
||||
[auto-ap.views.components.modal :as modal]
|
||||
[auto-ap.views.components.expense-accounts-field :refer [expense-accounts-field]]
|
||||
[auto-ap.views.components.dropdown :refer [drop-down]]
|
||||
[auto-ap.views.components.money-field :refer [money-field]]
|
||||
[auto-ap.views.components.switch-field :refer [switch-field]]
|
||||
@@ -23,11 +23,8 @@
|
||||
:refer [search-backed-typeahead]]
|
||||
[auto-ap.views.pages.invoices.common :refer [invoice-read]]
|
||||
[auto-ap.views.utils
|
||||
:refer [date->str
|
||||
date-picker-friendly
|
||||
:refer [date-picker-optional
|
||||
dispatch-event
|
||||
standard
|
||||
str->date
|
||||
with-user]]
|
||||
[cljs-time.core :as c]
|
||||
[clojure.spec.alpha :as s]
|
||||
@@ -58,11 +55,12 @@
|
||||
{:venia/operation {:operation/type :mutation
|
||||
:operation/name "AddInvoice"}
|
||||
:venia/queries [{:query/data [:add-invoice
|
||||
{:invoice {:date date
|
||||
:due due
|
||||
{:invoice {
|
||||
:vendor-id (:id vendor)
|
||||
:client-id (:id client)
|
||||
:date date
|
||||
:scheduled-payment scheduled-payment
|
||||
:due due
|
||||
:invoice-number (some-> invoice-number str/trim)
|
||||
:location location
|
||||
:total total
|
||||
@@ -79,6 +77,7 @@
|
||||
::edit-query
|
||||
:<- [::forms/form ::form]
|
||||
(fn [{{:keys [id invoice-number date due scheduled-payment total expense-accounts]} :data}]
|
||||
|
||||
{:venia/operation {:operation/type :mutation
|
||||
:operation/name "EditInvoice"}
|
||||
:venia/queries [{:query/data [:edit-invoice
|
||||
@@ -110,7 +109,7 @@
|
||||
(forms/stop-form ::form )
|
||||
(forms/start-form ::form {:client client
|
||||
:status :unpaid
|
||||
:date (date->str (c/now) standard)}))})))
|
||||
:date (c/now)}))})))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::adding
|
||||
@@ -119,7 +118,7 @@
|
||||
(fn [{:keys [db] ::subs/keys [locations-for-client]} [_ new]]
|
||||
{:db
|
||||
(-> db (forms/start-form ::form (assoc new :expense-accounts
|
||||
(expense-accounts-field/from-graphql (:expense-accounts new)
|
||||
(eaf/from-graphql (:expense-accounts new)
|
||||
0.0
|
||||
locations-for-client))))}))
|
||||
(re-frame/reg-event-fx
|
||||
@@ -127,10 +126,7 @@
|
||||
[(re-frame/inject-cofx ::inject/sub (fn [[_ which _]]
|
||||
[::subs/locations-for-client (:id (:client which))]))]
|
||||
(fn [{:keys [db] ::subs/keys [locations-for-client]} [_ which vendor-preferences]]
|
||||
(let [edit-invoice (update which :date #(date->str % standard))
|
||||
edit-invoice (update edit-invoice :due #(date->str % standard))
|
||||
edit-invoice (update edit-invoice :scheduled-payment #(date->str % standard))
|
||||
edit-invoice (assoc edit-invoice :original edit-invoice)]
|
||||
(let [edit-invoice which]
|
||||
{:db
|
||||
(-> db
|
||||
(forms/start-form ::form {:id (:id edit-invoice)
|
||||
@@ -143,10 +139,10 @@
|
||||
:invoice-number (:invoice-number edit-invoice)
|
||||
:total (cond-> (:total edit-invoice)
|
||||
(not (str/blank? (:total edit-invoice))) (js/parseFloat ))
|
||||
:original edit-invoice
|
||||
:original which
|
||||
:vendor (:vendor edit-invoice)
|
||||
:client (:client edit-invoice)
|
||||
:expense-accounts (expense-accounts-field/from-graphql (:expense-accounts which)
|
||||
:expense-accounts (eaf/from-graphql (:expense-accounts which)
|
||||
(:total which)
|
||||
locations-for-client)}))})))
|
||||
|
||||
@@ -160,8 +156,8 @@
|
||||
(cond
|
||||
(= [:vendor-preferences] field)
|
||||
(cond-> []
|
||||
(expense-accounts-field/can-replace-with-default? (:expense-accounts data))
|
||||
(into [[:expense-accounts] (expense-accounts-field/default-account (:expense-accounts data)
|
||||
(eaf/can-replace-with-default? (:expense-accounts data))
|
||||
(into [[:expense-accounts] (eaf/default-account (:expense-accounts data)
|
||||
(:default-account value)
|
||||
(:total data)
|
||||
(:locations (:client data)))])
|
||||
@@ -171,14 +167,14 @@
|
||||
[:schedule-when-due] true])
|
||||
|
||||
(:schedule-payment-dom value)
|
||||
(into [[:scheduled-payment] (date->str (next-dom (str->date (:date data) standard) (:schedule-payment-dom value)) standard)]))
|
||||
(into [[:scheduled-payment] (next-dom (:date data) (:schedule-payment-dom value))]))
|
||||
|
||||
(= [:total] field)
|
||||
[[:expense-accounts] (recalculate-amounts (:expense-accounts data) value)]
|
||||
|
||||
(and (= [:date] field)
|
||||
(:schedule-payment-dom (:vendor-preferences data)))
|
||||
[[:scheduled-payment] (date->str (next-dom (str->date value standard) (:schedule-payment-dom (:vendor-preferences data))) standard) ]
|
||||
[[:scheduled-payment] (next-dom value (:schedule-payment-dom (:vendor-preferences data))) ]
|
||||
|
||||
(and (= [:schedule-when-due] field) value)
|
||||
[[:scheduled-payment] (:due data)]
|
||||
@@ -293,11 +289,6 @@
|
||||
|
||||
;; VIEWS
|
||||
|
||||
(def invoice-form (forms/vertical-form {:can-submit [::can-submit]
|
||||
:change-event [::changed]
|
||||
:submit-event [::save-requested [::saving ]]
|
||||
:id ::form}))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::mounted
|
||||
(fn []
|
||||
@@ -318,8 +309,7 @@
|
||||
|
||||
(defn form-content [params]
|
||||
[layouts/side-bar {:on-close (dispatch-event [::forms/form-closing ::form ])}
|
||||
(let [{:keys [data id]} @(re-frame/subscribe [::forms/form ::form])
|
||||
{:keys [form-inline field raw-field error-notification submit-button ]} invoice-form
|
||||
(let [{:keys [data]} @(re-frame/subscribe [::forms/form ::form])
|
||||
can-submit? (boolean @(re-frame/subscribe [::can-submit]))
|
||||
status @(re-frame/subscribe [::status/single ::form])
|
||||
active-client @(re-frame/subscribe [::subs/client])
|
||||
@@ -361,8 +351,7 @@
|
||||
:type "typeahead-v3"
|
||||
:auto-focus (if active-client false true)
|
||||
:field [:client]
|
||||
:disabled exists?
|
||||
:spec ::invoice/client}]])
|
||||
:disabled exists?}]])
|
||||
[form-builder/field {:required? true}
|
||||
"Vendor"
|
||||
[search-backed-typeahead {:disabled exists?
|
||||
@@ -373,25 +362,27 @@
|
||||
:type "typeahead-v3"
|
||||
:auto-focus (if active-client true false)
|
||||
:field [:vendor]}]]
|
||||
[form-builder/field {:required? true}
|
||||
[form-builder/vertical-control {:required? true}
|
||||
"Date"
|
||||
[date-picker-friendly {:type "date"
|
||||
:field [:date]
|
||||
:spec ::invoice/date}]]
|
||||
[:label
|
||||
[form-builder/raw-field
|
||||
[date-picker-optional {:type "date2"
|
||||
:field [:date]
|
||||
:output :cljs-date}]]]]
|
||||
|
||||
[form-builder/field
|
||||
"Due (optional)"
|
||||
[date-picker-friendly {:type "date"
|
||||
:field [:due]
|
||||
:spec ::invoice/due}]]
|
||||
[date-picker-optional {:type "date2"
|
||||
:field [:due]
|
||||
:output :cljs-date}]]
|
||||
[form-builder/vertical-control
|
||||
"Scheduled payment (optional)"
|
||||
[left-stack
|
||||
[:div.control
|
||||
[form-builder/raw-field
|
||||
[date-picker-friendly {:type "date"
|
||||
[date-picker-optional {:type "date2"
|
||||
:field [:scheduled-payment]
|
||||
:spec ::invoice/scheduled-payment}]]]
|
||||
:output :cljs-date}]]]
|
||||
[:div.control
|
||||
[form-builder/raw-field
|
||||
|
||||
@@ -402,8 +393,7 @@
|
||||
[form-builder/field {:required? true}
|
||||
"Invoice #"
|
||||
[:input.input {:type "text"
|
||||
:field [:invoice-number]
|
||||
:spec ::invoice/invoice-number}]]
|
||||
:field [:invoice-number]}]]
|
||||
[form-builder/field {:required? true}
|
||||
"Total"
|
||||
[money-field {:type "money"
|
||||
@@ -411,7 +401,6 @@
|
||||
:disabled (if can-change-amount? "" "disabled")
|
||||
:style {:max-width "8em"}
|
||||
:min min-total
|
||||
:spec ::invoice/total
|
||||
:step "0.01"}]]]
|
||||
[form-builder/raw-field
|
||||
[expense-accounts-field {:type "expense-accounts"
|
||||
|
||||
Reference in New Issue
Block a user