ledger page is working pretty good.
This commit is contained in:
@@ -159,7 +159,6 @@
|
|||||||
_ (assert-can-see-client (:id context) client-id)
|
_ (assert-can-see-client (:id context) client-id)
|
||||||
all-ledger-entries (full-ledger-for-client client-id)
|
all-ledger-entries (full-ledger-for-client client-id)
|
||||||
lookup-account (build-account-lookup client-id)]
|
lookup-account (build-account-lookup client-id)]
|
||||||
|
|
||||||
(->graphql
|
(->graphql
|
||||||
{:periods (reduce (fn [acc {:keys [start end]}]
|
{:periods (reduce (fn [acc {:keys [start end]}]
|
||||||
(conj acc
|
(conj acc
|
||||||
|
|||||||
@@ -137,3 +137,9 @@
|
|||||||
(do
|
(do
|
||||||
^{:key (:info state)}
|
^{:key (:info state)}
|
||||||
[:p (:info state)]))])]))
|
[:p (:info state)]))])]))
|
||||||
|
|
||||||
|
(defn big-loader [status]
|
||||||
|
(when (= :loading (:state status))
|
||||||
|
[:div.container
|
||||||
|
[:div.column.is-4.is-offset-4.has-text-centered
|
||||||
|
[:div.loader.is-loading.is-active.big.is-centered]]]))
|
||||||
|
|||||||
@@ -45,19 +45,26 @@
|
|||||||
(fn [db [_ which]]
|
(fn [db [_ which]]
|
||||||
(get-in db [::table-params which])))
|
(get-in db [::table-params which])))
|
||||||
|
|
||||||
|
(re-frame/reg-sub
|
||||||
|
::additional-params
|
||||||
|
(fn [db [_ which]]
|
||||||
|
(get-in db [::additional-params which])))
|
||||||
|
|
||||||
(re-frame/reg-sub
|
(re-frame/reg-sub
|
||||||
::params
|
::params
|
||||||
(fn [[_ id]]
|
(fn [[_ id]]
|
||||||
[(re-frame/subscribe [::subs/client])
|
[(re-frame/subscribe [::subs/client])
|
||||||
(re-frame/subscribe [::settled-filters id])
|
(re-frame/subscribe [::settled-filters id])
|
||||||
(re-frame/subscribe [::table-params id])])
|
(re-frame/subscribe [::table-params id])
|
||||||
(fn [[client filters table-params query-params]]
|
(re-frame/subscribe [::additional-params id])])
|
||||||
|
(fn [[client filters table-params additional-params]]
|
||||||
(let [query-params (auto-ap.views.utils/query-params)]
|
(let [query-params (auto-ap.views.utils/query-params)]
|
||||||
(cond-> {}
|
(cond-> {}
|
||||||
client (assoc :client-id (:id client))
|
client (assoc :client-id (:id client))
|
||||||
(seq query-params) (merge query-params)
|
(seq query-params) (merge query-params)
|
||||||
(seq filters) (merge filters)
|
(seq filters) (merge filters)
|
||||||
(seq table-params) (merge table-params)))))
|
(seq table-params) (merge table-params)
|
||||||
|
(seq additional-params) (merge additional-params)))))
|
||||||
|
|
||||||
(re-frame/reg-event-fx
|
(re-frame/reg-event-fx
|
||||||
::received
|
::received
|
||||||
@@ -109,6 +116,12 @@
|
|||||||
(fn [{:keys [db]} [_ which params :as z]]
|
(fn [{:keys [db]} [_ which params :as z]]
|
||||||
{:db (update-in db [::table-params which] merge params)}))
|
{:db (update-in db [::table-params which] merge params)}))
|
||||||
|
|
||||||
|
|
||||||
|
(re-frame/reg-event-fx
|
||||||
|
::additional-params-changed
|
||||||
|
(fn [{:keys [db]} [_ which params :as z]]
|
||||||
|
{:db (update-in db [::additional-params which] merge params)}))
|
||||||
|
|
||||||
(re-frame/reg-sub
|
(re-frame/reg-sub
|
||||||
::specific-filters
|
::specific-filters
|
||||||
(fn [db [_ id]]
|
(fn [db [_ id]]
|
||||||
|
|||||||
@@ -23,7 +23,6 @@
|
|||||||
[vimsical.re-frame.fx.track :as track]
|
[vimsical.re-frame.fx.track :as track]
|
||||||
[auto-ap.views.pages.data-page :as data-page]
|
[auto-ap.views.pages.data-page :as data-page]
|
||||||
[clojure.set :as set]))
|
[clojure.set :as set]))
|
||||||
|
|
||||||
(defn data-params->query-params [params]
|
(defn data-params->query-params [params]
|
||||||
{:start (:start params 0)
|
{:start (:start params 0)
|
||||||
:sort (:sort params)
|
:sort (:sort params)
|
||||||
@@ -35,6 +34,7 @@
|
|||||||
:amount-gte (:amount-gte (:amount-range params))
|
:amount-gte (:amount-gte (:amount-range params))
|
||||||
:amount-lte (:amount-lte (:amount-range params))})
|
:amount-lte (:amount-lte (:amount-range params))})
|
||||||
|
|
||||||
|
|
||||||
(re-frame/reg-event-fx
|
(re-frame/reg-event-fx
|
||||||
::params-change
|
::params-change
|
||||||
[with-user]
|
[with-user]
|
||||||
|
|||||||
@@ -9,7 +9,11 @@
|
|||||||
[auto-ap.views.utils :refer [date->str date-picker bind-field standard pretty dispatch-event local-today ->% ->$ str->date with-user]]
|
[auto-ap.views.utils :refer [date->str date-picker bind-field standard pretty dispatch-event local-today ->% ->$ str->date with-user]]
|
||||||
[cljs-time.core :as t]
|
[cljs-time.core :as t]
|
||||||
[re-frame.core :as re-frame]
|
[re-frame.core :as re-frame]
|
||||||
[auto-ap.status :as status]))
|
[auto-ap.status :as status]
|
||||||
|
[auto-ap.views.pages.data-page :as data-page]
|
||||||
|
[vimsical.re-frame.fx.track :as track]
|
||||||
|
[reagent.core :as reagent]
|
||||||
|
[clojure.set :as set]))
|
||||||
(def ranges
|
(def ranges
|
||||||
{:sales [40000 49999]
|
{:sales [40000 49999]
|
||||||
:cogs [50000 59999]
|
:cogs [50000 59999]
|
||||||
@@ -55,45 +59,6 @@
|
|||||||
(fn [db]
|
(fn [db]
|
||||||
(-> db ::ledger-list-active?)))
|
(-> db ::ledger-list-active?)))
|
||||||
|
|
||||||
(re-frame/reg-sub
|
|
||||||
::loading
|
|
||||||
(fn [db]
|
|
||||||
(-> db ::loading)))
|
|
||||||
|
|
||||||
(re-frame/reg-sub
|
|
||||||
::ledger-list-loading
|
|
||||||
(fn [db]
|
|
||||||
(-> db ::ledger-list-loading)))
|
|
||||||
|
|
||||||
(re-frame/reg-sub
|
|
||||||
::ledger-list
|
|
||||||
(fn [db]
|
|
||||||
(-> db ::ledger-list :ledger-page)))
|
|
||||||
|
|
||||||
(re-frame/reg-sub
|
|
||||||
::last-ledger-params
|
|
||||||
(fn [db]
|
|
||||||
(-> db ::last-ledger-params )))
|
|
||||||
|
|
||||||
(re-frame/reg-sub
|
|
||||||
::investigate-ledger-params
|
|
||||||
(fn [db]
|
|
||||||
(-> db ::investigate-ledger-params )))
|
|
||||||
|
|
||||||
(re-frame/reg-sub
|
|
||||||
::ledger-params
|
|
||||||
:<- [::last-ledger-params]
|
|
||||||
:<- [::subs/client]
|
|
||||||
:<- [::ledger-table/table-params]
|
|
||||||
:<- [::investigate-ledger-params]
|
|
||||||
(fn [[last-params client table-params investigate-ledger-params]]
|
|
||||||
(let [params (cond-> {}
|
|
||||||
client (assoc :client-id (:id client))
|
|
||||||
(seq table-params) (merge table-params)
|
|
||||||
(seq investigate-ledger-params) (merge investigate-ledger-params))]
|
|
||||||
(when (not= params last-params)
|
|
||||||
(re-frame/dispatch [::ledger-params-changed]))
|
|
||||||
params)))
|
|
||||||
|
|
||||||
(re-frame/reg-sub
|
(re-frame/reg-sub
|
||||||
::period-accounts
|
::period-accounts
|
||||||
@@ -140,9 +105,7 @@
|
|||||||
(re-frame/reg-event-db
|
(re-frame/reg-event-db
|
||||||
::received
|
::received
|
||||||
(fn [db [_ data]]
|
(fn [db [_ data]]
|
||||||
(-> db
|
(-> db (assoc ::report (:profit-and-loss data)))))
|
||||||
(assoc ::report (:profit-and-loss data))
|
|
||||||
(assoc-in [::loading] false))))
|
|
||||||
|
|
||||||
(re-frame/reg-sub
|
(re-frame/reg-sub
|
||||||
::params
|
::params
|
||||||
@@ -161,36 +124,23 @@
|
|||||||
(fn [db]
|
(fn [db]
|
||||||
(assoc db ::ledger-list-active? false)))
|
(assoc db ::ledger-list-active? false)))
|
||||||
|
|
||||||
(re-frame/reg-event-db
|
|
||||||
::error
|
|
||||||
(fn [db [_ [error]]]
|
|
||||||
(assoc db ::error (:message error)
|
|
||||||
::loading false)))
|
|
||||||
|
|
||||||
(re-frame/reg-event-db
|
|
||||||
::ledger-list-received
|
|
||||||
(fn [db [_ ledger-list]]
|
|
||||||
(assoc db
|
|
||||||
::ledger-list ledger-list
|
|
||||||
::ledger-list-loading false)))
|
|
||||||
|
|
||||||
(re-frame/reg-event-fx
|
(re-frame/reg-event-fx
|
||||||
::params-change
|
::params-change
|
||||||
(fn [cofx [_ params]]
|
(fn [cofx [_ params]]
|
||||||
(let [c @(re-frame/subscribe [::subs/client])]
|
(let [c @(re-frame/subscribe [::subs/client])]
|
||||||
(cond-> {:db (-> (:db cofx)
|
(cond-> {:db (-> (:db cofx)
|
||||||
(assoc-in [::error] nil)
|
(assoc-in [::params] params)
|
||||||
(assoc-in [::loading] true)
|
(dissoc ::report))}
|
||||||
(assoc-in [::params] params))}
|
|
||||||
c (assoc :graphql (when @(re-frame/subscribe [::subs/client])
|
c (assoc :graphql (when @(re-frame/subscribe [::subs/client])
|
||||||
{:token (-> cofx :db :user)
|
{:token (-> cofx :db :user)
|
||||||
|
:owns-state {:single ::page}
|
||||||
:query-obj {:venia/queries [[:profit-and-loss
|
:query-obj {:venia/queries [[:profit-and-loss
|
||||||
{:client-id (:id c)
|
{:client-id (:id c)
|
||||||
:periods (mapv (fn [[start end] ] {:start (date->str start standard) :end (date->str end standard)} )
|
:periods (mapv (fn [[start end] ] {:start (date->str start standard) :end (date->str end standard)} )
|
||||||
(:periods params))}
|
(:periods params))}
|
||||||
[[:periods [[:accounts [:name :amount :account-type :id :numeric-code :location]]]]]]]}
|
[[:periods [[:accounts [:name :amount :account-type :id :numeric-code :location]]]]]]]}
|
||||||
:on-success [::received]
|
:on-success [::received]}))))))
|
||||||
:on-error [::error]}))))))
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -211,19 +161,27 @@
|
|||||||
:db (assoc db ::periods periods)}))
|
:db (assoc db ::periods periods)}))
|
||||||
|
|
||||||
|
|
||||||
|
(defn data-params->query-params [params]
|
||||||
|
(when params
|
||||||
|
{:start (:start params 0)
|
||||||
|
:sort (:sort params)
|
||||||
|
:vendor-id (:id (:vendor params))
|
||||||
|
:client-id (:client-id params )
|
||||||
|
:from-numeric-code (:from-numeric-code params)
|
||||||
|
:to-numeric-code (:to-numeric-code params)
|
||||||
|
:location (:location params)
|
||||||
|
:date-range (:date-range params)}))
|
||||||
|
|
||||||
(re-frame/reg-event-fx
|
(re-frame/reg-event-fx
|
||||||
::ledger-params-changed
|
::ledger-params-change
|
||||||
[with-user (re-frame/inject-cofx ::inject/sub [::ledger-params])]
|
[with-user]
|
||||||
(fn [{:keys [user ::ledger-params db]} [_ ]]
|
(fn [{:keys [user db]} [_ ledger-params]]
|
||||||
|
|
||||||
(if (seq ledger-params)
|
(if (seq ledger-params)
|
||||||
{:db (assoc db
|
{:graphql {:token user
|
||||||
::ledger-list-loading true
|
:owns-state {:single [::data-page/page ::ledger]}
|
||||||
::last-ledger-params ledger-params)
|
|
||||||
:graphql {:token user
|
|
||||||
:owns-state {:single ::ledger-list}
|
|
||||||
:query-obj {:venia/queries [[:ledger-page
|
:query-obj {:venia/queries [[:ledger-page
|
||||||
ledger-params
|
(data-params->query-params ledger-params)
|
||||||
[[:journal-entries [:id
|
[[:journal-entries [:id
|
||||||
:source
|
:source
|
||||||
:amount
|
:amount
|
||||||
@@ -238,22 +196,22 @@
|
|||||||
:total
|
:total
|
||||||
:start
|
:start
|
||||||
:end]]]}
|
:end]]]}
|
||||||
:on-success [::ledger-list-received]}})))
|
:on-success (fn [result]
|
||||||
|
|
||||||
|
[::data-page/received ::ledger (set/rename-keys (:ledger-page result)
|
||||||
|
{:journal-entries :data})])}})))
|
||||||
|
|
||||||
(re-frame/reg-event-db
|
(re-frame/reg-event-fx
|
||||||
::investigate-clicked
|
::investigate-clicked
|
||||||
(fn [db [_ location from-numeric-code to-numeric-code which]]
|
(fn [{:keys [db]} [_ location from-numeric-code to-numeric-code which]]
|
||||||
(let [[from to] (get @(re-frame/subscribe [::periods]) which)]
|
(let [[from to] (get @(re-frame/subscribe [::periods]) which)]
|
||||||
(-> db
|
{:db (-> db (assoc ::ledger-list-active? true))
|
||||||
(assoc
|
:dispatch [::data-page/additional-params-changed ::ledger {:client-id (:id @(re-frame/subscribe [::subs/client]))
|
||||||
::ledger-list-active? true
|
:from-numeric-code from-numeric-code
|
||||||
::ledger-list-loading true
|
:to-numeric-code to-numeric-code
|
||||||
::investigate-ledger-params {:client-id (:id @(re-frame/subscribe [::subs/client]))
|
:location location
|
||||||
:from-numeric-code from-numeric-code
|
:date-range {:start (date->str from standard)
|
||||||
:to-numeric-code to-numeric-code
|
:end (date->str to standard)}}]})))
|
||||||
:location location
|
|
||||||
:date-range {:start (date->str from standard)
|
|
||||||
:end (date->str to standard)}})))))
|
|
||||||
|
|
||||||
(def groupings
|
(def groupings
|
||||||
{:sales [["40000-43999 Food Sales " 40000 43999]
|
{:sales [["40000-43999 Food Sales " 40000 43999]
|
||||||
@@ -474,7 +432,7 @@
|
|||||||
(fn []
|
(fn []
|
||||||
(let [current-client @(re-frame/subscribe [::subs/client])
|
(let [current-client @(re-frame/subscribe [::subs/client])
|
||||||
user @(re-frame/subscribe [::subs/user])
|
user @(re-frame/subscribe [::subs/user])
|
||||||
error @(re-frame/subscribe [::error])
|
status @(re-frame/subscribe [::status/single ::page])
|
||||||
params @(re-frame/subscribe [::params])
|
params @(re-frame/subscribe [::params])
|
||||||
periods @(re-frame/subscribe [::periods])]
|
periods @(re-frame/subscribe [::periods])]
|
||||||
|
|
||||||
@@ -485,6 +443,7 @@
|
|||||||
|
|
||||||
[:div
|
[:div
|
||||||
[:h1.title "Profit and Loss"]
|
[:h1.title "Profit and Loss"]
|
||||||
|
[status/status-notification {:statuses [[::status/single ::page]]}]
|
||||||
[:div.report-controls
|
[:div.report-controls
|
||||||
[:h2.title.is-4 "Range"]
|
[:h2.title.is-4 "Range"]
|
||||||
[:div
|
[:div
|
||||||
@@ -604,63 +563,66 @@
|
|||||||
:event [::date-picked]
|
:event [::date-picked]
|
||||||
:popper-props (clj->js {:placement "right"})
|
:popper-props (clj->js {:placement "right"})
|
||||||
:subscription params}]]]])]
|
:subscription params}]]]])]
|
||||||
(cond
|
[status/big-loader status]
|
||||||
error
|
[:div
|
||||||
[:div.notification.is-warning error]
|
[:<>
|
||||||
|
(for [location @(re-frame/subscribe [::locations])]
|
||||||
@(re-frame/subscribe [::loading])
|
^{:key (str location "-summary")}
|
||||||
[:div [:i.icon.fa.fa-spin.fa-spinner]]
|
[location-summary location params]
|
||||||
|
)]
|
||||||
:else
|
[:h2.title.is-4 {:style {:margin-bottom "1rem"}} "Detail"]
|
||||||
[:div
|
[:table.table.compact.balance-sheet
|
||||||
|
[:tbody
|
||||||
|
[:tr
|
||||||
|
[:td.has-text-right "Period Ending"]
|
||||||
|
(map-periods
|
||||||
|
(fn [i]
|
||||||
|
[:<>
|
||||||
|
[:td.has-text-right (date->str (get-in periods [i 1]))]
|
||||||
|
[:td]])
|
||||||
|
(fn [i]
|
||||||
|
[:td.has-text-right "𝝙"])
|
||||||
|
periods)]
|
||||||
[:<>
|
[:<>
|
||||||
(for [location @(re-frame/subscribe [::locations])]
|
(for [location @(re-frame/subscribe [::locations])]
|
||||||
^{:key (str location "-summary")}
|
^{:key location}
|
||||||
[location-summary location params]
|
[location-rows location]
|
||||||
)]
|
)]]]]])))
|
||||||
[:h2.title.is-4 {:style {:margin-bottom "1rem"}} "Detail"]
|
|
||||||
[:table.table.compact.balance-sheet
|
|
||||||
[:tbody
|
|
||||||
[:tr
|
|
||||||
[:td.has-text-right "Period Ending"]
|
|
||||||
(map-periods
|
|
||||||
(fn [i]
|
|
||||||
[:<>
|
|
||||||
[:td.has-text-right (date->str (get-in periods [i 1]))]
|
|
||||||
[:td]])
|
|
||||||
(fn [i]
|
|
||||||
[:td.has-text-right "𝝙"])
|
|
||||||
periods)]
|
|
||||||
[:<>
|
|
||||||
(for [location @(re-frame/subscribe [::locations])]
|
|
||||||
^{:key location}
|
|
||||||
[location-rows location]
|
|
||||||
)]]]])])))
|
|
||||||
{:component-will-mount #(do (re-frame/dispatch-sync [::range-selected (and-last-year [(t/minus (local-today) (t/period :years 1)) (local-today)]) nil])) }))
|
{:component-will-mount #(do (re-frame/dispatch-sync [::range-selected (and-last-year [(t/minus (local-today) (t/period :years 1)) (local-today)]) nil])) }))
|
||||||
|
|
||||||
|
(re-frame/reg-event-fx
|
||||||
|
::unmounted
|
||||||
|
(fn [{:keys [db]} _]
|
||||||
|
{::track/dispose {:id ::ledger-params}}))
|
||||||
|
|
||||||
|
(re-frame/reg-event-fx
|
||||||
|
::mounted
|
||||||
|
(fn [{:keys [db]} _]
|
||||||
|
{::track/register {:id ::ledger-params
|
||||||
|
:subscription [::data-page/params ::ledger]
|
||||||
|
:event-fn (fn [params] [::ledger-params-change params])}}))
|
||||||
|
|
||||||
(defn ledger-list [_ ]
|
(defn ledger-list [_ ]
|
||||||
(let [ledger-page (re-frame/subscribe [::ledger-list])]
|
[:div [:a.delete.is-pulled-right {:on-click (dispatch-event [::ledger-list-closing])}]
|
||||||
[:div [:a.delete.is-pulled-right {:on-click (dispatch-event [::ledger-list-closing])}]
|
[:div
|
||||||
[:div
|
[:h1.title "Ledger entries"]
|
||||||
[:h1.title "Ledger entries"]
|
[ledger-table/table {:id :ledger
|
||||||
[ledger-table/table {:id :ledger
|
:data-page ::ledger}]]])
|
||||||
:ledger-page @ledger-page
|
|
||||||
:status @(re-frame/subscribe [::status/single ::ledger-list])
|
|
||||||
:params (re-frame/subscribe [::ledger-params])
|
|
||||||
:on-params-change (fn [params]
|
|
||||||
(re-frame/dispatch [::ledger-params-changed params]))}]]]))
|
|
||||||
|
|
||||||
(defn profit-and-loss-page []
|
(defn profit-and-loss-page []
|
||||||
(let [ledger-list-active? @(re-frame/subscribe [::ledger-list-active?])
|
(reagent/create-class
|
||||||
user (re-frame/subscribe [::subs/user])
|
{:display-name "profit-and-loss-page"
|
||||||
ledger-params @(re-frame/subscribe [::ledger-params])]
|
:component-did-mount #(re-frame/dispatch [::mounted])
|
||||||
(if (not= "manager" (:user/role @user))
|
:component-will-unmount #(re-frame/dispatch [::unmounted])
|
||||||
[side-bar-layout
|
:reagent-render
|
||||||
{:side-bar [ledger-side-bar]
|
(fn []
|
||||||
:main [profit-and-loss-content]
|
(let [ledger-list-active? @(re-frame/subscribe [::ledger-list-active?])
|
||||||
:right-side-bar [appearing-side-bar
|
user (re-frame/subscribe [::subs/user])]
|
||||||
{:visible? ledger-list-active?}
|
(if (not= "manager" (:user/role @user))
|
||||||
[ledger-list]]}]
|
[side-bar-layout
|
||||||
[:div "Not authorized"])))
|
{:side-bar [ledger-side-bar]
|
||||||
|
:main [profit-and-loss-content]
|
||||||
|
:right-side-bar [appearing-side-bar
|
||||||
|
{:visible? ledger-list-active?}
|
||||||
|
[ledger-list]]}]
|
||||||
|
[:div "Not authorized"])))}))
|
||||||
|
|||||||
Reference in New Issue
Block a user