made ledger table updated.
This commit is contained in:
@@ -67,7 +67,6 @@
|
|||||||
(re-frame/reg-event-fx
|
(re-frame/reg-event-fx
|
||||||
::editing
|
::editing
|
||||||
(fn [{:keys [db]} [_ client-id]]
|
(fn [{:keys [db]} [_ client-id]]
|
||||||
(println (get (:clients db) client-id))
|
|
||||||
{:db (-> db
|
{:db (-> db
|
||||||
(forms/stop-form ::form)
|
(forms/stop-form ::form)
|
||||||
(forms/start-form ::form (-> (get (:clients db) client-id)
|
(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)))))))
|
(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
|
(re-frame/reg-event-db
|
||||||
@@ -350,8 +328,6 @@
|
|||||||
next-week-b (if (is-week-a? (t/now))
|
next-week-b (if (is-week-a? (t/now))
|
||||||
"Next week"
|
"Next week"
|
||||||
"This week")]
|
"This week")]
|
||||||
(println "ID" (:id new-client))
|
|
||||||
|
|
||||||
[side-bar {:on-close (dispatch-event [::forms/form-closing ::form ])}
|
[side-bar {:on-close (dispatch-event [::forms/form-closing ::form ])}
|
||||||
^{:key (:id new-client)}
|
^{:key (:id new-client)}
|
||||||
[:div ;; div is important for actually unmounting for now
|
[:div ;; div is important for actually unmounting for now
|
||||||
@@ -416,11 +392,11 @@
|
|||||||
:maxlength 2
|
:maxlength 2
|
||||||
:style { :width "4em"}}]]}])]
|
:style { :width "4em"}}]]}])]
|
||||||
|
|
||||||
[:div {:style {:padding-bottom "0.75em" :padding-top "0.75em"}}
|
[:h2.subtitle "Address"]
|
||||||
[:h2.subtitle "Address"]
|
[address-field {:field [:address]
|
||||||
[address-field {:field [:address]
|
:event [::forms/change ::form]
|
||||||
:event [::forms/change ::form]
|
:subscription new-client}]
|
||||||
:subscription new-client}]]
|
|
||||||
|
|
||||||
[:h2.subtitle "Bank accounts"]
|
[:h2.subtitle "Bank accounts"]
|
||||||
(for [bank-account (sort-by :sort-order (:bank-accounts new-client))]
|
(for [bank-account (sort-by :sort-order (:bank-accounts new-client))]
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
(:require [auto-ap.events :as events]
|
(:require [auto-ap.events :as events]
|
||||||
[auto-ap.forms :as forms]
|
[auto-ap.forms :as forms]
|
||||||
[auto-ap.subs :as subs]
|
[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.bank-account-filter :refer [bank-account-filter]]
|
||||||
[auto-ap.views.components.layouts :refer [appearing-side-bar side-bar-layout]]
|
[auto-ap.views.components.layouts :refer [appearing-side-bar side-bar-layout]]
|
||||||
[auto-ap.routes :as routes]
|
[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]]
|
[auto-ap.views.utils :refer [bind-field date->str dispatch-event nf active-when with-user]]
|
||||||
[goog.string :as gstring]
|
[goog.string :as gstring]
|
||||||
[re-frame.core :as re-frame]
|
[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
|
(re-frame/reg-sub
|
||||||
@@ -27,35 +28,26 @@
|
|||||||
(fn [db]
|
(fn [db]
|
||||||
(-> db ::ledger-page)))
|
(-> db ::ledger-page)))
|
||||||
|
|
||||||
(re-frame/reg-sub
|
|
||||||
::last-params
|
|
||||||
(fn [db]
|
|
||||||
(-> db ::last-params)))
|
|
||||||
|
|
||||||
(re-frame/reg-sub
|
(re-frame/reg-sub
|
||||||
::params
|
::params
|
||||||
:<- [::last-params]
|
|
||||||
:<- [::subs/client]
|
:<- [::subs/client]
|
||||||
:<- [::side-bar/filter-params]
|
:<- [::side-bar/filter-params]
|
||||||
:<- [::table/table-params]
|
:<- [::table/table-params]
|
||||||
(fn [[last-params client filter-params table-params]]
|
(fn [[client filter-params table-params]]
|
||||||
(let [params (cond-> {}
|
(cond-> {}
|
||||||
client (assoc :client-id (:id client))
|
client (assoc :client-id (:id client))
|
||||||
(seq filter-params) (merge filter-params)
|
(seq filter-params) (merge filter-params)
|
||||||
(seq table-params) (merge table-params))]
|
(seq table-params) (merge table-params))))
|
||||||
(when (not= params last-params)
|
|
||||||
(re-frame/dispatch [::params-change]))
|
|
||||||
params)))
|
|
||||||
|
|
||||||
|
|
||||||
(re-frame/reg-event-fx
|
(re-frame/reg-event-fx
|
||||||
::params-change
|
::params-change
|
||||||
[with-user (re-frame/inject-cofx ::inject/sub [::params])]
|
[with-user]
|
||||||
(fn [{:keys [user ::params db]} [_]]
|
(fn [{:keys [user db]} [_ params]]
|
||||||
{:db (-> db
|
{:graphql {:token user
|
||||||
(assoc-in [::last-params] params)
|
:owns-state {:single ::page}
|
||||||
(assoc-in [:status :loading] true))
|
|
||||||
:graphql {:token user
|
|
||||||
:query-obj {:venia/queries [[:ledger-page
|
:query-obj {:venia/queries [[:ledger-page
|
||||||
params
|
params
|
||||||
[[:journal-entries [:id
|
[[:journal-entries [:id
|
||||||
@@ -80,22 +72,29 @@
|
|||||||
(re-frame/reg-event-fx
|
(re-frame/reg-event-fx
|
||||||
::unmounted
|
::unmounted
|
||||||
(fn [{:keys [db]} _]
|
(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
|
(re-frame/reg-event-db
|
||||||
::received
|
::received
|
||||||
(fn [db [_ data]]
|
(fn [db [_ data]]
|
||||||
(-> db
|
(-> db
|
||||||
(assoc ::ledger-page (:ledger-page data))
|
(assoc ::ledger-page (:ledger-page data)))))
|
||||||
(assoc-in [:status :loading] false))))
|
|
||||||
|
|
||||||
(defn ledger-content []
|
(defn ledger-content []
|
||||||
(let [current-client @(re-frame/subscribe [::subs/client])]
|
(let [current-client @(re-frame/subscribe [::subs/client])]
|
||||||
[:div
|
[:div
|
||||||
[:h1.title "Ledger"]
|
[:h1.title "Ledger"]
|
||||||
[table/table {:id :ledger
|
[table/table {:id :ledger
|
||||||
:ledger-page (re-frame/subscribe [::ledger-page])
|
:ledger-page @(re-frame/subscribe [::ledger-page])
|
||||||
:status (re-frame/subscribe [::subs/status])}]
|
:status @(re-frame/subscribe [::status/single ::page])}]
|
||||||
[manual/modal {:import-completed [::manual-import-completed ]}]]))
|
[manual/modal {:import-completed [::manual-import-completed ]}]]))
|
||||||
|
|
||||||
|
|
||||||
@@ -103,6 +102,7 @@
|
|||||||
(let [user (re-frame/subscribe [::subs/user])]
|
(let [user (re-frame/subscribe [::subs/user])]
|
||||||
(reagent/create-class
|
(reagent/create-class
|
||||||
{:display-name "ledger-page"
|
{:display-name "ledger-page"
|
||||||
|
:component-did-mount #(re-frame/dispatch [::mounted])
|
||||||
:component-will-unmount #(re-frame/dispatch [::unmounted])
|
:component-will-unmount #(re-frame/dispatch [::unmounted])
|
||||||
:reagent-render
|
:reagent-render
|
||||||
(fn []
|
(fn []
|
||||||
|
|||||||
@@ -5,7 +5,8 @@
|
|||||||
[auto-ap.views.components.sort-by-list :refer [sort-by-list]]
|
[auto-ap.views.components.sort-by-list :refer [sort-by-list]]
|
||||||
[auto-ap.views.utils :refer [date->str dispatch-event nf]]
|
[auto-ap.views.utils :refer [date->str dispatch-event nf]]
|
||||||
[goog.string :as gstring]
|
[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
|
(re-frame/reg-sub
|
||||||
::table-params
|
::table-params
|
||||||
@@ -18,121 +19,64 @@
|
|||||||
(fn [{table-params :db} [_ params :as z]]
|
(fn [{table-params :db} [_ params :as z]]
|
||||||
{:db (merge table-params params)}))
|
{: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]}]
|
(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?]
|
(fn [{:keys [id ledger-page status vendors checked status?]
|
||||||
:or {status? true}}]
|
:or {status? true}}]
|
||||||
(let [{:keys [sort]} @(re-frame/subscribe [::table-params])
|
(let [{:keys [sort]} @(re-frame/subscribe [::table-params])
|
||||||
{:keys [journal-entries start end count total]} @ledger-page
|
|
||||||
selected-client @(re-frame/subscribe [::subs/client])
|
selected-client @(re-frame/subscribe [::subs/client])
|
||||||
accounts-by-id @(re-frame/subscribe [::subs/accounts-by-id selected-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])
|
bank-accounts-by-id @(re-frame/subscribe [::subs/bank-accounts-by-id])]
|
||||||
percentage-size (if selected-client "25%" "33%")
|
[grid/grid {:on-params-change (fn [e]
|
||||||
opc (fn [e]
|
(re-frame/dispatch [::params-changed e]))
|
||||||
(re-frame/dispatch [::params-changed e]))]
|
:params @(re-frame/subscribe [::table-params])
|
||||||
[:div
|
:status status
|
||||||
[:div.level
|
:column-count (if selected-client 5 6)}
|
||||||
[:div.level-left
|
[grid/controls ledger-page]
|
||||||
[:div.level-item
|
[grid/table {:fullwidth true}
|
||||||
[paginator {:start start :end end :count count :total total
|
[grid/header
|
||||||
:on-change opc}]]
|
[grid/row {}
|
||||||
[:div.level-item
|
|
||||||
[sort-by-list {:sort sort
|
|
||||||
:on-change opc}]]]]
|
|
||||||
|
|
||||||
|
|
||||||
[:table.table.is-fullwidth.compact
|
|
||||||
[:thead
|
|
||||||
[:tr
|
|
||||||
(when-not selected-client
|
(when-not selected-client
|
||||||
[sorted-column {:on-sort opc
|
[grid/sortable-header-cell {:sort-key "client" :sort-name "Client"} "Client"])
|
||||||
:style {:width percentage-size :cursor "pointer"}
|
[grid/sortable-header-cell {:sort-key "vendor" :sort-name "Vendor"} "Vendor"]
|
||||||
:sort-key "client"
|
[grid/sortable-header-cell {:sort-key "date" :sort-name "Date" :style {:width "15em"}} "Date"]
|
||||||
:sort-name "Client"
|
[grid/header-cell {} "Account"]
|
||||||
:sort sort}
|
[grid/sortable-header-cell {:sort-key "amount" :sort-name "Amount" :class "has-text-right" :style {:width "12em"}} "Debit"]
|
||||||
"Client"])
|
[grid/sortable-header-cell {:sort-key "amount" :sort-name "Amount" :class "has-text-right" :style {:width "12em"}} "Credit"]]]
|
||||||
|
[grid/body
|
||||||
[sorted-column {:on-sort opc
|
(for [{:keys [client vendor status date amount id line-items] :as i} (:journal-entries ledger-page)]
|
||||||
:style {:width percentage-size :cursor "pointer"}
|
^{:key id}
|
||||||
:sort-key "vendor"
|
[ledger-row {:row i
|
||||||
:sort-name "Vendor"
|
:selected-client selected-client
|
||||||
:sort sort}
|
:accounts-by-id accounts-by-id
|
||||||
"Vendor"]
|
:bank-accounts-by-id bank-accounts-by-id}]
|
||||||
|
)]]])))
|
||||||
[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)))]]])))
|
|
||||||
|
|
||||||
|
|||||||
@@ -243,7 +243,6 @@
|
|||||||
event (if (keyword? event) [event] event)
|
event (if (keyword? event) [event] event)
|
||||||
keys (assoc keys
|
keys (assoc keys
|
||||||
:on-change (fn [value]
|
:on-change (fn [value]
|
||||||
(println value)
|
|
||||||
(re-frame/dispatch (conj (conj event field) value)))
|
(re-frame/dispatch (conj (conj event field) value)))
|
||||||
:value (get-in subscription field)
|
:value (get-in subscription field)
|
||||||
:class (str class
|
:class (str class
|
||||||
|
|||||||
Reference in New Issue
Block a user