merged.
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
[auto-ap.datomic :refer [remove-nils uri]]
|
||||
[datomic.api :as d]
|
||||
[auto-ap.parse :as parse]
|
||||
[auto-ap.parse.util :as parse-u]
|
||||
[auto-ap.graphql.utils :refer [assert-admin]]
|
||||
[auto-ap.routes.utils :refer [wrap-secure]]
|
||||
[clj-time.coerce :refer [to-date]]
|
||||
@@ -89,7 +90,7 @@
|
||||
|
||||
(defn parse-date [{:keys [raw-date]}]
|
||||
(try
|
||||
(parse/parse-value :clj-time "MM/dd/yyyy" raw-date)
|
||||
(parse-u/parse-value :clj-time "MM/dd/yyyy" raw-date)
|
||||
(catch Exception e
|
||||
(throw (Exception. (str "Could not parse date from '" raw-date "'") e)))))
|
||||
|
||||
@@ -167,32 +168,41 @@
|
||||
(let [clients (d-clients/get-all)
|
||||
_ (clojure.pprint/pprint imports)
|
||||
|
||||
transactions (reduce (fn [result {:keys [invoice-number customer-identifier total date vendor-code text] :as info}]
|
||||
transactions (reduce (fn [result {:keys [invoice-number customer-identifier total date vendor-code text full-text] :as info}]
|
||||
(println "searching for" vendor-code)
|
||||
(let [[matching-vendor default-account] (->> (d/query
|
||||
(cond-> {:query {:find ['?vendor '?default-account]
|
||||
{:query {:find ['?vendor '?default-account]
|
||||
:in ['$ '?vendor-name]
|
||||
:where ['[?vendor :vendor/name ?vendor-name]
|
||||
'[?vendor :vendor/default-account ?default-account]]}
|
||||
:args [(d/db (d/connect uri)) vendor-code]}))
|
||||
first)
|
||||
:args [(d/db (d/connect uri)) vendor-code]})
|
||||
first)
|
||||
_ (println "matching" customer-identifier "-" matching-vendor)
|
||||
matching-client (parse/best-match clients customer-identifier)
|
||||
_ (println "New invoice matches client '" matching-client "', vendor '" matching-vendor "', account '" default-account "'")
|
||||
matching-location (parse/best-location-match matching-client text )
|
||||
[existing-id existing-outstanding-balance existing-status import-status] (->> (d/query
|
||||
(cond-> {:query {:find ['?e '?outstanding-balance '?status '?import-status2]
|
||||
:in ['$ '?invoice-number '?vendor '?client]
|
||||
:where '[[?e :invoice/invoice-number ?invoice-number]
|
||||
[?e :invoice/vendor ?vendor]
|
||||
[?e :invoice/client ?client]
|
||||
[?e :invoice/outstanding-balance ?outstanding-balance]
|
||||
[?e :invoice/status ?status]
|
||||
[?e :invoice/import-status ?import-status]
|
||||
[?import-status :db/ident ?import-status2]]}
|
||||
:args [(d/db (d/connect uri)) invoice-number matching-vendor (:db/id matching-client)]}))
|
||||
first)]
|
||||
_ (println "New invoice matches client" matching-client)
|
||||
matching-location (parse/best-location-match matching-client text full-text)
|
||||
[existing-id existing-outstanding-balance existing-status import-status] (when (and matching-client matching-location)
|
||||
(->> (d/query
|
||||
(cond-> {:query {:find ['?e '?outstanding-balance '?status '?import-status2]
|
||||
:in ['$ '?invoice-number '?vendor '?client]
|
||||
:where '[[?e :invoice/invoice-number ?invoice-number]
|
||||
[?e :invoice/vendor ?vendor]
|
||||
[?e :invoice/client ?client]
|
||||
[?e :invoice/outstanding-balance ?outstanding-balance]
|
||||
[?e :invoice/status ?status]
|
||||
[?e :invoice/import-status ?import-status]
|
||||
[?import-status :db/ident ?import-status2]]}
|
||||
:args [(d/db (d/connect uri)) invoice-number matching-vendor (:db/id matching-client)]}))
|
||||
first))]
|
||||
|
||||
(if (= :import-status/imported import-status)
|
||||
(cond
|
||||
(not (and matching-location matching-client))
|
||||
result
|
||||
|
||||
(= :import-status/imported import-status)
|
||||
result
|
||||
|
||||
:else
|
||||
(conj result (remove-nils #:invoice {:invoice/client (:db/id matching-client)
|
||||
:invoice/vendor matching-vendor
|
||||
:invoice/invoice-number invoice-number
|
||||
|
||||
Reference in New Issue
Block a user