prevents external ledger imports before the client was locked.
This commit is contained in:
@@ -65,8 +65,10 @@
|
|||||||
|
|
||||||
(defn approve-invoices [context {:keys [invoices]} _]
|
(defn approve-invoices [context {:keys [invoices]} _]
|
||||||
(assert-power-user (:id context))
|
(assert-power-user (:id context))
|
||||||
(doseq [i invoices]
|
(doseq [i invoices
|
||||||
(assert-can-see-client (:id context) (:db/id (:invoice/client (d/entity (d/db conn) i)))))
|
: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)]
|
(let [transactions (map (fn [i] {:db/id i :invoice/import-status :import-status/imported}) invoices)]
|
||||||
(audit-transact transactions (:id context))
|
(audit-transact transactions (:id context))
|
||||||
invoices))
|
invoices))
|
||||||
|
|||||||
@@ -16,7 +16,8 @@
|
|||||||
[datomic.api :as d]
|
[datomic.api :as d]
|
||||||
[mount.core :as mount]
|
[mount.core :as mount]
|
||||||
[unilog.context :as lc]
|
[unilog.context :as lc]
|
||||||
[yang.scheduler :as scheduler]))
|
[yang.scheduler :as scheduler]
|
||||||
|
[clj-time.core :as t]))
|
||||||
|
|
||||||
(mount/defstate running-balance-cache
|
(mount/defstate running-balance-cache
|
||||||
:start (atom {}))
|
:start (atom {}))
|
||||||
@@ -234,6 +235,17 @@
|
|||||||
:status (or (:status (ex-data e))
|
:status (or (:status (ex-data e))
|
||||||
:error))))))
|
: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 _]
|
(defn delete-external-ledger [context args _]
|
||||||
(let [_ (assert-admin (:id context))
|
(let [_ (assert-admin (:id context))
|
||||||
args (assoc args :id (:id context))
|
args (assoc args :id (:id context))
|
||||||
@@ -244,7 +256,7 @@
|
|||||||
(#(l/raw-graphql-ids (d/db conn) %))
|
(#(l/raw-graphql-ids (d/db conn) %))
|
||||||
:ids)
|
:ids)
|
||||||
specific-ids (l/filter-ids (:ids args))
|
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)
|
(if (> (count all-ids) 1000)
|
||||||
{:message (str "You can only delete 1000 ledger entries at a time.")}
|
{:message (str "You can only delete 1000 ledger entries at a time.")}
|
||||||
(do
|
(do
|
||||||
@@ -310,6 +322,13 @@
|
|||||||
(throw (ex-info (str "Vendor '" (:vendor_name entry) "' not found.") {:status :error})))
|
(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))
|
(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})))
|
(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)))
|
(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))))
|
(reduce (fnil + 0.0 0.0) 0.0 (map :credit (:line_items entry))))
|
||||||
(throw (ex-info (str "Debits '"
|
(throw (ex-info (str "Debits '"
|
||||||
|
|||||||
@@ -94,6 +94,15 @@
|
|||||||
"sort_order" "DESC"
|
"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
|
(defn search
|
||||||
([client location d]
|
([client location d]
|
||||||
|
|||||||
Reference in New Issue
Block a user