supporting fixing of check numbers.

This commit is contained in:
BC
2019-02-13 21:55:14 -08:00
parent 8bb998dec1
commit 6c4cfadc0b
3 changed files with 13 additions and 2 deletions

View File

@@ -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-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/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 (c/ensure-conforms conn norms-map))

View 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)})]))

View File

@@ -254,7 +254,6 @@
(-> []
(conj payment)
(conj [:inc (:db/id bank-account) :bank-account/check-number 1])
(into (invoice-payments invoices invoice-amounts)))))
@@ -289,7 +288,10 @@
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))
(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)
(make-pdfs (filter #(= :payment-type/check (:payment/type %)) checks)))
@(d/transact (d/connect uri) checks)