bunch of small fixes. balance sheet has optional comparison and titles. trying to make payment unlinkable more easily.
This commit is contained in:
@@ -468,6 +468,7 @@
|
|||||||
:resolve :get-transaction-rule-matches}
|
:resolve :get-transaction-rule-matches}
|
||||||
:balance_sheet {:type :balance_sheet
|
:balance_sheet {:type :balance_sheet
|
||||||
:args {:client_id {:type :id}
|
:args {:client_id {:type :id}
|
||||||
|
:include_comparison {:type 'Boolean}
|
||||||
:date {:type :iso_date}}
|
:date {:type :iso_date}}
|
||||||
:resolve :get-balance-sheet}
|
:resolve :get-balance-sheet}
|
||||||
|
|
||||||
|
|||||||
@@ -180,10 +180,11 @@
|
|||||||
comparable-date (coerce/to-date (time/minus (:date args) (time/years 1)))
|
comparable-date (coerce/to-date (time/minus (:date args) (time/years 1)))
|
||||||
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)]
|
||||||
|
(log/info "Running balance sheet with " args)
|
||||||
|
|
||||||
(->graphql
|
(cond-> {:balance-sheet-accounts (roll-up-until lookup-account all-ledger-entries end-date)}
|
||||||
{:balance-sheet-accounts (roll-up-until lookup-account all-ledger-entries end-date)
|
(:include_comparison args) (assoc :comparable-balance-sheet-accounts (roll-up-until lookup-account all-ledger-entries comparable-date))
|
||||||
:comparable-balance-sheet-accounts (roll-up-until lookup-account all-ledger-entries comparable-date)})))
|
true ->graphql)))
|
||||||
|
|
||||||
(defn get-profit-and-loss [context args value]
|
(defn get-profit-and-loss [context args value]
|
||||||
(let [client-id (:client_id args)
|
(let [client-id (:client_id args)
|
||||||
|
|||||||
@@ -1,12 +1,14 @@
|
|||||||
(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]]
|
||||||
|
[auto-ap.views.components.switch-field :refer [switch-field]]
|
||||||
[goog.string :as gstring]
|
[goog.string :as gstring]
|
||||||
[auto-ap.utils :refer [by]]
|
[auto-ap.utils :refer [by]]
|
||||||
[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]]
|
||||||
[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]))
|
||||||
|
|
||||||
(re-frame/reg-sub
|
(re-frame/reg-sub
|
||||||
::report
|
::report
|
||||||
@@ -46,10 +48,6 @@
|
|||||||
(= type account-type)))
|
(= type account-type)))
|
||||||
(by :id))))
|
(by :id))))
|
||||||
|
|
||||||
(re-frame/reg-sub
|
|
||||||
::loading
|
|
||||||
(fn [db]
|
|
||||||
(-> db ::loading)))
|
|
||||||
|
|
||||||
(def groupings
|
(def groupings
|
||||||
{:asset [["1100 Cash and Bank Accounts" 11000 11999]
|
{:asset [["1100 Cash and Bank Accounts" 11000 11999]
|
||||||
@@ -73,20 +71,24 @@
|
|||||||
::received
|
::received
|
||||||
(fn [db [_ data]]
|
(fn [db [_ data]]
|
||||||
(-> db
|
(-> db
|
||||||
(assoc ::report (:balance-sheet data))
|
(assoc ::report (:balance-sheet data)))))
|
||||||
(assoc-in [::loading] false))))
|
|
||||||
|
|
||||||
(re-frame/reg-sub
|
(re-frame/reg-sub
|
||||||
::params
|
::params
|
||||||
(fn [db]
|
(fn [db]
|
||||||
(-> db ::params)))
|
(-> db ::params)))
|
||||||
|
|
||||||
|
(re-frame/reg-sub
|
||||||
|
::include-comparison
|
||||||
|
:<- [::params]
|
||||||
|
(fn [params]
|
||||||
|
(:include-comparison params)))
|
||||||
|
|
||||||
(re-frame/reg-event-fx
|
(re-frame/reg-event-fx
|
||||||
::params-change
|
::params-change
|
||||||
(fn [cofx [_ params]]
|
(fn [cofx [_ params]]
|
||||||
{:db (-> (:db cofx)
|
{:db (-> (:db cofx)
|
||||||
(assoc-in [::error] nil)
|
(dissoc ::report)
|
||||||
(assoc-in [::loading] true)
|
|
||||||
(assoc-in [::params] params))
|
(assoc-in [::params] params))
|
||||||
:graphql {:token (-> cofx :db :user)
|
:graphql {:token (-> cofx :db :user)
|
||||||
:query-obj {:venia/queries [[:balance-sheet
|
:query-obj {:venia/queries [[:balance-sheet
|
||||||
@@ -94,6 +96,8 @@
|
|||||||
:client-id (:id @(re-frame/subscribe [::subs/client])))
|
:client-id (:id @(re-frame/subscribe [::subs/client])))
|
||||||
[[:balance-sheet-accounts [:name :amount :account-type :id :numeric-code]]
|
[[:balance-sheet-accounts [:name :amount :account-type :id :numeric-code]]
|
||||||
[:comparable-balance-sheet-accounts [:name :amount :account-type :id :numeric-code]]]]]}
|
[:comparable-balance-sheet-accounts [:name :amount :account-type :id :numeric-code]]]]]}
|
||||||
|
|
||||||
|
:owns-state {:single ::page}
|
||||||
:on-success [::received]}}))
|
:on-success [::received]}}))
|
||||||
|
|
||||||
(re-frame/reg-event-fx
|
(re-frame/reg-event-fx
|
||||||
@@ -103,79 +107,104 @@
|
|||||||
:date
|
:date
|
||||||
date)]}))
|
date)]}))
|
||||||
|
|
||||||
|
(re-frame/reg-event-fx
|
||||||
|
::include-comparison-changed
|
||||||
|
(fn [cofx [_ include-comparison]]
|
||||||
|
{:dispatch [::params-change (assoc @(re-frame/subscribe [::params])
|
||||||
|
:include-comparison
|
||||||
|
include-comparison)]}))
|
||||||
|
|
||||||
(defn grouping [{:keys [header accounts comparable-accounts groupings]}]
|
(defn grouping [{:keys [header accounts comparable-accounts groupings]}]
|
||||||
|
(let [include-comparison @(re-frame/subscribe [::include-comparison])]
|
||||||
(for [[grouping-name from to] groupings
|
|
||||||
:let [matching-accounts (filter
|
(for [[grouping-name from to] groupings
|
||||||
#(<= from (:numeric-code %) to)
|
:let [matching-accounts (filter
|
||||||
accounts)]
|
#(<= from (:numeric-code %) to)
|
||||||
:when (seq matching-accounts)
|
accounts)]
|
||||||
|
:when (seq matching-accounts)
|
||||||
|
]
|
||||||
|
(list
|
||||||
|
[:tr [:th "---" grouping-name "---"]
|
||||||
|
[:td]
|
||||||
|
(when include-comparison
|
||||||
|
[:td])
|
||||||
|
(when include-comparison
|
||||||
|
[:td])
|
||||||
]
|
]
|
||||||
(list
|
(for [account matching-accounts]
|
||||||
[:tr [:th "---" grouping-name "---"]
|
[:tr [:td (:name account)]
|
||||||
[:td]
|
[:td.has-text-right (->$ (:amount account))]
|
||||||
[:td]
|
(when include-comparison
|
||||||
[:td]
|
[:td.has-text-right (->$ (:amount (get comparable-accounts (:id account)) 0))])
|
||||||
]
|
(when include-comparison
|
||||||
(for [account matching-accounts]
|
[:td.has-text-right (->$ (- (:amount account ) (:amount (get comparable-accounts (:id account)) 0)))])])
|
||||||
[:tr [:td (:name account)]
|
[:tr [:th "---" grouping-name "---"]
|
||||||
[:td.has-text-right (->$ (:amount account))]
|
[:th.has-text-right.total (->$ (reduce + 0 (map :amount
|
||||||
[:td.has-text-right (->$ (:amount (get comparable-accounts (:id account)) 0))]
|
matching-accounts))) ]
|
||||||
[:td.has-text-right (->$ (- (:amount account ) (:amount (get comparable-accounts (:id account)) 0)))]])
|
(when include-comparison
|
||||||
[:tr [:th "---" grouping-name "---"]
|
[:th.has-text-right.total (->$ (reduce + 0 (map #(:amount (get comparable-accounts (:id %)) 0)
|
||||||
[:th.has-text-right.total (->$ (reduce + 0 (map :amount
|
matching-accounts)))])
|
||||||
matching-accounts))) ]
|
(when include-comparison
|
||||||
[:th.has-text-right.total (->$ (reduce + 0 (map #(:amount (get comparable-accounts (:id %)) 0)
|
[:th.has-text-right.total (->$ (reduce + 0
|
||||||
matching-accounts)))]
|
(map #(- (:amount % ) (:amount (get comparable-accounts (:id %)) 0))
|
||||||
[:th.has-text-right.total (->$ (reduce + 0
|
matching-accounts)))])
|
||||||
(map #(- (:amount % ) (:amount (get comparable-accounts (:id %)) 0))
|
[:td]
|
||||||
matching-accounts)))]
|
]))))
|
||||||
[:td]
|
|
||||||
])))
|
|
||||||
|
|
||||||
(defn overall-grouping [type title]
|
(defn overall-grouping [type title]
|
||||||
(list
|
(let [include-comparison @(re-frame/subscribe [::include-comparison])]
|
||||||
[:tr [:th.has-text-centered title]
|
(list
|
||||||
[:td]
|
[:tr [:th.has-text-centered title]
|
||||||
[:td]
|
[:td]
|
||||||
[:td]]
|
(when include-comparison
|
||||||
(grouping {:accounts @(re-frame/subscribe [::accounts type])
|
[:td])
|
||||||
:groupings (type groupings)
|
(when include-comparison
|
||||||
:comparable-accounts @(re-frame/subscribe [::comparable-accounts-by-id type])
|
[:td])]
|
||||||
})
|
(grouping {:accounts @(re-frame/subscribe [::accounts type])
|
||||||
[:tr [:th.has-text-centered title]
|
:groupings (type groupings)
|
||||||
[:th.has-text-right (->$ (reduce + 0 (map :amount @(re-frame/subscribe [::accounts type]))))]
|
:comparable-accounts @(re-frame/subscribe [::comparable-accounts-by-id type])
|
||||||
[:th.has-text-right (->$ (reduce + 0 (map :amount (vals @(re-frame/subscribe [::comparable-accounts-by-id type])))))]
|
})
|
||||||
[:th.has-text-right (->$ (- (reduce + 0 (map :amount @(re-frame/subscribe [::accounts type])))
|
[:tr [:th.has-text-centered title]
|
||||||
(reduce + 0 (map :amount (vals @(re-frame/subscribe [::comparable-accounts-by-id type]))))))]]))
|
[:th.has-text-right (->$ (reduce + 0 (map :amount @(re-frame/subscribe [::accounts type]))))]
|
||||||
|
(when include-comparison
|
||||||
|
[:th.has-text-right (->$ (reduce + 0 (map :amount (vals @(re-frame/subscribe [::comparable-accounts-by-id type])))))])
|
||||||
|
(when include-comparison
|
||||||
|
[:th.has-text-right (->$ (- (reduce + 0 (map :amount @(re-frame/subscribe [::accounts type])))
|
||||||
|
(reduce + 0 (map :amount (vals @(re-frame/subscribe [::comparable-accounts-by-id type]))))))])])))
|
||||||
|
|
||||||
|
|
||||||
(defn retained-earnings []
|
(defn retained-earnings []
|
||||||
|
|
||||||
(list
|
(let [include-comparison @(re-frame/subscribe [::include-comparison])]
|
||||||
|
(list
|
||||||
#_(grouping {:accounts @(re-frame/subscribe [::accounts type])
|
|
||||||
:comparable-accounts @(re-frame/subscribe [::comparable-accounts-by-id type])
|
#_(grouping {:accounts @(re-frame/subscribe [::accounts type])
|
||||||
})
|
:comparable-accounts @(re-frame/subscribe [::comparable-accounts-by-id type])
|
||||||
[:tr [:th.has-text-centered "Retained Earnings"]
|
})
|
||||||
[:th.has-text-right (->$ (- (reduce + 0 (map :amount @(re-frame/subscribe [::accounts :revenue])))
|
[:tr [:th.has-text-centered "Retained Earnings"]
|
||||||
(reduce + 0 (map :amount @(re-frame/subscribe [::accounts :expense])))))]
|
[:th.has-text-right (->$ (- (reduce + 0 (map :amount @(re-frame/subscribe [::accounts :revenue])))
|
||||||
[:th.has-text-right (->$ (- (reduce + 0 (map :amount (vals @(re-frame/subscribe [::comparable-accounts-by-id :revenue]))))
|
(reduce + 0 (map :amount @(re-frame/subscribe [::accounts :expense])))))]
|
||||||
(reduce + 0 (map :amount (vals @(re-frame/subscribe [::comparable-accounts-by-id :expense]))))))]
|
(when include-comparison
|
||||||
[:th.has-text-right (->$ (- (- (reduce + 0 (map :amount @(re-frame/subscribe [::accounts :revenue])))
|
[:th.has-text-right (->$ (- (reduce + 0 (map :amount (vals @(re-frame/subscribe [::comparable-accounts-by-id :revenue]))))
|
||||||
(reduce + 0 (map :amount @(re-frame/subscribe [::accounts :expense]))))
|
(reduce + 0 (map :amount (vals @(re-frame/subscribe [::comparable-accounts-by-id :expense]))))))])
|
||||||
(- (reduce + 0 (map :amount (vals @(re-frame/subscribe [::comparable-accounts-by-id :revenue]))))
|
(when include-comparison
|
||||||
(reduce + 0 (map :amount (vals @(re-frame/subscribe [::comparable-accounts-by-id :expense])))))))]]))
|
[:th.has-text-right (->$ (- (- (reduce + 0 (map :amount @(re-frame/subscribe [::accounts :revenue])))
|
||||||
|
(reduce + 0 (map :amount @(re-frame/subscribe [::accounts :expense]))))
|
||||||
|
(- (reduce + 0 (map :amount (vals @(re-frame/subscribe [::comparable-accounts-by-id :revenue]))))
|
||||||
|
(reduce + 0 (map :amount (vals @(re-frame/subscribe [::comparable-accounts-by-id :expense])))))))])])))
|
||||||
|
|
||||||
(def balance-sheet-content
|
(def balance-sheet-content
|
||||||
(with-meta
|
(with-meta
|
||||||
(fn []
|
(fn []
|
||||||
(let [current-client @(re-frame/subscribe [::subs/client])
|
(let [current-client @(re-frame/subscribe [::subs/client])
|
||||||
|
status @(re-frame/subscribe [::status/single ::page])
|
||||||
user @(re-frame/subscribe [::subs/user])
|
user @(re-frame/subscribe [::subs/user])
|
||||||
params @(re-frame/subscribe [::params])]
|
params @(re-frame/subscribe [::params])]
|
||||||
(if current-client
|
(if current-client
|
||||||
[:div.is-inline
|
[:div.is-inline
|
||||||
[:h1.title "Balance Sheet"]
|
[:h1.title "Balance Sheet - " (:name current-client)]
|
||||||
|
[status/status-notification {:statuses [[::status/single ::page]]}]
|
||||||
|
|
||||||
[:div.report-controls
|
[:div.report-controls
|
||||||
[:p.help "Date"]
|
[:p.help "Date"]
|
||||||
[bind-field
|
[bind-field
|
||||||
@@ -190,28 +219,35 @@
|
|||||||
:field [:date]
|
:field [:date]
|
||||||
:event [::date-picked]
|
:event [::date-picked]
|
||||||
:popper-props (clj->js {:placement "right"})
|
:popper-props (clj->js {:placement "right"})
|
||||||
:subscription params}]]]
|
:subscription params}]]
|
||||||
(if @(re-frame/subscribe [::loading])
|
|
||||||
[:div [:i.icon.fa.fa-spin.fa-spinner]]
|
[switch-field {:id "include-comparison"
|
||||||
|
:checked (boolean (:include-comparison params))
|
||||||
|
:on-change (fn [e]
|
||||||
|
(re-frame/dispatch [::include-comparison-changed (.-checked (.-target e))]))
|
||||||
|
:label "Include comparison"
|
||||||
|
:type "checkbox"}]]
|
||||||
|
[status/big-loader status]
|
||||||
|
(when (not= :loading (:state status))
|
||||||
[:table.table.compact.balance-sheet
|
[:table.table.compact.balance-sheet
|
||||||
[:tr
|
[:tr
|
||||||
[:td.has-text-right "Period ending"]
|
[:td.has-text-right "Period ending"]
|
||||||
[:td.has-text-right (date->str (str->date (:date params) standard))]
|
(when (:include-comparison params)
|
||||||
[:td.has-text-right (when (:date params)
|
[:td.has-text-right (date->str (str->date (:date params) standard))])
|
||||||
(date->str (t/minus (str->date (:date params) standard) (t/years 1))))]
|
(when (:include-comparison params)
|
||||||
|
[:td.has-text-right (when (:date params)
|
||||||
|
(date->str (t/minus (str->date (:date params) standard) (t/years 1))))])
|
||||||
[:td]]
|
[:td]]
|
||||||
(list
|
(list
|
||||||
(overall-grouping :asset "Assets")
|
(overall-grouping :asset "Assets")
|
||||||
(overall-grouping :liability "Liabilities" )
|
(overall-grouping :liability "Liabilities" )
|
||||||
(overall-grouping :equity "Owner's Equity" )
|
(overall-grouping :equity "Owner's Equity" )
|
||||||
(retained-earnings))])
|
(retained-earnings))])]
|
||||||
|
|
||||||
|
|
||||||
]
|
|
||||||
[:div
|
[:div
|
||||||
[:h1.title "Balance sheet"]
|
[:h1.title "Balance sheet"]
|
||||||
[:h2.subtitle "Please choose a client first"]])))
|
[:h2.subtitle "Please choose a client first"]])))
|
||||||
{: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}]) }))
|
||||||
|
|
||||||
(defn balance-sheet-page []
|
(defn balance-sheet-page []
|
||||||
(let [user (re-frame/subscribe [::subs/user])]
|
(let [user (re-frame/subscribe [::subs/user])]
|
||||||
|
|||||||
@@ -235,6 +235,11 @@
|
|||||||
[:input.input {:type "text"
|
[:input.input {:type "text"
|
||||||
:field [:description-original]
|
:field [:description-original]
|
||||||
:disabled "disabled"}])
|
:disabled "disabled"}])
|
||||||
|
(when (and (:payment data)
|
||||||
|
is-admin?)
|
||||||
|
[:p.notification.is-info.is-light>div.level>div.level-left
|
||||||
|
[:div.level-item "This transaction is linked to a payment "]
|
||||||
|
[:div.level-item [:button.button.is-warning {:on-click (dispatch-event [::unlink])} "Unlink"]]])
|
||||||
|
|
||||||
(cond
|
(cond
|
||||||
(and (seq (:potential-transaction-rule-matches data))
|
(and (seq (:potential-transaction-rule-matches data))
|
||||||
@@ -289,11 +294,7 @@
|
|||||||
:type "typeahead-entity"
|
:type "typeahead-entity"
|
||||||
:field [:forecast-match]}])
|
:field [:forecast-match]}])
|
||||||
|
|
||||||
(when (and (:payment data)
|
|
||||||
is-admin?)
|
|
||||||
[:p.notification.is-info.is-light>div.level>div.level-left
|
|
||||||
[:div.level-item "This transaction is linked to a payment "]
|
|
||||||
[:div.level-item [:button.button.is-warning {:on-click (dispatch-event [::unlink])} "Unlink"]]])
|
|
||||||
|
|
||||||
|
|
||||||
(error-notification)
|
(error-notification)
|
||||||
|
|||||||
Reference in New Issue
Block a user