moved to new date picker.

This commit is contained in:
2022-07-17 08:28:35 -07:00
parent eba3a5dce3
commit d97d70e08f
14 changed files with 193 additions and 338 deletions

View File

@@ -530,8 +530,8 @@
[title a b (and (:value a) (:value b) [title a b (and (:value a) (:value b)
{:border (:border b) {:border (:border b)
:format :dollar :format :dollar
:value (- (:value a) :value (- (or (:value a) 0.0)
(:value b))})])))) (or (:value b) 0.0))})]))))
(defn summarize-balance-sheet [pnl-data] (defn summarize-balance-sheet [pnl-data]
(let [pnl-datas (map (fn [p] (let [pnl-datas (map (fn [p]

View File

@@ -17,7 +17,8 @@
(re-frame/reg-fx (re-frame/reg-fx
:redirect :redirect
(fn [uri] (fn [uri]
(pushy/set-token! p/history uri))) (pushy/set-token! p/history uri)
(p/dispatch-route (p/parse-url uri))))
(re-frame/reg-fx (re-frame/reg-fx
:set-uri-params :set-uri-params

View File

@@ -6,11 +6,11 @@
[cemerick.url :refer [url]] [cemerick.url :refer [url]]
[re-frame.core :as re-frame])) [re-frame.core :as re-frame]))
(defn- parse-url [url] (defn parse-url [url]
(println "parsing url" url) (println "parsing url" url)
(bidi/match-route routes/routes url)) (bidi/match-route routes/routes url))
(defn- dispatch-route [matched-route] (defn dispatch-route [matched-route]
(println "Matched route" matched-route) (println "Matched route" matched-route)
(re-frame/dispatch [:auto-ap.events/set-active-route (:handler matched-route) (u/query-params) (:route-params matched-route)])) (re-frame/dispatch [:auto-ap.events/set-active-route (:handler matched-route) (u/query-params) (:route-params matched-route)]))

View File

@@ -1,8 +1,6 @@
(ns auto-ap.views.components.date-range-filter (ns auto-ap.views.components.date-range-filter
(:require (:require
[clojure.spec.alpha :as s] [auto-ap.views.utils :refer [bind-field date-picker date->str local-now standard]]
[auto-ap.entities.invoice :as invoice]
[auto-ap.views.utils :refer [bind-field date-picker-optional date->str local-now standard]]
[cljs-time.core :as t] [cljs-time.core :as t]
[re-frame.core :as re-frame])) [re-frame.core :as re-frame]))
@@ -37,9 +35,9 @@
[:div.field.has-addons [:div.field.has-addons
[:div.control [:div.control
[bind-field [bind-field
[date-picker-optional [date-picker
{:event on-change-event {:event on-change-event
:type "date2" :type "date"
:placeholder "Start" :placeholder "Start"
:class "is-small" :class "is-small"
:field [:start] :field [:start]
@@ -47,9 +45,9 @@
:output :text}]]] :output :text}]]]
[:div.control [:div.control
[bind-field [bind-field
[date-picker-optional [date-picker
{:event on-change-event {:event on-change-event
:type "date2" :type "date"
:class "is-small" :class "is-small"
:placeholder "End" :placeholder "End"
:field [:end] :field [:end]

View File

@@ -1,43 +0,0 @@
(ns auto-ap.views.components.number-filter
(:require
[clojure.spec.alpha :as s]
[auto-ap.entities.invoice :as invoice]
[auto-ap.views.components.typeahead :refer [typeahead]]
[auto-ap.views.utils :refer [bind-field date-picker date->str local-now standard]]
[cljs-time.core :as t]
[re-frame.core :as re-frame]))
(defn dispatch-change [on-change-event start end]
(fn [_]
(re-frame/dispatch (into on-change-event [[:start] start]) )
(re-frame/dispatch (into on-change-event [[:end] end]))))
(defn number-filter [{:keys [value on-change-event]}]
[:div
[:div.field.has-addons
[:div.control
[bind-field
[date-picker {:class-name "input is-fullwidth"
:class "input"
:format-week-number (fn [] "")
:previous-month-button-label ""
:placeholder-text "Start"
:next-month-button-label ""
:next-month-label ""
:event on-change-event
:type "date"
:field [:start]
:subscription value}]]]
[:div.control
[bind-field
[date-picker {:class-name "input is-fullwidth"
:class "input"
:format-week-number (fn [] "")
:previous-month-button-label ""
:placeholder-text "End"
:next-month-button-label ""
:event on-change-event
:next-month-label ""
:type "date"
:field [:end]
:subscription value}]]]]])

View File

@@ -1,9 +1,6 @@
(ns auto-ap.views.components.number-filter (ns auto-ap.views.components.number-filter
(:require (:require
[clojure.spec.alpha :as s] [auto-ap.views.utils :refer [bind-field]]
[auto-ap.entities.invoice :as invoice]
[auto-ap.views.utils :refer [bind-field date-picker date->str local-now standard]]
[cljs-time.core :as t]
[re-frame.core :as re-frame])) [re-frame.core :as re-frame]))
(defn dispatch-change [on-change-event start end] (defn dispatch-change [on-change-event start end]
@@ -30,5 +27,4 @@
:field [:amount-lte] :field [:amount-lte]
:event on-change-event :event on-change-event
:step "0.01" :step "0.01"
:subscription value}]]]]]] :subscription value}]]]]]])
)

View File

@@ -13,13 +13,10 @@
[auto-ap.views.components.typeahead.vendor [auto-ap.views.components.typeahead.vendor
:refer [search-backed-typeahead]] :refer [search-backed-typeahead]]
[auto-ap.views.utils [auto-ap.views.utils
:refer [date->str :refer [date-picker
date-picker
date-picker-friendly
dispatch-event dispatch-event
horizontal-field horizontal-field
multi-field multi-field]]
standard]]
[bidi.bidi :as bidi] [bidi.bidi :as bidi]
[cljs-time.coerce :as coerce] [cljs-time.coerce :as coerce]
[cljs-time.core :as t] [cljs-time.core :as t]
@@ -135,15 +132,7 @@
:location (:location x)}) :location (:location x)})
(:ezcater-locations new-client-data)) (:ezcater-locations new-client-data))
:locked-until (cond (not (:locked-until new-client-data)) :locked-until (:locked-until new-client-data)
nil
(instance? goog.date.Date (:locked-until new-client-data))
(date->str (:locked-until new-client-data) standard)
:else
(:locked-until new-client-data)
)
:locations (mapv :location (:locations new-client-data)) :locations (mapv :location (:locations new-client-data))
:matches (mapv :match (:matches new-client-data)) :matches (mapv :match (:matches new-client-data))
:location-matches (:location-matches new-client-data) :location-matches (:location-matches new-client-data)
@@ -171,15 +160,7 @@
:numeric-code (when-not (str/blank? numeric-code) :numeric-code (when-not (str/blank? numeric-code)
(js/parseInt numeric-code)) (js/parseInt numeric-code))
:include-in-reports include-in-reports :include-in-reports include-in-reports
:start-date (cond (not start-date) :start-date start-date
nil
(instance? goog.date.Date start-date)
(date->str start-date standard)
:else
start-date
)
:type type :type type
:id id :id id
:sort-order i :sort-order i
@@ -204,7 +185,7 @@
:<- [::subs/route-params] :<- [::subs/route-params]
:<- [::subs/clients-by-id] :<- [::subs/clients-by-id]
(fn [[rp clients-by-id]] (fn [[rp clients-by-id]]
(or (clients-by-id (:id rp)) (or (get clients-by-id (:id rp))
{}))) {})))
(re-frame/reg-event-fx (re-frame/reg-event-fx
@@ -405,15 +386,9 @@
:field [:numeric-code]}]]] :field [:numeric-code]}]]]
[form-builder/field [form-builder/field
"Start date" "Start date"
[date-picker {:class-name "input" [date-picker {:type "date"
:class "input" :output :cljs-date
:format-week-number (fn [] "") :field [:start-date]}]]]
:previous-month-button-label ""
:placeholder "mm/dd/yyyy"
:next-month-button-label ""
:next-month-label ""
:type "date"
:field [:start-date]}]]]
(when (#{:check ":check"} type ) (when (#{:check ":check"} type )
[:div [:div
@@ -600,7 +575,8 @@
[form-builder/field [form-builder/field
"Locked Until" "Locked Until"
[date-picker-friendly {:type "date" [date-picker {:type "date"
:output :cljs-date
:field [:locked-until] :field [:locked-until]
:style {:width "15em"}}]]])) :style {:width "15em"}}]]]))

