Revert "Revert "Trying one fix""

This reverts commit 2d3b796793.
This commit is contained in:
2022-12-11 07:10:35 -08:00
parent 24d726e2e5
commit 6620666ca1
6 changed files with 60 additions and 110 deletions

View File

@@ -53,25 +53,22 @@
'[(<= ?date ?end-date)]]} '[(<= ?date ?end-date)]]}
:args [(c/to-date (:end (:date-range args)))]}) :args [(c/to-date (:end (:date-range args)))]})
(or (:from-numeric-code args) (or (seq (: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]]}})
(or (:from-numeric-code args) (seq (:numeric-code args))
(:to-numeric-code args)) (merge-query {:query {:in ['[[?from-numeric-code ?to-numeric-code]]]
(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])
:args []}) '[(>= ?c ?from-numeric-code)]
'[(<= ?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]
@@ -96,11 +93,6 @@
'[?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]]}
@@ -122,6 +114,7 @@
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}))

View File

@@ -754,7 +754,10 @@
:resolve :mutation/delete-external-ledger}}) :resolve :mutation/delete-external-ledger}})
(def input-objects (def input-objects
{:ledger_filters {:numeric_code_range
{: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}
@@ -763,8 +766,7 @@
: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}
:from_numeric_code {:type 'Int} :numeric_code {:type '(list :numeric_code_range)}
: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}

View File

@@ -21,20 +21,6 @@
: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]
@@ -93,18 +79,24 @@
: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]
["35001-40000 Other" 35001 39999]] ["35000-40000 Other" 35000 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
(vals ranges)) flat-categories)
false)) false))
(defn client-locations [pnl-data] (defn client-locations [pnl-data]
@@ -135,8 +127,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]
(->> ranges (->> flat-categories
(filter (fn [[_ [start end]]] (filter (fn [[category start end]]
(and (:numeric-code a) (and (:numeric-code a)
(<= start (:numeric-code a) end)))) (<= start (:numeric-code a) end))))
first first
@@ -164,19 +156,29 @@
data))) data)))
(update :filters (fn [f] (update :filters (fn [f]
(assoc f (assoc f
:from-numeric-code from :numeric-code [{:from from
:to-numeric-code to))))) :to 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]
(if (= 1 (count categories)) (-> pnl-data
(let [[from to] (ranges (first categories))] (update :data
(-> pnl-data (fn [data]
(filter-numeric-code from to))) (for [account data
(-> pnl-data :when (some #(account-belongs-in-category? (:numeric-code account) %) categories)]
(update :data (fn [data] account)))
(mapcat identity (update :filters
((apply juxt categories) (fn [f]
(group-by best-category data)))))))) (assoc f :numeric-code
(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
@@ -216,10 +218,11 @@
: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 (:from-numeric-code (:filters p)) ;; don't allow filtering when you don't at least filter numeric codes :filters (when (: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))
@@ -473,52 +476,12 @@
(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 (combine-tables pnl-datas table percent-of-sales deltas)})) :rows table}))
(defn warning-message [pnl-data] (defn warning-message [pnl-data]
(let [errors (->> pnl-data (let [errors (->> pnl-data
@@ -599,7 +562,6 @@
(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
@@ -611,7 +573,6 @@
(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")

View File

@@ -30,8 +30,7 @@
: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 )
:from-numeric-code (:from-numeric-code params) :numeric-code (:numeric-code params)
:to-numeric-code (:to-numeric-code params)
:date-range (:date-range params)})) :date-range (:date-range params)}))
@@ -120,11 +119,10 @@ 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 [from-numeric-code to-numeric-code date-range]}]] (fn [{:keys [db]} [_ {:keys [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]))
:from-numeric-code from-numeric-code :numeric-code 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)}}]}))

View File

@@ -170,8 +170,7 @@ 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)
:from-numeric-code (:from-numeric-code params) :numeric-code (: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)}))
@@ -207,12 +206,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 [location from-numeric-code to-numeric-code client-id] (fn [{:keys [db]} [_ {:keys [location 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
:from-numeric-code from-numeric-code :numeric-code 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)}}]}))

View File

@@ -170,8 +170,7 @@ 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)
:from-numeric-code (:from-numeric-code params) :numeric-code (: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)}))
@@ -207,12 +206,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 [location from-numeric-code to-numeric-code client-id] (fn [{:keys [db]} [_ {:keys [location 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
:from-numeric-code from-numeric-code :numeric-code 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)}}]}))