prevents external ledger imports before the client was locked.
This commit is contained in:
@@ -16,7 +16,8 @@
|
||||
[datomic.api :as d]
|
||||
[mount.core :as mount]
|
||||
[unilog.context :as lc]
|
||||
[yang.scheduler :as scheduler]))
|
||||
[yang.scheduler :as scheduler]
|
||||
[clj-time.core :as t]))
|
||||
|
||||
(mount/defstate running-balance-cache
|
||||
:start (atom {}))
|
||||
@@ -234,6 +235,17 @@
|
||||
:status (or (:status (ex-data e))
|
||||
:error))))))
|
||||
|
||||
(defn all-ids-not-locked [all-ids]
|
||||
(->> all-ids
|
||||
(d/q '[:find [?t ...]
|
||||
:in $ [?t ...]
|
||||
:where
|
||||
[?t :journal-entry/client ?c]
|
||||
[(get-else $ ?c :client/locked-until #inst "2000-01-01") ?lu]
|
||||
[?t :journal-entry/date ?d]
|
||||
[(>= ?d ?lu)]]
|
||||
(d/db conn))))
|
||||
|
||||
(defn delete-external-ledger [context args _]
|
||||
(let [_ (assert-admin (:id context))
|
||||
args (assoc args :id (:id context))
|
||||
@@ -244,7 +256,7 @@
|
||||
(#(l/raw-graphql-ids (d/db conn) %))
|
||||
:ids)
|
||||
specific-ids (l/filter-ids (:ids args))
|
||||
all-ids (into (set ids) specific-ids)]
|
||||
all-ids (all-ids-not-locked (into (set ids) specific-ids))]
|
||||
(if (> (count all-ids) 1000)
|
||||
{:message (str "You can only delete 1000 ledger entries at a time.")}
|
||||
(do
|
||||
@@ -310,6 +322,13 @@
|
||||
(throw (ex-info (str "Vendor '" (:vendor_name entry) "' not found.") {:status :error})))
|
||||
(when-not (re-find #"\d{1,2}/\d{1,2}/\d{4}" (:date entry))
|
||||
(throw (ex-info (str "Date must be MM/dd/yyyy") {:status :error})))
|
||||
(when-let [locked-until (:client/locked-until (all-clients (:client_code entry)))]
|
||||
(when (and (not (t/after? (coerce/to-date-time (coerce/to-date (parse/parse-value :clj-time "MM/dd/yyyy" (:date entry))))
|
||||
(coerce/to-date-time locked-until)))
|
||||
(not (t/equal? (coerce/to-date-time (coerce/to-date (parse/parse-value :clj-time "MM/dd/yyyy" (:date entry))))
|
||||
(coerce/to-date-time locked-until))))
|
||||
(throw (ex-info (str "Client's data is locked until " locked-until) {:status :error}))))
|
||||
|
||||
(when-not (dollars= (reduce (fnil + 0.0 0.0) 0.0 (map :debit (:line_items entry)))
|
||||
(reduce (fnil + 0.0 0.0) 0.0 (map :credit (:line_items entry))))
|
||||
(throw (ex-info (str "Debits '"
|
||||
|
||||
Reference in New Issue
Block a user