@@ -53,22 +53,25 @@
|
|||||||
'[(<= ?date ?end-date)]]}
|
'[(<= ?date ?end-date)]]}
|
||||||
:args [(c/to-date (:end (:date-range args)))]})
|
:args [(c/to-date (:end (:date-range args)))]})
|
||||||
|
|
||||||
(or (seq (:numeric-code args))
|
(or (:from-numeric-code args)
|
||||||
|
(:to-numeric-code args)
|
||||||
(:bank-account-id args)
|
(:bank-account-id args)
|
||||||
(not-empty (:location args)))
|
(not-empty (:location args)))
|
||||||
(merge-query {:query {:where ['[?e :journal-entry/line-items ?li]]}})
|
(merge-query {:query {:where ['[?e :journal-entry/line-items ?li]]}})
|
||||||
|
|
||||||
(seq (:numeric-code args))
|
(or (:from-numeric-code args)
|
||||||
(merge-query {:query {:in ['[[?from-numeric-code ?to-numeric-code]]]
|
(:to-numeric-code args))
|
||||||
|
(merge-query {:query {:in []
|
||||||
:where ['[?li :journal-entry-line/account ?a]
|
:where ['[?li :journal-entry-line/account ?a]
|
||||||
'(or-join [?a ?c]
|
'(or-join [?a ?c]
|
||||||
[?a :account/numeric-code ?c]
|
[?a :account/numeric-code ?c]
|
||||||
[?a :bank-account/numeric-code ?c])
|
[?a :bank-account/numeric-code ?c])]}
|
||||||
'[(>= ?c ?from-numeric-code)]
|
:args []})
|
||||||
'[(<= ?c ?to-numeric-code)]]}
|
|
||||||
:args [(vec (for [{:keys [from to]} (:numeric-code args)]
|
|
||||||
[(or from 0) (or to 99999)]))]})
|
|
||||||
|
|
||||||
|
(:from-numeric-code args)
|
||||||
|
(merge-query {:query {:in ['?from-numeric-code]
|
||||||
|
:where ['[(>= ?c ?from-numeric-code)]]}
|
||||||
|
:args [(:from-numeric-code args)]})
|
||||||
|
|
||||||
(:amount-gte args)
|
(:amount-gte args)
|
||||||
(merge-query {:query {:in ['?amount-gte]
|
(merge-query {:query {:in ['?amount-gte]
|
||||||
@@ -93,6 +96,11 @@
|
|||||||
'[?li2 :journal-entry-line/account ?a2]]}
|
'[?li2 :journal-entry-line/account ?a2]]}
|
||||||
:args [(:account-id args)]})
|
:args [(:account-id args)]})
|
||||||
|
|
||||||
|
(:to-numeric-code args)
|
||||||
|
(merge-query {:query {:in ['?to-numeric-code]
|
||||||
|
:where ['[(<= ?c ?to-numeric-code)]]}
|
||||||
|
:args [(:to-numeric-code args)]})
|
||||||
|
|
||||||
(not-empty (:location args))
|
(not-empty (:location args))
|
||||||
(merge-query {:query {:in ['?location]
|
(merge-query {:query {:in ['?location]
|
||||||
:where ['[?li :journal-entry-line/location ?location]]}
|
:where ['[?li :journal-entry-line/location ?location]]}
|
||||||
@@ -114,7 +122,6 @@
|
|||||||
|
|
||||||
true
|
true
|
||||||
(merge-query {:query {:find ['?sort-default '?e] :where ['[?e :journal-entry/date ?sort-default]]}}))]
|
(merge-query {:query {:find ['?sort-default '?e] :where ['[?e :journal-entry/date ?sort-default]]}}))]
|
||||||
(clojure.pprint/pprint query)
|
|
||||||
(->> query
|
(->> query
|
||||||
(d/query)
|
(d/query)
|
||||||
(apply-sort-3 (update args :sort conj {:sort-key "default-2" :asc true}))
|
(apply-sort-3 (update args :sort conj {:sort-key "default-2" :asc true}))
|
||||||
|
|||||||
@@ -754,10 +754,7 @@
|
|||||||
:resolve :mutation/delete-external-ledger}})
|
:resolve :mutation/delete-external-ledger}})
|
||||||
|
|
||||||
(def input-objects
|
(def input-objects
|
||||||
{:numeric_code_range
|
{:ledger_filters
|
||||||
{:fields {:from {:type 'Int}
|
|
||||||
:to {:type 'Int}}}
|
|
||||||
:ledger_filters
|
|
||||||
{:fields {:client_id {:type :id}
|
{:fields {:client_id {:type :id}
|
||||||
:vendor_id {:type :id}
|
:vendor_id {:type :id}
|
||||||
:account_id {:type :id}
|
:account_id {:type :id}
|
||||||
@@ -766,7 +763,8 @@
|
|||||||
:bank_account_id {:type :id}
|
:bank_account_id {:type :id}
|
||||||
:date_range {:type :date_range}
|
:date_range {:type :date_range}
|
||||||
:location {:type 'String}
|
:location {:type 'String}
|
||||||
:numeric_code {:type '(list :numeric_code_range)}
|
:from_numeric_code {:type 'Int}
|
||||||
|
:to_numeric_code {:type 'Int}
|
||||||
:start {:type 'Int}
|
:start {:type 'Int}
|
||||||
:per_page {:type 'Int}
|
:per_page {:type 'Int}
|
||||||
:only_external {:type 'Boolean}
|
:only_external {:type 'Boolean}
|
||||||
|
|||||||
@@ -21,6 +21,20 @@
|
|||||||
:cljs (au/date->str d au/pretty)))
|
:cljs (au/date->str d au/pretty)))
|
||||||
|
|
||||||
|
|
||||||
|
(def ranges
|
||||||
|
{:assets [11000 19999]
|
||||||
|
:liabilities [20100 28999]
|
||||||
|
:equities [30000 39999]
|
||||||
|
:sales [40000 49999]
|
||||||
|
:cogs [50000 59999]
|
||||||
|
:payroll [60000 69999]
|
||||||
|
:controllable [70000 79999]
|
||||||
|
:fixed-overhead [80000 89999]
|
||||||
|
:ownership-controllable [90000 99999]
|
||||||
|
:operating-activities [10000 99999]
|
||||||
|
:investment-activities [10000 99999]
|
||||||
|
:financing-activities [10000 99999]
|
||||||
|
:bottom-line [10000 99999]})
|
||||||
|
|
||||||
(def groupings
|
(def groupings
|
||||||
{:assets [["1100 Cash and Bank Accounts" 11000 11999]
|
{:assets [["1100 Cash and Bank Accounts" 11000 11999]
|
||||||
@@ -79,24 +93,18 @@
|
|||||||
|
|
||||||
:investment-activities [["14000-18000 Investments" 14000 17999]]
|
:investment-activities [["14000-18000 Investments" 14000 17999]]
|
||||||
:financing-activities [["28000-35000 Financing Activities" 28000 34999]
|
:financing-activities [["28000-35000 Financing Activities" 28000 34999]
|
||||||
["35000-40000 Other" 35000 39999]]
|
["35001-40000 Other" 35001 39999]]
|
||||||
:bottom-line [["11000-12000 Bottom Line" 11000 11999]]})
|
:bottom-line [["11000-12000 Bottom Line" 11000 11999]]})
|
||||||
|
|
||||||
|
|
||||||
(def flat-categories
|
|
||||||
(for [[category groups] groupings
|
|
||||||
[_ start end] groups]
|
|
||||||
[category start end]))
|
|
||||||
|
|
||||||
(defn in-range? [code]
|
(defn in-range? [code]
|
||||||
(if code
|
(if code
|
||||||
(reduce
|
(reduce
|
||||||
(fn [acc [_ start end]]
|
(fn [acc [start end]]
|
||||||
(if (<= start code end)
|
(if (<= start code end)
|
||||||
(reduced true)
|
(reduced true)
|
||||||
acc))
|
acc))
|
||||||
false
|
false
|
||||||
flat-categories)
|
(vals ranges))
|
||||||
false))
|
false))
|
||||||
|
|
||||||
(defn client-locations [pnl-data]
|
(defn client-locations [pnl-data]
|
||||||
@@ -127,8 +135,8 @@
|
|||||||
(reduce (fnil + 0.0) 0.0 (map :amount (:data pnl-data))))
|
(reduce (fnil + 0.0) 0.0 (map :amount (:data pnl-data))))
|
||||||
|
|
||||||
(defn best-category [a]
|
(defn best-category [a]
|
||||||
(->> flat-categories
|
(->> ranges
|
||||||
(filter (fn [[category start end]]
|
(filter (fn [[_ [start end]]]
|
||||||
(and (:numeric-code a)
|
(and (:numeric-code a)
|
||||||
(<= start (:numeric-code a) end))))
|
(<= start (:numeric-code a) end))))
|
||||||
first
|
first
|
||||||
@@ -156,29 +164,19 @@
|
|||||||
data)))
|
data)))
|
||||||
(update :filters (fn [f]
|
(update :filters (fn [f]
|
||||||
(assoc f
|
(assoc f
|
||||||
:numeric-code [{:from from
|
:from-numeric-code from
|
||||||
:to to}])))))
|
:to-numeric-code to)))))
|
||||||
|
|
||||||
(defn account-belongs-in-category? [numeric-code category]
|
|
||||||
(->> (groupings category)
|
|
||||||
(some (fn [[_ from to]]
|
|
||||||
(<= from (or numeric-code 0) to)))))
|
|
||||||
|
|
||||||
;; TODO make click-through work for multiple ranges :fliters
|
|
||||||
(defn filter-categories [pnl-data categories]
|
(defn filter-categories [pnl-data categories]
|
||||||
(-> pnl-data
|
(if (= 1 (count categories))
|
||||||
(update :data
|
(let [[from to] (ranges (first categories))]
|
||||||
(fn [data]
|
(-> pnl-data
|
||||||
(for [account data
|
(filter-numeric-code from to)))
|
||||||
:when (some #(account-belongs-in-category? (:numeric-code account) %) categories)]
|
(-> pnl-data
|
||||||
account)))
|
(update :data (fn [data]
|
||||||
(update :filters
|
(mapcat identity
|
||||||
(fn [f]
|
((apply juxt categories)
|
||||||
(assoc f :numeric-code
|
(group-by best-category data))))))))
|
||||||
(for [category categories
|
|
||||||
[_ from to] (groupings category)]
|
|
||||||
{:from from
|
|
||||||
:to to}))))))
|
|
||||||
|
|
||||||
(defn filter-period [pnl-data period]
|
(defn filter-period [pnl-data period]
|
||||||
(-> pnl-data
|
(-> pnl-data
|
||||||
@@ -218,11 +216,10 @@
|
|||||||
:bold true}]
|
:bold true}]
|
||||||
(map
|
(map
|
||||||
(fn [p]
|
(fn [p]
|
||||||
(println "FILTERS" (:filters p))
|
|
||||||
(merge
|
(merge
|
||||||
{:format :dollar
|
{:format :dollar
|
||||||
:value (aggregate-accounts p)
|
:value (aggregate-accounts p)
|
||||||
:filters (when (:numeric-code (:filters p)) ;; don't allow filtering when you don't at least filter numeric codes
|
:filters (when (:from-numeric-code (:filters p)) ;; don't allow filtering when you don't at least filter numeric codes
|
||||||
(:filters p))}
|
(:filters p))}
|
||||||
(:cell-args p)
|
(:cell-args p)
|
||||||
cell-args))
|
cell-args))
|
||||||
@@ -476,12 +473,52 @@
|
|||||||
|
|
||||||
(into (detail-rows pnl-datas
|
(into (detail-rows pnl-datas
|
||||||
:bottom-line
|
:bottom-line
|
||||||
(str prefix " Bottom Line"))))
|
(str prefix " Bottom Line")))
|
||||||
|
#_(into (detail-rows pnl-datas
|
||||||
|
:cogs
|
||||||
|
(str prefix " COGS")))
|
||||||
|
#_(into (detail-rows
|
||||||
|
pnl-datas
|
||||||
|
:payroll
|
||||||
|
(str prefix " Payroll")))
|
||||||
|
#_(conj (subtotal-by-column-row (map #(filter-categories % [:payroll :cogs])
|
||||||
|
pnl-datas)
|
||||||
|
(str prefix " Prime Costs")))
|
||||||
|
#_(conj (subtotal-by-column-row (map #(-> %
|
||||||
|
(filter-categories [:sales :payroll :cogs])
|
||||||
|
(negate #{:payroll :cogs}))
|
||||||
|
pnl-datas)
|
||||||
|
(str prefix " Gross Profits")))
|
||||||
|
#_(into (detail-rows
|
||||||
|
pnl-datas
|
||||||
|
:controllable
|
||||||
|
(str prefix " Controllable Expenses")))
|
||||||
|
#_(into (detail-rows
|
||||||
|
pnl-datas
|
||||||
|
:fixed-overhead
|
||||||
|
(str prefix " Fixed Overhead")))
|
||||||
|
#_(into (detail-rows
|
||||||
|
pnl-datas
|
||||||
|
:ownership-controllable
|
||||||
|
(str prefix " Ownership Controllable")))
|
||||||
|
#_(conj (subtotal-by-column-row (map #(filter-categories % [:controllable :fixed-overhead :ownership-controllable]) pnl-datas)
|
||||||
|
(str prefix " Overhead")))
|
||||||
|
#_(conj (subtotal-by-column-row (map #(-> %
|
||||||
|
(filter-categories [:sales :cogs :payroll :controllable :fixed-overhead :ownership-controllable])
|
||||||
|
(negate #{:cogs :payroll :controllable :fixed-overhead :ownership-controllable}))
|
||||||
|
pnl-datas)
|
||||||
|
(str prefix " Net Income"))))
|
||||||
|
#_table #_(if (seq client-datas)
|
||||||
|
(conj table (subtotal-by-column-row (map #(-> %
|
||||||
|
(filter-categories [:sales :cogs :payroll :controllable :fixed-overhead :ownership-controllable])
|
||||||
|
(negate #{:cogs :payroll :controllable :fixed-overhead :ownership-controllable}))
|
||||||
|
client-datas)
|
||||||
|
"All Location Net Income"))
|
||||||
|
table)
|
||||||
percent-of-sales (calc-percent-of-sales table pnl-datas)
|
percent-of-sales (calc-percent-of-sales table pnl-datas)
|
||||||
deltas (into [] (calc-deltas table))]
|
deltas (into [] (calc-deltas table))]
|
||||||
{:header (headers pnl-datas title)
|
{:header (headers pnl-datas title)
|
||||||
:rows table}))
|
:rows (combine-tables pnl-datas table percent-of-sales deltas)}))
|
||||||
|
|
||||||
(defn warning-message [pnl-data]
|
(defn warning-message [pnl-data]
|
||||||
(let [errors (->> pnl-data
|
(let [errors (->> pnl-data
|
||||||
@@ -562,6 +599,7 @@
|
|||||||
(for [[client-id location] (client-locations pnl-data)]
|
(for [[client-id location] (client-locations pnl-data)]
|
||||||
(-> pnl-data
|
(-> pnl-data
|
||||||
(filter-client client-id)
|
(filter-client client-id)
|
||||||
|
(filter-location location)
|
||||||
(filter-period period)
|
(filter-period period)
|
||||||
(zebra i)))
|
(zebra i)))
|
||||||
[(-> pnl-data
|
[(-> pnl-data
|
||||||
@@ -573,6 +611,7 @@
|
|||||||
(cash-flows-location-detail-table (for [[period i] (map vector (-> pnl-data :args :periods ) (range))]
|
(cash-flows-location-detail-table (for [[period i] (map vector (-> pnl-data :args :periods ) (range))]
|
||||||
(-> pnl-data
|
(-> pnl-data
|
||||||
(filter-client client-id)
|
(filter-client client-id)
|
||||||
|
(filter-location "A")
|
||||||
(filter-period period)
|
(filter-period period)
|
||||||
(zebra i)))
|
(zebra i)))
|
||||||
(str (-> pnl-data :clients-by-id (get client-id)) " Detail")
|
(str (-> pnl-data :clients-by-id (get client-id)) " Detail")
|
||||||
|
|||||||
@@ -30,7 +30,8 @@
|
|||||||
:per-page (:per-page params)
|
:per-page (:per-page params)
|
||||||
:vendor-id (:id (:vendor params))
|
:vendor-id (:id (:vendor params))
|
||||||
:client-id (:client-id params )
|
:client-id (:client-id params )
|
||||||
:numeric-code (:numeric-code params)
|
:from-numeric-code (:from-numeric-code params)
|
||||||
|
:to-numeric-code (:to-numeric-code params)
|
||||||
:date-range (:date-range params)}))
|
:date-range (:date-range params)}))
|
||||||
|
|
||||||
|
|
||||||
@@ -119,10 +120,11 @@ NOTE: Please review the transactions we may have question for you here: https://
|
|||||||
|
|
||||||
(re-frame/reg-event-fx
|
(re-frame/reg-event-fx
|
||||||
::investigate-clicked
|
::investigate-clicked
|
||||||
(fn [{:keys [db]} [_ {:keys [numeric-code date-range]}]]
|
(fn [{:keys [db]} [_ {:keys [from-numeric-code to-numeric-code date-range]}]]
|
||||||
{:db (-> db (assoc ::ledger-list-active? true))
|
{:db (-> db (assoc ::ledger-list-active? true))
|
||||||
:dispatch [::data-page/additional-params-changed ::ledger {:client-id (:id @(re-frame/subscribe [::subs/client]))
|
:dispatch [::data-page/additional-params-changed ::ledger {:client-id (:id @(re-frame/subscribe [::subs/client]))
|
||||||
:numeric-code numeric-code
|
:from-numeric-code from-numeric-code
|
||||||
|
:to-numeric-code to-numeric-code
|
||||||
:date-range {:start "2000-01-01"
|
:date-range {:start "2000-01-01"
|
||||||
:end (date->str date-range standard)}}]}))
|
:end (date->str date-range standard)}}]}))
|
||||||
|
|
||||||
|
|||||||
@@ -170,7 +170,8 @@ NOTE: Please review the transactions we may have question for you here: https://
|
|||||||
:per-page (:per-page params)
|
:per-page (:per-page params)
|
||||||
:vendor-id (:id (:vendor params))
|
:vendor-id (:id (:vendor params))
|
||||||
:client-id (:client-id params)
|
:client-id (:client-id params)
|
||||||
:numeric-code (:numeric-code params)
|
:from-numeric-code (:from-numeric-code params)
|
||||||
|
:to-numeric-code (:to-numeric-code params)
|
||||||
:location (:location params)
|
:location (:location params)
|
||||||
:date-range (:date-range params)}))
|
:date-range (:date-range params)}))
|
||||||
|
|
||||||
@@ -206,11 +207,12 @@ NOTE: Please review the transactions we may have question for you here: https://
|
|||||||
|
|
||||||
(re-frame/reg-event-fx
|
(re-frame/reg-event-fx
|
||||||
::investigate-clicked
|
::investigate-clicked
|
||||||
(fn [{:keys [db]} [_ {:keys [location numeric-code client-id]
|
(fn [{:keys [db]} [_ {:keys [location from-numeric-code to-numeric-code client-id]
|
||||||
{:keys [start end]} :date-range}]]
|
{:keys [start end]} :date-range}]]
|
||||||
{:db (-> db (assoc ::ledger-list-active? true))
|
{:db (-> db (assoc ::ledger-list-active? true))
|
||||||
:dispatch [::data-page/additional-params-changed ::ledger {:client-id client-id
|
:dispatch [::data-page/additional-params-changed ::ledger {:client-id client-id
|
||||||
:numeric-code numeric-code
|
:from-numeric-code from-numeric-code
|
||||||
|
:to-numeric-code to-numeric-code
|
||||||
:location location
|
:location location
|
||||||
:date-range {:start (date->str start standard)
|
:date-range {:start (date->str start standard)
|
||||||
:end (date->str end standard)}}]}))
|
:end (date->str end standard)}}]}))
|
||||||
|
|||||||
@@ -170,7 +170,8 @@ NOTE: Please review the transactions we may have question for you here: https://
|
|||||||
:per-page (:per-page params)
|
:per-page (:per-page params)
|
||||||
:vendor-id (:id (:vendor params))
|
:vendor-id (:id (:vendor params))
|
||||||
:client-id (:client-id params)
|
:client-id (:client-id params)
|
||||||
:numeric-code (:numeric-code params)
|
:from-numeric-code (:from-numeric-code params)
|
||||||
|
:to-numeric-code (:to-numeric-code params)
|
||||||
:location (:location params)
|
:location (:location params)
|
||||||
:date-range (:date-range params)}))
|
:date-range (:date-range params)}))
|
||||||
|
|
||||||
@@ -206,11 +207,12 @@ NOTE: Please review the transactions we may have question for you here: https://
|
|||||||
|
|
||||||
(re-frame/reg-event-fx
|
(re-frame/reg-event-fx
|
||||||
::investigate-clicked
|
::investigate-clicked
|
||||||
(fn [{:keys [db]} [_ {:keys [location numeric-code client-id]
|
(fn [{:keys [db]} [_ {:keys [location from-numeric-code to-numeric-code client-id]
|
||||||
{:keys [start end]} :date-range}]]
|
{:keys [start end]} :date-range}]]
|
||||||
{:db (-> db (assoc ::ledger-list-active? true))
|
{:db (-> db (assoc ::ledger-list-active? true))
|
||||||
:dispatch [::data-page/additional-params-changed ::ledger {:client-id client-id
|
:dispatch [::data-page/additional-params-changed ::ledger {:client-id client-id
|
||||||
:numeric-code numeric-code
|
:from-numeric-code from-numeric-code
|
||||||
|
:to-numeric-code to-numeric-code
|
||||||
:location location
|
:location location
|
||||||
:date-range {:start (date->str start standard)
|
:date-range {:start (date->str start standard)
|
||||||
:end (date->str end standard)}}]}))
|
:end (date->str end standard)}}]}))
|
||||||
|
|||||||
Reference in New Issue
Block a user