From 8cdc91d05782185f4e2266501b2f7bf97deee2e8 Mon Sep 17 00:00:00 2001 From: Bryce Covert Date: Sat, 30 Nov 2019 18:07:27 -0800 Subject: [PATCH] support for new templates. --- src/clj/auto_ap/parse/templates.clj | 26 ++++++++++++++++++++++++-- src/clj/auto_ap/parse/util.clj | 11 +++++++++++ src/clj/auto_ap/routes/invoices.clj | 1 - 3 files changed, 35 insertions(+), 3 deletions(-) diff --git a/src/clj/auto_ap/parse/templates.clj b/src/clj/auto_ap/parse/templates.clj index 09f65c45..81f6604b 100644 --- a/src/clj/auto_ap/parse/templates.clj +++ b/src/clj/auto_ap/parse/templates.clj @@ -139,7 +139,7 @@ :customer-identifier #"Bill To[^\n]+\n([A-Za-z ']+)" :invoice-number #"\n\s+[0-9/]+\s+(\d+)" :total #"Balance Due\s+\$([0-9\.]+)"} - :parser {#_#_:date [:clj-time "MM/dd/yyyy"]}} + :parser {:date [:clj-time "MM/dd/yyyy"]}} ;; PFG - ROMA @@ -150,7 +150,29 @@ :invoice-number #"INVOICE NO.\s+ ([\d]+)" :total #"([\d\.,]+)\s+INVOICE TOTAL"} :parser {:date [:clj-time "MM/dd/yy"] - :total [:trim-commas nil]}}]) + :total [:trim-commas nil]}} + + ;; PFG - ROMA LOOK 1 + {:vendor "Performance Food Group - ROMA" + :keywords [#"inquiries call 1-800-233-6211"] + :extract {:date #"([0-9]+/[0-9]+/[0-9]+)" + :customer-identifier #"BILL TO:\s+([\S ]+?)(?=\s{2,})" + :invoice-number #"^\s+([\dA-Z]+)" + :total #"([\d\.,\-]+\.[\d\-]+)"} + :parser {:date [:clj-time "MM/dd/yyyy"] + :total [:trim-commas-and-negate nil]} + :multi #"\n" + :multi-match? #"^\s+[\d]{6,8}\s+\d+"} + + ;; JFC + {:vendor "JFC International" + :keywords [#"48490 MILMONT DRIVE"] + :extract {:date #"([0-9]+/[0-9]+/[0-9]+)" + :customer-identifier #"SOLD\s+([\S ]+?)(?=(\s{2,}|\n))" + :invoice-number #"(\S+)\s+(?=[0-9]+/[0-9]+/[0-9]+)" + :total #"(?:INVOICE|TOTAL)\s+([\d\.,\-]+\.[\d\-]+( CR)?)"} + :parser {:date [:clj-time "MM/dd/yyyy"] + :total [:trim-commas-and-negate nil]}}]) (defn offset [c x y] (.toString (CellAddress. (+ y (.getRow (.getAddress c))) (+ x (.getColumn (.getAddress c))) ))) diff --git a/src/clj/auto_ap/parse/util.clj b/src/clj/auto_ap/parse/util.clj index 380d9b7c..b07f3e2a 100644 --- a/src/clj/auto_ap/parse/util.clj +++ b/src/clj/auto_ap/parse/util.clj @@ -14,6 +14,17 @@ (str/replace value #"," "") ) +(defmethod parse-value :trim-commas-and-negate + [_ _ value] + (let [[_ raw-value] (re-find #"([\d\.]+)" + (-> value + (str/replace #"," "") + (str/replace #"-" "")))] + (if (or (str/includes? value "-") + (str/includes? value "CR")) + (str (- (Double/parseDouble raw-value))) + (str raw-value)))) + (defmethod parse-value :clj-time [_ format value] (time/from-time-zone (f/parse (f/formatter format) value) diff --git a/src/clj/auto_ap/routes/invoices.clj b/src/clj/auto_ap/routes/invoices.clj index 485460ef..8f4e2c7c 100644 --- a/src/clj/auto_ap/routes/invoices.clj +++ b/src/clj/auto_ap/routes/invoices.clj @@ -161,7 +161,6 @@ (defn import-uploaded-invoice [imports] (let [clients (d-clients/get-all) - _ (clojure.pprint/pprint imports) transactions (reduce (fn [result {:keys [invoice-number customer-identifier total date vendor-code text full-text] :as info}] (println "searching for" vendor-code)