cleaned up how these are generated.
This commit is contained in:
@@ -30,7 +30,8 @@
|
||||
[re-frame.core :as re-frame]
|
||||
[reagent.core :as r]
|
||||
[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
|
||||
::params-change
|
||||
@@ -212,94 +213,83 @@
|
||||
(let [current-client @(re-frame/subscribe [::subs/client])
|
||||
checked-invoices @(re-frame/subscribe [::data-page/checked :invoices])
|
||||
print-checks-status @(re-frame/subscribe [::status/single ::print-checks])]
|
||||
[:div
|
||||
[:div.is-pulled-right
|
||||
[:div.buttons
|
||||
[void-selected-button]
|
||||
|
||||
[buttons/new-button {:event [::new-invoice-clicked]
|
||||
:name "Invoice"
|
||||
:class "is-primary"}]
|
||||
|
||||
(when current-client
|
||||
(let [balance (->> checked-invoices
|
||||
vals
|
||||
(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 ])
|
||||
:disabled (or (status/disabled-for print-checks-status) (not (seq checked-invoices)))
|
||||
:class (status/class-for @(re-frame/subscribe [::status/single ::print-checks]))}
|
||||
"Pay "
|
||||
(when (> (count checked-invoices ) 0)
|
||||
(str
|
||||
(count checked-invoices)
|
||||
" invoices "
|
||||
"(" (gstring/format "$%.2f" balance ) ")"))
|
||||
[:span " "]
|
||||
[:span.icon.is-small [:i.fa.fa-angle-down {:aria-hidden "true"}]]]
|
||||
:id ::print-checks
|
||||
:is-right? true}
|
||||
[:div
|
||||
(list
|
||||
(for [{:keys [id number name type]} (->> (:bank-accounts current-client) (filter :visible) (sort-by :sort-order))]
|
||||
(if (= :cash type)
|
||||
^{:key id} [:a.dropdown-item {:on-click (dispatch-event [::print-checks id :cash])
|
||||
:disabled (status/disabled-for print-checks-status)} "With cash"]
|
||||
(if (> balance 0.001)
|
||||
(list
|
||||
^{:key (str id "-check")} [:a.dropdown-item {:on-click (dispatch-event-with-propagation [::print-checks id :check])
|
||||
:disabled (status/disabled-for print-checks-status)} "Print checks from " name]
|
||||
^{:key (str id "-debit")} [:a.dropdown-item {:on-click (dispatch-event-with-propagation [::print-checks id :debit])
|
||||
:disabled (status/disabled-for print-checks-status)} "Debit from " name])
|
||||
(list
|
||||
^{: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]
|
||||
))))
|
||||
[:div.buttons
|
||||
[void-selected-button]
|
||||
|
||||
[buttons/new-button {:event [::new-invoice-clicked]
|
||||
:name "Invoice"
|
||||
:class "is-primary"}]
|
||||
|
||||
(when current-client
|
||||
(let [balance (->> checked-invoices
|
||||
vals
|
||||
(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 ])
|
||||
:disabled (or (status/disabled-for print-checks-status) (not (seq checked-invoices)))
|
||||
:class (status/class-for @(re-frame/subscribe [::status/single ::print-checks]))}
|
||||
"Pay "
|
||||
(when (> (count checked-invoices ) 0)
|
||||
(str
|
||||
(count checked-invoices)
|
||||
" invoices "
|
||||
"(" (gstring/format "$%.2f" balance ) ")"))
|
||||
[:span " "]
|
||||
[:span.icon.is-small [:i.fa.fa-angle-down {:aria-hidden "true"}]]]
|
||||
:id ::print-checks
|
||||
:is-right? true}
|
||||
[:div
|
||||
(list
|
||||
(for [{:keys [id number name type]} (->> (:bank-accounts current-client) (filter :visible) (sort-by :sort-order))]
|
||||
(if (= :cash type)
|
||||
^{:key id} [:a.dropdown-item {:on-click (dispatch-event [::print-checks id :cash])
|
||||
:disabled (status/disabled-for print-checks-status)} "With cash"]
|
||||
(if (> balance 0.001)
|
||||
(list
|
||||
^{:key (str id "-check")} [:a.dropdown-item {:on-click (dispatch-event-with-propagation [::print-checks id :check])
|
||||
:disabled (status/disabled-for print-checks-status)} "Print checks from " name]
|
||||
^{:key (str id "-debit")} [:a.dropdown-item {:on-click (dispatch-event-with-propagation [::print-checks id :debit])
|
||||
:disabled (status/disabled-for print-checks-status)} "Debit from " name])
|
||||
(list
|
||||
^{: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)
|
||||
(= 1 (count (set (map (comp :id :vendor) (vals checked-invoices)))))
|
||||
(< balance 0.001))
|
||||
^{: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 "])
|
||||
(when (and (> (count checked-invoices) 1)
|
||||
(= 1 (count (set (map (comp :id :vendor) (vals checked-invoices)))))
|
||||
(< balance 0.001))
|
||||
^{: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 "])
|
||||
|
||||
(when (and (= 1 (count (set (map (comp :id :vendor) (vals checked-invoices)))))
|
||||
(> balance 0.001))
|
||||
^{: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..."])
|
||||
(when (> balance 0.001)
|
||||
^{: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..."]))]]))]]
|
||||
[: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))]]))
|
||||
(when (and (= 1 (count (set (map (comp :id :vendor) (vals checked-invoices)))))
|
||||
(> balance 0.001))
|
||||
^{: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..."])
|
||||
(when (> balance 0.001)
|
||||
^{: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..."]))]]))]))
|
||||
|
||||
|
||||
(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])]
|
||||
[:div
|
||||
[:h1.title (str (str/capitalize (name (or status :all))) " invoices")]
|
||||
[status/status-notification {:statuses [[::status/single ::print-checks]
|
||||
[::status/last-multi ::table/void]
|
||||
[::status/last-multi ::table/unvoid]]}]
|
||||
(when (= status :unpaid)
|
||||
[pay-button])
|
||||
[table/invoice-table {:id (:id page)
|
||||
:data-page :invoices
|
||||
:check-boxes (= status :unpaid)
|
||||
:checkable-fn (fn [i] (not (:scheduled-payment i)))
|
||||
:actions #{:edit :void :expense-accounts}}]]))
|
||||
|
||||
[table/invoice-table {:id (:id page)
|
||||
:data-page :invoices
|
||||
:check-boxes (= status :unpaid)
|
||||
:checkable-fn (fn [i] (not (:scheduled-payment i)))
|
||||
:actions #{:edit :void :expense-accounts}
|
||||
:action-buttons (when (= status :unpaid)
|
||||
[pay-button])}]]))
|
||||
|
||||
(defn layout [params]
|
||||
(let [{invoice-bar-active? :active?} @(re-frame/subscribe [::forms/form ::form/form])]
|
||||
|
||||
Reference in New Issue
Block a user