From 94d8346baca932a95646b0904b1da15036e91b28 Mon Sep 17 00:00:00 2001 From: Bryce Covert Date: Mon, 3 Apr 2023 09:08:52 -0700 Subject: [PATCH] (cloud) moves pay to datomic ions. --- iol_ion/src/iol_ion/tx.clj | 10 ++++++++++ resources/datomic/ion-config.edn | 3 ++- src/clj/auto_ap/graphql/checks.clj | 7 +++---- things-to-search-for.txt | 3 --- 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/iol_ion/src/iol_ion/tx.clj b/iol_ion/src/iol_ion/tx.clj index 9012f73c..cd7ad944 100644 --- a/iol_ion/src/iol_ion/tx.clj +++ b/iol_ion/src/iol_ion/tx.clj @@ -391,3 +391,13 @@ (if journal-entry (upsert-ledger db journal-entry) [[:db/retractEntity [:journal-entry/original-entity (:db/id transaction)]]])))) + + +(defn pay [db e amount] + (let [current-outstanding-balance (-> (dc/pull db [:invoice/outstanding-balance] e) :invoice/outstanding-balance) + new-outstanding-balance (- current-outstanding-balance amount)] + (upsert-invoice db {:db/id e + :invoice/outstanding-balance new-outstanding-balance + :invoice/status (if (> new-outstanding-balance 0) + :invoice-status/unpaid + :invoice-status/paid)}))) diff --git a/resources/datomic/ion-config.edn b/resources/datomic/ion-config.edn index e40a703e..e235329d 100644 --- a/resources/datomic/ion-config.edn +++ b/resources/datomic/ion-config.edn @@ -5,7 +5,8 @@ iol-ion.tx/min-by iol-ion.tx/propose-invoice iol-ion.tx/upsert-invoice - + iol-ion.tx/upsert-transaction + iol-ion.tx/pay iol-ion.query/dollars= iol-ion.query/dollars-0?] :app-name "iol-cloud"} diff --git a/src/clj/auto_ap/graphql/checks.clj b/src/clj/auto_ap/graphql/checks.clj index a4df6324..3f35ce55 100644 --- a/src/clj/auto_ap/graphql/checks.clj +++ b/src/clj/auto_ap/graphql/checks.clj @@ -3,7 +3,7 @@ [amazonica.aws.s3 :as s3] [auto-ap.datomic :refer [conn remove-nils plus pull-many audit-transact]] [auto-ap.datomic.accounts :as a] - [iol-ion.tx :refer [upsert-invoice]] + [iol-ion.tx :refer [upsert-invoice pay]] [auto-ap.datomic.bank-accounts :as d-bank-accounts] [auto-ap.datomic.checks :as d-checks] [auto-ap.datomic.clients :as d-clients] @@ -230,7 +230,7 @@ [{:invoice-payment/payment (-> invoice :invoice/vendor :db/id str) :invoice-payment/amount invoice-amount :invoice-payment/invoice (:db/id invoice)} - `(d-checks/pay ~(:db/id invoice) ~invoice-amount)]) + `(pay ~(:db/id invoice) ~invoice-amount)]) (reduce into []))) (defn base-payment [invoices vendor client bank-account _ _ invoice-amounts] @@ -759,8 +759,7 @@ :mutation/void-payments void-payments :mutation/print-checks print-checks :mutation/pay-invoices-from-balance pay-invoices-from-balance - :mutation/add-handwritten-check add-handwritten-check - }) + :mutation/add-handwritten-check add-handwritten-check}) (defn attach [schema] (-> diff --git a/things-to-search-for.txt b/things-to-search-for.txt index ec2d21c3..3f145ea1 100644 --- a/things-to-search-for.txt +++ b/things-to-search-for.txt @@ -1,6 +1,3 @@ -* try again to see if we can get upsert-ledger into the same transaction, making it all or nothing -* look for all usages of transact-with-ledger - it looks like there are a bbunch of orrphaned customizations for accounts, breaking indexes upsertledger - matching transaction rule might not assign an account. Other things might not assign accounts. This is an assertion that is commented out. Determine consequence of disabling Double check each job still functions in the new system