Improves balance sheet, starts moving it to new layout
This commit is contained in:
@@ -164,23 +164,59 @@
|
||||
(defn ident [x]
|
||||
(:db/ident x))
|
||||
|
||||
(defn account-snapshot [db client-id end]
|
||||
(for [ running-balance-set (->> (dc/index-range db :journal-entry-line/running-balance-tuple [client-id] [(inc client-id)])
|
||||
(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)])
|
||||
(seq)
|
||||
(partition-by (fn [{[current-client current-account current-location current-date debit credit running-balance]
|
||||
:v}]
|
||||
[current-client current-account current-location])))
|
||||
:let [{id :e [client-id account-id location date _ _ current-balance] :v} (->> running-balance-set
|
||||
(sort-by (fn [{id :e [_ _ _ current-date] :v}]
|
||||
[current-date id]))
|
||||
(take-while (fn [{id :e [_ _ _ current-date] :v}]
|
||||
(<= (.compareTo current-date end) 0)))
|
||||
last)]
|
||||
[current-client current-account current-location]))) ]
|
||||
(->> running-balance-set
|
||||
(sort-by (fn [{id :e [_ _ _ current-date] :v}]
|
||||
[current-date id])))))
|
||||
|
||||
(defn account-snapshot [db client-id end]
|
||||
(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]
|
||||
[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
|
||||
#_(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)
|
||||
[:client/code "NGOP"])
|
||||
#inst "2022-01-01")
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -9,20 +9,6 @@
|
||||
|
||||
(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 [*]}])
|
||||
:in $ ?ba
|
||||
:where [?ba :bank-account/plaid-account ?pa]]
|
||||
@@ -84,3 +70,5 @@
|
||||
|
||||
(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-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]
|
||||
[clj-time.coerce :as c]
|
||||
[clj-time.core :as t]
|
||||
[iol-ion.query :refer [account-sets]]
|
||||
[com.brunobonacci.mulog :as mu]
|
||||
[com.unbounce.dogstatsd.core :as statsd]
|
||||
[datomic.api :as dc]
|
||||
@@ -410,6 +411,7 @@
|
||||
:bank-account/current-balance-synced (c/to-date (t/now))
|
||||
:bank-account/current-balance running-balance}])))))))
|
||||
|
||||
;; TODO using iol-ion query as the base, building running balance sets
|
||||
(defn upsert-running-balance []
|
||||
(mu/with-context {:service "upsert-running-balance"
|
||||
:source "upsert-running-balance" }
|
||||
@@ -424,14 +426,8 @@
|
||||
changes (for [c clients
|
||||
:let [client-id (:db/id c)
|
||||
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)])
|
||||
(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-set (account-sets db client-id)
|
||||
running-balance-change (->> running-balance-set
|
||||
(sort-by (fn [{id :e [_ _ _ current-date] :v}]
|
||||
[current-date id]))
|
||||
(reduce
|
||||
(fn [{:keys [changes last-running-balance]}
|
||||
{id :e
|
||||
|
||||
@@ -233,7 +233,7 @@
|
||||
["intuit" "Intuit import"]
|
||||
["plaid" "Plaid import"]
|
||||
["bulk-journal-import" "Bulk Journal Import"]
|
||||
["square2-import-job" "Square2 Import"]
|
||||
["square-import-job" "Square Import"]
|
||||
["register-invoice-import" "Register Invoice Import "]
|
||||
["ezcater-upsert" "Upsert recent ezcater orders"]
|
||||
["load-historical-sales" "Load Historical Square Sales"]
|
||||
|
||||
@@ -47,6 +47,7 @@
|
||||
(def field inputs/field-)
|
||||
(def inline-field inputs/inline-field-)
|
||||
(def validated-field inputs/validated-field-)
|
||||
(def validated-inline-field inputs/validated-inline-field-)
|
||||
(def errors inputs/errors-)
|
||||
(def form-errors inputs/form-errors-)
|
||||
|
||||
@@ -58,6 +59,7 @@
|
||||
(def card card/card-)
|
||||
|
||||
(def navbar navbar/navbar-)
|
||||
(def toggle inputs/toggle-)
|
||||
|
||||
(def page page/page-)
|
||||
(def radio-card radio/radio-card-)
|
||||
|
||||
@@ -130,6 +130,7 @@
|
||||
"No results found"]]]]])
|
||||
|
||||
(defn multi-typeahead- [params]
|
||||
(println "VALUE IS" (:value params))
|
||||
[:div.relative {:x-data (hx/json {:open false
|
||||
:baseUrl (if (str/includes? (:url params) "?")
|
||||
(str (:url params) "&q=")
|
||||
@@ -163,7 +164,7 @@
|
||||
(dissoc :class :value-fn :content-fn :placeholder :x-model)
|
||||
(assoc
|
||||
:type "hidden"
|
||||
"x-bind:value" "v"
|
||||
"x-bind:value" "v.value"
|
||||
))]]
|
||||
[:div.flex.w-full.justify-items-stretch
|
||||
[:span.flex-grow.text-left [:span {"x-text" "value.length"} ]
|
||||
@@ -204,7 +205,7 @@
|
||||
"placeholder" (:placeholder params)
|
||||
"@keydown.down.prevent" "active ++; active = active >= elements.length - 1 ? elements.length - 1 : 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}) }})"}]
|
||||
[:div.dropdown-options {:class "rounded-b-lg overflow-hidden"}
|
||||
[:template {:x-for "(element, index) in elements"}
|
||||
@@ -214,7 +215,7 @@
|
||||
":class" "active == index ? 'active' : ''"
|
||||
"@mouseover" "active = index"
|
||||
"@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)"} ]
|
||||
[:span {"x-html" "element.label"}]]]]
|
||||
@@ -329,6 +330,13 @@
|
||||
rest
|
||||
(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}]
|
||||
[:input (merge {:type "hidden" :value value :name name} params)])
|
||||
|
||||
@@ -340,3 +348,9 @@
|
||||
rest]]
|
||||
[: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 "+/-"}]))))))))
|
||||
|
||||
(defn append-deltas [table]
|
||||
(->> table
|
||||
(map (fn [[title a b]]
|
||||
[title a b (and (:value a) (:value b)
|
||||
(number? (:value a)) (number? (:value b))
|
||||
{:border (:border b)
|
||||
:format :dollar
|
||||
:value (- (doto (or (:value a) 0.0) println)
|
||||
(doto (or (:value b) 0.0) println))})]))))
|
||||
(->> table
|
||||
(map (fn [[title & pairs]]
|
||||
(reduce
|
||||
(fn [result [ a b]]
|
||||
(into result
|
||||
[a b (and (:value a) (:value b)
|
||||
(number? (:value a)) (number? (:value b))
|
||||
{: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]
|
||||
@@ -867,8 +872,7 @@
|
||||
p (:periods (:args pnl-data))]
|
||||
(-> pnl-data
|
||||
(filter-client client-id)
|
||||
(filter-period p))
|
||||
)]
|
||||
(filter-period p)))]
|
||||
(let [table (-> []
|
||||
(into (detail-rows pnl-datas
|
||||
:assets
|
||||
@@ -880,11 +884,11 @@
|
||||
:equities
|
||||
"Owner's Equity"))
|
||||
(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)
|
||||
"Retained Earnings")))
|
||||
(map #(-> %
|
||||
(filter-categories [:sales :cogs :payroll :controllable :fixed-overhead :ownership-controllable])
|
||||
(negate #{:cogs :payroll :controllable :fixed-overhead :ownership-controllable}))
|
||||
pnl-datas)
|
||||
"Retained Earnings")))
|
||||
table (if (:include-comparison (:args pnl-data))
|
||||
(append-deltas table)
|
||||
table)]
|
||||
|
||||
Reference in New Issue
Block a user