Improves balance sheet, starts moving it to new layout
This commit is contained in:
@@ -164,23 +164,59 @@
|
|||||||
(defn ident [x]
|
(defn ident [x]
|
||||||
(:db/ident x))
|
(:db/ident x))
|
||||||
|
|
||||||
(defn account-snapshot [db client-id end]
|
(defn account-sets [db client-id]
|
||||||
(for [ running-balance-set (->> (dc/index-range db :journal-entry-line/running-balance-tuple [client-id] [(inc client-id)])
|
(for [running-balance-set (->> (dc/index-range db :journal-entry-line/running-balance-tuple [client-id] [(inc client-id)])
|
||||||
(seq)
|
(seq)
|
||||||
(partition-by (fn [{[current-client current-account current-location current-date debit credit running-balance]
|
(partition-by (fn [{[current-client current-account current-location current-date debit credit running-balance]
|
||||||
:v}]
|
:v}]
|
||||||
[current-client current-account current-location])))
|
[current-client current-account current-location]))) ]
|
||||||
:let [{id :e [client-id account-id location date _ _ current-balance] :v} (->> running-balance-set
|
(->> running-balance-set
|
||||||
(sort-by (fn [{id :e [_ _ _ current-date] :v}]
|
(sort-by (fn [{id :e [_ _ _ current-date] :v}]
|
||||||
[current-date id]))
|
[current-date id])))))
|
||||||
(take-while (fn [{id :e [_ _ _ current-date] :v}]
|
|
||||||
(<= (.compareTo current-date end) 0)))
|
(defn account-snapshot [db client-id end]
|
||||||
last)]
|
(for [running-balance-set (account-sets db client-id)
|
||||||
|
:let [{id :e [client-id account-id location date _ _ current-balance] :v}
|
||||||
|
(->> running-balance-set
|
||||||
|
(take-while (fn [{id :e [_ _ _ current-date] :v}]
|
||||||
|
(<= (.compareTo current-date end) 0)))
|
||||||
|
last)]
|
||||||
:when id]
|
:when id]
|
||||||
[client-id account-id location date current-balance]))
|
[client-id account-id location date current-balance]))
|
||||||
|
|
||||||
|
(defn detailed-account-snapshot [db client-id end]
|
||||||
|
(for [running-balance-set (account-sets db client-id)
|
||||||
|
:let [{:keys [account-id client-id location current-balance debits credits count]}
|
||||||
|
(->> running-balance-set
|
||||||
|
|
||||||
|
(take-while (fn [{id :e [_ _ _ current-date] :v}]
|
||||||
|
(<= (.compareTo current-date end) 0)))
|
||||||
|
(reduce
|
||||||
|
(fn [acc {id :e [current-client current-account current-location current-date debit credit balance] :v}]
|
||||||
|
(-> acc
|
||||||
|
(update :count inc)
|
||||||
|
(update :debits + (or debit 0.0))
|
||||||
|
(update :credits + (or credit 0.0))
|
||||||
|
(assoc :current-balance balance
|
||||||
|
:account-id current-account
|
||||||
|
:client-id current-client
|
||||||
|
:location current-location)))
|
||||||
|
{: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
|
||||||
#_(account-snapshot (dc/db auto-ap.datomic/conn)
|
(detailed-account-snapshot (dc/db auto-ap.datomic/conn)
|
||||||
|
(auto-ap.datomic/pull-id (dc/db auto-ap.datomic/conn)
|
||||||
|
[:client/code "NGOP"])
|
||||||
|
#inst "2024-01-01")
|
||||||
|
|
||||||
|
(account-snapshot (dc/db auto-ap.datomic/conn)
|
||||||
(auto-ap.datomic/pull-id (dc/db auto-ap.datomic/conn)
|
(auto-ap.datomic/pull-id (dc/db auto-ap.datomic/conn)
|
||||||
[:client/code "NGOP"])
|
[:client/code "NGOP"])
|
||||||
#inst "2022-01-01")
|
#inst "2022-01-01")
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -9,20 +9,6 @@
|
|||||||
|
|
||||||
(take 5 (:transactions g))
|
(take 5 (:transactions g))
|
||||||
|
|
||||||
;; => ({:account_id "Dpj0d9yKmXsOxBd0eaL4UONyEJYomNIX7kba3",
|
|
||||||
;; :balances
|
|
||||||
;; {:available nil,
|
|
||||||
;; :current 17764.42,
|
|
||||||
;; :iso_currency_code "USD",
|
|
||||||
;; :limit nil,
|
|
||||||
;; :unofficial_currency_code nil},
|
|
||||||
;; :mask "1006",
|
|
||||||
;; :name "NICHOLAS TAPTELIS -91006",
|
|
||||||
;; :official_name "Business Gold Rewards Card",
|
|
||||||
;; :subtype "credit card",
|
|
||||||
;; :type "credit"})
|
|
||||||
|
|
||||||
|
|
||||||
(dc/q '[:find (pull ?pa [{ :plaid-item/_accounts [*]}])
|
(dc/q '[:find (pull ?pa [{ :plaid-item/_accounts [*]}])
|
||||||
:in $ ?ba
|
:in $ ?ba
|
||||||
:where [?ba :bank-account/plaid-account ?pa]]
|
:where [?ba :bank-account/plaid-account ?pa]]
|
||||||
@@ -84,3 +70,5 @@
|
|||||||
|
|
||||||
(user/init-repl)
|
(user/init-repl)
|
||||||
(p/get-transactions "access-production-bbd2330c-af72-4dd4-b3e1-afdca396b3d5" "bYEM58wRZRsJzyr5D6DkTE0nMyjdmPHDrkLAz" (clj-time.coerce/to-date-time #inst "2024-09-01") (clj-time.coerce/to-date-time #inst "2024-09-25"))
|
(p/get-transactions "access-production-bbd2330c-af72-4dd4-b3e1-afdca396b3d5" "bYEM58wRZRsJzyr5D6DkTE0nMyjdmPHDrkLAz" (clj-time.coerce/to-date-time #inst "2024-09-01") (clj-time.coerce/to-date-time #inst "2024-09-25"))
|
||||||
|
|
||||||
|
(p/get-transactions "access-production-b2efac2f-b8eb-408a-9391-eae996c5ac46" "JX3DpxLRDrS3gJje43BeIXRdONAd09IbxmbwE" (clj-time.coerce/to-date-time #inst "2024-09-01") (clj-time.coerce/to-date-time #inst "2024-09-25"))
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
[auto-ap.logging :as alog]
|
[auto-ap.logging :as alog]
|
||||||
[clj-time.coerce :as c]
|
[clj-time.coerce :as c]
|
||||||
[clj-time.core :as t]
|
[clj-time.core :as t]
|
||||||
|
[iol-ion.query :refer [account-sets]]
|
||||||
[com.brunobonacci.mulog :as mu]
|
[com.brunobonacci.mulog :as mu]
|
||||||
[com.unbounce.dogstatsd.core :as statsd]
|
[com.unbounce.dogstatsd.core :as statsd]
|
||||||
[datomic.api :as dc]
|
[datomic.api :as dc]
|
||||||
@@ -410,6 +411,7 @@
|
|||||||
:bank-account/current-balance-synced (c/to-date (t/now))
|
:bank-account/current-balance-synced (c/to-date (t/now))
|
||||||
:bank-account/current-balance running-balance}])))))))
|
:bank-account/current-balance running-balance}])))))))
|
||||||
|
|
||||||
|
;; TODO using iol-ion query as the base, building running balance sets
|
||||||
(defn upsert-running-balance []
|
(defn upsert-running-balance []
|
||||||
(mu/with-context {:service "upsert-running-balance"
|
(mu/with-context {:service "upsert-running-balance"
|
||||||
:source "upsert-running-balance" }
|
:source "upsert-running-balance" }
|
||||||
@@ -424,14 +426,8 @@
|
|||||||
changes (for [c clients
|
changes (for [c clients
|
||||||
:let [client-id (:db/id c)
|
:let [client-id (:db/id c)
|
||||||
account-lookup (build-account-lookup client-id)]
|
account-lookup (build-account-lookup client-id)]
|
||||||
running-balance-set (->> (dc/index-range db :journal-entry-line/running-balance-tuple [client-id] [(inc client-id)])
|
running-balance-set (account-sets db client-id)
|
||||||
(seq)
|
|
||||||
(partition-by (fn [{[current-client current-account current-location current-date debit credit running-balance]
|
|
||||||
:v}]
|
|
||||||
[current-client current-account current-location])))
|
|
||||||
running-balance-change (->> running-balance-set
|
running-balance-change (->> running-balance-set
|
||||||
(sort-by (fn [{id :e [_ _ _ current-date] :v}]
|
|
||||||
[current-date id]))
|
|
||||||
(reduce
|
(reduce
|
||||||
(fn [{:keys [changes last-running-balance]}
|
(fn [{:keys [changes last-running-balance]}
|
||||||
{id :e
|
{id :e
|
||||||
|
|||||||
@@ -233,7 +233,7 @@
|
|||||||
["intuit" "Intuit import"]
|
["intuit" "Intuit import"]
|
||||||
["plaid" "Plaid import"]
|
["plaid" "Plaid import"]
|
||||||
["bulk-journal-import" "Bulk Journal Import"]
|
["bulk-journal-import" "Bulk Journal Import"]
|
||||||
["square2-import-job" "Square2 Import"]
|
["square-import-job" "Square Import"]
|
||||||
["register-invoice-import" "Register Invoice Import "]
|
["register-invoice-import" "Register Invoice Import "]
|
||||||
["ezcater-upsert" "Upsert recent ezcater orders"]
|
["ezcater-upsert" "Upsert recent ezcater orders"]
|
||||||
["load-historical-sales" "Load Historical Square Sales"]
|
["load-historical-sales" "Load Historical Square Sales"]
|
||||||
|
|||||||
@@ -47,6 +47,7 @@
|
|||||||
(def field inputs/field-)
|
(def field inputs/field-)
|
||||||
(def inline-field inputs/inline-field-)
|
(def inline-field inputs/inline-field-)
|
||||||
(def validated-field inputs/validated-field-)
|
(def validated-field inputs/validated-field-)
|
||||||
|
(def validated-inline-field inputs/validated-inline-field-)
|
||||||
(def errors inputs/errors-)
|
(def errors inputs/errors-)
|
||||||
(def form-errors inputs/form-errors-)
|
(def form-errors inputs/form-errors-)
|
||||||
|
|
||||||
@@ -58,6 +59,7 @@
|
|||||||
(def card card/card-)
|
(def card card/card-)
|
||||||
|
|
||||||
(def navbar navbar/navbar-)
|
(def navbar navbar/navbar-)
|
||||||
|
(def toggle inputs/toggle-)
|
||||||
|
|
||||||
(def page page/page-)
|
(def page page/page-)
|
||||||
(def radio-card radio/radio-card-)
|
(def radio-card radio/radio-card-)
|
||||||
|
|||||||
@@ -130,6 +130,7 @@
|
|||||||
"No results found"]]]]])
|
"No results found"]]]]])
|
||||||
|
|
||||||
(defn multi-typeahead- [params]
|
(defn multi-typeahead- [params]
|
||||||
|
(println "VALUE IS" (:value params))
|
||||||
[:div.relative {:x-data (hx/json {:open false
|
[:div.relative {:x-data (hx/json {:open false
|
||||||
:baseUrl (if (str/includes? (:url params) "?")
|
:baseUrl (if (str/includes? (:url params) "?")
|
||||||
(str (:url params) "&q=")
|
(str (:url params) "&q=")
|
||||||
@@ -163,7 +164,7 @@
|
|||||||
(dissoc :class :value-fn :content-fn :placeholder :x-model)
|
(dissoc :class :value-fn :content-fn :placeholder :x-model)
|
||||||
(assoc
|
(assoc
|
||||||
:type "hidden"
|
:type "hidden"
|
||||||
"x-bind:value" "v"
|
"x-bind:value" "v.value"
|
||||||
))]]
|
))]]
|
||||||
[:div.flex.w-full.justify-items-stretch
|
[:div.flex.w-full.justify-items-stretch
|
||||||
[:span.flex-grow.text-left [:span {"x-text" "value.length"} ]
|
[:span.flex-grow.text-left [:span {"x-text" "value.length"} ]
|
||||||
@@ -204,7 +205,7 @@
|
|||||||
"placeholder" (:placeholder params)
|
"placeholder" (:placeholder params)
|
||||||
"@keydown.down.prevent" "active ++; active = active >= elements.length - 1 ? elements.length - 1 : active"
|
"@keydown.down.prevent" "active ++; active = active >= elements.length - 1 ? elements.length - 1 : active"
|
||||||
"@keydown.up.prevent" "active --; active = active < 0 ? 0 : active"
|
"@keydown.up.prevent" "active --; active = active < 0 ? 0 : active"
|
||||||
"@keydown.enter.prevent.stop" "if ($data.elements[active]) { value.push($data.elements[active].value) }"
|
"@keydown.enter.prevent.stop" "if ($data.elements[active]) { value.push($data.elements[active]) }"
|
||||||
"x-init" "$watch('search', s => { if($el.value.length > 2) {fetch(baseUrl + s).then(data=>data.json()).then(data => {elements = data; active=-1}) }})"}]
|
"x-init" "$watch('search', s => { if($el.value.length > 2) {fetch(baseUrl + s).then(data=>data.json()).then(data => {elements = data; active=-1}) }})"}]
|
||||||
[:div.dropdown-options {:class "rounded-b-lg overflow-hidden"}
|
[:div.dropdown-options {:class "rounded-b-lg overflow-hidden"}
|
||||||
[:template {:x-for "(element, index) in elements"}
|
[:template {:x-for "(element, index) in elements"}
|
||||||
@@ -214,7 +215,7 @@
|
|||||||
":class" "active == index ? 'active' : ''"
|
":class" "active == index ? 'active' : ''"
|
||||||
"@mouseover" "active = index"
|
"@mouseover" "active = index"
|
||||||
"@mouseout" "active = -1"
|
"@mouseout" "active = -1"
|
||||||
"@click.prevent" "value.push(element.value);"
|
"@click.prevent" "value.push({value: element.value, label: element.label});"
|
||||||
}
|
}
|
||||||
[ :input {:type "checkbox" ":checked" "value.includes(element.value)"} ]
|
[ :input {:type "checkbox" ":checked" "value.includes(element.value)"} ]
|
||||||
[:span {"x-html" "element.label"}]]]]
|
[:span {"x-html" "element.label"}]]]]
|
||||||
@@ -329,6 +330,13 @@
|
|||||||
rest
|
rest
|
||||||
(errors- {:errors (:errors params)})))
|
(errors- {:errors (:errors params)})))
|
||||||
|
|
||||||
|
(defn validated-inline-field- [params & rest]
|
||||||
|
(inline-field- (cond-> params
|
||||||
|
true (dissoc :errors)
|
||||||
|
(sequential? (:errors params)) (update :class #(hh/add-class (or % "") "has-error")))
|
||||||
|
rest
|
||||||
|
(errors- {:errors (:errors params)})))
|
||||||
|
|
||||||
(defn hidden- [{:keys [name value] :as params}]
|
(defn hidden- [{:keys [name value] :as params}]
|
||||||
[:input (merge {:type "hidden" :value value :name name} params)])
|
[:input (merge {:type "hidden" :value value :name name} params)])
|
||||||
|
|
||||||
@@ -340,3 +348,9 @@
|
|||||||
rest]]
|
rest]]
|
||||||
[:input (merge params {:type "checkbox" :class (hh/add-class default-checkbox-classes (:class params ""))})
|
[:input (merge params {:type "checkbox" :class (hh/add-class default-checkbox-classes (:class params ""))})
|
||||||
]))
|
]))
|
||||||
|
|
||||||
|
(defn toggle- [params & children]
|
||||||
|
[:label {:class "inline-flex items-center cursor-pointer"}
|
||||||
|
[:input (merge {:type "checkbox", :class "sr-only peer"} params)]
|
||||||
|
[:div {:class "relative w-11 h-6 bg-gray-200 peer-focus:outline-none peer-focus:ring-4 peer-focus:ring-blue-300 dark:peer-focus:ring-blue-800 rounded-full peer dark:bg-gray-700 peer-checked:after:translate-x-full rtl:peer-checked:after:-translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:start-[2px] after:bg-white after:border-gray-300 after:border after:rounded-full after:h-5 after:w-5 after:transition-all dark:border-gray-600 peer-checked:bg-blue-600"}]
|
||||||
|
[:span {:class "ms-3 text-sm font-medium text-gray-900 dark:text-gray-300"} children]])
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -808,14 +808,19 @@
|
|||||||
{:value "+/-"}]))))))))
|
{:value "+/-"}]))))))))
|
||||||
|
|
||||||
(defn append-deltas [table]
|
(defn append-deltas [table]
|
||||||
(->> table
|
(->> table
|
||||||
(map (fn [[title a b]]
|
(map (fn [[title & pairs]]
|
||||||
[title a b (and (:value a) (:value b)
|
(reduce
|
||||||
(number? (:value a)) (number? (:value b))
|
(fn [result [ a b]]
|
||||||
{:border (:border b)
|
(into result
|
||||||
:format :dollar
|
[a b (and (:value a) (:value b)
|
||||||
:value (- (doto (or (:value a) 0.0) println)
|
(number? (:value a)) (number? (:value b))
|
||||||
(doto (or (:value b) 0.0) println))})]))))
|
{:border (:border b)
|
||||||
|
:format :dollar
|
||||||
|
:value (- (or (:value a) 0.0)
|
||||||
|
(or (:value b) 0.0))})]))
|
||||||
|
[title]
|
||||||
|
(partition 2 pairs))))))
|
||||||
|
|
||||||
|
|
||||||
#_(defn summarize-balance-sheet [pnl-data]
|
#_(defn summarize-balance-sheet [pnl-data]
|
||||||
@@ -867,8 +872,7 @@
|
|||||||
p (:periods (:args pnl-data))]
|
p (:periods (:args pnl-data))]
|
||||||
(-> pnl-data
|
(-> pnl-data
|
||||||
(filter-client client-id)
|
(filter-client client-id)
|
||||||
(filter-period p))
|
(filter-period p)))]
|
||||||
)]
|
|
||||||
(let [table (-> []
|
(let [table (-> []
|
||||||
(into (detail-rows pnl-datas
|
(into (detail-rows pnl-datas
|
||||||
:assets
|
:assets
|
||||||
@@ -880,11 +884,11 @@
|
|||||||
:equities
|
:equities
|
||||||
"Owner's Equity"))
|
"Owner's Equity"))
|
||||||
(conj (subtotal-by-column-row
|
(conj (subtotal-by-column-row
|
||||||
(map #(-> %
|
(map #(-> %
|
||||||
(filter-categories [:sales :cogs :payroll :controllable :fixed-overhead :ownership-controllable])
|
(filter-categories [:sales :cogs :payroll :controllable :fixed-overhead :ownership-controllable])
|
||||||
(negate #{:cogs :payroll :controllable :fixed-overhead :ownership-controllable}))
|
(negate #{:cogs :payroll :controllable :fixed-overhead :ownership-controllable}))
|
||||||
pnl-datas)
|
pnl-datas)
|
||||||
"Retained Earnings")))
|
"Retained Earnings")))
|
||||||
table (if (:include-comparison (:args pnl-data))
|
table (if (:include-comparison (:args pnl-data))
|
||||||
(append-deltas table)
|
(append-deltas table)
|
||||||
table)]
|
table)]
|
||||||
|
|||||||
Reference in New Issue
Block a user