progress on reports.

This commit is contained in:
2024-11-10 22:09:14 -08:00
parent eed9bfbd11
commit df3183f85c
7 changed files with 54 additions and 33 deletions

View File

@@ -236,29 +236,37 @@
(dc/db auto-ap.datomic/conn) (dc/db auto-ap.datomic/conn)
#inst "2024-10-10" n)) #inst "2024-10-10" n))
(defn detailed-account-snapshot [db client-id ^java.util.Date end] (defn detailed-account-snapshot
(for [running-balance-set (account-sets db client-id) ([db client-id ^java.util.Date end]
:let [{:keys [account-id client-id location current-balance debits credits count]} (detailed-account-snapshot db client-id end nil))
(->> running-balance-set ([db client-id ^java.util.Date end ^java.util.Date start]
(take-while (fn until-date [^Line l]
(let [^java.util.Date d (.-date l)] (for [running-balance-set (account-sets db client-id)
(<= (.compareTo ^java.util.Date d end) 0)))) :let [{:keys [account-id client-id location current-balance debits credits count]}
(reduce (->> running-balance-set
(fn step [acc ^Line l] (filter (fn until-end [^Line l]
(assoc! acc (let [^java.util.Date d (.-date l)]
:count (unchecked-inc (:count acc)) (and
:debits (unchecked-add (:debits acc) (or (.-debit l) 0.0)) (if start
:credits (unchecked-add (:credits acc) (or (.-credit l) 0.0)) (>= (.compareTo ^java.util.Date d start) 0)
:current-balance (.-running-balance l) true)
:account-id (.-account-id l) (< (.compareTo ^java.util.Date d end) 0)))))
:client-id (.-client-id l) (reduce
:location (.-location l))) (fn step [acc ^Line l]
(transient {:count 0 (assoc! acc
:debits 0.0 :count (unchecked-inc (:count acc))
:credits 0.0 :debits (unchecked-add (:debits acc) (or (.-debit l) 0.0))
:current-balance 0.0})))] :credits (unchecked-add (:credits acc) (or (.-credit l) 0.0))
:when client-id] :current-balance (.-running-balance l)
[client-id account-id location debits credits current-balance count])) :account-id (.-account-id l)
:client-id (.-client-id l)
:location (.-location l)))
(transient {:count 0
:debits 0.0
:credits 0.0
:current-balance 0.0})))]
:when client-id]
[client-id account-id location debits credits current-balance count])))
(comment (comment

View File

@@ -211,7 +211,7 @@ const lastYearPeriod = (date) => {
// Create new Date objects for both years // Create new Date objects for both years
const originalDate = new Date(originalYear, date.getMonth(), date.getDate()); const originalDate = new Date(originalYear, date.getMonth(), date.getDate());
const priorYearDate = new Date(priorYear, date.getMonth(), date.getDate()); const priorYearDate = dateFns.addDays(new Date(priorYear, date.getMonth(), date.getDate()), 1);
return {end: formatDateMMDDYYYY(originalDate), start: formatDateMMDDYYYY(priorYearDate)}; return {end: formatDateMMDDYYYY(originalDate), start: formatDateMMDDYYYY(priorYearDate)};
} }

File diff suppressed because one or more lines are too long

View File

@@ -472,6 +472,7 @@
(mark-all-clients-dirty) (mark-all-clients-dirty)
(clients-needing-refresh (dc/db conn)) (clients-needing-refresh (dc/db conn))
(upsert-running-balance) (upsert-running-balance)

View File

@@ -341,6 +341,7 @@
(update :class (fnil hh/add-class "") default-input-classes) (update :class (fnil hh/add-class "") default-input-classes)
(assoc :x-modelable "value") (assoc :x-modelable "value")
(assoc :type "text") (assoc :type "text")
(assoc "autocomplete" "off")
(assoc :x-data (hx/json {:dp nil}) ) (assoc :x-data (hx/json {:dp nil}) )
(assoc :x-init " dp = initDatepicker($el);") (assoc :x-init " dp = initDatepicker($el);")
(assoc "@htmx:before-history-save" "destroyDatepicker(dp)" ) (assoc "@htmx:before-history-save" "destroyDatepicker(dp)" )

View File

@@ -33,7 +33,8 @@
[config.core :refer [env] :as env] [config.core :refer [env] :as env]
[datomic.api :as dc] [datomic.api :as dc]
[iol-ion.utils :refer [by]] [iol-ion.utils :refer [by]]
[malli.core :as mc]) [malli.core :as mc]
[medley.core :refer [map-vals]])
(:import (:import
[java.util UUID] [java.util UUID]
[org.apache.commons.io.output ByteArrayOutputStream])) [org.apache.commons.io.output ByteArrayOutputStream]))
@@ -84,7 +85,7 @@
data (into [] data (into []
(for [client-id client-ids (for [client-id client-ids
p periods p periods
[client-id account-id location debits credits balance count] (iol-ion.query/detailed-account-snapshot (dc/db conn) client-id (coerce/to-date (:end p))) [client-id account-id location debits credits balance count] (iol-ion.query/detailed-account-snapshot (dc/db conn) client-id (coerce/to-date (:end p)) (coerce/to-date (:start p)))
:let [account ((or (lookup-account client-id) {}) account-id)]] :let [account ((or (lookup-account client-id) {}) account-id)]]
{:client-id client-id {:client-id client-id
:account-id account-id :account-id account-id
@@ -92,7 +93,11 @@
:debits debits :debits debits
:credits credits :credits credits
:count count :count count
:amount balance :amount (if (#{:account-type/asset
:account-type/dividend
:account-type/expense} (:account_type account))
(- (or debits 0.0) (or credits 0.0))
(- (or credits 0.0) (or debits 0.0)))
:account-type (:account_type account) :account-type (:account_type account)
:numeric-code (:numeric_code account) :numeric-code (:numeric_code account)
:name (:name account) :name (:name account)
@@ -120,7 +125,7 @@
(let [{:keys [client warning]} (maybe-trim-clients request client) (let [{:keys [client warning]} (maybe-trim-clients request client)
{:keys [data report]} (get-report (assoc-in request [:form-params :client] client)) {:keys [data report]} (get-report (assoc-in request [:form-params :client] client))
client-count (count (set (map :client-id (:data data)))) client-count (count (set (map :client-id (:data data))))
table-contents (concat-tables (:details report))] table-contents (concat-tables (concat (:summaries report) (:details report)))]
(list (list
[:div.text-2xl.font-bold.text-gray-600 (str "Profit and loss - " (str/join ", " (map :client/name client)))] [:div.text-2xl.font-bold.text-gray-600 (str "Profit and loss - " (str/join ", " (map :client/name client)))]
(table {:widths (into [20] (take (dec (cell-count table-contents)) (table {:widths (into [20] (take (dec (cell-count table-contents))

View File

@@ -185,11 +185,11 @@
(:location x))])))) (:location x))]))))
(defn aggregate-accounts [pnl-data] (defn aggregate-accounts [pnl-data]
(reduce (fnil + 0.0) 0.0 (map :amount (:data pnl-data)))) (reduce (fnil + 0.0) 0.0 (map (comp or-0 :amount) (:data pnl-data))))
(defn aggregate-cashflow-accounts [pnl-data] (defn aggregate-cashflow-accounts [pnl-data]
(reduce (fnil + 0.0) 0.0 (map (fn [d] (reduce (fnil + 0.0) 0.0 (map (comp or-0 (fn [d]
(cashflow-account->amount (:numeric-code d) (:amount d))) (cashflow-account->amount (:numeric-code d) (:amount d))))
(:data pnl-data)))) (:data pnl-data))))
(defn aggregate-credits [pnl-data] (defn aggregate-credits [pnl-data]
@@ -260,6 +260,8 @@
(defn filter-period [pnl-data period] (defn filter-period [pnl-data period]
(-> pnl-data (-> pnl-data
(update :data (fn [data] (update :data (fn [data]
#_(println "THE PERIOD IS" period
(take 3 ((group-by :period data) period)))
((group-by :period data) period))) ((group-by :period data) period)))
(update :filters (fn [f] (update :filters (fn [f]
(assoc f :date-range period))))) (assoc f :date-range period)))))
@@ -498,6 +500,10 @@
this-name-exists? (->> (:data p) this-name-exists? (->> (:data p)
(filter (comp #{name} :name)) (filter (comp #{name} :name))
seq)] seq)]
(if ( = 40000 numeric-code)
(do (println "TEST HERE" numeric-code)
(clojure.pprint/pprint pnl-data))
)
(merge (merge
(if this-name-exists? (if this-name-exists?
{:format :dollar {:format :dollar