From 10ee974eaf5e21bca02a852cf24c3d2655505678 Mon Sep 17 00:00:00 2001 From: Bryce Covert Date: Thu, 24 Oct 2019 21:05:01 -0700 Subject: [PATCH] more invoices. --- src/clj/auto_ap/parse.clj | 1 + src/clj/auto_ap/parse/templates.clj | 16 +++++++++++++++- src/clj/auto_ap/routes/invoices.clj | 3 +-- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/clj/auto_ap/parse.clj b/src/clj/auto_ap/parse.clj index fb8ff478..28743d95 100644 --- a/src/clj/auto_ap/parse.clj +++ b/src/clj/auto_ap/parse.clj @@ -79,6 +79,7 @@ (let [fuzzy-match (->> clients (mapcat (fn [{:keys [:db/id :client/matches :client/name] :as client :or {matches []}}] (map (fn [m] + (println m invoice-client-name) [client (m/jaccard (.toLowerCase invoice-client-name) (.toLowerCase m))]) (conj matches name)))) (filter #(< (second %) 0.25)) diff --git a/src/clj/auto_ap/parse/templates.clj b/src/clj/auto_ap/parse/templates.clj index 9c0c966b..5ce3fc1e 100644 --- a/src/clj/auto_ap/parse/templates.clj +++ b/src/clj/auto_ap/parse/templates.clj @@ -57,7 +57,21 @@ :total #"\$([0-9.]+)"} :parser {:date [:clj-time "MM/dd/yyyy"]} :multi #"\n" - :multi-match? #"^[0-9]+/[0-9]+/[0-9]+\s+(\d+)"}]) + :multi-match? #"^[0-9]+/[0-9]+/[0-9]+\s+(\d+)"} + {:vendor "Performance Food Group" + :keywords [#"performancefoodservice"] + :extract {:date #"DELIVER TO[^\n]+\n.+?(?=[0-9]+/[0-9]+/[0-9]+)([0-9]+/[0-9]+/[0-9]+)" + :customer-identifier #"DELIVER TO[^\n]+\n\s*[\S ]+?(?=\s{2,}([\S ]+?)\s{2,})" ;; ([\S ]+)\s{2,} + :invoice-number #"DELIVER TO[^\n]+\n.+?(?=\d+)(\d+)\s*\n" + :total #"([0-9.]+)\s+Status Code"} + :parser {#_#_:date [:clj-time "MM/dd/yy"]}} + {:vendor "US Foods" + :keywords [#"US Foods"] + :extract {:date #"INVOICE NUMBER[^\n]+\n\n\d+\s+\d+\s+([0-9]+/[0-9]+/[0-9]+)" + :customer-identifier #"BILL TO[^\n]+\n([\S ]+?)(?=\s{2,})" ;; ([\S ]+)\s{2,} + :invoice-number #"INVOICE NUMBER[^\n]+\n\n\d+\s+(\d+)" + :total #"DELIVERED AMOUNT\s+\$([0-9.]+)"} + :parser {:date [:clj-time "MM/dd/yyyy"]}}]) (def excel-templates [{:vendor "Isp Productions" diff --git a/src/clj/auto_ap/routes/invoices.clj b/src/clj/auto_ap/routes/invoices.clj index e37b3be4..aea3a9ab 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) - _ (println imports) transactions (reduce (fn [result {:keys [invoice-number customer-identifier total date vendor-code text full-text] :as info}] (println "searching for" vendor-code) @@ -172,7 +171,7 @@ '[?vendor :vendor/default-expense-account ?default-expense-account]]} :args [(d/db (d/connect uri)) vendor-code]}) first) - _ (println matching-vendor) + _ (println "matching" customer-identifier "-" matching-vendor) matching-client (parse/best-match clients customer-identifier) _ (println "New invoice matches client" matching-client) matching-location (parse/best-location-match matching-client text full-text)