filtering on ledger page.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
(ns auto-ap.core
|
||||
(:require [reagent.core :as reagent]
|
||||
[reagent.dom :as rdom]
|
||||
[re-frame.core :as re-frame]
|
||||
[auto-ap.events :as events]
|
||||
[auto-ap.views.main :refer [page active-page] ]
|
||||
@@ -19,7 +20,7 @@
|
||||
|
||||
(defn mount-root []
|
||||
(re-frame/clear-subscription-cache!)
|
||||
(reagent/render [active-page]
|
||||
(rdom/render [active-page]
|
||||
(.getElementById js/document "app")))
|
||||
|
||||
(defn ^:export init []
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
(ns auto-ap.views.pages.import-invoices
|
||||
(:require [re-frame.core :as re-frame]
|
||||
[reagent.core :as reagent]
|
||||
[reagent.dom :as rdom]
|
||||
[auto-ap.events :as events]
|
||||
[auto-ap.subs :as subs]
|
||||
[auto-ap.entities.clients :as client]
|
||||
@@ -32,7 +33,7 @@
|
||||
[:i {:class "fa fa-cloud-download"}]]
|
||||
"Drop any invoices you want to process here"]]]])
|
||||
{:component-did-mount (fn [this]
|
||||
(js/Dropzone. (reagent/dom-node this)
|
||||
(js/Dropzone. (rdom/dom-node this)
|
||||
(clj->js {:init (fn []
|
||||
(.on (js-this) "success" (fn [_ files]
|
||||
(re-frame/dispatch [::invalidated])))
|
||||
|
||||
@@ -17,7 +17,8 @@
|
||||
[auto-ap.views.pages.transactions.manual :as manual]
|
||||
[auto-ap.views.utils :refer [bind-field date->str dispatch-event nf active-when]]
|
||||
[goog.string :as gstring]
|
||||
[re-frame.core :as re-frame]))
|
||||
[re-frame.core :as re-frame]
|
||||
[reagent.core :as reagent]))
|
||||
|
||||
|
||||
(re-frame/reg-sub
|
||||
@@ -38,30 +39,38 @@
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::params-change
|
||||
(fn [cofx [_ params]]
|
||||
{:db (-> (:db cofx)
|
||||
(assoc-in [:status :loading] true))
|
||||
:graphql {:token (-> cofx :db :user)
|
||||
:query-obj {:venia/queries [[:ledger-page
|
||||
@(re-frame/subscribe [::params])
|
||||
|
||||
[[:journal-entries [:id
|
||||
:source
|
||||
:amount
|
||||
:note
|
||||
:cleared-against
|
||||
[:vendor
|
||||
[:name :id]]
|
||||
[:client
|
||||
[:name :id]]
|
||||
[:line-items
|
||||
[:id :debit :credit :location
|
||||
[:account [:id :name]]]]
|
||||
:date]]
|
||||
:total
|
||||
:start
|
||||
:end]]]}
|
||||
:on-success [::received]}}))
|
||||
(fn [cofx [_]]
|
||||
(let [new-params @(re-frame/subscribe [::params])]
|
||||
(when (not= (::last-params (:db cofx)) new-params)
|
||||
{:db (-> (:db cofx)
|
||||
(assoc-in [::last-params] new-params)
|
||||
(assoc-in [:status :loading] true))
|
||||
:graphql {:token (-> cofx :db :user)
|
||||
:query-obj {:venia/queries [[:ledger-page
|
||||
new-params
|
||||
[[:journal-entries [:id
|
||||
:source
|
||||
:amount
|
||||
:note
|
||||
:cleared-against
|
||||
[:vendor
|
||||
[:name :id]]
|
||||
[:client
|
||||
[:name :id]]
|
||||
[:line-items
|
||||
[:id :debit :credit :location
|
||||
[:account [:id :name]]]]
|
||||
:date]]
|
||||
:total
|
||||
:start
|
||||
:end]]]}
|
||||
:on-success [::received]}}))))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::unmounted
|
||||
(fn [{:keys [db]} _]
|
||||
{:db (dissoc db ::last-params ::table/table-params ::side-bar/filters ::ledger-page)}))
|
||||
|
||||
|
||||
(re-frame/reg-event-db
|
||||
::received
|
||||
@@ -70,37 +79,27 @@
|
||||
(assoc ::ledger-page (:ledger-page data))
|
||||
(assoc-in [:status :loading] false))))
|
||||
|
||||
#_(re-frame/reg-event-db
|
||||
::change-selected-bank-account
|
||||
(fn [db [_ key value]]
|
||||
(let [[key] key
|
||||
updated (assoc-in db [::ledger-page :bank-account-filter key] value)]
|
||||
(if (and (= key :id)
|
||||
(not= value (get-in db [::params :bank-account-id])))
|
||||
(do
|
||||
(re-frame/dispatch [::params-change (assoc (::params updated) :bank-account-id value)])
|
||||
(assoc-in updated [::params :bank-account-id] value))
|
||||
updated))))
|
||||
|
||||
(def ledger-content
|
||||
|
||||
(with-meta
|
||||
(fn []
|
||||
(let [current-client @(re-frame/subscribe [::subs/client])
|
||||
user @(re-frame/subscribe [::subs/user])]
|
||||
[:div
|
||||
[:h1.title "Ledger"]
|
||||
[table/table {:id :ledger
|
||||
:params (re-frame/subscribe [::params])
|
||||
:ledger-page (re-frame/subscribe [::ledger-page])
|
||||
:status (re-frame/subscribe [::subs/status])
|
||||
:on-params-change (fn [params]
|
||||
(re-frame/dispatch [::params-change params]))}]
|
||||
[manual/modal {:import-completed [::manual-import-completed ]}]]))
|
||||
{:component-will-mount #(re-frame/dispatch-sync [::params-change {}]) }))
|
||||
(defn ledger-content []
|
||||
(let [current-client @(re-frame/subscribe [::subs/client])
|
||||
user @(re-frame/subscribe [::subs/user])]
|
||||
[:div
|
||||
[:h1.title "Ledger"]
|
||||
[table/table {:id :ledger
|
||||
:params (re-frame/subscribe [::params])
|
||||
:ledger-page (re-frame/subscribe [::ledger-page])
|
||||
:status (re-frame/subscribe [::subs/status])
|
||||
:on-params-change (fn [params]
|
||||
(re-frame/dispatch [::params-change params]))}]
|
||||
[manual/modal {:import-completed [::manual-import-completed ]}]]))
|
||||
|
||||
(defn ledger-page []
|
||||
[side-bar-layout
|
||||
{:side-bar [ledger-side-bar]
|
||||
:main [ledger-content]}])
|
||||
(reagent/create-class
|
||||
{:display-name "ledger-page"
|
||||
:component-did-mount #(re-frame/dispatch [::params-change {}])
|
||||
:component-will-unmount #(re-frame/dispatch [::unmounted])
|
||||
:reagent-render
|
||||
(fn []
|
||||
[side-bar-layout
|
||||
{:side-bar [ledger-side-bar]
|
||||
:main [ledger-content]}])}))
|
||||
|
||||
|
||||
@@ -155,8 +155,8 @@
|
||||
{:token (-> cofx :db :user)
|
||||
:query-obj {:venia/queries [[:profit-and-loss
|
||||
{:client-id (:id c)
|
||||
:from-date (:from-date params)
|
||||
:to-date (:to-date params)}
|
||||
:date-range {:start (:from-date params)
|
||||
:end (:to-date params)}}
|
||||
[[:balance-sheet-accounts [:name :amount :account-type :id :numeric-code :location]]
|
||||
[:comparable-balance-sheet-accounts [:name :amount :account-type :id :numeric-code :location]]]]]}
|
||||
:on-success [::received]
|
||||
@@ -219,14 +219,14 @@
|
||||
:from-numeric-code from-numeric-code
|
||||
:to-numeric-code to-numeric-code
|
||||
:location location
|
||||
:from-date (if (= :current which)
|
||||
(:from-date (::params db))
|
||||
(date->str (t/minus (str->date (:from-date (::params db)) standard) (t/years 1))
|
||||
standard))
|
||||
:to-date (if (= :current which)
|
||||
(:to-date (::params db))
|
||||
(date->str (t/minus (str->date (:to-date (::params db)) standard) (t/years 1))
|
||||
standard)))]}))
|
||||
:date-range {:start (if (= :current which)
|
||||
(:from-date (::params db))
|
||||
(date->str (t/minus (str->date (:from-date (::params db)) standard) (t/years 1))
|
||||
standard))
|
||||
:end (if (= :current which)
|
||||
(:to-date (::params db))
|
||||
(date->str (t/minus (str->date (:to-date (::params db)) standard) (t/years 1))
|
||||
standard))})]}))
|
||||
|
||||
(def groupings
|
||||
{:sales [["4000-4099 HQ Income" 4000 4099]
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
(:require [auto-ap.routes :as routes]
|
||||
[auto-ap.subs :as subs]
|
||||
[auto-ap.views.utils :refer [active-when]]
|
||||
[auto-ap.views.components.date-range-filter :refer [date-range-filter]]
|
||||
[auto-ap.views.components.bank-account-filter :refer [bank-account-filter]]
|
||||
[auto-ap.views.components.typeahead :refer [typeahead-entity]]
|
||||
[bidi.bidi :as bidi]
|
||||
[re-frame.core :as re-frame]))
|
||||
@@ -21,13 +23,20 @@
|
||||
::filter-params
|
||||
:<- [::filters]
|
||||
(fn [filters]
|
||||
{:vendor-id (:id (:vendor filters))}))
|
||||
{:vendor-id (:id (:vendor filters))
|
||||
:date-range (:date-range filters)
|
||||
:bank-account-id (:id (:bank-account filters))}))
|
||||
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::filter-changed
|
||||
(fn [{:keys [db]} [_ which val]]
|
||||
{:dispatch [:auto-ap.views.pages.ledger/params-change]
|
||||
:db (assoc-in db [::filters which] val)}))
|
||||
(fn [{:keys [db]} [_ & params]]
|
||||
(let [[a b c] params
|
||||
[which val] (if (= 3 (count params))
|
||||
[(into [a] b) c]
|
||||
[[a] b])]
|
||||
{:dispatch [:auto-ap.views.pages.ledger/params-change]
|
||||
:db (assoc-in db (into [::filters] which) val)})))
|
||||
|
||||
(defn ledger-side-bar []
|
||||
(let [ap @(re-frame/subscribe [::subs/active-page])
|
||||
@@ -60,10 +69,23 @@
|
||||
:class [(active-when ap = :external-import-ledger)]}
|
||||
[:span.icon [:i {:class "fa fa-download"}]]
|
||||
[:span {:class "name"} "External Import"]]])
|
||||
|
||||
[:p.menu-label "Bank Account"]
|
||||
[:div
|
||||
[bank-account-filter
|
||||
{:on-change-event [::filter-changed :bank-account]
|
||||
:value @(re-frame/subscribe [::filter :bank-account])
|
||||
:bank-accounts @(re-frame/subscribe [::subs/bank-accounts])}]]
|
||||
|
||||
[:p.menu-label "Vendor"]
|
||||
[:div
|
||||
[typeahead-entity {:matches @(re-frame/subscribe [::subs/vendors])
|
||||
:on-change #(re-frame/dispatch [::filter-changed :vendor %])
|
||||
:match->text :name
|
||||
:type "typeahead-entity"
|
||||
:value @(re-frame/subscribe [::filter :vendor])}]]]]))
|
||||
:value @(re-frame/subscribe [::filter :vendor])}]]
|
||||
[:p.menu-label "Date Range"]
|
||||
[:div
|
||||
[date-range-filter
|
||||
{:on-change-event [::filter-changed :date-range]
|
||||
:value @(re-frame/subscribe [::filter :date-range])}]]]]))
|
||||
|
||||
@@ -17,9 +17,7 @@
|
||||
[(re-frame/path [::table-params])]
|
||||
(fn [{table-params :db} [_ params :as z]]
|
||||
{:db (merge table-params params)
|
||||
:dispatch [:auto-ap.views.pages.ledger/params-change]}
|
||||
|
||||
))
|
||||
:dispatch [:auto-ap.views.pages.ledger/params-change]}))
|
||||
|
||||
(defn table [{:keys [id ledger-page status vendors params check-boxes checked on-check-changed expense-event]}]
|
||||
(fn [{:keys [id ledger-page status vendors checked status?]
|
||||
@@ -116,7 +114,8 @@
|
||||
|
||||
(when status?
|
||||
[:td status])]]
|
||||
(for [{:keys [debit credit location account]} line-items]
|
||||
(for [{:keys [debit credit location account id]} line-items]
|
||||
^{:key id}
|
||||
[:tr {:class (:class i)}
|
||||
(when-not selected-client
|
||||
[:td ])
|
||||
|
||||
Reference in New Issue
Block a user