made ledger table updated.

This commit is contained in:
Bryce Covert
2020-08-05 08:07:41 -07:00
parent 0fd8d4a1c1
commit e0222bac48
4 changed files with 86 additions and 167 deletions

View File

@@ -5,7 +5,8 @@
[auto-ap.views.components.sort-by-list :refer [sort-by-list]]
[auto-ap.views.utils :refer [date->str dispatch-event nf]]
[goog.string :as gstring]
[re-frame.core :as re-frame]))
[re-frame.core :as re-frame]
[auto-ap.views.components.grid :as grid]))
(re-frame/reg-sub
::table-params
@@ -18,121 +19,64 @@
(fn [{table-params :db} [_ params :as z]]
{:db (merge table-params params)}))
(defn ledger-row [{{:keys [client vendor status date amount id line-items] :as i} :row
:keys [selected-client accounts-by-id bank-accounts-by-id]}]
[:<>
[grid/row {:class (:class i)}
(when-not selected-client
[grid/cell {} (:name client)])
[grid/cell {} (if vendor
(:name vendor)
[:i.has-text-grey (str "Unknown Merchant")])]
[grid/cell {} (date->str date) ]
[grid/cell {} ]
[grid/cell {:class "has-text-right"} (nf amount )]
[grid/cell {:class "has-text-right"} (nf amount )]]
[:<>
(for [{:keys [debit credit location account id]} line-items
:let [account (or (accounts-by-id (:id account))
(bank-accounts-by-id (:id account)))]]
^{:key id}
[grid/row {}
(when-not selected-client
[grid/cell {} ])
[grid/cell {} ]
[grid/cell {} ]
[grid/cell {} (if (:name account)
(str location ": " (:name account))
[:i "unknown"])]
[grid/cell {:class "has-text-right"} (when debit (nf debit ))]
[grid/cell {:class "has-text-right"} (when credit (nf credit ))]])]])
(defn table [{:keys [id ledger-page status vendors check-boxes checked on-check-changed expense-event]}]
(fn [{:keys [id ledger-page status vendors checked status?]
:or {status? true}}]
(let [{:keys [sort]} @(re-frame/subscribe [::table-params])
{:keys [journal-entries start end count total]} @ledger-page
selected-client @(re-frame/subscribe [::subs/client])
accounts-by-id @(re-frame/subscribe [::subs/accounts-by-id selected-client])
bank-accounts-by-id @(re-frame/subscribe [::subs/bank-accounts-by-id])
percentage-size (if selected-client "25%" "33%")
opc (fn [e]
(re-frame/dispatch [::params-changed e]))]
[:div
[:div.level
[:div.level-left
[:div.level-item
[paginator {:start start :end end :count count :total total
:on-change opc}]]
[:div.level-item
[sort-by-list {:sort sort
:on-change opc}]]]]
[:table.table.is-fullwidth.compact
[:thead
[:tr
bank-accounts-by-id @(re-frame/subscribe [::subs/bank-accounts-by-id])]
[grid/grid {:on-params-change (fn [e]
(re-frame/dispatch [::params-changed e]))
:params @(re-frame/subscribe [::table-params])
:status status
:column-count (if selected-client 5 6)}
[grid/controls ledger-page]
[grid/table {:fullwidth true}
[grid/header
[grid/row {}
(when-not selected-client
[sorted-column {:on-sort opc
:style {:width percentage-size :cursor "pointer"}
:sort-key "client"
:sort-name "Client"
:sort sort}
"Client"])
[sorted-column {:on-sort opc
:style {:width percentage-size :cursor "pointer"}
:sort-key "vendor"
:sort-name "Vendor"
:sort sort}
"Vendor"]
[sorted-column {:on-sort opc
:style {:width "8em" :cursor "pointer"}
:sort-key "date"
:sort-name "Date"
:sort sort}
"Date"]
[:th
{:style {:width percentage-size }}
"Account"]
[sorted-column {:on-sort opc
:style {:width "8em" :cursor "pointer"}
:sort-key "amount"
:sort-name "Amount"
:class "has-text-right"
:sort sort}
"Debit"]
[sorted-column {:on-sort opc
:style {:width "8em" :cursor "pointer"}
:sort-key "amount"
:sort-name "Amount"
:class "has-text-right"
:sort sort}
"Credit"]
(when status?
[sorted-column {:on-sort opc
:style {:width "8em" :cursor "pointer"}
:sort-key "status"
:sort-name "Status"
:sort sort}
"Status"])]]
[:tbody
(if (:loading @status)
[:tr
[:td {:col-span 5}
[:i.fa.fa-spin.fa-spinner]]]
(->>
(for [{:keys [client vendor status date amount id line-items] :as i} (:journal-entries @ledger-page)]
(into
[^{:key id}
[:tr {:class (:class i)}
(when-not selected-client
[:td (:name client)])
[:td (if vendor
(:name vendor)
[:i.has-text-grey (str "Unknown Merchant")])]
#_[:td description-original]
[:td (date->str date) ]
[:td ]
[:td.has-text-right (nf amount )]
[:td.has-text-right (nf amount )]
(when status?
[:td status])]]
(for [{:keys [debit credit location account id]} line-items
:let [account (or (accounts-by-id (:id account))
(bank-accounts-by-id (:id account)))]]
^{:key id}
[:tr {:class (:class i)}
(when-not selected-client
[:td ])
[:td ]
#_[:td description-original]
[:td ]
[:td (if (:name account)
(str location ": " (:name account))
[:i "unknown"])]
[:td.has-text-right (when debit (nf debit ))]
[:td.has-text-right (when credit (nf credit ))]
(when status?
[:td status])]
)))
(mapcat identity)))]]])))
[grid/sortable-header-cell {:sort-key "client" :sort-name "Client"} "Client"])
[grid/sortable-header-cell {:sort-key "vendor" :sort-name "Vendor"} "Vendor"]
[grid/sortable-header-cell {:sort-key "date" :sort-name "Date" :style {:width "15em"}} "Date"]
[grid/header-cell {} "Account"]
[grid/sortable-header-cell {:sort-key "amount" :sort-name "Amount" :class "has-text-right" :style {:width "12em"}} "Debit"]
[grid/sortable-header-cell {:sort-key "amount" :sort-name "Amount" :class "has-text-right" :style {:width "12em"}} "Credit"]]]
[grid/body
(for [{:keys [client vendor status date amount id line-items] :as i} (:journal-entries ledger-page)]
^{:key id}
[ledger-row {:row i
:selected-client selected-client
:accounts-by-id accounts-by-id
:bank-accounts-by-id bank-accounts-by-id}]
)]]])))