made ledger table updated.
This commit is contained in:
@@ -67,7 +67,6 @@
|
||||
(re-frame/reg-event-fx
|
||||
::editing
|
||||
(fn [{:keys [db]} [_ client-id]]
|
||||
(println (get (:clients db) client-id))
|
||||
{:db (-> db
|
||||
(forms/stop-form ::form)
|
||||
(forms/start-form ::form (-> (get (:clients db) client-id)
|
||||
@@ -113,27 +112,6 @@
|
||||
|
||||
(assoc-in [:clients (:id (:edit-client client))] (update (:edit-client client) :bank-accounts (fn [bas] (->> bas (sort-by :sort-order) vec)))))))
|
||||
|
||||
(re-frame/reg-event-db
|
||||
::add-forecasted-transaction
|
||||
[(forms/in-form ::form) (re-frame/path [:data])]
|
||||
(fn [client _]
|
||||
(-> client
|
||||
(update :forecasted-transactions conj (assoc (:new-forecasted-transaction client) :temp-id (random-uuid)))
|
||||
(dissoc :new-forecasted-transaction))))
|
||||
|
||||
(re-frame/reg-event-db
|
||||
::remove-forecasted-transaction
|
||||
[(forms/in-form ::form) (re-frame/path [:data])]
|
||||
(fn [client [_ which]]
|
||||
|
||||
(-> client
|
||||
(update :forecasted-transactions #(transduce
|
||||
(filter (fn [x] (and (not= (:temp-id x) which)
|
||||
(not= (:id x) which))))
|
||||
|
||||
conj
|
||||
[]
|
||||
%)))))
|
||||
|
||||
|
||||
(re-frame/reg-event-db
|
||||
@@ -350,8 +328,6 @@
|
||||
next-week-b (if (is-week-a? (t/now))
|
||||
"Next week"
|
||||
"This week")]
|
||||
(println "ID" (:id new-client))
|
||||
|
||||
[side-bar {:on-close (dispatch-event [::forms/form-closing ::form ])}
|
||||
^{:key (:id new-client)}
|
||||
[:div ;; div is important for actually unmounting for now
|
||||
@@ -416,11 +392,11 @@
|
||||
:maxlength 2
|
||||
:style { :width "4em"}}]]}])]
|
||||
|
||||
[:div {:style {:padding-bottom "0.75em" :padding-top "0.75em"}}
|
||||
[:h2.subtitle "Address"]
|
||||
[address-field {:field [:address]
|
||||
:event [::forms/change ::form]
|
||||
:subscription new-client}]]
|
||||
[:h2.subtitle "Address"]
|
||||
[address-field {:field [:address]
|
||||
:event [::forms/change ::form]
|
||||
:subscription new-client}]
|
||||
|
||||
|
||||
[:h2.subtitle "Bank accounts"]
|
||||
(for [bank-account (sort-by :sort-order (:bank-accounts new-client))]
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
(:require [auto-ap.events :as events]
|
||||
[auto-ap.forms :as forms]
|
||||
[auto-ap.subs :as subs]
|
||||
[vimsical.re-frame.cofx.inject :as inject]
|
||||
[auto-ap.views.components.bank-account-filter :refer [bank-account-filter]]
|
||||
[auto-ap.views.components.layouts :refer [appearing-side-bar side-bar-layout]]
|
||||
[auto-ap.routes :as routes]
|
||||
@@ -19,7 +18,9 @@
|
||||
[auto-ap.views.utils :refer [bind-field date->str dispatch-event nf active-when with-user]]
|
||||
[goog.string :as gstring]
|
||||
[re-frame.core :as re-frame]
|
||||
[reagent.core :as reagent]))
|
||||
[reagent.core :as reagent]
|
||||
[auto-ap.status :as status]
|
||||
[vimsical.re-frame.fx.track :as track]))
|
||||
|
||||
|
||||
(re-frame/reg-sub
|
||||
@@ -27,35 +28,26 @@
|
||||
(fn [db]
|
||||
(-> db ::ledger-page)))
|
||||
|
||||
(re-frame/reg-sub
|
||||
::last-params
|
||||
(fn [db]
|
||||
(-> db ::last-params)))
|
||||
|
||||
|
||||
(re-frame/reg-sub
|
||||
::params
|
||||
:<- [::last-params]
|
||||
:<- [::subs/client]
|
||||
:<- [::side-bar/filter-params]
|
||||
:<- [::table/table-params]
|
||||
(fn [[last-params client filter-params table-params]]
|
||||
(let [params (cond-> {}
|
||||
client (assoc :client-id (:id client))
|
||||
(seq filter-params) (merge filter-params)
|
||||
(seq table-params) (merge table-params))]
|
||||
(when (not= params last-params)
|
||||
(re-frame/dispatch [::params-change]))
|
||||
params)))
|
||||
(fn [[client filter-params table-params]]
|
||||
(cond-> {}
|
||||
client (assoc :client-id (:id client))
|
||||
(seq filter-params) (merge filter-params)
|
||||
(seq table-params) (merge table-params))))
|
||||
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::params-change
|
||||
[with-user (re-frame/inject-cofx ::inject/sub [::params])]
|
||||
(fn [{:keys [user ::params db]} [_]]
|
||||
{:db (-> db
|
||||
(assoc-in [::last-params] params)
|
||||
(assoc-in [:status :loading] true))
|
||||
:graphql {:token user
|
||||
[with-user]
|
||||
(fn [{:keys [user db]} [_ params]]
|
||||
{:graphql {:token user
|
||||
:owns-state {:single ::page}
|
||||
:query-obj {:venia/queries [[:ledger-page
|
||||
params
|
||||
[[:journal-entries [:id
|
||||
@@ -80,22 +72,29 @@
|
||||
(re-frame/reg-event-fx
|
||||
::unmounted
|
||||
(fn [{:keys [db]} _]
|
||||
{:db (dissoc db ::last-params ::table/table-params ::side-bar/filters ::ledger-page)}))
|
||||
{:db (dissoc db ::table/table-params ::side-bar/filters ::ledger-page)
|
||||
::track/dispose {:id ::params}}))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::mounted
|
||||
(fn [{:keys [db]} _]
|
||||
{::track/register {:id ::params
|
||||
:subscription [::params]
|
||||
:event-fn (fn [params] [::params-change params])}}))
|
||||
|
||||
(re-frame/reg-event-db
|
||||
::received
|
||||
(fn [db [_ data]]
|
||||
(-> db
|
||||
(assoc ::ledger-page (:ledger-page data))
|
||||
(assoc-in [:status :loading] false))))
|
||||
(assoc ::ledger-page (:ledger-page data)))))
|
||||
|
||||
(defn ledger-content []
|
||||
(let [current-client @(re-frame/subscribe [::subs/client])]
|
||||
[:div
|
||||
[:h1.title "Ledger"]
|
||||
[table/table {:id :ledger
|
||||
:ledger-page (re-frame/subscribe [::ledger-page])
|
||||
:status (re-frame/subscribe [::subs/status])}]
|
||||
:ledger-page @(re-frame/subscribe [::ledger-page])
|
||||
:status @(re-frame/subscribe [::status/single ::page])}]
|
||||
[manual/modal {:import-completed [::manual-import-completed ]}]]))
|
||||
|
||||
|
||||
@@ -103,6 +102,7 @@
|
||||
(let [user (re-frame/subscribe [::subs/user])]
|
||||
(reagent/create-class
|
||||
{:display-name "ledger-page"
|
||||
:component-did-mount #(re-frame/dispatch [::mounted])
|
||||
:component-will-unmount #(re-frame/dispatch [::unmounted])
|
||||
:reagent-render
|
||||
(fn []
|
||||
|
||||
@@ -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}]
|
||||
)]]])))
|
||||
|
||||
|
||||
@@ -243,7 +243,6 @@
|
||||
event (if (keyword? event) [event] event)
|
||||
keys (assoc keys
|
||||
:on-change (fn [value]
|
||||
(println value)
|
||||
(re-frame/dispatch (conj (conj event field) value)))
|
||||
:value (get-in subscription field)
|
||||
:class (str class
|
||||
|
||||
Reference in New Issue
Block a user