diff --git a/src/clj/auto_ap/parse.clj b/src/clj/auto_ap/parse.clj index 3d2f3578..db214af8 100644 --- a/src/clj/auto_ap/parse.clj +++ b/src/clj/auto_ap/parse.clj @@ -48,7 +48,6 @@ :full-text full-text}))]))) (defn parse [text] - (info-event "Parsing pdf text" {:raw text}) (reset! last-text text) (->> t/pdf-templates (filter (partial template-applies? text)) @@ -134,6 +133,8 @@ #_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]} (defn dbg-parse [v] + (println v) (map (fn [x] (dissoc x :full-text :text)) (parse v))) + diff --git a/src/clj/auto_ap/parse/templates.clj b/src/clj/auto_ap/parse/templates.clj index e2711341..9432c5c0 100644 --- a/src/clj/auto_ap/parse/templates.clj +++ b/src/clj/auto_ap/parse/templates.clj @@ -162,13 +162,13 @@ :keywords [#"WORLDWIDE PRODUCE"] :extract {:date #"([0-9]+/[0-9]+/[0-9]+)" :customer-identifier #"Bill to.*\n\s*(.*?(?=(\s{2,}|\()))" - :invoice-number #"Invoice No\.\s+(\d+)" - :total #"Total\s+([0-9\.,]+)" + :invoice-number #"(?:Invoice|Adjustment) No\.\s+(\d+)" + :total #"Total \S*\s+([0-9\.,\-]+)" :account-number #"Customer No.\s+(.*?)\s{2}"} :parser {:date [:clj-time "MM/dd/yy"] :total [:trim-commas nil]} :multi (. java.util.regex.Pattern (compile (-> \formfeed str) java.util.regex.Pattern/CASE_INSENSITIVE)) - :multi-match? #"Total\s+[0-9\.]+" + :multi-match? #"(Total\s+[0-9\.]+|Total Order)" } ;; AUTO-CHLOR diff --git a/src/clj/auto_ap/routes/invoices.clj b/src/clj/auto_ap/routes/invoices.clj index c957f5f3..f01b3132 100644 --- a/src/clj/auto_ap/routes/invoices.clj +++ b/src/clj/auto_ap/routes/invoices.clj @@ -230,7 +230,7 @@ (defn import-uploaded-invoice [user imports] (lc/with-context {:area "upload-invoice"} - (log/info "Number of invoices to import is" (count imports) "sample: " (first imports)) + (log/info "Number of invoices to import is" (count imports) ) (let [clients (d-clients/get-all) potential-invoices (->> imports (mapv #(import->invoice % clients)) @@ -240,7 +240,7 @@ (mapv (fn [i] [:propose-invoice i])))] (when-not (seq potential-invoices) (throw (ex-info "No new invoices found." - {:imports (str (vec imports))}))) + {}))) (log/info "creating invoice" potential-invoices) @(d/transact (d/connect uri) potential-invoices)))) @@ -425,7 +425,7 @@ :headers {"Content-Type" "application/edn"}} (catch Exception e (log/warn e) - {:status 500 + {:status 400 :body (pr-str {:message (.getMessage e) :error (.toString e) :data (ex-data e)}) diff --git a/src/clj/auto_ap/yodlee/core2.clj b/src/clj/auto_ap/yodlee/core2.clj index c29fbb6b..a40416f0 100644 --- a/src/clj/auto_ap/yodlee/core2.clj +++ b/src/clj/auto_ap/yodlee/core2.clj @@ -57,7 +57,9 @@ (log/info "logging in as " client-code) (-> (str (:yodlee2-base-url env) "/auth/token") (client/post (merge {:headers (assoc base-headers - "loginName" client-code + "loginName" (if (<= (count client-code) 3) + (str client-code client-code) + client-code) "Content-Type" "application/x-www-form-urlencoded") :body (str "clientId=" (:yodlee2-client-id env) " &secret=" (:yodlee2-client-secret env)) :as :json}