(cloud) fixes issues encountered in testing.
This commit is contained in:
@@ -15,16 +15,20 @@
|
||||
[auto-ap.ledger :refer [build-account-lookup]]
|
||||
[auto-ap.ledger.reports :as l-reports]
|
||||
[auto-ap.parse.util :as parse]
|
||||
[auto-ap.pdf.ledger
|
||||
:refer [print-balance-sheet
|
||||
print-cash-flows
|
||||
print-journal-detail-report
|
||||
print-pnl]]
|
||||
[auto-ap.time :as atime]
|
||||
[auto-ap.utils :refer [by dollars=]]
|
||||
[auto-ap.pdf.ledger :refer [print-balance-sheet print-pnl print-journal-detail-report print-cash-flows]]
|
||||
[clj-time.coerce :as coerce]
|
||||
[clj-time.core :as t]
|
||||
[clojure.data.csv :as csv]
|
||||
[clojure.tools.logging :as log]
|
||||
[com.brunobonacci.mulog :as mu]
|
||||
[datomic.client.api :as dc]
|
||||
[iol-ion.tx :refer [upsert-ledger]])
|
||||
[iol-ion.tx :refer [random-tempid upsert-ledger]])
|
||||
(:import
|
||||
(org.apache.commons.codec.binary Base64)))
|
||||
|
||||
@@ -343,29 +347,37 @@
|
||||
(map first)
|
||||
(pull-many (dc/db conn) [:db/id :vendor/name])
|
||||
(by :vendor/name)))
|
||||
all-clients (mu/trace ::get-all-clients []
|
||||
(by :client/code (d-clients/get-all )))
|
||||
client-locked-lookup (mu/trace ::get-all-clients []
|
||||
(->> (dc/q '[:find ?code ?locked-until
|
||||
:in $
|
||||
:where [?c :client/code ?code]
|
||||
[(get-else $ ?c :client/locked-until #inst "2000-01-01") ?locked-until]]
|
||||
(dc/db conn))
|
||||
(into {})))
|
||||
all-client-bank-accounts (mu/trace ::get-all-client-bank-accounts
|
||||
[]
|
||||
(reduce
|
||||
(fn [acc client]
|
||||
(assoc acc (:client/code client)
|
||||
(set (->> (:client/bank-accounts client)
|
||||
(map :bank-account/code)
|
||||
))))
|
||||
{}
|
||||
(d-clients/get-all)))
|
||||
[]
|
||||
(->> (dc/q '[:find ?code ?ba-code
|
||||
:in $
|
||||
:where [?c :client/code ?code]
|
||||
[?c :client/bank-accounts ?ba]
|
||||
[?ba :bank-account/code ?ba-code]]
|
||||
(dc/db conn))
|
||||
(reduce
|
||||
(fn [acc [code ba-code]]
|
||||
(update acc code (fnil conj #{}) ba-code))
|
||||
{})))
|
||||
|
||||
all-client-locations (mu/trace ::get-all-client-locations
|
||||
[]
|
||||
(reduce
|
||||
(fn [acc client]
|
||||
(assoc acc (:client/code client)
|
||||
(-> (set (:client/locations client))
|
||||
(conj "HQ")
|
||||
(conj "A"))))
|
||||
{}
|
||||
(d-clients/get-all)))
|
||||
(->> (dc/q '[:find ?code ?location
|
||||
:in $
|
||||
:where [?c :client/code ?code]
|
||||
[?c :client/locations ?location]]
|
||||
(dc/db conn))
|
||||
(reduce
|
||||
(fn [acc [code ba-code]]
|
||||
(update acc code (fnil conj #{"HQ" "A"}) ba-code))
|
||||
{})))
|
||||
|
||||
new-hidden-vendors (reduce
|
||||
(fn [new-vendors {:keys [vendor_name]}]
|
||||
@@ -396,13 +408,13 @@
|
||||
(doall (map
|
||||
(assoc-error (fn [entry]
|
||||
(let [vendor (all-vendors (:vendor_name entry))]
|
||||
(when-not (all-clients (:client_code entry))
|
||||
(when-not (client-locked-lookup (:client_code entry))
|
||||
(throw (ex-info (str "Client '" (:client_code entry )"' not found.") {:status :error}) ))
|
||||
(when-not vendor
|
||||
(throw (ex-info (str "Vendor '" (:vendor_name entry) "' not found.") {:status :error})))
|
||||
(when-not (re-find #"\d{1,2}/\d{1,2}/\d{4}" (:date entry))
|
||||
(throw (ex-info (str "Date must be MM/dd/yyyy") {:status :error})))
|
||||
(when-let [locked-until (:client/locked-until (all-clients (:client_code entry)))]
|
||||
(when-let [locked-until (client-locked-lookup (:client_code entry))]
|
||||
(when (and (not (t/after? (coerce/to-date-time (coerce/to-date (parse/parse-value :clj-time "MM/dd/yyyy" (:date entry))))
|
||||
(coerce/to-date-time locked-until)))
|
||||
(not (t/equal? (coerce/to-date-time (coerce/to-date (parse/parse-value :clj-time "MM/dd/yyyy" (:date entry))))
|
||||
@@ -478,7 +490,8 @@
|
||||
(:location ea)
|
||||
"'")
|
||||
{:status :error})))
|
||||
(remove-nils (cond-> {:journal-entry-line/location (:location ea)
|
||||
(remove-nils (cond-> {:db/id (random-tempid)
|
||||
:journal-entry-line/location (:location ea)
|
||||
:journal-entry-line/debit (when (> debit 0)
|
||||
debit)
|
||||
:journal-entry-line/credit (when (> credit 0)
|
||||
|
||||
@@ -117,6 +117,10 @@
|
||||
:in ['$ ]
|
||||
:where []}
|
||||
:args [(dc/db conn)]}
|
||||
description
|
||||
(merge-query {:query {:in ['?descr]
|
||||
:where ['[(iol-ion.query/->pattern ?descr) ?description-regex]]}
|
||||
:args [description]})
|
||||
|
||||
(limited-clients id)
|
||||
(merge-query {:query {:in ['[?xx ...]]
|
||||
@@ -129,10 +133,8 @@
|
||||
:args [(:db/id bank-account)]})
|
||||
|
||||
description
|
||||
(merge-query {:query {:in ['?description-regex]
|
||||
:where ['[?e :transaction/description-original ?do]
|
||||
'[(re-find ?description-regex ?do)]]}
|
||||
:args [(rm/->pattern description)]})
|
||||
(merge-query {:query {:where ['[?e :transaction/description-original ?do]
|
||||
'[(re-find ?description-regex ?do)]]}})
|
||||
|
||||
yodlee-merchant
|
||||
(merge-query {:query {:in ['?yodlee-merchant-id]
|
||||
@@ -154,18 +156,14 @@
|
||||
dom-lte
|
||||
(merge-query {:query {:in ['?dom-lte]
|
||||
:where ['[?e :transaction/date ?transaction-date]
|
||||
'[(.toInstant ^java.util.Date ?transaction-date ) ?transaction-instant]
|
||||
'[(.atZone ^java.time.Instant ?transaction-instant (java.time.ZoneId/of "US/Pacific")) ?transaction-local]
|
||||
'[(.get ?transaction-local java.time.temporal.ChronoField/DAY_OF_MONTH) ?dom]
|
||||
'[(iol-ion.query/dom ?transaction-date) ?dom]
|
||||
'[(<= ?dom ?dom-lte)]]}
|
||||
:args [dom-lte]})
|
||||
|
||||
dom-gte
|
||||
(merge-query {:query {:in ['?dom-gte]
|
||||
:where ['[?e :transaction/date ?transaction-date]
|
||||
'[(.toInstant ^java.util.Date ?transaction-date ) ?transaction-instant]
|
||||
'[(.atZone ^java.time.Instant ?transaction-instant (java.time.ZoneId/of "US/Pacific")) ?transaction-local]
|
||||
'[(.get ?transaction-local java.time.temporal.ChronoField/DAY_OF_MONTH) ?dom]
|
||||
'[(iol-ion.query/dom ?transaction-date) ?dom]
|
||||
'[(>= ?dom ?dom-gte)]]}
|
||||
:args [dom-gte]})
|
||||
|
||||
|
||||
@@ -498,7 +498,7 @@
|
||||
conj
|
||||
[]
|
||||
transaction_ids)
|
||||
transaction-rule (update (tr/get-by-id transaction_rule_id) :transaction-rule/description #(some-> % rm/->pattern))]
|
||||
transaction-rule (update (tr/get-by-id transaction_rule_id) :transaction-rule/description #(some-> % iol-ion.query/->pattern))]
|
||||
(doseq [transaction transactions]
|
||||
(when (not (rm/rule-applies? transaction transaction-rule))
|
||||
(throw (ex-info "Transaction rule does not apply" {:validation-error "Transaction rule does not apply"
|
||||
|
||||
Reference in New Issue
Block a user