From ca2f1d84ded51eef10d7487ad0dead54126ccc20 Mon Sep 17 00:00:00 2001 From: Bryce Covert Date: Thu, 19 Dec 2019 10:16:01 -0800 Subject: [PATCH] added implementations --- src/clj/auto_ap/parse.clj | 7 +++++ src/clj/auto_ap/parse/templates.clj | 40 ++++++++++++++++++++++++++--- 2 files changed, 43 insertions(+), 4 deletions(-) diff --git a/src/clj/auto_ap/parse.clj b/src/clj/auto_ap/parse.clj index 6b2eceb9..52fb658f 100644 --- a/src/clj/auto_ap/parse.clj +++ b/src/clj/auto_ap/parse.clj @@ -126,3 +126,10 @@ first) (:client/default-location client) (first (:client/locations client)))) + +(defn dbg-parse [v] + (doto + (map + (fn [x] (dissoc x :full-text :text)) + (parse v)) + clojure.pprint/pprint )) diff --git a/src/clj/auto_ap/parse/templates.clj b/src/clj/auto_ap/parse/templates.clj index d993c127..f9373b0f 100644 --- a/src/clj/auto_ap/parse/templates.clj +++ b/src/clj/auto_ap/parse/templates.clj @@ -41,8 +41,9 @@ :extract {:invoice-number #"Invoice #\s*\n\s*[\w\.]+\s+[\w\./]+(.*)\s*\n" :customer-identifier #"Bill To[^\n]+\n[^\n]*\n([\w ]+)\s{2,}" :date #"Invoice #\s*\n\s*[\w\.]+\s+([\w\./]+)" - :total #"Total\s+\$([0-9.]+)"} - :parser {:date [:clj-time "MM/dd/yy"]}} + :total #"Total\s+\$([0-9.,]+)"} + :parser {:date [:clj-time "MM/dd/yy"] + :total [:trim-commas nil]}} ;; DVW {:vendor "DVW Commercial" @@ -79,8 +80,39 @@ :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"]}} + :total #"([0-9.\-]+)\s+Status Code"} + :parser {:date [:clj-time "MM/dd/yy"] + :total [:trim-commas-and-negate nil]}} + + ;; SOUTHERN GLAZER'S + {:vendor "Southern Glazers" + :keywords [#"Southern Glazer's"] + :extract {:date #"INVOICE DATE(?s:.*)(?= (?:[0-9]+/[0-9]+/[0-9]+)\s+([0-9]+/[0-9]+/[0-9]+)) " + :customer-identifier #"SOLD TO:(?:.*)(?=\n)\n(.*)(?=\s{2,})" ;; ([\S ]+)\s{2,} + :invoice-number #"INVOICE\n(?:.*?)(?=\d{4,})(\d+)" + :total #"PAY THIS AMOUNT(?s:.*)(?= ([0-9,]+\.[0-9]{2}))"} + :parser {:date [:clj-time "MM/dd/yy"] + :total [:trim-commas nil]}} + + ;; GOLDEN BRANDS + {:vendor "Golden Brands San Jose" + :keywords [#"GOLDEN BRANDS"] + :extract {:date #"0430\n(.*)" + :customer-identifier #"Account:(?:.*\n)(.*(?=\s{2,}))" + :invoice-number #"Invoice#: (\d+)" + :total #"Invoice Total\s+([0-9]+\.[0-9]{2})"} + :parser {:date [:clj-time "EEE MMM dd, yyyy HH:mm aa"] + :total [:trim-commas nil]}} + + ;; WINE WAREHOUSE + {:vendor "Wine Warehouse" + :keywords [#"WINE WAREHOUSE"] + :extract {:date #"INVOICE DATE\s+([0-9]+/[0-9]+/[0-9]+)" + :customer-identifier #"SHIP-TO-PARTY.*\n(.*?)(?=\s{2,})" + :invoice-number #"INV #\s+(\d+)" + :total #"PLEASE PAY THIS AMOUNT\s+([0-9]+\.[0-9]{2})"} + :parser {:date [:clj-time "MM/dd/yyyy"] + :total [:trim-commas nil]}} ;; US FOODS {:vendor "US Foods"