View File

@@ -23,7 +23,7 @@
:refer [search-backed-typeahead]] :refer [search-backed-typeahead]]
[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 [date-picker-optional :refer [date-picker
dispatch-event dispatch-event
with-user]] with-user]]
[cljs-time.core :as c] [cljs-time.core :as c]
@@ -366,21 +366,21 @@
"Date" "Date"
[:label [:label
[form-builder/raw-field [form-builder/raw-field
[date-picker-optional {:type "date2" [date-picker {:type "date"
:field [:date] :field [:date]
:output :cljs-date}]]]] :output :cljs-date}]]]]
[form-builder/field [form-builder/field
"Due (optional)" "Due (optional)"
[date-picker-optional {:type "date2" [date-picker {:type "date"
:field [:due] :field [:due]
:output :cljs-date}]] :output :cljs-date}]]
[form-builder/vertical-control [form-builder/vertical-control
"Scheduled payment (optional)" "Scheduled payment (optional)"
[left-stack [left-stack
[:div.control [:div.control
[form-builder/raw-field [form-builder/raw-field
[date-picker-optional {:type "date2" [date-picker {:type "date"
:field [:scheduled-payment] :field [:scheduled-payment]
:output :cljs-date}]]] :output :cljs-date}]]]
[:div.control [:div.control

View File

@@ -1,84 +1,69 @@
(ns auto-ap.views.pages.invoices.handwritten-checks (ns auto-ap.views.pages.invoices.handwritten-checks
(:require [auto-ap.entities.invoice :as invoice] (:require
[auto-ap.forms :as forms] [auto-ap.forms :as forms]
[auto-ap.status :as status] [auto-ap.forms.builder :as form-builder]
[auto-ap.subs :as subs] [auto-ap.status :as status]
[auto-ap.utils :refer [by]] [auto-ap.subs :as subs]
[auto-ap.views.components.modal :as modal] [auto-ap.views.components.modal :as modal]
[auto-ap.views.pages.data-page :as data-page] [auto-ap.views.components.money-field :refer [money-field]]
[auto-ap.views.pages.invoices.common [auto-ap.views.pages.invoices.common
:refer :refer [does-amount-exceed-outstanding? invoice-read]]
[does-amount-exceed-outstanding? invoice-read]] [auto-ap.views.utils
[auto-ap.views.pages.invoices.form :as form] :refer [date-picker dispatch-event with-user]]
[auto-ap.views.utils [clojure.string :as str]
:refer [re-frame.core :as re-frame]))
[date-picker dispatch-event horizontal-field with-user]]
[clojure.string :as str]
[re-frame.core :as re-frame]))
(def handwrite-checks-form (forms/vertical-form {:submit-event [::save]
:change-event [::forms/change ::form]
:can-submit [::can-submit]
:id ::form}))
(defn form [] (defn form []
(let [real-bank-accounts @(re-frame/subscribe [::subs/real-bank-accounts]) (let [real-bank-accounts @(re-frame/subscribe [::subs/real-bank-accounts])
{:keys [data active? error id]} @(re-frame/subscribe [::forms/form ::form]) {:keys [data]} @(re-frame/subscribe [::forms/form ::form])]
{:keys [form-inline horizontal-field field raw-field error-notification submit-button]} handwrite-checks-form] [form-builder/builder {:submit-event [::save]
(form-inline {} :can-submit [::can-submit]
[:<> :id ::form}
[:div.field [form-builder/vertical-control
[:label.label "Pay using"] "Pay using"
[:div.control [:div.control
[:span.select [:span.select
[raw-field [form-builder/raw-field
[:select {:type "select" [:select {:type "select"
:field :bank-account-id} :field :bank-account-id}
(for [{:keys [id number name]} real-bank-accounts] (for [{:keys [id name]} real-bank-accounts]
^{:key id} [:option {:value id} name])]]]]] ^{:key id} [:option {:value id} name])]]]]]
(field "Date" [form-builder/field
[date-picker {:class-name "input" "Date"
:class "input" [date-picker {:type "date"
:format-week-number (fn [] "") :output :cljs-date
:previous-month-button-label "" :field [:date]}]]
:placeholder "mm/dd/yyyy" [form-builder/field
:next-month-button-label "" "Check number"
:next-month-label "" [:input.input {:type "number"
:type "date" :field [:check-number]}]]
:field [:date] [:table.table.is-fullwidth
:spec ::invoice/date}]) [:thead
(field "Check number" [:tr
[:input.input {:type "number" [:th "Invoice ID"]
:field [:check-number]}]) [:th {:style {"width" "14em"}} "Payment"]]]
[:table.table.is-fullwidth [:tbody
[:thead (doall
[:tr (for [{:keys [invoice-number id]} (:invoices data)]
[:th "Invoice ID"] ^{:key id}
[:th {:style {"width" "14em"}} "Payment"]]] [:tr
[:tbody [:td invoice-number]
(doall [:td
(for [{:keys [payment outstanding-balance invoice-number id] :as i} (:invoices data)] [form-builder/raw-field
^{:key id} [money-field {:type "money"
[:tr :field [:invoice-amounts id :amount]
[:td invoice-number] :style {:max-width "8em"}
[:td [:div.field.has-addons.is-extended }]]]]))]]
[:p.control [:a.button.is-static "$"]] [form-builder/hidden-submit-button]]))
[:p.control
(raw-field
[:input.input.has-text-right {:type "number"
:field [:invoice-amounts id :amount]
#_#_:max outstanding-balance
:step "0.01"}])]]]]))]]])))
(re-frame/reg-sub (re-frame/reg-sub
::can-submit ::can-submit
:<- [::forms/form ::form] :<- [::forms/form ::form]
(fn [{ {:keys [check-number date invoices invoice-amounts]} :data}] (fn [{ {:keys [check-number date invoices invoice-amounts]} :data}]
(boolean (cond (seq (filter (boolean (cond (seq (filter
(fn [{:keys [id outstanding-balance]}] (fn [{:keys [id outstanding-balance]}]
(does-amount-exceed-outstanding? (get-in invoice-amounts [id :amount]) outstanding-balance )) (does-amount-exceed-outstanding? (get-in invoice-amounts [id :amount]) outstanding-balance ))
invoices)) invoices))
false false
:else :else
@@ -132,6 +117,6 @@
(re-frame/reg-event-fx (re-frame/reg-event-fx
::succeeded ::succeeded
[(forms/triggers-stop ::form)] [(forms/triggers-stop ::form)]
(fn [{:keys [db]} [_ invoices]] (fn [_ _]
{:dispatch [::modal/modal-closed]})) {:dispatch [::modal/modal-closed]}))

View File

@@ -13,11 +13,9 @@
[auto-ap.views.pages.ledger.side-bar :refer [ledger-side-bar]] [auto-ap.views.pages.ledger.side-bar :refer [ledger-side-bar]]
[auto-ap.views.pages.ledger.table :as ledger-table] [auto-ap.views.pages.ledger.table :as ledger-table]
[auto-ap.views.utils [auto-ap.views.utils
:refer [date->str :refer [date-picker
date-picker-friendly
dispatch-event dispatch-event
local-now local-now
standard
with-user]] with-user]]
[cljs-time.core :as t] [cljs-time.core :as t]
[clojure.set :as set] [clojure.set :as set]
@@ -78,9 +76,7 @@
:graphql {:token user :graphql {:token user
:query-obj {:venia/queries [[:balance-sheet :query-obj {:venia/queries [[:balance-sheet
(-> (:data db) (-> (:data db)
(assoc :client-id (:id client)) (assoc :client-id (:id client)))
(update :date (fnil #(date->str % standard) nil))
(update :comparison-date (fnil #(date->str % standard) nil)))
[[:balance-sheet-accounts [:name :amount :account-type :id :numeric-code]] [[:balance-sheet-accounts [:name :amount :account-type :id :numeric-code]]
[:comparable-balance-sheet-accounts [:name :amount :account-type :id :numeric-code]]]]]} [:comparable-balance-sheet-accounts [:name :amount :account-type :id :numeric-code]]]]]}
@@ -122,9 +118,7 @@ NOTE: Please review the transactions we may have question for you here: https://
:graphql {:token user :graphql {:token user
:query-obj {:venia/queries [[:balance-sheet-pdf :query-obj {:venia/queries [[:balance-sheet-pdf
(-> (:data db) (-> (:data db)
(assoc :client-id (:id client)) (assoc :client-id (:id client)))
(update :date (fnil #(date->str % standard) nil))
(update :comparison-date (fnil #(date->str % standard) nil)))
[:url :name]]]} [:url :name]]]}
:owns-state {:single ::page} :owns-state {:single ::page}
@@ -139,7 +133,7 @@ NOTE: Please review the transactions we may have question for you here: https://
:from-numeric-code from-numeric-code :from-numeric-code from-numeric-code
:to-numeric-code to-numeric-code :to-numeric-code to-numeric-code
:date-range {:start "2000-01-01" :date-range {:start "2000-01-01"
:end (date->str date-range standard)}}]})) :end date-range}}]}))
(re-frame/reg-event-fx (re-frame/reg-event-fx
::ledger-params-change ::ledger-params-change
@@ -206,9 +200,9 @@ NOTE: Please review the transactions we may have question for you here: https://
[:div.control [:div.control
[:p.help "Date"] [:p.help "Date"]
(raw-field (raw-field
[date-picker-friendly {:cljs-date? true [date-picker {:output :cljs-date
:type "date" :type "date"
:field [:date]}])]] :field [:date]}])]]
[:div.level-item [:div.level-item
[:div.control [:div.control
[:div.mt-3] [:div.mt-3]
@@ -224,9 +218,9 @@ NOTE: Please review the transactions we may have question for you here: https://
[:div.control [:div.control
[:p.help "Comparison Date"] [:p.help "Comparison Date"]
(raw-field (raw-field
[date-picker-friendly {:cljs-date? true [date-picker {:output :cljs-date
:type "date" :type "date"
:field [:comparison-date]}])])]] :field [:comparison-date]}])])]]
[:div.level-right [:div.level-right
[:div.buttons [:div.buttons

View File

@@ -1,20 +1,17 @@
(ns auto-ap.views.pages.ledger.external-import (ns auto-ap.views.pages.ledger.external-import
(:require [auto-ap.subs :as subs] (:require
[auto-ap.views.components.layouts :refer [side-bar-layout]] [auto-ap.events :as events]
[goog.string :as gstring] [auto-ap.forms :as forms]
[auto-ap.forms :as forms] [auto-ap.status :as status]
[auto-ap.utils :refer [by]] [auto-ap.subs :as subs]
[auto-ap.events :as events] [auto-ap.views.components.dropdown
[auto-ap.views.pages.ledger.side-bar :refer [ledger-side-bar]] :refer [drop-down drop-down-contents]]
[auto-ap.views.utils :refer [date->str date-picker bind-field local-now standard ->$ str->date dispatch-event]] [auto-ap.views.components.layouts :refer [side-bar-layout]]
[auto-ap.views.components.dropdown :refer [drop-down drop-down-contents]] [auto-ap.views.pages.ledger.side-bar :refer [ledger-side-bar]]
[cljs-time.core :as t] [auto-ap.views.utils :refer [bind-field dispatch-event]]
[re-frame.core :as re-frame] [clojure.string :as str]
[reagent.core :as r] [re-frame.core :as re-frame]
[clojure.string :as str] [reagent.core :as r]))
[auto-ap.status :as status]))
(re-frame/reg-sub (re-frame/reg-sub
::loading ::loading

View File

@@ -16,7 +16,7 @@
[auto-ap.views.pages.ledger.table :as ledger-table] [auto-ap.views.pages.ledger.table :as ledger-table]
[auto-ap.views.utils [auto-ap.views.utils
:refer [date->str :refer [date->str
date-picker-friendly date-picker
dispatch-event dispatch-event
local-today local-today
multi-field multi-field
@@ -73,7 +73,7 @@
:owns-state {:single ::page} :owns-state {:single ::page}
:query-obj {:venia/queries [[:profit-and-loss :query-obj {:venia/queries [[:profit-and-loss
{:client-ids (map :id (:clients (:data db))) {:client-ids (map :id (:clients (:data db)))
:periods (mapv encode-period (:periods (:data db))) :periods (mapv #(select-keys % #{:start :end} ) (:periods (:data db)))
:include-deltas (:include-deltas (:data db)) :include-deltas (:include-deltas (:data db))
:column-per-location (:column-per-location (:data db))} :column-per-location (:column-per-location (:data db))}
[[:periods [[:accounts [:name :amount :client_id :account-type :id :count :numeric-code :location]]]]]]]} [[:periods [[:accounts [:name :amount :client_id :account-type :id :count :numeric-code :location]]]]]]]}
@@ -129,7 +129,7 @@ NOTE: Please review the transactions we may have question for you here: https://
{:client-ids (map :id (:clients (:data db))) {:client-ids (map :id (:clients (:data db)))
:include-deltas (:include-deltas (:data db)) :include-deltas (:include-deltas (:data db))
:column-per-location (:column-per-location (:data db)) :column-per-location (:column-per-location (:data db))
:periods (mapv encode-period (:periods (:data db)))} :periods (mapv #(select-keys % #{:start :end}) (:periods (:data db)))}
[:url :name]]]} [:url :name]]]}
:on-success [::received-pdf]} :on-success [::received-pdf]}
:set-uri-params {:periods (mapv encode-period (:periods (:data db))) :set-uri-params {:periods (mapv encode-period (:periods (:data db)))
@@ -288,10 +288,10 @@ NOTE: Please review the transactions we may have question for you here: https://
[:div.field.has-addons [:div.field.has-addons
[:div.control [:div.control
(raw-field (raw-field
[date-picker-friendly {:placeholder "End date" [date-picker {:placeholder "End date"
:type "date" :type "date"
:cljs-date? true :output :cljs-date
:field [:thirteen-periods-end]}])] :field [:thirteen-periods-end]}])]
[period-preset-button {:title "13 periods" [period-preset-button {:title "13 periods"
:periods (let [today (or (some-> (:thirteen-periods-end data)) :periods (let [today (or (some-> (:thirteen-periods-end data))
(local-today))] (local-today))]
@@ -309,8 +309,8 @@ NOTE: Please review the transactions we may have question for you here: https://
[:div.field.has-addons [:div.field.has-addons
[:div.control [:div.control
(raw-field (raw-field
[date-picker-friendly {:placeholder "End date" [date-picker {:placeholder "End date"
:cljs-date? true :output :cljs-date
:type "date" :type "date"
:field [:twelve-periods-end]}])] :field [:twelve-periods-end]}])]
[period-preset-button {:title "12 months" [period-preset-button {:title "12 months"
@@ -388,15 +388,15 @@ NOTE: Please review the transactions we may have question for you here: https://
[:div.control [:div.control
[:p.help "From"] [:p.help "From"]
(raw-field (raw-field
[date-picker-friendly {:type "date" [date-picker {:type "date"
:cljs-date? true :output :cljs-date
:field [:periods i :start]}])] :field [:periods i :start]}])]
[:div.control [:div.control
[:p.help "To"] [:p.help "To"]
(raw-field (raw-field
[date-picker-friendly {:type "date" [date-picker {:type "date"
:cljs-date? true :output :cljs-date
:field [:periods i :end]}])]])))]]] :field [:periods i :end]}])]])))]]]
[:div.level-item [:div.level-item

View File

@@ -1,20 +1,15 @@
(ns auto-ap.views.pages.pos.form (ns auto-ap.views.pages.pos.form
(:require (:require
[auto-ap.events :as events] [auto-ap.forms :as forms]
[auto-ap.forms :as forms] [auto-ap.subs :as subs]
[auto-ap.subs :as subs] [auto-ap.views.components.layouts :as layouts]
[auto-ap.utils :refer [dollars=]] [auto-ap.views.components.money-field :refer [money-field]]
[auto-ap.views.components.dropdown :refer [drop-down]] [auto-ap.views.components.typeahead :refer [typeahead-v3]]
[auto-ap.views.components.expense-accounts-field :as expense-accounts-field :refer [expense-accounts-field recalculate-amounts]] [auto-ap.views.utils
[auto-ap.views.components.layouts :as layouts] :refer [date->str date-picker dispatch-event standard]]
[auto-ap.views.components.money-field :refer [money-field]] [re-frame.core :as re-frame]
[auto-ap.views.components.typeahead :refer [typeahead-v3]] [auto-ap.forms.builder :as form-builder]))
[auto-ap.status :as status]
[auto-ap.views.utils :refer [date->str date-picker dispatch-event standard with-user]]
[cljs-time.core :as c]
[clojure.spec.alpha :as s]
[clojure.string :as str]
[re-frame.core :as re-frame]))
(re-frame/reg-sub (re-frame/reg-sub
::can-submit ::can-submit
:<- [::forms/form ::form] :<- [::forms/form ::form]
@@ -27,70 +22,67 @@
(let [which (update which :date #(date->str % standard))] (let [which (update which :date #(date->str % standard))]
(forms/start-form db ::form which)))) (forms/start-form db ::form which))))
(def sales-order-form (forms/vertical-form {:can-submit [::can-submit]
:change-event [::forms/changed]
:submit-event [::saving ]
:id ::form}))
(defn form [{:keys [can-change-amount?] :as params}] (defn form []
[layouts/side-bar {:on-close (dispatch-event [::forms/form-closing ::form ])} [layouts/side-bar {:on-close (dispatch-event [::forms/form-closing ::form ])}
(let [{:keys [data active? error id]} @(re-frame/subscribe [::forms/form ::form]) (let [{:keys [data]} @(re-frame/subscribe [::forms/form ::form])]
{:keys [form-inline field raw-field error-notification submit-button ]} sales-order-form] [form-builder/builder {:can-submit [::can-submit]
(with-meta :submit-event [::saving ]
(form-inline (assoc params :title "Sales order") :id ::form}
[:<> [form-builder/section {:title "Sales Order"}
(when-not @(re-frame/subscribe [::subs/client]) (when-not @(re-frame/subscribe [::subs/client])
(field [:span "Client" [form-builder/field
[:span.has-text-danger " *"]] "Client"
[typeahead-v3 {:entities @(re-frame/subscribe [::subs/clients]) [typeahead-v3 {:entities @(re-frame/subscribe [::subs/clients])
:entity->text :name :entity->text :name
:type "typeahead-v3" :type "typeahead-v3"
:field [:client] :field [:client]
:disabled true}])) :disabled true}]])
(field "Date" [form-builder/field "Date"
[date-picker {:class-name "input" [date-picker {:type "date"
:class "input" :output :cljs-date
:type "date" :disabled true
:disabled true :field [:date]}]]
:field [:date]}]) [form-builder/field
(field "Total" "Total"
[money-field {:type "money" [money-field {:type "money"
:field [:total] :field [:total]
:disabled true}]) :disabled true}]]
(field "Tax" [form-builder/field "Tax"
[money-field {:type "money" [money-field {:type "money"
:field [:tax] :field [:tax]
:disabled true}]) :disabled true}]
(field "Discount" [form-builder/field
[money-field {:type "money" "Discount"
:field [:discount] [money-field {:type "money"
:disabled true}]) :field [:discount]
:disabled true}]]]
(field "Returns" [form-builder/field "Returns"
[money-field {:type "money" [money-field {:type "money"
:field [:returns] :field [:returns]
:disabled true}]) :disabled true}]]
(field "Service Charge" [form-builder/field "Service Charge"
[money-field {:type "money" [money-field {:type "money"
:field [:service-charge] :field [:service-charge]
:disabled true}]) :disabled true}]]
(field "Tip" [form-builder/field
[money-field {:type "money" "Tip"
:field [:tip] [money-field {:type "money"
:disabled true}]) :field [:tip]
:disabled true}]]
[:h1.subtitle.is-4 "Charges"] [form-builder/section {:title "Charges"}
[:ul [:ul
(for [charge (:charges data)] (for [charge (:charges data)]
[:li (:type-name charge) ": " (:total charge)])] [:li (:type-name charge) ": " (:total charge)])]]
[:h1.subtitle.is-4 "Line Items"] [form-builder/section {:title "Line Items"}
[:ul [:ul
(for [line-item (:line-items data)] (for [line-item (:line-items data)]
[:li (:item-name line-item) ": " (:total line-item) [:span.tag (:category line-item)]])]]) [:li (:item-name line-item) ": " (:total line-item) [:span.tag (:category line-item)]])]]]])])
{:key (:id data)}))])

View File

@@ -251,6 +251,7 @@
options (if allow-nil? options (if allow-nil?
(with-keys (conj rest [:option {:value nil}])) (with-keys (conj rest [:option {:value nil}]))
(with-keys rest))] (with-keys rest))]
(println "KEYS" keys (dissoc keys :allow-nil?))
(into [dom (dissoc keys :allow-nil?)] options))) (into [dom (dissoc keys :allow-nil?)] options)))
@@ -340,33 +341,6 @@
(into [dom keys] (with-keys rest)))) (into [dom keys] (with-keys rest))))
(defmethod do-bind "date" [dom {:keys [field event subscription class spec] :as keys} & rest] (defmethod do-bind "date" [dom {:keys [field event subscription class spec] :as keys} & rest]
(let [field (if (keyword? field) [field] field)
event (if (keyword? event) [event] event)
selected (get-in subscription field)
selected (cond (string? selected)
(c/to-date (t/to-default-time-zone (t/from-default-time-zone (str->date selected standard))))
(instance? goog.date.DateTime selected)
(c/to-date (t/to-default-time-zone (t/from-default-time-zone selected)))
(instance? goog.date.Date selected)
(c/to-date selected)
:else
selected )
keys (assoc keys
:on-change (if (:cljs-date? keys)
(dispatch-cljs-date-change (conj event field))
(dispatch-date-change (conj event field)))
:selected selected
:class (str class
(when (and spec (not (s/valid? spec (get-in subscription field))))
" is-danger")))
keys (dissoc keys :field :subscription :event :spec)]
(into [dom keys] (with-keys rest))))
(defmethod do-bind "date2" [dom {:keys [field event subscription class spec] :as keys} & rest]
(let [field (if (keyword? field) [field] field) (let [field (if (keyword? field) [field] field)
event (if (keyword? event) [event] event) event (if (keyword? event) [event] event)
selected (get-in subscription field) selected (get-in subscription field)
@@ -489,21 +463,6 @@
[:div.field-body] [:div.field-body]
(with-keys (map (fn [x] [:div.field x]) controls)))]) (with-keys (map (fn [x] [:div.field x]) controls)))])
(def date-picker
(reagent/adapt-react-class (.-default react-datepicker)))
(defn date-picker-friendly [params]
[date-picker (assoc params
:class-name "input"
:disabled-keyboard-navigation true
:start-open false
:class "input"
:format-week-number (fn [] "")
:previous-month-button-label ""
:next-month-button-label ""
:next-month-label ""
:type "date")])
(defn coerce-date [d] (defn coerce-date [d]
(cond (and (string? d) (cond (and (string? d)
(some->> (re-find #"^(\d{4})" d) (some->> (re-find #"^(\d{4})" d)
@@ -524,7 +483,7 @@
:else :else
nil )) nil ))
(defn date-picker-optional-internal [params] (defn date-picker-internal [params]
(let [[text set-text ] (react/useState (some-> params :value coerce-date (date->str standard))) (let [[text set-text ] (react/useState (some-> params :value coerce-date (date->str standard)))
[value set-value ] (react/useState (some-> params :value coerce-date)) [value set-value ] (react/useState (some-> params :value coerce-date))
@@ -565,8 +524,8 @@
:type "date" :placeholder "12/1/2021")] :type "date" :placeholder "12/1/2021")]
]])) ]]))
(defn date-picker-optional [] (defn date-picker []
[:f> date-picker-optional-internal [:f> date-picker-internal
(r/props (r/current-component))]) (r/props (r/current-component))])
(defn local-now [] (defn local-now []