From f95a3b2c3adc4c7a03fedf0f81ca159f9e3934d7 Mon Sep 17 00:00:00 2001 From: Bryce Covert Date: Tue, 7 Dec 2021 12:04:20 -0800 Subject: [PATCH] adding new square locations. adding new extra validaiton --- config/prod-background-worker.edn | 15 +++++++++++++++ src/clj/auto_ap/ledger.clj | 29 ++++++++++++++++++++++++++++- 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/config/prod-background-worker.edn b/config/prod-background-worker.edn index 75d59872..e002181b 100644 --- a/config/prod-background-worker.edn +++ b/config/prod-background-worker.edn @@ -127,6 +127,21 @@ {:square-location "LZDDMFASCHD2K", :location "FT", :token "EAAAEO2xSqesDutZz71hz3eulKmrlKTiEqG3uZ4j25x5GYlOluQ2cj2JxNUXqXD7"} + "NGDV" + {:square-location "LRCHF1R2BQPEG", + :location "DV", + :token "EAAAEO2xSqesDutZz71hz3eulKmrlKTiEqG3uZ4j25x5GYlOluQ2cj2JxNUXqXD7"} + + "NGGL" + {:square-location "LC7ZWEHCFN31B" + :location "GL", + :token "EAAAEO2xSqesDutZz71hz3eulKmrlKTiEqG3uZ4j25x5GYlOluQ2cj2JxNUXqXD7"} + + ;; "NGGT" + ;; {:square-location "WAITING" + ;; :location "GT", + ;; :token "EAAAEO2xSqesDutZz71hz3eulKmrlKTiEqG3uZ4j25x5GYlOluQ2cj2JxNUXqXD7"} + "20TY" {:square-location "L2579ATQ0X1ET", :location "WG", diff --git a/src/clj/auto_ap/ledger.clj b/src/clj/auto_ap/ledger.clj index 8b1996d4..c1835437 100644 --- a/src/clj/auto_ap/ledger.clj +++ b/src/clj/auto_ap/ledger.clj @@ -287,6 +287,27 @@ (:transaction/amount transaction?))) (map :db/id))) +(defn unbalanced-invoices [] + (->> (d/query {:query {:find ['?je '?a '(sum ?debit) '(sum ?credit)] + :with ['?jel] + :in '[$] + :where ['[?je :journal-entry/amount ?a] + '[?je :journal-entry/line-items ?jel] + '[(get-else $ ?jel :journal-entry-line/debit 0.0) ?debit] + '[(get-else $ ?jel :journal-entry-line/credit 0.0) ?credit]] + } + :args [(d/db auto-ap.datomic/conn)]}) + (filter (fn [[_ a d c]] + (or (not (dollars= a d)) + (not (dollars= a c))))) + (map first) + (map (fn [je] + (:journal-entry/original-entity (d/entity (d/db auto-ap.datomic/conn) + je)))) + (filter (fn [invoice?] + (:invoice/total invoice?))) + (map :db/id))) + (defn mismatched-invoices [] (let [jel-accounts (reduce (fn [acc [e lia]] @@ -344,7 +365,13 @@ (log/warn (count mismatched-is) " invoice exist but don't match ledger ") (doseq [[m] mismatched-is] (touch-invoice m))))) - + (log/info "Attempting to fix transactions that are in the ledger but debits/credits don't add up") + (let [unbalanced-invoices (unbalanced-invoices)] + (if (seq unbalanced-invoices) + (do + (log/warn (count unbalanced-invoices) " invoices exist but don't have matching debits/credits ") + (doseq [m unbalanced-invoices] + (touch-invoice m))))) (log/info "Finished fixing invoices that are in the ledger but are wrong") (catch Exception e