supporting fixing of check numbers.
This commit is contained in:
@@ -62,6 +62,7 @@
|
|||||||
:auto-ap/add-default-location-2 {:txes-fn 'auto-ap.datomic.migrate.invoice-converter/add-default-location-2 :requires [:auto-ap/add-default-location]}
|
:auto-ap/add-default-location-2 {:txes-fn 'auto-ap.datomic.migrate.invoice-converter/add-default-location-2 :requires [:auto-ap/add-default-location]}
|
||||||
:auto-ap/add-import-status {:txes auto-ap.datomic.migrate.invoice-converter/add-import-status :requires [:auto-ap/add-default-location-2]}
|
:auto-ap/add-import-status {:txes auto-ap.datomic.migrate.invoice-converter/add-import-status :requires [:auto-ap/add-default-location-2]}
|
||||||
:auto-ap/add-import-status-existing-invoices {:txes-fn 'auto-ap.datomic.migrate.invoice-converter/add-import-status-existing-invoices :requires [:auto-ap/add-import-status]}
|
:auto-ap/add-import-status-existing-invoices {:txes-fn 'auto-ap.datomic.migrate.invoice-converter/add-import-status-existing-invoices :requires [:auto-ap/add-import-status]}
|
||||||
|
:auto-ap/fix-check-numbers {:txes-fn 'auto-ap.datomic.migrate.check-numbers/fix-check-numbers :requires [:auto-ap/add-import-status-existing-invoices]}
|
||||||
}]
|
}]
|
||||||
(println "Conforming database...")
|
(println "Conforming database...")
|
||||||
(println (c/ensure-conforms conn norms-map))
|
(println (c/ensure-conforms conn norms-map))
|
||||||
|
|||||||
8
src/clj/auto_ap/datomic/migrate/check_numbers.clj
Normal file
8
src/clj/auto_ap/datomic/migrate/check_numbers.clj
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
(ns auto-ap.datomic.migrate.check-numbers
|
||||||
|
(:require [datomic.api :as d]))
|
||||||
|
|
||||||
|
(defn fix-check-numbers [conn]
|
||||||
|
(let [max-check-numbers (d/query {:query {:find '[?e ?check-number (max ?d)] :in ['$] :where ['[?e :bank-account/check-number ?check-number] '[?c :payment/bank-account ?e] '[?c :payment/check-number ?d]]} :args [(d/db conn)]})]
|
||||||
|
[(for [[bank-account check-number max-check client] max-check-numbers
|
||||||
|
:when (>= max-check check-number)]
|
||||||
|
{:db/id bank-account :payment/check-number (inc max-check)})]))
|
||||||
@@ -254,7 +254,6 @@
|
|||||||
|
|
||||||
(-> []
|
(-> []
|
||||||
(conj payment)
|
(conj payment)
|
||||||
(conj [:inc (:db/id bank-account) :bank-account/check-number 1])
|
|
||||||
(into (invoice-payments invoices invoice-amounts)))))
|
(into (invoice-payments invoices invoice-amounts)))))
|
||||||
|
|
||||||
|
|
||||||
@@ -289,7 +288,10 @@
|
|||||||
checks (->> (for [[[vendor-id invoices] index] (map vector invoices-grouped-by-vendor (range))]
|
checks (->> (for [[[vendor-id invoices] index] (map vector invoices-grouped-by-vendor (range))]
|
||||||
(invoices->entities invoices (vendors vendor-id) client bank-account type index invoice-amounts))
|
(invoices->entities invoices (vendors vendor-id) client bank-account type index invoice-amounts))
|
||||||
(reduce into [])
|
(reduce into [])
|
||||||
doall)]
|
doall)
|
||||||
|
checks (if (= type :payment-type/check)
|
||||||
|
(conj checks [:inc (:db/id bank-account) :bank-account/check-number (count invoices-grouped-by-vendor)])
|
||||||
|
checks)]
|
||||||
(when (= type :payment-type/check)
|
(when (= type :payment-type/check)
|
||||||
(make-pdfs (filter #(= :payment-type/check (:payment/type %)) checks)))
|
(make-pdfs (filter #(= :payment-type/check (:payment/type %)) checks)))
|
||||||
@(d/transact (d/connect uri) checks)
|
@(d/transact (d/connect uri) checks)
|
||||||
|
|||||||
Reference in New Issue
Block a user