fixing percentages.
This commit is contained in:
@@ -41,6 +41,7 @@
|
|||||||
first
|
first
|
||||||
first
|
first
|
||||||
(update :user/role :db/ident))]
|
(update :user/role :db/ident))]
|
||||||
|
(println "USER" user)
|
||||||
(if user
|
(if user
|
||||||
user
|
user
|
||||||
(let [new-user-trans @(d/transact (d/connect uri) [(cond-> new-user
|
(let [new-user-trans @(d/transact (d/connect uri) [(cond-> new-user
|
||||||
|
|||||||
@@ -127,7 +127,7 @@
|
|||||||
:transaction/payment (:db/id payment)
|
:transaction/payment (:db/id payment)
|
||||||
:transaction/vendor (:db/id (:payment/vendor payment))
|
:transaction/vendor (:db/id (:payment/vendor payment))
|
||||||
:transaction/location "A"
|
:transaction/location "A"
|
||||||
:transaction/accounts [{:transaction-account/account (:db/id (a/get-account-by-numeric-code-and-sets 2110 ["default"]))
|
:transaction/accounts [{:transaction-account/account (:db/id (a/get-account-by-numeric-code-and-sets 21000 ["default"]))
|
||||||
:transaction-account/location "A"
|
:transaction-account/location "A"
|
||||||
:transaction-account/amount (Math/abs (:transaction/amount transaction))}]}]
|
:transaction-account/amount (Math/abs (:transaction/amount transaction))}]}]
|
||||||
(map (fn [x] [:db/retractEntity (:db/id x)] )
|
(map (fn [x] [:db/retractEntity (:db/id x)] )
|
||||||
|
|||||||
@@ -81,7 +81,9 @@
|
|||||||
valid-locations (or (:bank-account/locations bank-account) (:client/locations client))
|
valid-locations (or (:bank-account/locations bank-account) (:client/locations client))
|
||||||
check (transaction->payment transaction check-number client-id bank-account-id amount id)]
|
check (transaction->payment transaction check-number client-id bank-account-id amount id)]
|
||||||
:when (and client-id
|
:when (and client-id
|
||||||
(not (existing (sha-256 (str id)))))]
|
(not (existing (sha-256 (str id))))
|
||||||
|
(= "POSTED" status)
|
||||||
|
)]
|
||||||
(->
|
(->
|
||||||
#:transaction
|
#:transaction
|
||||||
{:post-date (coerce/to-date (time/parse post-date "YYYY-MM-dd"))
|
{:post-date (coerce/to-date (time/parse post-date "YYYY-MM-dd"))
|
||||||
@@ -94,7 +96,9 @@
|
|||||||
:amount (double amount)
|
:amount (double amount)
|
||||||
:description-original description-original
|
:description-original description-original
|
||||||
:description-simple description-simple
|
:description-simple description-simple
|
||||||
:approval-status :transaction-approval-status/unapproved
|
:approval-status (if check
|
||||||
|
:transaction-approval-status/approved
|
||||||
|
:transaction-approval-status/unapproved)
|
||||||
:type type
|
:type type
|
||||||
:status status
|
:status status
|
||||||
:client client-id
|
:client client-id
|
||||||
|
|||||||
@@ -242,8 +242,8 @@
|
|||||||
[]
|
[]
|
||||||
rows)]
|
rows)]
|
||||||
|
|
||||||
#_txes
|
txes
|
||||||
@(d/transact conn txes)))
|
#_@(d/transact conn txes)))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
[goog.string :as gstring]
|
[goog.string :as gstring]
|
||||||
[auto-ap.utils :refer [dollars-0? by ]]
|
[auto-ap.utils :refer [dollars-0? 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 standard dispatch-event local-now ->$ str->date]]
|
[auto-ap.views.utils :refer [date->str date-picker bind-field standard dispatch-event local-now ->% ->$ str->date]]
|
||||||
[cljs-time.core :as t]
|
[cljs-time.core :as t]
|
||||||
[re-frame.core :as re-frame]))
|
[re-frame.core :as re-frame]))
|
||||||
(def ranges
|
(def ranges
|
||||||
@@ -84,6 +84,30 @@
|
|||||||
(<= (get-in ranges [type 0]) numeric-code (get-in ranges [type 1])))))
|
(<= (get-in ranges [type 0]) numeric-code (get-in ranges [type 1])))))
|
||||||
(sort-by :numeric-code))))
|
(sort-by :numeric-code))))
|
||||||
|
|
||||||
|
(re-frame/reg-sub
|
||||||
|
::amount
|
||||||
|
(fn [[_ type only-location]]
|
||||||
|
[(re-frame/subscribe [::accounts type only-location])])
|
||||||
|
(fn [[accounts] _]
|
||||||
|
(reduce + 0 (map :amount accounts))))
|
||||||
|
|
||||||
|
(re-frame/reg-sub
|
||||||
|
::comparable-amount
|
||||||
|
(fn [[_ type only-location]]
|
||||||
|
[(re-frame/subscribe [::comparable-accounts-by-id type only-location])])
|
||||||
|
(fn [[accounts] _]
|
||||||
|
(reduce + 0 (map :amount (vals accounts)))))
|
||||||
|
|
||||||
|
(re-frame/reg-sub
|
||||||
|
::comparable-percent-of-sales
|
||||||
|
(fn [[_ type only-location]]
|
||||||
|
[(re-frame/subscribe [::comparable-amount :sales only-location])
|
||||||
|
(re-frame/subscribe [::comparable-amount type only-location])])
|
||||||
|
(fn [[sales accounts] _]
|
||||||
|
(if (> (or sales 0) 0 )
|
||||||
|
(/ accounts sales)
|
||||||
|
0.0)))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -268,38 +292,55 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
(defn grouping [{:keys [header accounts comparable-accounts groupings location]}]
|
(defn grouping [{:keys [header accounts comparable-accounts groupings location sales comparable-sales]}]
|
||||||
(for [[grouping-name from to] groupings
|
(for [[grouping-name from to] groupings
|
||||||
:let [matching-accounts (filter
|
:let [matching-accounts (filter
|
||||||
#(<= from (:numeric-code %) to)
|
#(<= from (:numeric-code %) to)
|
||||||
accounts)]
|
accounts)
|
||||||
|
total (reduce + 0 (map :amount matching-accounts))
|
||||||
|
comparable-total (reduce + 0 (map #(:amount (get comparable-accounts (:id %)) 0) matching-accounts))]
|
||||||
:when (seq matching-accounts)
|
:when (seq matching-accounts)
|
||||||
]
|
]
|
||||||
(list
|
(list
|
||||||
|
^{:key "title"}
|
||||||
[:tr [:th "---" grouping-name "---"]
|
[:tr [:th "---" grouping-name "---"]
|
||||||
|
[:td]
|
||||||
|
[:td]
|
||||||
[:td]
|
[:td]
|
||||||
[:td]
|
[:td]
|
||||||
[:td]
|
[:td]
|
||||||
]
|
]
|
||||||
|
^{:key "detail"}
|
||||||
(for [account matching-accounts]
|
(for [account matching-accounts]
|
||||||
|
^{:key (:name account)}
|
||||||
[:tr [:td (:name account)]
|
[:tr [:td (:name account)]
|
||||||
[:td.has-text-right [:a {:on-click (dispatch-event [::investigate-clicked location (:numeric-code account) (:numeric-code account) :current])}
|
[:td.has-text-right [:a {:on-click (dispatch-event [::investigate-clicked location (:numeric-code account) (:numeric-code account) :current])}
|
||||||
(->$ (:amount account))]]
|
(->$ (:amount account))]]
|
||||||
|
[:td.has-text-right (->% (if (> sales 0)
|
||||||
|
(/ (:amount account) sales)
|
||||||
|
0.0))]
|
||||||
[:td.has-text-right [:a {:on-click (dispatch-event [::investigate-clicked location (:numeric-code account) (:numeric-code account) :comparable])}
|
[:td.has-text-right [:a {:on-click (dispatch-event [::investigate-clicked location (:numeric-code account) (:numeric-code account) :comparable])}
|
||||||
(->$ (:amount (get comparable-accounts (:id account)) 0))]]
|
(->$ (:amount (get comparable-accounts (:id account)) 0))]]
|
||||||
|
[:td.has-text-right (->% (if (> comparable-sales 0)
|
||||||
|
(/ (:amount (get comparable-accounts (:id account)) 0) sales)
|
||||||
|
0.0))]
|
||||||
[: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)))]])
|
||||||
|
|
||||||
|
^{:key "total"}
|
||||||
[:tr [:th "---" grouping-name "---"]
|
[:tr [:th "---" grouping-name "---"]
|
||||||
[:th.has-text-right.total [:a
|
[:th.has-text-right.total [:a
|
||||||
{:on-click (dispatch-event [::investigate-clicked location from to :current])}
|
{:on-click (dispatch-event [::investigate-clicked location from to :current])}
|
||||||
(->$ (reduce + 0 (map :amount
|
(->$ total)] ]
|
||||||
matching-accounts)))] ]
|
[:th.has-text-right.total (->% (if (> sales 0)
|
||||||
|
(/ total sales)
|
||||||
|
0.0))]
|
||||||
[:th.has-text-right.total [:a
|
[:th.has-text-right.total [:a
|
||||||
{:on-click (dispatch-event [::investigate-clicked location from to :comparable])}
|
{:on-click (dispatch-event [::investigate-clicked location from to :comparable])}
|
||||||
(->$ (reduce + 0 (map #(:amount (get comparable-accounts (:id %)) 0)
|
(->$ comparable-total)]]
|
||||||
matching-accounts)))]]
|
[:th.has-text-right.total (->% (if (> comparable-sales 0)
|
||||||
[:th.has-text-right.total (->$ (reduce + 0
|
(/ comparable-total sales)
|
||||||
(map #(- (:amount % ) (:amount (get comparable-accounts (:id %)) 0))
|
0.0))]
|
||||||
matching-accounts)))]
|
[:th.has-text-right.total (->$ (- total comparable-total))]
|
||||||
[:td]
|
[:td]
|
||||||
])))
|
])))
|
||||||
|
|
||||||
@@ -308,24 +349,32 @@
|
|||||||
min-numeric-code (or (first (map :numeric-code accounts)) 0)
|
min-numeric-code (or (first (map :numeric-code accounts)) 0)
|
||||||
max-numeric-code (or (last (map :numeric-code accounts)) 0)]
|
max-numeric-code (or (last (map :numeric-code accounts)) 0)]
|
||||||
(list
|
(list
|
||||||
|
^{:key "title"}
|
||||||
[:tr [:th.has-text-centered title]
|
[:tr [:th.has-text-centered title]
|
||||||
[:td]
|
[:td]
|
||||||
[:td]
|
[:td]
|
||||||
[:td]]
|
[:td]]
|
||||||
|
|
||||||
|
^{:key "grouping"}
|
||||||
(grouping {:accounts accounts
|
(grouping {:accounts accounts
|
||||||
:location location
|
:location location
|
||||||
:groupings (type groupings)
|
:groupings (type groupings)
|
||||||
:comparable-accounts @(re-frame/subscribe [::comparable-accounts-by-id type location])
|
:comparable-accounts @(re-frame/subscribe [::comparable-accounts-by-id type location])
|
||||||
})
|
:sales @(re-frame/subscribe [::amount :sales location])
|
||||||
|
:comparable-sales @(re-frame/subscribe [::comparable-amount :sales location])})
|
||||||
|
|
||||||
|
^{:key "total"}
|
||||||
[:tr [:th.has-text-centered title]
|
[:tr [:th.has-text-centered title]
|
||||||
[:th.has-text-right [:a
|
[:th.has-text-right [:a
|
||||||
{:on-click (dispatch-event [::investigate-clicked location min-numeric-code max-numeric-code :current])}
|
{:on-click (dispatch-event [::investigate-clicked location min-numeric-code max-numeric-code :current])}
|
||||||
(->$ (reduce + 0 (map :amount @(re-frame/subscribe [::accounts type location]))))]]
|
(->$ @(re-frame/subscribe [::amount type location]))]]
|
||||||
|
[:th.has-text-right (->% @(re-frame/subscribe [::percent-of-sales type location]))]
|
||||||
[:th.has-text-right [:a
|
[:th.has-text-right [:a
|
||||||
{:on-click (dispatch-event [::investigate-clicked location min-numeric-code max-numeric-code :comparable])}
|
{:on-click (dispatch-event [::investigate-clicked location min-numeric-code max-numeric-code :comparable])}
|
||||||
(->$ (reduce + 0 (map :amount (vals @(re-frame/subscribe [::comparable-accounts-by-id type location])))))]]
|
(->$ @(re-frame/subscribe [::comparable-amount type location]))]]
|
||||||
[:th.has-text-right (->$ (- (reduce + 0 (map :amount @(re-frame/subscribe [::accounts type location])))
|
[:th.has-text-right (->% @(re-frame/subscribe [::comparable-percent-of-sales type location]))]
|
||||||
(reduce + 0 (map :amount (vals @(re-frame/subscribe [::comparable-accounts-by-id type location]))))))]])))
|
[:th.has-text-right (->$ (- @(re-frame/subscribe [::amount type location])
|
||||||
|
@(re-frame/subscribe [::comparable-amount type location])))]])))
|
||||||
|
|
||||||
(defn subtotal [types negs title location]
|
(defn subtotal [types negs title location]
|
||||||
(let [accounts (transduce (comp
|
(let [accounts (transduce (comp
|
||||||
@@ -348,17 +397,26 @@
|
|||||||
[]
|
[]
|
||||||
types)
|
types)
|
||||||
min-numeric-code (or (first (map :numeric-code accounts)) 0)
|
min-numeric-code (or (first (map :numeric-code accounts)) 0)
|
||||||
max-numeric-code (or (last (map :numeric-code accounts)) 0)]
|
max-numeric-code (or (last (map :numeric-code accounts)) 0)
|
||||||
(list
|
sales @(re-frame/subscribe [::amount :sales location])
|
||||||
[:tr [:th.has-text-centered title]
|
comparable-sales @(re-frame/subscribe [::comparable-amount :sales location])]
|
||||||
[:th.has-text-right [:a
|
[:tr [:th.has-text-centered title]
|
||||||
{:on-click (dispatch-event [::investigate-clicked location min-numeric-code max-numeric-code :current])}
|
[:td.has-text-right [:a
|
||||||
(->$ (reduce + 0 (map :amount accounts)))]]
|
{:on-click (dispatch-event [::investigate-clicked location min-numeric-code max-numeric-code :current])}
|
||||||
[:th.has-text-right [:a
|
(->$ (reduce + 0 (map :amount accounts)))]]
|
||||||
{:on-click (dispatch-event [::investigate-clicked location min-numeric-code max-numeric-code :comparable])}
|
[:td.has-text-right (->% (if (> sales 0)
|
||||||
(->$ (reduce + 0 (map :amount comparable)))]]
|
(/ (reduce + 0 (map :amount accounts))
|
||||||
[:th.has-text-right (->$ (- (reduce + 0 (map :amount accounts))
|
sales)
|
||||||
(reduce + 0 (map :amount comparable))))]])))
|
0))]
|
||||||
|
[:td.has-text-right [:a
|
||||||
|
{:on-click (dispatch-event [::investigate-clicked location min-numeric-code max-numeric-code :comparable])}
|
||||||
|
(->$ (reduce + 0 (map :amount comparable)))]]
|
||||||
|
[:td.has-text-right (->% (if (> comparable-sales 0)
|
||||||
|
(/ (reduce + 0 (map :amount comparable))
|
||||||
|
comparable-sales)
|
||||||
|
0))]
|
||||||
|
[:td.has-text-right (->$ (- (reduce + 0 (map :amount accounts))
|
||||||
|
(reduce + 0 (map :amount comparable))))]]))
|
||||||
|
|
||||||
(def profit-and-loss-content
|
(def profit-and-loss-content
|
||||||
(with-meta
|
(with-meta
|
||||||
@@ -494,24 +552,38 @@
|
|||||||
[:div
|
[:div
|
||||||
[:table.table.compact.balance-sheet
|
[:table.table.compact.balance-sheet
|
||||||
(list
|
(list
|
||||||
|
^{:key "title"}
|
||||||
[:tr
|
[:tr
|
||||||
[:td.has-text-right "Period ending"]
|
[:td.has-text-right "Period ending"]
|
||||||
[:td.has-text-right (date->str (str->date (:to-date params) standard))]
|
[:td.has-text-right (date->str (str->date (:to-date params) standard))]
|
||||||
[:td.has-text-right (when (:to-date params)
|
[:td.has-text-right (when (:to-date params)
|
||||||
(date->str (t/minus (str->date (:to-date params) standard) (t/years 1))))]
|
(date->str (t/minus (str->date (:to-date params) standard) (t/years 1))))]
|
||||||
[:td]]
|
[:td]]
|
||||||
|
^{:key "report"}
|
||||||
(for [location @(re-frame/subscribe [::locations])]
|
(for [location @(re-frame/subscribe [::locations])]
|
||||||
|
^{:key location}
|
||||||
(list
|
(list
|
||||||
|
^{:key "sales"}
|
||||||
(overall-grouping :sales (str location " Sales") location)
|
(overall-grouping :sales (str location " Sales") location)
|
||||||
|
^{:key "cogs"}
|
||||||
(overall-grouping :cogs (str location " COGS") location)
|
(overall-grouping :cogs (str location " COGS") location)
|
||||||
|
^{:key "payroll"}
|
||||||
(overall-grouping :payroll (str location " Payroll") location)
|
(overall-grouping :payroll (str location " Payroll") location)
|
||||||
|
^{:key "prime"}
|
||||||
(subtotal [:payroll :cogs] #{} (str location " Prime Costs") location)
|
(subtotal [:payroll :cogs] #{} (str location " Prime Costs") location)
|
||||||
|
^{:key "gross profit"}
|
||||||
(subtotal [:sales :payroll :cogs] #{:payroll :cogs} (str location " Gross Profits") location)
|
(subtotal [:sales :payroll :cogs] #{:payroll :cogs} (str location " Gross Profits") location)
|
||||||
|
^{:key "controllable"}
|
||||||
(overall-grouping :controllable (str location " Controllable Expenses") location)
|
(overall-grouping :controllable (str location " Controllable Expenses") location)
|
||||||
|
^{:key "fixed overhead"}
|
||||||
(overall-grouping :fixed-overhead (str location " Fixed Overhead") location)
|
(overall-grouping :fixed-overhead (str location " Fixed Overhead") location)
|
||||||
|
^{:key "ownership"}
|
||||||
(overall-grouping :ownership-controllable (str location " Ownership Controllable") location)
|
(overall-grouping :ownership-controllable (str location " Ownership Controllable") location)
|
||||||
|
^{:key "sub-overhead"}
|
||||||
(subtotal [:controllable :fixed-overhead :ownership-controllable] #{} (str location " Overhead") location)
|
(subtotal [:controllable :fixed-overhead :ownership-controllable] #{} (str location " Overhead") location)
|
||||||
|
^{:key "sub-loc-income"}
|
||||||
(subtotal [:sales :cogs :payroll :controllable :fixed-overhead :ownership-controllable] #{:cogs :payroll :controllable :fixed-overhead :ownership-controllable} (str location " Net Income") location)
|
(subtotal [:sales :cogs :payroll :controllable :fixed-overhead :ownership-controllable] #{:cogs :payroll :controllable :fixed-overhead :ownership-controllable} (str location " Net Income") location)
|
||||||
|
^{:key "sub-net-income"}
|
||||||
(subtotal [:sales :cogs :payroll :controllable :fixed-overhead :ownership-controllable] #{:cogs :payroll :controllable :fixed-overhead :ownership-controllable} "Net Income" nil))))]])])))
|
(subtotal [:sales :cogs :payroll :controllable :fixed-overhead :ownership-controllable] #{:cogs :payroll :controllable :fixed-overhead :ownership-controllable} "Net Income" nil))))]])])))
|
||||||
{:component-will-mount #(re-frame/dispatch-sync [::params-change {:from-date (date->str (t/minus (local-now) (t/period :years 1)) standard)
|
{:component-will-mount #(re-frame/dispatch-sync [::params-change {:from-date (date->str (t/minus (local-now) (t/period :years 1)) standard)
|
||||||
:to-date (date->str (local-now) standard)}]) }))
|
:to-date (date->str (local-now) standard)}]) }))
|
||||||
|
|||||||
@@ -28,6 +28,17 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
(defn- nf%
|
||||||
|
[num]
|
||||||
|
(.format (doto
|
||||||
|
(NumberFormat. Format/PERCENT)
|
||||||
|
(.setMaximumFractionDigits 1)
|
||||||
|
(.setMinimumFractionDigits 1))
|
||||||
|
(str num)))
|
||||||
|
|
||||||
|
(defn ->% [x]
|
||||||
|
(nf% x))
|
||||||
|
|
||||||
(defn active-when= [active-page candidate]
|
(defn active-when= [active-page candidate]
|
||||||
(when (= active-page candidate) " is-active"))
|
(when (= active-page candidate) " is-active"))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user