no need for ledger automation.
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
(ns auto-ap.graphql.checks
|
||||
(:require
|
||||
[amazonica.aws.s3 :as s3]
|
||||
[auto-ap.datomic :refer [audit-transact remove-nils conn]]
|
||||
[auto-ap.datomic :refer [conn remove-nils]]
|
||||
[auto-ap.datomic.accounts :as a]
|
||||
[auto-ap.datomic.bank-accounts :as d-bank-accounts]
|
||||
[auto-ap.datomic.checks :as d-checks]
|
||||
@@ -10,7 +10,14 @@
|
||||
[auto-ap.datomic.transactions :as d-transactions]
|
||||
[auto-ap.datomic.vendors :as d-vendors]
|
||||
[auto-ap.graphql.utils
|
||||
:refer [->graphql <-graphql assert-admin assert-failure assert-can-see-client enum->keyword assert-not-locked]]
|
||||
:refer [->graphql
|
||||
<-graphql
|
||||
assert-admin
|
||||
assert-can-see-client
|
||||
assert-failure
|
||||
assert-not-locked
|
||||
enum->keyword]]
|
||||
[auto-ap.ledger :refer [transact-with-ledger]]
|
||||
[auto-ap.numeric :refer [num->words]]
|
||||
[auto-ap.time :refer [iso-date local-now parse]]
|
||||
[auto-ap.utils :refer [by dollars-0?]]
|
||||
@@ -405,7 +412,7 @@
|
||||
(make-pdfs (filter #(and (= :payment-type/check (:payment/type %))
|
||||
(> (:payment/amount %) 0.0))
|
||||
checks)))
|
||||
(audit-transact checks id)
|
||||
(transact-with-ledger checks id)
|
||||
|
||||
|
||||
{:invoices (d-invoices/get-multi (map :invoice-id invoice-payments))
|
||||
@@ -461,7 +468,7 @@
|
||||
0
|
||||
invoice-payment-lookup)]
|
||||
|
||||
(audit-transact
|
||||
(transact-with-ledger
|
||||
(into [(assoc base-payment
|
||||
:payment/type :payment-type/check
|
||||
:payment/status :payment-status/pending
|
||||
@@ -494,7 +501,7 @@
|
||||
updated-payment {:db/id id
|
||||
:payment/amount 0.0
|
||||
:payment/status :payment-status/voided}]
|
||||
(audit-transact (conj removing-payments updated-payment)
|
||||
(transact-with-ledger (conj removing-payments updated-payment)
|
||||
(:id context)))
|
||||
(-> (d-checks/get-by-id id)
|
||||
(->graphql))))
|
||||
@@ -514,7 +521,7 @@
|
||||
specific-ids (d-checks/filter-ids (:ids args))
|
||||
all-ids (into (set ids) specific-ids)]
|
||||
(log/info "Voiding " (count all-ids) args)
|
||||
(audit-transact (->> all-ids
|
||||
(transact-with-ledger (->> all-ids
|
||||
(d/q '[:find [(pull ?p [:db/id
|
||||
{:invoice-payment/_payment [:invoice-payment/amount
|
||||
:db/id
|
||||
@@ -630,7 +637,7 @@
|
||||
|
||||
|
||||
|
||||
(audit-transact (-> []
|
||||
(transact-with-ledger (-> []
|
||||
(conj payment)
|
||||
(into (invoice-payments invoices invoice-amounts))) (:id context))
|
||||
(->graphql {:invoices (d-invoices/get-multi (map :db/id invoices))})))
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
(ns auto-ap.graphql.invoices
|
||||
(:require
|
||||
[auto-ap.datomic
|
||||
:refer [audit-transact conn remove-nils uri]]
|
||||
:refer [conn remove-nils uri]]
|
||||
[auto-ap.ledger :refer [transact-with-ledger]]
|
||||
[auto-ap.datomic.clients :as d-clients]
|
||||
[auto-ap.datomic.invoices :as d-invoices]
|
||||
[auto-ap.datomic.vendors :as d-vendors]
|
||||
@@ -59,7 +60,7 @@
|
||||
(doseq [i invoices]
|
||||
(assert-can-see-client (:id context) (:db/id (:invoice/client (d/entity (d/db conn) i)))))
|
||||
(let [transactions (map (fn [i] [:db/retractEntity i]) invoices)]
|
||||
(audit-transact transactions (:id context))
|
||||
(transact-with-ledger transactions (:id context))
|
||||
invoices))
|
||||
|
||||
(defn approve-invoices [context {:keys [invoices]} _]
|
||||
@@ -69,7 +70,7 @@
|
||||
(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))
|
||||
(transact-with-ledger transactions (:id context))
|
||||
invoices))
|
||||
|
||||
(defn assert-no-conflicting [{:keys [invoice_number client_id vendor_id]}]
|
||||
@@ -166,7 +167,7 @@
|
||||
(assert-valid-expense-accounts expense_accounts)
|
||||
(assert-invoice-amounts-add-up in)
|
||||
|
||||
(let [transaction-result (audit-transact [(add-invoice-transaction in)] (:id context))]
|
||||
(let [transaction-result (transact-with-ledger [(add-invoice-transaction in)] (:id context))]
|
||||
(-> (d-invoices/get-by-id (get-in transaction-result [:tempids "invoice"]))
|
||||
(->graphql (:id context)))))
|
||||
|
||||
@@ -183,7 +184,7 @@
|
||||
(assert-not-locked client_id (:date in))
|
||||
(assert-valid-expense-accounts (:expense_accounts in))
|
||||
(assert-invoice-amounts-add-up in)
|
||||
(let [transaction-result (audit-transact [(add-invoice-transaction in)] (:id context))]
|
||||
(let [transaction-result (transact-with-ledger [(add-invoice-transaction in)] (:id context))]
|
||||
(-> (gq-checks/print-checks-internal [{:invoice-id (get-in transaction-result [:tempids "invoice"])
|
||||
:amount total}]
|
||||
client_id
|
||||
@@ -217,7 +218,7 @@
|
||||
expense_accounts)}
|
||||
due (assoc :invoice/due (coerce/to-date due))
|
||||
scheduled_payment (assoc :invoice/scheduled-payment (coerce/to-date scheduled_payment)))]
|
||||
(audit-transact (concat [updated-invoice]
|
||||
(transact-with-ledger (concat [updated-invoice]
|
||||
(map (fn [d] [:db/retract id :invoice/expense-accounts d]) deleted))
|
||||
(:id context))
|
||||
(-> (d-invoices/get-by-id id)
|
||||
@@ -227,7 +228,7 @@
|
||||
(let [invoice (d-invoices/get-by-id id)]
|
||||
(assert-can-see-client (:id context) (:db/id (:invoice/client invoice)))
|
||||
(assert-not-locked (:db/id (:invoice/client invoice)) (:invoice/date invoice))
|
||||
(audit-transact [{:db/id id
|
||||
(transact-with-ledger [{:db/id id
|
||||
:invoice/total 0.0
|
||||
:invoice/outstanding-balance 0.0
|
||||
:invoice/status :invoice-status/voided
|
||||
@@ -253,7 +254,7 @@
|
||||
all-ids (into (set ids) specific-ids)]
|
||||
|
||||
(log/info "Voiding " (count all-ids) args)
|
||||
(audit-transact
|
||||
(transact-with-ledger
|
||||
(->> all-ids
|
||||
(d/q '[:find [(pull ?i [:db/id :invoice/date {:invoice/expense-accounts [:db/id]}]) ...]
|
||||
:in $ [?i ...]
|
||||
@@ -293,7 +294,7 @@
|
||||
:in ['$ '?e]}
|
||||
:args [history id]})
|
||||
[last-transaction] (->> txs (sort-by first) (last))]
|
||||
(audit-transact [(->> txs
|
||||
(transact-with-ledger [(->> txs
|
||||
(filter (fn [[tx]] (= tx last-transaction)))
|
||||
(reduce (fn [new-transaction [_ entity original-status original-outstanding total expense-account expense-account-amount]]
|
||||
(-> new-transaction
|
||||
@@ -313,7 +314,7 @@
|
||||
(assert-can-see-client (:id context) (:db/id (:invoice/client invoice)))
|
||||
(assert-not-locked (:db/id (:invoice/client invoice)) (:invoice/date invoice))
|
||||
(assert (not (seq (:invoice-payment/_invoice invoice))))
|
||||
(audit-transact [[:db/add id :invoice/status :invoice-status/unpaid]
|
||||
(transact-with-ledger [[:db/add id :invoice/status :invoice-status/unpaid]
|
||||
[:db/add id :invoice/outstanding-balance (:invoice/total invoice)]
|
||||
[:db/retract id :invoice/scheduled-payment (:invoice/scheduled-payment invoice)]]
|
||||
(:id context))
|
||||
@@ -333,7 +334,7 @@
|
||||
expense-account->entity
|
||||
(:expense_accounts args))}]
|
||||
|
||||
(audit-transact (concat [updated]
|
||||
(transact-with-ledger (concat [updated]
|
||||
(map (fn [d] [:db/retract invoice-id :invoice/expense-accounts d]) deleted))
|
||||
(:id context))
|
||||
(->graphql
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
(ns auto-ap.graphql.transactions
|
||||
(:require
|
||||
[auto-ap.datomic
|
||||
:refer [audit-transact audit-transact-batch conn remove-nils]]
|
||||
[auto-ap.datomic :refer [conn remove-nils]]
|
||||
[auto-ap.datomic.accounts :as a]
|
||||
[auto-ap.datomic.checks :as d-checks]
|
||||
[auto-ap.datomic.invoices :as d-invoices]
|
||||
@@ -19,6 +18,8 @@
|
||||
ident->enum-f
|
||||
snake->kebab]]
|
||||
[auto-ap.import.transactions :as i-transactions]
|
||||
[auto-ap.ledger
|
||||
:refer [transact-batch-with-ledger transact-with-ledger]]
|
||||
[auto-ap.rule-matching :as rm]
|
||||
[auto-ap.utils :refer [dollars=]]
|
||||
[clj-time.coerce :as coerce]
|
||||
@@ -87,7 +88,7 @@
|
||||
all-ids-not-locked)]
|
||||
|
||||
(log/info "Unapproving " (count all-ids) args)
|
||||
(audit-transact-batch
|
||||
(transact-batch-with-ledger
|
||||
(->> all-ids
|
||||
(mapv (fn [t]
|
||||
{:db/id t
|
||||
@@ -166,7 +167,7 @@
|
||||
(throw (ex-info err {:validation-error err}) ))))
|
||||
|
||||
(log/info "Bulk coding " (count all-ids) args)
|
||||
(audit-transact-batch
|
||||
(transact-batch-with-ledger
|
||||
(mapcat (fn [i]
|
||||
(cond-> [(cond-> i
|
||||
(:approval_status args) (assoc :transaction/approval-status (enum->keyword (:approval_status args) "transaction-approval-status"))
|
||||
@@ -185,7 +186,7 @@
|
||||
db (d/db conn)]
|
||||
|
||||
(log/info "Deleting " (count all-ids) args)
|
||||
(audit-transact-batch
|
||||
(transact-batch-with-ledger
|
||||
(mapcat (fn [i]
|
||||
(let [transaction (d/entity db i)
|
||||
payment-id (-> transaction :transaction/payment :db/id)
|
||||
@@ -265,7 +266,7 @@
|
||||
(when (not= :payment-status/cleared (-> payment :payment/status :db/ident))
|
||||
(throw (ex-info "Payment can't be undone because it isn't cleared." {:validation-error "Payment can't be undone because it isn't cleared."})))
|
||||
(if is-autopay-payment?
|
||||
(audit-transact
|
||||
(transact-with-ledger
|
||||
(cond-> [{:db/id (:db/id payment)
|
||||
:payment/status :payment-status/pending}
|
||||
{:db/id transaction-id
|
||||
@@ -291,7 +292,7 @@
|
||||
:where ['[?ip :invoice-payment/payment ?p]]}
|
||||
:args [(d/db conn) (:db/id payment)]} ))))
|
||||
(:id context))
|
||||
(audit-transact
|
||||
(transact-with-ledger
|
||||
(into (cond-> [{:db/id (:db/id payment)
|
||||
:payment/status :payment-status/pending}
|
||||
{:db/id transaction-id
|
||||
@@ -374,7 +375,7 @@
|
||||
(when missing-locations
|
||||
(throw (ex-info (str "Location '" (str/join ", " missing-locations) "' not found on client.") {})) )
|
||||
|
||||
(audit-transact (concat [(remove-nils {:db/id id
|
||||
(transact-with-ledger (concat [(remove-nils {:db/id id
|
||||
:transaction/vendor vendor_id
|
||||
:transaction/approval-status (some->> approval_status
|
||||
name
|
||||
@@ -413,7 +414,7 @@
|
||||
(when-not (dollars= (- (:transaction/amount transaction))
|
||||
(:payment/amount payment))
|
||||
(throw (ex-info "Amounts don't match" {:validation-error "Amounts don't match"})))
|
||||
(audit-transact (into
|
||||
(transact-with-ledger (into
|
||||
[{:db/id (:db/id payment)
|
||||
:payment/status :payment-status/cleared
|
||||
:payment/date (coerce/to-date (first (sort [(:payment/date payment)
|
||||
@@ -469,7 +470,7 @@
|
||||
(:db/id (:transaction/bank-account transaction))
|
||||
(:db/id (:transaction/client transaction)))]
|
||||
(log/info "Adding a new payment" payment-tx)
|
||||
@(d/transact conn payment-tx))
|
||||
(transact-with-ledger payment-tx (:id context)))
|
||||
|
||||
(-> (d-transactions/get-by-id transaction_id)
|
||||
approval-status->graphql
|
||||
@@ -506,7 +507,7 @@
|
||||
(:db/id (:transaction/bank-account transaction))
|
||||
(:db/id (:transaction/client transaction)))]
|
||||
(log/info "Adding a new payment" payment-tx)
|
||||
@(d/transact conn payment-tx))
|
||||
(transact-with-ledger payment-tx (:id context)))
|
||||
|
||||
(-> (d-transactions/get-by-id transaction_id)
|
||||
approval-status->graphql
|
||||
@@ -541,7 +542,7 @@
|
||||
(when (:transaction/payment transaction)
|
||||
|
||||
(throw (ex-info "Transaction already associated with a payment" {:validation-error "Transaction already associated with a payment"}))))
|
||||
(audit-transact (transduce
|
||||
(transact-with-ledger (transduce
|
||||
(map #(into
|
||||
[(remove-nils (rm/apply-rule {:db/id (:db/id %)
|
||||
:transaction/amount (:transaction/amount %)}
|
||||
|
||||
Reference in New Issue
Block a user