Accounts don't need to be loaded

This commit is contained in:
2022-04-19 13:27:47 -07:00
parent f73b406abd
commit f51f3450d6
22 changed files with 398 additions and 420 deletions

View File

@@ -13,7 +13,6 @@
[auto-ap.views.utils :refer [date->str dispatch-event dispatch-event-with-propagation nf days-until]]
[bidi.bidi :as bidi]
[cemerick.url :as url]
[cljs-time.core :as t]
[clojure.string :as str]
[goog.string :as gstring]
[re-frame.core :as re-frame]
@@ -51,7 +50,7 @@
[[:invoices [:id :total :outstanding-balance :invoice-number :date :due :status :client-identifier :scheduled-payment :source-url :similarity
[:vendor [:name :id]]
[:expense_accounts [:amount :id :location
[:account [:id ]]]]
[:account [:id :name :location]]]]
[:client [:name :id :locations]]
[:payments [:amount :id [:payment [:id :status :amount :s3_url :check_number
[:transaction [:post_date]]]]]]]]
@@ -112,15 +111,13 @@
(re-frame/reg-event-fx
::invoice-updated
(fn [{:keys [db]} [_ invoice]]
(fn [{:keys [db]} [_ _]]
{:db db}))
(defn row [{:keys [invoice check-boxes selected-client overrides checkable? expense-event actions]}]
(defn row [{:keys [invoice selected-client overrides checkable? actions]}]
(let [{:keys [client status payments expense-accounts invoice-number date due total outstanding-balance id vendor source-url] :as i} invoice
accounts-by-id @(re-frame/subscribe [::subs/accounts-by-id client])
unautopay-states @(re-frame/subscribe [::status/multi ::unautopay])
editing-states @(re-frame/subscribe [::status/multi ::edits])
account->name #(:name (accounts-by-id (:id %)))]
editing-states @(re-frame/subscribe [::status/multi ::edits])]
[grid/row {:class (:class i) :id id :checkable? checkable? :entity invoice}
(when-not selected-client
[grid/cell {}
@@ -143,9 +140,8 @@
[grid/cell {:class "has-text-right"} (nf total )]
[grid/cell {:class "has-text-right"}
(if (:scheduled-payment i)
[:<> [:div.tag.is-info.is-light "Autopay"] " "]
)
(when (:scheduled-payment i)
[:<> [:div.tag.is-info.is-light "Autopay"] " "])
(nf outstanding-balance )]
[grid/button-cell {}
[:div.buttons
@@ -160,7 +156,7 @@
[:div
(for [e expense-accounts]
^{:key (:id e)}
[:span.dropdown-item (account->name (:account e)) " " (gstring/format "$%.2f" (:amount e) ) ])
[:span.dropdown-item (:name (:account e)) " " (gstring/format "$%.2f" (:amount e) ) ])
(when (get actions :expense-accounts)
[:<>
@@ -237,17 +233,14 @@
:class (status/class-for (get unautopay-states (:id i)))
:event [::unautopay i]}])]]]))
(defn invoice-table [{:keys [id check-boxes overrides actions data-page checkable-fn]}]
(let [selected-client @(re-frame/subscribe [::subs/client])
{:keys [data status params table-params]} @(re-frame/subscribe [::data-page/page data-page])
(defn invoice-table [{:keys [check-boxes overrides actions data-page checkable-fn]}]
(let [{:keys [data status params table-params]} @(re-frame/subscribe [::data-page/page data-page])
selected-client @(re-frame/subscribe [::subs/client])
is-loading? (= :loading (:state status))
is-sorted-by-vendor? (and (= "vendor" (:sort-key (first (:sort table-params))))
(not is-loading?)
(or (apply <= (map (comp :name :vendor) (:data data)))
(apply >= (map (comp :name :vendor) (:data data)))))
[invoice-groups] (if is-sorted-by-vendor?
(reduce
(fn [[acc last-vendor] invoice]