filtering on ledger page.

This commit is contained in:
Bryce Covert
2020-04-28 07:49:53 -07:00
parent 1f649794eb
commit edc7d50661
10 changed files with 137 additions and 111 deletions

View File

@@ -110,7 +110,7 @@
org.eclipse.jetty.websocket/websocket-servlet
args4j]]]}
:provided {:dependencies [[org.clojure/clojurescript "1.10.339"]
[reagent "0.7.0" ]
[reagent "1.0.0-alpha1" ]
[cljsjs/react-datepicker "2.1.0-0"]
[cljsjs/react-transition-group "2.4.0-0"]
[re-frame "0.10.2"]

View File

@@ -41,17 +41,17 @@
'[?client-id :client/code ?client-code]]}
:args [(:client-code args)]})
(:to-date args)
(merge-query {:query {:in ['?to-date]
:where ['[?e :journal-entry/date ?d]
'[(<= ?d ?to-date)]]}
:args [(c/to-date (:to-date args))]})
(:start (:date-range args))
(merge-query {:query {:in ['?start-date]
:where ['[?e :journal-entry/date ?date]
'[(>= ?date ?start-date)]]}
:args [(c/to-date (:start (:date-range args)))]})
(:from-date args)
(merge-query {:query {:in ['?from-date]
:where ['[?e :journal-entry/date ?d]
'[(>= ?d ?from-date)]]}
:args [(c/to-date (:from-date args))]})
(:end (:date-range args))
(merge-query {:query {:in ['?end-date]
:where ['[?e :journal-entry/date ?date]
'[(<= ?date ?end-date)]]}
:args [(c/to-date (:end (:date-range args)))]})
(:from-numeric-code args)
(merge-query {:query {:in ['?from-numeric-code]
@@ -61,6 +61,12 @@
'[(>= ?c ?from-numeric-code)]]}
:args [(:from-numeric-code args)]})
(:bank-account-id args)
(merge-query {:query {:in ['?a]
:where ['[?e :journal-entry/line-items ?li]
'[?li :journal-entry-line/account ?a]]}
:args [(:bank-account-id args)]})
(:to-numeric-code args)
(merge-query {:query {:in ['?to-numeric-code]
:where ['[?e :journal-entry/line-items ?li]

View File

@@ -373,8 +373,7 @@
:profit_and_loss {:type :balance_sheet
:args {:client_id {:type :id}
:from_date {:type :iso_date}
:to_date {:type :iso_date}}
:date_range {:type :date_range}}
:resolve :get-profit-and-loss}
@@ -435,18 +434,17 @@
:resolve :get-transaction-rule-page}
:ledger_page {:type :ledger_page
:args {:client_id {:type :id}
:vendor_id {:type :id}
:bank_account_id {:type :id}
:from_date {:type :iso_date}
:to_date {:type :iso_date}
:location {:type 'String}
:from_numeric_code {:type 'Int}
:to_numeric_code {:type 'Int}
:start {:type 'Int}
:sort {:type '(list :sort_item)}}
:resolve :get-ledger-page}
:args {:client_id {:type :id}
:vendor_id {:type :id}
:bank_account_id {:type :id}
:date_range {:type :date_range}
:location {:type 'String}
:from_numeric_code {:type 'Int}
:to_numeric_code {:type 'Int}
:start {:type 'Int}
:sort {:type '(list :sort_item)}}
:resolve :get-ledger-page}
:payment_page {:type '(list :payment_page)
:args {:client_id {:type :id}

View File

@@ -88,7 +88,7 @@
(defn get-balance-sheet [context args value]
(let [args (assoc args :id (:id context))
[results] (l/get-graphql {:client-id (:client_id args)
:to-date (coerce/to-date (:date args))
:date-range {:end (coerce/to-date (:date args))}
:count Integer/MAX_VALUE})
@@ -105,12 +105,12 @@
pnl (fn [from-date to-date]
(println "FROM" from-date to-date)
(let [[starting-results] (l/get-graphql {:client-id (:client_id args)
:to-date (-> from-date
(time/minus (time/seconds 1))
coerce/to-date)
:date-range {:end (-> from-date
(time/minus (time/seconds 1))
coerce/to-date)}
:count Integer/MAX_VALUE})
[ending-results] (l/get-graphql {:client-id (:client_id args)
:to-date (coerce/to-date to-date)
:date-range {:end (coerce/to-date to-date)}
:count Integer/MAX_VALUE})
starting-accounts (by :id (roll-up starting-results))
ending-accounts (by :id (roll-up ending-results))]
@@ -122,10 +122,10 @@
[]
ending-accounts)))]
(->graphql
{:balance-sheet-accounts (pnl (coerce/to-date-time (:from_date args))
(coerce/to-date-time (:to_date args)))
:comparable-balance-sheet-accounts (pnl (time/minus (coerce/to-date-time (:from_date args)) (time/years 1))
(time/minus (coerce/to-date-time (:to_date args)) (time/years 1)))})))
{:balance-sheet-accounts (pnl (coerce/to-date-time (:start (:date_range args)))
(coerce/to-date-time (:end (:date_range args))))
:comparable-balance-sheet-accounts (pnl (time/minus (coerce/to-date-time (:start (:date_range args))) (time/years 1))
(time/minus (coerce/to-date-time (:end (:date_range args))) (time/years 1)))})))
#_(get-profit-and-loss nil {:client_id [:client/code "CBC"]
:from_date "2018-01-01"

View File

@@ -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 []

View File

@@ -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])))

View File

@@ -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]}])}))

View File

@@ -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]

View File

@@ -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])}]]]]))

View File

@@ -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 ])