tweaks for totals.
This commit is contained in:
@@ -505,7 +505,8 @@
|
|||||||
|
|
||||||
|
|
||||||
(defn get-journal-detail-report [context input _]
|
(defn get-journal-detail-report [context input _]
|
||||||
{:categories
|
(let [category-totals (atom {})
|
||||||
|
base-categories (into []
|
||||||
(for [client-id (:client_ids input)
|
(for [client-id (:client_ids input)
|
||||||
:let [_ (assert-can-see-client (:id context) client-id)
|
:let [_ (assert-can-see-client (:id context) client-id)
|
||||||
account-lookup (build-account-lookup client-id)
|
account-lookup (build-account-lookup client-id)
|
||||||
@@ -540,6 +541,9 @@
|
|||||||
(:alternate_description je))
|
(:alternate_description je))
|
||||||
:account (:account jel)
|
:account (:account jel)
|
||||||
:location (:location jel)}))))))
|
:location (:location jel)}))))))
|
||||||
|
_ (swap! category-totals assoc-in [client-id location category]
|
||||||
|
(- (or (reduce + 0.0 (map #(or (:credit %) 0.0) all-journal-entries)) 0.0)
|
||||||
|
(or (reduce + 0.0 (map #(or (:debit %) 0.0) all-journal-entries)) 0.0)) )
|
||||||
journal-entries-by-account (group-by #(account-lookup (get-in % [:account :id])) all-journal-entries)]
|
journal-entries-by-account (group-by #(account-lookup (get-in % [:account :id])) all-journal-entries)]
|
||||||
[account journal-entries] (conj journal-entries-by-account [nil all-journal-entries])
|
[account journal-entries] (conj journal-entries-by-account [nil all-journal-entries])
|
||||||
:let [journal-entries (first (reduce
|
:let [journal-entries (first (reduce
|
||||||
@@ -558,7 +562,40 @@
|
|||||||
{:name (str "All " (name category))})
|
{:name (str "All " (name category))})
|
||||||
:journal_entries (when account (sort-by :date journal-entries))
|
:journal_entries (when account (sort-by :date journal-entries))
|
||||||
:total (- (or (reduce + 0.0 (map #(or (:credit %) 0.0) journal-entries)) 0.0)
|
:total (- (or (reduce + 0.0 (map #(or (:credit %) 0.0) journal-entries)) 0.0)
|
||||||
(or (reduce + 0.0 (map #(or (:debit %) 0.0) journal-entries)) 0.0))})})
|
(or (reduce + 0.0 (map #(or (:debit %) 0.0) journal-entries)) 0.0))}))
|
||||||
|
result {:categories
|
||||||
|
(into base-categories
|
||||||
|
(for [client-id (:client_ids input)
|
||||||
|
:let [_ (assert-can-see-client (:id context) client-id)
|
||||||
|
account-lookup (build-account-lookup client-id)
|
||||||
|
c (d/pull (d/db conn) '[:client/locations] client-id)]
|
||||||
|
location (:client/locations c)
|
||||||
|
line [{:client_id client-id
|
||||||
|
:location location
|
||||||
|
:account {:name "Gross Profit"}
|
||||||
|
:journal_entries nil
|
||||||
|
:total (+ (get-in @category-totals [client-id location :sales] 0.0)
|
||||||
|
(- (get-in @category-totals [client-id location :cogs] 0.0))
|
||||||
|
(- (get-in @category-totals [client-id location :payroll] 0.0)))}
|
||||||
|
{:client_id client-id
|
||||||
|
:location location
|
||||||
|
:account {:name "Overhead"}
|
||||||
|
:journal_entries nil
|
||||||
|
:total (+ (get-in @category-totals [client-id location :controllable] 0.0)
|
||||||
|
(get-in @category-totals [client-id location :fixed-overhead] 0.0)
|
||||||
|
(get-in @category-totals [client-id location :ownership-controllable] 0.0))}
|
||||||
|
{:client_id client-id
|
||||||
|
:location location
|
||||||
|
:account {:name "Net Profit"}
|
||||||
|
:journal_entries nil
|
||||||
|
:total (+ (get-in @category-totals [client-id location :sales] 0.0)
|
||||||
|
(- (get-in @category-totals [client-id location :cogs] 0.0))
|
||||||
|
(- (get-in @category-totals [client-id location :payroll] 0.0))
|
||||||
|
(- (+ (get-in @category-totals [client-id location :controllable] 0.0)
|
||||||
|
(get-in @category-totals [client-id location :fixed-overhead] 0.0)
|
||||||
|
(get-in @category-totals [client-id location :ownership-controllable] 0.0))))}]]
|
||||||
|
line))}]
|
||||||
|
result))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -244,7 +244,7 @@
|
|||||||
(conj [:paragraph {:color [128 0 0] :size 9} (:warning report)])
|
(conj [:paragraph {:color [128 0 0] :size 9} (:warning report)])
|
||||||
(conj
|
(conj
|
||||||
(table->pdf report
|
(table->pdf report
|
||||||
[80 25 80 20 20 20])))
|
[80 25 80 25 25 25])))
|
||||||
output-stream)
|
output-stream)
|
||||||
(.toByteArray output-stream)))
|
(.toByteArray output-stream)))
|
||||||
|
|
||||||
|
|||||||
@@ -586,7 +586,6 @@
|
|||||||
{:value (get je :running-balance)
|
{:value (get je :running-balance)
|
||||||
:format :dollar}])
|
:format :dollar}])
|
||||||
(:journal-entries category))
|
(:journal-entries category))
|
||||||
(when (seq (:journal-entries category))
|
|
||||||
[[
|
[[
|
||||||
{:value (str (client-codes (:client-id category)) " - " (:location category) " - " (:name (:account category)))
|
{:value (str (client-codes (:client-id category)) " - " (:location category) " - " (:name (:account category)))
|
||||||
:bold true
|
:bold true
|
||||||
@@ -603,7 +602,7 @@
|
|||||||
{:value (:total category)
|
{:value (:total category)
|
||||||
:format :dollar
|
:format :dollar
|
||||||
:bold true
|
:bold true
|
||||||
:border [:top]}]])))
|
:border [:top]}]]))
|
||||||
|
|
||||||
)
|
)
|
||||||
[]
|
[]
|
||||||
|
|||||||
Reference in New Issue
Block a user