not sure if this is a good idea.

This commit is contained in:
Bryce Covert
2020-05-14 07:35:42 -07:00
parent aa6ed8355b
commit d5dc62cc6a

View File

@@ -164,7 +164,21 @@
visible-checks @(re-frame/subscribe [::visible-checks])
visible-expense-accounts @(re-frame/subscribe [::visible-expense-accounts])
selected-client @(re-frame/subscribe [::subs/client])
percentage-size (if selected-client "%50%" "33%")]
percentage-size (if selected-client "%50%" "33%")
is-sorted-by-vendor? (seq (filter #(= "vendor" (:sort-key %)) sort))
_ (println is-sorted-by-vendor? sort)
[invoice-groups] (if is-sorted-by-vendor?
(reduce
(fn [[acc last-vendor] invoice]
(if (not= (:id (:vendor invoice))
last-vendor)
[(update-in acc [(clojure.core/count acc)] #(conj (or % []) invoice))
(:id (:vendor invoice))]
[(update-in acc [(dec (clojure.core/count acc))] #(conj (or % []) invoice))
(:id (:vendor invoice))]))
[[] nil]
(:invoices @invoice-page))
[[(:invoices @invoice-page)]])]
[:div
[:div.level
[:div.level-left
@@ -174,86 +188,89 @@
[:div.level-item
[sort-by-list {:sort sort
:on-change opc}]]]]
[:table.table.is-fullwidth
[:thead
[:tr
(when check-boxes
[:th {:style {"width" "20px"}}])
(when-not selected-client
[sorted-column {:on-sort opc
:style {:width percentage-size :cursor "pointer"}
:sort-name "Client"
:sort-key "client"
:sort sort}
"Client"])
[sorted-column {:on-sort opc
:style {:width percentage-size :cursor "pointer"}
:sort-name "Vendor"
:sort-key "vendor"
:sort sort}
"Vendor"]
[sorted-column {:on-sort opc
:style {:width percentage-size :cursor "pointer"}
:sort-name "Invoice Number"
:sort-key "invoice-number"
:sort sort}
"Invoice #"]
[sorted-column {:on-sort opc
:style {:width "8em" :cursor "pointer"}
:sort-name "Date"
:sort-key "date"
:sort sort}
"Date"]
[sorted-column {:on-sort opc
:style {:width "8em" :cursor "pointer"}
:sort-name "Due"
:sort-key "due"
:sort sort}
"Due"]
[sorted-column {:on-sort opc
:style {:width "5em" :cursor "pointer"}
:sort-name "Location"
:sort-key "location"
:sort sort}
"Loc"]
[sorted-column {:on-sort opc
:style {:width "8em" :cursor "pointer"}
:sort-name "Total"
:sort-key "total"
:class "has-text-right"
:sort sort}
"Amount"]
(doall
(for [invoices invoice-groups]
^{:key (:id (first invoices))}
[:table.table.is-fullwidth
[:thead
[:tr
(when check-boxes
[:th {:style {"width" "20px"}}])
(when-not selected-client
[sorted-column {:on-sort opc
:style {:width percentage-size :cursor "pointer"}
:sort-name "Client"
:sort-key "client"
:sort sort}
"Client"])
[sorted-column {:on-sort opc
:style {:width percentage-size :cursor "pointer"}
:sort-name "Vendor"
:sort-key "vendor"
:sort sort}
"Vendor"]
[sorted-column {:on-sort opc
:style {:width percentage-size :cursor "pointer"}
:sort-name "Invoice Number"
:sort-key "invoice-number"
:sort sort}
"Invoice #"]
[sorted-column {:on-sort opc
:style {:width "8em" :cursor "pointer"}
:sort-name "Date"
:sort-key "date"
:sort sort}
"Date"]
[sorted-column {:on-sort opc
:style {:width "8em" :cursor "pointer"}
:sort-name "Due"
:sort-key "due"
:sort sort}
"Due"]
[sorted-column {:on-sort opc
:style {:width "5em" :cursor "pointer"}
:sort-name "Location"
:sort-key "location"
:sort sort}
"Loc"]
[sorted-column {:on-sort opc
:style {:width "8em" :cursor "pointer"}
:sort-name "Total"
:sort-key "total"
:class "has-text-right"
:sort sort}
"Amount"]
[sorted-column {:on-sort opc
:style {:width "10em" :cursor "pointer"}
:sort-name "Outstanding"
:sort-key "outstanding-balance"
:class "has-text-right"
:sort sort}
"Outstanding"]
[:th {
:style {:width "20rem" :cursor "pointer"}
}
""]]]
[:tbody
(if (:loading @status)
[:tr
[:td {:col-span 5}
[:i.fa.fa-spin.fa-spinner]]]
(for [{:keys [client payments expense-accounts invoice-number date due total outstanding-balance id vendor] :as i} (:invoices @invoice-page)]
^{:key id}
[row {:invoice i
:check-boxes check-boxes
:checked checked
:on-check-changed on-check-changed
:selected-client selected-client
:overrides overrides
:expense-event expense-event
:on-edit-invoice on-edit-invoice
:on-void-invoice on-void-invoice
:on-unvoid-invoice on-unvoid-invoice}]))]]]))
[sorted-column {:on-sort opc
:style {:width "10em" :cursor "pointer"}
:sort-name "Outstanding"
:sort-key "outstanding-balance"
:class "has-text-right"
:sort sort}
"Outstanding"]
[:th {
:style {:width "20rem" :cursor "pointer"}
}
""]]]
[:tbody
(if (:loading @status)
[:tr
[:td {:col-span 5}
[:i.fa.fa-spin.fa-spinner]]]
(for [{:keys [client payments expense-accounts invoice-number date due total outstanding-balance id vendor] :as i} invoices]
^{:key id}
[row {:invoice i
:check-boxes check-boxes
:checked checked
:on-check-changed on-check-changed
:selected-client selected-client
:overrides overrides
:expense-event expense-event
:on-edit-invoice on-edit-invoice
:on-void-invoice on-void-invoice
:on-unvoid-invoice on-unvoid-invoice}]))]]))]))