prevents external ledger imports before the client was locked.
This commit is contained in:
@@ -65,8 +65,10 @@
|
||||
|
||||
(defn approve-invoices [context {:keys [invoices]} _]
|
||||
(assert-power-user (:id context))
|
||||
(doseq [i invoices]
|
||||
(assert-can-see-client (:id context) (:db/id (:invoice/client (d/entity (d/db conn) i)))))
|
||||
(doseq [i invoices
|
||||
:let [invoice (d/entity (d/db conn) i)]]
|
||||
(assert-can-see-client (:id context) (-> invoice :invoice/client :db/id))
|
||||
(assert-not-locked (-> invoice :invoice/client :db/id) (-> invoice :invoice/date)))
|
||||
(let [transactions (map (fn [i] {:db/id i :invoice/import-status :import-status/imported}) invoices)]
|
||||
(audit-transact transactions (:id context))
|
||||
invoices))
|
||||
|
||||
@@ -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 '"
|
||||
|
||||
@@ -94,6 +94,15 @@
|
||||
"sort_order" "DESC"
|
||||
}}})
|
||||
|
||||
(defn get-order
|
||||
([client location order-id]
|
||||
(log/info "Searching for" (:square-location/client-location location))
|
||||
(let [result (->> (client/get (str "https://connect.squareup.com/v2/orders/" order-id)
|
||||
{:headers (client-base-headers client)
|
||||
:as :json})
|
||||
:body
|
||||
)]
|
||||
result)))
|
||||
|
||||
(defn search
|
||||
([client location d]
|
||||
|
||||
Reference in New Issue
Block a user