Getting closer to datomic cloud
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
(ns auto-ap.graphql.invoices
|
||||
(:require
|
||||
[auto-ap.datomic :refer [conn random-tempid remove-nils upsert-entity]]
|
||||
[auto-ap.datomic
|
||||
:refer [conn pull-attr pull-many pull-ref random-tempid upsert-entity]]
|
||||
[auto-ap.datomic.clients :as d-clients]
|
||||
[auto-ap.datomic.invoices :as d-invoices]
|
||||
[auto-ap.datomic.vendors :as d-vendors]
|
||||
@@ -22,10 +23,7 @@
|
||||
[clj-time.coerce :as coerce]
|
||||
[clj-time.core :as time]
|
||||
[clojure.tools.logging :as log]
|
||||
[datomic.api :as d]
|
||||
[manifold.deferred :as de]
|
||||
[com.brunobonacci.mulog :as mu]
|
||||
[com.walmartlabs.lacinia.util :refer [attach-resolvers]]
|
||||
[datomic.client.api :as dc]))
|
||||
|
||||
(defn ->graphql [invoice user ]
|
||||
@@ -139,7 +137,7 @@
|
||||
|
||||
(when (and (= :allowance/denied
|
||||
(:account/invoice-allowance account))
|
||||
(not= (:db/id (:vendor/default-account (d/entity (d/db conn) vendor_id)))
|
||||
(not= (pull-ref (dc/db conn) vendor_id :vendor/default-account)
|
||||
(:db/id account)))
|
||||
(let [err (str "Account isn't allowed for invoice use.")]
|
||||
(throw (ex-info err
|
||||
@@ -262,30 +260,32 @@
|
||||
|
||||
(defn all-ids-not-locked [all-ids]
|
||||
(->> all-ids
|
||||
(d/q '[:find [?i ...]
|
||||
(dc/q '[:find ?i
|
||||
:in $ [?i ...]
|
||||
:where
|
||||
[?i :invoice/client ?c]
|
||||
[(get-else $ ?c :client/locked-until #inst "2000-01-01") ?lu]
|
||||
[?i :invoice/date ?d]
|
||||
[(>= ?d ?lu)]]
|
||||
(d/db conn))))
|
||||
(dc/db conn))
|
||||
(map first)))
|
||||
|
||||
(defn void-invoices [context args _]
|
||||
(let [_ (assert-admin (:id context))
|
||||
args (assoc args :id (:id context))
|
||||
all-ids (all-ids-not-locked (get-ids-matching-filters args))
|
||||
voidable-cash-payments (d/q '[:find [?p ...]
|
||||
:in $ [?i ...]
|
||||
:where [?ip :invoice-payment/invoice ?i]
|
||||
[?ip :invoice-payment/payment ?p]
|
||||
[?p :payment/type :payment-type/cash]
|
||||
[?i :invoice/client ?c]
|
||||
[(get-else $ ?c :client/locked-until #inst "2000-01-01") ?lu]
|
||||
[?i :invoice/date ?d]
|
||||
[(>= ?d ?lu)]]
|
||||
(d/db conn)
|
||||
all-ids)
|
||||
voidable-cash-payments (->> (dc/q '[:find ?p
|
||||
:in $ [?i ...]
|
||||
:where [?ip :invoice-payment/invoice ?i]
|
||||
[?ip :invoice-payment/payment ?p]
|
||||
[?p :payment/type :payment-type/cash]
|
||||
[?i :invoice/client ?c]
|
||||
[(get-else $ ?c :client/locked-until #inst "2000-01-01") ?lu]
|
||||
[?i :invoice/date ?d]
|
||||
[(>= ?d ?lu)]]
|
||||
(dc/db conn)
|
||||
all-ids)
|
||||
(map first))
|
||||
]
|
||||
(log/info "Voiding " (count voidable-cash-payments) "cash payments first")
|
||||
(gq-checks/void-payments-internal voidable-cash-payments (:id context))
|
||||
@@ -422,11 +422,11 @@
|
||||
(throw (ex-info "Client is required"
|
||||
{:validation-error "client is required"})))
|
||||
(let [args (assoc args :id (:id context))
|
||||
locations (:client/locations (d/pull (d/db conn)
|
||||
[:client/locations]
|
||||
(:client_id args)))
|
||||
locations (pull-attr (dc/db conn)
|
||||
:client/locations
|
||||
(:client_id args))
|
||||
all-ids (all-ids-not-locked (get-ids-matching-filters args))
|
||||
invoices (d/pull-many (d/db conn) '[:db/id :invoice/total] (vec all-ids))
|
||||
invoices (pull-many (dc/db conn) '[:db/id :invoice/total] (vec all-ids))
|
||||
account-total (reduce + 0 (map (fn [x] (:percentage x)) (:accounts args)))]
|
||||
(log/info "client is" locations)
|
||||
(when
|
||||
@@ -434,7 +434,7 @@
|
||||
(let [error (str "Account total (" account-total ") does not reach 100%")]
|
||||
(throw (ex-info error {:validation-error error}))))
|
||||
(doseq [a (:accounts args)
|
||||
:let [{:keys [:account/location :account/name]} (d/entity (d/db conn) (:account_id a))]]
|
||||
:let [{:keys [:account/location :account/name]} (dc/pull (dc/db conn) [:account/location :account/name] (:account_id a))]]
|
||||
(when (and location (not= location (:location a)))
|
||||
(let [err (str "Account " name " uses location " (:location a) ", but is supposed to be " location)]
|
||||
(throw (ex-info err {:validation-error err}) )))
|
||||
|
||||
Reference in New Issue
Block a user