diff --git a/notes.txt b/notes.txt index 703054c2..9604ab2b 100644 --- a/notes.txt +++ b/notes.txt @@ -5,3 +5,21 @@ 5) List of payments 6) add payment 7) add invoice - X + + + +-- +Rules priority: +Match check +Match debit +Match rule (assign vendor and account) + + Memo + + Wild card matches + + Match memo and amount + + Match for specificclient + + Match for specifo + +Transfers +Splits + + diff --git a/src/clj/auto_ap/datomic/clients.clj b/src/clj/auto_ap/datomic/clients.clj index d82d8cb0..0eb7aecb 100644 --- a/src/clj/auto_ap/datomic/clients.clj +++ b/src/clj/auto_ap/datomic/clients.clj @@ -29,3 +29,12 @@ #_(map first) #_(first))) + +(defn assoc-image [code image] + @(d/transact (d/connect uri) + [{ :client/code code + :client/signature-file (str "https://s3.amazonaws.com/integreat-signature-images/" image)}])) + + +#_(d/pull (d/db (d/connect uri)) '[*] [:client/code "FTLO"]) +#_(assoc-image "FTLO" "Fratello.jpg" ) diff --git a/src/clj/auto_ap/graphql/checks.clj b/src/clj/auto_ap/graphql/checks.clj index a9f7ba99..9c9ace0f 100644 --- a/src/clj/auto_ap/graphql/checks.clj +++ b/src/clj/auto_ap/graphql/checks.clj @@ -11,7 +11,7 @@ [auto-ap.datomic.clients :as d-clients] [auto-ap.datomic.bank-accounts :as d-bank-accounts] [auto-ap.datomic :refer [uri remove-nils]] - [auto-ap.utils :refer [by]] + [auto-ap.utils :refer [by dollars-0?]] [auto-ap.numeric :refer [num->words]] [config.core :refer [env]] [auto-ap.time :refer [parse normal-date iso-date local-now]] @@ -368,7 +368,7 @@ [[:db.fn/retractEntity (:db/id x)] {:db/id (:db/id invoice) :invoice/outstanding-balance new-balance - :invoice/status (if (< -0.001 new-balance 0.001) + :invoice/status (if (dollars-0? new-balance) (:invoice/status invoice) :invoice-status/unpaid)}])) (:payment/invoices check)) diff --git a/src/clj/auto_ap/graphql/invoices.clj b/src/clj/auto_ap/graphql/invoices.clj index c07d87c0..95beb9fc 100644 --- a/src/clj/auto_ap/graphql/invoices.clj +++ b/src/clj/auto_ap/graphql/invoices.clj @@ -7,6 +7,7 @@ [auto-ap.expense-accounts :as expense-accounts] [auto-ap.graphql.checks :as gq-checks] [auto-ap.time :refer [parse iso-date]] + [auto-ap.utils :refer [dollars=]] [datomic.api :as d] [auto-ap.datomic :refer [uri]] [clj-time.coerce :as coerce] @@ -105,7 +106,7 @@ (throw (ex-info (str "Invoice '" invoice_number "' already exists.") {:invoice-number invoice_number}))) expense-account-total (reduce + 0 (map (fn [x] (Double/parseDouble (:amount x))) expense_accounts)) - _ (when (not= total expense-account-total) + _ (when-not (dollars= total expense-account-total) (let [error (str "Expense account total (" expense-account-total ") does not equal invoice total (" total ")")] (throw (ex-info error {:validation-error error})))) paid-amount (- (:invoice/total invoice) (:invoice/outstanding-balance invoice)) diff --git a/src/clj/auto_ap/routes/exports.clj b/src/clj/auto_ap/routes/exports.clj index fde51090..cf21f8a4 100644 --- a/src/clj/auto_ap/routes/exports.clj +++ b/src/clj/auto_ap/routes/exports.clj @@ -31,7 +31,7 @@ [:client [:name :id :code :locations]]]]] invoices (graphql/query identity (venia/graphql-query {:venia/queries (->graphql query)}))] - (doto (list (:all-invoices (:data invoices))) clojure.pprint/pprint))) + (list (:all-invoices (:data invoices))))) (GET "/payments/export" {:keys [query-params identity]} (assert-admin identity) (let [query [[:all_payments diff --git a/src/cljc/auto_ap/utils.cljc b/src/cljc/auto_ap/utils.cljc index 32fdadba..adf9ecb7 100644 --- a/src/cljc/auto_ap/utils.cljc +++ b/src/cljc/auto_ap/utils.cljc @@ -17,3 +17,10 @@ (conj xs x))) [] existing)) + + +(defn dollars-0? [amt] + (< -0.001 amt 0.001)) + +(defn dollars= [amt1 amt2] + (dollars-0? (- amt1 amt2) ))