cleaned up how these are generated.

This commit is contained in:
2022-07-25 05:15:16 -07:00
parent bc07ad8f01
commit f6f73a6110
7 changed files with 122 additions and 117 deletions

View File

@@ -6,7 +6,8 @@
[re-frame.core :as re-frame] [re-frame.core :as re-frame]
[auto-ap.views.pages.data-page :as data-page] [auto-ap.views.pages.data-page :as data-page]
[auto-ap.views.components.buttons :as buttons] [auto-ap.views.components.buttons :as buttons]
[auto-ap.subs :as subs])) [auto-ap.subs :as subs]
[react-dom :as react-dom]))
(set! *warn-on-infer* true) (set! *warn-on-infer* true)
(defonce ^js/React.Context grid-context ( react/createContext "default")) (defonce ^js/React.Context grid-context ( react/createContext "default"))
@@ -116,7 +117,7 @@
[:a.tag.is-medium.is-delete {:on-click (fn [] [:a.tag.is-medium.is-delete {:on-click (fn []
(on-change {:sort (filter #(not= sort-key (:sort-key %)) sort)}))}]]])]) (on-change {:sort (filter #(not= sort-key (:sort-key %)) sort)}))}]]])])
(defn controls [{:keys [start end count total per-page] :as para}] (defn controls [{:keys [start end count total per-page action-buttons] :as para}]
(let [children (r/children (r/current-component))] (let [children (r/children (r/current-component))]
[:> Consumer {} [:> Consumer {}
(fn [consume] (fn [consume]
@@ -134,7 +135,8 @@
[sort-by-list {:sort (:sort params) [sort-by-list {:sort (:sort params)
:on-change on-params-change}]]] :on-change on-params-change}]]]
(mapv (fn [c] (mapv (fn [c]
[:div.level-item c]) children))]]))))])) [:div.level-item c]) children))
[:div.level-right action-buttons]]]))))]))
(defn table [{:keys [fullwidth class style]}] (defn table [{:keys [fullwidth class style]}]

View File

@@ -237,7 +237,7 @@
:class (status/class-for (get unautopay-states (:id i))) :class (status/class-for (get unautopay-states (:id i)))
:event [::unautopay i]}])]]])) :event [::unautopay i]}])]]]))
(defn invoice-table [{:keys [check-boxes overrides actions data-page checkable-fn]}] (defn invoice-table [{:keys [check-boxes overrides actions data-page checkable-fn action-buttons]}]
(let [{:keys [data status params table-params]} @(re-frame/subscribe [::data-page/page data-page]) (let [{:keys [data status params table-params]} @(re-frame/subscribe [::data-page/page data-page])
selected-client @(re-frame/subscribe [::subs/client]) selected-client @(re-frame/subscribe [::subs/client])
is-loading? (= :loading (:state status)) is-loading? (= :loading (:state status))
@@ -260,10 +260,11 @@
[grid/grid {:data-page data-page [grid/grid {:data-page data-page
:check-boxes? check-boxes :check-boxes? check-boxes
:column-count (if selected-client 8 9)} :column-count (if selected-client 8 9)}
[grid/controls data [grid/controls {:action-buttons action-buttons}
[:div.level-item [:div.level-item
"Outstanding " (nf (:outstanding data)) [:div.tags
" Total " (nf (:total-amount data))]] [:div.tag.is-info.is-light "Outstanding " (nf (:outstanding data))]
[:div.tag.is-info.is-light " Total " (nf (:total-amount data))]]]]
(for [invoices invoice-groups] (for [invoices invoice-groups]
^{:key (or (:id (first invoices)) "init")} ^{:key (or (:id (first invoices)) "init")}
[grid/table {:fullwidth true} [grid/table {:fullwidth true}

View File

@@ -133,11 +133,8 @@
(defn action-buttons [] (defn action-buttons []
(let [checked-payments @(re-frame/subscribe [::data-page/checked ::page])] (let [checked-payments @(re-frame/subscribe [::data-page/checked ::page])]
[:div [:<>
[:div.is-pulled-right [:div.level-item
[:div.buttons
[void-selected-button]]]
[:div.is-pulled-right {:style {:margin-right "0.5rem"}}
(into [:div.tags ] (map (fn [[z {:keys [id check-number type amount]}]] (into [:div.tags ] (map (fn [[z {:keys [id check-number type amount]}]]
(if (= z "header") (if (= z "header")
[:span.tag.is-medium "All visible payments" [:span.tag.is-medium "All visible payments"
@@ -149,15 +146,18 @@
:else (gstring/format "Check #%d (%s)" check-number (nf amount ))) :else (gstring/format "Check #%d (%s)" check-number (nf amount )))
[:button.delete.is-small {:on-click [:button.delete.is-small {:on-click
(dispatch-event [::data-page/remove-check ::page id])}]])) (dispatch-event [::data-page/remove-check ::page id])}]]))
checked-payments))]])) checked-payments))]
[:div.level-item
[:div.buttons
[void-selected-button]]]]))
(defn content [] (defn content []
[:div [:div
[:h1.title "Payments"] [:h1.title "Payments"]
[action-buttons]
[status/status-notification {:statuses [[::status/last-multi ::table/void]]}] [status/status-notification {:statuses [[::status/last-multi ::table/void]]}]
[table/table {:id :payments [table/table {:id :payments
:data-page ::page}]]) :data-page ::page
:action-buttons [action-buttons]}]])
(defn payments-page [] (defn payments-page []
(reagent/create-class (reagent/create-class

View File

@@ -103,14 +103,14 @@
[buttons/sl-icon {:event [::void-check check] :icon :icon-bin-2 [buttons/sl-icon {:event [::void-check check] :icon :icon-bin-2
:class (status/class-for (get states (:id check)))}])]]])) :class (status/class-for (get states (:id check)))}])]]]))
(defn table [{:keys [data-page]}] (defn table [{:keys [data-page action-buttons]}]
(let [selected-client @(re-frame/subscribe [::subs/client]) (let [selected-client @(re-frame/subscribe [::subs/client])
{:keys [data params]} @(re-frame/subscribe [::data-page/page data-page]) {:keys [data params]} @(re-frame/subscribe [::data-page/page data-page])
states @(re-frame/subscribe [::status/multi ::void])] states @(re-frame/subscribe [::status/multi ::void])]
[grid/grid {:data-page data-page [grid/grid {:data-page data-page
:check-boxes? true :check-boxes? true
:column-count (if selected-client 7 8)} :column-count (if selected-client 7 8)}
[grid/controls data] [grid/controls {:action-buttons action-buttons} data]
[grid/table {:fullwidth true} [grid/table {:fullwidth true}
[grid/header {} [grid/header {}
[grid/row {:id "header" [grid/row {:id "header"

View File

@@ -129,27 +129,28 @@
(when (:sample-error result) (when (:sample-error result)
(str " Sample error: " (:info (:sample-error result)))))])}]})) (str " Sample error: " (:info (:sample-error result)))))])}]}))
(defn action-buttons []
(defn content []
(let [is-admin? @(re-frame/subscribe [::subs/is-admin?]) (let [is-admin? @(re-frame/subscribe [::subs/is-admin?])
params @(re-frame/subscribe [::data-page/params ::page]) params @(re-frame/subscribe [::data-page/params ::page])
checked @(re-frame/subscribe [::data-page/checked ::page])] checked @(re-frame/subscribe [::data-page/checked ::page])]
[:div (when is-admin?
[:h1.title "Transactions"] [:<>
[status/status-notification {:statuses [[::status/single ::delete-selected] [:div.level-item
[::status/single ::manual-import]]}] [:div.tags
(when is-admin? (map (fn [[z {:keys [id]}]]
[:div.is-pulled-right (if (= "header" z)
^{:key "header"}
[:span.tag.is-medium {:on-click
(dispatch-event [::data-page/remove-check ::page "header"])}
"All visible transactions"]
^{:key id}
[:span.tag.is-medium id
[:button.delete.is-small {:on-click
(dispatch-event [::data-page/remove-check ::page id])}]]))
checked)]]
[:div.level-item
[:div.buttons [:div.buttons
(into [:div.tags ] (map (fn [[z {:keys [id]}]]
(if (= "header" z)
[:span.tag.is-medium {:on-click
(dispatch-event [::data-page/remove-check ::page "header"])}
"All visible transactions"]
[:span.tag.is-medium id
[:button.delete.is-small {:on-click
(dispatch-event [::data-page/remove-check ::page id])}]]))
checked))
[:button.button.is-outlined.is-primary {:on-click (dispatch-event [::manual/opening])} [:button.button.is-outlined.is-primary {:on-click (dispatch-event [::manual/opening])}
"Manual Yodlee Import"] "Manual Yodlee Import"]
(when (:client-id params) (when (:client-id params)
@@ -161,10 +162,20 @@
"Delete"] "Delete"]
[:button.button.is-danger {:on-click (dispatch-event [::delete-selected-requested params true]) [:button.button.is-danger {:on-click (dispatch-event [::delete-selected-requested params true])
:disabled (not (seq checked))} :disabled (not (seq checked))}
"Suppress"]]]) "Suppress"]]]])))
(defn content []
(let [is-admin? @(re-frame/subscribe [::subs/is-admin?])]
[:div
[:h1.title "Transactions"]
[status/status-notification {:statuses [[::status/single ::delete-selected]
[::status/single ::manual-import]]}]
[table/table {:id :transactions [table/table {:id :transactions
:check-boxes? is-admin? :check-boxes? is-admin?
:data-page ::page}]])) :data-page ::page
:action-buttons [action-buttons]}]]))
(defn transactions-page [{:keys [approval-status]}] (defn transactions-page [{:keys [approval-status]}]

View File

@@ -74,14 +74,15 @@
(fn [{table-params :db} [_ params :as z]] (fn [{table-params :db} [_ params :as z]]
{:db (merge table-params params)})) {:db (merge table-params params)}))
(defn table [{:keys [data-page check-boxes?]}] (defn table [{:keys [data-page check-boxes? action-buttons]}]
(let [selected-client @(re-frame/subscribe [::subs/client]) (let [selected-client @(re-frame/subscribe [::subs/client])
{:keys [data params]} @(re-frame/subscribe [::data-page/page data-page]) {:keys [data params]} @(re-frame/subscribe [::data-page/page data-page])
states @(re-frame/subscribe [::status/multi ::edits])] states @(re-frame/subscribe [::status/multi ::edits])]
[grid/grid {:data-page data-page [grid/grid {:data-page data-page
:column-count (if selected-client 6 7) :column-count (if selected-client 6 7)
:check-boxes? check-boxes?} :check-boxes? check-boxes?}
[grid/controls data] [grid/controls {:action-buttons action-buttons}
data]
[grid/table {:fullwidth true} [grid/table {:fullwidth true}
[grid/header {} [grid/header {}
[grid/row {:id "header" [grid/row {:id "header"

View File

@@ -30,7 +30,8 @@
[re-frame.core :as re-frame] [re-frame.core :as re-frame]
[reagent.core :as r] [reagent.core :as r]
[vimsical.re-frame.fx.track :as track] [vimsical.re-frame.fx.track :as track]
[vimsical.re-frame.cofx.inject :as inject])) [vimsical.re-frame.cofx.inject :as inject]
[react-dom :as react-dom]))
(re-frame/reg-event-fx (re-frame/reg-event-fx
::params-change ::params-change
@@ -212,94 +213,83 @@
(let [current-client @(re-frame/subscribe [::subs/client]) (let [current-client @(re-frame/subscribe [::subs/client])
checked-invoices @(re-frame/subscribe [::data-page/checked :invoices]) checked-invoices @(re-frame/subscribe [::data-page/checked :invoices])
print-checks-status @(re-frame/subscribe [::status/single ::print-checks])] print-checks-status @(re-frame/subscribe [::status/single ::print-checks])]
[:div [:div.buttons
[:div.is-pulled-right [void-selected-button]
[:div.buttons
[void-selected-button] [buttons/new-button {:event [::new-invoice-clicked]
:name "Invoice"
[buttons/new-button {:event [::new-invoice-clicked] :class "is-primary"}]
:name "Invoice"
:class "is-primary"}] (when current-client
(let [balance (->> checked-invoices
(when current-client vals
(let [balance (->> checked-invoices (map (comp js/parseFloat :outstanding-balance))
vals (reduce + 0)
(map (comp js/parseFloat :outstanding-balance)) )]
(reduce + 0) [drop-down {:header [:button.button.is-primary {:aria-haspopup true
)] :on-click (dispatch-event [::events/toggle-menu ::print-checks ])
[drop-down {:header [:button.button.is-primary {:aria-haspopup true :disabled (or (status/disabled-for print-checks-status) (not (seq checked-invoices)))
:on-click (dispatch-event [::events/toggle-menu ::print-checks ]) :class (status/class-for @(re-frame/subscribe [::status/single ::print-checks]))}
:disabled (or (status/disabled-for print-checks-status) (not (seq checked-invoices))) "Pay "
:class (status/class-for @(re-frame/subscribe [::status/single ::print-checks]))} (when (> (count checked-invoices ) 0)
"Pay " (str
(when (> (count checked-invoices ) 0) (count checked-invoices)
(str " invoices "
(count checked-invoices) "(" (gstring/format "$%.2f" balance ) ")"))
" invoices " [:span " "]
"(" (gstring/format "$%.2f" balance ) ")")) [:span.icon.is-small [:i.fa.fa-angle-down {:aria-hidden "true"}]]]
[:span " "] :id ::print-checks
[:span.icon.is-small [:i.fa.fa-angle-down {:aria-hidden "true"}]]] :is-right? true}
:id ::print-checks [:div
:is-right? true} (list
[:div (for [{:keys [id number name type]} (->> (:bank-accounts current-client) (filter :visible) (sort-by :sort-order))]
(list (if (= :cash type)
(for [{:keys [id number name type]} (->> (:bank-accounts current-client) (filter :visible) (sort-by :sort-order))] ^{:key id} [:a.dropdown-item {:on-click (dispatch-event [::print-checks id :cash])
(if (= :cash type) :disabled (status/disabled-for print-checks-status)} "With cash"]
^{:key id} [:a.dropdown-item {:on-click (dispatch-event [::print-checks id :cash]) (if (> balance 0.001)
:disabled (status/disabled-for print-checks-status)} "With cash"] (list
(if (> balance 0.001) ^{:key (str id "-check")} [:a.dropdown-item {:on-click (dispatch-event-with-propagation [::print-checks id :check])
(list :disabled (status/disabled-for print-checks-status)} "Print checks from " name]
^{:key (str id "-check")} [:a.dropdown-item {:on-click (dispatch-event-with-propagation [::print-checks id :check]) ^{:key (str id "-debit")} [:a.dropdown-item {:on-click (dispatch-event-with-propagation [::print-checks id :debit])
:disabled (status/disabled-for print-checks-status)} "Print checks from " name] :disabled (status/disabled-for print-checks-status)} "Debit from " name])
^{:key (str id "-debit")} [:a.dropdown-item {:on-click (dispatch-event-with-propagation [::print-checks id :debit]) (list
:disabled (status/disabled-for print-checks-status)} "Debit from " name]) ^{:key (str id "-credit")} [:a.dropdown-item {:on-click (dispatch-event-with-propagation [::print-checks id :credit])
(list :disabled (status/disabled-for print-checks-status)} "Credit from " name]
^{:key (str id "-credit")} [:a.dropdown-item {:on-click (dispatch-event-with-propagation [::print-checks id :credit]) ))))
:disabled (status/disabled-for print-checks-status)} "Credit from " name]
))))
^{:key "advanced-divider"} [:hr.dropdown-divider] ^{:key "advanced-divider"} [:hr.dropdown-divider]
(when (and (> (count checked-invoices) 1) (when (and (> (count checked-invoices) 1)
(= 1 (count (set (map (comp :id :vendor) (vals checked-invoices))))) (= 1 (count (set (map (comp :id :vendor) (vals checked-invoices)))))
(< balance 0.001)) (< balance 0.001))
^{:key (str "balance-credit")} [:a.dropdown-item {:on-click (dispatch-event-with-propagation [::pay-invoices-from-balance]) ^{:key (str "balance-credit")} [:a.dropdown-item {:on-click (dispatch-event-with-propagation [::pay-invoices-from-balance])
:disabled (status/disabled-for print-checks-status)} "Pay invoices using balance "]) :disabled (status/disabled-for print-checks-status)} "Pay invoices using balance "])
(when (and (= 1 (count (set (map (comp :id :vendor) (vals checked-invoices))))) (when (and (= 1 (count (set (map (comp :id :vendor) (vals checked-invoices)))))
(> balance 0.001)) (> balance 0.001))
^{:key "handwritten"} [:a.dropdown-item {:on-click (dispatch-event-with-propagation [::handwritten-checks/show (vals checked-invoices)]) ^{:key "handwritten"} [:a.dropdown-item {:on-click (dispatch-event-with-propagation [::handwritten-checks/show (vals checked-invoices)])
:disabled (status/disabled-for print-checks-status)} "Handwritten Check..."]) :disabled (status/disabled-for print-checks-status)} "Handwritten Check..."])
(when (> balance 0.001) (when (> balance 0.001)
^{:key "advanced"} [:a.dropdown-item {:on-click (dispatch-event-with-propagation [::advanced-print-checks/show (vals checked-invoices)]) ^{:key "advanced"} [:a.dropdown-item {:on-click (dispatch-event-with-propagation [::advanced-print-checks/show (vals checked-invoices)])
:disabled (status/disabled-for print-checks-status)} "Advanced..."]))]]))]] :disabled (status/disabled-for print-checks-status)} "Advanced..."]))]]))]))
[:div.is-pulled-right {:style {:margin-right "0.5rem"}}
(into [:div.tags ] (map (fn [[z {:keys [id invoice-number]}]]
(if (= z "header")
[:span.tag.is-medium "All visible invoices"
[:button.delete.is-small {:on-click
(dispatch-event [::data-page/remove-check :invoices z])}]]
[:span.tag.is-medium invoice-number
[:button.delete.is-small {:on-click
(dispatch-event [::data-page/remove-check :invoices id])}]]))
checked-invoices))]]))
(defn unpaid-invoices-content [{:keys [status]}] (defn unpaid-invoices-content [{:keys [status]}]
(let [page @(re-frame/subscribe [::data-page/page :invoices]) (let [page @(re-frame/subscribe [::data-page/page :invoices])
current-client @(re-frame/subscribe [::subs/client])] current-client @(re-frame/subscribe [::subs/client])]
[:div [:div
[:h1.title (str (str/capitalize (name (or status :all))) " invoices")] [:h1.title (str (str/capitalize (name (or status :all))) " invoices")]
[status/status-notification {:statuses [[::status/single ::print-checks] [status/status-notification {:statuses [[::status/single ::print-checks]
[::status/last-multi ::table/void] [::status/last-multi ::table/void]
[::status/last-multi ::table/unvoid]]}] [::status/last-multi ::table/unvoid]]}]
(when (= status :unpaid)
[pay-button]) [table/invoice-table {:id (:id page)
[table/invoice-table {:id (:id page) :data-page :invoices
:data-page :invoices :check-boxes (= status :unpaid)
:check-boxes (= status :unpaid) :checkable-fn (fn [i] (not (:scheduled-payment i)))
:checkable-fn (fn [i] (not (:scheduled-payment i))) :actions #{:edit :void :expense-accounts}
:actions #{:edit :void :expense-accounts}}]])) :action-buttons (when (= status :unpaid)
[pay-button])}]]))
(defn layout [params] (defn layout [params]
(let [{invoice-bar-active? :active?} @(re-frame/subscribe [::forms/form ::form/form])] (let [{invoice-bar-active? :active?} @(re-frame/subscribe [::forms/form ::form/form])]