tweaks for totals.
This commit is contained in:
@@ -505,60 +505,97 @@
|
|||||||
|
|
||||||
|
|
||||||
(defn get-journal-detail-report [context input _]
|
(defn get-journal-detail-report [context input _]
|
||||||
{:categories
|
(let [category-totals (atom {})
|
||||||
(for [client-id (:client_ids input)
|
base-categories (into []
|
||||||
:let [_ (assert-can-see-client (:id context) client-id)
|
(for [client-id (:client_ids input)
|
||||||
account-lookup (build-account-lookup client-id)
|
:let [_ (assert-can-see-client (:id context) client-id)
|
||||||
c (d/pull (d/db conn) '[:client/locations] client-id) ]
|
account-lookup (build-account-lookup client-id)
|
||||||
location (:client/locations c)
|
c (d/pull (d/db conn) '[:client/locations] client-id)]
|
||||||
category (:categories input)
|
location (:client/locations c)
|
||||||
:let [category (<-graphql category)
|
category (:categories input)
|
||||||
all-journal-entries (->> (get-ledger-page context
|
:let [category (<-graphql category)
|
||||||
{:filters {:client_id client-id
|
all-journal-entries (->> (get-ledger-page context
|
||||||
:location location
|
{:filters {:client_id client-id
|
||||||
:date_range (:date_range input)
|
:location location
|
||||||
:from_numeric_code (get-in l-reports/ranges [category 0])
|
:date_range (:date_range input)
|
||||||
:to_numeric_code (get-in l-reports/ranges [category 1])
|
:from_numeric_code (get-in l-reports/ranges [category 0])
|
||||||
:per_page Integer/MAX_VALUE}}
|
:to_numeric_code (get-in l-reports/ranges [category 1])
|
||||||
nil)
|
:per_page Integer/MAX_VALUE}}
|
||||||
:journal_entries
|
nil)
|
||||||
(mapcat (fn [je]
|
:journal_entries
|
||||||
(->> (je :line_items)
|
(mapcat (fn [je]
|
||||||
(filter (fn [jel]
|
(->> (je :line_items)
|
||||||
(when-let [account (account-lookup (:id (:account jel)))]
|
(filter (fn [jel]
|
||||||
(and
|
(when-let [account (account-lookup (:id (:account jel)))]
|
||||||
(<= (get-in l-reports/ranges [category 0])
|
(and
|
||||||
(:numeric_code account)
|
(<= (get-in l-reports/ranges [category 0])
|
||||||
(get-in l-reports/ranges [category 1]))
|
(:numeric_code account)
|
||||||
(= location (:location jel)))))
|
(get-in l-reports/ranges [category 1]))
|
||||||
)
|
(= location (:location jel)))))
|
||||||
(map (fn [jel ]
|
)
|
||||||
{:date (:date je)
|
(map (fn [jel ]
|
||||||
:debit (:debit jel)
|
{:date (:date je)
|
||||||
:credit (:credit jel)
|
:debit (:debit jel)
|
||||||
:description (or (:name (:vendor je))
|
:credit (:credit jel)
|
||||||
(:alternate_description je))
|
:description (or (:name (:vendor je))
|
||||||
:account (:account jel)
|
(:alternate_description je))
|
||||||
:location (:location jel)}))))))
|
:account (:account jel)
|
||||||
journal-entries-by-account (group-by #(account-lookup (get-in % [:account :id])) all-journal-entries)]
|
:location (:location jel)}))))))
|
||||||
[account journal-entries] (conj journal-entries-by-account [nil all-journal-entries])
|
_ (swap! category-totals assoc-in [client-id location category]
|
||||||
:let [journal-entries (first (reduce
|
(- (or (reduce + 0.0 (map #(or (:credit %) 0.0) all-journal-entries)) 0.0)
|
||||||
(fn [[acc last-je] je]
|
(or (reduce + 0.0 (map #(or (:debit %) 0.0) all-journal-entries)) 0.0)) )
|
||||||
(let [next-je (assoc je :running_balance
|
journal-entries-by-account (group-by #(account-lookup (get-in % [:account :id])) all-journal-entries)]
|
||||||
(- (+ (or (:running_balance last-je 0.0) 0.0)
|
[account journal-entries] (conj journal-entries-by-account [nil all-journal-entries])
|
||||||
(or (:credit je 0.0) 0.0))
|
:let [journal-entries (first (reduce
|
||||||
(or (:debit je 0.0) 0.0)))]
|
(fn [[acc last-je] je]
|
||||||
[(conj acc next-je) next-je]))
|
(let [next-je (assoc je :running_balance
|
||||||
[]
|
(- (+ (or (:running_balance last-je 0.0) 0.0)
|
||||||
(sort-by :date journal-entries)))]]
|
(or (:credit je 0.0) 0.0))
|
||||||
{:category (->graphql category)
|
(or (:debit je 0.0) 0.0)))]
|
||||||
:client_id client-id
|
[(conj acc next-je) next-je]))
|
||||||
:location location
|
[]
|
||||||
:account (or account
|
(sort-by :date journal-entries)))]]
|
||||||
{:name (str "All " (name category))})
|
{:category (->graphql category)
|
||||||
:journal_entries (when account (sort-by :date journal-entries))
|
:client_id client-id
|
||||||
:total (- (or (reduce + 0.0 (map #(or (:credit %) 0.0) journal-entries)) 0.0)
|
:location location
|
||||||
(or (reduce + 0.0 (map #(or (:debit %) 0.0) journal-entries)) 0.0))})})
|
:account (or account
|
||||||
|
{:name (str "All " (name category))})
|
||||||
|
:journal_entries (when account (sort-by :date journal-entries))
|
||||||
|
: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))}))
|
||||||
|
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,24 +586,23 @@
|
|||||||
{: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
|
:border [:top]}
|
||||||
:border [:top]}
|
{:value ""
|
||||||
{:value ""
|
:border [:top]}
|
||||||
:border [:top]}
|
{:value (str "Total" )
|
||||||
{:value (str "Total" )
|
:bold true
|
||||||
:bold true
|
:border [:top]}
|
||||||
:border [:top]}
|
{:value ""
|
||||||
{:value ""
|
:border [:top]}
|
||||||
:border [:top]}
|
{:value ""
|
||||||
{:value ""
|
:border [:top]}
|
||||||
:border [:top]}
|
{: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