makes balance sheet clickable.
This commit is contained in:
@@ -1,15 +1,31 @@
|
|||||||
(ns auto-ap.views.pages.ledger.balance-sheet
|
(ns auto-ap.views.pages.ledger.balance-sheet
|
||||||
(:require [auto-ap.subs :as subs]
|
(:require [auto-ap.subs :as subs]
|
||||||
[auto-ap.views.components.layouts :refer [side-bar-layout]]
|
[auto-ap.views.components.layouts :refer [side-bar-layout appearing-side-bar]]
|
||||||
[auto-ap.views.components.switch-field :refer [switch-field]]
|
[auto-ap.views.components.switch-field :refer [switch-field]]
|
||||||
|
[auto-ap.views.pages.ledger.table :as ledger-table ]
|
||||||
[goog.string :as gstring]
|
[goog.string :as gstring]
|
||||||
|
[vimsical.re-frame.fx.track :as track]
|
||||||
[auto-ap.utils :refer [by]]
|
[auto-ap.utils :refer [by]]
|
||||||
|
[auto-ap.views.pages.data-page :as data-page]
|
||||||
[auto-ap.views.pages.ledger.side-bar :refer [ledger-side-bar]]
|
[auto-ap.views.pages.ledger.side-bar :refer [ledger-side-bar]]
|
||||||
[auto-ap.views.utils :refer [date->str date-picker bind-field local-now standard ->$ str->date]]
|
[auto-ap.views.utils :refer [date->str date-picker bind-field local-now standard ->$ str->date dispatch-event with-user]]
|
||||||
[cljs-time.core :as t]
|
[cljs-time.core :as t]
|
||||||
[re-frame.core :as re-frame]
|
[re-frame.core :as re-frame]
|
||||||
|
[reagent.core :as reagent]
|
||||||
|
[clojure.set :as set]
|
||||||
[auto-ap.status :as status]))
|
[auto-ap.status :as status]))
|
||||||
|
|
||||||
|
(defn data-params->query-params [params]
|
||||||
|
(when params
|
||||||
|
{:start (:start params 0)
|
||||||
|
:sort (:sort params)
|
||||||
|
:per-page (:per-page 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)
|
||||||
|
:date-range (:date-range params)}))
|
||||||
|
|
||||||
(re-frame/reg-sub
|
(re-frame/reg-sub
|
||||||
::report
|
::report
|
||||||
(fn [db]
|
(fn [db]
|
||||||
@@ -48,7 +64,10 @@
|
|||||||
(= type account-type)))
|
(= type account-type)))
|
||||||
(by :id))))
|
(by :id))))
|
||||||
|
|
||||||
|
(re-frame/reg-sub
|
||||||
|
::ledger-list-active?
|
||||||
|
(fn [db]
|
||||||
|
(-> db ::ledger-list-active?)))
|
||||||
(def groupings
|
(def groupings
|
||||||
{:asset [["1100 Cash and Bank Accounts" 11000 11999]
|
{:asset [["1100 Cash and Bank Accounts" 11000 11999]
|
||||||
["1200 Accounts Receivable" 12000 12999]
|
["1200 Accounts Receivable" 12000 12999]
|
||||||
@@ -114,6 +133,63 @@
|
|||||||
:include-comparison
|
:include-comparison
|
||||||
include-comparison)]}))
|
include-comparison)]}))
|
||||||
|
|
||||||
|
(re-frame/reg-event-fx
|
||||||
|
::investigate-clicked
|
||||||
|
(fn [{:keys [db]} [_ from-numeric-code to-numeric-code which]]
|
||||||
|
(let [date (if (= :current which)
|
||||||
|
(get @(re-frame/subscribe [::params]) :date)
|
||||||
|
(date->str (t/minus (str->date (get @(re-frame/subscribe [::params]) :date) standard) (t/years 1)) standard))]
|
||||||
|
{:db (-> db (assoc ::ledger-list-active? true))
|
||||||
|
:dispatch [::data-page/additional-params-changed ::ledger {:client-id (:id @(re-frame/subscribe [::subs/client]))
|
||||||
|
:from-numeric-code from-numeric-code
|
||||||
|
:to-numeric-code to-numeric-code
|
||||||
|
:date-range {:start "2000-01-01"
|
||||||
|
:end date}}]})))
|
||||||
|
|
||||||
|
(re-frame/reg-event-fx
|
||||||
|
::ledger-params-change
|
||||||
|
[with-user]
|
||||||
|
(fn [{:keys [user db]} [_ ledger-params]]
|
||||||
|
|
||||||
|
(if (seq ledger-params)
|
||||||
|
{:graphql {:token user
|
||||||
|
:owns-state {:single [::data-page/page ::ledger]}
|
||||||
|
:query-obj {:venia/queries [[:ledger-page
|
||||||
|
{:filters (data-params->query-params ledger-params)}
|
||||||
|
[[:journal-entries [:id
|
||||||
|
:source
|
||||||
|
:original-entity
|
||||||
|
:amount
|
||||||
|
:alternate-description
|
||||||
|
[:vendor
|
||||||
|
[:name :id]]
|
||||||
|
[:client
|
||||||
|
[:name :id]]
|
||||||
|
[:line-items
|
||||||
|
[:id :debit :credit :location :running-balance
|
||||||
|
[:account [:id :name]]]]
|
||||||
|
:date]]
|
||||||
|
:total
|
||||||
|
:start
|
||||||
|
:end]]]}
|
||||||
|
:on-success (fn [result]
|
||||||
|
|
||||||
|
[::data-page/received ::ledger (set/rename-keys (:ledger-page result)
|
||||||
|
{:journal-entries :data})])}})))
|
||||||
|
|
||||||
|
(re-frame/reg-event-fx
|
||||||
|
::unmounted-balance-sheet
|
||||||
|
(fn [{:keys [db]} _]
|
||||||
|
{:dispatch [::data-page/dispose ::ledger]
|
||||||
|
::track/dispose {:id ::ledger-params}}))
|
||||||
|
|
||||||
|
(re-frame/reg-event-fx
|
||||||
|
::mounted-balance-sheet
|
||||||
|
(fn [{:keys [db]} _]
|
||||||
|
{::track/register {:id ::ledger-params
|
||||||
|
:subscription [::data-page/params ::ledger]
|
||||||
|
:event-fn (fn [params] [::ledger-params-change params])}}))
|
||||||
|
|
||||||
(defn grouping [{:keys [header accounts comparable-accounts groupings]}]
|
(defn grouping [{:keys [header accounts comparable-accounts groupings]}]
|
||||||
(let [include-comparison @(re-frame/subscribe [::include-comparison])]
|
(let [include-comparison @(re-frame/subscribe [::include-comparison])]
|
||||||
|
|
||||||
@@ -133,17 +209,21 @@
|
|||||||
]
|
]
|
||||||
(for [account matching-accounts]
|
(for [account matching-accounts]
|
||||||
[:tr [:td (:name account)]
|
[:tr [:td (:name account)]
|
||||||
[:td.has-text-right (->$ (:amount account))]
|
[:td.has-text-right [:a {:on-click (dispatch-event [::investigate-clicked (:numeric-code account) (:numeric-code account) :current])}
|
||||||
|
(->$ (:amount account))] ]
|
||||||
(when include-comparison
|
(when include-comparison
|
||||||
[:td.has-text-right (->$ (:amount (get comparable-accounts (:id account)) 0))])
|
[:td.has-text-right [:a {:on-click (dispatch-event [::investigate-clicked (:numeric-code account) (:numeric-code account) :comparable])}
|
||||||
|
(->$ (:amount (get comparable-accounts (:id account)) 0))]])
|
||||||
(when include-comparison
|
(when include-comparison
|
||||||
[:td.has-text-right (->$ (- (:amount account ) (:amount (get comparable-accounts (:id account)) 0)))])])
|
[:td.has-text-right (->$ (- (:amount account ) (:amount (get comparable-accounts (:id account)) 0)))])])
|
||||||
[:tr [:th "---" grouping-name "---"]
|
[:tr [:th "---" grouping-name "---"]
|
||||||
[:th.has-text-right.total (->$ (reduce + 0 (map :amount
|
[:th.has-text-right.total [:a {:on-click (dispatch-event [::investigate-clicked from to :current])}
|
||||||
matching-accounts))) ]
|
(->$ (reduce + 0 (map :amount
|
||||||
|
matching-accounts)))] ]
|
||||||
(when include-comparison
|
(when include-comparison
|
||||||
[:th.has-text-right.total (->$ (reduce + 0 (map #(:amount (get comparable-accounts (:id %)) 0)
|
[:th.has-text-right.total [:a {:on-click (dispatch-event [::investigate-clicked from to :comparable])}
|
||||||
matching-accounts)))])
|
(->$ (reduce + 0 (map #(:amount (get comparable-accounts (:id %)) 0)
|
||||||
|
matching-accounts)))]])
|
||||||
(when include-comparison
|
(when include-comparison
|
||||||
[:th.has-text-right.total (->$ (reduce + 0
|
[:th.has-text-right.total (->$ (reduce + 0
|
||||||
(map #(- (:amount % ) (:amount (get comparable-accounts (:id %)) 0))
|
(map #(- (:amount % ) (:amount (get comparable-accounts (:id %)) 0))
|
||||||
@@ -249,10 +329,27 @@
|
|||||||
{:component-will-mount #(re-frame/dispatch-sync [::params-change {:date (date->str (local-now) standard)
|
{:component-will-mount #(re-frame/dispatch-sync [::params-change {:date (date->str (local-now) standard)
|
||||||
:include-comparison true}]) }))
|
:include-comparison true}]) }))
|
||||||
|
|
||||||
|
(defn ledger-list [_ ]
|
||||||
|
[:div [:a.delete.is-pulled-right {:on-click (dispatch-event [::ledger-list-closing])}]
|
||||||
|
[:div
|
||||||
|
[:h1.title "Ledger entries"]
|
||||||
|
[ledger-table/table {:id :ledger
|
||||||
|
:data-page ::ledger}]]])
|
||||||
|
|
||||||
(defn balance-sheet-page []
|
(defn balance-sheet-page []
|
||||||
(let [user (re-frame/subscribe [::subs/user])]
|
(reagent/create-class
|
||||||
(if (not= "manager" (:user/role @user))
|
{:display-name "balance-sheet-page"
|
||||||
[side-bar-layout
|
:component-did-mount #(re-frame/dispatch [::mounted-balance-sheet])
|
||||||
{:side-bar [ledger-side-bar]
|
:component-will-unmount #(re-frame/dispatch [::unmounted-balance-sheet])
|
||||||
:main [balance-sheet-content]}]
|
:reagent-render
|
||||||
[:div "Not Authorized"])))
|
(fn []
|
||||||
|
(let [ledger-list-active? @(re-frame/subscribe [::ledger-list-active?])
|
||||||
|
user (re-frame/subscribe [::subs/user])]
|
||||||
|
(if (not= "manager" (:user/role @user))
|
||||||
|
[side-bar-layout
|
||||||
|
{:side-bar [ledger-side-bar]
|
||||||
|
:main [balance-sheet-content]
|
||||||
|
:right-side-bar [appearing-side-bar
|
||||||
|
{:visible? ledger-list-active?}
|
||||||
|
[ledger-list]]}]
|
||||||
|
[:div "Not authorized"])))}))
|
||||||
|
|||||||
Reference in New Issue
Block a user