transactions page progress.

This commit is contained in:
2025-03-02 20:09:40 -08:00
parent 3d65816d9c
commit 7c7fc10a8d
11 changed files with 1340 additions and 29 deletions

View File

@@ -0,0 +1,165 @@
(def to-remove (dc/q '[:find (pull ?p [{:payment/client [:client/code]}
[:payment/date :xform clj-time.coerce/from-date]
:payment/amount
:db/id])
:where [?ip :invoice-payment/payment ?p]
[?p :payment/status :payment-status/cleared]
(not [?ip :invoice-payment/invoice]) ]
(dc/db conn)))
#'user/to-remove
(def to-remove-ids (into #{} (map (comp :db/id first) to-remove)))
(def new-invoice-fixes
(into [] (dc/q '[:find ?ip ?pi ?pa ?deleted-invoice-number ?target-i ?target-total
:in $ $$ [ ?pi ...]
:where
[?pi :payment/client ?c]
[?c :client/code "NGPX"]
[?pi :payment/amount ?pa]
[?ip :invoice-payment/payment ?pi]
(not [?ip :invoice-payment/invoice])
[$$ ?ip :invoice-payment/invoice ?deleted-i _ true]
[$$ ?deleted-i :invoice/invoice-number ?deleted-invoice-number _ true]
[?target-i :invoice/client ?c]
[?target-i :invoice/status :invoice-status/unpaid]
[?target-i :invoice/invoice-number ?deleted-invoice-number]
[?target-i :invoice/total ?target-total]
#_[(iol-ion.query/dollars= ?target-total ?deleted-i-total)]]
(dc/db conn)
(dc/history (dc/db conn))
to-remove-ids)))
(reduce
(fn [acc [pi t invoice number a]]
(-> acc
(assoc-in [ pi :total] t)
(update-in [ pi :fixes-total] (fnil + 0.0) a)
(update-in [ pi :fixes-list] (fnil conj []) [invoice number])))
{}
new-invoice-fixes )
;;=> {17592295145246
;; {:total 3026.2300000000005,
;; :fixes-total 4074.4900000000016,
;; :fixes-list
;; [["549126264" 17592339946782]
;; ["549127019" 17592339946787]
;; ["549117468" 17592339946772]
;; ["549130300" 17592339946792]
;; ["549121810" 17592339946777]
;; ["549114455" 17592339946767]
;; ["549137551" 17592339946802]]},
;; 17592295143072
;; {:total 7360.6,
;; :fixes-total 3888.9599999999996,
;; :fixes-list
;; [["549136814" 17592339946797]
;; ["549139494" 17592339946807]
;; ["549139495" 17592339946812]]}}
;;
(def link-to-new-invoices (for [[ip _ _ _ i] new-invoice-fixes
n [[:db/add ip :invoice-payment/invoice i]
[:db/add i :invoice/status :invoice-status/paid]
[:db/add i :invoice/outstanding-balance 0.0]]]
n))
(def with-new-invoice-fixes (:db-after (dc/with (dc/db conn)
link-to-new-invoices)))
(def recreate-invoice-fixes
(into []
(dc/q '[:find (pull $$$ ?deleted-i [*] ) ?extant-ledger ?ip
:in $ $$ $$$ [ ?p ...]
:where
[?p :payment/client ?c]
[?p :payment/amount ?a]
[?c :client/code "NGPX"]
[?ip :invoice-payment/payment ?p]
(not [?ip :invoice-payment/invoice])
[$$ ?ip :invoice-payment/invoice ?deleted-i _ true]
[$$ ?deleted-i :invoice/invoice-number ?deleted-invoice-number _ true]
[$$ ?deleted-i :invoice/total ?deleted-invoice-total _ true]
[$$ ?extant-ledger :journal-entry/original-entity ?deleted-i _ true]
[?extant-ledger :journal-entry/date ?d]
(not [?extant-ledger :journal-entry/original-entity ?deleted-i])
#_[?target-i :invoice/client ?c]
#_[?target-i :invoice/status :invoice-status/unpaid]
#_[?target-i :invoice/invoice-number ?deleted-invoice-number]
#_[?target-i :invoice/total ?target-total]
#_[(iol-ion.query/dollars= ?target-total ?deleted-i-total)]]
with-new-invoice-fixes
(dc/history (dc/db conn))
(dc/as-of (dc/db conn) #inst "2023-10-01")
to-remove-ids)))
;;=> #'user/recreate-invoice-fixes
;;
recreate-invoice-fixes
(def recreate-invoices
(for [[{:keys [db/id] :as i} je ip] recreate-invoice-fixes
n [(assoc i :invoice/status :invoice-status/paid :invoice/outstanding-balance 0.0)
{:db/id ip :invoice-payment/invoice id}
{:db/id je :journal-entry/original-entity id}]]
n))
to-remove-ids
(def with-recreate-invoices
(:db-after (dc/with
with-new-invoice-fixes
recreate-invoices
)))
(into []
(dc/q '[:find ?a (sum ?ipa) (sum ?it) (pull ?p [:payment/amount :payment/date :payment/memo {:invoice-payment/_payment [:invoice-payment/amount {:invoice-payment/invoice [:invoice/invoice-number :invoice/total]}]}])
:with ?ip
:in $ [ ?p ...]
:where
[?p :payment/client ?c]
[?p :payment/amount ?a]
[?c :client/code "NGPX"]
[?ip :invoice-payment/payment ?p]
[?ip :invoice-payment/amount ?ipa ]
[?ip :invoice-payment/invoice ?i]
[?i :invoice/total ?it]
#_(not [?ip :invoice-payment/invoice])
#_[$$ ?ip :invoice-payment/invoice ?deleted-i _ true]
#_[$$ ?deleted-i :invoice/invoice-number ?deleted-invoice-number _ true]
#_[$$ ?deleted-i :invoice/total ?deleted-invoice-total _ true]
#_[$$ ?extant-ledger :journal-entry/original-entity ?deleted-i _ true]
#_[?extant-ledger :journal-entry/date ?d]
#_(not [?extant-ledger :journal-entry/original-entity ?deleted-i])
#_[?target-i :invoice/client ?c]
#_[?target-i :invoice/status :invoice-status/unpaid]
#_[?target-i :invoice/invoice-number ?deleted-invoice-number]
#_[?target-i :invoice/total ?target-total]
#_[(iol-ion.query/dollars= ?target-total ?deleted-i-total)]]
with-recreate-invoices
to-remove-ids))
(dc/pull (dc/db conn)
'[*]
17592295143072)
(reverse (sort (dc/q '[:find ?d
:where [?je :journal-entry/source "invoice"]
(not [?je :journal-entry/original-entity])
[?je :journal-entry/date ?d]]
(dc/db conn))))

View File

@@ -259,6 +259,7 @@
:oob (or oob []))))
(def next-handler
(-> (fn [{:keys [wizard] :as request}]
(let [current-step (get-current-step wizard)]
(if (satisfies? CustomNext current-step)

View File

@@ -12,6 +12,7 @@
[auto-ap.ssr-routes :as ssr-routes]
[auto-ap.ssr.components :as com]
[auto-ap.ssr.components.link-dropdown :refer [link-dropdown]]
[auto-ap.ssr.transaction.edit :as edit]
[auto-ap.ssr.grid-page-helper :as helper :refer [wrap-apply-sort]]
[auto-ap.ssr.hx :as hx]
[auto-ap.ssr.ledger :refer [wrap-ensure-bank-account-belongs]]
@@ -271,17 +272,10 @@
::route/new)}
"Add Transaction")])
:row-buttons (fn [request entity]
[#_(when (and (can? (:identity request) {:subject :transaction :activity :edit}))
(com/icon-button {:hx-put (bidi/path-for ssr-routes/only-routes
::route/edit-wizard
:db/id (:db/id entity))}
svg/pencil))
#_(when (and (can? (:identity request) {:subject :transaction :activity :delete}))
(com/icon-button {:hx-delete (bidi/path-for ssr-routes/only-routes
::route/delete
:db/id (:db/id entity))
:hx-confirm "Are you sure you want to delete this transaction?"}
svg/trash))])
[(com/icon-button {:hx-get (bidi/path-for ssr-routes/only-routes
::route/edit-wizard
:db/id (:db/id entity))}
svg/pencil)])
:breadcrumbs [[:a {:href (bidi/path-for ssr-routes/only-routes ::route/page)}
"Transactions"]]
@@ -290,6 +284,10 @@
:entity-name "register"
:route ::route/table
:csv-route ::route/csv
:table-attributes (fn [_]
{:hx-trigger "refreshTable from:body"
:hx-get (bidi/path-for ssr-routes/only-routes ::route/table)
:hx-target "#entity-table"})
:break-table (fn [request entity]
(cond
(= (-> request :query-params :sort first :name) "Vendor")
@@ -375,18 +373,19 @@
(def csv (helper/csv-route grid-page))
(def key->handler
(apply-middleware-to-all-handlers
{::route/page page
::route/table table
::route/csv csv
::route/bank-account-filter bank-account-filter}
(fn [h]
(-> h
(wrap-copy-qp-pqp)
(wrap-apply-sort grid-page)
(merge edit/key->handler
(apply-middleware-to-all-handlers
{::route/page page
::route/table table
::route/csv csv
::route/bank-account-filter bank-account-filter}
(fn [h]
(-> h
(wrap-copy-qp-pqp)
(wrap-apply-sort grid-page)
(wrap-ensure-bank-account-belongs)
(wrap-merge-prior-hx)
(wrap-schema-enforce :query-schema query-schema)
(wrap-schema-enforce :hx-schema query-schema)
(wrap-must {:activity :view :subject :transaction})
(wrap-client-redirect-unauthenticated)))))
(wrap-schema-enforce :query-schema query-schema)
(wrap-schema-enforce :hx-schema query-schema)
(wrap-must {:activity :view :subject :transaction})
(wrap-client-redirect-unauthenticated))))))

File diff suppressed because it is too large Load Diff

View File

@@ -329,7 +329,7 @@
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(defn tx-detail [i]
(map (juxt :e #(pull-attr (dc/db conn) :db/ident (:a %)) :v)
(map (juxt :e #(pull-attr (dc/db conn) :db/ident (:a %)) :v :added)
(:data (first
(dc/tx-range (dc/log conn)
i

View File

@@ -1,6 +1,7 @@
(ns auto-ap.routes.transactions)
(def routes {"" {:get ::page}
(def routes {"" {:get ::page
:put ::edit-wizard-navigate}
"/new" {:get ::new
:post ::new-submit
"/location-select" ::location-select
@@ -13,5 +14,18 @@
"/import" ::external-import-import}
"/table" ::table
"/csv" ::csv
"/bank-account-filter" ::bank-account-filter })
"/csv" ::csv
"/bank-account-filter" ::bank-account-filter
["/" [#"\d+" :db/id]] {"/edit" {:get ::edit-wizard
} }
"/edit-submit" ::edit-submit
"/location-select" ::location-select
"/account-total" ::account-total
"/account-balance" ::account-balance
"/edit-wizard-new-account" ::edit-wizard-new-account
"/match-payment" ::match-payment
"/match-autopay-invoices" ::match-autopay-invoices
"/match-unpaid-invoices" ::match-unpaid-invoices
"/apply-rule" ::apply-rule
"/unlink-payment" ::unlink-payment})